Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d20e9c4

Browse files
armano2slorber
authored andcommittedMay 15, 2023
refactor(theme): expose copy, success and word-wrap icons as standalone components (#8862)
1 parent 74781b0 commit d20e9c4

File tree

6 files changed

+90
-15
lines changed

6 files changed

+90
-15
lines changed
 

‎packages/docusaurus-theme-classic/src/theme-classic.d.ts

+24
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,14 @@ declare module '@theme/Icon/Close' {
13221322
export default function IconClose(props: Props): JSX.Element;
13231323
}
13241324

1325+
declare module '@theme/Icon/Copy' {
1326+
import type {ComponentProps} from 'react';
1327+
1328+
export interface Props extends ComponentProps<'svg'> {}
1329+
1330+
export default function IconCopy(props: Props): JSX.Element;
1331+
}
1332+
13251333
declare module '@theme/Icon/Language' {
13261334
import type {ComponentProps} from 'react';
13271335

@@ -1330,6 +1338,14 @@ declare module '@theme/Icon/Language' {
13301338
export default function IconLanguage(props: Props): JSX.Element;
13311339
}
13321340

1341+
declare module '@theme/Icon/Success' {
1342+
import type {ComponentProps} from 'react';
1343+
1344+
export interface Props extends ComponentProps<'svg'> {}
1345+
1346+
export default function IconSuccess(props: Props): JSX.Element;
1347+
}
1348+
13331349
declare module '@theme/Icon/ExternalLink' {
13341350
import type {ComponentProps} from 'react';
13351351

@@ -1338,6 +1354,14 @@ declare module '@theme/Icon/ExternalLink' {
13381354
export default function IconExternalLink(props: Props): JSX.Element;
13391355
}
13401356

1357+
declare module '@theme/Icon/WordWrap' {
1358+
import type {ComponentProps} from 'react';
1359+
1360+
export interface Props extends ComponentProps<'svg'> {}
1361+
1362+
export default function IconWordWrap(props: Props): JSX.Element;
1363+
}
1364+
13411365
declare module '@theme/TagsListByLetter' {
13421366
import type {TagsListItem} from '@docusaurus/utils';
13431367

‎packages/docusaurus-theme-classic/src/theme/CodeBlock/CopyButton/index.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import clsx from 'clsx';
1111
import copy from 'copy-text-to-clipboard';
1212
import {translate} from '@docusaurus/Translate';
1313
import type {Props} from '@theme/CodeBlock/CopyButton';
14+
import IconCopy from '@theme/Icon/Copy';
15+
import IconSuccess from '@theme/Icon/Success';
1416

1517
import styles from './styles.module.css';
1618

@@ -56,12 +58,8 @@ export default function CopyButton({code, className}: Props): JSX.Element {
5658
)}
5759
onClick={handleCopyCode}>
5860
<span className={styles.copyButtonIcons} aria-hidden="true">
59-
<svg className={styles.copyButtonIcon} viewBox="0 0 24 24">
60-
<path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" />
61-
</svg>
62-
<svg className={styles.copyButtonSuccessIcon} viewBox="0 0 24 24">
63-
<path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" />
64-
</svg>
61+
<IconCopy className={styles.copyButtonIcon} />
62+
<IconSuccess className={styles.copyButtonSuccessIcon} />
6563
</span>
6664
</button>
6765
);

‎packages/docusaurus-theme-classic/src/theme/CodeBlock/WordWrapButton/index.tsx

+2-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import React from 'react';
99
import clsx from 'clsx';
1010
import {translate} from '@docusaurus/Translate';
1111
import type {Props} from '@theme/CodeBlock/WordWrapButton';
12+
import IconWordWrap from '@theme/Icon/WordWrap';
1213

1314
import styles from './styles.module.css';
1415

@@ -35,15 +36,7 @@ export default function WordWrapButton({
3536
)}
3637
aria-label={title}
3738
title={title}>
38-
<svg
39-
className={styles.wordWrapButtonIcon}
40-
viewBox="0 0 24 24"
41-
aria-hidden="true">
42-
<path
43-
fill="currentColor"
44-
d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3l3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"
45-
/>
46-
</svg>
39+
<IconWordWrap className={styles.wordWrapButtonIcon} aria-hidden="true" />
4740
</button>
4841
);
4942
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import React from 'react';
9+
import type {Props} from '@theme/Icon/Copy';
10+
11+
export default function IconCopy(props: Props): JSX.Element {
12+
return (
13+
<svg viewBox="0 0 24 24" {...props}>
14+
<path
15+
fill="currentColor"
16+
d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"
17+
/>
18+
</svg>
19+
);
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import React from 'react';
9+
import type {Props} from '@theme/Icon/Success';
10+
11+
export default function IconSuccess(props: Props): JSX.Element {
12+
return (
13+
<svg viewBox="0 0 24 24" {...props}>
14+
<path
15+
fill="currentColor"
16+
d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"
17+
/>
18+
</svg>
19+
);
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import React from 'react';
9+
import type {Props} from '@theme/Icon/WordWrap';
10+
11+
export default function IconWordWrap(props: Props): JSX.Element {
12+
return (
13+
<svg viewBox="0 0 24 24" {...props}>
14+
<path
15+
fill="currentColor"
16+
d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3l3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"
17+
/>
18+
</svg>
19+
);
20+
}

0 commit comments

Comments
 (0)
Please sign in to comment.