Skip to content

Commit 674eb63

Browse files
committed
docs: switch to CSF Next
1 parent 94f1861 commit 674eb63

File tree

12 files changed

+127
-42
lines changed

12 files changed

+127
-42
lines changed

packages/storybook/.storybook/main.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { StorybookConfig } from "@storybook/react-vite";
1+
import { defineMain } from "@storybook/react-vite/node";
22
import type { UserConfig } from "vite";
33

4-
const config: StorybookConfig = {
4+
export default defineMain({
55
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
66
addons: [
77
"@storybook/addon-docs",
@@ -29,5 +29,4 @@ const config: StorybookConfig = {
2929
],
3030
} satisfies UserConfig);
3131
},
32-
};
33-
export default config;
32+
});

packages/storybook/.storybook/preview.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
import type { Preview } from "@storybook/react-vite";
2-
3-
import "@scouterna/ui-webc/dist/ui-webc/ui-webc.css";
4-
51
import { setCustomElementsManifest } from "@stencil/storybook-plugin";
2+
import { definePreview } from "@storybook/react-vite";
63
import kebabCase from "lodash.kebabcase";
74
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
5+
import addonDocs from "@storybook/addon-docs";
6+
import addonA11y from "@storybook/addon-a11y";
7+
import addonVitest from "@storybook/addon-vitest";
8+
9+
// This import isn't very nice, but @stencil/storybook-plugin doesn't expose this functionality
910
import { parameters } from "../node_modules/@stencil/storybook-plugin/dist/entry-preview-argtypes";
1011

12+
// Include styles to have our web components render correctly
13+
import "@scouterna/ui-webc/dist/ui-webc/ui-webc.css";
14+
15+
// Register the custom elements manifest for Stencil integration
1116
setCustomElementsManifest(customElements);
1217

