diff --git a/lib/components/src/blocks/ArgsTable/ArgRow.stories.tsx b/lib/components/src/blocks/ArgsTable/ArgRow.stories.tsx index 6277a3f00646..5928adca91c7 100644 --- a/lib/components/src/blocks/ArgsTable/ArgRow.stories.tsx +++ b/lib/components/src/blocks/ArgsTable/ArgRow.stories.tsx @@ -298,6 +298,24 @@ LongEnum.args = { }, }; +export const complexUnion = + '((a: string | SVGSVGElement) => void) | RefObject | [a|b] | {a|b}'; + +export const ComplexUnion = Template.bind({}); +ComplexUnion.args = { + ...baseArgs, + row: { + key: 'complexUnion', + name: 'Complex', + type: { required: true }, + table: { + type: { + summary: complexUnion, + }, + }, + }, +}; + export const Markdown = Template.bind({}); Markdown.args = { ...baseArgs, diff --git a/lib/components/src/blocks/ArgsTable/ArgValue.tsx b/lib/components/src/blocks/ArgsTable/ArgValue.tsx index 03b1bb536cf3..14e15015851f 100644 --- a/lib/components/src/blocks/ArgsTable/ArgValue.tsx +++ b/lib/components/src/blocks/ArgsTable/ArgValue.tsx @@ -15,6 +15,7 @@ interface ArgValueProps { interface ArgTextProps { text: string; + simple?: boolean; } interface ArgSummaryProps { @@ -33,19 +34,24 @@ const Summary = styled.div<{ isExpanded?: boolean }>(({ isExpanded }) => ({ minWidth: 100, })); -const Text = styled.span<{}>(codeCommon, ({ theme }) => ({ +const Text = styled.span<{ simple?: boolean }>(codeCommon, ({ theme, simple = false }) => ({ flex: '0 0 auto', fontFamily: theme.typography.fonts.mono, fontSize: theme.typography.size.s1, wordBreak: 'break-word', + whiteSpace: 'normal', + maxWidth: '100%', margin: 0, marginRight: '4px', marginBottom: '4px', paddingTop: '2px', paddingBottom: '2px', lineHeight: '13px', - whiteSpace: 'normal', - maxWidth: '100%', + ...(simple && { + background: 'transparent', + border: '0 none', + paddingLeft: 0, + }), })); const ExpandButton = styled.button<{}>(({ theme }) => ({ @@ -93,8 +99,8 @@ const EmptyArg = () => { return -; }; -const ArgText: FC = ({ text }) => { - return {text}; +const ArgText: FC = ({ text, simple }) => { + return {text}; }; const calculateDetailWidth = memoize(1000)((detail: string): string => { @@ -132,6 +138,12 @@ const ArgSummary: FC = ({ value, initialExpandedArgs }) => { const summaryAsString = typeof summary.toString === 'function' ? summary.toString() : summary; if (detail == null) { + const cannotBeSafelySplitted = /[(){}[\]<>]/.test(summaryAsString); + + if (cannotBeSafelySplitted) { + return ; + } + const summaryItems = getSummaryItems(summaryAsString); const itemsCount = summaryItems.length; const hasManyItems = itemsCount > ITEMS_BEFORE_EXPANSION;