Skip to content

Commit 8657a88

Browse files
authored
refactor: reinternalize slot components (#206)
1 parent a5e3ab3 commit 8657a88

File tree

141 files changed

+208468
-117
lines changed

Some content is hidden

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

141 files changed

+208468
-117
lines changed

.github/workflows/storybook.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Deploy Storybook
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
10+
jobs:
11+
build:
12+
name: Build Storybook
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-node@v4
17+
- run: yarn
18+
- name: Build Storybook
19+
run: yarn build-storybook
20+
- uses: actions/upload-artifact@v4
21+
with:
22+
name: storybook-static
23+
path: storybook-static
24+
25+
deploy:
26+
name: Deploy Storybook
27+
runs-on: ubuntu-latest
28+
needs: build
29+
if: github.event_name == 'push'
30+
steps:
31+
- name: Download Storybook artifact
32+
uses: actions/download-artifact@v4
33+
with:
34+
name: storybook-static
35+
path: storybook-static
36+
- name: Deploy storybook to GitHub Pages
37+
uses: peaceiris/actions-gh-pages@v4
38+
with:
39+
github_token: ${{ secrets.GITHUB_TOKEN }}
40+
publish_dir: ./storybook-static
41+
destination_dir: ./storybook

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ public/workers/*
2727
coverage
2828

2929
/public/nomenclatures/
30+
31+
storybook-static/

.storybook/DocsContainer.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, { ComponentProps, useEffect } from 'react'
2+
3+
import { useIsDark } from '@codegouvfr/react-dsfr/useIsDark'
4+
import { DocsContainer as DocsContainer_base } from '@storybook/blocks'
5+
import { addons } from '@storybook/preview-api'
6+
import { DARK_MODE_EVENT_NAME } from 'storybook-dark-mode'
7+
8+
import { darkTheme, lightTheme } from './customTheme'
9+
10+
const channel = addons.getChannel()
11+
12+
type Props = ComponentProps<typeof DocsContainer_base>
13+
14+
export function DocsContainer(props: Props) {
15+
const { children, context } = props
16+
17+
const { setIsDark, isDark } = useIsDark()
18+
19+
useEffect(() => {
20+
// listen to DARK_MODE event
21+
channel.on(DARK_MODE_EVENT_NAME, setIsDark)
22+
return () => channel.off(DARK_MODE_EVENT_NAME, setIsDark)
23+
}, [channel, setIsDark])
24+
25+
return (
26+
<DocsContainer_base
27+
context={context}
28+
theme={isDark ? darkTheme : lightTheme}
29+
>
30+
{children}
31+
</DocsContainer_base>
32+
)
33+
}

.storybook/customTheme.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { create } from '@storybook/theming'
2+
3+
const brandImage = 'logo.png'
4+
const brandTitle = 'stromae-dsfr'
5+
const brandUrl = 'https://github.com/InseeFr/stromae-dsfr'
6+
const fontBase = '"Marianne", arial, sans-serif'
7+
const fontCode = 'monospace'
8+
9+
/**
10+
* Dark theme configuration for Storybook.
11+
*
12+
* @see For possible values that can be overridden, refer to:
13+
* {@link https://github.com/storybookjs/storybook/blob/fd6a748190f09d9fee906357daaead829ca4243f/code/lib/theming/src/types.ts|Storybook Theming Types}
14+
*
15+
*/
16+
export const darkTheme = create({
17+
base: 'dark',
18+
appBg: '#1E1E1E',
19+
appContentBg: '#161616',
20+
appPreviewBg: '#161616',
21+
barBg: '#1E1E1E',
22+
//"colorPrimary": "#8585F6",
23+
colorSecondary: '#8585F6',
24+
textColor: '#FFFFFF',
25+
brandImage,
26+
brandTitle,
27+
brandUrl,
28+
fontBase,
29+
fontCode,
30+
// brandTarget
31+
// gridCellSize
32+
})
33+
34+
/**
35+
* Light theme configuration for Storybook.
36+
*
37+
* @see For possible values that can be overridden, refer to:
38+
* {@link https://github.com/storybookjs/storybook/blob/fd6a748190f09d9fee906357daaead829ca4243f/code/lib/theming/src/types.ts|Storybook Theming Types}
39+
*
40+
*/
41+
export const lightTheme = create({
42+
base: 'light',
43+
appBg: '#F6F6F6',
44+
appContentBg: '#FFFFFF',
45+
appPreviewBg: '#FFFFFF',
46+
barBg: '#FFFFFF',
47+
//"colorPrimary": "#000091",
48+
colorSecondary: '#000091',
49+
textColor: '#212121',
50+
brandImage,
51+
brandTitle,
52+
brandUrl,
53+
fontBase,
54+
fontCode,
55+
})

.storybook/main.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { StorybookConfig } from '@storybook/react-vite'
2+
3+
export default {
4+
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
5+
6+
addons: [
7+
'@storybook/addon-links',
8+
'@storybook/addon-essentials',
9+
'@storybook/addon-interactions',
10+
'storybook-dark-mode',
11+
'@storybook/addon-a11y',
12+
],
13+
14+
docs: {
15+
defaultName: 'Documentation',
16+
},
17+
18+
framework: {
19+
name: '@storybook/react-vite',
20+
options: {},
21+
},
22+
23+
core: {
24+
builder: '@storybook/builder-vite',
25+
},
26+
staticDirs: ['./static'],
27+
28+
async viteFinal(config) {
29+
const { mergeConfig } = await import('vite')
30+
31+
// Merge custom configuration into the default config
32+
return mergeConfig(config, {
33+
plugins: ['./tsconfig.json'],
34+
// Add dependencies to pre-optimization
35+
optimizeDeps: {
36+
include: ['storybook-dark-mode'],
37+
},
38+
})
39+
},
40+
} satisfies StorybookConfig

.storybook/preview.tsx

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import React, { useEffect, useRef } from 'react'
2+
3+
import '@codegouvfr/react-dsfr/main.css'
4+
import { startReactDsfr } from '@codegouvfr/react-dsfr/spa'
5+
import { useIsDark as useIsDsfrDark } from '@codegouvfr/react-dsfr/useIsDark'
6+
import type { Channel } from '@storybook/channels'
7+
import { UPDATE_STORY_ARGS } from '@storybook/core-events'
8+
import type { Preview } from '@storybook/react'
9+
import { useDarkMode as useStorybookUiDarkMode } from 'storybook-dark-mode'
10+
11+
import { DocsContainer } from './DocsContainer'
12+
import { darkTheme, lightTheme } from './customTheme'
13+
14+
const defaultLang = 'fr'
15+
16+
startReactDsfr({
17+
defaultColorScheme: 'system',
18+
useLang: () => defaultLang,
19+
})
20+
21+
const preview = {
22+
globalTypes: {
23+
locale: {
24+
description: 'Internationalization locale',
25+
defaultValue: defaultLang,
26+
toolbar: {
27+
icon: 'globe',
28+
items: [
29+
{ value: 'fr', right: '🇫🇷', title: 'Français' },
30+
{ value: 'en', right: '🇺🇸', title: 'English' },
31+
],
32+
},
33+
},
34+
},
35+
36+
parameters: {
37+
backgrounds: { disable: true },
38+
docs: {
39+
autodocs: true,
40+
container: DocsContainer,
41+
controls: { exclude: ['darkMode'] },
42+
},
43+
darkMode: {
44+
light: lightTheme,
45+
dark: darkTheme,
46+
},
47+
controls: {
48+
exclude: ['activeControls', 'shortcut', 'filterDescription'],
49+
expanded: true,
50+
},
51+
},
52+
53+
argTypes: {
54+
darkMode: {
55+
control: { type: 'boolean' },
56+
description:
57+
'Global color scheme enabled, light or dark, it change only the color scheme of the Canvas',
58+
},
59+
initialPage: {
60+
table: { disable: true },
61+
control: { type: 'text' },
62+
},
63+
autoSuggesterLoading: {
64+
table: { disable: true },
65+
control: { type: 'boolean' },
66+
},
67+
detailAlwaysDisplayed: {
68+
table: { disable: true, category: 'components options' },
69+
control: { type: 'boolean' },
70+
},
71+
},
72+
73+
decorators: [
74+
(Story, context) => {
75+
const isStorybookUiDark = useStorybookUiDarkMode()
76+
const { setIsDark: setIsDsfrDark } = useIsDsfrDark()
77+
const channel = (window as any).__STORYBOOK_ADDONS_CHANNEL__ as Channel
78+
79+
useEffect(
80+
//We initialize storybook canva with the same theme as storybook webSite
81+
() => {
82+
setIsDsfrDark(isStorybookUiDark)
83+
channel.emit(UPDATE_STORY_ARGS, {
84+
storyId: context.id,
85+
updatedArgs: { darkMode: isStorybookUiDark },
86+
})
87+
},
88+
[],
89+
)
90+
useEffectOnValueChange(() => {
91+
setIsDsfrDark(context.args.darkMode)
92+
}, [context.args.darkMode])
93+
94+
return <Story />
95+
},
96+
],
97+
98+
tags: ['autodocs'],
99+
} satisfies Preview
100+
101+
export default preview
102+
103+
function useEffectOnValueChange<
104+
T extends readonly [value: any, ...moreValues: any[]],
105+
>(effect: (...args: T) => void | (() => void), values: T): void {
106+
const refIsFistRender = useRef(true)
107+
108+
useEffect(() => {
109+
if (refIsFistRender.current) {
110+
refIsFistRender.current = false
111+
return
112+
}
113+
114+
return effect(...values)
115+
}, values)
116+
}

.storybook/static/logo.png

141 KB
Loading

0 commit comments

Comments
 (0)