This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
declare const AllThemes: readonly ["light", "dark"];
type Theme = (typeof AllThemes)[number];
type RenderFn = ({ theme, className, }: {
theme: Theme;
className: string;
}) => React.ReactNode;
type Props = {
children: RenderFn;
className?: string;
};
/**
* Generic component to render anything themed in light/dark
* Note: it's preferable to use CSS for theming because this component
* will need to render all the variants during SSR to avoid a theme flash.
*
* Use this only when CSS customizations are not convenient or impossible.
* For example, rendering themed images or SVGs...
*
* @param className applied to all the variants
* @param children function to render a theme variant
* @constructor
*/
export default function ThemedComponent({ className, children, }: Props): JSX.Element;
export {};
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +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"}

View File

@@ -0,0 +1,48 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import clsx from 'clsx';
import useIsBrowser from '@docusaurus/useIsBrowser';
import { useColorMode } from '../../contexts/colorMode';
import styles from './styles.module.css';
const AllThemes = ['light', 'dark'];
/**
* Generic component to render anything themed in light/dark
* Note: it's preferable to use CSS for theming because this component
* will need to render all the variants during SSR to avoid a theme flash.
*
* Use this only when CSS customizations are not convenient or impossible.
* For example, rendering themed images or SVGs...
*
* @param className applied to all the variants
* @param children function to render a theme variant
* @constructor
*/
export default function ThemedComponent({ className, children, }) {
const isBrowser = useIsBrowser();
const { colorMode } = useColorMode();
function getThemesToRender() {
if (isBrowser) {
return colorMode === 'dark' ? ['dark'] : ['light'];
}
// We need to render both components on the server / hydration to avoid:
// - a flash of wrong theme before hydration
// - React hydration mismatches
// See https://github.com/facebook/docusaurus/pull/3730
return ['light', 'dark'];
}
return (<>
{getThemesToRender().map((theme) => {
const themedElement = children({
theme,
className: clsx(className, styles.themedComponent, styles[`themedComponent--${theme}`]),
});
return <React.Fragment key={theme}>{themedElement}</React.Fragment>;
})}
</>);
}
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +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"}

View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
.themedComponent {
display: none;
}
[data-theme='light'] .themedComponent--light {
display: initial;
}
[data-theme='dark'] .themedComponent--dark {
display: initial;
}
/*
JS disabled??? Show light version by default => better than showing nothing
TODO bad, but we currently always show light mode when there's no data-theme
*/
html:not([data-theme]) .themedComponent--light {
display: initial;
}