@docusaurus/theme-classic 0.0.0-4243 → 0.0.0-4248

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = _default;
6
+ exports.default = Toggle;
7
7
 
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
 
@@ -27,32 +27,20 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
27
27
  * This source code is licensed under the MIT license found in the
28
28
  * LICENSE file in the root directory of this source tree.
29
29
  */
30
- function Dark({
31
- icon,
32
- style
33
- }) {
34
- return <span className={(0, _clsx.default)(_stylesModule.default.toggleIcon, _stylesModule.default.dark)} style={style}>
35
- {icon}
36
- </span>;
37
- }
38
-
39
- function Light({
40
- icon,
41
- style
42
- }) {
43
- return <span className={(0, _clsx.default)(_stylesModule.default.toggleIcon, _stylesModule.default.light)} style={style}>
44
- {icon}
45
- </span>;
46
- } // Based on react-toggle (https://github.com/aaronshaf/react-toggle/).
47
-
48
-
49
- const Toggle = (0, _react.memo)(({
30
+ // Based on react-toggle (https://github.com/aaronshaf/react-toggle/).
31
+ const ToggleComponent = (0, _react.memo)(({
50
32
  className,
51
- icons,
33
+ switchConfig,
52
34
  checked: defaultChecked,
53
35
  disabled,
54
36
  onChange
55
37
  }) => {
38
+ const {
39
+ darkIcon,
40
+ darkIconStyle,
41
+ lightIcon,
42
+ lightIconStyle
43
+ } = switchConfig;
56
44
  const [checked, setChecked] = (0, _react.useState)(defaultChecked);
57
45
  const [focused, setFocused] = (0, _react.useState)(false);
58
46
  const inputRef = (0, _react.useRef)(null);
@@ -69,8 +57,16 @@ const Toggle = (0, _react.memo)(({
69
57
 
70
58
  return (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.click();
71
59
  }}>
72
- <div className={_stylesModule.default.toggleTrackCheck}>{icons.checked}</div>
73
- <div className={_stylesModule.default.toggleTrackX}>{icons.unchecked}</div>
60
+ <div className={_stylesModule.default.toggleTrackCheck}>
61
+ <span className={_stylesModule.default.toggleIcon} style={darkIconStyle}>
62
+ {darkIcon}
63
+ </span>
64
+ </div>
65
+ <div className={_stylesModule.default.toggleTrackX}>
66
+ <span className={_stylesModule.default.toggleIcon} style={lightIconStyle}>
67
+ {lightIcon}
68
+ </span>
69
+ </div>
74
70
  <div className={_stylesModule.default.toggleTrackThumb} />
75
71
  </div>
76
72
 
@@ -84,20 +80,12 @@ const Toggle = (0, _react.memo)(({
84
80
  </div>;
85
81
  });
86
82
 
87
- function _default(props) {
83
+ function Toggle(props) {
88
84
  const {
89
85
  colorMode: {
90
- switchConfig: {
91
- darkIcon,
92
- darkIconStyle,
93
- lightIcon,
94
- lightIconStyle
95
- }
86
+ switchConfig
96
87
  }
97
88
  } = (0, _themeCommon.useThemeConfig)();
98
89
  const isBrowser = (0, _useIsBrowser.default)();
99
- return <Toggle disabled={!isBrowser} icons={{
100
- checked: <Dark icon={darkIcon} style={darkIconStyle} />,
101
- unchecked: <Light icon={lightIcon} style={lightIconStyle} />
102
- }} {...props} />;
90
+ return <ToggleComponent switchConfig={switchConfig} disabled={!isBrowser} {...props} />;
103
91
  }
@@ -103,6 +103,3 @@
103
103
  justify-content: center;
104
104
  width: 10px;
105
105
  }
106
- .toggle::before {
107
- position: absolute;
108
- }
@@ -8,26 +8,11 @@ import React, {useState, useRef, memo} from 'react';
8
8
  import {useThemeConfig} from '@docusaurus/theme-common';
9
9
  import useIsBrowser from '@docusaurus/useIsBrowser';
10
10
  import clsx from 'clsx';
11
- import styles from './styles.module.css';
11
+ import styles from './styles.module.css'; // Based on react-toggle (https://github.com/aaronshaf/react-toggle/).
12
12
 
13
- function Dark({icon, style}) {
14
- return (
15
- <span className={clsx(styles.toggleIcon, styles.dark)} style={style}>
16
- {icon}
17
- </span>
18
- );
19
- }
20
-
21
- function Light({icon, style}) {
22
- return (
23
- <span className={clsx(styles.toggleIcon, styles.light)} style={style}>
24
- {icon}
25
- </span>
26
- );
27
- } // Based on react-toggle (https://github.com/aaronshaf/react-toggle/).
28
-
29
- const Toggle = memo(
30
- ({className, icons, checked: defaultChecked, disabled, onChange}) => {
13
+ const ToggleComponent = memo(
14
+ ({className, switchConfig, checked: defaultChecked, disabled, onChange}) => {
15
+ const {darkIcon, darkIconStyle, lightIcon, lightIconStyle} = switchConfig;
31
16
  const [checked, setChecked] = useState(defaultChecked);
32
17
  const [focused, setFocused] = useState(false);
33
18
  const inputRef = useRef(null);
@@ -44,8 +29,16 @@ const Toggle = memo(
44
29
  role="button"
45
30
  tabIndex={-1}
46
31
  onClick={() => inputRef.current?.click()}>
47
- <div className={styles.toggleTrackCheck}>{icons.checked}</div>
48
- <div className={styles.toggleTrackX}>{icons.unchecked}</div>
32
+ <div className={styles.toggleTrackCheck}>
33
+ <span className={styles.toggleIcon} style={darkIconStyle}>
34
+ {darkIcon}
35
+ </span>
36
+ </div>
37
+ <div className={styles.toggleTrackX}>
38
+ <span className={styles.toggleIcon} style={lightIconStyle}>
39
+ {lightIcon}
40
+ </span>
41
+ </div>
49
42
  <div className={styles.toggleTrackThumb} />
50
43
  </div>
51
44
 
@@ -69,20 +62,15 @@ const Toggle = memo(
69
62
  );
70
63
  },
71
64
  );
72
- export default function (props) {
65
+ export default function Toggle(props) {
73
66
  const {
74
- colorMode: {
75
- switchConfig: {darkIcon, darkIconStyle, lightIcon, lightIconStyle},
76
- },
67
+ colorMode: {switchConfig},
77
68
  } = useThemeConfig();
78
69
  const isBrowser = useIsBrowser();
79
70
  return (
80
- <Toggle
71
+ <ToggleComponent
72
+ switchConfig={switchConfig}
81
73
  disabled={!isBrowser}
82
- icons={{
83
- checked: <Dark icon={darkIcon} style={darkIconStyle} />,
84
- unchecked: <Light icon={lightIcon} style={lightIconStyle} />,
85
- }}
86
74
  {...props}
87
75
  />
88
76
  );
@@ -103,6 +103,3 @@
103
103
  justify-content: center;
104
104
  width: 10px;
105
105
  }
106
- .toggle::before {
107
- position: absolute;
108
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-classic",
3
- "version": "0.0.0-4243",
3
+ "version": "0.0.0-4248",
4
4
  "description": "Classic theme for Docusaurus",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/theme-classic.d.ts",
@@ -23,14 +23,14 @@
23
23
  "update-code-translations": "node -e 'require(\"./update-code-translations.js\").run()'"
24
24
  },
25
25
  "dependencies": {
26
- "@docusaurus/core": "0.0.0-4243",
27
- "@docusaurus/plugin-content-blog": "0.0.0-4243",
28
- "@docusaurus/plugin-content-docs": "0.0.0-4243",
29
- "@docusaurus/plugin-content-pages": "0.0.0-4243",
30
- "@docusaurus/theme-common": "0.0.0-4243",
31
- "@docusaurus/theme-translations": "0.0.0-4243",
32
- "@docusaurus/utils": "0.0.0-4243",
33
- "@docusaurus/utils-validation": "0.0.0-4243",
26
+ "@docusaurus/core": "0.0.0-4248",
27
+ "@docusaurus/plugin-content-blog": "0.0.0-4248",
28
+ "@docusaurus/plugin-content-docs": "0.0.0-4248",
29
+ "@docusaurus/plugin-content-pages": "0.0.0-4248",
30
+ "@docusaurus/theme-common": "0.0.0-4248",
31
+ "@docusaurus/theme-translations": "0.0.0-4248",
32
+ "@docusaurus/utils": "0.0.0-4248",
33
+ "@docusaurus/utils-validation": "0.0.0-4248",
34
34
  "@mdx-js/mdx": "^1.6.21",
35
35
  "@mdx-js/react": "^1.6.21",
36
36
  "chalk": "^4.1.2",
@@ -46,8 +46,8 @@
46
46
  "rtlcss": "^3.3.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@docusaurus/module-type-aliases": "0.0.0-4243",
50
- "@docusaurus/types": "0.0.0-4243",
49
+ "@docusaurus/module-type-aliases": "0.0.0-4248",
50
+ "@docusaurus/types": "0.0.0-4248",
51
51
  "@types/mdx-js__react": "^1.5.4",
52
52
  "@types/parse-numeric-range": "^0.0.1",
53
53
  "@types/rtlcss": "^3.1.1",
@@ -62,5 +62,5 @@
62
62
  "engines": {
63
63
  "node": ">=14"
64
64
  },
65
- "gitHead": "9ff41c223c3422e3483bc1049ee9ec703d11e0cd"
65
+ "gitHead": "8e90c0997091505e1992605827901633ba301c1b"
66
66
  }
@@ -5,46 +5,27 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import React, {useState, useRef, memo, CSSProperties} from 'react';
8
+ import React, {useState, useRef, memo} from 'react';
9
9
  import type {Props} from '@theme/Toggle';
10
- import {useThemeConfig} from '@docusaurus/theme-common';
10
+ import {useThemeConfig, ColorModeConfig} from '@docusaurus/theme-common';
11
11
  import useIsBrowser from '@docusaurus/useIsBrowser';
12
12
 
13
13
  import clsx from 'clsx';
14
14
  import styles from './styles.module.css';
15
15
 
16
- interface IconProps {
17
- icon: string;
18
- style: CSSProperties;
19
- }
20
-
21
- function Dark({icon, style}: IconProps): JSX.Element {
22
- return (
23
- <span className={clsx(styles.toggleIcon, styles.dark)} style={style}>
24
- {icon}
25
- </span>
26
- );
27
- }
28
- function Light({icon, style}: IconProps): JSX.Element {
29
- return (
30
- <span className={clsx(styles.toggleIcon, styles.light)} style={style}>
31
- {icon}
32
- </span>
33
- );
34
- }
35
-
36
16
  // Based on react-toggle (https://github.com/aaronshaf/react-toggle/).
37
- const Toggle = memo(
17
+ const ToggleComponent = memo(
38
18
  ({
39
19
  className,
40
- icons,
20
+ switchConfig,
41
21
  checked: defaultChecked,
42
22
  disabled,
43
23
  onChange,
44
24
  }: Props & {
45
- icons: {checked: JSX.Element; unchecked: JSX.Element};
25
+ switchConfig: ColorModeConfig['switchConfig'];
46
26
  disabled: boolean;
47
27
  }): JSX.Element => {
28
+ const {darkIcon, darkIconStyle, lightIcon, lightIconStyle} = switchConfig;
48
29
  const [checked, setChecked] = useState(defaultChecked);
49
30
  const [focused, setFocused] = useState(false);
50
31
  const inputRef = useRef<HTMLInputElement>(null);
@@ -62,8 +43,16 @@ const Toggle = memo(
62
43
  role="button"
63
44
  tabIndex={-1}
64
45
  onClick={() => inputRef.current?.click()}>
65
- <div className={styles.toggleTrackCheck}>{icons.checked}</div>
66
- <div className={styles.toggleTrackX}>{icons.unchecked}</div>
46
+ <div className={styles.toggleTrackCheck}>
47
+ <span className={styles.toggleIcon} style={darkIconStyle}>
48
+ {darkIcon}
49
+ </span>
50
+ </div>
51
+ <div className={styles.toggleTrackX}>
52
+ <span className={styles.toggleIcon} style={lightIconStyle}>
53
+ {lightIcon}
54
+ </span>
55
+ </div>
67
56
  <div className={styles.toggleTrackThumb} />
68
57
  </div>
69
58
 
@@ -88,21 +77,16 @@ const Toggle = memo(
88
77
  },
89
78
  );
90
79
 
91
- export default function (props: Props): JSX.Element {
80
+ export default function Toggle(props: Props): JSX.Element {
92
81
  const {
93
- colorMode: {
94
- switchConfig: {darkIcon, darkIconStyle, lightIcon, lightIconStyle},
95
- },
82
+ colorMode: {switchConfig},
96
83
  } = useThemeConfig();
97
84
  const isBrowser = useIsBrowser();
98
85
 
99
86
  return (
100
- <Toggle
87
+ <ToggleComponent
88
+ switchConfig={switchConfig}
101
89
  disabled={!isBrowser}
102
- icons={{
103
- checked: <Dark icon={darkIcon} style={darkIconStyle} />,
104
- unchecked: <Light icon={lightIcon} style={lightIconStyle} />,
105
- }}
106
90
  {...props}
107
91
  />
108
92
  );
@@ -103,6 +103,3 @@
103
103
  justify-content: center;
104
104
  width: 10px;
105
105
  }
106
- .toggle::before {
107
- position: absolute;
108
- }