mirror of
https://github.com/home-assistant/frontend.git
synced 2026-12-04 18:49:22 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c026348f28 | ||
|
|
4062e8c2cd |
No files matched your search
@@ -19,6 +19,10 @@ workflows:
|
||||
'.github/workflows/codeql-analysis.yaml':
|
||||
- 'actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1'
|
||||
- 'github/codeql-action@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea'
|
||||
'.github/workflows/components_storybook.yaml':
|
||||
- 'actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9'
|
||||
- 'actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1'
|
||||
- 'actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1'
|
||||
'.github/workflows/copilot-setup-steps.yml':
|
||||
- 'actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9'
|
||||
- 'actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1'
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
# Builds the Storybook of @home-assistant/components (packages/components) and
|
||||
# deploys it to Netlify, when the package or the app theme it uses changes:
|
||||
# - a pull request gets a preview at deploy-preview-<number>--<site>.netlify.app
|
||||
# - a push to dev updates dev--<site>.netlify.app
|
||||
# The main site shows the version on npm, so it is deployed when publishing,
|
||||
# not here. Without the NETLIFY_COMPONENTS_SITE_ID secret, Storybook is only
|
||||
# built, which still catches broken stories.
|
||||
name: Components Storybook
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
paths:
|
||||
- "packages/components/**"
|
||||
- "src/resources/theme/**"
|
||||
- "src/resources/roboto.ts"
|
||||
- "src/common/style/derived-css-vars.ts"
|
||||
- ".github/workflows/components_storybook.yaml"
|
||||
pull_request:
|
||||
branches:
|
||||
- dev
|
||||
paths:
|
||||
- "packages/components/**"
|
||||
- "src/resources/theme/**"
|
||||
- "src/resources/roboto.ts"
|
||||
- "src/common/style/derived-css-vars.ts"
|
||||
- ".github/workflows/components_storybook.yaml"
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
NODE_OPTIONS: --max_old_space_size=6144
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
name: Build and deploy
|
||||
runs-on: ubuntu-latest
|
||||
# Pull requests from forks get no secrets, so they can't deploy
|
||||
if: >-
|
||||
github.repository == 'home-assistant/frontend' &&
|
||||
((github.event_name == 'pull_request' &&
|
||||
github.event.pull_request.head.repo.full_name == github.repository) ||
|
||||
(github.event_name != 'pull_request' && github.ref == 'refs/heads/dev'))
|
||||
environment:
|
||||
name: ${{ github.event_name == 'pull_request' && 'Components Storybook preview' || 'Components Storybook dev' }}
|
||||
url: ${{ steps.deploy.outputs.netlify_url }}
|
||||
steps:
|
||||
- name: Check out files from GitHub
|
||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Setup Node and install
|
||||
uses: $/.github/actions/setup
|
||||
|
||||
- name: Build Storybook
|
||||
run: pnpm --filter @home-assistant/components build-storybook
|
||||
|
||||
- name: Check for the Netlify site
|
||||
id: site
|
||||
env:
|
||||
SITE_ID: ${{ secrets.NETLIFY_COMPONENTS_SITE_ID }}
|
||||
run: |
|
||||
if [ -n "$SITE_ID" ]; then
|
||||
echo "configured=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "::notice::NETLIFY_COMPONENTS_SITE_ID is not set, so Storybook is built but not deployed"
|
||||
fi
|
||||
|
||||
- name: Deploy to Netlify
|
||||
id: deploy
|
||||
if: steps.site.outputs.configured == 'true'
|
||||
uses: $/.github/actions/netlify-deploy
|
||||
with:
|
||||
dir: packages/components/storybook-static
|
||||
# A preview per pull request, and the unreleased state of dev
|
||||
alias: ${{ github.event_name == 'pull_request' && format('deploy-preview-{0}', github.event.number) || 'dev' }}
|
||||
auth-token: ${{ secrets.NETLIFY_AUTH_TOKEN }}
|
||||
site-id: ${{ secrets.NETLIFY_COMPONENTS_SITE_ID }}
|
||||
|
||||
- name: Generate summary
|
||||
if: steps.deploy.outputs.netlify_url
|
||||
env:
|
||||
URL: ${{ steps.deploy.outputs.netlify_url }}
|
||||
run: |
|
||||
echo "Storybook: $URL" >> "$GITHUB_STEP_SUMMARY"
|
||||
@@ -67,3 +67,4 @@ test/e2e/app/dist/
|
||||
.serena
|
||||
|
||||
test/benchmarks/results/
|
||||
storybook-static/
|
||||
+7
-3
@@ -303,9 +303,13 @@ export default tseslint.config(
|
||||
},
|
||||
},
|
||||
{
|
||||
// Published as native ESM, where package subpath imports such as
|
||||
// "lit/decorators.js" need their extension.
|
||||
files: ["packages/*/src/**/*.ts"],
|
||||
// Published as native ESM and run by Vite in Storybook, where package
|
||||
// subpath imports such as "lit/decorators.js" need their extension.
|
||||
files: [
|
||||
"packages/*/src/**/*.ts",
|
||||
"packages/*/stories/**/*.ts",
|
||||
"packages/*/.storybook/**/*.ts",
|
||||
],
|
||||
rules: {
|
||||
"import-x/extensions": ["error", "ignorePackages", { ts: "never" }],
|
||||
},
|
||||
|
||||
+2
-2
@@ -8,11 +8,11 @@
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"build": "node build-scripts/build-manager.mjs",
|
||||
"lint:eslint": "eslint \"**/src/**/*.{js,ts,html}\" --cache --cache-strategy=content --cache-location=node_modules/.cache/eslint/.eslintcache --ignore-pattern=.gitignore --max-warnings=0",
|
||||
"lint:eslint": "eslint \"**/src/**/*.{js,ts,html}\" \"packages/*/{stories,.storybook}/**/*.ts\" --cache --cache-strategy=content --cache-location=node_modules/.cache/eslint/.eslintcache --ignore-pattern=.gitignore --max-warnings=0",
|
||||
"format:eslint": "eslint \"**/src/**/*.{js,ts,html}\" --cache --cache-strategy=content --cache-location=node_modules/.cache/eslint/.eslintcache --ignore-pattern=.gitignore --fix",
|
||||
"lint:prettier": "prettier . --cache --check",
|
||||
"format:prettier": "prettier . --cache --write",
|
||||
"lint:types": "node ./node_modules/@typescript/native/bin/tsc && node ./node_modules/@typescript/native/bin/tsc -p .github/scripts",
|
||||
"lint:types": "node ./node_modules/@typescript/native/bin/tsc && node ./node_modules/@typescript/native/bin/tsc -p .github/scripts && node ./node_modules/@typescript/native/bin/tsc -p packages/components/tsconfig.storybook.json",
|
||||
"lint:lit": "lit-analyzer \"{.,*,packages/*}/src/**/*.ts\"",
|
||||
"lint:element-imports": "eslint \"**/src/**/*.{js,ts,html}\" --ignore-pattern=.gitignore --rule '{\"ha/no-unused-element-import\": \"warn\"}'",
|
||||
"lint:licenses": "node --no-deprecation script/check-licenses",
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { create } from "storybook/theming/create";
|
||||
|
||||
const dark = matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
|
||||
// Storybook's own interface and docs pages follow the system setting. The
|
||||
// toolbar switch only changes the Home Assistant theme of the stories.
|
||||
export const brandTheme = create({
|
||||
base: dark ? "dark" : "light",
|
||||
brandTitle: "Home Assistant Components",
|
||||
brandUrl:
|
||||
"https://github.com/home-assistant/frontend/tree/dev/packages/components",
|
||||
brandTarget: "_blank",
|
||||
colorPrimary: "#18bcf2",
|
||||
colorSecondary: dark ? "#37c8fd" : "#009ac7",
|
||||
fontBase: "Roboto, system-ui, sans-serif",
|
||||
});
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// Defined in main.ts for the app's font faces
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
declare const __STATIC_PATH__: string;
|
||||
|
||||
// Generated into dist/ when Storybook starts, so it doesn't exist for a type
|
||||
// check before the first build
|
||||
declare module "@home-assistant/components/custom-elements.json" {
|
||||
const manifest: object;
|
||||
export default manifest;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { StorybookConfig } from "@storybook/web-components-vite";
|
||||
|
||||
const config: StorybookConfig = {
|
||||
framework: "@storybook/web-components-vite",
|
||||
stories: ["../stories/**/*.mdx", "../stories/**/*.stories.ts"],
|
||||
addons: ["@storybook/addon-docs", "@storybook/addon-a11y"],
|
||||
core: { disableTelemetry: true },
|
||||
staticDirs: [
|
||||
{
|
||||
from: "../../../node_modules/roboto-fontface/fonts/roboto",
|
||||
to: "/static/fonts/roboto",
|
||||
},
|
||||
{ from: "../../../public/static/icons", to: "/static/icons" },
|
||||
],
|
||||
managerHead: (head) => `${head}
|
||||
<link rel="icon" href="static/icons/favicon-32x32.png" />
|
||||
`,
|
||||
viteFinal: (viteConfig) => ({
|
||||
...viteConfig,
|
||||
define: {
|
||||
...viteConfig.define,
|
||||
// The theme's font faces load from here. Relative, so a build works
|
||||
// under any path, like a preview deploy.
|
||||
__STATIC_PATH__: JSON.stringify("static/"),
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -0,0 +1,4 @@
|
||||
import { addons } from "storybook/manager-api";
|
||||
import { brandTheme } from "./brand";
|
||||
|
||||
addons.setConfig({ theme: brandTheme });
|
||||
@@ -0,0 +1,57 @@
|
||||
import {
|
||||
setCustomElementsManifest,
|
||||
type Preview,
|
||||
} from "@storybook/web-components-vite";
|
||||
import { setStorybookHelpersConfig } from "@wc-toolkit/storybook-helpers";
|
||||
import manifest from "@home-assistant/components/custom-elements.json";
|
||||
import { brandTheme } from "./brand";
|
||||
import { withHomeAssistantTheme } from "./theme";
|
||||
|
||||
// Controls, templates and the API tables on the docs pages come from the JSDoc
|
||||
setCustomElementsManifest(manifest);
|
||||
setStorybookHelpersConfig({ hideArgRef: true, useCssPropTypes: true });
|
||||
|
||||
const preview: Preview = {
|
||||
decorators: [withHomeAssistantTheme],
|
||||
globalTypes: {
|
||||
theme: {
|
||||
description: "Home Assistant theme",
|
||||
toolbar: {
|
||||
title: "Theme",
|
||||
icon: "mirror",
|
||||
items: [
|
||||
{ value: "light", title: "Light" },
|
||||
{ value: "dark", title: "Dark" },
|
||||
],
|
||||
dynamicTitle: true,
|
||||
},
|
||||
},
|
||||
direction: {
|
||||
description: "Text direction",
|
||||
toolbar: {
|
||||
title: "Direction",
|
||||
icon: "transfer",
|
||||
items: [
|
||||
{ value: "ltr", title: "Left to right" },
|
||||
{ value: "rtl", title: "Right to left" },
|
||||
],
|
||||
dynamicTitle: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
initialGlobals: {
|
||||
theme: matchMedia("(prefers-color-scheme: dark)").matches
|
||||
? "dark"
|
||||
: "light",
|
||||
direction: "ltr",
|
||||
},
|
||||
parameters: {
|
||||
controls: { expanded: true },
|
||||
docs: { theme: brandTheme },
|
||||
options: {
|
||||
storySort: { order: ["Introduction", "Components"] },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default preview;
|
||||
@@ -0,0 +1,47 @@
|
||||
import type { Decorator } from "@storybook/web-components-vite";
|
||||
// Taken from the app until the Home Assistant theme is a package of its own,
|
||||
// which the app and Storybook can then both import
|
||||
/* eslint-disable import-x/no-relative-packages */
|
||||
import { darkColorVariables } from "../../../src/resources/theme/color";
|
||||
import { darkSemanticVariables } from "../../../src/resources/theme/semantic.globals";
|
||||
import { themeStyles } from "../../../src/resources/theme/theme";
|
||||
/* eslint-enable import-x/no-relative-packages */
|
||||
|
||||
// The same tokens the app puts on the page. On docs pages each example box
|
||||
// gets them too, as the page itself follows Storybook's theme.
|
||||
const style = document.createElement("style");
|
||||
style.textContent = `${themeStyles}
|
||||
body,
|
||||
.docs-story {
|
||||
background-color: var(--ha-color-surface-low);
|
||||
color: var(--ha-color-text-primary);
|
||||
font-family: var(--ha-font-family-body);
|
||||
}
|
||||
`;
|
||||
document.head.append(style);
|
||||
|
||||
const darkVariables = { ...darkSemanticVariables, ...darkColorVariables };
|
||||
|
||||
// Dark mode works like in the app, which sets the dark values on <html>
|
||||
export const withHomeAssistantTheme: Decorator = (story, context) => {
|
||||
const root = document.documentElement;
|
||||
const dark = context.globals.theme === "dark";
|
||||
for (const [name, value] of Object.entries(darkVariables)) {
|
||||
if (dark) {
|
||||
root.style.setProperty(`--${name}`, value);
|
||||
} else {
|
||||
root.style.removeProperty(`--${name}`);
|
||||
}
|
||||
}
|
||||
root.style.colorScheme = dark ? "dark" : "light";
|
||||
// Like setDirectionStyles in the app: the theme sets `direction: ltr` on
|
||||
// <html>, which wins over the dir attribute
|
||||
const rtl = context.globals.direction === "rtl";
|
||||
root.dir = rtl ? "rtl" : "ltr";
|
||||
root.style.direction = root.dir;
|
||||
root.style.setProperty("--direction", root.dir);
|
||||
root.style.setProperty("--float-start", rtl ? "right" : "left");
|
||||
root.style.setProperty("--float-end", rtl ? "left" : "right");
|
||||
root.style.setProperty("--scale-direction", rtl ? "-1" : "1");
|
||||
return story();
|
||||
};
|
||||
@@ -168,6 +168,7 @@ side effects, which `sideEffects` relies on for tree shaking.
|
||||
```bash
|
||||
pnpm --filter @home-assistant/components build # ESM, type declarations and custom-elements.json to dist/
|
||||
pnpm --filter @home-assistant/components dev # rebuild on change
|
||||
pnpm --filter @home-assistant/components storybook # Storybook on http://localhost:6006
|
||||
```
|
||||
|
||||
Inside this repository the app uses the sources directly through
|
||||
@@ -177,3 +178,16 @@ source file becomes its own ES module. The build then generates a
|
||||
[custom elements manifest](https://custom-elements-manifest.open-wc.org) from
|
||||
the JSDoc of each element, so document new slots, parts, CSS properties and
|
||||
events there.
|
||||
|
||||
### Storybook
|
||||
|
||||
Each element has stories in `stories/`. Their controls, API tables and event
|
||||
logging come from the custom elements manifest, through
|
||||
[`@wc-toolkit/storybook-helpers`](https://wc-toolkit.com/integrations/storybook/),
|
||||
so a story only needs the template and the examples worth showing. The
|
||||
toolbar switches between the light and dark Home Assistant theme and the text
|
||||
direction. Restart Storybook after changing the JSDoc, as the manifest is
|
||||
generated on start.
|
||||
|
||||
Pull requests from branches in this repository that change this package get
|
||||
a Storybook preview, and the latest `dev` gets one too.
|
||||
@@ -51,7 +51,9 @@
|
||||
"scripts": {
|
||||
"build": "rslib build && cem analyze",
|
||||
"dev": "rslib build --watch",
|
||||
"prepublishOnly": "pnpm run build"
|
||||
"prepublishOnly": "pnpm run build",
|
||||
"storybook": "cem analyze && storybook dev -p 6006",
|
||||
"build-storybook": "cem analyze && storybook build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@floating-ui/dom": "^1.8.0"
|
||||
@@ -62,7 +64,13 @@
|
||||
"devDependencies": {
|
||||
"@custom-elements-manifest/analyzer": "0.11.0",
|
||||
"@rslib/core": "1.1.0",
|
||||
"@storybook/addon-a11y": "10.6.10",
|
||||
"@storybook/addon-docs": "10.6.10",
|
||||
"@storybook/web-components-vite": "10.6.10",
|
||||
"@wc-toolkit/storybook-helpers": "10.7.7",
|
||||
"lit": "3.3.3",
|
||||
"typescript": "6.0.3"
|
||||
"storybook": "10.6.10",
|
||||
"typescript": "6.0.3",
|
||||
"vite": "8.4.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import type { Meta, StoryObj } from "@storybook/web-components-vite";
|
||||
import { getStorybookHelpers } from "@wc-toolkit/storybook-helpers";
|
||||
import { html } from "lit";
|
||||
import "../src/components/card/global";
|
||||
import type { HacCard } from "../src/components/card/hac-card";
|
||||
|
||||
const { args, argTypes, template } = getStorybookHelpers<HacCard>("hac-card");
|
||||
|
||||
const header = html`<h2
|
||||
slot="header"
|
||||
style="margin: 0; padding: 16px; font-size: 20px; font-weight: 500;"
|
||||
>
|
||||
Living room
|
||||
</h2>`;
|
||||
|
||||
const body = html`The lights are on and the temperature is 21 °C.`;
|
||||
|
||||
const footer = html`<button slot="footer">Turn off</button>`;
|
||||
|
||||
const meta: Meta<typeof args> = {
|
||||
title: "Components/Card",
|
||||
component: "hac-card",
|
||||
tags: ["autodocs"],
|
||||
args,
|
||||
argTypes,
|
||||
render: (storyArgs) => template(storyArgs, html`${header}${body}${footer}`),
|
||||
decorators: [
|
||||
(story) => html`<div style="max-width: 360px;">${story()}</div>`,
|
||||
],
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof args>;
|
||||
|
||||
export const Default: Story = {};
|
||||
|
||||
export const Raised: Story = {
|
||||
args: { appearance: "raised" },
|
||||
};
|
||||
|
||||
/** Without a header the content keeps its top padding; an empty footer is hidden. */
|
||||
export const ContentOnly: Story = {
|
||||
render: (storyArgs) => template(storyArgs, body),
|
||||
};
|
||||
|
||||
export const CustomStyle: Story = {
|
||||
// The helpers set CSS properties for the whole page, so keep them in a frame
|
||||
// on the docs page
|
||||
parameters: { docs: { story: { inline: false, height: "220px" } } },
|
||||
args: {
|
||||
"--hac-card-border-radius": "24px",
|
||||
"--hac-card-content-padding": "24px",
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Markdown, Meta } from "@storybook/addon-docs/blocks";
|
||||
import readme from "../README.md?raw";
|
||||
|
||||
<Meta title="Introduction" />
|
||||
|
||||
<Markdown>{readme}</Markdown>
|
||||
@@ -0,0 +1,210 @@
|
||||
import type { Meta, StoryObj } from "@storybook/web-components-vite";
|
||||
import { getStorybookHelpers } from "@wc-toolkit/storybook-helpers";
|
||||
import { html } from "lit";
|
||||
import "../src/components/popover/global";
|
||||
import type { HacPopover } from "../src/components/popover/hac-popover";
|
||||
|
||||
const { args, argTypes, template } =
|
||||
getStorybookHelpers<HacPopover>("hac-popover");
|
||||
|
||||
const infoIcon = html`<svg viewBox="0 0 24 24" width="20" height="20">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z"
|
||||
/>
|
||||
</svg>`;
|
||||
|
||||
const content = html`
|
||||
Use the username and password you made when you set up Home Assistant.
|
||||
<a href="https://www.home-assistant.io/docs/authentication/">Learn more</a>
|
||||
`;
|
||||
|
||||
// Docs pages show several stories in one document, the first one twice, so
|
||||
// each example gets its own anchor id. It stays the same across renders,
|
||||
// because the controls follow attribute changes and would render again.
|
||||
const exampleIds = new WeakMap<HTMLElement, string>();
|
||||
let lastExampleId = 0;
|
||||
const exampleId = (canvas: HTMLElement): string => {
|
||||
let id = exampleIds.get(canvas);
|
||||
if (!id) {
|
||||
id = `popover-example-${++lastExampleId}`;
|
||||
exampleIds.set(canvas, id);
|
||||
}
|
||||
return id;
|
||||
};
|
||||
|
||||
const meta: Meta<typeof args> = {
|
||||
title: "Components/Popover",
|
||||
component: "hac-popover",
|
||||
tags: ["autodocs"],
|
||||
parameters: { layout: "centered" },
|
||||
args,
|
||||
argTypes: {
|
||||
...argTypes,
|
||||
// The type comes from Floating UI, so the manifest has no values for it
|
||||
placement: {
|
||||
...argTypes.placement,
|
||||
control: "select",
|
||||
options: [
|
||||
"top",
|
||||
"top-start",
|
||||
"top-end",
|
||||
"right",
|
||||
"right-start",
|
||||
"right-end",
|
||||
"bottom",
|
||||
"bottom-start",
|
||||
"bottom-end",
|
||||
"left",
|
||||
"left-start",
|
||||
"left-end",
|
||||
],
|
||||
},
|
||||
},
|
||||
render: (storyArgs, { canvasElement }) => {
|
||||
const id = exampleId(canvasElement);
|
||||
return html`
|
||||
<button id=${`${id}-anchor`}>More info</button>
|
||||
${template({ ...storyArgs, for: `${id}-anchor` }, content)}
|
||||
`;
|
||||
},
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof args>;
|
||||
|
||||
export const Default: Story = {};
|
||||
|
||||
export const Open: Story = {
|
||||
args: { open: true },
|
||||
};
|
||||
|
||||
/** An info button next to a title. Hover opens it with a mouse, a click pins it. */
|
||||
export const InfoButton: Story = {
|
||||
args: { trigger: "hover" },
|
||||
render: (storyArgs, { canvasElement }) => {
|
||||
const id = exampleId(canvasElement);
|
||||
return html`
|
||||
<div style="display: flex; align-items: center; gap: 4px;">
|
||||
<strong>Log in</strong>
|
||||
<button
|
||||
id=${`${id}-anchor`}
|
||||
aria-label="About logging in"
|
||||
style="display: inline-flex; padding: 4px; border: none; border-radius: 50%; background: none; color: var(--ha-color-text-secondary); cursor: pointer;"
|
||||
>
|
||||
${infoIcon}
|
||||
</button>
|
||||
${template(
|
||||
{ ...storyArgs, for: `${id}-anchor` },
|
||||
html`<strong>Logging in</strong><br />
|
||||
Use the username and password you made when you set up Home
|
||||
Assistant. If you have lost them, the owner of this home can reset
|
||||
them for you.`
|
||||
)}
|
||||
</div>
|
||||
`;
|
||||
},
|
||||
};
|
||||
|
||||
/** With `trigger="manual"` only `open`, `show()` and `hide()` open it. */
|
||||
export const Manual: Story = {
|
||||
args: { trigger: "manual", open: true, placement: "right" },
|
||||
};
|
||||
|
||||
export const CustomStyle: Story = {
|
||||
// The helpers set CSS properties for the whole page, so keep them in a frame
|
||||
// on the docs page
|
||||
parameters: { docs: { story: { inline: false, height: "260px" } } },
|
||||
args: {
|
||||
open: true,
|
||||
"--hac-popover-max-width": "160px",
|
||||
"--hac-popover-border-radius": "0",
|
||||
"--hac-popover-background-color":
|
||||
"var(--ha-color-fill-primary-normal-resting)",
|
||||
"--hac-popover-border": "2px solid var(--ha-color-border-primary-loud)",
|
||||
"--hac-popover-box-shadow": "none",
|
||||
},
|
||||
};
|
||||
|
||||
/** Flips to the other side, or shifts along it, when there is no room. */
|
||||
export const Placements: Story = {
|
||||
render: (_storyArgs, { canvasElement }) => {
|
||||
const id = exampleId(canvasElement);
|
||||
return html`
|
||||
<div style="display: flex; flex-wrap: wrap; gap: 8px;">
|
||||
${(["top", "right", "bottom-end", "left"] as const).map(
|
||||
(placement) => html`
|
||||
<button id=${`${id}-${placement}`}>${placement}</button>
|
||||
<hac-popover for=${`${id}-${placement}`} placement=${placement}>
|
||||
Placed at ${placement}.
|
||||
</hac-popover>
|
||||
`
|
||||
)}
|
||||
</div>
|
||||
`;
|
||||
},
|
||||
};
|
||||
|
||||
/** Follows its anchor while the container scrolls, and hides while the anchor is scrolled out of view. */
|
||||
export const InScrollingContainer: Story = {
|
||||
render: (storyArgs, { canvasElement }) => {
|
||||
const id = exampleId(canvasElement);
|
||||
return html`
|
||||
<div
|
||||
style="height: 160px; width: 280px; overflow: auto; border: 1px solid var(--ha-color-border-neutral-quiet);"
|
||||
>
|
||||
<div style="padding: 120px 16px 240px;">
|
||||
<button id=${`${id}-anchor`}>Scroll me</button>
|
||||
${template({ ...storyArgs, for: `${id}-anchor` }, content)}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
},
|
||||
};
|
||||
|
||||
/** Scrolls inside when the content is taller than the room left on screen. */
|
||||
export const LongContent: Story = {
|
||||
render: (storyArgs, { canvasElement }) => {
|
||||
const id = exampleId(canvasElement);
|
||||
return html`
|
||||
<button id=${`${id}-anchor`}>Long</button>
|
||||
${template(
|
||||
{ ...storyArgs, for: `${id}-anchor` },
|
||||
html`${Array.from(
|
||||
{ length: 6 },
|
||||
() =>
|
||||
html`<p>
|
||||
Use the username and password you made when you set up Home
|
||||
Assistant. If you have lost them, the owner of this home can reset
|
||||
them for you.
|
||||
</p>`
|
||||
)}`
|
||||
)}
|
||||
`;
|
||||
},
|
||||
};
|
||||
|
||||
const openNextDialog = (ev: Event) => {
|
||||
(
|
||||
(ev.target as HTMLElement).nextElementSibling as HTMLDialogElement
|
||||
).showModal();
|
||||
};
|
||||
|
||||
/** Shows above a modal dialog. Escape closes the popover first, then the dialog. */
|
||||
export const InDialog: Story = {
|
||||
render: (storyArgs, { canvasElement }) => {
|
||||
const id = exampleId(canvasElement);
|
||||
return html`
|
||||
<button @click=${openNextDialog}>Open dialog</button>
|
||||
<dialog aria-label="Example dialog">
|
||||
<p>
|
||||
Inside the dialog
|
||||
<button id=${`${id}-anchor`}>Info</button>
|
||||
${template({ ...storyArgs, for: `${id}-anchor` }, content)}
|
||||
</p>
|
||||
<form method="dialog"><button>Close</button></form>
|
||||
</dialog>
|
||||
`;
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
import type { Meta, StoryObj } from "@storybook/web-components-vite";
|
||||
import { getStorybookHelpers } from "@wc-toolkit/storybook-helpers";
|
||||
import { html } from "lit";
|
||||
import "../src/components/spinner/global";
|
||||
import type { HacSpinner } from "../src/components/spinner/hac-spinner";
|
||||
|
||||
const { args, argTypes, template } =
|
||||
getStorybookHelpers<HacSpinner>("hac-spinner");
|
||||
|
||||
const meta: Meta<typeof args> = {
|
||||
title: "Components/Spinner",
|
||||
component: "hac-spinner",
|
||||
tags: ["autodocs"],
|
||||
parameters: { layout: "centered" },
|
||||
args,
|
||||
argTypes,
|
||||
render: (storyArgs) => template(storyArgs),
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof args>;
|
||||
|
||||
export const Default: Story = {};
|
||||
|
||||
export const Sizes: Story = {
|
||||
render: () => html`
|
||||
<div style="display: flex; align-items: center; gap: 24px;">
|
||||
<hac-spinner size="tiny"></hac-spinner>
|
||||
<hac-spinner size="small"></hac-spinner>
|
||||
<hac-spinner size="medium"></hac-spinner>
|
||||
<hac-spinner size="large"></hac-spinner>
|
||||
</div>
|
||||
`,
|
||||
};
|
||||
|
||||
/** Name what is in progress, so screen readers announce more than "Loading". */
|
||||
export const WithLabel: Story = {
|
||||
args: { "accessible-label": "Installing update" },
|
||||
};
|
||||
|
||||
/** Next to text that already says what is happening, hide it from screen readers. */
|
||||
export const Decorative: Story = {
|
||||
render: () => html`
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<hac-spinner size="tiny" aria-hidden="true"></hac-spinner>
|
||||
Installing update…
|
||||
</div>
|
||||
`,
|
||||
};
|
||||
|
||||
export const CustomColors: Story = {
|
||||
// The helpers set CSS properties for the whole page, so keep them in a frame
|
||||
// on the docs page
|
||||
parameters: { docs: { story: { inline: false, height: "120px" } } },
|
||||
args: {
|
||||
"--hac-spinner-indicator-color": "#ff9800",
|
||||
"--hac-spinner-track-color": "#ffe0b2",
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
// Stories and the Storybook config. Checked on their own, because in the app's
|
||||
// program the Storybook types crash tsgo's declaration emit.
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "../../node_modules/.cache/typescript/storybook.tsbuildinfo"
|
||||
},
|
||||
"include": ["stories/**/*.ts", ".storybook/*.ts"],
|
||||
"exclude": []
|
||||
}
|
||||
Generated
+1326
-24
File diff suppressed because it is too large.
Load diff
@@ -25,6 +25,7 @@ trustPolicyExclude:
|
||||
allowBuilds:
|
||||
"@tsparticles/engine": false
|
||||
core-js: false
|
||||
esbuild: false
|
||||
rs-module-lexer: false
|
||||
unrs-resolver: false
|
||||
|
||||
|
||||
+1
-1
@@ -158,5 +158,5 @@
|
||||
}
|
||||
},
|
||||
// Exclude e2e tests — they have their own tsconfig that adds node types.
|
||||
"exclude": ["test/e2e", "packages/*/dist"]
|
||||
"exclude": ["test/e2e", "packages/*/dist", "packages/*/stories"]
|
||||
}
|
||||
Reference in new issue
Block a user