@redocly/theme 0.1.10 → 0.1.11

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 (37) hide show
  1. package/Navbar/NavbarMenu.js +1 -1
  2. package/Search/ClearIcon.js +1 -1
  3. package/Search/SearchIcon.js +1 -1
  4. package/TableOfContent/TableOfContent.js +5 -6
  5. package/globalStyle.d.ts +1 -0
  6. package/globalStyle.js +7 -3
  7. package/mocks/Link.js +4 -1
  8. package/mocks/hooks/usePageData.js +4 -1
  9. package/package.json +1 -1
  10. package/src/DesignTokens/borders.stories.mdx +20 -0
  11. package/src/DesignTokens/colors.stories.mdx +24 -0
  12. package/src/DesignTokens/page-layout.stories.mdx +12 -0
  13. package/src/DesignTokens/tokens-generated.scss +610 -0
  14. package/src/DesignTokens/typography.stories.mdx +36 -0
  15. package/src/Navbar/Navbar.stories.tsx +1 -1
  16. package/src/Navbar/NavbarMenu.tsx +1 -1
  17. package/src/Navbar/__tests__/Navbar.test.tsx +55 -0
  18. package/src/Navbar/__tests__/__snapshots__/Navbar.test.tsx.snap +256 -0
  19. package/src/NavbarLogo/NavbarLogo.stories.tsx +1 -1
  20. package/src/PageNavigation/PageNavigation.stories.tsx +21 -0
  21. package/src/PageNavigation/__tests__/NextPageLink.test.tsx +29 -0
  22. package/src/PageNavigation/__tests__/PageNavigation.test.tsx +54 -0
  23. package/src/PageNavigation/__tests__/PreviousPageLink.test.tsx +29 -0
  24. package/src/PageNavigation/__tests__/__snapshots__/NextPageLink.test.tsx.snap +67 -0
  25. package/src/PageNavigation/__tests__/__snapshots__/PageNavigation.test.tsx.snap +275 -0
  26. package/src/PageNavigation/__tests__/__snapshots__/PreviousPageLink.test.tsx.snap +67 -0
  27. package/src/Search/ClearIcon.tsx +11 -12
  28. package/src/Search/SearchIcon.tsx +11 -12
  29. package/src/Search/__tests__/Input.test.tsx +13 -0
  30. package/src/Search/__tests__/__snapshots__/Input.test.tsx.snap +36 -0
  31. package/src/TableOfContent/TableOfContent.stories.tsx +5 -7
  32. package/src/TableOfContent/TableOfContent.tsx +6 -4
  33. package/src/TableOfContent/__tests__/TableOfContent.test.tsx +61 -0
  34. package/src/TableOfContent/__tests__/__snapshots__/TableOfContent.test.tsx.snap +153 -0
  35. package/src/globalStyle.ts +232 -138
  36. package/src/mocks/Link.tsx +5 -2
  37. package/src/mocks/hooks/usePageData.ts +4 -1
