Skip to content

Commit db460fe

Browse files
feat: add storybook (#51)
* feat: add storybook * docs: add segmented control stories * fix: update ci for storybook * fix: improve storybook theme * docs: add popover stories * docs: add popover and tooltip stories
1 parent 6a86880 commit db460fe

Some content is hidden

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

50 files changed

+8468
-235
lines changed

.github/workflows/format.yml

-30
This file was deleted.

.github/workflows/tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jobs:
2828
- name: Install dependencies
2929
run: pnpm install
3030

31-
- name: Run Build and Tests
32-
run: pnpm run build-test
31+
# - name: Run Build and Tests
32+
# run: pnpm run build-test
3333

3434
env:
3535
CI: true

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ lerna-debug.log
3333
Thumbs.db
3434
# Local Netlify folder
3535
.netlify
36+
storybook-static

netlify.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# repository root netlify.toml
22
[build]
33
base = "/"
4-
publish = "packages/playground-next/dist/public"
5-
command = "pnpm --filter=@codeui/vanilla-extract build && pnpm --filter=@codeui/playground-next build"
4+
publish = "packages/storybook/storybook-static"
5+
command = "pnpm --filter=@codeui/storybook-playground build-storybook"

packages/kit/src/components/RadioList/RadioList.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { baseFieldContainer } from "../TextField/TextField.css";
1111
import { createFieldMessageProps } from "../Field/FieldMessage/createFieldMessageProps";
1212
import * as styles from "./Radio.css";
1313

14-
type RadioListProps = RadioGroup.RadioGroupRootProps &
14+
export type RadioListProps = RadioGroup.RadioGroupRootProps &
1515
BaseFieldProps &
1616
FieldWithErrorMessageSupport & { label?: JSXElement; description?: string };
1717

packages/kit/src/components/SegmentedControl/SegmentedControl.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ export function SegmentedControl(props: SegmentedControlProps) {
7070
}, 0);
7171

7272
onMount(() => {
73+
if (!listRef) {
74+
return;
75+
}
7376
const resizeObserver = new ResizeObserver(handleListResize);
7477
resizeObserver.observe(listRef);
7578
});

packages/kit/src/index.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export {
3535
export { Popover, PopoverTrigger, PopoverContent } from "./components/Popover/Popover";
3636
export { Select } from "./components/Select/Select";
3737
export { createSelectOptions } from "./components/Select/createSelectValue";
38+
3839
export { RadioList, RadioListItem } from "./components/RadioList/RadioList";
40+
export type { RadioListProps } from "./components/RadioList/RadioList";
3941

4042
export { Link } from "./components/Link/Link";
4143

@@ -60,3 +62,5 @@ export {
6062
layoutVars,
6163
responsiveStyle,
6264
} from "./foundation";
65+
66+
export { As } from "@kobalte/core";

packages/storybook/.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { globalStyle } from "@vanilla-extract/css";
2+
import { themeVars } from "@codeui/kit";
3+
4+
globalStyle("[data-cui-theme=dark] html, body", {
5+
background: themeVars.accent1,
6+
color: themeVars.foreground,
7+
});
8+
9+
globalStyle("[data-cui-theme=light] html, body", {
10+
background: themeVars.background,
11+
color: themeVars.foreground,
12+
});
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@200;300;400;500;600;700;800&display=swap');
2+
3+
html, body {
4+
font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
5+
}
6+
7+
.multipleItemsContainer {
8+
display: flex;
9+
flex-direction: column;
10+
gap: 2rem;
11+
}
12+
13+
.itemsContainer {
14+
display: flex;
15+
align-items: center;
16+
gap: 2rem;
17+
}
18+

packages/storybook/.storybook/main.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { StorybookConfig } from "storybook-solidjs-vite";
2+
3+
import { join, dirname } from "path";
4+
5+
/**
6+
* This function is used to resolve the absolute path of a package.
7+
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
8+
*/
9+
function getAbsolutePath(value: string): any {
10+
return dirname(require.resolve(join(value, "package.json")));
11+
}
12+
13+
const config: StorybookConfig = {
14+
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
15+
addons: [
16+
getAbsolutePath("@storybook/addon-links"),
17+
getAbsolutePath("@storybook/addon-essentials"),
18+
getAbsolutePath("@storybook/addon-interactions"),
19+
getAbsolutePath("storybook-dark-mode"),
20+
],
21+
framework: {
22+
name: getAbsolutePath("storybook-solidjs-vite"),
23+
options: {},
24+
},
25+
docs: {
26+
autodocs: "tag",
27+
},
28+
};
29+
30+
export default config;
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { Preview } from "storybook-solidjs";
2+
import { themes, ThemeVars } from "@storybook/theming";
3+
import { DARK_MODE_EVENT_NAME, useDarkMode } from "storybook-dark-mode";
4+
import { addons } from "@storybook/addons";
5+
import { Component, createEffect, createSignal, FlowProps } from "solid-js";
6+
import "./reset.css";
7+
import "./global.css";
8+
import "./global-ve.css";
9+
import { DocsContainer, DocsContainerProps } from "@storybook/blocks";
10+
import { themeVars } from "@codeui/kit";
11+
12+
function ThemeWrapper(props: FlowProps) {
13+
const [darkMode, setDarkMode] = createSignal<boolean>(true);
14+
const channel = addons.getChannel();
15+
channel.on(DARK_MODE_EVENT_NAME, setDarkMode);
16+
17+
createEffect(() => {
18+
document.documentElement.setAttribute(
19+
"data-cui-theme",
20+
darkMode() ? "dark" : "light",
21+
);
22+
});
23+
return <div>{props.children}</div>;
24+
}
25+
26+
export const decorators = [
27+
(Story: () => any) => {
28+
return <ThemeWrapper>{Story()}</ThemeWrapper>;
29+
},
30+
];
31+
32+
const darkTheme: ThemeVars = {
33+
...themes.dark,
34+
appBg: "#111",
35+
barBg: "#111",
36+
appContentBg: "#050505",
37+
};
38+
39+
const lightTheme: ThemeVars = {
40+
...themes.normal,
41+
};
42+
43+
const preview: Preview = {
44+
parameters: {
45+
actions: { argTypesRegex: "^on[A-Z].*" },
46+
decorators: decorators,
47+
darkMode: {
48+
current: "dark",
49+
dark: darkTheme,
50+
light: lightTheme,
51+
},
52+
controls: {
53+
matchers: {
54+
color: /(background|color)$/i,
55+
date: /Date$/i,
56+
},
57+
},
58+
docs: {
59+
container: (props: DocsContainerProps) => {
60+
const dark = useDarkMode();
61+
return <DocsContainer {...props} theme={dark ? darkTheme : lightTheme} />;
62+
},
63+
},
64+
},
65+
};
66+
67+
export default preview;

0 commit comments

Comments
 (0)