Skip to content

Commit cd17cbf

Browse files
committed
chore: automatically detect component props and description
1 parent 221cb0e commit cd17cbf

File tree

9 files changed

+249
-70
lines changed

9 files changed

+249
-70
lines changed

packages/storybook/.storybook/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { UserConfig } from "vite";
44
const config: StorybookConfig = {
55
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
66
addons: [
7-
"@chromatic-com/storybook",
87
"@storybook/addon-docs",
98
"@storybook/addon-a11y",
109
"@storybook/addon-vitest",

packages/storybook/.storybook/preview.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,56 @@ import type { Preview } from "@storybook/react-vite";
22

33
import "@scouterna/ui-webc/dist/ui-webc/ui-webc.css";
44

5+
import { setCustomElementsManifest } from "@stencil/storybook-plugin";
6+
import kebabCase from "lodash.kebabcase";
7+
import customElements from "../../ui-webc/dist/custom-elements.json";
8+
// This export isn't very nice, but @stencil/storybook-plugin doesn't expose this functionality
9+
import { parameters } from "../node_modules/@stencil/storybook-plugin/dist/entry-preview-argtypes";
10+
11+
setCustomElementsManifest(customElements);
12+
13+
const getComponentWebcName = (component: unknown): string | null => {
14+
if (
15+
component &&
16+
typeof component === "object" &&
17+
"displayName" in component &&
18+
typeof component.displayName === "string"
19+
) {
20+
return `scout-${kebabCase(component.displayName)}`;
21+
}
22+
23+
return null;
24+
};
25+
526
const preview: Preview = {
627
parameters: {
28+
docs: {
29+
extractArgTypes: (component: unknown) => {
30+
const webcName = getComponentWebcName(component);
31+
if (!webcName) return null;
32+
return parameters.docs.extractArgTypes(webcName);
33+
},
34+
extractComponentDescription: (component: unknown) => {
35+
const webcName = getComponentWebcName(component);
36+
if (!webcName) return null;
37+
return parameters.docs.extractComponentDescription(webcName);
38+
},
39+
},
740
controls: {
841
matchers: {
942
color: /(background|color)$/i,
1043
date: /Date$/i,
1144
},
1245
},
13-
46+
actions: { argTypesRegex: "^onScout.*" },
1447
a11y: {
1548
// 'todo' - show a11y violations in the test UI only
1649
// 'error' - fail CI on a11y violations
1750
// 'off' - skip a11y checks entirely
1851
test: "todo",
1952
},
2053
},
54+
tags: ["autodocs"],
2155
};
2256

2357
export default preview;

packages/storybook/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,36 @@
1212
"build-storybook": "storybook build"
1313
},
1414
"dependencies": {
15+
"lodash.kebabcase": "^4.1.1",
1516
"react": "^19.2.0",
1617
"react-dom": "^19.2.0"
1718
},
1819
"devDependencies": {
19-
"@chromatic-com/storybook": "^4.1.3",
2020
"@eslint/js": "^9.39.1",
21-
"@scouterna/ui-webc": "workspace:^",
2221
"@scouterna/ui-react": "workspace:^",
22+
"@scouterna/ui-webc": "workspace:^",
23+
"@stencil/storybook-plugin": "^0.5.6",
2324
"@storybook/addon-a11y": "^10.0.8",
2425
"@storybook/addon-docs": "^10.0.8",
2526
"@storybook/addon-vitest": "^10.0.8",
2627
"@storybook/react-vite": "^10.0.8",
28+
"@types/lodash.kebabcase": "^4.1.9",
2729
"@types/node": "^24.10.1",
2830
"@types/react": "^19.2.5",
2931
"@types/react-dom": "^19.2.3",
3032
"@vitejs/plugin-react": "^5.1.1",
33+
"@vitest/browser-playwright": "^4.0.12",
34+
"@vitest/coverage-v8": "^4.0.12",
3135
"eslint": "^9.39.1",
3236
"eslint-plugin-react-hooks": "^7.0.1",
3337
"eslint-plugin-react-refresh": "^0.4.24",
3438
"eslint-plugin-storybook": "^10.0.8",
3539
"globals": "^16.5.0",
40+
"playwright": "^1.56.1",
3641
"storybook": "^10.0.8",
3742
"typescript": "~5.9.3",
3843
"typescript-eslint": "^8.46.4",
3944
"vite": "^7.2.4",
40-
"vitest": "^4.0.12",
41-
"playwright": "^1.56.1",
42-
"@vitest/browser-playwright": "^4.0.12",
43-
"@vitest/coverage-v8": "^4.0.12"
45+
"vitest": "^4.0.12"
4446
}
4547
}

