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

refactor(theme): expose copy, success and word-wrap icons as standalone components #8862

Merged
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
24 changes: 24 additions & 0 deletions packages/docusaurus-theme-classic/src/theme-classic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,14 @@ declare module '@theme/Icon/Close' {
export default function IconClose(props: Props): JSX.Element;
}

declare module '@theme/Icon/Copy' {
import type {ComponentProps} from 'react';

export interface Props extends ComponentProps<'svg'> {}

export default function IconCopy(props: Props): JSX.Element;
}

declare module '@theme/Icon/Language' {
import type {ComponentProps} from 'react';

Expand All @@ -1439,6 +1447,14 @@ declare module '@theme/Icon/Language' {
export default function IconLanguage(props: Props): JSX.Element;
}

declare module '@theme/Icon/Success' {
import type {ComponentProps} from 'react';

export interface Props extends ComponentProps<'svg'> {}

export default function IconSuccess(props: Props): JSX.Element;
}

declare module '@theme/Icon/ExternalLink' {
import type {ComponentProps} from 'react';

Expand All @@ -1447,6 +1463,14 @@ declare module '@theme/Icon/ExternalLink' {
export default function IconExternalLink(props: Props): JSX.Element;
}

declare module '@theme/Icon/WordWrap' {
import type {ComponentProps} from 'react';

export interface Props extends ComponentProps<'svg'> {}

export default function IconWordWrap(props: Props): JSX.Element;
}

declare module '@theme/TagsListByLetter' {
import type {TagsListItem} from '@docusaurus/utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import clsx from 'clsx';
import copy from 'copy-text-to-clipboard';
import {translate} from '@docusaurus/Translate';
import type {Props} from '@theme/CodeBlock/CopyButton';
import IconCopy from '@theme/Icon/Copy';
import IconSuccess from '@theme/Icon/Success';

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

Expand Down Expand Up @@ -56,12 +58,8 @@ export default function CopyButton({code, className}: Props): JSX.Element {
)}
onClick={handleCopyCode}>
<span className={styles.copyButtonIcons} aria-hidden="true">
<svg className={styles.copyButtonIcon} viewBox="0 0 24 24">
<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" />
</svg>
<svg className={styles.copyButtonSuccessIcon} viewBox="0 0 24 24">
<path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" />
</svg>
<IconCopy className={styles.copyButtonIcon} />
<IconSuccess className={styles.copyButtonSuccessIcon} />
</span>
</button>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react';
import clsx from 'clsx';
import {translate} from '@docusaurus/Translate';
import type {Props} from '@theme/CodeBlock/WordWrapButton';
import IconWordWrap from '@theme/Icon/WordWrap';

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

Expand All @@ -35,15 +36,7 @@ export default function WordWrapButton({
)}
aria-label={title}
title={title}>
<svg
className={styles.wordWrapButtonIcon}
viewBox="0 0 24 24"
aria-hidden="true">
<path
fill="currentColor"
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"
/>
</svg>
<IconWordWrap className={styles.wordWrapButtonIcon} aria-hidden="true" />
</button>
);
}
20 changes: 20 additions & 0 deletions packages/docusaurus-theme-classic/src/theme/Icon/Copy/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import type {Props} from '@theme/Icon/Copy';

export default function IconCopy(props: Props): JSX.Element {
return (
<svg viewBox="0 0 24 24" {...props}>
<path
fill="currentColor"
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"
/>
</svg>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import type {Props} from '@theme/Icon/Success';

export default function IconSuccess(props: Props): JSX.Element {
return (
<svg viewBox="0 0 24 24" {...props}>
<path
fill="currentColor"
d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"
/>
</svg>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import type {Props} from '@theme/Icon/WordWrap';

export default function IconWordWrap(props: Props): JSX.Element {
return (
<svg viewBox="0 0 24 24" {...props}>
<path
fill="currentColor"
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"
/>
</svg>
);
}