Skip to content

Commit f715dc1

Browse files
committed
docs(Playground): expand and copy buttons
1 parent 77a8dd8 commit f715dc1

File tree

9 files changed

+39
-32
lines changed

9 files changed

+39
-32
lines changed

packages/vkui-docs-theme/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ export { Head, Navbar, TOC, Footer, Search } from './src/components';
77
export type { SearchProps } from './src/components';
88
export { useConfig } from './src/contexts';
99
export { Layout } from './src/layout';
10-
export { getMdxComponents, Callout, Code, HeadingLink, Table, Th, Td, Tr } from './src/mdx';
10+
export {
11+
getMdxComponents,
12+
Callout,
13+
Code,
14+
HeadingLink,
15+
Table,
16+
Th,
17+
Td,
18+
Tr,
19+
CopyToClipboard,
20+
} from './src/mdx';
1121

1222
export { PostsLayout, PostHeader, getTags } from './src/blog';

packages/vkui-docs-theme/src/mdx/Pre/CopyToClipboard/CopyToClipboard.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import * as React from 'react';
24
import { Icon24ChecksOutline, Icon24CopyOutline } from '@vkontakte/icons';
35
import { classNames, copyTextToClipboard } from '@vkontakte/vkjs';

packages/vkui-docs-theme/src/mdx/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { H1 } from './H1';
66
import { HeadingLink } from './HeadingLink/HeadingLink';
77
import { Main } from './Main/Main';
88
import { PackageManagers } from './PackageManagers/PackageManagers';
9+
import { CopyToClipboard } from './Pre/CopyToClipboard/CopyToClipboard';
910
import { Pre } from './Pre/Pre';
1011
import { Steps } from './Steps/Steps';
1112
import { Table, Td, Th, Tr } from './Table/Table';
@@ -54,4 +55,4 @@ export const getMdxComponents = (components?: MDXComponents): MDXComponents => {
5455
};
5556
};
5657

57-
export { Callout, Code, HeadingLink, Table, Td, Th, Tr };
58+
export { Callout, Code, HeadingLink, Table, Td, Th, Tr, CopyToClipboard };
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.host {
2+
position: absolute;
3+
inset-block-start: 0;
4+
inset-inline-end: 0;
5+
color: var(--vkui--color_icon_tertiary);
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use client';
2+
3+
import * as React from 'react';
4+
import { CopyToClipboard } from '@vkontakte/vkui-docs-theme';
5+
import { LiveContext } from 'react-live';
6+
import styles from './CopyCodeButton.module.css';
7+
8+
export function CopyCodeButton() {
9+
const { newCode } = React.useContext(LiveContext);
10+
11+
return <CopyToClipboard getValue={() => newCode || ''} className={styles.host} />;
12+
}

website/components/mdx/Playground/Playground.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
}
77

88
.code {
9+
position: relative;
910
padding-block: var(--vkui--spacing_size_m);
1011
padding-inline: var(--vkui--spacing_size_xs);
1112
font-size: 14px;

website/components/mdx/Playground/Playground.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as React from 'react';
44
import { classNames, useColorScheme } from '@vkontakte/vkui';
55
import { JetBrains_Mono } from 'next/font/google';
66
import { LiveEditor, LiveProvider } from 'react-live';
7+
import { CopyCodeButton } from './CopyCodeButton/CopyCodeButton';
78
import {
89
PlaygroundPreview,
910
type PlaygroundPreviewProps,
@@ -44,6 +45,7 @@ export function Playground({
4445
{codeVisible && (
4546
<div className={styles.code}>
4647
<LiveEditor style={{ whiteSpace: 'nowrap' }} />
48+
<CopyCodeButton />
4749
</div>
4850
)}
4951
</LiveProvider>

website/components/mdx/Playground/PlaygroundToolbar/CopyCodeButton.tsx

Lines changed: 0 additions & 22 deletions
This file was deleted.

website/components/mdx/Playground/PlaygroundToolbar/PlaygroundToolbar.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import {
2-
Icon20ArrowLeftRightCornersOutline,
3-
Icon20ArrowRightLeftCornersOutline,
4-
} from '@vkontakte/icons';
1+
import { Icon20ArrowRightLeftCornersOutline, Icon20BracketsSlashOutline } from '@vkontakte/icons';
52
import { AdaptivityProvider, Button, Flex } from '@vkontakte/vkui';
63
import { ColorSchemePicker } from './ColorSchemePicker';
7-
import { CopyCodeButton } from './CopyCodeButton';
84
import { PlatformPicker } from './PlatformPicker/PlatformPicker';
95
import { ThemePicker } from './ThemePicker/ThemePicker';
106
import styles from './PlaygroundToolbar.module.css';
@@ -17,7 +13,7 @@ interface PlaygroundToolbarProps {
1713
export function PlaygroundToolbar({ codeVisible, setCodeVisible }: PlaygroundToolbarProps) {
1814
const CodeExpandedIcon = codeVisible
1915
? Icon20ArrowRightLeftCornersOutline
20-
: Icon20ArrowLeftRightCornersOutline;
16+
: Icon20BracketsSlashOutline;
2117

2218
return (
2319
<Flex align="center" gap="s" className={styles.root}>
@@ -27,13 +23,12 @@ export function PlaygroundToolbar({ codeVisible, setCodeVisible }: PlaygroundToo
2723
<AdaptivityProvider sizeY="regular">
2824
<ThemePicker className={styles.themePicker} />
2925
<ColorSchemePicker />
30-
<CopyCodeButton />
3126
<Button
3227
size="s"
3328
mode="secondary"
3429
appearance="neutral"
3530
onClick={() => setCodeVisible(!codeVisible)}
36-
before={<CodeExpandedIcon className={styles.rotateIcon} />}
31+
before={<CodeExpandedIcon {...(codeVisible && { className: styles.rotateIcon })} />}
3732
aria-label={codeVisible ? 'Свернуть блок с кодом' : 'Развернуть блок с кодом'}
3833
/>
3934
</AdaptivityProvider>

0 commit comments

Comments
 (0)