Skip to content

Commit

Permalink
fix: toggleswitch and storybook config
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfrancois committed Oct 13, 2023
1 parent 883562a commit d1d5d3b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .changeset/bright-zoos-hug.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const ToggleSwitchPrimitive = forwardRef(
<span
className={classnames(styles.switch, {
[styles.switch_readOnly]: !!readOnly,
[styles.switch_checked]: !!checked,
[styles.switch_checked]: controlled.value,
[styles.switch_disabled]: !!disabled,
[styles.switch_inline]: !!isInline,
})}
Expand All @@ -53,7 +53,7 @@ const ToggleSwitchPrimitive = forwardRef(
disabled={disabled}
readOnly={readOnly}
required={required}
aria-checked={checked}
aria-checked={controlled.value}
checked={controlled.value}
onChange={e => controlled.onChange(e)}
{...rest}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { ToggleSwitch } from './ToggleSwitch';
export * from './ToggleSwitch';
9 changes: 6 additions & 3 deletions packages/design-system/src/useControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type UseControlOptions = {
};

export function useControl<T>(props: any, opts: UseControlOptions) {

Check warning on line 11 in packages/design-system/src/useControl.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/design-system/src/useControl.ts#L11

[@typescript-eslint/no-explicit-any] Unexpected any. Specify a different type.
const isControlled = props[opts.valueKey] !== undefined && props[opts.onChangeKey] !== undefined;
let defaultValue = props[opts.defaultValueKey];
if (defaultValue === undefined) {
if (props[opts.valueKey] !== undefined) {
Expand All @@ -18,7 +19,6 @@ export function useControl<T>(props: any, opts: UseControlOptions) {
}
}
const [state, setState] = useState<T>(defaultValue);
const isControlled = props[opts.valueKey] !== undefined && props[opts.onChangeKey] !== undefined;

const onChange = (value: any) => {

Check warning on line 23 in packages/design-system/src/useControl.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/design-system/src/useControl.ts#L23

[@typescript-eslint/no-explicit-any] Unexpected any. Specify a different type.
let safeValue = value;
Expand All @@ -31,9 +31,12 @@ export function useControl<T>(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,
};
}
31 changes: 24 additions & 7 deletions tools/scripts-config-storybook-lib/.storybook-templates/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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$/,
Expand All @@ -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: {
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit d1d5d3b

Please sign in to comment.