@docusaurus/theme-classic 0.0.0-4655 → 0.0.0-4656

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.
@@ -11,91 +11,114 @@ exports.default = getSwizzleConfig;
11
11
  * This source code is licensed under the MIT license found in the
12
12
  * LICENSE file in the root directory of this source tree.
13
13
  */
14
+
15
+ /* eslint sort-keys: "error" */
14
16
  function getSwizzleConfig() {
15
17
  return {
16
18
  components: {
17
19
  CodeBlock: {
18
20
  actions: {
19
- wrap: 'safe',
20
- eject: 'safe'
21
+ eject: 'safe',
22
+ wrap: 'safe'
21
23
  },
22
24
  description: 'The component used to render multi-line code blocks, generally used in Markdown files.'
23
25
  },
26
+ ColorModeToggle: {
27
+ actions: {
28
+ eject: 'safe',
29
+ wrap: 'safe'
30
+ },
31
+ description: 'The color mode toggle to switch between light and dark mode.'
32
+ },
24
33
  DocSidebar: {
25
34
  actions: {
26
- wrap: 'safe',
27
- eject: 'unsafe' // too much technical code in sidebar, not very safe atm
28
-
35
+ eject: 'unsafe',
36
+ // too much technical code in sidebar, not very safe atm
37
+ wrap: 'safe'
29
38
  },
30
39
  description: 'The sidebar component on docs pages'
31
40
  },
32
41
  Footer: {
33
42
  actions: {
34
- wrap: 'safe',
35
- eject: 'unsafe' // TODO split footer into smaller parts
36
-
43
+ eject: 'unsafe',
44
+ // TODO split footer into smaller parts
45
+ wrap: 'safe'
37
46
  },
38
47
  description: "The footer component of you site's layout"
39
48
  },
40
- NotFound: {
41
- actions: {
42
- wrap: 'safe',
43
- eject: 'safe'
44
- },
45
- description: 'The global 404 page of your site, meant to be ejected and customized'
46
- },
47
- SearchBar: {
49
+ IconArrow: {
48
50
  actions: {
49
- wrap: 'safe',
50
- eject: 'safe'
51
+ eject: 'safe',
52
+ wrap: 'safe'
51
53
  },
52
- // TODO how to describe this one properly?
53
- // By default it's an empty placeholder for the user to fill
54
- description: 'The search bar component of your site, appearing in the navbar.'
54
+ description: 'The arrow icon component'
55
55
  },
56
- IconArrow: {
56
+ IconDarkMode: {
57
57
  actions: {
58
- wrap: 'safe',
59
- eject: 'safe'
58
+ eject: 'safe',
59
+ wrap: 'safe'
60
60
  },
61
- description: 'The arrow icon component'
61
+ description: 'The dark mode icon component.'
62
62
  },
63
63
  IconEdit: {
64
64
  actions: {
65
- wrap: 'safe',
66
- eject: 'safe'
65
+ eject: 'safe',
66
+ wrap: 'safe'
67
67
  },
68
68
  description: 'The edit icon component'
69
69
  },
70
- IconMenu: {
70
+ IconLightMode: {
71
71
  actions: {
72
- wrap: 'safe',
73
- eject: 'safe'
72
+ eject: 'safe',
73
+ wrap: 'safe'
74
74
  },
75
- description: 'The menu icon component'
75
+ description: 'The light mode icon component.'
76
76
  },
77
- 'prism-include-languages': {
77
+ IconMenu: {
78
78
  actions: {
79
- wrap: 'forbidden',
80
- // not a component!
81
- eject: 'safe'
79
+ eject: 'safe',
80
+ wrap: 'safe'
82
81
  },
83
- description: 'The Prism languages to include for code block syntax highlighting. Meant to be ejected.'
82
+ description: 'The menu icon component'
84
83
  },
85
84
  MDXComponents: {
86
85
  actions: {
87
- wrap: 'forbidden',
88
- /// TODO allow wrapping objects???
89
- eject: 'safe'
86
+ eject: 'safe',
87
+ wrap: 'forbidden' /// TODO allow wrapping objects???
88
+
90
89
  },
91
90
  description: 'The MDX components to use for rendering MDX files. Meant to be ejected.'
92
91
  },
93
92
  // TODO should probably not even appear here
94
93
  'NavbarItem/utils': {
95
94
  actions: {
96
- wrap: 'forbidden',
97
- eject: 'forbidden'
95
+ eject: 'forbidden',
96
+ wrap: 'forbidden'
98
97
  }
98
+ },
99
+ NotFound: {
100
+ actions: {
101
+ eject: 'safe',
102
+ wrap: 'safe'
103
+ },
104
+ description: 'The global 404 page of your site, meant to be ejected and customized'
105
+ },
106
+ SearchBar: {
107
+ actions: {
108
+ eject: 'safe',
109
+ wrap: 'safe'
110
+ },
111
+ // TODO how to describe this one properly?
112
+ // By default it's an empty placeholder for the user to fill
113
+ description: 'The search bar component of your site, appearing in the navbar.'
114
+ },
115
+ 'prism-include-languages': {
116
+ actions: {
117
+ eject: 'safe',
118
+ wrap: 'forbidden' // not a component!
119
+
120
+ },
121
+ description: 'The Prism languages to include for code block syntax highlighting. Meant to be ejected.'
99
122
  }
100
123
  }
101
124
  };
@@ -632,7 +632,7 @@ declare module '@theme/TOCCollapsible' {
632
632
  export default function TOCCollapsible(props: Props): JSX.Element;
633
633
  }
634
634
 
635
- declare module '@theme/Toggle' {
635
+ declare module '@theme/ColorModeToggle' {
636
636
  import type {SyntheticEvent} from 'react';
637
637
 
638
638
  export interface Props {
@@ -663,6 +663,14 @@ declare module '@theme/IconArrow' {
663
663
  export default function IconArrow(props: Props): JSX.Element;
664
664
  }
665
665
 
666
+ declare module '@theme/IconDarkMode' {
667
+ import type {ComponentProps} from 'react';
668
+
669
+ export interface Props extends ComponentProps<'svg'> {}
670
+
671
+ export default function IconDarkMode(props: Props): JSX.Element;
672
+ }
673
+
666
674
  declare module '@theme/IconEdit' {
667
675
  import type {ComponentProps} from 'react';
668
676
 
@@ -671,6 +679,14 @@ declare module '@theme/IconEdit' {
671
679
  export default function IconEdit(props: Props): JSX.Element;
672
680
  }
673
681
 
682
+ declare module '@theme/IconLightMode' {
683
+ import type {ComponentProps} from 'react';
684
+
685
+ export interface Props extends ComponentProps<'svg'> {}
686
+
687
+ export default function IconLightMode(props: Props): JSX.Element;
688
+ }
689
+
674
690
  declare module '@theme/IconMenu' {
675
691
  import type {ComponentProps} from 'react';
676
692
 
@@ -25,13 +25,7 @@ const DocsSchema = _utilsValidation.Joi.object({
25
25
  const DEFAULT_COLOR_MODE_CONFIG = {
26
26
  defaultMode: 'light',
27
27
  disableSwitch: false,
28
- respectPrefersColorScheme: false,
29
- switchConfig: {
30
- darkIcon: '🌜',
31
- darkIconStyle: {},
32
- lightIcon: '🌞',
33
- lightIconStyle: {}
34
- }
28
+ respectPrefersColorScheme: false
35
29
  };
36
30
  const DEFAULT_CONFIG = {
37
31
  colorMode: DEFAULT_COLOR_MODE_CONFIG,
@@ -189,12 +183,9 @@ const ColorModeSchema = _utilsValidation.Joi.object({
189
183
  defaultMode: _utilsValidation.Joi.string().equal('dark', 'light').default(DEFAULT_COLOR_MODE_CONFIG.defaultMode),
190
184
  disableSwitch: _utilsValidation.Joi.bool().default(DEFAULT_COLOR_MODE_CONFIG.disableSwitch),
191
185
  respectPrefersColorScheme: _utilsValidation.Joi.bool().default(DEFAULT_COLOR_MODE_CONFIG.respectPrefersColorScheme),
192
- switchConfig: _utilsValidation.Joi.object({
193
- darkIcon: _utilsValidation.Joi.string().default(DEFAULT_COLOR_MODE_CONFIG.switchConfig.darkIcon),
194
- darkIconStyle: _utilsValidation.Joi.object().default(DEFAULT_COLOR_MODE_CONFIG.switchConfig.darkIconStyle),
195
- lightIcon: _utilsValidation.Joi.string().default(DEFAULT_COLOR_MODE_CONFIG.switchConfig.lightIcon),
196
- lightIconStyle: _utilsValidation.Joi.object().default(DEFAULT_COLOR_MODE_CONFIG.switchConfig.lightIconStyle)
197
- }).default(DEFAULT_COLOR_MODE_CONFIG.switchConfig)
186
+ switchConfig: _utilsValidation.Joi.any().forbidden().messages({
187
+ 'any.unknown': 'colorMode.switchConfig is deprecated. If you want to customize the icons for light and dark mode, swizzle IconLightMode, IconDarkMode, or ColorModeToggle instead.'
188
+ })
198
189
  }).default(DEFAULT_COLOR_MODE_CONFIG); // schema can probably be improved
199
190
 
200
191
 
@@ -0,0 +1,83 @@
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
+ import React, {useState, useRef, useEffect} from 'react';
8
+ import useIsBrowser from '@docusaurus/useIsBrowser';
9
+ import {translate} from '@docusaurus/Translate';
10
+ import IconLightMode from '@theme/IconLightMode';
11
+ import IconDarkMode from '@theme/IconDarkMode';
12
+ import clsx from 'clsx';
13
+ import styles from './styles.module.css';
14
+
15
+ function ColorModeToggle({className, checked: defaultChecked, onChange}) {
16
+ const isBrowser = useIsBrowser();
17
+ const [checked, setChecked] = useState(defaultChecked);
18
+ const [focused, setFocused] = useState(false);
19
+ const inputRef = useRef(null);
20
+ useEffect(() => {
21
+ setChecked(defaultChecked);
22
+ }, [defaultChecked]);
23
+ return (
24
+ <div
25
+ className={clsx(styles.toggle, className, {
26
+ [styles.toggleChecked]: checked,
27
+ [styles.toggleFocused]: focused,
28
+ [styles.toggleDisabled]: !isBrowser,
29
+ })}>
30
+ {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
31
+ <div
32
+ className={styles.toggleButton}
33
+ role="button"
34
+ tabIndex={-1}
35
+ onClick={() => inputRef.current?.click()}>
36
+ <IconLightMode
37
+ className={clsx(styles.toggleIcon, styles.lightToggleIcon)}
38
+ />
39
+ <IconDarkMode
40
+ className={clsx(styles.toggleIcon, styles.darkToggleIcon)}
41
+ />
42
+ </div>
43
+
44
+ <input
45
+ ref={inputRef}
46
+ checked={checked}
47
+ type="checkbox"
48
+ className={styles.toggleScreenReader}
49
+ aria-label={translate(
50
+ {
51
+ message: 'Switch between dark and light mode (currently {mode})',
52
+ id: 'theme.colorToggle.ariaLabel',
53
+ description: 'The ARIA label for the navbar color mode toggle',
54
+ },
55
+ {
56
+ mode: checked
57
+ ? translate({
58
+ message: 'dark mode',
59
+ id: 'theme.colorToggle.ariaLabel.mode.dark',
60
+ description: 'The name for the dark color mode',
61
+ })
62
+ : translate({
63
+ message: 'light mode',
64
+ id: 'theme.colorToggle.ariaLabel.mode.light',
65
+ description: 'The name for the light color mode',
66
+ }),
67
+ },
68
+ )}
69
+ onChange={onChange}
70
+ onClick={() => setChecked(!checked)}
71
+ onFocus={() => setFocused(true)}
72
+ onBlur={() => setFocused(false)}
73
+ onKeyDown={(e) => {
74
+ if (e.key === 'Enter') {
75
+ inputRef.current?.click();
76
+ }
77
+ }}
78
+ />
79
+ </div>
80
+ );
81
+ }
82
+
83
+ export default React.memo(ColorModeToggle);
@@ -0,0 +1,51 @@
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
+ position: relative;
10
+ width: 32px;
11
+ height: 32px;
12
+ }
13
+
14
+ .toggleScreenReader {
15
+ border: 0;
16
+ clip: rect(0 0 0 0);
17
+ height: 1px;
18
+ margin: -1px;
19
+ overflow: hidden;
20
+ position: absolute;
21
+ width: 1px;
22
+ }
23
+
24
+ .toggleDisabled {
25
+ cursor: not-allowed;
26
+ }
27
+
28
+ .toggleButton {
29
+ cursor: pointer;
30
+ user-select: none;
31
+ -webkit-tap-highlight-color: transparent;
32
+ align-items: center;
33
+ display: flex;
34
+ justify-content: center;
35
+ width: 100%;
36
+ height: 100%;
37
+ border-radius: 50%;
38
+ }
39
+
40
+ .toggleButton:hover {
41
+ background-color: #00000010;
42
+ }
43
+
44
+ [data-theme='dark'] .toggleButton:hover {
45
+ background-color: #ffffff20;
46
+ }
47
+
48
+ [data-theme='light'] .darkToggleIcon,
49
+ [data-theme='dark'] .lightToggleIcon {
50
+ display: none;
51
+ }
@@ -0,0 +1,17 @@
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
+ import React from 'react';
8
+ export default function IconDarkMode(props) {
9
+ return (
10
+ <svg viewBox="0 0 24 24" width={24} height={24} {...props}>
11
+ <path
12
+ fill="currentColor"
13
+ d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"
14
+ />
15
+ </svg>
16
+ );
17
+ }
@@ -0,0 +1,17 @@
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
+ import React from 'react';
8
+ export default function IconLightMode(props) {
9
+ return (
10
+ <svg viewBox="0 0 24 24" width={24} height={24} {...props}>
11
+ <path
12
+ fill="currentColor"
13
+ d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"
14
+ />
15
+ </svg>
16
+ );
17
+ }
@@ -8,7 +8,7 @@ import React, {useCallback, useState, useEffect} from 'react';
8
8
  import clsx from 'clsx';
9
9
  import Translate from '@docusaurus/Translate';
10
10
  import SearchBar from '@theme/SearchBar';
11
- import Toggle from '@theme/Toggle';
11
+ import ColorModeToggle from '@theme/ColorModeToggle';
12
12
  import {
13
13
  useThemeConfig,
14
14
  useMobileSecondaryMenuRenderer,
@@ -157,7 +157,7 @@ function NavbarMobileSidebar({sidebarShown, toggleSidebar}) {
157
157
  titleClassName="navbar__title"
158
158
  />
159
159
  {!colorModeToggle.disabled && (
160
- <Toggle
160
+ <ColorModeToggle
161
161
  className={styles.navbarSidebarToggle}
162
162
  checked={colorModeToggle.isDarkTheme}
163
163
  onChange={colorModeToggle.toggle}
@@ -254,7 +254,7 @@ export default function Navbar() {
254
254
  <NavbarItem {...item} key={i} />
255
255
  ))}
256
256
  {!colorModeToggle.disabled && (
257
- <Toggle
257
+ <ColorModeToggle
258
258
  className={styles.toggle}
259
259
  checked={colorModeToggle.isDarkTheme}
260
260
  onChange={colorModeToggle.toggle}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-classic",
3
- "version": "0.0.0-4655",
3
+ "version": "0.0.0-4656",
4
4
  "description": "Classic theme for Docusaurus",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/theme-classic.d.ts",
@@ -21,15 +21,15 @@
21
21
  "format:lib-next": "prettier --config ../../.prettierrc --write \"lib-next/**/*.{js,ts,jsx,tsc}\""
22
22
  },
23
23
  "dependencies": {
24
- "@docusaurus/core": "0.0.0-4655",
25
- "@docusaurus/plugin-content-blog": "0.0.0-4655",
26
- "@docusaurus/plugin-content-docs": "0.0.0-4655",
27
- "@docusaurus/plugin-content-pages": "0.0.0-4655",
28
- "@docusaurus/theme-common": "0.0.0-4655",
29
- "@docusaurus/theme-translations": "0.0.0-4655",
30
- "@docusaurus/utils": "0.0.0-4655",
31
- "@docusaurus/utils-common": "0.0.0-4655",
32
- "@docusaurus/utils-validation": "0.0.0-4655",
24
+ "@docusaurus/core": "0.0.0-4656",
25
+ "@docusaurus/plugin-content-blog": "0.0.0-4656",
26
+ "@docusaurus/plugin-content-docs": "0.0.0-4656",
27
+ "@docusaurus/plugin-content-pages": "0.0.0-4656",
28
+ "@docusaurus/theme-common": "0.0.0-4656",
29
+ "@docusaurus/theme-translations": "0.0.0-4656",
30
+ "@docusaurus/utils": "0.0.0-4656",
31
+ "@docusaurus/utils-common": "0.0.0-4656",
32
+ "@docusaurus/utils-validation": "0.0.0-4656",
33
33
  "@mdx-js/react": "^1.6.22",
34
34
  "clsx": "^1.1.1",
35
35
  "copy-text-to-clipboard": "^3.0.1",
@@ -42,8 +42,8 @@
42
42
  "rtlcss": "^3.3.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@docusaurus/module-type-aliases": "0.0.0-4655",
46
- "@docusaurus/types": "0.0.0-4655",
45
+ "@docusaurus/module-type-aliases": "0.0.0-4656",
46
+ "@docusaurus/types": "0.0.0-4656",
47
47
  "@types/mdx-js__react": "^1.5.5",
48
48
  "@types/prismjs": "^1.26.0",
49
49
  "@types/rtlcss": "^3.1.2",
@@ -59,5 +59,5 @@
59
59
  "engines": {
60
60
  "node": ">=14"
61
61
  },
62
- "gitHead": "9f0edee4694adaf8c8a6e11ef83991519e1f4b90"
62
+ "gitHead": "9d3c7ee0e8413fe481c1f1be202fd3ec76efb087"
63
63
  }
@@ -7,94 +7,116 @@
7
7
 
8
8
  import type {SwizzleConfig} from '@docusaurus/types';
9
9
 
10
+ /* eslint sort-keys: "error" */
11
+
10
12
  export default function getSwizzleConfig(): SwizzleConfig {
11
13
  return {
12
14
  components: {
13
15
  CodeBlock: {
14
16
  actions: {
15
- wrap: 'safe',
16
17
  eject: 'safe',
18
+ wrap: 'safe',
17
19
  },
18
20
  description:
19
21
  'The component used to render multi-line code blocks, generally used in Markdown files.',
20
22
  },
21
- DocSidebar: {
23
+ ColorModeToggle: {
22
24
  actions: {
25
+ eject: 'safe',
23
26
  wrap: 'safe',
27
+ },
28
+ description:
29
+ 'The color mode toggle to switch between light and dark mode.',
30
+ },
31
+ DocSidebar: {
32
+ actions: {
24
33
  eject: 'unsafe', // too much technical code in sidebar, not very safe atm
34
+ wrap: 'safe',
25
35
  },
26
36
  description: 'The sidebar component on docs pages',
27
37
  },
28
38
  Footer: {
29
39
  actions: {
30
- wrap: 'safe',
31
40
  eject: 'unsafe', // TODO split footer into smaller parts
41
+ wrap: 'safe',
32
42
  },
33
43
  description: "The footer component of you site's layout",
34
44
  },
35
- NotFound: {
45
+ IconArrow: {
36
46
  actions: {
37
- wrap: 'safe',
38
47
  eject: 'safe',
39
- },
40
- description:
41
- 'The global 404 page of your site, meant to be ejected and customized',
42
- },
43
- SearchBar: {
44
- actions: {
45
48
  wrap: 'safe',
46
- eject: 'safe',
47
49
  },
48
- // TODO how to describe this one properly?
49
- // By default it's an empty placeholder for the user to fill
50
- description:
51
- 'The search bar component of your site, appearing in the navbar.',
50
+ description: 'The arrow icon component',
52
51
  },
53
- IconArrow: {
52
+ IconDarkMode: {
54
53
  actions: {
55
- wrap: 'safe',
56
54
  eject: 'safe',
55
+ wrap: 'safe',
57
56
  },
58
- description: 'The arrow icon component',
57
+ description: 'The dark mode icon component.',
59
58
  },
60
59
  IconEdit: {
61
60
  actions: {
62
- wrap: 'safe',
63
61
  eject: 'safe',
62
+ wrap: 'safe',
64
63
  },
65
64
  description: 'The edit icon component',
66
65
  },
67
- IconMenu: {
66
+ IconLightMode: {
68
67
  actions: {
69
- wrap: 'safe',
70
68
  eject: 'safe',
69
+ wrap: 'safe',
71
70
  },
72
- description: 'The menu icon component',
71
+ description: 'The light mode icon component.',
73
72
  },
74
-
75
- 'prism-include-languages': {
73
+ IconMenu: {
76
74
  actions: {
77
- wrap: 'forbidden', // not a component!
78
75
  eject: 'safe',
76
+ wrap: 'safe',
79
77
  },
80
- description:
81
- 'The Prism languages to include for code block syntax highlighting. Meant to be ejected.',
78
+ description: 'The menu icon component',
82
79
  },
83
80
  MDXComponents: {
84
81
  actions: {
85
- wrap: 'forbidden', /// TODO allow wrapping objects???
86
82
  eject: 'safe',
83
+ wrap: 'forbidden', /// TODO allow wrapping objects???
87
84
  },
88
85
  description:
89
86
  'The MDX components to use for rendering MDX files. Meant to be ejected.',
90
87
  },
91
-
92
88
  // TODO should probably not even appear here
93
89
  'NavbarItem/utils': {
94
90
  actions: {
95
- wrap: 'forbidden',
96
91
  eject: 'forbidden',
92
+ wrap: 'forbidden',
93
+ },
94
+ },
95
+ NotFound: {
96
+ actions: {
97
+ eject: 'safe',
98
+ wrap: 'safe',
99
+ },
100
+ description:
101
+ 'The global 404 page of your site, meant to be ejected and customized',
102
+ },
103
+ SearchBar: {
104
+ actions: {
105
+ eject: 'safe',
106
+ wrap: 'safe',
97
107
  },
108
+ // TODO how to describe this one properly?
109
+ // By default it's an empty placeholder for the user to fill
110
+ description:
111
+ 'The search bar component of your site, appearing in the navbar.',
112
+ },
113
+ 'prism-include-languages': {
114
+ actions: {
115
+ eject: 'safe',
116
+ wrap: 'forbidden', // not a component!
117
+ },
118
+ description:
119
+ 'The Prism languages to include for code block syntax highlighting. Meant to be ejected.',
98
120
  },
99
121
  },
100
122
  };
@@ -0,0 +1,92 @@
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} from 'react';
9
+ import type {Props} from '@theme/ColorModeToggle';
10
+ import useIsBrowser from '@docusaurus/useIsBrowser';
11
+ import {translate} from '@docusaurus/Translate';
12
+ import IconLightMode from '@theme/IconLightMode';
13
+ import IconDarkMode from '@theme/IconDarkMode';
14
+
15
+ import clsx from 'clsx';
16
+ import styles from './styles.module.css';
17
+
18
+ function ColorModeToggle({
19
+ className,
20
+ checked: defaultChecked,
21
+ onChange,
22
+ }: Props): JSX.Element {
23
+ const isBrowser = useIsBrowser();
24
+ const [checked, setChecked] = useState(defaultChecked);
25
+ const [focused, setFocused] = useState(false);
26
+ const inputRef = useRef<HTMLInputElement>(null);
27
+
28
+ useEffect(() => {
29
+ setChecked(defaultChecked);
30
+ }, [defaultChecked]);
31
+
32
+ return (
33
+ <div
34
+ className={clsx(styles.toggle, className, {
35
+ [styles.toggleChecked]: checked,
36
+ [styles.toggleFocused]: focused,
37
+ [styles.toggleDisabled]: !isBrowser,
38
+ })}>
39
+ {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
40
+ <div
41
+ className={styles.toggleButton}
42
+ role="button"
43
+ tabIndex={-1}
44
+ onClick={() => inputRef.current?.click()}>
45
+ <IconLightMode
46
+ className={clsx(styles.toggleIcon, styles.lightToggleIcon)}
47
+ />
48
+ <IconDarkMode
49
+ className={clsx(styles.toggleIcon, styles.darkToggleIcon)}
50
+ />
51
+ </div>
52
+
53
+ <input
54
+ ref={inputRef}
55
+ checked={checked}
56
+ type="checkbox"
57
+ className={styles.toggleScreenReader}
58
+ aria-label={translate(
59
+ {
60
+ message: 'Switch between dark and light mode (currently {mode})',
61
+ id: 'theme.colorToggle.ariaLabel',
62
+ description: 'The ARIA label for the navbar color mode toggle',
63
+ },
64
+ {
65
+ mode: checked
66
+ ? translate({
67
+ message: 'dark mode',
68
+ id: 'theme.colorToggle.ariaLabel.mode.dark',
69
+ description: 'The name for the dark color mode',
70
+ })
71
+ : translate({
72
+ message: 'light mode',
73
+ id: 'theme.colorToggle.ariaLabel.mode.light',
74
+ description: 'The name for the light color mode',
75
+ }),
76
+ },
77
+ )}
78
+ onChange={onChange}
79
+ onClick={() => setChecked(!checked)}
80
+ onFocus={() => setFocused(true)}
81
+ onBlur={() => setFocused(false)}
82
+ onKeyDown={(e) => {
83
+ if (e.key === 'Enter') {
84
+ inputRef.current?.click();
85
+ }
86
+ }}
87
+ />
88
+ </div>
89
+ );
90
+ }
91
+
92
+ export default React.memo(ColorModeToggle);
@@ -0,0 +1,51 @@
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
+ position: relative;
10
+ width: 32px;
11
+ height: 32px;
12
+ }
13
+
14
+ .toggleScreenReader {
15
+ border: 0;
16
+ clip: rect(0 0 0 0);
17
+ height: 1px;
18
+ margin: -1px;
19
+ overflow: hidden;
20
+ position: absolute;
21
+ width: 1px;
22
+ }
23
+
24
+ .toggleDisabled {
25
+ cursor: not-allowed;
26
+ }
27
+
28
+ .toggleButton {
29
+ cursor: pointer;
30
+ user-select: none;
31
+ -webkit-tap-highlight-color: transparent;
32
+ align-items: center;
33
+ display: flex;
34
+ justify-content: center;
35
+ width: 100%;
36
+ height: 100%;
37
+ border-radius: 50%;
38
+ }
39
+
40
+ .toggleButton:hover {
41
+ background-color: #00000010;
42
+ }
43
+
44
+ [data-theme='dark'] .toggleButton:hover {
45
+ background-color: #ffffff20;
46
+ }
47
+
48
+ [data-theme='light'] .darkToggleIcon,
49
+ [data-theme='dark'] .lightToggleIcon {
50
+ display: none;
51
+ }
@@ -0,0 +1,20 @@
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 from 'react';
9
+ import type {Props} from '@theme/IconDarkMode';
10
+
11
+ export default function IconDarkMode(props: Props): JSX.Element {
12
+ return (
13
+ <svg viewBox="0 0 24 24" width={24} height={24} {...props}>
14
+ <path
15
+ fill="currentColor"
16
+ d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"
17
+ />
18
+ </svg>
19
+ );
20
+ }
@@ -0,0 +1,20 @@
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 from 'react';
9
+ import type {Props} from '@theme/IconLightMode';
10
+
11
+ export default function IconLightMode(props: Props): JSX.Element {
12
+ return (
13
+ <svg viewBox="0 0 24 24" width={24} height={24} {...props}>
14
+ <path
15
+ fill="currentColor"
16
+ d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"
17
+ />
18
+ </svg>
19
+ );
20
+ }
@@ -9,7 +9,7 @@ import React, {useCallback, useState, useEffect} from 'react';
9
9
  import clsx from 'clsx';
10
10
  import Translate from '@docusaurus/Translate';
11
11
  import SearchBar from '@theme/SearchBar';
12
- import Toggle from '@theme/Toggle';
12
+ import ColorModeToggle from '@theme/ColorModeToggle';
13
13
  import {
14
14
  useThemeConfig,
15
15
  useMobileSecondaryMenuRenderer,
@@ -171,7 +171,7 @@ function NavbarMobileSidebar({
171
171
  titleClassName="navbar__title"
172
172
  />
173
173
  {!colorModeToggle.disabled && (
174
- <Toggle
174
+ <ColorModeToggle
175
175
  className={styles.navbarSidebarToggle}
176
176
  checked={colorModeToggle.isDarkTheme}
177
177
  onChange={colorModeToggle.toggle}
@@ -271,7 +271,7 @@ export default function Navbar(): JSX.Element {
271
271
  <NavbarItem {...item} key={i} />
272
272
  ))}
273
273
  {!colorModeToggle.disabled && (
274
- <Toggle
274
+ <ColorModeToggle
275
275
  className={styles.toggle}
276
276
  checked={colorModeToggle.isDarkTheme}
277
277
  onChange={colorModeToggle.toggle}
@@ -632,7 +632,7 @@ declare module '@theme/TOCCollapsible' {
632
632
  export default function TOCCollapsible(props: Props): JSX.Element;
633
633
  }
634
634
 
635
- declare module '@theme/Toggle' {
635
+ declare module '@theme/ColorModeToggle' {
636
636
  import type {SyntheticEvent} from 'react';
637
637
 
638
638
  export interface Props {
@@ -663,6 +663,14 @@ declare module '@theme/IconArrow' {
663
663
  export default function IconArrow(props: Props): JSX.Element;
664
664
  }
665
665
 
666
+ declare module '@theme/IconDarkMode' {
667
+ import type {ComponentProps} from 'react';
668
+
669
+ export interface Props extends ComponentProps<'svg'> {}
670
+
671
+ export default function IconDarkMode(props: Props): JSX.Element;
672
+ }
673
+
666
674
  declare module '@theme/IconEdit' {
667
675
  import type {ComponentProps} from 'react';
668
676
 
@@ -671,6 +679,14 @@ declare module '@theme/IconEdit' {
671
679
  export default function IconEdit(props: Props): JSX.Element;
672
680
  }
673
681
 
682
+ declare module '@theme/IconLightMode' {
683
+ import type {ComponentProps} from 'react';
684
+
685
+ export interface Props extends ComponentProps<'svg'> {}
686
+
687
+ export default function IconLightMode(props: Props): JSX.Element;
688
+ }
689
+
674
690
  declare module '@theme/IconMenu' {
675
691
  import type {ComponentProps} from 'react';
676
692
 
@@ -21,12 +21,6 @@ const DEFAULT_COLOR_MODE_CONFIG = {
21
21
  defaultMode: 'light',
22
22
  disableSwitch: false,
23
23
  respectPrefersColorScheme: false,
24
- switchConfig: {
25
- darkIcon: '🌜',
26
- darkIconStyle: {},
27
- lightIcon: '🌞',
28
- lightIconStyle: {},
29
- },
30
24
  };
31
25
 
32
26
  export const DEFAULT_CONFIG = {
@@ -220,20 +214,10 @@ const ColorModeSchema = Joi.object({
220
214
  respectPrefersColorScheme: Joi.bool().default(
221
215
  DEFAULT_COLOR_MODE_CONFIG.respectPrefersColorScheme,
222
216
  ),
223
- switchConfig: Joi.object({
224
- darkIcon: Joi.string().default(
225
- DEFAULT_COLOR_MODE_CONFIG.switchConfig.darkIcon,
226
- ),
227
- darkIconStyle: Joi.object().default(
228
- DEFAULT_COLOR_MODE_CONFIG.switchConfig.darkIconStyle,
229
- ),
230
- lightIcon: Joi.string().default(
231
- DEFAULT_COLOR_MODE_CONFIG.switchConfig.lightIcon,
232
- ),
233
- lightIconStyle: Joi.object().default(
234
- DEFAULT_COLOR_MODE_CONFIG.switchConfig.lightIconStyle,
235
- ),
236
- }).default(DEFAULT_COLOR_MODE_CONFIG.switchConfig),
217
+ switchConfig: Joi.any().forbidden().messages({
218
+ 'any.unknown':
219
+ 'colorMode.switchConfig is deprecated. If you want to customize the icons for light and dark mode, swizzle IconLightMode, IconDarkMode, or ColorModeToggle instead.',
220
+ }),
237
221
  }).default(DEFAULT_COLOR_MODE_CONFIG);
238
222
 
239
223
  // schema can probably be improved
@@ -1,100 +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
- import React, {useState, useRef, useEffect, memo} from 'react';
8
- import {useThemeConfig} from '@docusaurus/theme-common';
9
- import useIsBrowser from '@docusaurus/useIsBrowser';
10
- import {translate} from '@docusaurus/Translate';
11
- import clsx from 'clsx';
12
- import styles from './styles.module.css'; // Based on react-toggle (https://github.com/aaronshaf/react-toggle/).
13
-
14
- const ToggleComponent = memo(
15
- ({className, switchConfig, checked: defaultChecked, disabled, onChange}) => {
16
- const {darkIcon, darkIconStyle, lightIcon, lightIconStyle} = switchConfig;
17
- const [checked, setChecked] = useState(defaultChecked);
18
- const [focused, setFocused] = useState(false);
19
- const inputRef = useRef(null);
20
- useEffect(() => {
21
- setChecked(defaultChecked);
22
- }, [defaultChecked]);
23
- return (
24
- <div
25
- className={clsx(styles.toggle, className, {
26
- [styles.toggleChecked]: checked,
27
- [styles.toggleFocused]: focused,
28
- [styles.toggleDisabled]: disabled,
29
- })}>
30
- {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
31
- <div
32
- className={styles.toggleTrack}
33
- role="button"
34
- tabIndex={-1}
35
- onClick={() => inputRef.current?.click()}>
36
- <div className={styles.toggleTrackCheck}>
37
- <span className={styles.toggleIcon} style={darkIconStyle}>
38
- {darkIcon}
39
- </span>
40
- </div>
41
- <div className={styles.toggleTrackX}>
42
- <span className={styles.toggleIcon} style={lightIconStyle}>
43
- {lightIcon}
44
- </span>
45
- </div>
46
- <div className={styles.toggleTrackThumb} />
47
- </div>
48
-
49
- <input
50
- ref={inputRef}
51
- checked={checked}
52
- type="checkbox"
53
- className={styles.toggleScreenReader}
54
- aria-label={translate(
55
- {
56
- message: 'Switch between dark and light mode (currently {mode})',
57
- id: 'theme.colorToggle.ariaLabel',
58
- description: 'The ARIA label for the navbar color mode toggle',
59
- },
60
- {
61
- mode: checked
62
- ? translate({
63
- message: 'dark mode',
64
- id: 'theme.colorToggle.ariaLabel.mode.dark',
65
- description: 'The name for the dark color mode',
66
- })
67
- : translate({
68
- message: 'light mode',
69
- id: 'theme.colorToggle.ariaLabel.mode.light',
70
- description: 'The name for the light color mode',
71
- }),
72
- },
73
- )}
74
- onChange={onChange}
75
- onClick={() => setChecked(!checked)}
76
- onFocus={() => setFocused(true)}
77
- onBlur={() => setFocused(false)}
78
- onKeyDown={(e) => {
79
- if (e.key === 'Enter') {
80
- inputRef.current?.click();
81
- }
82
- }}
83
- />
84
- </div>
85
- );
86
- },
87
- );
88
- export default function Toggle(props) {
89
- const {
90
- colorMode: {switchConfig},
91
- } = useThemeConfig();
92
- const isBrowser = useIsBrowser();
93
- return (
94
- <ToggleComponent
95
- switchConfig={switchConfig}
96
- disabled={!isBrowser}
97
- {...props}
98
- />
99
- );
100
- }
@@ -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
- }