@@ -0,0 +1,275 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`PageNavigation renders 1`] = `
4
+ .c2 {
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-background-color);
22
+ border: 2px solid var(--button-background-color);
23
+ background-color: transparent;
24
+ font-size: var(--button-large-font-size);
25
+ padding: var(--button-large-padding);
26
+ min-width: var(--button-large-min-width);
27
+ }
28
+
29
+ .c2:hover {
30
+ box-shadow: var(--button-active-box-shadow);
31
+ }
32
+
33
+ .c2:active {
34
+ box-shadow: var(--button-active-box-shadow);
35
+ }
36
+
37
+ .c2:hover {
38
+ border: 2px solid var(--button-active-background-color);
39
+ background-color: transparent;
40
+ }
41
+
42
+ .c2:active {
43
+ border: 2px solid var(--button-outlined-active-border-color);
44
+ }
45
+
46
+ .c1 + .c1 {
47
+ margin-left: 0.85em;
48
+ }
49
+
50
+ .c0 {
51
+ display: -webkit-box;
52
+ display: -webkit-flex;
53
+ display: -ms-flexbox;
54
+ display: flex;
55
+ -webkit-box-pack: justify;
56
+ -webkit-justify-content: space-between;
57
+ -ms-flex-pack: justify;
58
+ justify-content: space-between;
59
+ margin: 25px 0px;
60
+ }
61
+
62
+ <div
63
+ class="c0"
64
+ data-component-name="PageNavigation/PageNavigation"
65
+ >
66
+ <a
67
+ class="c1 c2 button-color-default"
68
+ data-component-name="ui/Button"
69
+ href="https://previous-page"
70
+ role="button"
71
+ to="https://previous-page"
72
+ variant="outlined"
73
+ >
74
+ Back to
75
+ The Previous Page
76
+ </a>
77
+ <a
78
+ class="c1 c2 button-color-default"
79
+ data-component-name="ui/Button"
80
+ href="https://next-page"
81
+ role="button"
82
+ to="https://next-page"
83
+ variant="outlined"
84
+ >
85
+ Next to
86
+ The Next Page
87
+ </a>
88
+ </div>
89
+ `;
90
+
91
+ exports[`PageNavigation renders with missing next and previous pages 1`] = `
92
+ .c0 {
93
+ display: -webkit-box;
94
+ display: -webkit-flex;
95
+ display: -ms-flexbox;
96
+ display: flex;
97
+ -webkit-box-pack: justify;
98
+ -webkit-justify-content: space-between;
99
+ -ms-flex-pack: justify;
100
+ justify-content: space-between;
101
+ margin: 25px 0px;
102
+ }
103
+
104
+ <div
105
+ class="c0"
106
+ data-component-name="PageNavigation/PageNavigation"
107
+ >
108
+ <div>
109
+  
110
+ </div>
111
+ <div>
112
+  
113
+ </div>
114
+ </div>
115
+ `;
116
+
117
+ exports[`PageNavigation renders with next page only 1`] = `
118
+ .c2 {
119
+ -webkit-text-decoration: none;
120
+ text-decoration: none;
121
+ text-align: center;
122
+ width: auto;
123
+ outline: none;
124
+ border: none;
125
+ border-radius: var(--button-border-radius);
126
+ font-weight: var(--button-font-weight);
127
+ font-size: 14px;
128
+ padding: 2px 20px;
129
+ cursor: pointer;
130
+ -webkit-transition: background-color 0.25s ease,border-color 0.25s ease,box-shadow 0.25s ease;
131
+ transition: background-color 0.25s ease,border-color 0.25s ease,box-shadow 0.25s ease;
132
+ line-height: 1;
133
+ font-family: var(--button-font-family);
134
+ box-shadow: var(--button-box-shadow);
135
+ color: var(--button-background-color);
136
+ border: 2px solid var(--button-background-color);
137
+ background-color: transparent;
138
+ font-size: var(--button-large-font-size);
139
+ padding: var(--button-large-padding);
140
+ min-width: var(--button-large-min-width);
141
+ }
142
+
143
+ .c2:hover {
144
+ box-shadow: var(--button-active-box-shadow);
145
+ }
146
+
147
+ .c2:active {
148
+ box-shadow: var(--button-active-box-shadow);
149
+ }
150
+
151
+ .c2:hover {
152
+ border: 2px solid var(--button-active-background-color);
153
+ background-color: transparent;
154
+ }
155
+
156
+ .c2:active {
157
+ border: 2px solid var(--button-outlined-active-border-color);
158
+ }
159
+
160
+ .c1 + .c1 {
161
+ margin-left: 0.85em;
162
+ }
163
+
164
+ .c0 {
165
+ display: -webkit-box;
166
+ display: -webkit-flex;
167
+ display: -ms-flexbox;
168
+ display: flex;
169
+ -webkit-box-pack: justify;
170
+ -webkit-justify-content: space-between;
171
+ -ms-flex-pack: justify;
172
+ justify-content: space-between;
173
+ margin: 25px 0px;
174
+ }
175
+
176
+ <div
177
+ class="c0"
178
+ data-component-name="PageNavigation/PageNavigation"
179
+ >
180
+ <div>
181
+  
182
+ </div>
183
+ <a
184
+ class="c1 c2 button-color-default"
185
+ data-component-name="ui/Button"
186
+ href="https://next-page"
187
+ role="button"
188
+ to="https://next-page"
189
+ variant="outlined"
190
+ >
191
+ Next to
192
+ The Next Page
193
+ </a>
194
+ </div>
195
+ `;
196
+
197
+ exports[`PageNavigation renders with previous page only 1`] = `
198
+ .c2 {
199
+ -webkit-text-decoration: none;
200
+ text-decoration: none;
201
+ text-align: center;
202
+ width: auto;
203
+ outline: none;
204
+ border: none;
205
+ border-radius: var(--button-border-radius);
206
+ font-weight: var(--button-font-weight);
207
+ font-size: 14px;
208
+ padding: 2px 20px;
209
+ cursor: pointer;
210
+ -webkit-transition: background-color 0.25s ease,border-color 0.25s ease,box-shadow 0.25s ease;
211
+ transition: background-color 0.25s ease,border-color 0.25s ease,box-shadow 0.25s ease;
212
+ line-height: 1;
213
+ font-family: var(--button-font-family);
214
+ box-shadow: var(--button-box-shadow);
215
+ color: var(--button-background-color);
216
+ border: 2px solid var(--button-background-color);
217
+ background-color: transparent;
218
+ font-size: var(--button-large-font-size);
219
+ padding: var(--button-large-padding);
220
+ min-width: var(--button-large-min-width);
221
+ }
222
+
223
+ .c2:hover {
224
+ box-shadow: var(--button-active-box-shadow);
225
+ }
226
+
227
+ .c2:active {
228
+ box-shadow: var(--button-active-box-shadow);
229
+ }
230
+
231
+ .c2:hover {
232
+ border: 2px solid var(--button-active-background-color);
233
+ background-color: transparent;
234
+ }
235
+
236
+ .c2:active {
237
+ border: 2px solid var(--button-outlined-active-border-color);
238
+ }
239
+
240
+ .c1 + .c1 {
241
+ margin-left: 0.85em;
242
+ }
243
+
244
+ .c0 {
245
+ display: -webkit-box;
246
+ display: -webkit-flex;
247
+ display: -ms-flexbox;
248
+ display: flex;
249
+ -webkit-box-pack: justify;
250
+ -webkit-justify-content: space-between;
251
+ -ms-flex-pack: justify;
252
+ justify-content: space-between;
253
+ margin: 25px 0px;
254
+ }
255
+
256
+ <div
257
+ class="c0"
258
+ data-component-name="PageNavigation/PageNavigation"
259
+ >
260
+ <a
261
+ class="c1 c2 button-color-default"
262
+ data-component-name="ui/Button"
263
+ href="https://previous-page"
264
+ role="button"
265
+ to="https://previous-page"
266
+ variant="outlined"
267
+ >
268
+ Back to
269
+ The Previous Page
270
+ </a>
271
+ <div>
272
+  
273
+ </div>
274
+ </div>
275
+ `;
@@ -0,0 +1,67 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`PreviousPageLink renders when prevPage exists 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-background-color);
22
+ border: 2px solid var(--button-background-color);
23
+ background-color: transparent;
24
+ font-size: var(--button-large-font-size);
25
+ padding: var(--button-large-padding);
26
+ min-width: var(--button-large-min-width);
27
+ }
28
+
29
+ .c1:hover {
30
+ box-shadow: var(--button-active-box-shadow);
31
+ }
32
+
33
+ .c1:active {
34
+ box-shadow: var(--button-active-box-shadow);
35
+ }
36
+
37
+ .c1:hover {
38
+ border: 2px solid var(--button-active-background-color);
39
+ background-color: transparent;
40
+ }
41
+
42
+ .c1:active {
43
+ border: 2px solid var(--button-outlined-active-border-color);
44
+ }
45
+
46
+ .c0 + .c0 {
47
+ margin-left: 0.85em;
48
+ }
49
+
50
+ <a
51
+ class="c0 c1 button-color-default"
52
+ data-component-name="ui/Button"
53
+ href="https://test.com"
54
+ role="button"
55
+ to="https://test.com"
56
+ variant="outlined"
57
+ >
58
+ Back to
59
+ The Previous Page
60
+ </a>
61
+ `;
62
+
63
+ exports[`PreviousPageLink renders when prevPage is null 1`] = `
64
+ <div>
65
+  
66
+ </div>
67
+ `;
@@ -2,18 +2,17 @@ import React, { SVGProps } from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
4
  const Icon = (props: SVGProps<SVGSVGElement>) => (
5
- <span data-component-name="Search/ClearIcon">
6
- <svg
7
- xmlns="http://www.w3.org/2000/svg"
8
- version="1.1"
9
- x="0"
10
- y="0"
11
- viewBox="0 0 298.7 298.7"
12
- {...props}
13
- >
14
- <polygon points="298.7 30.2 268.5 0 149.3 119.1 30.2 0 0 30.2 119.1 149.3 0 268.5 30.2 298.7 149.3 179.5 268.5 298.7 298.7 268.5 179.5 149.3 " />
15
- </svg>
16
- </span>
5
+ <svg
6
+ xmlns="http://www.w3.org/2000/svg"
7
+ version="1.1"
8
+ x="0"
9
+ y="0"
10
+ viewBox="0 0 298.7 298.7"
11
+ data-component-name="Search/ClearIcon"
12
+ {...props}
13
+ >
14
+ <polygon points="298.7 30.2 268.5 0 149.3 119.1 30.2 0 0 30.2 119.1 149.3 0 268.5 30.2 298.7 149.3 179.5 268.5 298.7 298.7 268.5 179.5 149.3 " />
15
+ </svg>
17
16
  );
