mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
make headers in MDX unstyled components
This commit is contained in:
parent
18dad97975
commit
653052fc8b
@ -8,11 +8,19 @@ However sometimes you might want some of your content to not have these styles a
|
||||
```md
|
||||
import { Unstyled } from '@storybook/blocks';
|
||||
|
||||
# This heading will be styled
|
||||
|
||||
<h2>So will this subheading</h2>
|
||||
|
||||
> This block quote will be styled
|
||||
|
||||
... and so will this paragraph.
|
||||
|
||||
<Unstyled>
|
||||
# This heading will not be styled
|
||||
|
||||
<h2>Neither will this subheading</h2>
|
||||
|
||||
> This block quote will not be styled
|
||||
|
||||
... neither will this paragraph, nor the following component:
|
||||
@ -22,11 +30,19 @@ import { Unstyled } from '@storybook/blocks';
|
||||
|
||||
Yields:
|
||||
|
||||
# This heading will be styled
|
||||
|
||||
<h2>So will this subheading</h2>
|
||||
|
||||
> This block quote will be styled
|
||||
|
||||
... and so will this paragraph.
|
||||
|
||||
<Unstyled>
|
||||
# This heading will not be styled
|
||||
|
||||
<h2>Neither will this subheading</h2>
|
||||
|
||||
> This block quote will not be styled
|
||||
|
||||
... neither will this paragraph, nor the following component:
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { FC, SyntheticEvent } from 'react';
|
||||
import React, { useContext } from 'react';
|
||||
import { NAVIGATE_URL } from '@storybook/core-events';
|
||||
import { Code, components } from '@storybook/components';
|
||||
import { Code, components, nameSpaceClassNames } from '@storybook/components';
|
||||
import { global } from '@storybook/global';
|
||||
import { styled } from '@storybook/theming';
|
||||
import { Source } from '../components';
|
||||
@ -120,13 +120,12 @@ export const AnchorMdx: FC<AnchorMdxProps> = (props) => {
|
||||
return <A {...props} />;
|
||||
};
|
||||
|
||||
const SUPPORTED_MDX_HEADERS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
|
||||
const SUPPORTED_MDX_HEADERS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const;
|
||||
|
||||
const OcticonHeaders = SUPPORTED_MDX_HEADERS.reduce(
|
||||
(acc, headerType) => ({
|
||||
...acc,
|
||||
// @ts-expect-error (Converted from ts-ignore)
|
||||
[headerType]: styled(components[headerType])({
|
||||
[headerType]: styled(headerType)({
|
||||
'& svg': {
|
||||
visibility: 'hidden',
|
||||
},
|
||||
@ -213,12 +212,10 @@ export const HeaderMdx: FC<HeaderMdxProps> = (props) => {
|
||||
</HeaderWithOcticonAnchor>
|
||||
);
|
||||
}
|
||||
|
||||
// @ts-expect-error (Converted from ts-ignore)
|
||||
const Header = components[as];
|
||||
|
||||
// Make sure it still work if "remark-slug" plugin is not present.
|
||||
return <Header {...props} />;
|
||||
const Component = as as React.ElementType;
|
||||
const { as: omittedAs, ...withoutAs } = props;
|
||||
return <Component {...nameSpaceClassNames(withoutAs, as)} />;
|
||||
};
|
||||
|
||||
export const HeadersMdx = SUPPORTED_MDX_HEADERS.reduce(
|
||||
|
@ -121,8 +121,6 @@ export const DocsContent = styled.div(({ theme }) => {
|
||||
return {
|
||||
maxWidth: 1000,
|
||||
width: '100%',
|
||||
|
||||
...reset,
|
||||
[toGlobalSelector('a')]: {
|
||||
...reset,
|
||||
fontSize: 'inherit',
|
||||
|
Loading…
x
Reference in New Issue
Block a user