diff --git a/.changeset/bright-zoos-hug.md b/.changeset/bright-zoos-hug.md new file mode 100644 index 00000000000..ac5a93e247c --- /dev/null +++ b/.changeset/bright-zoos-hug.md @@ -0,0 +1,6 @@ +--- +'@talend/scripts-config-storybook-lib': patch +--- + +fix: add keys on all items in the decorators +fix: improve build performance copy/pasted from #4931 \ No newline at end of file diff --git a/packages/design-system/src/components/Form/ToggleSwitch/Primitive/ToggleSwitchPrimitive.tsx b/packages/design-system/src/components/Form/ToggleSwitch/Primitive/ToggleSwitchPrimitive.tsx index 8c8b3c4e15a..2f3bd5206ad 100644 --- a/packages/design-system/src/components/Form/ToggleSwitch/Primitive/ToggleSwitchPrimitive.tsx +++ b/packages/design-system/src/components/Form/ToggleSwitch/Primitive/ToggleSwitchPrimitive.tsx @@ -41,7 +41,7 @@ const ToggleSwitchPrimitive = forwardRef( controlled.onChange(e)} {...rest} diff --git a/packages/design-system/src/components/Form/ToggleSwitch/index.ts b/packages/design-system/src/components/Form/ToggleSwitch/index.ts index 9af62e8b0cc..abd33f3ca71 100644 --- a/packages/design-system/src/components/Form/ToggleSwitch/index.ts +++ b/packages/design-system/src/components/Form/ToggleSwitch/index.ts @@ -1 +1 @@ -export { ToggleSwitch } from './ToggleSwitch'; +export * from './ToggleSwitch'; diff --git a/packages/design-system/src/useControl.ts b/packages/design-system/src/useControl.ts index 8b0d626f9b6..a60b2d376a5 100644 --- a/packages/design-system/src/useControl.ts +++ b/packages/design-system/src/useControl.ts @@ -9,6 +9,7 @@ type UseControlOptions = { }; export function useControl(props: any, opts: UseControlOptions) { + const isControlled = props[opts.valueKey] !== undefined && props[opts.onChangeKey] !== undefined; let defaultValue = props[opts.defaultValueKey]; if (defaultValue === undefined) { if (props[opts.valueKey] !== undefined) { @@ -18,7 +19,6 @@ export function useControl(props: any, opts: UseControlOptions) { } } const [state, setState] = useState(defaultValue); - const isControlled = props[opts.valueKey] !== undefined && props[opts.onChangeKey] !== undefined; const onChange = (value: any) => { let safeValue = value; @@ -31,9 +31,12 @@ export function useControl(props: any, opts: UseControlOptions) { setState(safeValue); } }; - + let value = isControlled ? props[opts.valueKey] : state; + if (value === undefined) { + value = defaultValue; + } return { - value: isControlled ? props[opts.valueKey] : state, + value, onChange: isControlled ? props[opts.onChangeKey] : onChange, }; } diff --git a/tools/scripts-config-storybook-lib/.storybook-templates/main.js b/tools/scripts-config-storybook-lib/.storybook-templates/main.js index 3efa432806b..185f19cb1d7 100644 --- a/tools/scripts-config-storybook-lib/.storybook-templates/main.js +++ b/tools/scripts-config-storybook-lib/.storybook-templates/main.js @@ -26,11 +26,19 @@ const defaultMain = { name: '@storybook/react-webpack5', options: { builder: { - disableTelemetry: true, - enableCrashReports: false, + fsCache: true, + //lazyCompilation: true }, }, }, + typescript: { + reactDocgen: false, + check: false, + }, + core: { + enableCrashReports: false, + disableTelemetry: true, + }, features: { buildStoriesJson: true, }, @@ -43,12 +51,12 @@ const defaultMain = { '@storybook/addon-interactions', '@storybook/addon-storysource', ], - webpackFinal: async (config) => { + webpackFinal: async (config, { configType }) => { // by default storybook do not support scss without css module // here we remove storybook scss config and replace it by our config const rules = [ ...config.module.rules.filter(rule => { - return !rule.test?.toString().includes('s[ca]ss'); + return !rule.te?.toString().includes('s[ca]ss'); }), { test: /\.scss$/, @@ -60,6 +68,14 @@ const defaultMain = { use: getSassLoaders(true, '', true), }, ]; + // commented to have devtools back + // if (configType === 'PRODUCTION') { + // config.mode = 'production'; + // } + // config.optimization = { + // minimize: false, + // minimizer: [], + // }; const mergedConfig = { ...config, module: { @@ -95,11 +111,12 @@ module.exports = { stories, addons: [...defaultMain.addons, ...(userMain.addons || [])], core: merge(defaultMain.core, userMain.core), + typescript: merge(defaultMain.typescript, userMain.typescript), staticDirs: fixWindowsPaths([...(defaultMain.staticDirs|| []), ...(userMain.staticDirs || [])]), - webpackFinal: async (config) => { - let finalConfig = await defaultMain.webpackFinal(config); + webpackFinal: async (config, options) => { + let finalConfig = await defaultMain.webpackFinal(config, options); if(userMain.webpackFinal) { - finalConfig = await userMain.webpackFinal(finalConfig); + finalConfig = await userMain.webpackFinal(finalConfig, options); } return finalConfig } diff --git a/tools/scripts-config-storybook-lib/.storybook-templates/preview.js b/tools/scripts-config-storybook-lib/.storybook-templates/preview.js index dbbb08b4cf5..5bbd44ff39f 100644 --- a/tools/scripts-config-storybook-lib/.storybook-templates/preview.js +++ b/tools/scripts-config-storybook-lib/.storybook-templates/preview.js @@ -98,6 +98,7 @@ const defaultPreview = { }), React.createElement(ToggleBootstrap, { disabled: context.globals.bootstrapTheme === 'false', + key: 'toggle-bootstrap-decorator' }), React.createElement(ThemeProvider, { key: 'theme-provider-decorator',