18
17
 
19
18
  export const ClearIcon = styled(Icon)`
@@ -2,18 +2,17 @@ import React, { SVGProps } from 'react';
2
2
  import styled from 'styled-components';
3
3
 
4
4
  const Icon = (props: SVGProps<SVGSVGElement>) => (
5
- <span data-component-name="Search/SearchIcon">
6
- <svg
7
- xmlns="http://www.w3.org/2000/svg"
8
- version="1.1"
9
- x="0"
10
- y="0"
11
- viewBox="0 0 490 490"
12
- {...props}
13
- >
14
- <path d="M484 455.2L366.2 337.4c29.2-35.6 46.8-81.2 46.8-130.9C413 92.5 320.5 0 206.5 0 92.4 0 0 92.5 0 206.5S92.4 413 206.5 413c49.7 0 95.2-17.5 130.8-46.7L455.1 484c8 8 20.9 8 28.9 0C492 476.1 492 463.1 484 455.2zM206.5 371.9C115.2 371.9 41 297.7 41 206.5S115.2 41 206.5 41C297.7 41 372 115.3 372 206.5S297.7 371.9 206.5 371.9z" />
15
- </svg>
16
- </span>
5
+ <svg
6
+ xmlns="http://www.w3.org/2000/svg"
7
+ version="1.1"
8
+ x="0"
9
+ y="0"
10
+ viewBox="0 0 490 490"
11
+ data-component-name="Search/SearchIcon"
12
+ {...props}
13
+ >
14
+ <path d="M484 455.2L366.2 337.4c29.2-35.6 46.8-81.2 46.8-130.9C413 92.5 320.5 0 206.5 0 92.4 0 0 92.5 0 206.5S92.4 413 206.5 413c49.7 0 95.2-17.5 130.8-46.7L455.1 484c8 8 20.9 8 28.9 0C492 476.1 492 463.1 484 455.2zM206.5 371.9C115.2 371.9 41 297.7 41 206.5S115.2 41 206.5 41C297.7 41 372 115.3 372 206.5S297.7 371.9 206.5 371.9z" />
15
+ </svg>
17
16
  );
18
17
 
19
18
  export const SearchIcon = styled(Icon)`
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+
3
+ import { renderWithTheme } from '../../../tests/utils';
4
+
5
+ import { FormInput } from '@theme/Search/Input';
6
+
7
+ describe('FormInput', () => {
8
+ it('renders', () => {
9
+ const { container } = renderWithTheme(<FormInput />);
10
+
11
+ expect(container.firstChild).toMatchSnapshot();
12
+ });
13
+ });
@@ -0,0 +1,36 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`FormInput renders 1`] = `
4
+ .c0 {
5
+ padding: 1em 2.5em 1em 1em;
6
+ background-color: var(--input-background-color);
7
+ border-radius: var(--input-border-radius);
8
+ border: none;
9
+ outline: none;
10
+ color: var(--input-text-color);
11
+ font-size: var(--input-font-size);
12
+ font-family: var(--input-font-family);
13
+ line-height: var(--input-line-height);
14
+ }
15
+
16
+ .c0::-webkit-input-placeholder {
17
+ color: var(--input-text-color);
18
+ }
19
+
20
+ .c0::-moz-placeholder {
21
+ color: var(--input-text-color);
22
+ }
23
+
24
+ .c0:-ms-input-placeholder {
25
+ color: var(--input-text-color);
26
+ }
27
+
28
+ .c0::placeholder {
29
+ color: var(--input-text-color);
30
+ }
31
+
32
+ <input
33
+ class="c0"
34
+ data-component-name="Search/Input"
35
+ />
36
+ `;
@@ -23,17 +23,15 @@ export default {
23
23
  ],
