Skip to content

Commit

Permalink
Fix false obj values not showing up in code snippet
Browse files Browse the repository at this point in the history
+ remove `PRESERVED_FALSE_VALUE_PROPS` logic - we should let the defaultProps logic handle that instead and always show `false` props if they're non-defaults (testable on, e.g. `<EuiExpression uppercase={false} />`)
  • Loading branch information
cee-chen committed Sep 6, 2024
1 parent f6c9b55 commit 8aa6c0a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
2 changes: 0 additions & 2 deletions packages/eui/.storybook/addons/code-snippet/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export const EXCLUDED_PROPS = new Set([
EMOTION_LABEL_KEY,
'key',
]);
// props with 'false' value that should not be removed but shown in the code snippet
export const PRESERVED_FALSE_VALUE_PROPS = new Set(['grow']);

/** ERRORS */
export const ADDON_ERROR =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ export const customJsxDecorator = (

for (const key of Object.keys(context.args)) {
// checks story args for:
// - remove if no value
// - remove if `chidlren`
// - remove if no value (but allow `false`)
// - remove if `children`
// - remove if arg is a default prop
if (
!context.args[key] ||
context.args[key] == null ||
key === 'children' ||
defaultProps?.includes(key)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ import { getDocgenSection } from '@storybook/docs-tools';
import { logger } from '@storybook/client-logger';

import { UseEuiTheme } from '../../../../src/services';
import {
ADDON_PARAMETER_KEY,
EXCLUDED_PROPS,
PRESERVED_FALSE_VALUE_PROPS,
} from '../constants';
import { ADDON_PARAMETER_KEY, EXCLUDED_PROPS } from '../constants';
import {
getStoryComponentDisplayName,
getEmotionComponentDisplayName,
Expand Down Expand Up @@ -135,6 +131,7 @@ export const renderJsx = (
sortProps: true,
// using any type here as component props can have any type
filterProps: (value: any, key: string) => {
// Note that false values should be allowed, and handled by `removeDefaultProps`
if (
EXCLUDED_PROPS.has(key) ||
value == null ||
Expand All @@ -145,12 +142,6 @@ export const renderJsx = (
return false;
}

// manually filter props with `false` values as this allows us to preserve
// `false` values where required e.g. grow={false}
if (value === false && !PRESERVED_FALSE_VALUE_PROPS.has(key)) {
return false;
}

return true;
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const NoToolbar: StoryObj<Pick<EuiDataGridProps, 'toolbarVisibility'>> =
{
parameters: {
codeSnippet: {
snippet: `<EuiDataGrid toolbarVisibility={{{STORY_ARGS}}} />`,
snippet: `<EuiDataGrid {{...STORY_ARGS}} />`,
},
controls: { include: ['toolbarVisibility'] },
},
Expand All @@ -60,6 +60,7 @@ export const ToolbarVisibilityOptions: StoryObj<EuiDataGridToolBarVisibilityOpti
parameters: {
codeSnippet: {
snippet: `<EuiDataGrid toolbarVisibility={{{STORY_ARGS}}} />`,
removeDefaultProps: false,
},
controls: {
include: [
Expand Down

0 comments on commit 8aa6c0a

Please sign in to comment.