Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Fix Subtitle block when no of prop passed #27147

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/ui/blocks/src/blocks/Subtitle.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ export const OfStringMetaAttached: Story = {
parameters: { relativeCsfPaths: ['../examples/Button.stories'], attached: true },
};
export const Children: Story = {
parameters: { relativeCsfPaths: ['../examples/Button.stories'], attached: true },
parameters: { relativeCsfPaths: ['../examples/Button.stories'], attached: false },
render: () => <Subtitle>This subtitle is a string passed as a children</Subtitle>,
};
13 changes: 11 additions & 2 deletions code/ui/blocks/src/blocks/Subtitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,17 @@ export const Subtitle: FunctionComponent<SubtitleProps> = (props) => {
throw new Error('Unexpected `of={undefined}`, did you mistype a CSF file reference?');
}

const { preparedMeta } = useOf(of || 'meta', ['meta']);
const { componentSubtitle, docs } = preparedMeta.parameters || {};
let preparedMeta;
try {
preparedMeta = useOf(of || 'meta', ['meta']).preparedMeta;
} catch (error) {
if (children && !error.message.includes('did you forget to use <Meta of={} />?')) {
// ignore error about unattached CSF since we can still render children
throw error;
}
}

const { componentSubtitle, docs } = preparedMeta?.parameters || {};

if (componentSubtitle) {
deprecate(
Expand Down
2 changes: 1 addition & 1 deletion code/ui/blocks/src/blocks/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const Title: FunctionComponent<TitleProps> = (props) => {
}
}

const content = children || extractTitle(preparedMeta.title);
const content = children || extractTitle(preparedMeta?.title);

return content ? <PureTitle className="sbdocs-title sb-unstyled">{content}</PureTitle> : null;
};
Loading