From 0815d27d05f6ed1ce0dbb837578107fa97540441 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Sun, 17 May 2020 17:18:41 +0800 Subject: [PATCH 1/3] Addon-docs: Eval argTypes default value --- addons/docs/src/frameworks/react/extractArgTypes.ts | 11 +++++++++-- examples/official-storybook/main.js | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/addons/docs/src/frameworks/react/extractArgTypes.ts b/addons/docs/src/frameworks/react/extractArgTypes.ts index 6af5403fd8e6..4f27a18d6170 100644 --- a/addons/docs/src/frameworks/react/extractArgTypes.ts +++ b/addons/docs/src/frameworks/react/extractArgTypes.ts @@ -12,10 +12,17 @@ export const extractArgTypes: ArgTypesExtractor = (component) => { const { rows } = props as PropsTableRowsProps; if (rows) { return rows.reduce((acc: ArgTypes, row: PropDef) => { - const { type, sbType, defaultValue, jsDocTags, required } = row; + const { type, sbType, defaultValue: defaultSummary, jsDocTags, required } = row; + let defaultValue = defaultSummary && trim(defaultSummary.detail || defaultSummary.summary); + try { + // eslint-disable-next-line no-eval + defaultValue = eval(defaultValue); + // eslint-disable-next-line no-empty + } catch {} + acc[row.name] = { ...row, - defaultValue: defaultValue && trim(defaultValue.detail || defaultValue.summary), + defaultValue, type: { required, ...sbType }, table: { type, diff --git a/examples/official-storybook/main.js b/examples/official-storybook/main.js index 71770c99b4cc..6eea9d783a01 100644 --- a/examples/official-storybook/main.js +++ b/examples/official-storybook/main.js @@ -3,7 +3,7 @@ module.exports = { // FIXME: Breaks e2e tests './intro.stories.mdx', '../../lib/ui/src/**/*.stories.(js|tsx|mdx)', '../../lib/components/src/**/*.stories.(js|tsx|mdx)', - './stories/**/*.stories.(js|tsx|mdx)', + './stories/**/*.stories.(js|ts|tsx|mdx)', './../../addons/docs/**/*.stories.tsx', ], addons: [ From beab55946eb7570474729711e9245b8a2e31d317 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Sun, 17 May 2020 17:42:29 +0800 Subject: [PATCH 2/3] ArgTypes: Clean up redundant quote removal --- addons/docs/src/frameworks/react/extractArgTypes.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/addons/docs/src/frameworks/react/extractArgTypes.ts b/addons/docs/src/frameworks/react/extractArgTypes.ts index 4f27a18d6170..999afa18f598 100644 --- a/addons/docs/src/frameworks/react/extractArgTypes.ts +++ b/addons/docs/src/frameworks/react/extractArgTypes.ts @@ -1,11 +1,8 @@ import { PropDef, PropsTableRowsProps } from '@storybook/components'; import { ArgTypes } from '@storybook/api'; import { ArgTypesExtractor } from '../../lib/docgen'; -import { trimQuotes } from '../../lib/sbtypes/utils'; import { extractProps } from './extractProps'; -const trim = (val: any) => (val && typeof val === 'string' ? trimQuotes(val) : val); - export const extractArgTypes: ArgTypesExtractor = (component) => { if (component) { const props = extractProps(component); @@ -13,7 +10,7 @@ export const extractArgTypes: ArgTypesExtractor = (component) => { if (rows) { return rows.reduce((acc: ArgTypes, row: PropDef) => { const { type, sbType, defaultValue: defaultSummary, jsDocTags, required } = row; - let defaultValue = defaultSummary && trim(defaultSummary.detail || defaultSummary.summary); + let defaultValue = defaultSummary && (defaultSummary.detail || defaultSummary.summary); try { // eslint-disable-next-line no-eval defaultValue = eval(defaultValue); From 3200bbc06360f078f8c21ff0db9142ba5c7b3db4 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Sun, 17 May 2020 18:17:08 +0800 Subject: [PATCH 3/3] ArgTypes: Fix table.defaultValue annotation --- addons/docs/src/frameworks/react/extractArgTypes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/docs/src/frameworks/react/extractArgTypes.ts b/addons/docs/src/frameworks/react/extractArgTypes.ts index 999afa18f598..fa35147a79ad 100644 --- a/addons/docs/src/frameworks/react/extractArgTypes.ts +++ b/addons/docs/src/frameworks/react/extractArgTypes.ts @@ -24,7 +24,7 @@ export const extractArgTypes: ArgTypesExtractor = (component) => { table: { type, jsDocTags, - defaultValue, + defaultValue: defaultSummary, }, }; return acc;