@redocly/theme 0.1.12 → 0.1.15
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/CodeBlock/CodeBlock.js +2 -1
- package/Markdown/CodeSample/index.d.ts +0 -1
- package/Markdown/CodeSample/index.js +0 -1
- package/Markdown/CodeSample/styled.d.ts +0 -1
- package/Markdown/CodeSample/styled.js +8 -79
- package/Markdown/StyledMarkdown.d.ts +0 -2
- package/Markdown/StyledMarkdown.js +5 -16
- package/OperationBadge/OperationBadge.js +1 -1
- package/PageNavigation/NextPageLink.js +1 -1
- package/PageNavigation/PreviousPageLink.js +1 -1
- package/Search/SearchItem.js +1 -1
- package/globalStyle.js +1 -1
- package/mocks/hooks/usePageData.d.ts +1 -1
- package/package.json +1 -1
- package/src/CodeBlock/CodeBlock.ts +3 -42
- package/src/Markdown/CodeSample/index.ts +0 -1
- package/src/Markdown/CodeSample/styled.ts +18 -98
- package/src/Markdown/StyledMarkdown.tsx +14 -28
- package/src/OperationBadge/OperationBadge.ts +5 -2
- package/src/PageNavigation/NextPageLink.tsx +2 -2
- package/src/PageNavigation/PreviousPageLink.tsx +2 -2
- package/src/Search/SearchItem.tsx +1 -1
- package/src/globalStyle.ts +36 -0
- package/src/mocks/hooks/usePageData.ts +1 -1
- package/src/ui/Typography.tsx +10 -87
- package/src/utils/ClipboardService.ts +3 -86
- package/src/utils/theme-helpers.ts +46 -0
- package/ui/Typography.d.ts +2 -71
- package/ui/Typography.js +15 -93
- package/utils/ClipboardService.d.ts +1 -5
- package/utils/ClipboardService.js +2 -73
- package/utils/theme-helpers.d.ts +1 -0
- package/utils/theme-helpers.js +42 -2
- package/Markdown/CodeSample/types.d.ts +0 -9
- package/Markdown/CodeSample/types.js +0 -2
- package/src/Markdown/CodeSample/types.ts +0 -40
|
@@ -1,45 +1,5 @@
|
|
|
1
|
-
import { getLuminance } from 'polished';
|
|
2
1
|
import styled, { css } from 'styled-components';
|
|
3
2
|
|
|
4
|
-
import { typography } from '@theme/ui/Typography';
|
|
5
|
-
import type { Tokens, Token } from '@theme/Markdown/CodeSample/types';
|
|
6
|
-
import { AppTheme } from '@theme/types/portal';
|
|
7
|
-
|
|
8
|
-
function genTokens(tokens?: Tokens | null) {
|
|
9
|
-
if (!tokens) {
|
|
10
|
-
return '';
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
let res = '';
|
|
14
|
-
|
|
15
|
-
for (const token of Object.keys(tokens)) {
|
|
16
|
-
if (token !== 'default') {
|
|
17
|
-
res += `.token.${token} { color: ${tokens[token as Token]?.color}; }\n`;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (tokens.default) {
|
|
22
|
-
return css`
|
|
23
|
-
pre& {
|
|
24
|
-
${typography(tokens.default)}
|
|
25
|
-
}
|
|
26
|
-
${res}
|
|
27
|
-
`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return res;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const getCodeBlockBackgroundColor = (theme: AppTheme) =>
|
|
34
|
-
Array.isArray(theme.codeBlock.backgroundColor)
|
|
35
|
-
? theme.codeBlock.backgroundColor[0]
|
|
36
|
-
: theme.codeBlock.backgroundColor;
|
|
37
|
-
|
|
38
|
-
export const CodeButton = css`
|
|
39
|
-
padding: 0 5px;
|
|
40
|
-
border-radius: 4px;
|
|
41
|
-
`;
|
|
42
|
-
|
|
43
3
|
export const CodeSampleButtonContainer = styled.div`
|
|
44
4
|
position: absolute;
|
|
45
5
|
top: 12px;
|
|
@@ -47,44 +7,20 @@ export const CodeSampleButtonContainer = styled.div`
|
|
|
47
7
|
`;
|
|
48
8
|
|
|
49
9
|
export const CopyCodeButton = styled.div`
|
|
50
|
-
|
|
10
|
+
padding: 0 5px;
|
|
11
|
+
border-radius: 4px;
|
|
51
12
|
display: none;
|
|
52
|
-
|
|
53
13
|
&:hover {
|
|
54
14
|
cursor: pointer;
|
|
55
15
|
}
|
|
56
16
|
`;
|
|
57
17
|
|
|
58
18
|
export const DoneIndicator = styled.div`
|
|
59
|
-
|
|
19
|
+
padding: 0 5px;
|
|
20
|
+
border-radius: 4px;
|
|
60
21
|
cursor: default;
|
|
61
22
|
`;
|
|
62
23
|
|
|
63
|
-
const lightStyleCodeButton = css`
|
|
64
|
-
${CopyCodeButton},
|
|
65
|
-
${DoneIndicator} {
|
|
66
|
-
color: ${({ theme }) => theme.codeBlock.copyButton.visibleText};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
${CopyCodeButton}:hover {
|
|
70
|
-
color: ${({ theme }) => theme.codeBlock.copyButton.visibleText};
|
|
71
|
-
outline: 1px solid ${({ theme }) => theme.codeBlock.copyButton.visibleText};
|
|
72
|
-
}
|
|
73
|
-
`;
|
|
74
|
-
|
|
75
|
-
const darkStyleCodeButton = css`
|
|
76
|
-
${CopyCodeButton},
|
|
77
|
-
${DoneIndicator} {
|
|
78
|
-
color: ${({ theme }) => theme.codeBlock.copyButton.visibleText};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
${CopyCodeButton}:hover {
|
|
82
|
-
color: white;
|
|
83
|
-
color: ${({ theme }) => theme.codeBlock.copyButton.contrastText};
|
|
84
|
-
background-color: ${({ theme }) => theme.codeBlock.copyButton.background};
|
|
85
|
-
}
|
|
86
|
-
`;
|
|
87
|
-
|
|
88
24
|
const lightStyleTokens = css`
|
|
89
25
|
.token.comment,
|
|
90
26
|
.token.prolog,
|
|
@@ -93,11 +29,9 @@ const lightStyleTokens = css`
|
|
|
93
29
|
color: #999988;
|
|
94
30
|
font-style: italic;
|
|
95
31
|
}
|
|
96
|
-
|
|
97
32
|
.token.namespace {
|
|
98
33
|
opacity: 0.7;
|
|
99
34
|
}
|
|
100
|
-
|
|
101
35
|
.token.string,
|
|
102
36
|
.token.attr-value {
|
|
103
37
|
color: #e3116c;
|
|
@@ -106,7 +40,6 @@ const lightStyleTokens = css`
|
|
|
106
40
|
.token.operator {
|
|
107
41
|
color: #393a34; /* no highlight */
|
|
108
42
|
}
|
|
109
|
-
|
|
110
43
|
.token.entity,
|
|
111
44
|
.token.url,
|
|
112
45
|
.token.symbol,
|
|
@@ -119,20 +52,17 @@ const lightStyleTokens = css`
|
|
|
119
52
|
.token.inserted {
|
|
120
53
|
color: #36acaa;
|
|
121
54
|
}
|
|
122
|
-
|
|
123
55
|
.token.atrule,
|
|
124
56
|
.token.keyword,
|
|
125
57
|
.token.attr-name,
|
|
126
58
|
.language-autohotkey .token.selector {
|
|
127
59
|
color: #00a4db;
|
|
128
60
|
}
|
|
129
|
-
|
|
130
61
|
.token.function,
|
|
131
62
|
.token.deleted,
|
|
132
63
|
.language-autohotkey .token.tag {
|
|
133
64
|
color: #9a050f;
|
|
134
65
|
}
|
|
135
|
-
|
|
136
66
|
.token.tag,
|
|
137
67
|
.token.selector,
|
|
138
68
|
.language-autohotkey .token.keyword {
|
|
@@ -147,7 +77,6 @@ const darkStyleTokens = css`
|
|
|
147
77
|
.token.cdata {
|
|
148
78
|
color: hsl(30, 20%, 50%);
|
|
149
79
|
}
|
|
150
|
-
|
|
151
80
|
.token.property,
|
|
152
81
|
.token.tag,
|
|
153
82
|
.token.number,
|
|
@@ -186,7 +115,6 @@ const darkStyleTokens = css`
|
|
|
186
115
|
.token.important {
|
|
187
116
|
color: #e90;
|
|
188
117
|
}
|
|
189
|
-
|
|
190
118
|
.token.deleted {
|
|
191
119
|
color: red;
|
|
192
120
|
}
|
|
@@ -197,58 +125,53 @@ export const Wrapper = styled.div`
|
|
|
197
125
|
border-radius: 4px;
|
|
198
126
|
position: relative;
|
|
199
127
|
|
|
200
|
-
${
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
128
|
+
${CopyCodeButton},
|
|
129
|
+
${DoneIndicator} {
|
|
130
|
+
color: rgba(255, 255, 255, 0.15);
|
|
131
|
+
}
|
|
132
|
+
${CopyCodeButton}:hover {
|
|
133
|
+
color: #fff;
|
|
134
|
+
background-color: rgba(255, 255, 255, 0.15);
|
|
135
|
+
}
|
|
204
136
|
|
|
205
137
|
&:hover {
|
|
206
138
|
${CodeSampleButtonContainer} ${CopyCodeButton} {
|
|
207
139
|
display: block;
|
|
208
140
|
}
|
|
209
141
|
}
|
|
210
|
-
|
|
211
142
|
pre {
|
|
212
|
-
white-space:
|
|
143
|
+
white-space: var(--code-wrap);
|
|
213
144
|
color: white;
|
|
214
145
|
padding: 12px 14px 15px 14px;
|
|
215
146
|
overflow-x: auto;
|
|
216
147
|
line-height: normal;
|
|
217
148
|
border-radius: 4px;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
background-color: ${({ theme }) => theme.codeBlock.backgroundColor};
|
|
221
|
-
|
|
149
|
+
font-family: var(--code-font-family);
|
|
150
|
+
background-color: var(--code-block-preformatted-background-color);
|
|
222
151
|
code {
|
|
223
152
|
background-color: transparent;
|
|
224
153
|
border: 0;
|
|
225
154
|
padding: 0;
|
|
226
|
-
|
|
227
|
-
color: ${({ theme }) =>
|
|
228
|
-
getLuminance(theme.codeBlock.backgroundColor) < 0.5 ? 'white' : '#393A34'};
|
|
229
|
-
|
|
155
|
+
color: white;
|
|
230
156
|
&:before,
|
|
231
157
|
&:after {
|
|
232
158
|
content: none;
|
|
233
159
|
}
|
|
234
160
|
}
|
|
235
161
|
}
|
|
236
|
-
|
|
237
162
|
pre[class*='language-'] {
|
|
238
163
|
padding: 1em;
|
|
239
164
|
margin: 0.5em 0;
|
|
240
165
|
overflow: auto;
|
|
241
166
|
border: 0;
|
|
242
|
-
border-radius:
|
|
167
|
+
border-radius: var(--global-border-radius);
|
|
243
168
|
}
|
|
244
|
-
|
|
245
169
|
code[class='language-text'] {
|
|
246
170
|
line-height: 1.2em;
|
|
247
171
|
display: inline-flex;
|
|
248
172
|
white-space: pre-wrap;
|
|
249
173
|
overflow-wrap: anywhere;
|
|
250
174
|
}
|
|
251
|
-
|
|
252
175
|
code[class*='language-'],
|
|
253
176
|
pre[class*='language-'] {
|
|
254
177
|
text-align: left;
|
|
@@ -264,7 +187,6 @@ export const Wrapper = styled.div`
|
|
|
264
187
|
-moz-hyphens: none;
|
|
265
188
|
-ms-hyphens: none;
|
|
266
189
|
hyphens: none;
|
|
267
|
-
|
|
268
190
|
.token.important,
|
|
269
191
|
.token.bold {
|
|
270
192
|
font-weight: bold;
|
|
@@ -282,8 +204,6 @@ export const Wrapper = styled.div`
|
|
|
282
204
|
opacity: 0.7;
|
|
283
205
|
}
|
|
284
206
|
|
|
285
|
-
${
|
|
286
|
-
getLuminance(getCodeBlockBackgroundColor(theme)) < 0.5 ? darkStyleTokens : lightStyleTokens}
|
|
287
|
-
${({ theme }) => genTokens(theme.codeBlock.tokens)}
|
|
207
|
+
${darkStyleTokens};
|
|
288
208
|
}
|
|
289
209
|
`;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import styled, { css, FlattenSimpleInterpolation } from 'styled-components';
|
|
2
2
|
|
|
3
|
-
import { typography
|
|
3
|
+
import { typography } from '@theme/utils';
|
|
4
4
|
|
|
5
5
|
export const baseTable = css`
|
|
6
6
|
table {
|
|
@@ -68,19 +68,6 @@ export const baseTable = css`
|
|
|
68
68
|
}
|
|
69
69
|
`;
|
|
70
70
|
|
|
71
|
-
export function margins(theme: ITypography): FlattenSimpleInterpolation | string {
|
|
72
|
-
if (!theme) return '';
|
|
73
|
-
|
|
74
|
-
return css`
|
|
75
|
-
${{
|
|
76
|
-
marginTop: theme.marginTop || theme.marginVertical || '',
|
|
77
|
-
marginBottom: theme.marginBottom || theme.marginVertical || '',
|
|
78
|
-
marginLeft: theme.marginLeft || theme.marginHorizontal || '',
|
|
79
|
-
marginRight: theme.marginRight || theme.marginHorizontal || '',
|
|
80
|
-
}}
|
|
81
|
-
`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
71
|
// TODO: Can users specify another className or we should hardcode it?
|
|
85
72
|
export function headingAnchor(className = 'anchor'): FlattenSimpleInterpolation {
|
|
86
73
|
return css`
|
|
@@ -220,8 +207,8 @@ export const StyledMarkdown = styled.main.attrs(() => ({
|
|
|
220
207
|
}
|
|
221
208
|
|
|
222
209
|
h1 {
|
|
223
|
-
${typography(
|
|
224
|
-
|
|
210
|
+
${typography('h1', 'h')};
|
|
211
|
+
margin: var(--h1-margin-top) var(--h1-margin-bottom);
|
|
225
212
|
${headingAnchor()};
|
|
226
213
|
|
|
227
214
|
&:first-child {
|
|
@@ -230,32 +217,32 @@ export const StyledMarkdown = styled.main.attrs(() => ({
|
|
|
230
217
|
}
|
|
231
218
|
|
|
232
219
|
h2 {
|
|
233
|
-
${typography(
|
|
234
|
-
|
|
220
|
+
${typography('h2', 'h')};
|
|
221
|
+
margin: var(--h2-margin-top) var(--h2-margin-bottom);
|
|
235
222
|
${headingAnchor()};
|
|
236
223
|
}
|
|
237
224
|
|
|
238
225
|
h3 {
|
|
239
|
-
${typography(
|
|
240
|
-
|
|
226
|
+
${typography('h3', 'h')};
|
|
227
|
+
margin: var(--h3-margin-top) var(--h3-margin-bottom);
|
|
241
228
|
${headingAnchor()};
|
|
242
229
|
}
|
|
243
230
|
|
|
244
231
|
h4 {
|
|
245
|
-
${typography(
|
|
246
|
-
|
|
232
|
+
${typography('h4', 'h')};
|
|
233
|
+
margin: var(--h4-margin-top) var(--h4-margin-bottom);
|
|
247
234
|
${headingAnchor()};
|
|
248
235
|
}
|
|
249
236
|
|
|
250
237
|
h5 {
|
|
251
|
-
${typography(
|
|
252
|
-
|
|
238
|
+
${typography('h5', 'h')};
|
|
239
|
+
margin: var(--h5-margin-top) var(--h5-margin-bottom);
|
|
253
240
|
${headingAnchor()};
|
|
254
241
|
}
|
|
255
242
|
|
|
256
243
|
h6 {
|
|
257
|
-
${typography(
|
|
258
|
-
|
|
244
|
+
${typography('h6', 'h')};
|
|
245
|
+
margin: var(--h6-margin-top) var(--h6-margin-bottom);
|
|
259
246
|
${headingAnchor()};
|
|
260
247
|
}
|
|
261
248
|
|
|
@@ -277,8 +264,7 @@ export const StyledMarkdown = styled.main.attrs(() => ({
|
|
|
277
264
|
padding: var(--bloquote-padding-vertical) var(--bloquote-padding-horizontal);
|
|
278
265
|
border-left: 4px solid var(--global-border-color);
|
|
279
266
|
background-color: var(--bloquote-background-color);
|
|
280
|
-
|
|
281
|
-
${typography(typographyTokens.blockquote)};
|
|
267
|
+
color: var(--color-content);
|
|
282
268
|
|
|
283
269
|
& > p:first-child {
|
|
284
270
|
margin-top: 0;
|
|
@@ -3,7 +3,9 @@ import styled from 'styled-components';
|
|
|
3
3
|
export const OperationBadge = styled.span.attrs((props: { type: string }) => ({
|
|
4
4
|
className: `operation-type ${props.type}`,
|
|
5
5
|
}))<{ type: string }>`
|
|
6
|
-
display: inline-
|
|
6
|
+
display: inline-flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
justify-content: center;
|
|
7
9
|
font-size: var(--http-badge-menu-font-size);
|
|
8
10
|
font-family: var(--http-badge-font-family);
|
|
9
11
|
font-weight: var(--http-badge-font-weight);
|
|
@@ -41,7 +43,8 @@ export const OperationBadge = styled.span.attrs((props: { type: string }) => ({
|
|
|
41
43
|
background-color: var(--color-http-delete);
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
&.basic
|
|
46
|
+
&.basic,
|
|
47
|
+
&.schema {
|
|
45
48
|
background-color: var(--color-http-basic);
|
|
46
49
|
}
|
|
47
50
|
|
|
@@ -5,11 +5,11 @@ import { usePageData } from '@portal/hooks/usePageData';
|
|
|
5
5
|
import { Button } from '@theme/ui';
|
|
6
6
|
|
|
7
7
|
interface NextPageType {
|
|
8
|
-
nextPage
|
|
8
|
+
nextPage?: ResolvedNavLinkItem | null;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function NextPageLink(): JSX.Element {
|
|
12
|
-
const { nextPage }: NextPageType = usePageData();
|
|
12
|
+
const { nextPage }: NextPageType = usePageData() || {};
|
|
13
13
|
if (!nextPage) {
|
|
14
14
|
return <div> </div>;
|
|
15
15
|
}
|
|
@@ -5,11 +5,11 @@ import { usePageData } from '@portal/hooks/usePageData';
|
|
|
5
5
|
import { Button } from '@theme/ui';
|
|
6
6
|
|
|
7
7
|
interface PreviousPageType {
|
|
8
|
-
prevPage
|
|
8
|
+
prevPage?: ResolvedNavLinkItem | null;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function PreviousPageLink(): JSX.Element {
|
|
12
|
-
const { prevPage }: PreviousPageType = usePageData();
|
|
12
|
+
const { prevPage }: PreviousPageType = usePageData() || {};
|
|
13
13
|
if (!prevPage) {
|
|
14
14
|
return <div> </div>;
|
|
15
15
|
}
|
|
@@ -25,7 +25,7 @@ export function SearchItem({ item }: SearchItemProps): JSX.Element {
|
|
|
25
25
|
{item.httpVerb ? (
|
|
26
26
|
<Operation>
|
|
27
27
|
<OperationBadge type={item.httpVerb}>{item.httpVerb}</OperationBadge>
|
|
28
|
-
{highlight(item.pathName)}
|
|
28
|
+
{item.pathName ? highlight(item.pathName) : null}
|
|
29
29
|
</Operation>
|
|
30
30
|
) : null}
|
|
31
31
|
<Title>{highlight(item.title)}</Title>
|
package/src/globalStyle.ts
CHANGED
|
@@ -557,6 +557,42 @@ const code = css`
|
|
|
557
557
|
--code-block-word-break: initial;
|
|
558
558
|
--code-block-preformatted-background-color: #323f4b; // @presenter Color
|
|
559
559
|
|
|
560
|
+
--code-block-tokens-default-color: var(--color-content-inverse); // @presenter Color
|
|
561
|
+
|
|
562
|
+
--code-block-tokens-comment-color: hsl(30, 20%, 50%); // @presenter Color
|
|
563
|
+
--code-block-tokens-prolog-color: var(--code-block-tokens-comment-color); // @presenter Color
|
|
564
|
+
--code-block-tokens-doctype-color: var(--code-block-tokens-comment-color); // @presenter Color
|
|
565
|
+
--code-block-tokens-cdata-color: var(--code-block-tokens-comment-color); // @presenter Color
|
|
566
|
+
|
|
567
|
+
--code-block-tokens-property-color: var(--code-block-tokens-default-color); // @presenter Color
|
|
568
|
+
--code-block-tokens-tag-color: var(--code-block-tokens-default-color); // @presenter Color
|
|
569
|
+
--code-block-tokens-number-color: var(--code-block-tokens-default-color); // @presenter Color
|
|
570
|
+
--code-block-tokens-constant-color: var(--code-block-tokens-default-color); // @presenter Color
|
|
571
|
+
--code-block-tokens-symbol-color: var(--code-block-tokens-default-color); // @presenter Color
|
|
572
|
+
|
|
573
|
+
--code-block-tokens-boolean-color: var(--color-error-500); // @presenter Color
|
|
574
|
+
|
|
575
|
+
--code-block-tokens-string-color: #fee39e; // @presenter Color
|
|
576
|
+
--code-block-tokens-selector-color: var(--code-block-tokens-string-color); // @presenter Color
|
|
577
|
+
--code-block-tokens-attr-name-color: var(--code-block-tokens-string-color); // @presenter Color
|
|
578
|
+
--code-block-tokens-char-color: var(--code-block-tokens-string-color); // @presenter Color
|
|
579
|
+
--code-block-tokens-builtin-color: var(--code-block-tokens-string-color); // @presenter Color
|
|
580
|
+
--code-block-tokens-inserted-color: var(--code-block-tokens-string-color); // @presenter Color
|
|
581
|
+
|
|
582
|
+
--code-block-tokens-operator-color: #f5b83d; // @presenter Color
|
|
583
|
+
--code-block-tokens-entity-color: var(--code-block-tokens-operator-color); // @presenter Color
|
|
584
|
+
--code-block-tokens-url-color: var(--code-block-tokens-operator-color); // @presenter Color
|
|
585
|
+
--code-block-tokens-variable-color: var(--code-block-tokens-operator-color); // @presenter Color
|
|
586
|
+
|
|
587
|
+
--code-block-tokens-keyword-color: #ffdbf4; // @presenter Color
|
|
588
|
+
--code-block-tokens-atrule-color: var(--code-block-tokens-keyword-color); // @presenter Color
|
|
589
|
+
--code-block-tokens-attr-value-color: var(--code-block-tokens-keyword-color); // @presenter Color
|
|
590
|
+
|
|
591
|
+
--code-block-tokens-regex-color: #e90; // @presenter Color
|
|
592
|
+
--code-block-tokens-important-color: var(--code-block-tokens-regex-color); // @presenter Color
|
|
593
|
+
|
|
594
|
+
--code-block-tokens-deleted-color: red; // @presenter Color
|
|
595
|
+
|
|
560
596
|
// @tokens End
|
|
561
597
|
`;
|
|
562
598
|
|
|
@@ -3,7 +3,7 @@ import type { ResolvedNavLinkItem } from '@theme/types/portal';
|
|
|
3
3
|
export function usePageData(): {
|
|
4
4
|
prevPage: ResolvedNavLinkItem | null;
|
|
5
5
|
nextPage: ResolvedNavLinkItem | null;
|
|
6
|
-
} {
|
|
6
|
+
} | null {
|
|
7
7
|
return {
|
|
8
8
|
prevPage: { label: 'Intro', type: 'link', link: '#prev' },
|
|
9
9
|
nextPage: { label: 'FAQ', type: 'link', link: '#next' },
|
package/src/ui/Typography.tsx
CHANGED
|
@@ -1,86 +1,7 @@
|
|
|
1
|
-
import styled
|
|
1
|
+
import styled from 'styled-components';
|
|
2
2
|
import { color, typography as typographySystem, ColorProps, TypographyProps } from 'styled-system';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
fontSize?: string;
|
|
6
|
-
fontWeight?: string | number;
|
|
7
|
-
fontFamily?: string;
|
|
8
|
-
lineHeight?: string;
|
|
9
|
-
color?: string;
|
|
10
|
-
transform?: string;
|
|
11
|
-
marginTop?: string;
|
|
12
|
-
marginRight?: string;
|
|
13
|
-
marginLeft?: string;
|
|
14
|
-
marginBottom?: string;
|
|
15
|
-
marginVertical?: string;
|
|
16
|
-
marginHorizontal?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const typographyTokens = {
|
|
20
|
-
typography: {
|
|
21
|
-
fontSize: 'var(--font-size-base)',
|
|
22
|
-
fontFamily: 'var(--h-font-family)',
|
|
23
|
-
lineHeight: 'var(--line-height-base)',
|
|
24
|
-
},
|
|
25
|
-
heading1: {
|
|
26
|
-
fontSize: 'var(--h1-font-size)',
|
|
27
|
-
fontFamily: 'var(--h-font-family)',
|
|
28
|
-
fontWeight: 'var(--h1-font-weight, var(--h-font-weight))',
|
|
29
|
-
lineHeight: 'var(--h1-line-height)',
|
|
30
|
-
color: 'var(--h-color)',
|
|
31
|
-
marginTop: 'var(--h1-margin-top)',
|
|
32
|
-
marginBottom: 'var(--h1-margin-bottom)',
|
|
33
|
-
},
|
|
34
|
-
heading2: {
|
|
35
|
-
fontSize: 'var(--h2-font-size)',
|
|
36
|
-
fontFamily: 'var(--h-font-family)',
|
|
37
|
-
fontWeight: 'var(--h2-font-weight, var(--h-font-weight))',
|
|
38
|
-
lineHeight: 'var(--h2-line-height)',
|
|
39
|
-
color: 'var(--h-color)',
|
|
40
|
-
marginTop: 'var(--h2-margin-top)',
|
|
41
|
-
marginBottom: 'var(--h2-margin-bottom)',
|
|
42
|
-
},
|
|
43
|
-
heading3: {
|
|
44
|
-
fontSize: 'var(--h3-font-size)',
|
|
45
|
-
fontFamily: 'var(--h-font-family)',
|
|
46
|
-
fontWeight: 'var(--h3-font-weight, var(--h-font-weight))',
|
|
47
|
-
lineHeight: 'var(--h3-line-height)',
|
|
48
|
-
color: 'var(--h-color)',
|
|
49
|
-
marginTop: 'var(--h3-margin-top)',
|
|
50
|
-
marginBottom: 'var(--h3-margin-bottom)',
|
|
51
|
-
},
|
|
52
|
-
heading4: {},
|
|
53
|
-
heading5: {},
|
|
54
|
-
heading6: {},
|
|
55
|
-
blockquote: {
|
|
56
|
-
color: 'var(--color-content)',
|
|
57
|
-
},
|
|
58
|
-
alert: {
|
|
59
|
-
fontSize: 'var(--admonition-font-size)',
|
|
60
|
-
fontWeight: 'var(--admonition-font-weight)',
|
|
61
|
-
lineHeight: 'var(--admonition-line-height)',
|
|
62
|
-
marginTop: 'var(--admonition-margin-vertical)',
|
|
63
|
-
marginBottom: 'var(--admonition-margin-vertical)',
|
|
64
|
-
heading: {
|
|
65
|
-
fontSize: 'var(--admonition-heading-font-size)',
|
|
66
|
-
fontWeight: 'var(--admonition-heading-font-weight)',
|
|
67
|
-
lineHeight: 'var(--admonition-line-height)',
|
|
68
|
-
transform: 'var(--admonition-heading-transform)',
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export function typography(theme?: ITypography): string | SimpleInterpolation {
|
|
74
|
-
if (!theme) return '';
|
|
75
|
-
return css`
|
|
76
|
-
font-size: ${theme.fontSize || ''};
|
|
77
|
-
font-weight: ${theme.fontWeight || ''};
|
|
78
|
-
font-family: ${theme.fontFamily || ''};
|
|
79
|
-
line-height: ${theme.lineHeight || ''};
|
|
80
|
-
color: ${theme.color || ''};
|
|
81
|
-
text-transform: ${theme.transform || ''};
|
|
82
|
-
`;
|
|
83
|
-
}
|
|
4
|
+
import { typography } from '@theme/utils';
|
|
84
5
|
|
|
85
6
|
type HeadingProps = TypographyProps &
|
|
86
7
|
ColorProps & {
|
|
@@ -97,7 +18,7 @@ export const Emphasis = styled.strong.attrs(() => ({
|
|
|
97
18
|
export const H1 = styled.h1.attrs(() => ({
|
|
98
19
|
'data-component-name': 'ui/Typography/H1',
|
|
99
20
|
}))<HeadingProps>`
|
|
100
|
-
${typography(
|
|
21
|
+
${typography('h1', 'h')};
|
|
101
22
|
margin: 1.35em 0 0.9em;
|
|
102
23
|
&& {
|
|
103
24
|
${({ mt }) => mt && `margin-top: ${mt};`}
|
|
@@ -107,10 +28,10 @@ export const H1 = styled.h1.attrs(() => ({
|
|
|
107
28
|
}
|
|
108
29
|
`;
|
|
109
30
|
|
|
110
|
-
export const H2 = styled.
|
|
31
|
+
export const H2 = styled.h2.attrs(() => ({
|
|
111
32
|
'data-component-name': 'ui/Typography/H2',
|
|
112
33
|
}))<HeadingProps>`
|
|
113
|
-
${typography(
|
|
34
|
+
${typography('h2', 'h')};
|
|
114
35
|
margin: 1.25em 0 0.8em;
|
|
115
36
|
&& {
|
|
116
37
|
${({ mt }) => mt && `margin-top: ${mt};`}
|
|
@@ -120,10 +41,10 @@ export const H2 = styled.h1.attrs(() => ({
|
|
|
120
41
|
}
|
|
121
42
|
`;
|
|
122
43
|
|
|
123
|
-
export const H3 = styled.
|
|
44
|
+
export const H3 = styled.h3.attrs(() => ({
|
|
124
45
|
'data-component-name': 'ui/Typography/H3',
|
|
125
46
|
}))<HeadingProps>`
|
|
126
|
-
${typography(
|
|
47
|
+
${typography('h3', 'h')};
|
|
127
48
|
margin: 1.25em 0 0.8em;
|
|
128
49
|
&& {
|
|
129
50
|
${({ mt }) => mt && `margin-top: ${mt};`}
|
|
@@ -152,7 +73,9 @@ export const Typography = styled.p.attrs(() => ({
|
|
|
152
73
|
mb?: string;
|
|
153
74
|
}
|
|
154
75
|
>`
|
|
155
|
-
|
|
76
|
+
font-size: var(--font-size-base);
|
|
77
|
+
font-family: var(--font-family-base);
|
|
78
|
+
line-height: var(--line-height-base);
|
|
156
79
|
color: var(--color-content);
|
|
157
80
|
${color};
|
|
158
81
|
margin-top: ${({ mt }) => mt || '1em'};
|
|
@@ -1,92 +1,9 @@
|
|
|
1
1
|
export class ClipboardService {
|
|
2
2
|
static isSupported(): boolean {
|
|
3
|
-
return
|
|
4
|
-
typeof document !== 'undefined' &&
|
|
5
|
-
!!document.queryCommandSupported &&
|
|
6
|
-
document.queryCommandSupported('copy')
|
|
7
|
-
);
|
|
3
|
+
return typeof navigator !== 'undefined' && !!navigator.clipboard;
|
|
8
4
|
}
|
|
9
5
|
|
|
10
|
-
static
|
|
11
|
-
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
let range;
|
|
15
|
-
let selection;
|
|
16
|
-
if ((document.body as any).createTextRange) {
|
|
17
|
-
range = (document.body as any).createTextRange();
|
|
18
|
-
range.moveToElementText(element);
|
|
19
|
-
range.select();
|
|
20
|
-
} else if (document.createRange && window.getSelection) {
|
|
21
|
-
selection = window.getSelection();
|
|
22
|
-
range = document.createRange();
|
|
23
|
-
range.selectNodeContents(element);
|
|
24
|
-
selection?.removeAllRanges();
|
|
25
|
-
selection?.addRange(range);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static deselect(): void {
|
|
30
|
-
if ((document as any).selection) {
|
|
31
|
-
(document as any).selection.empty();
|
|
32
|
-
} else if (window.getSelection) {
|
|
33
|
-
const selection = window.getSelection();
|
|
34
|
-
if (selection) {
|
|
35
|
-
selection.removeAllRanges();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
static copySelected(): boolean {
|
|
41
|
-
let result;
|
|
42
|
-
try {
|
|
43
|
-
result = document.execCommand('copy');
|
|
44
|
-
} catch (err) {
|
|
45
|
-
result = false;
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static copyElement(element: HTMLDivElement | null): boolean {
|
|
51
|
-
ClipboardService.selectElement(element);
|
|
52
|
-
const res = ClipboardService.copySelected();
|
|
53
|
-
if (res) {
|
|
54
|
-
ClipboardService.deselect();
|
|
55
|
-
}
|
|
56
|
-
return res;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
static copyCustom(text: string): boolean {
|
|
60
|
-
const textArea = document.createElement('textarea');
|
|
61
|
-
textArea.style.position = 'fixed';
|
|
62
|
-
textArea.style.top = '0';
|
|
63
|
-
textArea.style.left = '0';
|
|
64
|
-
|
|
65
|
-
// Ensure it has a small width and height. Setting to 1px / 1em
|
|
66
|
-
// doesn't work as this gives a negative w/h on some browsers.
|
|
67
|
-
textArea.style.width = '2em';
|
|
68
|
-
textArea.style.height = '2em';
|
|
69
|
-
|
|
70
|
-
// We don't need padding, reducing the size if it does flash render.
|
|
71
|
-
textArea.style.padding = '0';
|
|
72
|
-
|
|
73
|
-
// Clean up any borders.
|
|
74
|
-
textArea.style.border = 'none';
|
|
75
|
-
textArea.style.outline = 'none';
|
|
76
|
-
textArea.style.boxShadow = 'none';
|
|
77
|
-
|
|
78
|
-
// Avoid flash of white box if rendered for any reason.
|
|
79
|
-
textArea.style.background = 'transparent';
|
|
80
|
-
|
|
81
|
-
textArea.value = text;
|
|
82
|
-
|
|
83
|
-
document.body.appendChild(textArea);
|
|
84
|
-
|
|
85
|
-
textArea.select();
|
|
86
|
-
|
|
87
|
-
const res = ClipboardService.copySelected();
|
|
88
|
-
|
|
89
|
-
document.body.removeChild(textArea);
|
|
90
|
-
return res;
|
|
6
|
+
static copyCustom(text: string): Promise<void> {
|
|
7
|
+
return navigator.clipboard.writeText(text);
|
|
91
8
|
}
|
|
92
9
|
}
|