@storybook/components 5.2.1 → 5.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/dist/html.js +1 -1
  2. package/dist/typography/DocumentFormatting.js +2 -1
  3. package/dist/typography/DocumentWrapper.js +2 -2
  4. package/package.json +11 -5
  5. package/src/ActionBar/ActionBar.stories.tsx +0 -41
  6. package/src/ActionBar/ActionBar.tsx +0 -75
  7. package/src/Badge/Badge.stories.tsx +0 -11
  8. package/src/Badge/Badge.tsx +0 -68
  9. package/src/Button/Button.stories.tsx +0 -53
  10. package/src/Button/Button.tsx +0 -256
  11. package/src/ScrollArea/ScrollArea.stories.tsx +0 -85
  12. package/src/ScrollArea/ScrollArea.tsx +0 -62
  13. package/src/ScrollArea/ScrollAreaStyles.tsx +0 -166
  14. package/src/addon-panel/addon-panel.tsx +0 -33
  15. package/src/bar/bar.tsx +0 -93
  16. package/src/bar/button.ts +0 -89
  17. package/src/bar/separator.tsx +0 -39
  18. package/src/blocks/BlockBackgroundStyles.tsx +0 -9
  19. package/src/blocks/ColorPalette.stories.tsx +0 -29
  20. package/src/blocks/ColorPalette.tsx +0 -168
  21. package/src/blocks/Description.stories.tsx +0 -15
  22. package/src/blocks/Description.tsx +0 -18
  23. package/src/blocks/DocsPage.stories.tsx +0 -67
  24. package/src/blocks/DocsPage.tsx +0 -81
  25. package/src/blocks/DocsPageExampleCaption.md +0 -93
  26. package/src/blocks/DocsPageExampleCaption.mdx +0 -93
  27. package/src/blocks/EmptyBlock.stories.tsx +0 -9
  28. package/src/blocks/EmptyBlock.tsx +0 -23
  29. package/src/blocks/IFrame.tsx +0 -60
  30. package/src/blocks/IconGallery.stories.tsx +0 -32
  31. package/src/blocks/IconGallery.tsx +0 -72
  32. package/src/blocks/Preview.stories.tsx +0 -96
  33. package/src/blocks/Preview.tsx +0 -162
  34. package/src/blocks/PropsTable/PropDef.ts +0 -7
  35. package/src/blocks/PropsTable/PropRow.stories.tsx +0 -113
  36. package/src/blocks/PropsTable/PropRow.tsx +0 -102
  37. package/src/blocks/PropsTable/PropsTable.stories.tsx +0 -14
  38. package/src/blocks/PropsTable/PropsTable.tsx +0 -169
  39. package/src/blocks/Source.stories.tsx +0 -36
  40. package/src/blocks/Source.tsx +0 -72
  41. package/src/blocks/Story.stories.tsx +0 -25
  42. package/src/blocks/Story.tsx +0 -115
  43. package/src/blocks/Toolbar.tsx +0 -85
  44. package/src/blocks/Typeset.stories.tsx +0 -16
  45. package/src/blocks/Typeset.tsx +0 -68
  46. package/src/blocks/ZoomContext.tsx +0 -5
  47. package/src/blocks/index.ts +0 -10
  48. package/src/brand/StorybookIcon.stories.tsx +0 -6
  49. package/src/brand/StorybookIcon.tsx +0 -26
  50. package/src/brand/StorybookLogo.stories.tsx +0 -10
  51. package/src/brand/StorybookLogo.tsx +0 -33
  52. package/src/form/field/field.tsx +0 -42
  53. package/src/form/form.stories.tsx +0 -133
  54. package/src/form/index.tsx +0 -18
  55. package/src/form/input/input.tsx +0 -178
  56. package/src/html.tsx +0 -12
  57. package/src/icon/icon.stories.tsx +0 -77
  58. package/src/icon/icon.tsx +0 -22
  59. package/src/icon/icons.tsx +0 -310
  60. package/src/icon/svg.tsx +0 -24
  61. package/src/index.ts +0 -37
  62. package/src/placeholder/placeholder.stories.tsx +0 -24
  63. package/src/placeholder/placeholder.tsx +0 -25
  64. package/src/spaced/Spaced.stories.tsx +0 -72
  65. package/src/spaced/Spaced.tsx +0 -69
  66. package/src/syntaxhighlighter/formatter.test.js +0 -90
  67. package/src/syntaxhighlighter/formatter.ts +0 -26
  68. package/src/syntaxhighlighter/syntaxhighlighter.stories.tsx +0 -136
  69. package/src/syntaxhighlighter/syntaxhighlighter.tsx +0 -165
  70. package/src/tabs/tabs.stories.tsx +0 -207
  71. package/src/tabs/tabs.tsx +0 -252
  72. package/src/tooltip/ListItem.stories.tsx +0 -35
  73. package/src/tooltip/ListItem.tsx +0 -245
  74. package/src/tooltip/Tooltip.stories.tsx +0 -42
  75. package/src/tooltip/Tooltip.tsx +0 -146
  76. package/src/tooltip/TooltipLinkList.stories.tsx +0 -52
  77. package/src/tooltip/TooltipLinkList.tsx +0 -49
  78. package/src/tooltip/TooltipMessage.stories.tsx +0 -37
  79. package/src/tooltip/TooltipMessage.tsx +0 -67
  80. package/src/tooltip/TooltipNote.stories.tsx +0 -15
  81. package/src/tooltip/TooltipNote.tsx +0 -25
  82. package/src/tooltip/WithTooltip.stories.tsx +0 -85
  83. package/src/tooltip/WithTooltip.tsx +0 -159
  84. package/src/typings.d.ts +0 -4
  85. package/src/typography/DocumentFormatting.tsx +0 -355
  86. package/src/typography/DocumentFormattingSample.md +0 -127
  87. package/src/typography/DocumentWrapper.stories.tsx +0 -190
  88. package/src/typography/DocumentWrapper.tsx +0 -441
  89. package/src/typography/link/link.stories.tsx +0 -67
  90. package/src/typography/link/link.test.tsx +0 -108
  91. package/src/typography/link/link.tsx +0 -223
  92. package/src/typography/typography.stories.tsx +0 -111
  93. package/src/typography/withReset.tsx +0 -12
  94. package/tsconfig.json +0 -18
