Skip to content

Commit

Permalink
build: move all components under subdirectories like shoelace
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Jun 4, 2024
1 parent ce685f1 commit 9eff1c0
Show file tree
Hide file tree
Showing 23 changed files with 369 additions and 97 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/cdn_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ jobs:
aws s3 sync --delete \
--exclude "*" \
--include='dist/*' \
--include "components/*.js" \
--include='components/*.d.ts' \
--include "react/*.js" \
--include='react/*.d.ts' \
--include "components/*" \
--include "react/*" \
--include "theme/*" \
--include "i18n/*.xliff" \
${{ github.workspace }} \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from "@storybook/web-components";
import "../../components/Button.js";
import "../../components/button/button.js";
import { html } from "lit";

const meta: Meta = {
Expand All @@ -11,12 +11,12 @@ export default meta;
export const Template: StoryObj = {
args: {
text: "Click Me",
variant: "primary",
variant: "default",
disabled: false,
},
argTypes: {
variant: {
options: ["primary", "secondary"],
options: ["default", "primary", "success", "neutral", "warning", "danger"],
control: {
type: "select",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from "@storybook/web-components";
import { hrefTo } from '@storybook/addon-links';
import "../../components/Header.js";
import "../../components/header/header.js";
import { html } from "lit";

const defaultLogo = new URL('../../theme/logo.png', import.meta.url).href;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Meta, StoryObj } from "@storybook/web-components";
import "../../components/Toolbar.js";
import "../../components/toolbar/toolbar.js";
import { html } from "lit";

const meta: Meta = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from "@storybook/web-components";
import '@shoelace-style/shoelace/dist/components/alert/alert.js';
import "../../components/Tracking.js";
import "../../components/tracking/tracking.js";
import { html } from "lit";

const meta: Meta = {
Expand Down Expand Up @@ -42,10 +42,10 @@ export const Template: StoryObj = {
}
},
addKeyLocalStorage: (siteId: number) => {
localStorage.setItem(`${siteId}-optout-closed`, 'true');
localStorage.setItem(`${siteId}-matomo-agree`, 'true');
},
removeKeyLocalStorage: (siteId: number) => {
localStorage.removeItem(`${siteId}-optout-closed`);
localStorage.removeItem(`${siteId}-matomo-agree`);
},
},
render: (args, { parameters }) => {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ including a bundler such as rollup/vite/webpack, this is probably the best appro
Example:

```js
import '@hotosm/ui/components/Toolbar';
import '@hotosm/ui/components/toolbar/toolbar';

// Then in your template
<hot-button>Click Me</hot-button>
Expand Down
22 changes: 12 additions & 10 deletions components/Button.ts → components/button/button.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import "../theme/hot.css";
import '@shoelace-style/shoelace/dist/themes/light.css';
import '@shoelace-style/shoelace/dist/themes/dark.css';
import "../../theme/sl-custom.css";

import '@shoelace-style/shoelace/dist/components/button/button.js';

Expand All @@ -13,9 +11,9 @@ const buttonStyle = cva(
"bg-primary text-white py-3 px-6 rounded leading-[1.15]",
{
variants: {
variant: {
primary: "bg-primary border-2 border-primary text-white",
secondary: `
classGroup: {
classGroup1: "bg-primary border-2 border-primary text-white",
classGroup2: `
bg-white border-2 border-primary text-primary! hover:bg-lightGray
focus:bg-transparent focus:border-primary
`,
Expand All @@ -27,15 +25,19 @@ const buttonStyle = cva(
},
},
);
type variants = "classGroup1" | "classGroup2";

export class Button extends LitElement {
@property() name = "hot-button";

/** Type of button. */
@property({ type: String }) variant: string = "default";

/** Disable the button, greyed out, not clickable. */
@property({ type: Boolean }) disabled: boolean = false;

/** CVA button type. */
@property({ type: String }) variant: "primary" | "secondary" = "primary";
/** CVA button class group. */
@property({ type: String, attribute: 'class-group' }) classGroup: variants = "classGroup1";

static styles = [
css`
Expand All @@ -46,9 +48,9 @@ export class Button extends LitElement {
protected render() {
return html`<sl-button
class=${buttonStyle({
variant: this.variant,
disabled: this.disabled,
classGroup: this.classGroup,
})}
variant=${this.variant}
?disabled=${this.disabled}
@click=${(e: MouseEvent) => {
this._handleClick(e);
Expand Down
39 changes: 29 additions & 10 deletions components/Header.ts → components/header/header.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import "../theme/hot.css";
import '@shoelace-style/shoelace/dist/themes/light.css';
import '@shoelace-style/shoelace/dist/themes/dark.css';
import "../../theme/sl-custom.css";

import '@shoelace-style/shoelace/dist/components/icon-button/icon-button.js';
import '@shoelace-style/shoelace/dist/components/tab-panel/tab-panel.js';
Expand All @@ -10,11 +8,11 @@ import '@shoelace-style/shoelace/dist/components/tab/tab.js';
import { LitElement, css, html, unsafeCSS } from "lit";
import { property, state } from "lit/decorators.js";

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

registerBundledIcons();

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

interface MenuItem {
label: string,
Expand Down Expand Up @@ -91,6 +89,11 @@ export class Header extends LitElement {
align-items: center;
}
#right-section {
display: flex;
align-items: center;
}
sl-tab-group {
display: flex;
}
Expand All @@ -114,6 +117,9 @@ export class Header extends LitElement {
header {
color: black;
}
#break {
background-color: black;
}
}
`
];
Expand Down Expand Up @@ -149,11 +155,20 @@ export class Header extends LitElement {
)}
</sl-tab-group>
</div>
<div id="drawer-block" style="font-size: 32px;">
${this.drawer ? html`
<sl-icon-button library="bundled" name="list" label="drawer-open"></sl-icon-button>
` : null}
<div id="right-section" style="display: flex; align-items: center;">
<sl-icon-button
library="bundled"
name="person-circle"
style="font-size: 1.8rem;"
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" name="list" label="drawer-open"></sl-icon-button>
` : null}
</div>
</div>
</header>
`;
Expand All @@ -163,6 +178,10 @@ export class Header extends LitElement {
this.selectedTab = index;
clickAction();
}

private _handleLogin(_e: MouseEvent) {
console.log("Login button clicked");
}
}

export default Header;
Expand Down
6 changes: 6 additions & 0 deletions components/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ const icons = {
<path fill-rule="evenodd" d="M6 12.5a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-4-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5zm0-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/>
</svg>
`,
'person-circle': `
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-person-circle" viewBox="0 0 16 16">
<path d="M11 6a3 3 0 1 1-6 0 3 3 0 0 1 6 0z"/>
<path fill-rule="evenodd" d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8zm8-7a7 7 0 0 0-5.468 11.37C3.242 11.226 4.805 10 8 10s4.757 1.225 5.468 2.37A7 7 0 0 0 8 1z"/>
</svg>
`
};

const libraryResolver: IconLibraryResolver = (name: string) => {
Expand Down
15 changes: 11 additions & 4 deletions components/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// Index to import all components together
// import '@hotosm/ui/components';

export { default as Button } from './Button';
export { default as Header } from './Header';
export { default as Toolbar } from './Toolbar';
export { default as Tracking } from './Tracking';
// NOTE Must be included or rollup-plugin-css-only does not pick them up
// NOTE the light theme must be imported before the sl-custom override!
import '../theme/hot.css';
import '@shoelace-style/shoelace/dist/themes/light.css';
// import '@shoelace-style/shoelace/dist/themes/dark.css';
import "../theme/sl-custom.css";

export { default as Button } from './button/button';
export { default as Header } from './header/header';
export { default as Toolbar } from './toolbar/toolbar';
export { default as Tracking } from './tracking/tracking';
6 changes: 2 additions & 4 deletions components/Toolbar.ts → components/toolbar/toolbar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import "../theme/hot.css";
import '@shoelace-style/shoelace/dist/themes/light.css';
import '@shoelace-style/shoelace/dist/themes/dark.css';
import "../../theme/sl-custom.css";

import '@shoelace-style/shoelace/dist/components/button/button.js';
import '@shoelace-style/shoelace/dist/components/button-group/button-group.js';
Expand All @@ -10,7 +8,7 @@ import '@shoelace-style/shoelace/dist/components/tooltip/tooltip.js';
import { LitElement, css, html, unsafeCSS } from "lit";
import { property } from "lit/decorators.js";

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

registerBundledIcons();

Expand Down
7 changes: 2 additions & 5 deletions components/Tracking.ts → components/tracking/tracking.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import "../theme/hot.css";
import '@shoelace-style/shoelace/dist/themes/light.css';
import '@shoelace-style/shoelace/dist/themes/dark.css';
import "../../theme/sl-custom.css";

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

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

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

registerBundledIcons();

Expand Down Expand Up @@ -41,7 +39,6 @@ export class Tracking extends LitElement {
#tracking-header {
font-weight: var(--sl-font-weight-bold);
font-size: var(--sl-font-size-large);
color: #d63f3f;
text-align: center;
}
sl-alert::part(base) {
Expand Down
11 changes: 6 additions & 5 deletions docs/components/hot-button.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

## Properties

| Property | Attribute | Type | Default | Description |
|------------|------------|----------------------------|--------------|------------------------------------------------|
| `disabled` | `disabled` | `boolean` | false | Disable the button, greyed out, not clickable. |
| `name` | `name` | `string` | "hot-button" | |
| `variant` | `variant` | `"primary" \| "secondary"` | "primary" | CVA button type. |
| Property | Attribute | Type | Default | Description |
|--------------|---------------|------------|---------------|------------------------------------------------|
| `classGroup` | `class-group` | `variants` | "classGroup1" | CVA button class group. |
| `disabled` | `disabled` | `boolean` | false | Disable the button, greyed out, not clickable. |
| `name` | `name` | `string` | "hot-button" | |
| `variant` | `variant` | `string` | "default" | Type of button. |

## Events

Expand Down
1 change: 1 addition & 0 deletions docs/components/hot-header.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
| `drawer` | `drawer` | `boolean` | true |
| `logo` | `logo` | `string \| URL` | "hotLogo" |
| `name` | `name` | `string` | "hot-header" |
| `tabs` | `tabs` | `MenuItem[]` | [] |
| `title` | `title` | `string` | "" |
2 changes: 1 addition & 1 deletion examples/svelte/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script type="module" lang="ts">
import '@hotosm/ui/components/Toolbar';
import '@hotosm/ui/components/toolbar/toolbar';
import hotLogo from '@hotosm/ui/theme/logo.png';
import { onMount } from 'svelte';
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</template>

<script setup>
import '@hotosm/ui/components/Toolbar';
import '@hotosm/ui/components/toolbar/toolbar';
import hotLogo from '@hotosm/ui/theme/logo.png';
import { ref } from "vue";
Expand Down
5 changes: 1 addition & 4 deletions examples/vue/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",

"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
"baseUrl": "."
}
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"prepare": "pnpm run build",
"compile": "tsc",
"build": "pnpm run compile && rollup --config",
"build:docstrings": "wca analyze 'components/*.ts' --outDir 'docs/components' --format 'markdown'",
"build:docstrings": "wca analyze 'components/**/*.ts' --outDir 'docs/components' --format 'markdown'",
"build:stories": "pnpm run build && storybook build --output-dir=docs/stories",
"build:docs": "pnpm run build:docstrings && pnpm run build:stories",
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down Expand Up @@ -84,8 +84,7 @@
},
"files": [
"dist/**/*",
"components/*.js",
"components/*.d.ts",
"components/**/*",
"react/*.js",
"react/*.d.ts",
"theme/**/*",
Expand Down
Loading

0 comments on commit 9eff1c0

Please sign in to comment.