18+
// Utility for converting our React component display names to web component tag names
1319
const getComponentWebcName = (component: unknown): string | null => {
1420
if (
1521
component &&
@@ -23,9 +29,11 @@ const getComponentWebcName = (component: unknown): string | null => {
2329
return null;
2430
};
2531

26-
const preview: Preview = {
32+
export default definePreview({
33+
addons: [addonDocs(), addonA11y(), addonVitest()],
2734
parameters: {
2835
docs: {
36+
// Automatically extract argTypes and component descriptions from web components
2937
extractArgTypes: (component: unknown) => {
3038
const webcName = getComponentWebcName(component);
3139
if (!webcName) return null;
@@ -36,7 +44,8 @@ const preview: Preview = {
3644
if (!webcName) return null;
3745
return parameters.docs.extractComponentDescription(webcName);
3846
},
39-
},
47+
// biome-ignore lint/suspicious/noExplicitAny: We need to cast becuase these are internal APIs.
48+
} as any,
4049
actions: {
4150
argTypesRegex: "^onScout.*",
4251
},
@@ -48,11 +57,9 @@ const preview: Preview = {
4857
},
4958
options: {
5059
storySort: {
51-
order: ["Basics", "Jamboree26"],
60+
order: ["Basics", "Jamboree26", ["Bottom Bar", "Bottom Bar Item"]],
5261
},
5362
},
5463
},
5564
tags: ["autodocs"],
56-
};
57-
58-
export default preview;
65+
});

packages/storybook/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
"private": true,
44
"version": "0.0.0",
55
"type": "module",
6+
"imports": {
7+
"#*": [
8+
"./*",
9+
"./*.ts",
10+
"./*.tsx"
11+
]
12+
},
613
"scripts": {
714
"build": "storybook build",
815
"dev": "storybook dev -p 6006 --no-open"
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
import { ScoutBottomBarItem } from "@scouterna/ui-react";
2-
3-
import type { Meta, StoryObj } from "@storybook/react-vite";
4-
52
import BonfireIcon from "iconoir/icons/bonfire.svg?raw";
3+
import preview from "#.storybook/preview";
64

7-
const meta = {
5+
const meta = preview.meta({
86
title: "Jamboree26/Bottom Bar Item",
97
component: ScoutBottomBarItem,
108
parameters: {
119
layout: "centered",
1210
},
13-
} satisfies Meta<typeof ScoutBottomBarItem>;
11+
});
1412

1513
export default meta;
16-
type Story = StoryObj<typeof meta>;
1714

18-
export const BottomBarItem: Story = {
15+
export const BottomBarItem = meta.story({
1916
args: {
2017
icon: BonfireIcon,
2118
label: "Activities",
@@ -25,4 +22,4 @@ export const BottomBarItem: Story = {
2522
<ScoutBottomBarItem {...args} />
2623
</div>
2724
),
28-
};
25+
});
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
import { ScoutBottomBar, ScoutBottomBarItem } from "@scouterna/ui-react";
2-
3-
import type { Meta, StoryObj } from "@storybook/react-vite";
4-
52
import BonfireIcon from "iconoir/icons/bonfire.svg?raw";
63
import CalendarIcon from "iconoir/icons/calendar.svg?raw";
74
import MapIcon from "iconoir/icons/map.svg?raw";
85
import MoreHorizIcon from "iconoir/icons/more-horiz.svg?raw";
6+
import preview from "#.storybook/preview";
97

10-
const meta = {
8+
const meta = preview.meta({
119
title: "Jamboree26/Bottom Bar",
1210
component: ScoutBottomBar,
1311
parameters: {
1412
layout: "centered",
1513
},
16-
} satisfies Meta<typeof ScoutBottomBar>;
14+
});
1715

1816
export default meta;
19-
type Story = StoryObj<typeof meta>;
2017

21-
export const BasicExample: Story = {
18+
export const BasicExample = meta.story({
2219
args: {},
2320
render: (args) => (
2421
<div style={{ maxWidth: "24rem", width: "100vw" }}>
@@ -30,4 +27,4 @@ export const BasicExample: Story = {
3027
</ScoutBottomBar>
3128
</div>
3229
),
33-
};
30+
});
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
import { ScoutButton } from "@scouterna/ui-react";
2-
3-
import type { Meta, StoryObj } from "@storybook/react-vite";
2+
import preview from "#.storybook/preview";
43

54
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
6-
const meta = {
5+
const meta = preview.meta({
76
title: "Basics/Button",
87
component: ScoutButton,
98
parameters: {
109
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
1110
layout: "centered",
1211
},
13-
} satisfies Meta<typeof ScoutButton>;
12+
});
1413

1514
export default meta;
16-
type Story = StoryObj<typeof meta>;
1715

1816
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
19-
export const Primary: Story = {
17+
export const Primary = meta.story({
2018
args: {
2119
variant: "primary",
2220
},
2321
render: (args) => <ScoutButton {...args}>Hello, World!</ScoutButton>,
24-
};
22+
});

packages/ui-react/lib/components/stencil-generated/components.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ export const ScoutBottomBar: StencilReactComponent<ScoutBottomBarElement, ScoutB
2525
defineCustomElement: defineScoutBottomBar
2626
});
2727

28-
export type ScoutBottomBarItemEvents = NonNullable<unknown>;
28+
export type ScoutBottomBarItemEvents = { onScoutClick: EventName<CustomEvent<void>> };
2929

3030
export const ScoutBottomBarItem: StencilReactComponent<ScoutBottomBarItemElement, ScoutBottomBarItemEvents> = /*@__PURE__*/ createComponent<ScoutBottomBarItemElement, ScoutBottomBarItemEvents>({
3131
tagName: 'scout-bottom-bar-item',
3232
elementClass: ScoutBottomBarItemElement,
3333
// @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.
3434
react: React,
35-
events: {} as ScoutBottomBarItemEvents,
35+
events: { onScoutClick: 'scoutClick' } as ScoutBottomBarItemEvents,
3636
defineCustomElement: defineScoutBottomBarItem
3737
});
3838

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ import { Variant } from "./components/button/button";
1010
export { ItemType } from "./components/bottom-bar-item/bottom-bar-item";
1111
export { Variant } from "./components/button/button";
1212
export namespace Components {
13+
/**
14+
* The bottom bar component is used in the Jamboree26 app to provide
15+
* navigation at the bottom of the screen.
16+
*/
1317
interface ScoutBottomBar {
1418
}
19+
/**
20+
* A bottom bar item used within the bottom bar for navigation. Should not be
21+
* used outside of a bottom bar.
22+
*/
1523
interface ScoutBottomBarItem {
1624
"active"?: boolean;
1725
"href"?: string;
@@ -37,18 +45,41 @@ export namespace Components {
3745
"variant": Variant;
3846
}
3947
}
48+
export interface ScoutBottomBarItemCustomEvent<T> extends CustomEvent<T> {
49+
detail: T;
50+
target: HTMLScoutBottomBarItemElement;
51+
}
4052
export interface ScoutButtonCustomEvent<T> extends CustomEvent<T> {
4153
detail: T;
4254
target: HTMLScoutButtonElement;
4355
}
4456
declare global {
57+
/**
58+
* The bottom bar component is used in the Jamboree26 app to provide
59+
* navigation at the bottom of the screen.
60+
*/
4561
interface HTMLScoutBottomBarElement extends Components.ScoutBottomBar, HTMLStencilElement {
4662
}
4763
var HTMLScoutBottomBarElement: {
4864
prototype: HTMLScoutBottomBarElement;
4965
new (): HTMLScoutBottomBarElement;
5066
};
67+
interface HTMLScoutBottomBarItemElementEventMap {
68+
"scoutClick": void;
69+
}
70+
/**
71+
* A bottom bar item used within the bottom bar for navigation. Should not be
72+
* used outside of a bottom bar.
73+
*/
5174
interface HTMLScoutBottomBarItemElement extends Components.ScoutBottomBarItem, HTMLStencilElement {
75+
addEventListener<K extends keyof HTMLScoutBottomBarItemElementEventMap>(type: K, listener: (this: HTMLScoutBottomBarItemElement, ev: ScoutBottomBarItemCustomEvent<HTMLScoutBottomBarItemElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
76+
addEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
77+
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
78+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
79+
removeEventListener<K extends keyof HTMLScoutBottomBarItemElementEventMap>(type: K, listener: (this: HTMLScoutBottomBarItemElement, ev: ScoutBottomBarItemCustomEvent<HTMLScoutBottomBarItemElementEventMap[K]>) => any, options?: boolean | EventListenerOptions): void;
80+
removeEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
81+
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
82+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
5283
}
5384
var HTMLScoutBottomBarItemElement: {
5485
prototype: HTMLScoutBottomBarItemElement;
@@ -81,13 +112,22 @@ declare global {
81112
}
82113
}
83114
declare namespace LocalJSX {
115+
/**
116+
* The bottom bar component is used in the Jamboree26 app to provide
117+
* navigation at the bottom of the screen.
118+
*/
84119
interface ScoutBottomBar {
85120
}
121+
/**
122+
* A bottom bar item used within the bottom bar for navigation. Should not be
123+
* used outside of a bottom bar.
124+
*/
86125
interface ScoutBottomBarItem {
87126
"active"?: boolean;
88127
"href"?: string;
89128
"icon": string;
90129
"label": string;
130+
"onScoutClick"?: (event: ScoutBottomBarItemCustomEvent<void>) => void;
91131
/**
92132
* @default "button"
93133
*/
@@ -118,7 +158,15 @@ export { LocalJSX as JSX };
118158
declare module "@stencil/core" {
119159
export namespace JSX {
120160
interface IntrinsicElements {
161+
/**
162+
* The bottom bar component is used in the Jamboree26 app to provide
163+
* navigation at the bottom of the screen.
164+
*/
121165
"scout-bottom-bar": LocalJSX.ScoutBottomBar & JSXBase.HTMLAttributes<HTMLScoutBottomBarElement>;
166+
/**
167+
* A bottom bar item used within the bottom bar for navigation. Should not be
168+
* used outside of a bottom bar.
169+
*/
122170
"scout-bottom-bar-item": LocalJSX.ScoutBottomBarItem & JSXBase.HTMLAttributes<HTMLScoutBottomBarItemElement>;
123171
/**
124172
* A simple button component.

packages/ui-webc/src/components/bottom-bar-item/bottom-bar-item.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
import { Component, h, Prop } from "@stencil/core";
1+
import { Component, Event, type EventEmitter, h, Prop } from "@stencil/core";
22
import clsx from "clsx";
33

44
export type ItemType = "button" | "link";
55

6+
/**
7+
* A bottom bar item used within the bottom bar for navigation. Should not be
8+
* used outside of a bottom bar.
9+
*/
610
@Component({
711
tag: "scout-bottom-bar-item",
812
styleUrl: "bottom-bar-item.css",
@@ -16,6 +20,9 @@ export class BottomBarItem {
1620
@Prop() label!: string;
1721
@Prop() active?: boolean;
1822

23+
@Event()
24+
scoutClick: EventEmitter<void>;
25+
1926
render() {
2027
const Tag = this.type === "link" ? "a" : "button";
2128

@@ -27,7 +34,11 @@ export class BottomBarItem {
2734
: {};
2835

2936
return (
30-
<Tag class={clsx("button", this.active && "active")} {...props}>
37+
<Tag
38+
class={clsx("button", this.active && "active")}
39+
onClick={() => this.scoutClick.emit()}
40+
{...props}
41+
>
3142
<span class="icon" innerHTML={this.icon} />
3243
<span class="label">{this.label}</span>
3344
</Tag>

packages/ui-webc/src/components/bottom-bar-item/readme.md

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

77

8+
## Overview
9+
10+
A bottom bar item used within the bottom bar for navigation. Should not be
11+
used outside of a bottom bar.
12+
813
## Properties
914

1015
| Property | Attribute | Description | Type | Default |
@@ -16,6 +21,13 @@
1621
| `type` | `type` | | `"button" \| "link"` | `"button"` |
1722

1823

24+
## Events
25+
26+
| Event | Description | Type |
27+
| ------------ | ----------- | ------------------- |
28+
| `scoutClick` | | `CustomEvent<void>` |
29+
30+
1931
----------------------------------------------
2032

2133
*Built with [StencilJS](https://stenciljs.com/)*

0 commit comments

Comments
 (0)