package/src/index.ts DELETED
@@ -1,37 +0,0 @@
1
- export { Badge } from './Badge/Badge';
2
-
3
- // Typography
4
- export { Link } from './typography/link/link';
5
- export { DocumentWrapper } from './typography/DocumentWrapper';
6
- export { SyntaxHighlighter } from './syntaxhighlighter/syntaxhighlighter';
7
-
8
- // UI
9
- export { ActionBar } from './ActionBar/ActionBar';
10
- export { Spaced } from './spaced/Spaced';
11
- export { Placeholder } from './placeholder/placeholder';
12
- export { ScrollArea } from './ScrollArea/ScrollArea';
13
-
14
- // Forms
15
- export { Button } from './Button/Button';
16
- export { Form } from './form/index';
17
-
18
- // Tooltips
19
- export { WithTooltip, WithTooltipPure } from './tooltip/WithTooltip';
20
- export { TooltipMessage } from './tooltip/TooltipMessage';
21
- export { TooltipNote } from './tooltip/TooltipNote';
22
- export { TooltipLinkList } from './tooltip/TooltipLinkList';
23
-
24
- // Toolbar and subcomponents
25
- export { Tabs, TabsState, TabBar, TabWrapper } from './tabs/tabs';
26
- export { IconButton, TabButton } from './bar/button';
27
- export { Separator, interleaveSeparators } from './bar/separator';
28
- export { Bar, FlexBar } from './bar/bar';
29
- export { AddonPanel } from './addon-panel/addon-panel';
30
-
31
- // Graphics
32
- export { Icons } from './icon/icon';
33
- export { StorybookLogo } from './brand/StorybookLogo';
34
- export { StorybookIcon } from './brand/StorybookIcon';
35
-
36
- // Doc blocks
37
- export * from './blocks';
@@ -1,24 +0,0 @@
1
- import React, { Fragment } from 'react';
2
-
3
- import { Placeholder } from './placeholder';
4
- import { Link } from '../typography/link/link';
5
-
6
- export default {
7
- component: Placeholder,
8
- title: 'Basics|Placeholder',
9
- };
10
-
11
- export const singleChild = () => (
12
- <Placeholder>This is a placeholder with single child, it's bolded</Placeholder>
13
- );
14
- export const twoChildren = () => (
15
- <Placeholder>
16
- <Fragment key="title">This has two children, the first bold</Fragment>
17
- <Fragment key="desc">
18
- The second normal weight. Here's a{' '}
19
- <Link href="https://storybook.js.org" secondary cancel={false}>
20
- link
21
- </Link>
22
- </Fragment>
23
- </Placeholder>
24
- );
@@ -1,25 +0,0 @@
1
- import React, { Children, FunctionComponent } from 'react';
2
- import { styled } from '@storybook/theming';
3
-
4
- const Title = styled.div`
5
- font-weight: ${props => props.theme.typography.weight.bold};
6
- `;
7
-
8
- const Desc = styled.div``;
9
-
10
- const Message = styled.div`
11
- padding: 30px;
12
- text-align: center;
13
- color: ${props => props.theme.color.defaultText};
14
- font-size: ${props => props.theme.typography.size.s2 - 1}px;
15
- `;
16
-
17
- export const Placeholder: FunctionComponent = ({ children, ...props }) => {
18
- const [title, desc] = Children.toArray(children);
19
- return (
20
- <Message {...props}>
21
- <Title>{title}</Title>
22
- {desc && <Desc>{desc}</Desc>}
23
- </Message>
24
- );
25
- };
@@ -1,72 +0,0 @@
1
- import React from 'react';
2
- import { storiesOf } from '@storybook/react';
3
- import { styled } from '@storybook/theming';
4
-
5
- import { Spaced } from './Spaced';
6
-
7
- const PlaceholderBlock = styled.div(({ color }) => ({
8
- background: color || 'hotpink',
9
- padding: 20,
10
- }));
11
- const PlaceholderInline = styled.span(({ color }) => ({
12
- background: color || 'hotpink',
13
- display: 'inline-block',
14
- padding: 20,
15
- }));
16
-
17
- storiesOf('Basics|Spaced', module)
18
- .add('row', () => (
19
- <div>
20
- <PlaceholderBlock color="silver" />
21
- <Spaced row={1}>
22
- <PlaceholderBlock />
23
- <PlaceholderBlock />
24
- <PlaceholderBlock />
25
- </Spaced>
26
- <PlaceholderBlock color="silver" />
27
- </div>
28
- ))
29
- .add('row outer', () => (
30
- <div>
31
- <PlaceholderBlock color="silver" />
32
- <Spaced row={1} outer>
33
- <PlaceholderBlock />
34
- <PlaceholderBlock />
35
- <PlaceholderBlock />
36
- </Spaced>
37
- <PlaceholderBlock color="silver" />
38
- </div>
39
- ))
40
- .add('row multiply', () => (
41
- <div>
42
- <PlaceholderBlock color="silver" />
43
- <Spaced row={3} outer={0.5}>
44
- <PlaceholderBlock />
45
- <PlaceholderBlock />
46
- <PlaceholderBlock />
47
- </Spaced>
48
- <PlaceholderBlock color="silver" />
49
- </div>
50
- ))
51
- .add('col', () => (
52
- <div>
53
- <PlaceholderInline color="silver" />
54
- <Spaced col={1}>
55
- <PlaceholderInline />
56
- <PlaceholderInline />
57
- <PlaceholderInline />
58
- </Spaced>
59
- <PlaceholderInline color="silver" />
60
- </div>
61
- ))
62
- .add('col outer', () => (
63
- <div>
64
- <PlaceholderInline color="silver" />
65
- <Spaced col={1} outer>
66
- <PlaceholderInline />
67
- <PlaceholderInline />
68
- <PlaceholderInline />
69
- </Spaced>
70
- <PlaceholderInline color="silver" />
71
- </div>
72
- ));
@@ -1,69 +0,0 @@
1
- import React, { FunctionComponent } from 'react';
2
- import { styled } from '@storybook/theming';
3
-
4
- const toNumber = (input: any) => (typeof input === 'number' ? input : Number(input));
5
-
6
- export interface ContainerProps {
7
- col?: number;
8
- row?: number;
9
- outer?: number;
10
- }
11
-
12
- const Container = styled.div<ContainerProps>(
13
- ({ theme, col, row = 1 }) =>
14
- col
15
- ? {
16
- display: 'inline-block',
17
- verticalAlign: 'inherit',
18
- '& > *': {
19
- marginLeft: col * theme.layoutMargin,
20
- verticalAlign: 'inherit',
21
- },
22
- '& > *:first-of-type': {
23
- marginLeft: 0,
24
- },
25
- }
26
- : {
27
- '& > *': {
28
- marginTop: row * theme.layoutMargin,
29
- },
30
- '& > *:first-of-type': {
31
- marginTop: 0,
32
- },
33
- },
34
- ({ theme, outer, col, row }) => {
35
- switch (true) {
36
- case !!(outer && col): {
37
- return {
38
- marginLeft: outer * theme.layoutMargin,
39
- marginRight: outer * theme.layoutMargin,
40
- };
41
- }
42
- case !!(outer && row): {
43
- return {
44
- marginTop: outer * theme.layoutMargin,
45
- marginBottom: outer * theme.layoutMargin,
46
- };
47
- }
48
- default: {
49
- return {};
50
- }
51
- }
52
- }
53
- );
54
-
55
- export interface SpacedProps {
56
- col?: number;
57
- row?: number;
58
- outer?: number | boolean;
59
- }
60
-
61
- export const Spaced: FunctionComponent<SpacedProps> = ({ col, row, outer, children }) => {
62
- const outerAmount = toNumber(typeof outer === 'number' || !outer ? outer : col || row);
63
-
64
- return (
65
- <Container col={col} row={row} outer={outerAmount}>
66
- {children}
67
- </Container>
68
- );
69
- };
@@ -1,90 +0,0 @@
1
- import { stripIndents } from 'common-tags';
2
-
3
- import { formatter } from './formatter';
4
-
5
- test('handles empty string', () => {
6
- const input = '';
7
- const result = formatter(input);
8
-
9
- expect(result).toBe(input);
10
- });
11
-
12
- test('handles single line', () => {
13
- const input = 'console.log("hello world")';
14
- const result = formatter(input);
15
-
16
- expect(result).toBe(input);
17
- });
18
-
19
- test('does not transform correct code', () => {
20
- const input = stripIndents`
21
- console.log("hello");
22
- console.log("world");
23
- `;
24
- const result = formatter(input);
25
-
26
- expect(result).toBe(input);
27
- });
28
-
29
- test('does transform incorrect code', () => {
30
- const input = `
31
- console.log("hello");
32
- console.log("world");
33
- `;
34
- const result = formatter(input);
35
-
36
- expect(result).toBe(`console.log("hello");
37
- console.log("world");`);
38
- });
39
-
40
- test('more indentations - skip first line', () => {
41
- const input = `
42
- test('handles empty string', () => {
43
- const input = '';
44
- const result = formatter(input);
45
-
46
- expect(result).toBe(input);
47
- });
48
- `;
49
- const result = formatter(input);
50
-
51
- expect(result).toBe(`test('handles empty string', () => {
52
- const input = '';
53
- const result = formatter(input);
54
-
55
- expect(result).toBe(input);
56
- });`);
57
- });
58
-
59
- test('more indentations - code on first line', () => {
60
- const input = `// some comment
61
- test('handles empty string', () => {
62
- const input = '';
63
- const result = formatter(input);
64
-
65
- expect(result).toBe(input);
66
- });
67
- `;
68
- const result = formatter(input);
69
-
70
- expect(result).toBe(`// some comment
71
- test('handles empty string', () => {
72
- const input = '';
73
- const result = formatter(input);
74
-
75
- expect(result).toBe(input);
76
- });`);
77
- });
78
-
79
- test('removes whitespace in empty line completely', () => {
80
- const input = `
81
- console.log("hello");
82
-
83
- console.log("world");
84
- `;
85
- const result = formatter(input);
86
-
87
- expect(result).toBe(`console.log("hello");
88
-
89
- console.log("world");`);
90
- });
@@ -1,26 +0,0 @@
1
- import memoize from 'memoizerific';
2
-
3
- export const formatter = memoize(2)((code: string) => {
4
- // code provided to the component is often coming from template literals, which preserve whitespace.
5
- // sometimes the first line doesn't have padding, but the second does.
6
- // we split the code-string into lines, then if we find padding on line 0 or 1,
7
- // we assume that padding is bad, and remove that much padding on all following lines
8
- return code
9
- .split(/\n/)
10
- .reduce(
11
- (acc, i, index) => {
12
- const match = i.match(/^((:?\s|\t)+)/);
13
- const padding = match ? match[1] : '';
14
-
15
- if (acc.firstIndent === '' && padding && index < 3) {
16
- return { result: `${acc.result}\n${i.replace(padding, '')}`, firstIndent: padding };
17
- }
18
- return {
19
- result: `${acc.result}\n${i.replace(acc.firstIndent, '').replace(/\s*$/, '')}`,
20
- firstIndent: acc.firstIndent,
21
- };
22
- },
23
- { firstIndent: '', result: '' }
24
- )
25
- .result.trim();
26
- });
@@ -1,136 +0,0 @@
1
- import * as React from 'react';
2
- import { storiesOf } from '@storybook/react';
3
- import { ThemeProvider, themes, convert, ensure } from '@storybook/theming';
4
- import { SyntaxHighlighter } from './syntaxhighlighter';
5
-
6
- storiesOf('Basics|SyntaxHighlighter', module)
7
- .add('bash', () => (
8
- <SyntaxHighlighter language="bash" copyable={false}>
9
- npx npm-check-updates '/storybook/' -u && npm install
10
- </SyntaxHighlighter>
11
- ))
12
- .add('jsx', () => (
13
- <SyntaxHighlighter language="jsx" copyable={false}>
14
- {`import { Good, Things } from 'life';
15
-
16
- const result = () => <Good><Things all={true} /></Good>;
17
-
18
- export { result as default };
19
- `}
20
- </SyntaxHighlighter>
21
- ))
22
- .add('unsupported', () => (
23
- <SyntaxHighlighter language="C#" bordered copyable>
24
- {`
25
- // A Hello World! program in C#.
26
- using System;
27
- namespace HelloWorld
28
- {
29
- class Hello
30
- {
31
- static void Main()
32
- {
33
- Console.WriteLine("Hello World!");
34
-
35
- // Keep the console window open in debug mode.
36
- Console.WriteLine("Press any key to exit.");
37
- Console.ReadKey();
38
- }
39
- }
40
- }
41
- `}
42
- </SyntaxHighlighter>
43
- ))
44
- .add('dark unsupported', () => {
45
- const theme = ensure(themes.dark);
46
- return (
47
- <ThemeProvider theme={theme}>
48
- <SyntaxHighlighter bordered language="C#" copyable>
49
- {`
50
- // A Hello World! program in C#.
51
- using System;
52
- namespace HelloWorld
53
- {
54
- class Hello
55
- {
56
- static void Main()
57
- {
58
- Console.WriteLine("Hello World!");
59
-
60
- // Keep the console window open in debug mode.
61
- Console.WriteLine("Press any key to exit.");
62
- Console.ReadKey();
63
- }
64
- }
65
- }
66
- `}
67
- </SyntaxHighlighter>
68
- </ThemeProvider>
69
- );
70
- })
71
- .add('story', () => (
72
- <SyntaxHighlighter language="jsx" copyable={false}>
73
- {`
74
- import React from 'react';
75
- import { storiesOf } from '@storybook/react';
76
- import { styled } from '@storybook/theming';
77
-
78
- import Heading from './heading';
79
-
80
- const Holder = styled.div({
81
- margin: 10,
82
- border: '1px dashed deepskyblue',
83
- // overflow: 'hidden',
84
- });
85
-
86
- storiesOf('Basics|Heading', module).add('types', () => (
87
- <div>
88
- <Holder>
89
- <Heading>DEFAULT WITH ALL CAPS</Heading>
90
- </Holder>
91
- <Holder>
92
- <Heading sub="With a great sub">THIS LONG DEFAULT WITH ALL CAPS & SUB</Heading>
93
- </Holder>
94
- <Holder>
95
- <Heading type="page">page type</Heading>
96
- </Holder>
97
- <Holder>
98
- <Heading type="page" sub="With a sub">
99
- page type
100
- </Heading>
101
- </Holder>
102
- </div>
103
- ));
104
- `}
105
- </SyntaxHighlighter>
106
- ))
107
- .add('bordered & copy-able', () => (
108
- <SyntaxHighlighter language="jsx" copyable bordered>
109
- {`import { Good, Things } from 'life';
110
-
111
- const result = () => <Good><Things /></Good>;
112
-
113
- export { result as default };
114
- `}
115
- </SyntaxHighlighter>
116
- ))
117
- .add('padded', () => (
118
- <SyntaxHighlighter language="jsx" padded>
119
- {`import { Good, Things } from 'life';
120
-
121
- const result = () => <Good><Things /></Good>;
122
-
123
- export { result as default };
124
- `}
125
- </SyntaxHighlighter>
126
- ))
127
- .add('showLineNumbers', () => (
128
- <SyntaxHighlighter language="jsx" copyable={false} showLineNumbers>
129
- {`import { Good, Things } from 'life';
130
-
131
- const result = () => <Good><Things /></Good>;
132
-
133
- export { result as default };
134
- `}
135
- </SyntaxHighlighter>
136
- ));
@@ -1,165 +0,0 @@
1
- import React, { Component } from 'react';
2
- import { styled } from '@storybook/theming';
3
- import { document, window } from 'global';
4
- import memoize from 'memoizerific';
5
-
6
- import jsx from 'react-syntax-highlighter/languages/prism/jsx';
7
- import bash from 'react-syntax-highlighter/languages/prism/bash';
8
- import css from 'react-syntax-highlighter/languages/prism/css';
9
- import html from 'react-syntax-highlighter/languages/prism/markup';
10
-
11
- import ReactSyntaxHighlighter, { registerLanguage } from 'react-syntax-highlighter/prism-light';
12
-
13
- import { ActionBar } from '../ActionBar/ActionBar';
14
- import { ScrollArea } from '../ScrollArea/ScrollArea';
15
-
16
- import { formatter } from './formatter';
17
-
18
- registerLanguage('jsx', jsx);
19
- registerLanguage('bash', bash);
20
- registerLanguage('css', css);
21
- registerLanguage('html', html);
22
-
23
- const themedSyntax = memoize(2)(theme =>
24
- Object.entries(theme.code || {}).reduce((acc, [key, val]) => ({ ...acc, [`* .${key}`]: val }), {})
25
- );
26
-
27
- export interface WrapperProps {
28
- bordered?: boolean;
29
- padded?: boolean;
30
- }
31
-
32
- const Wrapper = styled.div<WrapperProps>(
33
- ({ theme }) => ({
34
- position: 'relative',
35
- overflow: 'hidden',
36
- color: theme.color.defaultText,
37
- }),
38
- ({ theme, bordered }) =>
39
- bordered
40
- ? {
41
- border: `1px solid ${theme.appBorderColor}`,
42
- borderRadius: theme.borderRadius,
43
- background: theme.background.content,
44
- }
45
- : {}
46
- );
47
-
48
- const Scroller = styled(({ children, className }) => (
49
- <ScrollArea horizontal vertical className={className}>
50
- {children}
51
- </ScrollArea>
52
- ))(
53
- {
54
- position: 'relative',
55
- },
56
- ({ theme }) => ({
57
- '& code': {
58
- paddingRight: theme.layoutMargin,
59
- },
60
- }),
61
- ({ theme }) => themedSyntax(theme)
62
- );
63
-
64
- export interface PreProps {
65
- padded?: boolean;
66
- }
67
-
68
- const Pre = styled.pre<PreProps>(({ theme, padded }) => ({
69
- display: 'flex',
70
- justifyContent: 'flex-start',
71
- margin: 0,
72
- padding: padded ? theme.layoutMargin : 0,
73
- }));
74
-
75
- const Code = styled.code({
76
- flex: 1,
77
- paddingRight: 0,
78
- opacity: 1,
79
- });
80
-
81
- export interface SyntaxHighlighterProps {
82
- language: string;
83
- copyable?: boolean;
84
- bordered?: boolean;
85
- padded?: boolean;
86
- format?: boolean;
87
- className?: string;
88
- }
89
-
90
- export interface SyntaxHighlighterState {
91
- copied: boolean;
92
- }
93
-
94
- type ReactSyntaxHighlighterProps = React.ComponentProps<typeof ReactSyntaxHighlighter>;
95
-
96
- export class SyntaxHighlighter extends Component<
97
- SyntaxHighlighterProps & ReactSyntaxHighlighterProps,
98
- SyntaxHighlighterState
99
- > {
100
- static defaultProps: SyntaxHighlighterProps = {
101
- language: null,
102
- copyable: false,
103
- bordered: false,
104
- padded: false,
105
- format: true,
106
- className: null,
107
- };
108
-
109
- state = { copied: false };
110
-
111
- onClick = (e: React.MouseEvent) => {
112
- const { children } = this.props;
113
-
114
- e.preventDefault();
115
- const tmp = document.createElement('TEXTAREA');
116
- const focus = document.activeElement;
117
-
118
- tmp.value = children;
119
-
120
- document.body.appendChild(tmp);
121
- tmp.select();
122
- document.execCommand('copy');
123
- document.body.removeChild(tmp);
124
- focus.focus();
125
-
126
- this.setState({ copied: true }, () => {
127
- window.setTimeout(() => this.setState({ copied: false }), 1500);
128
- });
129
- };
130
-
131
- render() {
132
- const {
133
- children,
134
- language = 'jsx',
135
- copyable,
136
- bordered,
137
- padded,
138
- format,
139
- className,
140
- ...rest
141
- } = this.props;
142
- const { copied } = this.state;
143
-
144
- return children ? (
145
- <Wrapper bordered={bordered} padded={padded} className={className}>
146
- <Scroller>
147
- <ReactSyntaxHighlighter
148
- padded={padded || bordered}
149
- language={language}
150
- useInlineStyles={false}
151
- PreTag={Pre}
152
- CodeTag={Code}
153
- lineNumberContainerStyle={{}}
154
- {...rest}
155
- >
156
- {format ? formatter((children as string).trim()) : (children as string).trim()}
157
- </ReactSyntaxHighlighter>
158
- </Scroller>
159
- {copyable ? (
160
- <ActionBar actionItems={[{ title: copied ? 'Copied' : 'Copy', onClick: this.onClick }]} />
161
- ) : null}
162
- </Wrapper>
163
- ) : null;
164
- }
165
- }