24
24
  } as ComponentMeta<typeof TableOfContent>;
25
25
 
26
- const Template: ComponentStory<typeof TableOfContent> = (args) => (
27
- <TableOfContent {...args}>Click</TableOfContent>
28
- );
26
+ const Template: ComponentStory<typeof TableOfContent> = (args) => <TableOfContent {...args} />;
29
27
 
30
28
  export const Default = Template.bind({});
31
29
  Default.args = {
32
30
  headings: [
33
31
  { id: '1', value: 'test 1', depth: 1 },
34
- { id: '2', value: 'test 2', depth: 1 },
35
- { id: '3', value: 'test 3', depth: 2 },
36
- { id: '4', value: 'test 4', depth: 2 },
37
- { id: '5', value: 'test 5', depth: 1 },
32
+ { id: '2', value: 'test 2', depth: 2 },
33
+ { id: '3', value: 'test 3', depth: 3 },
34
+ { id: '4', value: 'test 4', depth: 3 },
35
+ { id: '5', value: 'test 5', depth: 2 },
38
36
  ],
39
37
  };
@@ -12,13 +12,13 @@ interface TableOfContentProps {
12
12
  }
13
13
 
14
14
  export function TableOfContent(props: TableOfContentProps): JSX.Element | null {
15
- const { headings, tocMaxDepth } = props;
15
+ const { headings, tocMaxDepth, contentWrapper } = props;
16
16
 
17
17
  const sidebar = useRef<HTMLDivElement | null>(null);
18
18
  useFullHeight(sidebar);
19
- const activeHeadingId = useActiveHeading(props.contentWrapper);
19
+ const activeHeadingId = useActiveHeading(contentWrapper);
20
20
 
21
- if (headings && headings.length === 1 && headings[0]?.depth === 1) {
21
+ if (headings && headings.length === 1 && (!headings[0] || headings[0].depth === 1)) {
22
22
  return null;
23
23
  }
24
24
  if (!headings?.length) {
@@ -46,8 +46,8 @@ export function TableOfContent(props: TableOfContentProps): JSX.Element | null {
46
46
  return (
47
47
  <MenuItem
48
48
  key={href}
49
- depth={heading.depth || 0}
50
49
  href={href}
50
+ depth={heading.depth || 0}
51
51
  className={activeHeadingId === heading.id ? 'active' : ''}
52
52
  dangerouslySetInnerHTML={{ __html: heading.value || '' }}
53
53
  data-cy={`toc-${heading.value}`}
@@ -79,11 +79,13 @@ const MenuItem = styled.a<{ depth: number }>`
79
79
  text-decoration: none;
80
80
  word-break: break-word;
81
81
  font-family: var(--h-font-family);
82
+
82
83
  :hover,
83
84
  &.active {
84
85
  color: var(--sidebar-item-active-color);
85
86
  background-color: var(--sidebar-item-active-background-color);
86
87
  }
88
+
87
89
  :empty {
88
90
  padding: 0;
89
91
  }
@@ -0,0 +1,61 @@
1
+ import React from 'react';
2
+
3
+ import { TableOfContent } from '@theme';
4
+ import { renderWithTheme } from '../../../tests/utils';
5
+
6
+ describe('TableOfContent', () => {
7
+ it('renders', () => {
8
+ const { container } = renderWithTheme(
9
+ <TableOfContent
10
+ headings={[
11
+ { id: '1', value: 'test 1', depth: 1 },
12
+ { id: '2', value: 'test 2', depth: 1 },
13
+ null,
14
+ { id: '3', value: '', depth: 2 },
15
+ { id: '4', value: 'test 4', depth: 0 },
16
+ { id: '4', value: 'test 4', depth: 5 },
17
+ { id: '5', value: 'test 5', depth: 1 },
18
+ ]}
19
+ tocMaxDepth={3}
20
+ contentWrapper={null}
21
+ />,
22
+ );
23
+
24
+ expect(container.firstChild).toMatchSnapshot();
25
+ });
26
+
27
+ it('renders nothing with no headings', () => {
28
+ const { container } = renderWithTheme(
29
+ <TableOfContent headings={null} tocMaxDepth={3} contentWrapper={null} />,
30
+ );
31
+
32
+ expect(container.firstChild).toBeNull();
33
+ });
34
+
35
+ it('renders nothing with empty headings array', () => {
36
+ const { container } = renderWithTheme(
37
+ <TableOfContent headings={[]} tocMaxDepth={3} contentWrapper={null} />,
38
+ );
39
+
40
+ expect(container.firstChild).toBeNull();
41
+ });
42
+
43
+ it('renders nothing for single heading with depth 1', () => {
44
+ const { container } = renderWithTheme(
45
+ <TableOfContent
46
+ headings={[{ id: '3', value: 'test 3', depth: 1 }]}
47
+ tocMaxDepth={3}
48
+ contentWrapper={null}
49
+ />,
50
+ );
51
+
52
+ expect(container.firstChild).toBeNull();
53
+ });
54
+ it('renders nothing for single empty heading', () => {
55
+ const { container } = renderWithTheme(
56
+ <TableOfContent headings={[null]} tocMaxDepth={3} contentWrapper={null} />,
57
+ );
58
+
59
+ expect(container.firstChild).toBeNull();
60
+ });
61
+ });