@docusaurus/theme-common 0.0.0-5539 → 0.0.0-5545
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/components/ThemedComponent/index.d.ts +32 -0
- package/lib/components/ThemedComponent/index.d.ts.map +1 -0
- package/lib/components/ThemedComponent/index.js +48 -0
- package/lib/components/ThemedComponent/index.js.map +1 -0
- package/lib/components/ThemedComponent/styles.module.css +18 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/package.json +11 -11
- package/src/components/ThemedComponent/index.tsx +77 -0
- package/src/components/ThemedComponent/styles.module.css +18 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
declare const AllThemes: readonly ["light", "dark"];
|
|
9
|
+
type Theme = (typeof AllThemes)[number];
|
|
10
|
+
type RenderFn = ({ theme, className, }: {
|
|
11
|
+
theme: Theme;
|
|
12
|
+
className: string;
|
|
13
|
+
}) => React.ReactNode;
|
|
14
|
+
type Props = {
|
|
15
|
+
children: RenderFn;
|
|
16
|
+
className?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Generic component to render anything themed in light/dark
|
|
20
|
+
* Note: it's preferable to use CSS for theming because this component
|
|
21
|
+
* will need to render all the variants during SSR to avoid a theme flash.
|
|
22
|
+
*
|
|
23
|
+
* Use this only when CSS customizations are not convenient or impossible.
|
|
24
|
+
* For example, rendering themed images or SVGs...
|
|
25
|
+
*
|
|
26
|
+
* @param className applied to all the variants
|
|
27
|
+
* @param children function to render a theme variant
|
|
28
|
+
* @constructor
|
|
29
|
+
*/
|
|
30
|
+
export default function ThemedComponent({ className, children, }: Props): JSX.Element;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ThemedComponent/index.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,QAAA,MAAM,SAAS,4BAA6B,CAAC;AAE7C,KAAK,KAAK,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAExC,KAAK,QAAQ,GAAG,CAAC,EACf,KAAK,EACL,SAAS,GACV,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,KAAK,KAAK,CAAC,SAAS,CAAC;AAEtB,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EACtC,SAAS,EACT,QAAQ,GACT,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CA8BrB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
import clsx from 'clsx';
|
|
9
|
+
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
10
|
+
import { useColorMode } from '../../contexts/colorMode';
|
|
11
|
+
import styles from './styles.module.css';
|
|
12
|
+
const AllThemes = ['light', 'dark'];
|
|
13
|
+
/**
|
|
14
|
+
* Generic component to render anything themed in light/dark
|
|
15
|
+
* Note: it's preferable to use CSS for theming because this component
|
|
16
|
+
* will need to render all the variants during SSR to avoid a theme flash.
|
|
17
|
+
*
|
|
18
|
+
* Use this only when CSS customizations are not convenient or impossible.
|
|
19
|
+
* For example, rendering themed images or SVGs...
|
|
20
|
+
*
|
|
21
|
+
* @param className applied to all the variants
|
|
22
|
+
* @param children function to render a theme variant
|
|
23
|
+
* @constructor
|
|
24
|
+
*/
|
|
25
|
+
export default function ThemedComponent({ className, children, }) {
|
|
26
|
+
const isBrowser = useIsBrowser();
|
|
27
|
+
const { colorMode } = useColorMode();
|
|
28
|
+
function getThemesToRender() {
|
|
29
|
+
if (isBrowser) {
|
|
30
|
+
return colorMode === 'dark' ? ['dark'] : ['light'];
|
|
31
|
+
}
|
|
32
|
+
// We need to render both components on the server / hydration to avoid:
|
|
33
|
+
// - a flash of wrong theme before hydration
|
|
34
|
+
// - React hydration mismatches
|
|
35
|
+
// See https://github.com/facebook/docusaurus/pull/3730
|
|
36
|
+
return ['light', 'dark'];
|
|
37
|
+
}
|
|
38
|
+
return (<>
|
|
39
|
+
{getThemesToRender().map((theme) => {
|
|
40
|
+
const themedElement = children({
|
|
41
|
+
theme,
|
|
42
|
+
className: clsx(className, styles.themedComponent, styles[`themedComponent--${theme}`]),
|
|
43
|
+
});
|
|
44
|
+
return <React.Fragment key={theme}>{themedElement}</React.Fragment>;
|
|
45
|
+
})}
|
|
46
|
+
</>);
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/ThemedComponent/index.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,YAAY,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAEtD,OAAO,MAAM,MAAM,qBAAqB,CAAC;AAEzC,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE,MAAM,CAAU,CAAC;AAiB7C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,EACtC,SAAS,EACT,QAAQ,GACF;IACN,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IACjC,MAAM,EAAC,SAAS,EAAC,GAAG,YAAY,EAAE,CAAC;IAEnC,SAAS,iBAAiB;QACxB,IAAI,SAAS,EAAE;YACb,OAAO,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SACpD;QACD,wEAAwE;QACxE,4CAA4C;QAC5C,+BAA+B;QAC/B,uDAAuD;QACvD,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,CACL,EACE;MAAA,CAAC,iBAAiB,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACjC,MAAM,aAAa,GAAG,QAAQ,CAAC;gBAC7B,KAAK;gBACL,SAAS,EAAE,IAAI,CACb,SAAS,EACT,MAAM,CAAC,eAAe,EACtB,MAAM,CAAC,oBAAoB,KAAK,EAAE,CAAC,CACpC;aACF,CAAC,CAAC;YACH,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;QACtE,CAAC,CAAC,CACJ;IAAA,GAAG,CACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
.themedComponent {
|
|
9
|
+
display: none;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
[data-theme='light'] .themedComponent--light {
|
|
13
|
+
display: initial;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
[data-theme='dark'] .themedComponent--dark {
|
|
17
|
+
display: initial;
|
|
18
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
export { useThemeConfig, type ThemeConfig, type UserThemeConfig, type Navbar, type NavbarItem, type NavbarLogo, type MultiColumnFooter, type SimpleFooter, type Footer, type FooterLogo, type FooterLinkItem, type ColorModeConfig, } from './utils/useThemeConfig';
|
|
8
|
+
export { default as ThemedComponent } from './components/ThemedComponent';
|
|
8
9
|
export { createStorageSlot, useStorageSlot, listStorageKeys, } from './utils/storageUtils';
|
|
9
10
|
export { useContextualSearchFilters } from './utils/searchUtils';
|
|
10
11
|
export { useCurrentSidebarCategory, filterDocCardListItems, } from './utils/docsUtils';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EACL,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAC,0BAA0B,EAAC,MAAM,qBAAqB,CAAC;AAE/D,OAAO,EACL,yBAAyB,EACzB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAC,aA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oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAC,wBAAwB,EAAC,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAC,mBAAmB,EAAC,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAC,UAAU,EAAE,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAC,uBAAuB,EAAC,MAAM,iCAAiC,CAAC;AAExE,OAAO,EAAC,sBAAsB,EAAC,MAAM,yBAAyB,CAAC;AAE/D,OAAO,EACL,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* APIs to document
|
|
9
9
|
*/
|
|
10
10
|
export { useThemeConfig, } from './utils/useThemeConfig';
|
|
11
|
+
export { default as ThemedComponent } from './components/ThemedComponent';
|
|
11
12
|
export { createStorageSlot, useStorageSlot, listStorageKeys, } from './utils/storageUtils';
|
|
12
13
|
export { useContextualSearchFilters } from './utils/searchUtils';
|
|
13
14
|
export { useCurrentSidebarCategory, filterDocCardListItems, } from './utils/docsUtils';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AAEH,OAAO,EACL,cAAc,GAYf,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAC,0BAA0B,EAAC,MAAM,qBA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AU,EAAE,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAC,uBAAuB,EAAC,MAAM,iCAAiC,CAAC;AAExE,OAAO,EAAC,sBAAsB,EAAC,MAAM,yBAAyB,CAAC;AAE/D,OAAO,EACL,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-common",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-5545",
|
|
4
4
|
"description": "Common code for Docusaurus themes.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
},
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
34
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
35
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
36
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
37
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
38
|
-
"@docusaurus/utils": "0.0.0-
|
|
39
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
33
|
+
"@docusaurus/mdx-loader": "0.0.0-5545",
|
|
34
|
+
"@docusaurus/module-type-aliases": "0.0.0-5545",
|
|
35
|
+
"@docusaurus/plugin-content-blog": "0.0.0-5545",
|
|
36
|
+
"@docusaurus/plugin-content-docs": "0.0.0-5545",
|
|
37
|
+
"@docusaurus/plugin-content-pages": "0.0.0-5545",
|
|
38
|
+
"@docusaurus/utils": "0.0.0-5545",
|
|
39
|
+
"@docusaurus/utils-common": "0.0.0-5545",
|
|
40
40
|
"@types/history": "^4.7.11",
|
|
41
41
|
"@types/react": "*",
|
|
42
42
|
"@types/react-router-config": "*",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"utility-types": "^3.10.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@docusaurus/core": "0.0.0-
|
|
52
|
-
"@docusaurus/types": "0.0.0-
|
|
51
|
+
"@docusaurus/core": "0.0.0-5545",
|
|
52
|
+
"@docusaurus/types": "0.0.0-5545",
|
|
53
53
|
"fs-extra": "^11.1.0",
|
|
54
54
|
"lodash": "^4.17.21"
|
|
55
55
|
},
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=16.14"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "862e4be6c3aea4d26fce77e3ef31f644ce386962"
|
|
64
64
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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 clsx from 'clsx';
|
|
10
|
+
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
11
|
+
import {useColorMode} from '../../contexts/colorMode';
|
|
12
|
+
|
|
13
|
+
import styles from './styles.module.css';
|
|
14
|
+
|
|
15
|
+
const AllThemes = ['light', 'dark'] as const;
|
|
16
|
+
|
|
17
|
+
type Theme = (typeof AllThemes)[number];
|
|
18
|
+
|
|
19
|
+
type RenderFn = ({
|
|
20
|
+
theme,
|
|
21
|
+
className,
|
|
22
|
+
}: {
|
|
23
|
+
theme: Theme;
|
|
24
|
+
className: string;
|
|
25
|
+
}) => React.ReactNode;
|
|
26
|
+
|
|
27
|
+
type Props = {
|
|
28
|
+
children: RenderFn;
|
|
29
|
+
className?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Generic component to render anything themed in light/dark
|
|
34
|
+
* Note: it's preferable to use CSS for theming because this component
|
|
35
|
+
* will need to render all the variants during SSR to avoid a theme flash.
|
|
36
|
+
*
|
|
37
|
+
* Use this only when CSS customizations are not convenient or impossible.
|
|
38
|
+
* For example, rendering themed images or SVGs...
|
|
39
|
+
*
|
|
40
|
+
* @param className applied to all the variants
|
|
41
|
+
* @param children function to render a theme variant
|
|
42
|
+
* @constructor
|
|
43
|
+
*/
|
|
44
|
+
export default function ThemedComponent({
|
|
45
|
+
className,
|
|
46
|
+
children,
|
|
47
|
+
}: Props): JSX.Element {
|
|
48
|
+
const isBrowser = useIsBrowser();
|
|
49
|
+
const {colorMode} = useColorMode();
|
|
50
|
+
|
|
51
|
+
function getThemesToRender(): Theme[] {
|
|
52
|
+
if (isBrowser) {
|
|
53
|
+
return colorMode === 'dark' ? ['dark'] : ['light'];
|
|
54
|
+
}
|
|
55
|
+
// We need to render both components on the server / hydration to avoid:
|
|
56
|
+
// - a flash of wrong theme before hydration
|
|
57
|
+
// - React hydration mismatches
|
|
58
|
+
// See https://github.com/facebook/docusaurus/pull/3730
|
|
59
|
+
return ['light', 'dark'];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<>
|
|
64
|
+
{getThemesToRender().map((theme) => {
|
|
65
|
+
const themedElement = children({
|
|
66
|
+
theme,
|
|
67
|
+
className: clsx(
|
|
68
|
+
className,
|
|
69
|
+
styles.themedComponent,
|
|
70
|
+
styles[`themedComponent--${theme}`],
|
|
71
|
+
),
|
|
72
|
+
});
|
|
73
|
+
return <React.Fragment key={theme}>{themedElement}</React.Fragment>;
|
|
74
|
+
})}
|
|
75
|
+
</>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
.themedComponent {
|
|
9
|
+
display: none;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
[data-theme='light'] .themedComponent--light {
|
|
13
|
+
display: initial;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
[data-theme='dark'] .themedComponent--dark {
|
|
17
|
+
display: initial;
|
|
18
|
+
}
|