Skip to content

Commit

Permalink
Addon-docs: Fix props table for sections props (#8904)
Browse files Browse the repository at this point in the history
Addon-docs: Fix props table for sections props
  • Loading branch information
shilman authored Nov 21, 2019
2 parents c077437 + 778fdc3 commit 9aa9463
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions addons/docs/src/blocks/Props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
PropsTable,
PropsTableError,
PropsTableProps,
PropsTableRowsProps,
PropsTableSectionsProps,
PropDef,
TabsState,
} from '@storybook/components';
Expand Down Expand Up @@ -37,6 +39,9 @@ const inferPropsExtractor = (framework: string): PropsExtractor | null => {
}
};

const filterRows = (rows: PropDef[], exclude: string[]) =>
rows && rows.filter((row: PropDef) => !exclude.includes(row.name));

export const getComponentProps = (
component: Component,
{ exclude }: PropsProps,
Expand All @@ -49,16 +54,25 @@ export const getComponentProps = (
const params = parameters || {};
const { framework = null } = params;

const { extractProps = inferPropsExtractor(framework) } = params.docs || {};
const { extractProps = inferPropsExtractor(framework) }: { extractProps: PropsExtractor } =
params.docs || {};
if (!extractProps) {
throw new Error(PropsTableError.PROPS_UNSUPPORTED);
}
let { rows } = extractProps(component);
let props = extractProps(component);
if (!isNil(exclude)) {
rows = rows.filter((row: PropDef) => !exclude.includes(row.name));
const { rows } = props as PropsTableRowsProps;
const { sections } = props as PropsTableSectionsProps;
if (rows) {
props = { rows: filterRows(rows, exclude) };
} else if (sections) {
Object.keys(sections).forEach(section => {
sections[section] = filterRows(sections[section], exclude);
});
}
}

return { rows };
return props;
} catch (err) {
return { error: err.message };
}
Expand Down
2 changes: 1 addition & 1 deletion examples/web-components-kitchen-sink/.storybook/presets.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = ['@storybook/addon-docs/web-components/preset'];
module.exports = ['@storybook/addon-docs/preset'];

0 comments on commit 9aa9463

Please sign in to comment.