Skip to content

Commit 5560468

Browse files
committed
feat(storybook): custom properties panel
1 parent bcabedc commit 5560468

File tree

114 files changed

+2232
-383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+2232
-383
lines changed

.changeset/eleven-plants-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@spectrum-css/generator": patch
3+
---
4+
5+
Update story templates to include the cssprops imports

.changeset/new-bulldogs-add.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@spectrum-css/preview": minor
3+
---
4+
5+
New feature: Custom properties panel added to the development preview showing a list of modifiable custom properties as loaded from the metadata/metadata.json resource in each component.

.eslintrc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
"parserOptions": {
99
"sourceType": "module"
1010
},
11+
"settings": {
12+
"react": {
13+
"version": "detect"
14+
}
15+
},
1116
"extends": "eslint:recommended",
1217
"rules": {
1318
"brace-style": ["warn", "stroustrup", { "allowSingleLine": true }],
@@ -17,7 +22,8 @@
1722
"no-console": ["warn", { "allow": ["warn", "error"] }],
1823
"quotes": ["warn", "double"],
1924
"semi": ["warn", "always"],
20-
"space-before-blocks": ["warn", "always"]
25+
"space-before-blocks": ["warn", "always"],
26+
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }]
2127
},
2228
"overrides": [
2329
{
@@ -172,8 +178,10 @@
172178
"files": [
173179
"components/*/stories/*.js",
174180
".storybook/*.js",
175-
".storybook/**/*.js"
181+
".storybook/**/*.js",
182+
"plugins/storybook-addon-*/*.js"
176183
],
184+
"extends": ["plugin:react/recommended", "plugin:react/jsx-runtime"],
177185
"parserOptions": {
178186
"ecmaVersion": "latest",
179187
"sourceType": "module",

.storybook/decorators/utilities.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,12 @@ export const renderContent = (content = [], {
556556
if (content.length === 0) return nothing;
557557

558558
return html`
559-
${content.map((c) => {
559+
${content.map((c, idx) => {
560560
if (typeof c === "undefined") return nothing;
561561
562562
/* If the content is an object (but not a lit object), we need to merge the object with the template */
563563
if (typeof c !== "string" && (typeof c === "object" && !c._$litType$)) {
564-
return callback({ ...args, ...c }, context);
564+
return callback({ ...args, ...c, idx }, context);
565565
}
566566
567567
if (typeof c === "function") {

.storybook/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export default {
6363
name: "@storybook/addon-actions",
6464
options: {},
6565
},
66+
// https://github.com/ljcl/storybook-addon-cssprops
67+
"@ljcl/storybook-addon-cssprops",
6668
// https://www.npmjs.com/package/@whitespace/storybook-addon-html
6769
"@whitespace/storybook-addon-html",
6870
// https://github.com/storybookjs/storybook/tree/next/code/addons/a11y

.storybook/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@babel/core": "^7.28.0",
5050
"@chromatic-com/storybook": "^3.2.7",
5151
"@etchteam/storybook-addon-status": "^5.0.0",
52+
"@ljcl/storybook-addon-cssprops": "4.0.0",
5253
"@storybook/addon-a11y": "8.4.7",
5354
"@storybook/addon-actions": "8.4.7",
5455
"@storybook/addon-designs": "^8.2.1",
@@ -66,7 +67,7 @@
6667
"@storybook/web-components-vite": "8.4.7",
6768
"@whitespace/storybook-addon-html": "^7.0.0",
6869
"chromatic": "^13.1.2",
69-
"lit": "^3.3.1",
70+
"lit": "^3.3.0",
7071
"lodash-es": "^4.17.21",
7172
"npm-registry-fetch": "^18.0.2",
7273
"postcss": "^8.5.6",

components/accordion/index.css

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
--spectrum-accordion-item-content-line-height: var(--spectrum-line-height-100);
4545

4646
/* Colors */
47-
--spectrum-accordion-background-color-default: rgba(var(--spectrum-gray-900-rgb), var(--spectrum-background-opacity-default));
48-
--spectrum-accordion-background-color-hover: rgba(var(--spectrum-gray-900-rgb), var(--spectrum-background-opacity-hover));
49-
--spectrum-accordion-background-color-down: rgba(var(--spectrum-gray-900-rgb), var(--spectrum-background-opacity-down));
50-
--spectrum-accordion-background-color-key-focus: rgba(var(--spectrum-gray-900-rgb), var(--spectrum-background-opacity-key-focus));
47+
--spectrum-accordion-background-color-default: rgb(var(--spectrum-gray-900-rgb), var(--spectrum-background-opacity-default));
48+
--spectrum-accordion-background-color-hover: rgb(var(--spectrum-gray-900-rgb), var(--spectrum-background-opacity-hover));
49+
--spectrum-accordion-background-color-down: rgb(var(--spectrum-gray-900-rgb), var(--spectrum-background-opacity-down));
50+
--spectrum-accordion-background-color-key-focus: rgb(var(--spectrum-gray-900-rgb), var(--spectrum-background-opacity-key-focus));
5151

5252
/* Label */
5353
--spectrum-accordion-item-header-color-default: var(--spectrum-neutral-content-color-default);
@@ -72,6 +72,7 @@
7272
&:lang(ja),
7373
&:lang(zh),
7474
&:lang(ko) {
75+
/* @description When the language is CJK, update line-height values to prevent cut off diacritics */
7576
--spectrum-accordion-item-header-line-height: var(--spectrum-cjk-line-height-100);
7677
--spectrum-accordion-item-content-line-height: var(--spectrum-cjk-line-height-100);
7778
}

components/accordion/stories/accordion.stories.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { Sizes } from "@spectrum-css/preview/decorators";
33
import { disableDefaultModes } from "@spectrum-css/preview/modes";
44
import { size } from "@spectrum-css/preview/types";
55
import { Template as Typography } from "@spectrum-css/typography/stories/template.js";
6-
import metadata from "../dist/metadata.json";
7-
import packageJson from "../package.json";
86
import { AccordionGroup } from "./accordion.test.js";
97
import { Template } from "./template.js";
108

9+
// Local assets to render the component styles and structure
10+
import metadata from "../dist/metadata.json";
11+
import packageJson from "../package.json";
12+
1113
/**
1214
* The accordion element contains a list of items that can be expanded or collapsed to reveal additional content or information associated with each item. There can be zero expanded items, exactly one expanded item, or more than one item expanded at a time, depending on the configuration. This list of items is defined by child accordion item elements.
1315
*
@@ -68,6 +70,18 @@ export default {
6870
},
6971
packageJson,
7072
metadata,
73+
cssprops: {
74+
...metadata.modifiers.reduce((acc, modifier) => {
75+
const name = modifier.replace(/^--/, "");
76+
acc[name] = {
77+
category: "Modifier",
78+
description: "",
79+
value: undefined,
80+
control: name.includes("color") ? "color" : "text",
81+
};
82+
return acc;
83+
}, {}),
84+
},
7185
},
7286
};
7387

components/actionbar/stories/actionbar.stories.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { default as CloseButton } from "@spectrum-css/closebutton/stories/closeb
33
import { default as Popover } from "@spectrum-css/popover/stories/popover.stories.js";
44
import { disableDefaultModes } from "@spectrum-css/preview/modes";
55
import { isEmphasized, isOpen } from "@spectrum-css/preview/types";
6-
import metadata from "../dist/metadata.json";
7-
import packageJson from "../package.json";
86
import { ActionBarGroup } from "./actionbar.test.js";
97
import { BehavioralTemplate } from "./template.js";
108

9+
// Local assets to render the component styles and structure
10+
import metadata from "../dist/metadata.json";
11+
import packageJson from "../package.json";
12+
1113
/**
1214
* The action bar component is a floating full width bar that appears upon selection. Action bars are used for single and bulk selection patterns, when a user needs to perform actions on either a single or multiple items at the same time.
1315
*
@@ -72,6 +74,18 @@ export default {
7274
},
7375
packageJson,
7476
metadata,
77+
cssprops: {
78+
...metadata.modifiers.reduce((acc, modifier) => {
79+
const name = modifier.replace(/^--/, "");
80+
acc[name] = {
81+
category: "Modifier",
82+
description: "",
83+
value: undefined,
84+
control: name.includes("color") ? "color" : "text",
85+
};
86+
return acc;
87+
}, {}),
88+
},
7589
},
7690
};
7791

components/actionbar/stories/template.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { Container } from "@spectrum-css/preview/decorators";
21
import { Template as ActionGroup } from "@spectrum-css/actiongroup/stories/template.js";
32
import { Template as CloseButton } from "@spectrum-css/closebutton/stories/template.js";
43
import { Template as FieldLabel } from "@spectrum-css/fieldlabel/stories/template.js";
54
import { Template as Popover } from "@spectrum-css/popover/stories/template.js";
5+
import { Container, getRandomId } from "@spectrum-css/preview/decorators";
66
import { html } from "lit";
77
import { classMap } from "lit/directives/class-map.js";
8+
import { ifDefined } from "lit/directives/if-defined.js";
89
import { styleMap } from "lit/directives/style-map.js";
910

1011
import "../index.css";
@@ -14,6 +15,7 @@ import "../themes/express.css";
1415

1516
export const Template = ({
1617
rootClass = "spectrum-ActionBar",
18+
id = getRandomId("action-bar"),
1719
size = "m",
1820
isOpen = true,
1921
isEmphasized = false,
@@ -36,6 +38,7 @@ export const Template = ({
3638
"is-open": isOpen,
3739
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
3840
})}
41+
id=${ifDefined(id)}
3942
style=${styleMap(customStyles)}
4043
>
4144
${Popover({

0 commit comments

Comments
 (0)