@redocly/theme 0.1.2 → 0.1.3
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.
- package/Button/Button.d.ts +17 -0
- package/Button/Button.js +34 -0
- package/Button/index.d.ts +1 -0
- package/Button/index.js +1 -0
- package/CodeBlock/CodeBlock.d.ts +1 -0
- package/CodeBlock/CodeBlock.js +7 -0
- package/CodeBlock/index.d.ts +1 -0
- package/CodeBlock/index.js +1 -0
- package/CopyButton/CopyButton.d.ts +6 -0
- package/CopyButton/CopyButton.js +69 -0
- package/CopyButton/CopyButtonWrapper.d.ts +9 -0
- package/CopyButton/CopyButtonWrapper.js +37 -0
- package/CopyButton/index.d.ts +2 -0
- package/CopyButton/index.js +2 -0
- package/Headings/Headings.d.ts +3 -0
- package/Headings/Headings.js +10 -0
- package/Headings/index.d.ts +1 -0
- package/Headings/index.js +1 -0
- package/JsonViewer/JsonViewer.d.ts +10 -0
- package/JsonViewer/JsonViewer.js +92 -0
- package/JsonViewer/index.d.ts +1 -0
- package/JsonViewer/index.js +1 -0
- package/JsonViewer/styled.d.ts +1 -0
- package/JsonViewer/styled.js +7 -0
- package/Logo/Logo.d.ts +10 -0
- package/Logo/Logo.js +25 -0
- package/Navbar/Navbar.d.ts +9 -0
- package/Navbar/Navbar.js +23 -0
- package/Navbar/NavbarItem.d.ts +40 -0
- package/Navbar/NavbarItem.js +43 -0
- package/Navbar/NavbarMenu.d.ts +4 -0
- package/Navbar/NavbarMenu.js +29 -0
- package/Panel/CodePanel.d.ts +1 -0
- package/Panel/CodePanel.js +13 -0
- package/Panel/ContentPanel.d.ts +1 -0
- package/Panel/ContentPanel.js +12 -0
- package/Panel/DarkHeader.d.ts +1 -0
- package/Panel/DarkHeader.js +7 -0
- package/Panel/Panel.d.ts +2 -0
- package/Panel/Panel.js +10 -0
- package/Panel/PanelBody.d.ts +6 -0
- package/Panel/PanelBody.js +15 -0
- package/Panel/PanelComponent.d.ts +10 -0
- package/Panel/PanelComponent.js +40 -0
- package/Panel/PanelHeader.d.ts +7 -0
- package/Panel/PanelHeader.js +16 -0
- package/Panel/PanelHeaderTitle.d.ts +1 -0
- package/Panel/PanelHeaderTitle.js +7 -0
- package/Panel/index.d.ts +7 -0
- package/Panel/index.js +7 -0
- package/SamplesPanelControls/SamplesPanelControls.d.ts +4 -0
- package/SamplesPanelControls/SamplesPanelControls.js +17 -0
- package/SamplesPanelControls/index.d.ts +1 -0
- package/SamplesPanelControls/index.js +1 -0
- package/SidebarLogo/SidebarLogo.d.ts +9 -0
- package/SidebarLogo/SidebarLogo.js +29 -0
- package/SidebarLogo/index.d.ts +1 -0
- package/SidebarLogo/index.js +1 -0
- package/SourceCode/SourceCode.d.ts +24 -0
- package/SourceCode/SourceCode.js +31 -0
- package/SourceCode/index.d.ts +1 -0
- package/SourceCode/index.js +1 -0
- package/Tooltip/Tooltip.d.ts +12 -0
- package/Tooltip/Tooltip.js +57 -0
- package/Tooltip/index.d.ts +1 -0
- package/Tooltip/index.js +1 -0
- package/globalStyle.d.ts +1 -0
- package/globalStyle.js +7 -0
- package/hooks/index.d.ts +3 -0
- package/hooks/index.js +3 -0
- package/hooks/useControl.d.ts +6 -0
- package/hooks/useControl.js +12 -0
- package/hooks/useMount.d.ts +1 -0
- package/hooks/useMount.js +7 -0
- package/hooks/useUnmount.d.ts +1 -0
- package/hooks/useUnmount.js +9 -0
- package/icons/ShelfIcon/ShelfIcon.d.ts +10 -0
- package/icons/ShelfIcon/ShelfIcon.js +33 -0
- package/icons/ShelfIcon/index.d.ts +2 -0
- package/icons/ShelfIcon/index.js +1 -0
- package/icons/index.d.ts +1 -0
- package/icons/index.js +1 -0
- package/index.d.ts +14 -0
- package/mocks/Link.d.ts +2 -0
- package/mocks/Link.js +17 -0
- package/mocks/utils.d.ts +1 -0
- package/mocks/utils.js +3 -0
- package/package.json +1 -4
- package/src/Button/Button.stories.tsx +74 -0
- package/src/Button/Button.tsx +122 -0
- package/src/Button/__tests__/Button.test.tsx +42 -0
- package/src/Button/__tests__/__snapshots__/Button.test.tsx.snap +274 -0
- package/src/Button/index.ts +1 -0
- package/src/CodeBlock/CodeBlock.ts +125 -0
- package/src/CodeBlock/__tests__/CodeBlock.test.tsx +12 -0
- package/src/CodeBlock/__tests__/__snapshots__/CodeBlock.test.tsx.snap +140 -0
- package/src/CodeBlock/index.ts +1 -0
- package/src/CopyButton/CopyButton.stories.tsx +18 -0
- package/src/CopyButton/CopyButton.tsx +26 -0
- package/src/CopyButton/CopyButtonWrapper.tsx +52 -0
- package/src/CopyButton/__tests__/CopyButton.test.tsx +35 -0
- package/src/CopyButton/__tests__/CopyButtonWrapper.test.tsx +16 -0
- package/src/CopyButton/__tests__/__snapshots__/CopyButton.test.tsx.snap +55 -0
- package/src/CopyButton/__tests__/__snapshots__/CopyButtonWrapper.test.tsx.snap +46 -0
- package/src/CopyButton/index.ts +2 -0
- package/src/Headings/Headings.stories.tsx +36 -0
- package/src/Headings/Headings.ts +23 -0
- package/src/Headings/__tests__/Headings.test.tsx +24 -0
- package/src/Headings/__tests__/__snapshots__/Headings.test.tsx.snap +57 -0
- package/src/Headings/index.ts +1 -0
- package/src/Introduction.stories.mdx +7 -0
- package/src/JsonViewer/JsonViewer.stories.tsx +57 -0
- package/src/JsonViewer/JsonViewer.tsx +130 -0
- package/src/JsonViewer/__tests__/JsonViewer.test.tsx +82 -0
- package/src/JsonViewer/__tests__/__snapshots__/JsonViewer.test.tsx.snap +2728 -0
- package/src/JsonViewer/index.ts +1 -0
- package/src/JsonViewer/styled.ts +103 -0
- package/src/Logo/Logo.tsx +23 -0
- package/src/Navbar/Navbar.stories.tsx +38 -0
- package/src/Navbar/Navbar.tsx +60 -0
- package/src/Navbar/NavbarItem.tsx +90 -0
- package/src/Navbar/NavbarMenu.tsx +29 -0
- package/src/Panel/CodePanel.stories.tsx +27 -0
- package/src/Panel/CodePanel.ts +31 -0
- package/src/Panel/ContentPanel.stories.tsx +27 -0
- package/src/Panel/ContentPanel.ts +43 -0
- package/src/Panel/DarkHeader.ts +8 -0
- package/src/Panel/Panel.stories.tsx +58 -0
- package/src/Panel/Panel.ts +18 -0
- package/src/Panel/PanelBody.ts +30 -0
- package/src/Panel/PanelComponent.tsx +73 -0
- package/src/Panel/PanelHeader.ts +25 -0
- package/src/Panel/PanelHeaderTitle.ts +11 -0
- package/src/Panel/__tests__/CodePanel.test.tsx +26 -0
- package/src/Panel/__tests__/ContentPanel.test.tsx +26 -0
- package/src/Panel/__tests__/Panel.test.tsx +54 -0
- package/src/Panel/__tests__/__snapshots__/CodePanel.test.tsx.snap +258 -0
- package/src/Panel/__tests__/__snapshots__/ContentPanel.test.tsx.snap +278 -0
- package/src/Panel/__tests__/__snapshots__/Panel.test.tsx.snap +398 -0
- package/src/Panel/index.ts +7 -0
- package/src/SamplesPanelControls/SamplesControlButton.stories.tsx +18 -0
- package/src/SamplesPanelControls/SamplesPanelControls.ts +70 -0
- package/src/SamplesPanelControls/__tests__/SamplesPanelControls.test.tsx +36 -0
- package/src/SamplesPanelControls/__tests__/__snapshots__/SamplesPanelControls.test.tsx.snap +228 -0
- package/src/SamplesPanelControls/index.ts +1 -0
- package/src/SidebarLogo/SidebarLogo.stories.tsx +21 -0
- package/src/SidebarLogo/SidebarLogo.tsx +47 -0
- package/src/SidebarLogo/__tests__/SidebarLogo.test.tsx +32 -0
- package/src/SidebarLogo/__tests__/__snapshots__/SidebarLogo.test.tsx.snap +62 -0
- package/src/SidebarLogo/index.ts +1 -0
- package/src/SourceCode/SourceCode.stories.tsx +29 -0
- package/src/SourceCode/SourceCode.tsx +67 -0
- package/src/SourceCode/__tests__/SourceCode.test.tsx +47 -0
- package/src/SourceCode/__tests__/__snapshots__/SourceCode.test.tsx.snap +786 -0
- package/src/SourceCode/index.ts +1 -0
- package/src/Tooltip/Tooltip.stories.tsx +27 -0
- package/src/Tooltip/Tooltip.tsx +171 -0
- package/src/Tooltip/__tests__/Tooltip.test.tsx +41 -0
- package/src/Tooltip/__tests__/__snapshots__/Tooltip.test.tsx.snap +83 -0
- package/src/Tooltip/index.ts +1 -0
- package/src/globalStyle.ts +512 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useControl.ts +20 -0
- package/src/hooks/useMount.ts +8 -0
- package/src/hooks/useUnmount.ts +10 -0
- package/src/icons/ShelfIcon/ShelfIcon.stories.tsx +36 -0
- package/src/icons/ShelfIcon/ShelfIcon.tsx +45 -0
- package/src/icons/ShelfIcon/__tests__/ShelfIcon.test.tsx +54 -0
- package/src/icons/ShelfIcon/__tests__/__snapshots__/ShelfIcon.test.tsx.snap +235 -0
- package/src/icons/ShelfIcon/index.ts +2 -0
- package/src/icons/index.ts +1 -0
- package/src/index.ts +14 -0
- package/src/mocks/Link.tsx +7 -0
- package/src/mocks/utils.ts +3 -0
- package/src/utils/ClipboardService.ts +92 -0
- package/src/utils/__tests__/ClipboardService.test.ts +24 -0
- package/src/utils/__tests__/__snapshots__/highlight.test.ts.snap +5 -0
- package/src/utils/__tests__/__snapshots__/jsonToHtml.test.ts.snap +5 -0
- package/src/utils/__tests__/css-variables.test.ts +20 -0
- package/src/utils/__tests__/highlight.test.ts +51 -0
- package/src/utils/__tests__/jsonToHtml.test.ts +40 -0
- package/src/utils/__tests__/media-css.test.ts +20 -0
- package/src/utils/__tests__/theme-helpers.test.ts +25 -0
- package/src/utils/css-variables.ts +2 -0
- package/src/utils/highlight.ts +81 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/jsonToHtml.ts +122 -0
- package/src/utils/media-css.ts +16 -0
- package/src/utils/theme-helpers.ts +34 -0
- package/utils/ClipboardService.d.ts +8 -0
- package/utils/ClipboardService.js +83 -0
- package/utils/css-variables.d.ts +1 -0
- package/utils/css-variables.js +4 -0
- package/utils/highlight.d.ts +32 -0
- package/utils/highlight.js +65 -0
- package/utils/index.d.ts +6 -0
- package/utils/index.js +6 -0
- package/utils/jsonToHtml.d.ts +1 -0
- package/utils/jsonToHtml.js +116 -0
- package/utils/media-css.d.ts +12 -0
- package/utils/media-css.js +9 -0
- package/utils/theme-helpers.d.ts +3 -0
- package/utils/theme-helpers.js +27 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { CodeBlock } from '../CodeBlock';
|
|
5
|
+
|
|
6
|
+
describe('CodeBlock', () => {
|
|
7
|
+
it('renders', () => {
|
|
8
|
+
const { container } = render(<CodeBlock>Test</CodeBlock>);
|
|
9
|
+
|
|
10
|
+
expect(container.firstChild).toMatchSnapshot();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`CodeBlock renders 1`] = `
|
|
4
|
+
.c0 {
|
|
5
|
+
max-height: var(--code-block-max-height,600px);
|
|
6
|
+
word-break: var(--code-block-word-break,initial);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.c0 code[class*='language-'],
|
|
10
|
+
.c0 pre[class*='language-'] {
|
|
11
|
+
text-shadow: 0 -0.1em 0.2em black;
|
|
12
|
+
text-align: left;
|
|
13
|
+
white-space: pre;
|
|
14
|
+
word-spacing: normal;
|
|
15
|
+
word-break: normal;
|
|
16
|
+
word-wrap: normal;
|
|
17
|
+
line-height: 1.5;
|
|
18
|
+
-moz-tab-size: 4;
|
|
19
|
+
-o-tab-size: 4;
|
|
20
|
+
tab-size: 4;
|
|
21
|
+
-webkit-hyphens: none;
|
|
22
|
+
-moz-hyphens: none;
|
|
23
|
+
-ms-hyphens: none;
|
|
24
|
+
-webkit-hyphens: none;
|
|
25
|
+
-moz-hyphens: none;
|
|
26
|
+
-ms-hyphens: none;
|
|
27
|
+
hyphens: none;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.c0 pre[class*='language-'] {
|
|
31
|
+
padding: 1em;
|
|
32
|
+
margin: 0.5em 0;
|
|
33
|
+
overflow: auto;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.c0 .token.comment,
|
|
37
|
+
.c0 .token.prolog,
|
|
38
|
+
.c0 .token.doctype,
|
|
39
|
+
.c0 .token.cdata {
|
|
40
|
+
color: hsl(30,20%,50%);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.c0 .token.punctuation {
|
|
44
|
+
opacity: 1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.c0 .namespace {
|
|
48
|
+
opacity: 0.7;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.c0 .token.property,
|
|
52
|
+
.c0 .token.tag,
|
|
53
|
+
.c0 .token.number,
|
|
54
|
+
.c0 .token.constant,
|
|
55
|
+
.c0 .token.symbol {
|
|
56
|
+
color: var(--color-content-inverse);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.c0 .token.boolean {
|
|
60
|
+
color: var(--color-error-500);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.c0 .token.selector,
|
|
64
|
+
.c0 .token.attr-name,
|
|
65
|
+
.c0 .token.string,
|
|
66
|
+
.c0 .token.char,
|
|
67
|
+
.c0 .token.builtin,
|
|
68
|
+
.c0 .token.inserted {
|
|
69
|
+
color: #fee39e;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.c0 .token.selector + a,
|
|
73
|
+
.c0 .token.attr-name + a,
|
|
74
|
+
.c0 .token.string + a,
|
|
75
|
+
.c0 .token.char + a,
|
|
76
|
+
.c0 .token.builtin + a,
|
|
77
|
+
.c0 .token.inserted + a,
|
|
78
|
+
.c0 .token.selector + a:visited,
|
|
79
|
+
.c0 .token.attr-name + a:visited,
|
|
80
|
+
.c0 .token.string + a:visited,
|
|
81
|
+
.c0 .token.char + a:visited,
|
|
82
|
+
.c0 .token.builtin + a:visited,
|
|
83
|
+
.c0 .token.inserted + a:visited {
|
|
84
|
+
color: #4ed2ba;
|
|
85
|
+
-webkit-text-decoration: underline;
|
|
86
|
+
text-decoration: underline;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.c0 .token.property.string {
|
|
90
|
+
color: #9efaa7;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.c0 .token.operator,
|
|
94
|
+
.c0 .token.entity,
|
|
95
|
+
.c0 .token.url,
|
|
96
|
+
.c0 .token.variable {
|
|
97
|
+
color: #f5b83d;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.c0 .token.atrule,
|
|
101
|
+
.c0 .token.attr-value,
|
|
102
|
+
.c0 .token.keyword {
|
|
103
|
+
color: #ffdbf4;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.c0 .token.regex,
|
|
107
|
+
.c0 .token.important {
|
|
108
|
+
color: #e90;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.c0 .token.important,
|
|
112
|
+
.c0 .token.bold {
|
|
113
|
+
font-weight: bold;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.c0 .token.italic {
|
|
117
|
+
font-style: italic;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.c0 .token.entity {
|
|
121
|
+
cursor: help;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.c0 .token.deleted {
|
|
125
|
+
color: red;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@media print {
|
|
129
|
+
.c0 code[class*='language-'],
|
|
130
|
+
.c0 pre[class*='language-'] {
|
|
131
|
+
text-shadow: none;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
<div
|
|
136
|
+
class="c0"
|
|
137
|
+
>
|
|
138
|
+
Test
|
|
139
|
+
</div>
|
|
140
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CodeBlock';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import { CopyButton } from './CopyButton';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'CopyButton',
|
|
8
|
+
component: CopyButton,
|
|
9
|
+
} as ComponentMeta<typeof CopyButton>;
|
|
10
|
+
|
|
11
|
+
const Template: ComponentStory<typeof CopyButton> = (args) => (
|
|
12
|
+
<CopyButton {...args}>Copy</CopyButton>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const Default = Template.bind({});
|
|
16
|
+
Default.args = {
|
|
17
|
+
text: 'Something useful',
|
|
18
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Button } from '../Button';
|
|
4
|
+
|
|
5
|
+
export interface CopyButtonProps {
|
|
6
|
+
text: string;
|
|
7
|
+
dataTestId?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const CopyButton = ({ text, dataTestId = 'copy-button' }: CopyButtonProps): JSX.Element => {
|
|
11
|
+
const [title, setTitle] = useState('Copy');
|
|
12
|
+
|
|
13
|
+
async function write() {
|
|
14
|
+
await navigator.clipboard.writeText(text);
|
|
15
|
+
|
|
16
|
+
setTitle('Copied!');
|
|
17
|
+
|
|
18
|
+
setTimeout(() => setTitle('Copy'), 1500);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Button color="secondary" onClick={write} data-cy={dataTestId}>
|
|
23
|
+
{title}
|
|
24
|
+
</Button>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React, { memo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { SamplesControlButton } from '../SamplesPanelControls';
|
|
4
|
+
import { Tooltip } from '../Tooltip';
|
|
5
|
+
import { useControl } from '../hooks';
|
|
6
|
+
import { ClipboardService } from '../utils';
|
|
7
|
+
|
|
8
|
+
export interface CopyButtonWrapperProps {
|
|
9
|
+
data: unknown;
|
|
10
|
+
children: (props: { renderCopyButton: () => JSX.Element }) => JSX.Element;
|
|
11
|
+
dataTestId?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function CopyButtonWrapperComponent({
|
|
15
|
+
data,
|
|
16
|
+
children,
|
|
17
|
+
dataTestId = 'copy-button',
|
|
18
|
+
}: CopyButtonWrapperProps): JSX.Element {
|
|
19
|
+
const tooltip = useControl();
|
|
20
|
+
|
|
21
|
+
const showTooltip = (): void => {
|
|
22
|
+
tooltip.handleOpen();
|
|
23
|
+
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
tooltip.handleClose();
|
|
26
|
+
}, 1500);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const copy = (): void => {
|
|
30
|
+
const content = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
|
|
31
|
+
ClipboardService.copyCustom(content);
|
|
32
|
+
showTooltip();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const renderCopyButton = (): JSX.Element => {
|
|
36
|
+
return (
|
|
37
|
+
<Tooltip
|
|
38
|
+
className="copy-button"
|
|
39
|
+
tip={ClipboardService.isSupported() ? 'Copied' : 'Not supported in your browser'}
|
|
40
|
+
open={tooltip.isOpened}
|
|
41
|
+
>
|
|
42
|
+
<SamplesControlButton onClick={copy} data-cy={dataTestId}>
|
|
43
|
+
Copy
|
|
44
|
+
</SamplesControlButton>
|
|
45
|
+
</Tooltip>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return children({ renderCopyButton });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const CopyButtonWrapper = memo<CopyButtonWrapperProps>(CopyButtonWrapperComponent);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent, getByText, render } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { CopyButton } from '../CopyButton';
|
|
5
|
+
|
|
6
|
+
const mockSetState = jest.fn();
|
|
7
|
+
|
|
8
|
+
jest.mock('react', () => {
|
|
9
|
+
const original = jest.requireActual('react');
|
|
10
|
+
return {
|
|
11
|
+
...original,
|
|
12
|
+
useState: (initial: any) => [initial, mockSetState],
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('CopyButton', () => {
|
|
17
|
+
it('renders', () => {
|
|
18
|
+
const { container } = render(<CopyButton text="test copy" dataTestId="copy" />);
|
|
19
|
+
|
|
20
|
+
expect(container.firstChild).toMatchSnapshot();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('changes button text on click', () => {
|
|
24
|
+
Object.assign(navigator, {
|
|
25
|
+
clipboard: { writeText: jest.fn() },
|
|
26
|
+
});
|
|
27
|
+
const textToCopy = 'test copy';
|
|
28
|
+
const { container } = render(<CopyButton text={textToCopy} />);
|
|
29
|
+
const button = getByText(container, /Copy/);
|
|
30
|
+
|
|
31
|
+
fireEvent.click(button);
|
|
32
|
+
|
|
33
|
+
expect(navigator.clipboard.writeText).toBeCalledWith(textToCopy);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { renderWithTheme } from '../../../tests/utils';
|
|
4
|
+
import { CopyButtonWrapper } from '../CopyButtonWrapper';
|
|
5
|
+
|
|
6
|
+
describe('CopyButtonWrapper', () => {
|
|
7
|
+
it('renders', () => {
|
|
8
|
+
const { container } = renderWithTheme(
|
|
9
|
+
<CopyButtonWrapper data="Something" dataTestId="copy">
|
|
10
|
+
{({ renderCopyButton }) => <div>{renderCopyButton()}</div>}
|
|
11
|
+
</CopyButtonWrapper>,
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
expect(container.firstChild).toMatchSnapshot();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`CopyButton renders 1`] = `
|
|
4
|
+
.c1 {
|
|
5
|
+
-webkit-text-decoration: none;
|
|
6
|
+
text-decoration: none;
|
|
7
|
+
text-align: center;
|
|
8
|
+
width: auto;
|
|
9
|
+
outline: none;
|
|
10
|
+
border: none;
|
|
11
|
+
border-radius: var(--button-border-radius);
|
|
12
|
+
font-weight: var(--button-font-weight);
|
|
13
|
+
font-size: 14px;
|
|
14
|
+
padding: 2px 20px;
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
-webkit-transition: background-color 0.25s ease,border-color 0.25s ease,box-shadow 0.25s ease;
|
|
17
|
+
transition: background-color 0.25s ease,border-color 0.25s ease,box-shadow 0.25s ease;
|
|
18
|
+
line-height: 1;
|
|
19
|
+
font-family: var(--button-font-family);
|
|
20
|
+
box-shadow: var(--button-box-shadow);
|
|
21
|
+
color: var(--button-color);
|
|
22
|
+
background-color: var(--button-background-color);
|
|
23
|
+
font-size: var(--button-medium-font-size);
|
|
24
|
+
padding: var(--button-medium-padding);
|
|
25
|
+
min-width: var(--button-medium-min-width);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.c1:hover {
|
|
29
|
+
box-shadow: var(--button-active-box-shadow);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.c1:active {
|
|
33
|
+
box-shadow: var(--button-active-box-shadow);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.c1:hover {
|
|
37
|
+
background-color: var(--button-hover-background-color);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.c1:active {
|
|
41
|
+
background-color: var(--button-active-background-color);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.c0 + .c0 {
|
|
45
|
+
margin-left: 0.85em;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
<button
|
|
49
|
+
class="c0 c1 button-color-secondary"
|
|
50
|
+
color="secondary"
|
|
51
|
+
data-cy="copy"
|
|
52
|
+
>
|
|
53
|
+
Copy
|
|
54
|
+
</button>
|
|
55
|
+
`;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`CopyButtonWrapper renders 1`] = `
|
|
4
|
+
.c1 {
|
|
5
|
+
background-color: var(--samples-panel-controls-background-color);
|
|
6
|
+
border: 0;
|
|
7
|
+
outline: 0;
|
|
8
|
+
border-radius: var(--global-border-radius);
|
|
9
|
+
height: 20px;
|
|
10
|
+
color: var(--color-content-inverse);
|
|
11
|
+
font-size: 12px;
|
|
12
|
+
line-height: 12px;
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
padding: 1px 6px;
|
|
15
|
+
min-width: 90px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.c1:hover,
|
|
19
|
+
.c1:focus {
|
|
20
|
+
background-color: var(--samples-panel-controls-hover-background-color);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.c0 {
|
|
24
|
+
position: relative;
|
|
25
|
+
display: inline-block;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@media screen and (min-width:50rem) {
|
|
29
|
+
.c1 {
|
|
30
|
+
padding: 2px 20px;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
<div>
|
|
35
|
+
<div
|
|
36
|
+
class="c0 tooltip-copy-button"
|
|
37
|
+
>
|
|
38
|
+
<button
|
|
39
|
+
class="c1"
|
|
40
|
+
data-cy="copy"
|
|
41
|
+
>
|
|
42
|
+
Copy
|
|
43
|
+
</button>
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
`;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { H1, H2, H3 } from './Headings';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Typography/Headings',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const Heading1 = (): JSX.Element => <H1>H1</H1>;
|
|
10
|
+
Heading1.storyName = 'H1';
|
|
11
|
+
Heading1.parameters = {
|
|
12
|
+
controls: { hideNoControlsWarning: true },
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const Heading2 = (): JSX.Element => <H2>H2</H2>;
|
|
16
|
+
Heading2.storyName = 'H2';
|
|
17
|
+
Heading2.parameters = {
|
|
18
|
+
controls: { hideNoControlsWarning: true },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const Heading3 = (): JSX.Element => <H3>H3</H3>;
|
|
22
|
+
Heading3.storyName = 'H3';
|
|
23
|
+
Heading3.parameters = {
|
|
24
|
+
controls: { hideNoControlsWarning: true },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const AllHeadings = (): JSX.Element => (
|
|
28
|
+
<>
|
|
29
|
+
<H1>H1</H1>
|
|
30
|
+
<H2>H2</H2>
|
|
31
|
+
<H3>H3</H3>
|
|
32
|
+
</>
|
|
33
|
+
);
|
|
34
|
+
AllHeadings.parameters = {
|
|
35
|
+
controls: { hideNoControlsWarning: true },
|
|
36
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
|
|
3
|
+
import { typography } from '../utils';
|
|
4
|
+
|
|
5
|
+
export const H1 = styled.h1`
|
|
6
|
+
color: var(--color-content);
|
|
7
|
+
margin: 0 0 25px;
|
|
8
|
+
|
|
9
|
+
${typography('h1', 'h')};
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
export const H2 = styled.h2`
|
|
13
|
+
color: var(--color-content);
|
|
14
|
+
margin: 0 0 20px;
|
|
15
|
+
|
|
16
|
+
${typography('h2', 'h')};
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
export const H3 = styled.h3`
|
|
20
|
+
color: var(--color-content);
|
|
21
|
+
|
|
22
|
+
${typography('h3', 'h')};
|
|
23
|
+
`;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { H1, H2, H3 } from '../Headings';
|
|
5
|
+
|
|
6
|
+
describe('Headings', () => {
|
|
7
|
+
it('renders H1', () => {
|
|
8
|
+
const { container } = render(<H1>H1</H1>);
|
|
9
|
+
|
|
10
|
+
expect(container.firstChild).toMatchSnapshot();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('renders H2', () => {
|
|
14
|
+
const { container } = render(<H2>H2</H2>);
|
|
15
|
+
|
|
16
|
+
expect(container.firstChild).toMatchSnapshot();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('renders H3', () => {
|
|
20
|
+
const { container } = render(<H3>H3</H3>);
|
|
21
|
+
|
|
22
|
+
expect(container.firstChild).toMatchSnapshot();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Headings renders H1 1`] = `
|
|
4
|
+
.c0 {
|
|
5
|
+
color: var(--color-content);
|
|
6
|
+
margin: 0 0 25px;
|
|
7
|
+
font-size: var(--h1-font-size,var(--h-font-size));
|
|
8
|
+
font-weight: var(--h1-font-weight,var(--h-font-weight));
|
|
9
|
+
font-family: var(--h1-font-family,var(--h-font-family));
|
|
10
|
+
line-height: var(--h1-line-height,var(--h-line-height));
|
|
11
|
+
color: var(--h1-color,var(--h-color));
|
|
12
|
+
text-transform: var(--h1-text-transform,var(--h-text-transform));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
<h1
|
|
16
|
+
class="c0"
|
|
17
|
+
>
|
|
18
|
+
H1
|
|
19
|
+
</h1>
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
exports[`Headings renders H2 1`] = `
|
|
23
|
+
.c0 {
|
|
24
|
+
color: var(--color-content);
|
|
25
|
+
margin: 0 0 20px;
|
|
26
|
+
font-size: var(--h2-font-size,var(--h-font-size));
|
|
27
|
+
font-weight: var(--h2-font-weight,var(--h-font-weight));
|
|
28
|
+
font-family: var(--h2-font-family,var(--h-font-family));
|
|
29
|
+
line-height: var(--h2-line-height,var(--h-line-height));
|
|
30
|
+
color: var(--h2-color,var(--h-color));
|
|
31
|
+
text-transform: var(--h2-text-transform,var(--h-text-transform));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
<h2
|
|
35
|
+
class="c0"
|
|
36
|
+
>
|
|
37
|
+
H2
|
|
38
|
+
</h2>
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
exports[`Headings renders H3 1`] = `
|
|
42
|
+
.c0 {
|
|
43
|
+
color: var(--color-content);
|
|
44
|
+
font-size: var(--h3-font-size,var(--h-font-size));
|
|
45
|
+
font-weight: var(--h3-font-weight,var(--h-font-weight));
|
|
46
|
+
font-family: var(--h3-font-family,var(--h-font-family));
|
|
47
|
+
line-height: var(--h3-line-height,var(--h-line-height));
|
|
48
|
+
color: var(--h3-color,var(--h-color));
|
|
49
|
+
text-transform: var(--h3-text-transform,var(--h-text-transform));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
<h3
|
|
53
|
+
class="c0"
|
|
54
|
+
>
|
|
55
|
+
H3
|
|
56
|
+
</h3>
|
|
57
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Headings';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import { JsonViewer } from './JsonViewer';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'JsonViewer',
|
|
8
|
+
component: JsonViewer,
|
|
9
|
+
} as ComponentMeta<typeof JsonViewer>;
|
|
10
|
+
|
|
11
|
+
const data = {
|
|
12
|
+
id: '600dc3b5d617e547a0e74cb9',
|
|
13
|
+
name: 'Mitchell Fitzgerald',
|
|
14
|
+
about: 'lorem ipsum',
|
|
15
|
+
address: '48 Avenue, City, North',
|
|
16
|
+
company: 'Test',
|
|
17
|
+
bio: null,
|
|
18
|
+
nicknames: [
|
|
19
|
+
'Mitch',
|
|
20
|
+
'Fitz',
|
|
21
|
+
{ title: 'MitFitz', createdAt: new Date('2022-04-19T11:46:00.019Z') },
|
|
22
|
+
],
|
|
23
|
+
age: 27,
|
|
24
|
+
isBanned: true,
|
|
25
|
+
link: 'https://google.com',
|
|
26
|
+
emptyArray: [],
|
|
27
|
+
empty: {},
|
|
28
|
+
contacts: {
|
|
29
|
+
email: 'test@mail.com',
|
|
30
|
+
phone: {
|
|
31
|
+
code: '+1',
|
|
32
|
+
rest: '999',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const Template: ComponentStory<typeof JsonViewer> = (args) => <JsonViewer {...args} />;
|
|
38
|
+
|
|
39
|
+
export const ExpandLevel1 = Template.bind({});
|
|
40
|
+
ExpandLevel1.args = {
|
|
41
|
+
jsonSampleExpandLevel: 1,
|
|
42
|
+
data,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const ExpandLevel3 = Template.bind({});
|
|
46
|
+
ExpandLevel3.args = {
|
|
47
|
+
jsonSampleExpandLevel: 3,
|
|
48
|
+
data,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const WithoutFoldingButtons = Template.bind({});
|
|
52
|
+
WithoutFoldingButtons.args = {
|
|
53
|
+
jsonSampleExpandLevel: 3,
|
|
54
|
+
data: {
|
|
55
|
+
message: 'success',
|
|
56
|
+
},
|
|
57
|
+
};
|