@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,55 @@
1
+ import React from 'react';
2
+
3
+ import { renderWithTheme } from '../../../tests/utils';
4
+
5
+ import { Navbar, NavbarMenu } from '@theme/Navbar';
6
+ import { NavbarLogo } from '@theme/NavbarLogo';
7
+
8
+ jest.mock('react-router-dom', () => {
9
+ const originalModule = jest.requireActual('react-router-dom');
10
+ return {
11
+ __esModule: true,
12
+ ...originalModule,
13
+ useLocation: jest.fn().mockReturnValue({ pathname: '/' }),
14
+ };
15
+ });
16
+
17
+ describe('Navbar', () => {
18
+ it('renders', () => {
19
+ const { container } = renderWithTheme(
20
+ <Navbar
21
+ logo={
22
+ <NavbarLogo
23
+ logo={{ link: '/test/', image: 'https://picsum.photos/id/2/400/100', altText: 'test' }}
24
+ />
25
+ }
26
+ menu={
27
+ <NavbarMenu
28
+ menuItems={[
29
+ { type: 'link', link: 'https://google.com', label: 'Google' },
30
+ { type: 'link', link: '/', label: 'Test' },
31
+ ]}
32
+ />
33
+ }
34
+ search={<span> Search </span>}
35
+ />,
36
+ );
37
+
38
+ expect(container.firstChild).toMatchSnapshot();
39
+ });
40
+ it('renders with empty menu items', () => {
41
+ const { container } = renderWithTheme(
42
+ <Navbar
43
+ logo={
44
+ <NavbarLogo
45
+ logo={{ link: '/test/', image: 'https://picsum.photos/id/2/400/100', altText: 'test' }}
46
+ />
47
+ }
48
+ menu={<NavbarMenu menuItems={[]} />}
49
+ search={<span> Search </span>}
50
+ />,
51
+ );
52
+
53
+ expect(container.firstChild).toMatchSnapshot();
54
+ });
55
+ });
@@ -0,0 +1,256 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Navbar renders 1`] = `
4
+ .c0 {
5
+ height: var(--navbar-height);
6
+ box-sizing: border-box;
7
+ display: -webkit-box;
8
+ display: -webkit-flex;
9
+ display: -ms-flexbox;
10
+ display: flex;
11
+ color: var(--navbar-text-color);
12
+ -webkit-align-items: center;
13
+ -webkit-box-align: center;
14
+ -ms-flex-align: center;
15
+ align-items: center;
16
+ -webkit-box-pack: justify;
17
+ -webkit-justify-content: space-between;
18
+ -ms-flex-pack: justify;
19
+ justify-content: space-between;
20
+ -webkit-flex-shrink: 0;
21
+ -ms-flex-negative: 0;
22
+ flex-shrink: 0;
23
+ font-size: 0.875rem;
24
+ position: -webkit-sticky;
25
+ position: sticky;
26
+ top: 0;
27
+ z-index: 200;
28
+ padding: 10px var(--sidebar-margin-left);
29
+ background: var(--navbar-background-color);
30
+ font-family: var(--h-font-family);
31
+ }
32
+
33
+ .c3 {
34
+ display: inline-block;
35
+ padding: 20px calc(var(--sidebar-spacing-horizontal) * 2);
36
+ text-align: center;
37
+ line-height: 1;
38
+ font-size: var(--navbar-item-font-size);
39
+ margin-left: var(--navbar-item-margin-horizontal);
40
+ margin-right: var(--navbar-item-margin-horizontal);
41
+ border-radius: var(--navbar-item-border-radius);
42
+ font-weight: var(--navbar-item-font-weight);
43
+ background: none;
44
+ }
45
+
46
+ .c6 {
47
+ display: inline-block;
48
+ padding: 20px calc(var(--sidebar-spacing-horizontal) * 2);
49
+ text-align: center;
50
+ line-height: 1;
51
+ font-size: var(--navbar-item-font-size);
52
+ margin-left: var(--navbar-item-margin-horizontal);
53
+ margin-right: var(--navbar-item-margin-horizontal);
54
+ border-radius: var(--navbar-item-border-radius);
55
+ font-weight: var(--navbar-item-font-weight);
56
+ background: var(--navbar-item-active-background-color);
57
+ }
58
+
59
+ .c4 {
60
+ color: var(--navbar-text-color);
61
+ -webkit-text-decoration: none;
62
+ text-decoration: none;
63
+ }
64
+
65
+ .c7 {
66
+ color: var(--navbar-item-active-text-color);
67
+ -webkit-text-decoration: var(--navbar-item-active-text-decoration);
68
+ text-decoration: var(--navbar-item-active-text-decoration);
69
+ }
70
+
71
+ .c5 {
72
+ cursor: pointer;
73
+ vertical-align: middle;
74
+ }
75
+
76
+ .c2 {
77
+ list-style: none;
78
+ margin: 0;
79
+ padding: 0;
80
+ display: block;
81
+ }
82
+
83
+ .c1 {
84
+ max-width: var(--logo-max-width);
85
+ max-height: var(--logo-max-height);
86
+ height: var(--logo-height);
87
+ margin: var(--logo-margin);
88
+ }
89
+
90
+ @media screen and (min-width:85rem) {
91
+ .c0 {
92
+ padding: 10px var(--sidebar-margin-left);
93
+ font-size: 1rem;
94
+ }
95
+ }
96
+
97
+ @media print {
98
+ .c0 {
99
+ background: transparent;
100
+ display: none;
101
+ }
102
+
103
+ .c0 > :not(a,img) {
104
+ display: none !important;
105
+ }
106
+
107
+ .c0 img {
108
+ padding: 0;
109
+ margin: 0;
110
+ }
111
+ }
112
+
113
+ @media screen and (min-width:85rem) {
114
+ .c2 {
115
+ display: block;
116
+ }
117
+ }
118
+
119
+ <nav
120
+ class="c0"
121
+ data-component-name="Navbar/Navbar"
122
+ >
123
+ <a
124
+ href="/test/"
125
+ to="/test/"
126
+ >
127
+ <img
128
+ alt="test"
129
+ class="c1"
130
+ data-component-name="NavbarLogo/NavbarLogo"
131
+ src="https://picsum.photos/id/2/400/100"
132
+ />
133
+ </a>
134
+ <ul
135
+ class="c2"
136
+ data-component-name="Navbar/NavbarMenu"
137
+ >
138
+ <li
139
+ class="c3"
140
+ data-component-name="Navbar/NavbarItem"
141
+ >
142
+ <a
143
+ class="c4"
144
+ href="https://google.com"
145
+ to="https://google.com"
146
+ >
147
+ <span
148
+ class="c5"
149
+ >
150
+ Google
151
+ </span>
152
+ </a>
153
+ </li>
154
+ <li
155
+ class="c6"
156
+ data-component-name="Navbar/NavbarItem"
157
+ >
158
+ <a
159
+ class="c7"
160
+ href="/"
161
+ to="/"
162
+ >
163
+ <span
164
+ class="c5"
165
+ >
166
+ Test
167
+ </span>
168
+ </a>
169
+ </li>
170
+ </ul>
171
+ <span>
172
+ Search
173
+ </span>
174
+ </nav>
175
+ `;
176
+
177
+ exports[`Navbar renders with empty menu items 1`] = `
178
+ .c0 {
179
+ height: var(--navbar-height);
180
+ box-sizing: border-box;
181
+ display: -webkit-box;
182
+ display: -webkit-flex;
183
+ display: -ms-flexbox;
184
+ display: flex;
185
+ color: var(--navbar-text-color);
186
+ -webkit-align-items: center;
187
+ -webkit-box-align: center;
188
+ -ms-flex-align: center;
189
+ align-items: center;
190
+ -webkit-box-pack: justify;
191
+ -webkit-justify-content: space-between;
192
+ -ms-flex-pack: justify;
193
+ justify-content: space-between;
194
+ -webkit-flex-shrink: 0;
195
+ -ms-flex-negative: 0;
196
+ flex-shrink: 0;
197
+ font-size: 0.875rem;
198
+ position: -webkit-sticky;
199
+ position: sticky;
200
+ top: 0;
201
+ z-index: 200;
202
+ padding: 10px var(--sidebar-margin-left);
203
+ background: var(--navbar-background-color);
204
+ font-family: var(--h-font-family);
205
+ }
206
+
207
+ .c1 {
208
+ max-width: var(--logo-max-width);
209
+ max-height: var(--logo-max-height);
210
+ height: var(--logo-height);
211
+ margin: var(--logo-margin);
212
+ }
213
+
214
+ @media screen and (min-width:85rem) {
215
+ .c0 {
216
+ padding: 10px var(--sidebar-margin-left);
217
+ font-size: 1rem;
218
+ }
219
+ }
220
+
221
+ @media print {
222
+ .c0 {
223
+ background: transparent;
224
+ display: none;
225
+ }
226
+
227
+ .c0 > :not(a,img) {
228
+ display: none !important;
229
+ }
230
+
231
+ .c0 img {
232
+ padding: 0;
233
+ margin: 0;
234
+ }
235
+ }
236
+
237
+ <nav
238
+ class="c0"
239
+ data-component-name="Navbar/Navbar"
240
+ >
241
+ <a
242
+ href="/test/"
243
+ to="/test/"
244
+ >
245
+ <img
246
+ alt="test"
247
+ class="c1"
248
+ data-component-name="NavbarLogo/NavbarLogo"
249
+ src="https://picsum.photos/id/2/400/100"
250
+ />
251
+ </a>
252
+ <span>
253
+ Search
254
+ </span>
255
+ </nav>
256
+ `;
@@ -4,7 +4,7 @@ import { ComponentStory, ComponentMeta } from '@storybook/react';
4
4
  import { NavbarLogo } from '@theme/NavbarLogo/NavbarLogo';
5
5
 
6
6
  export default {
7
- title: 'Components/NavbarLogo',
7
+ title: 'Portal/NavbarLogo',
8
8
  component: NavbarLogo,
9
9
  } as ComponentMeta<typeof NavbarLogo>;
10
10
 
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { ComponentStory, ComponentMeta } from '@storybook/react';
3
+
4
+ import { PageNavigation } from '@theme/PageNavigation/PageNavigation';
5
+
6
+ export default {
7
+ title: 'Portal/PageNavigation',
8
+ component: PageNavigation,
9
+ parameters: {
10
+ controls: { hideNoControlsWarning: true },
11
+ },
12
+ } as ComponentMeta<typeof PageNavigation>;
13
+
14
+ const Template: ComponentStory<typeof PageNavigation> = () => (
15
+ <div style={{ maxWidth: '400px' }}>
16
+ <PageNavigation />
17
+ </div>
18
+ );
19
+
20
+ export const Default = Template.bind({});
21
+ Default.args = {};
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+
3
+ import { renderWithTheme } from '../../../tests/utils';
4
+
5
+ import { NextPageLink } from '@theme/PageNavigation/NextPageLink';
6
+ import { usePageData } from '@portal/hooks/usePageData';
7
+
8
+ jest.mock('@portal/hooks/usePageData');
9
+
10
+ describe('NextPageLink', () => {
11
+ it('renders when nextPage is null', () => {
12
+ (usePageData as jest.MockedFn<any>).mockReturnValue({ prevPage: null, nextPage: null });
13
+
14
+ const { container } = renderWithTheme(<NextPageLink />);
15
+
16
+ expect(container.firstChild).toMatchSnapshot();
17
+ });
18
+
19
+ it('renders when nextPage exists', () => {
20
+ (usePageData as jest.MockedFn<any>).mockReturnValue({
21
+ prevPage: null,
22
+ nextPage: { type: 'link', label: 'The Next Page', link: 'https://test.com' },
23
+ });
24
+
25
+ const { container } = renderWithTheme(<NextPageLink />);
26
+
27
+ expect(container.firstChild).toMatchSnapshot();
28
+ });
29
+ });
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+
3
+ import { renderWithTheme } from '../../../tests/utils';
4
+
5
+ import { PageNavigation } from '@theme/PageNavigation/PageNavigation';
6
+ import { usePageData } from '@portal/hooks/usePageData';
7
+
8
+ jest.mock('@portal/hooks/usePageData');
9
+
10
+ describe('PageNavigation', () => {
11
+ it('renders', () => {
12
+ (usePageData as jest.MockedFn<any>).mockReturnValue({
13
+ prevPage: { type: 'link', label: 'The Previous Page', link: 'https://previous-page' },
14
+ nextPage: { type: 'link', label: 'The Next Page', link: 'https://next-page' },
15
+ });
16
+
17
+ const { container } = renderWithTheme(<PageNavigation />);
18
+
19
+ expect(container.firstChild).toMatchSnapshot();
20
+ });
21
+
22
+ it('renders with previous page only', () => {
23
+ (usePageData as jest.MockedFn<any>).mockReturnValue({
24
+ prevPage: { type: 'link', label: 'The Previous Page', link: 'https://previous-page' },
25
+ nextPage: null,
26
+ });
27
+
28
+ const { container } = renderWithTheme(<PageNavigation />);
29
+
30
+ expect(container.firstChild).toMatchSnapshot();
31
+ });
32
+
33
+ it('renders with missing next and previous pages', () => {
34
+ (usePageData as jest.MockedFn<any>).mockReturnValue({
35
+ prevPage: null,
36
+ nextPage: null,
37
+ });
38
+
39
+ const { container } = renderWithTheme(<PageNavigation />);
40
+
41
+ expect(container.firstChild).toMatchSnapshot();
42
+ });
43
+
44
+ it('renders with next page only', () => {
45
+ (usePageData as jest.MockedFn<any>).mockReturnValue({
46
+ prevPage: null,
47
+ nextPage: { type: 'link', label: 'The Next Page', link: 'https://next-page' },
48
+ });
49
+
50
+ const { container } = renderWithTheme(<PageNavigation />);
51
+
52
+ expect(container.firstChild).toMatchSnapshot();
53
+ });
54
+ });
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+
3
+ import { renderWithTheme } from '../../../tests/utils';
4
+
5
+ import { PreviousPageLink } from '@theme/PageNavigation/PreviousPageLink';
6
+ import { usePageData } from '@portal/hooks/usePageData';
7
+
8
+ jest.mock('@portal/hooks/usePageData');
9
+
10
+ describe('PreviousPageLink', () => {
11
+ it('renders when prevPage is null', () => {
12
+ (usePageData as jest.MockedFn<any>).mockReturnValue({ prevPage: null, nextPage: null });
13
+
14
+ const { container } = renderWithTheme(<PreviousPageLink />);
15
+
16
+ expect(container.firstChild).toMatchSnapshot();
17
+ });
18
+
19
+ it('renders when prevPage exists', () => {
20
+ (usePageData as jest.MockedFn<any>).mockReturnValue({
21
+ prevPage: { type: 'link', label: 'The Previous Page', link: 'https://test.com' },
22
+ nextPage: null,
23
+ });
24
+
25
+ const { container } = renderWithTheme(<PreviousPageLink />);
26
+
27
+ expect(container.firstChild).toMatchSnapshot();
28
+ });
29
+ });
@@ -0,0 +1,67 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`NextPageLink renders when nextPage 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
+ Next to
59
+ The Next Page
60
+ </a>
61
+ `;
62
+
63
+ exports[`NextPageLink renders when nextPage is null 1`] = `
64
+ <div>
65
+  
66
+ </div>
67
+ `;