@docusaurus/theme-classic 2.0.0-beta.16 → 2.0.0-beta.17
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/lib/getSwizzleConfig.js +64 -41
- package/lib/theme-classic.d.ts +17 -1
- package/lib/validateThemeConfig.js +4 -13
- package/lib-next/theme/BlogPostAuthor/index.js +18 -6
- package/lib-next/theme/ColorModeToggle/index.js +83 -0
- package/lib-next/theme/ColorModeToggle/styles.module.css +51 -0
- package/lib-next/theme/IconDarkMode/index.js +17 -0
- package/lib-next/theme/IconLanguage/index.js +3 -3
- package/lib-next/theme/IconLightMode/index.js +17 -0
- package/lib-next/theme/MDXComponents/index.js +15 -1
- package/lib-next/theme/Navbar/index.js +3 -3
- package/lib-next/theme/SearchMetadata/index.js +9 -0
- package/package.json +14 -14
- package/src/getSwizzleConfig.ts +53 -31
- package/src/theme/BlogPostAuthor/index.tsx +17 -7
- package/src/theme/ColorModeToggle/index.tsx +92 -0
- package/src/theme/ColorModeToggle/styles.module.css +51 -0
- package/src/theme/IconDarkMode/index.tsx +20 -0
- package/src/theme/IconLanguage/index.tsx +3 -3
- package/src/theme/IconLightMode/index.tsx +20 -0
- package/src/theme/MDXComponents/index.tsx +15 -1
- package/src/theme/Navbar/index.tsx +3 -3
- package/src/theme/SearchMetadata/index.tsx +9 -0
- package/src/theme-classic.d.ts +17 -1
- package/src/validateThemeConfig.ts +4 -20
- package/lib-next/theme/Toggle/index.js +0 -100
- package/lib-next/theme/Toggle/styles.module.css +0 -106
- package/src/theme/Toggle/index.tsx +0 -117
- package/src/theme/Toggle/styles.module.css +0 -106
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
.toggle {
|
|
9
|
-
touch-action: pan-x;
|
|
10
|
-
position: relative;
|
|
11
|
-
cursor: pointer;
|
|
12
|
-
user-select: none;
|
|
13
|
-
-webkit-tap-highlight-color: transparent;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.toggleScreenReader {
|
|
17
|
-
border: 0;
|
|
18
|
-
clip: rect(0 0 0 0);
|
|
19
|
-
height: 1px;
|
|
20
|
-
margin: -1px;
|
|
21
|
-
overflow: hidden;
|
|
22
|
-
position: absolute;
|
|
23
|
-
width: 1px;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.toggleDisabled {
|
|
27
|
-
cursor: not-allowed;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.toggleTrack {
|
|
31
|
-
width: 50px;
|
|
32
|
-
height: 24px;
|
|
33
|
-
border-radius: 30px;
|
|
34
|
-
background-color: #4d4d4d;
|
|
35
|
-
transition: all 0.2s ease;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
.toggleTrackCheck {
|
|
39
|
-
position: absolute;
|
|
40
|
-
width: 14px;
|
|
41
|
-
height: 10px;
|
|
42
|
-
top: 0;
|
|
43
|
-
bottom: 0;
|
|
44
|
-
margin: auto 0;
|
|
45
|
-
left: 8px;
|
|
46
|
-
opacity: 0;
|
|
47
|
-
transition: opacity 0.25s ease;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
.toggleChecked .toggleTrackCheck,
|
|
51
|
-
[data-theme='dark'] .toggle .toggleTrackCheck {
|
|
52
|
-
opacity: 1;
|
|
53
|
-
transition: opacity 0.25s ease;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.toggleTrackX {
|
|
57
|
-
position: absolute;
|
|
58
|
-
width: 10px;
|
|
59
|
-
height: 10px;
|
|
60
|
-
top: 0;
|
|
61
|
-
bottom: 0;
|
|
62
|
-
margin: auto 0;
|
|
63
|
-
right: 10px;
|
|
64
|
-
opacity: 1;
|
|
65
|
-
transition: opacity 0.25s ease;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
.toggleChecked .toggleTrackX,
|
|
69
|
-
[data-theme='dark'] .toggle .toggleTrackX {
|
|
70
|
-
opacity: 0;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.toggleTrackThumb {
|
|
74
|
-
position: absolute;
|
|
75
|
-
top: 1px;
|
|
76
|
-
left: 1px;
|
|
77
|
-
width: 22px;
|
|
78
|
-
height: 22px;
|
|
79
|
-
border: 1px solid #4d4d4d;
|
|
80
|
-
border-radius: 50%;
|
|
81
|
-
background-color: #fafafa;
|
|
82
|
-
transition: all 0.25s ease;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.toggleFocused .toggleTrackThumb,
|
|
86
|
-
.toggle:hover .toggleTrackThumb {
|
|
87
|
-
box-shadow: 0 0 2px 3px var(--ifm-color-primary);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/* stylelint-disable-next-line no-descending-specificity */
|
|
91
|
-
.toggleChecked .toggleTrackThumb,
|
|
92
|
-
[data-theme='dark'] .toggle .toggleTrackThumb {
|
|
93
|
-
left: 27px;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
.toggle:active:not(.toggleDisabled) .toggleTrackThumb {
|
|
97
|
-
box-shadow: 0 0 5px 5px var(--ifm-color-primary);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
.toggleIcon {
|
|
101
|
-
align-items: center;
|
|
102
|
-
display: flex;
|
|
103
|
-
height: 10px;
|
|
104
|
-
justify-content: center;
|
|
105
|
-
width: 10px;
|
|
106
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import React, {useState, useRef, useEffect, memo} from 'react';
|
|
9
|
-
import type {Props} from '@theme/Toggle';
|
|
10
|
-
import {useThemeConfig, type ColorModeConfig} from '@docusaurus/theme-common';
|
|
11
|
-
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
12
|
-
import {translate} from '@docusaurus/Translate';
|
|
13
|
-
|
|
14
|
-
import clsx from 'clsx';
|
|
15
|
-
import styles from './styles.module.css';
|
|
16
|
-
|
|
17
|
-
// Based on react-toggle (https://github.com/aaronshaf/react-toggle/).
|
|
18
|
-
const ToggleComponent = memo(
|
|
19
|
-
({
|
|
20
|
-
className,
|
|
21
|
-
switchConfig,
|
|
22
|
-
checked: defaultChecked,
|
|
23
|
-
disabled,
|
|
24
|
-
onChange,
|
|
25
|
-
}: Props & {
|
|
26
|
-
switchConfig: ColorModeConfig['switchConfig'];
|
|
27
|
-
disabled: boolean;
|
|
28
|
-
}): JSX.Element => {
|
|
29
|
-
const {darkIcon, darkIconStyle, lightIcon, lightIconStyle} = switchConfig;
|
|
30
|
-
const [checked, setChecked] = useState(defaultChecked);
|
|
31
|
-
const [focused, setFocused] = useState(false);
|
|
32
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
setChecked(defaultChecked);
|
|
36
|
-
}, [defaultChecked]);
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<div
|
|
40
|
-
className={clsx(styles.toggle, className, {
|
|
41
|
-
[styles.toggleChecked]: checked,
|
|
42
|
-
[styles.toggleFocused]: focused,
|
|
43
|
-
[styles.toggleDisabled]: disabled,
|
|
44
|
-
})}>
|
|
45
|
-
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
|
|
46
|
-
<div
|
|
47
|
-
className={styles.toggleTrack}
|
|
48
|
-
role="button"
|
|
49
|
-
tabIndex={-1}
|
|
50
|
-
onClick={() => inputRef.current?.click()}>
|
|
51
|
-
<div className={styles.toggleTrackCheck}>
|
|
52
|
-
<span className={styles.toggleIcon} style={darkIconStyle}>
|
|
53
|
-
{darkIcon}
|
|
54
|
-
</span>
|
|
55
|
-
</div>
|
|
56
|
-
<div className={styles.toggleTrackX}>
|
|
57
|
-
<span className={styles.toggleIcon} style={lightIconStyle}>
|
|
58
|
-
{lightIcon}
|
|
59
|
-
</span>
|
|
60
|
-
</div>
|
|
61
|
-
<div className={styles.toggleTrackThumb} />
|
|
62
|
-
</div>
|
|
63
|
-
|
|
64
|
-
<input
|
|
65
|
-
ref={inputRef}
|
|
66
|
-
checked={checked}
|
|
67
|
-
type="checkbox"
|
|
68
|
-
className={styles.toggleScreenReader}
|
|
69
|
-
aria-label={translate(
|
|
70
|
-
{
|
|
71
|
-
message: 'Switch between dark and light mode (currently {mode})',
|
|
72
|
-
id: 'theme.colorToggle.ariaLabel',
|
|
73
|
-
description: 'The ARIA label for the navbar color mode toggle',
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
mode: checked
|
|
77
|
-
? translate({
|
|
78
|
-
message: 'dark mode',
|
|
79
|
-
id: 'theme.colorToggle.ariaLabel.mode.dark',
|
|
80
|
-
description: 'The name for the dark color mode',
|
|
81
|
-
})
|
|
82
|
-
: translate({
|
|
83
|
-
message: 'light mode',
|
|
84
|
-
id: 'theme.colorToggle.ariaLabel.mode.light',
|
|
85
|
-
description: 'The name for the light color mode',
|
|
86
|
-
}),
|
|
87
|
-
},
|
|
88
|
-
)}
|
|
89
|
-
onChange={onChange}
|
|
90
|
-
onClick={() => setChecked(!checked)}
|
|
91
|
-
onFocus={() => setFocused(true)}
|
|
92
|
-
onBlur={() => setFocused(false)}
|
|
93
|
-
onKeyDown={(e) => {
|
|
94
|
-
if (e.key === 'Enter') {
|
|
95
|
-
inputRef.current?.click();
|
|
96
|
-
}
|
|
97
|
-
}}
|
|
98
|
-
/>
|
|
99
|
-
</div>
|
|
100
|
-
);
|
|
101
|
-
},
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
export default function Toggle(props: Props): JSX.Element {
|
|
105
|
-
const {
|
|
106
|
-
colorMode: {switchConfig},
|
|
107
|
-
} = useThemeConfig();
|
|
108
|
-
const isBrowser = useIsBrowser();
|
|
109
|
-
|
|
110
|
-
return (
|
|
111
|
-
<ToggleComponent
|
|
112
|
-
switchConfig={switchConfig}
|
|
113
|
-
disabled={!isBrowser}
|
|
114
|
-
{...props}
|
|
115
|
-
/>
|
|
116
|
-
);
|
|
117
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
.toggle {
|
|
9
|
-
touch-action: pan-x;
|
|
10
|
-
position: relative;
|
|
11
|
-
cursor: pointer;
|
|
12
|
-
user-select: none;
|
|
13
|
-
-webkit-tap-highlight-color: transparent;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.toggleScreenReader {
|
|
17
|
-
border: 0;
|
|
18
|
-
clip: rect(0 0 0 0);
|
|
19
|
-
height: 1px;
|
|
20
|
-
margin: -1px;
|
|
21
|
-
overflow: hidden;
|
|
22
|
-
position: absolute;
|
|
23
|
-
width: 1px;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.toggleDisabled {
|
|
27
|
-
cursor: not-allowed;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.toggleTrack {
|
|
31
|
-
width: 50px;
|
|
32
|
-
height: 24px;
|
|
33
|
-
border-radius: 30px;
|
|
34
|
-
background-color: #4d4d4d;
|
|
35
|
-
transition: all 0.2s ease;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
.toggleTrackCheck {
|
|
39
|
-
position: absolute;
|
|
40
|
-
width: 14px;
|
|
41
|
-
height: 10px;
|
|
42
|
-
top: 0;
|
|
43
|
-
bottom: 0;
|
|
44
|
-
margin: auto 0;
|
|
45
|
-
left: 8px;
|
|
46
|
-
opacity: 0;
|
|
47
|
-
transition: opacity 0.25s ease;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
.toggleChecked .toggleTrackCheck,
|
|
51
|
-
[data-theme='dark'] .toggle .toggleTrackCheck {
|
|
52
|
-
opacity: 1;
|
|
53
|
-
transition: opacity 0.25s ease;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.toggleTrackX {
|
|
57
|
-
position: absolute;
|
|
58
|
-
width: 10px;
|
|
59
|
-
height: 10px;
|
|
60
|
-
top: 0;
|
|
61
|
-
bottom: 0;
|
|
62
|
-
margin: auto 0;
|
|
63
|
-
right: 10px;
|
|
64
|
-
opacity: 1;
|
|
65
|
-
transition: opacity 0.25s ease;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
.toggleChecked .toggleTrackX,
|
|
69
|
-
[data-theme='dark'] .toggle .toggleTrackX {
|
|
70
|
-
opacity: 0;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.toggleTrackThumb {
|
|
74
|
-
position: absolute;
|
|
75
|
-
top: 1px;
|
|
76
|
-
left: 1px;
|
|
77
|
-
width: 22px;
|
|
78
|
-
height: 22px;
|
|
79
|
-
border: 1px solid #4d4d4d;
|
|
80
|
-
border-radius: 50%;
|
|
81
|
-
background-color: #fafafa;
|
|
82
|
-
transition: all 0.25s ease;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.toggleFocused .toggleTrackThumb,
|
|
86
|
-
.toggle:hover .toggleTrackThumb {
|
|
87
|
-
box-shadow: 0 0 2px 3px var(--ifm-color-primary);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/* stylelint-disable-next-line no-descending-specificity */
|
|
91
|
-
.toggleChecked .toggleTrackThumb,
|
|
92
|
-
[data-theme='dark'] .toggle .toggleTrackThumb {
|
|
93
|
-
left: 27px;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
.toggle:active:not(.toggleDisabled) .toggleTrackThumb {
|
|
97
|
-
box-shadow: 0 0 5px 5px var(--ifm-color-primary);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
.toggleIcon {
|
|
101
|
-
align-items: center;
|
|
102
|
-
display: flex;
|
|
103
|
-
height: 10px;
|
|
104
|
-
justify-content: center;
|
|
105
|
-
width: 10px;
|
|
106
|
-
}
|