Skip to content

Commit

Permalink
Merge pull request #52 from hotosm/feature/styles
Browse files Browse the repository at this point in the history
Styles code improvements, Header component, + Logo component
  • Loading branch information
spwoodcock authored Aug 22, 2024
2 parents c1c8822 + 49a5669 commit 1921e4e
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 336 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ site
**/**/*.js
**/**/*.js.map
**/**/*.d.ts

# Common system files
.DS_Store
16 changes: 12 additions & 4 deletions .storybook/stories/header.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { hrefTo } from '@storybook/addon-links';
import "../../components/header/header.ts";
import { html } from "lit";

const defaultLogo = new URL('../../theme/logo.png', import.meta.url).href;
const defaultLogo = "";

const meta: Meta = {
title: "Header",
Expand Down Expand Up @@ -99,9 +99,17 @@ export const Template: StoryObj = {
.tabs=${args.tabs}
></hot-header>
<h1>Page Content</h1>
<br>
<p>Text on the page</p>
<h1 class="hot-font-sans hot-font-size-x-large">
Page Content
</h1>
<p class="hot-font-sans hot-font-size-medium">
Lorem ipsum dolor sit amet, consectetur adipiscing
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
laborum.
</p>
`;
},
};
19 changes: 19 additions & 0 deletions .storybook/stories/logo.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// The HOT logo

import type { Meta, StoryObj } from "@storybook/web-components";
import "../../components/index";
import { html } from "lit";

const meta: Meta = {
title: "Logo",
component: "hot-logo",
};
export default meta;

export const Template: StoryObj = {
render: (args, { parameters }) => {
return html`
<hot-logo></hot-logo>
`;
},
};
159 changes: 21 additions & 138 deletions components/header/header.ts
Original file line number Diff line number Diff line change
@@ -1,115 +1,32 @@
import "../../theme/sl-custom.css";
import "../../theme/hot.css";

import "@shoelace-style/shoelace/dist/components/icon-button/icon-button.js";
import "@shoelace-style/shoelace/dist/components/tab-panel/tab-panel.js";
import "@shoelace-style/shoelace/dist/components/tab-group/tab-group.js";
import "@shoelace-style/shoelace/dist/components/tab/tab.js";

import { LitElement, css, html } from "lit";
import { LitElement, html } from "lit";
import { property, state } from "lit/decorators.js";
import { cva } from "class-variance-authority";
import { headerVariants, type sizes, styles} from "./styles";

import registerBundledIcons from "../../components/icons";

registerBundledIcons();

const headerVariants = cva(
// Defaults to include in all variants
`
flex flex-row bg-[var(--hot-white)] items-center justify-between
sm:justify-around p-2 border-b-2 border-b-gray-100 border-b-solid
`,
{
variants: {
size: {
small: "h-8",
large: "h-14",
},
},
}
);
type sizes = "small" | "large";

interface MenuItem {
label: string;
clickEvent: () => void;
}

export class Header extends LitElement {

@property() name = "hot-header";

/** Use a text-based title in the header. */
@property({ type: String }) title: string = "";

/** Display a logo on the left of the header. */
@property({ type: String }) logo: string | URL = `
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAB9CAMAAAAvBq6hAAAAbFBMVEX
////XPz/ke3vura3++vr32dn76+vYRET65eX10ND88PDxurrkfX3cVlb99PTkf3/zxMThb2/tqKjv
sbHfZWXlhIT439/cWVnyv7/rn5/idHT0ysrplpbaTU3qnJzZSEjni4veYWHgaWnokpKZE/dBAAAOH
ElEQVR4nO1cabuqvA6lMsggCCgzKOD//483SQvitiDoOfe4n7frw2YDHVfTJE2LmqagoKCgoKCgoK
CgoKCgoKCgoKCgoKCgoKCgoKDwhEu0+wzJW9Wmu0Mg/q127Uc9iHcVXlxj5n21iz8qfwKHfYronWo
rxlzxb8HYRz3w2U3TjNqfI+vG/I/KnyL9mK13ZMth+4Es/cPOXPqcypt7n/eXj8p/QPUxW2805g+S
RUj/oPgswvuYrdPmOp/Ici2aRobl0o2mmbmDD+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WQt
ulvrsN7dGsnKppl68Stg7feTpcmWMtuwOo41kpUIy2CfI0MbIo/ZLyBLWxNOWMTqONbUdaDwWU9Hp
/jT+vt1lvYn3K2132Y2o4IDP2qnx9nwu2tFeOrAG03QKaVDLvx3o8SvqHwVrFcfFrzEylXJZLlTkI
vXoeoy+OGO3EF/XueH175WssAF1D/EZR1ZoXdfTTr14SB+I8iNj+UNaPNOhmZ7pPotj9bQrrcUj1R
QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQ+Gf4H5j7yuOYiAtqAAAAAElFTkSuQmCC
`;
@property({ type: String }) logo: string | URL = "";

/** Add a drawer icon with a click event to e.g. open a sidebar. */
@property({ type: Boolean }) drawer: boolean = true;
Expand All @@ -122,45 +39,7 @@ export class Header extends LitElement {

@state() private selectedTab: number = 0;

static styles = [
css`
@unocss-placeholder;
`,
css`
#right-section {
display: flex;
align-items: center;
}
sl-tab-group {
display: flex;
}
sl-tab::part(base) {
font-size: 1rem;
border-bottom: 2px solid transparent;
}
sl-tab[selected]::part(base) {
border-bottom: 2px solid white;
}
#drawer-block {
display: flex;
align-items: center;
padding-right: 30px;
}
@media (prefers-color-scheme: light) {
header {
color: black;
}
#break {
background-color: black;
}
}
`,
];
static styles = styles;

protected render() {
const logoSrc =
Expand All @@ -172,20 +51,25 @@ export class Header extends LitElement {

return html`
<header class=${headerVariants({ size: this.size })}>
<a href="/" class="flex flex-row">
<a href="/" class="logo-link header-logo hot-flex hot-flex-row">
${logoSrc.length > 0
? html`
<img
id="logo"
src="${this.logo}"
alt="Logo"
class="h-10 px-10 hover:opacity-90"
class="hot-h-10 hot-px-10 hot-hover:opacity-90"
/>
`
: null}
: html`
<hot-logo
?iconOnly="${this.title.length > 0}"
>
</hot-logo>
`}
${this.title.length > 0
? html`
<h1 class="text-2xl color-primary font-sans font-bold pl-3 m-0">
<h1 class="hot-text-2xl hot-color-primary hot-font-sans hot-font-bold hot-pl-3 hot-m-0">
${this.title}
</h1>
`
Expand All @@ -194,9 +78,9 @@ export class Header extends LitElement {
${/* Navigation bar for desktop, hide on mobile */ ""}
<nav
className="hidden sm:flex justify-between items-center gap-4 font-semibold"
className="hot-hidden hot-sm:flex hot-justify-between hot-items-center hot-gap-4 hot-font-semibold"
>
<sl-tab-group>
<sl-tab-group className="hot-flex-col>
${this.tabs.map(
(item, index) => html`
<sl-tab
Expand All @@ -216,25 +100,24 @@ export class Header extends LitElement {
${/* Stacked navigation drawer for mobile */ ""}
${/* NOTE this should probably be in a drawer instead */ ""}
<nav
className="sm:hidden flex flex-col items-end gap-1 font-semibold"
className="hot-sm:hidden hot-flex hot-flex-col hot-items-end hot-gap-1 hot-font-semibold"
></nav>
<div id="right-section" style="display: flex; align-items: center;">
<div id="right-section" class="hot-flex hot-flex-center">
<sl-icon-button
library="bundled"
name="person-circle"
style="font-size: 1.8rem;"
style="font-size: var(--sl-font-size-x-large)"
label="login"
@click=${(e: MouseEvent) => {
this._handleLogin(e);
}}
></sl-icon-button>
<div id="drawer-block" style="font-size: 2rem;">
${this.drawer
? html`
<sl-icon-button
library="bundled"
style="font-size: var(--sl-font-size-x-large)"
name="list"
label="drawer-open"
></sl-icon-button>
Expand Down
40 changes: 40 additions & 0 deletions components/header/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { cva } from "class-variance-authority";
import { css } from "lit";

export const headerVariants = cva(
// Defaults to include in all variants
`
hot-flex hot-flex-row hot-bg-[var(--sl-color-white)] hot-items-center hot-justify-between
hot-sm:justify-around hot-p-2 hot-border-b-2 hot-border-b-gray-100 hot-border-b-solid
`,
{
variants: {
size: {
small: "hot-h-8",
large: "hot-h-14",
},
},
}
);

export type sizes = "small" | "large";

export const styles = [
css`
@unocss-placeholder;
`,
css`
.logo-link {
text-decoration: none;
}
sl-tab-group {
display: flex;
}
sl-tab::part(base) {
font-size: var(--sl-font-size-2);
}
`,
];
2 changes: 2 additions & 0 deletions components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import SlVisuallyHidden from '@shoelace-style/shoelace/dist/components/visually-

// Custom composite components
import HotHeader from './header/header';
import HotLogo from './logo/logo';
import HotToolbar from './toolbar/toolbar';
import HotTracking from './tracking/tracking';

Expand Down Expand Up @@ -259,6 +260,7 @@ export {
SlVisuallyHidden,
// Custom composite components
HotHeader,
HotLogo,
HotToolbar,
HotTracking,
}
31 changes: 31 additions & 0 deletions components/logo/logo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import "../../theme/hot.css";

import { LitElement, html } from "lit";
import { property } from "lit/decorators.js";

export class Logo extends LitElement {

@property() name = "hot-logo";

/** Display the icon only */
@property({ type: Boolean }) iconOnly: boolean = false;

/** Display the text only */
@property({ type: Boolean }) textOnly: boolean = false;

protected render() {

return html`
<h1 class="hot-flex hot-flex-row">
${ !this.textOnly ? html`<img src="../../theme/logo/hot-logo-icon.svg" />` : null }
${ !this.iconOnly ? html`<img src="../../theme/logo/hot-logo-text.svg" />` : null }
</h1>
`;
}

}

export default Logo;

// Define web component
customElements.define("hot-logo", Logo);
2 changes: 1 addition & 1 deletion components/toolbar/toolbar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "../../theme/sl-custom.css";
import "../../theme/hot.css";

import "@shoelace-style/shoelace/dist/components/button/button.js";
import "@shoelace-style/shoelace/dist/components/button-group/button-group.js";
Expand Down
2 changes: 1 addition & 1 deletion components/tracking/tracking.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "../../theme/sl-custom.css";
import "../../theme/hot.css";

import "@shoelace-style/shoelace/dist/components/alert/alert.js";

Expand Down
Loading

0 comments on commit 1921e4e

Please sign in to comment.