Skip to content

Commit f547fd2

Browse files
committed
feat: customize theming
1 parent d4a0c5d commit f547fd2

File tree

5 files changed

+53
-18
lines changed

5 files changed

+53
-18
lines changed

.storybook/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import type { StorybookConfig } from '@storybook/react-vite';
33
const config: StorybookConfig = {
44
stories: ['./stories/**/*.stories.@(ts|tsx)'],
55
addons: ['@storybook/addon-links', '@storybook/addon-docs'],
6+
docs: {
7+
defaultName: 'API',
8+
},
69
framework: {
710
name: '@storybook/react-vite',
811
options: {},

.storybook/manager.css

Lines changed: 0 additions & 5 deletions
This file was deleted.

.storybook/manager.ts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
11
import { addons } from 'storybook/manager-api';
2-
// import { create } from 'storybook/theming';
3-
import './manager.css';
2+
import { create } from 'storybook/theming';
43

4+
// import './manager.css';
5+
6+
const isPreferDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
57
addons.setConfig({
6-
// theme: create({
7-
// base: 'light',
8-
// fontBase: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
9-
// }),
8+
theme: create({
9+
base: isPreferDark ? 'dark' : 'light',
10+
brandTitle: '@tiny-codes/react-easy',
11+
}),
12+
// navSize: 300,
13+
// bottomPanelHeight: 300,
14+
// rightPanelWidth: 300,
15+
// panelPosition: 'bottom',
16+
// enableShortcuts: true,
17+
// showToolbar: true,
18+
// selectedPanel: undefined,
19+
// initialActive: 'sidebar',
20+
// layoutCustomisations: {
21+
// showSidebar(state: State, defaultValue: boolean) {
22+
// return state.storyId === 'landing' ? false : defaultValue;
23+
// },
24+
// showToolbar(state: State, defaultValue: boolean) {
25+
// return state.viewMode === 'docs' ? false : defaultValue;
26+
// },
27+
// },
28+
// sidebar: {
29+
// showRoots: false,
30+
// collapsedRoots: ['other'],
31+
// },
32+
// toolbar: {
33+
// title: { hidden: false },
34+
// zoom: { hidden: false },
35+
// eject: { hidden: false },
36+
// copy: { hidden: false },
37+
// fullscreen: { hidden: false },
38+
// },
1039
});

.storybook/preview.css

Lines changed: 0 additions & 4 deletions
This file was deleted.

.storybook/preview.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ import type { Preview, ReactRenderer } from '@storybook/react-vite';
44
import { App as AntdApp, ConfigProvider as AntdConfigProvider, theme } from 'antd';
55
import enUS from 'antd/es/locale/en_US';
66
import zhCN from 'antd/es/locale/zh_CN';
7+
import { FORCE_RE_RENDER } from 'storybook/internal/core-events';
78
import type { StoryContext, StoryContextForEnhancers } from 'storybook/internal/csf';
9+
import { addons, useStoryContext } from 'storybook/preview-api';
810
import { themes } from 'storybook/theming';
911
import ConfigProvider from '../src/components/ConfigProvider';
12+
import { useRefValue } from '../src/hooks';
1013
import storyI18n from './locales';
1114
import { inferControlFromDocgenType, standardizeJsDocDefaultValue } from './utils/jsdoc';
12-
import './preview.css';
15+
16+
// import './preview.css';
1317

1418
const isPreferDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
1519

@@ -66,10 +70,18 @@ const preview: Preview = {
6670
const bgValue = context.globals?.backgrounds?.value;
6771
const lang = context.globals.lang ?? 'en-US';
6872
const antdLocale = lang === 'zh-CN' ? zhCN : enUS;
73+
const { viewMode } = useStoryContext();
74+
const viewModeRef = useRefValue(viewMode);
75+
6976
useMemo(() => {
7077
if (storyI18n.language !== lang) {
71-
storyI18n.changeLanguage(lang);
72-
(window.top ?? window.parent ?? window).location.reload();
78+
storyI18n.changeLanguage(lang).then(() => {
79+
if (viewModeRef.current === 'docs') {
80+
addons.getChannel().emit(FORCE_RE_RENDER);
81+
} else if (viewModeRef.current === 'story') {
82+
(window.top ?? window.parent ?? window).location.reload();
83+
}
84+
});
7385
}
7486
}, [lang]);
7587

0 commit comments

Comments
 (0)