Skip to content

Commit 8243cd6

Browse files
authored
Merge pull request #43 from rtCamp/fix/build
Fix: Build storybook command and setup gp-pages workflow
2 parents 6df3622 + 6b717ba commit 8243cd6

8 files changed

Lines changed: 96 additions & 74 deletions

File tree

.github/workflows/gh-pages.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Publish To Github Pages
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
CI: false
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
environment:
17+
name: github-pages
18+
url: ${{ steps.deployment.outputs.page_url }}
19+
20+
permissions:
21+
contents: 'read'
22+
id-token: 'write'
23+
pages: 'write'
24+
actions: 'write'
25+
checks: 'write'
26+
deployments: 'write'
27+
strategy:
28+
matrix:
29+
node-version: [18.x]
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v3
34+
- name: Setup Node
35+
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c
36+
with:
37+
node-version-file: '.nvmrc'
38+
cache: npm
39+
- name: Install dependencies
40+
run: |
41+
npm ci
42+
- name: Build Storybook
43+
run: |
44+
npm run build-storybook
45+
46+
- name: Deploy
47+
uses: peaceiris/actions-gh-pages@v4
48+
with:
49+
github_token: ${{ secrets.GITHUB_TOKEN }}
50+
publish_dir: ./storybook-static

.storybook/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const config: StorybookConfig = {
1515
getAbsolutePath("@storybook/addon-docs"),
1616
getAbsolutePath("@storybook/addon-onboarding"),
1717
getAbsolutePath("@storybook/addon-a11y"),
18-
getAbsolutePath("storybook-dark-mode"),
18+
getAbsolutePath('@storybook/addon-themes'),
1919
],
2020
framework: {
2121
name: getAbsolutePath("@storybook/react-vite"),

.storybook/modeDecorator.tsx

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
import { useEffect } from "react";
2-
import { useDarkMode } from "storybook-dark-mode";
3-
4-
const ModeDecorator = (Story) => {
5-
const mode = useDarkMode() ? "dark" : "light";
6-
7-
useEffect(() => {
8-
document.body.className = `${mode} bg-surface-white min-h-screen`;
9-
const docsStory = document.querySelector(".docs-story");
10-
11-
if (docsStory) {
12-
docsStory.className = `${mode} bg-surface-white`;
13-
}
14-
}, [mode]);
15-
16-
return <Story />;
17-
};
18-
19-
export default ModeDecorator;
1+
import { withThemeByClassName } from '@storybook/addon-themes';
2+
3+
export const decorators = [
4+
withThemeByClassName({
5+
themes: {
6+
light: '', // Class name for light mode
7+
dark: 'dark', // Class name for dark mode
8+
},
9+
defaultTheme: 'light', // Default theme
10+
}),
11+
];

.storybook/preview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { Preview } from "@storybook/react-vite";
2+
import {decorators} from "./modeDecorator";
23
import "@rtcamp/frappe-ui-react/theme.css";
3-
import ModeDecorator from "./modeDecorator";
44

55
const preview: Preview = {
6-
decorators: [ModeDecorator],
6+
decorators,
77
parameters: {
88
controls: {
99
matchers: {

package-lock.json

Lines changed: 26 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@storybook/addon-a11y": "^9.1.3",
2929
"@storybook/addon-docs": "^9.1.3",
3030
"@storybook/addon-onboarding": "^9.1.3",
31+
"@storybook/addon-themes": "^9.1.10",
3132
"@storybook/addon-vitest": "^9.1.3",
3233
"@storybook/addons": "^7.6.17",
3334
"@storybook/react-vite": "^9.1.3",

packages/frappe-ui-react/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
"dompurify": "^3.2.6",
3131
"echarts": "^5.6.0",
3232
"feather-icons": "^4.29.2",
33+
"lodash": "^4.17.21",
3334
"lodash-es": "^4.17.21",
35+
"lodash.clonedeep": "^4.5.0",
36+
"lodash.isequal": "^4.5.0",
3437
"lucide-react": "^0.539.0",
3538
"quill-image-resize-module-react": "^3.0.0",
3639
"quill-paste-smart": "^2.0.0",

packages/frappe-ui-react/src/components/sidebar/sidebar.stories.tsx

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback } from "react";
1+
import React from "react";
22
import Sidebar from "./sidebar";
33
import {
44
LucideBell,
@@ -8,17 +8,14 @@ import {
88
LucideClipboard,
99
LucideLink,
1010
LucideMail,
11-
LucideMoon,
1211
LucidePhone,
1312
LucideSettings,
1413
LucideUser,
1514
LucideUserCheck,
1615
LucideUsers,
1716
} from "lucide-react";
1817
import { MemoryRouter } from "react-router";
19-
import { Meta, StoryObj } from "@storybook/react-vite/*";
20-
import { useDarkMode } from "storybook-dark-mode";
21-
import { noop } from "../../utils";
18+
import type { Meta, StoryObj } from "@storybook/react-vite";
2219

2320
const meta: Meta<typeof Sidebar> = {
2421
title: "Components/Sidebar",
@@ -65,11 +62,6 @@ const crmSidebar = {
6562
subtitle: "Jane Doe",
6663
logo: "https://raw.githubusercontent.com/frappe/crm/develop/.github/logo.svg",
6764
menuItems: [
68-
{
69-
label: "Toggle Theme",
70-
icon: <LucideMoon size={16} className="text-ink-gray-6 mr-2" />,
71-
onClick: noop,
72-
},
7365
{
7466
label: "Help",
7567
to: "/help",
@@ -171,42 +163,6 @@ const crmSidebar = {
171163

172164
export const SidebarExample: Story = {
173165
render: () => {
174-
const mode = useDarkMode() ? "dark" : "light";
175-
176-
const toggleTheme = useCallback(() => {
177-
const container = document.getElementById("sidebar-container");
178-
if (!container) return;
179-
180-
const bodyHasDark = mode === "dark";
181-
const containerHasDark = container.classList.contains("dark");
182-
183-
// Sync container's dark class with body
184-
if (bodyHasDark !== containerHasDark) {
185-
if (bodyHasDark) {
186-
container.classList.add("dark");
187-
} else {
188-
container.classList.remove("dark");
189-
}
190-
}
191-
192-
// Toggle theme
193-
if (bodyHasDark) {
194-
const button = parent.document.querySelector(
195-
'[title="Change theme to light mode"]'
196-
) as HTMLButtonElement;
197-
if (button) button.click();
198-
199-
container.classList.remove("dark");
200-
} else {
201-
const button = parent.document.querySelector(
202-
'[title="Change theme to dark mode"]'
203-
) as HTMLButtonElement;
204-
if (button) button.click();
205-
206-
container.classList.add("dark");
207-
}
208-
}, [mode]);
209-
210166
return (
211167
<div
212168
className="flex h-screen w-full flex-col bg-surface-white shadow"
@@ -216,11 +172,6 @@ export const SidebarExample: Story = {
216172
<Sidebar
217173
header={{
218174
...crmSidebar.header,
219-
menuItems: crmSidebar.header.menuItems.map((item) =>
220-
item.label === "Toggle Theme"
221-
? { ...item, onClick: toggleTheme }
222-
: item
223-
),
224175
}}
225176
sections={crmSidebar.sections}
226177
/>

0 commit comments

Comments
 (0)