packages/storybook/src/stories/button.stories.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { ScoutButton } from "@scouterna/ui-react";
22

33
import type { Meta, StoryObj } from "@storybook/react-vite";
4-
import { fn } from "storybook/test";
5-
// import { ScoutButton } from "../../../ui-react/lib/components/stencil-generated/components";
64

75
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
86
const meta = {
@@ -12,10 +10,6 @@ const meta = {
1210
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
1311
layout: "centered",
1412
},
15-
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
16-
tags: ["autodocs"],
17-
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#story-args
18-
args: { onClick: fn() },
1913
} satisfies Meta<typeof ScoutButton>;
2014

2115
export default meta;

packages/ui-webc/src/components.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export namespace Components {
2222
*/
2323
"type": ItemType;
2424
}
25+
/**
26+
* A simple button component.
27+
*/
2528
interface ScoutButton {
2629
"icon"?: string;
2730
/**
@@ -54,6 +57,9 @@ declare global {
5457
interface HTMLScoutButtonElementEventMap {
5558
"scoutClick": void;
5659
}
60+
/**
61+
* A simple button component.
62+
*/
5763
interface HTMLScoutButtonElement extends Components.ScoutButton, HTMLStencilElement {
5864
addEventListener<K extends keyof HTMLScoutButtonElementEventMap>(type: K, listener: (this: HTMLScoutButtonElement, ev: ScoutButtonCustomEvent<HTMLScoutButtonElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
5965
addEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
@@ -87,6 +93,9 @@ declare namespace LocalJSX {
8793
*/
8894
"type"?: ItemType;
8995
}
96+
/**
97+
* A simple button component.
98+
*/
9099
interface ScoutButton {
91100
"icon"?: string;
92101
"onScoutClick"?: (event: ScoutButtonCustomEvent<void>) => void;
@@ -111,6 +120,9 @@ declare module "@stencil/core" {
111120
interface IntrinsicElements {
112121
"scout-bottom-bar": LocalJSX.ScoutBottomBar & JSXBase.HTMLAttributes<HTMLScoutBottomBarElement>;
113122
"scout-bottom-bar-item": LocalJSX.ScoutBottomBarItem & JSXBase.HTMLAttributes<HTMLScoutBottomBarItemElement>;
123+
/**
124+
* A simple button component.
125+
*/
114126
"scout-button": LocalJSX.ScoutButton & JSXBase.HTMLAttributes<HTMLScoutButtonElement>;
115127
}
116128
}

packages/ui-webc/src/components/button/button.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { Component, Event, type EventEmitter, h, Prop } from "@stencil/core";
22

33
export type Variant = "primary" | "outlined" | "text" | "caution" | "danger";
44

5+
/**
6+
* A simple button component.
7+
*/
58
@Component({
69
tag: "scout-button",
710
styleUrl: "button.css",

packages/ui-webc/src/components/button/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
<!-- Auto Generated Below -->
66

77

8+
## Overview
9+
10+
A simple button component.
11+
812
## Properties
913

1014
| Property | Attribute | Description | Type | Default |

packages/ui-webc/stencil.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export const config: Config = {
3030
type: "www",
3131
serviceWorker: null, // disable service workers
3232
},
33+
{
34+
type: "docs-json",
35+
file: "dist/custom-elements.json",
36+
},
3337
],
3438
testing: {
3539
browserHeadless: "shell",

0 commit comments

Comments
 (0)