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

feat(mdx-typography): add basic typography support #705

Merged
merged 1 commit into from
Apr 27, 2022
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
3 changes: 2 additions & 1 deletion components/Article/ArticleContent.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import MDXComponents from '@components/MDX';
import { Ease } from '@components/Motion';
import type { Post } from '@types';
import { MDXRemote } from 'next-mdx-remote';
Expand All @@ -8,7 +9,7 @@ interface Props {
const ArticleContent = ({ source }: Props): JSX.Element => {
return (
<Ease>
<MDXRemote {...source} />
<MDXRemote {...source} components={MDXComponents} />
</Ease>
);
};
Expand Down
8 changes: 6 additions & 2 deletions components/Article/__snapshots__/Article.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ exports[`Article should render correctly (snapshot) 1`] = `
<div
style="opacity: 0;"
>
<h2>
<h2
class="ant-typography"
>
1 Basic Notes
</h2>
</div>
Expand Down Expand Up @@ -585,7 +587,9 @@ exports[`Article should render correctly with partial data (snapshot) 1`] = `
data-projection-id="2"
style="opacity: 0;"
>
<h2>
<h2
class="ant-typography"
>
1 Basic Notes
</h2>
</div>
Expand Down
7 changes: 7 additions & 0 deletions components/MDX/Anchor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Typography } from 'antd';

interface Props {}

const Anchor = (props: Props): JSX.Element => <Typography.Link {...props} />;

export default Anchor;
29 changes: 29 additions & 0 deletions components/MDX/Headings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Typography } from 'antd';
import type { TitleProps } from 'antd/lib/typography/Title';

interface Props {}

const Heading = (props: TitleProps): JSX.Element => (
<Typography.Title {...props} />
);

const H1 = (props: Props): JSX.Element => <Heading {...props} level={1} />;

const H2 = (props: Props): JSX.Element => <Heading {...props} level={2} />;

const H3 = (props: Props): JSX.Element => <Heading {...props} level={3} />;

const H4 = (props: Props): JSX.Element => <Heading {...props} level={4} />;

const H5 = (props: Props): JSX.Element => <Heading {...props} level={5} />;

const Headings = {
h1: H1,
h2: H2,
h3: H3,
h4: H4,
h5: H5,
h6: H5,
};

export default Headings;
43 changes: 43 additions & 0 deletions components/MDX/MDX.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { render } from '@testing-library/react';
import Anchor from './Anchor';
import Headings from './Headings';
import Paragraph from './Paragraph';
import Texts from './Texts';

describe('Anchor', () => {
test('should render correctly (snapshot)', () => {
const { container } = render(<Anchor />);

expect(container).toMatchSnapshot();
});
});

describe('Paragraph', () => {
test('should render correctly (snapshot)', () => {
const { container } = render(<Paragraph />);

expect(container).toMatchSnapshot();
});
});

describe('Headings', () => {
test.each(Object.values(Headings))(
'should render correctly (snapshot)',
Heading => {
const { container } = render(<Heading />);

expect(container).toMatchSnapshot();
}
);
});

describe('Texts', () => {
test.each(Object.values(Texts))(
'should render correctly (snapshot)',
Text => {
const { container } = render(<Text />);

expect(container).toMatchSnapshot();
}
);
});
9 changes: 9 additions & 0 deletions components/MDX/Paragraph.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Typography } from 'antd';

interface Props {}

const Paragraph = (props: Props): JSX.Element => (
<Typography.Paragraph {...props} />
);

export default Paragraph;
20 changes: 20 additions & 0 deletions components/MDX/Texts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Typography } from 'antd';
import type { TextProps } from 'antd/lib/typography/Text';

interface Props {}

const Text = (props: TextProps): JSX.Element => <Typography.Text {...props} />;

const Strong = (props: Props): JSX.Element => <Text {...props} strong />;

const Emphasis = (props: Props): JSX.Element => <Text {...props} italic />;

const Delete = (props: Props): JSX.Element => <Text {...props} delete />;

const Texts = {
strong: Strong,
em: Emphasis,
del: Delete,
};

export default Texts;
95 changes: 95 additions & 0 deletions components/MDX/__snapshots__/MDX.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Anchor should render correctly (snapshot) 1`] = `
<div>
<a
class="ant-typography"
/>
</div>
`;

exports[`Headings should render correctly (snapshot) 1`] = `
<div>
<h1
class="ant-typography"
/>
</div>
`;

exports[`Headings should render correctly (snapshot) 2`] = `
<div>
<h2
class="ant-typography"
/>
</div>
`;

exports[`Headings should render correctly (snapshot) 3`] = `
<div>
<h3
class="ant-typography"
/>
</div>
`;

exports[`Headings should render correctly (snapshot) 4`] = `
<div>
<h4
class="ant-typography"
/>
</div>
`;

exports[`Headings should render correctly (snapshot) 5`] = `
<div>
<h5
class="ant-typography"
/>
</div>
`;

exports[`Headings should render correctly (snapshot) 6`] = `
<div>
<h5
class="ant-typography"
/>
</div>
`;

exports[`Paragraph should render correctly (snapshot) 1`] = `
<div>
<div
class="ant-typography"
/>
</div>
`;

exports[`Texts should render correctly (snapshot) 1`] = `
<div>
<span
class="ant-typography"
>
<strong />
</span>
</div>
`;

exports[`Texts should render correctly (snapshot) 2`] = `
<div>
<span
class="ant-typography"
>
<i />
</span>
</div>
`;

exports[`Texts should render correctly (snapshot) 3`] = `
<div>
<span
class="ant-typography"
>
<del />
</span>
</div>
`;
13 changes: 13 additions & 0 deletions components/MDX/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Anchor from './Anchor';
import Headings from './Headings';
import Paragraph from './Paragraph';
import Texts from './Texts';

const MDXComponents = {
a: Anchor,
p: Paragraph,
...Headings,
...Texts,
};

export default MDXComponents;
4 changes: 4 additions & 0 deletions contents/implementFancyMDX.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ _This is italic text_
>> ...by using additional greater-than signs right next to each other...
> > > ...or with spaces between arrows.

> Blockquotes can also be continued...
> ...continued...
> ...continued continued...

## Lists

Unordered
Expand Down