update docusaurus to v2.0.0-beta.5
Signed-off-by: jffarge <jf@dagger.io>
This commit is contained in:
@@ -33,9 +33,8 @@ $desktop-xl-width: 1160px;
|
||||
--ifm-background-color: var(--ifm-color-primary-light);
|
||||
--ifm-code-background: var(--ifm-color-primary-dark);
|
||||
--ifm-code-font-size: 100%;
|
||||
--ifm-code-border-radius: 2rem;
|
||||
--ifm-code-color: var(--ifm-color-primary-light);
|
||||
--ifm-code-padding-vertical: 0;
|
||||
--ifm-code-padding-vertical: 0.05rem;
|
||||
--ifm-code-padding-horizontal: 0.2rem;
|
||||
--ifm-color-primary: #0e2b3d;
|
||||
--ifm-color-primary-dark: #131226;
|
||||
@@ -143,6 +142,16 @@ code {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
li {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 500px;
|
||||
display: block;
|
||||
margin: auto;
|
||||
}
|
||||
}
|
||||
|
||||
p {
|
||||
@@ -236,6 +245,14 @@ h1[class^="h1Heading"] {
|
||||
.navbar {
|
||||
align-self: center;
|
||||
box-shadow: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.navbar-sidebar__back {
|
||||
background: transparent;
|
||||
color: white;
|
||||
padding: 1rem 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.navbar__item {
|
||||
@@ -336,7 +353,6 @@ html[data-theme="dark"] .table-of-contents__link {
|
||||
|
||||
/* codeBlock */
|
||||
div[class^="codeBlockContainer"] {
|
||||
border-radius: var(--ifm-code-border-radius);
|
||||
margin-bottom: 2.5rem;
|
||||
|
||||
div[class^="codeBlockTitle"] {
|
||||
@@ -466,6 +482,7 @@ button[class^="copyButton"] {
|
||||
&--active:not(.menu__link--sublist) {
|
||||
background-color: var(--ifm-color-primary);
|
||||
color: var(--ifm-color-primary-light);
|
||||
font-weight: bold;
|
||||
|
||||
html[data-theme="dark"] & {
|
||||
background-color: var(--ifm-menu-color-background-hover);
|
||||
@@ -490,6 +507,8 @@ button[class^="copyButton"] {
|
||||
|
||||
&.menu__link--sublist {
|
||||
color: var(--ifm-color-primary-dark);
|
||||
padding-right: 2rem;
|
||||
margin-bottom: 0;
|
||||
|
||||
&:active,
|
||||
&:focus {
|
||||
@@ -511,6 +530,14 @@ button[class^="copyButton"] {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&--sublist {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
&--sublist::after {
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
|
||||
/* docsearch */
|
||||
|
@@ -4,54 +4,28 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
import React, { useState, useCallback, useEffect } from 'react';
|
||||
import { MDXProvider } from '@mdx-js/react';
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
import React, {useState, useCallback, useEffect} from 'react';
|
||||
import {MDXProvider} from '@mdx-js/react';
|
||||
import renderRoutes from '@docusaurus/renderRoutes';
|
||||
import Layout from '@theme/Layout';
|
||||
import DocSidebar from '@theme/DocSidebar';
|
||||
import MDXComponents from '@theme/MDXComponents';
|
||||
import NotFound from '@theme/NotFound';
|
||||
import IconArrow from '@theme/IconArrow';
|
||||
import BackToTopButton from '@theme/BackToTopButton';
|
||||
import {matchPath} from '@docusaurus/router';
|
||||
import {translate} from '@docusaurus/Translate';
|
||||
import clsx from 'clsx';
|
||||
import styles from './styles.module.css';
|
||||
import {ThemeClassNames, docVersionSearchTag} from '@docusaurus/theme-common';
|
||||
import DocPageCustom from '../../components/DocPageCustom';
|
||||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
||||
|
||||
function getSidebar({versionMetadata, currentDocRoute}) {
|
||||
function addTrailingSlash(str) {
|
||||
return str.endsWith('/') ? str : `${str}/`;
|
||||
}
|
||||
|
||||
function removeTrailingSlash(str) {
|
||||
return str.endsWith('/') ? str.slice(0, -1) : str;
|
||||
}
|
||||
|
||||
const {permalinkToSidebar, docsSidebars} = versionMetadata; // With/without trailingSlash, we should always be able to get the appropriate sidebar
|
||||
// note: docs plugin permalinks currently never have trailing slashes
|
||||
// trailingSlash is handled globally at the framework level, not plugin level
|
||||
|
||||
const sidebarName =
|
||||
permalinkToSidebar[currentDocRoute.path] ||
|
||||
permalinkToSidebar[addTrailingSlash(currentDocRoute.path)] ||
|
||||
permalinkToSidebar[removeTrailingSlash(currentDocRoute.path)];
|
||||
const sidebar = docsSidebars[sidebarName];
|
||||
return {
|
||||
sidebar,
|
||||
sidebarName,
|
||||
};
|
||||
}
|
||||
import DocPageCustom from "../../components/DocPageCustom"
|
||||
|
||||
function DocPageContent({currentDocRoute, versionMetadata, children}) {
|
||||
const {siteConfig, isClient} = useDocusaurusContext();
|
||||
const {pluginId, version} = versionMetadata;
|
||||
const {sidebarName, sidebar} = getSidebar({
|
||||
versionMetadata,
|
||||
currentDocRoute,
|
||||
});
|
||||
const sidebarName = currentDocRoute.sidebar;
|
||||
const sidebar = sidebarName
|
||||
? versionMetadata.docsSidebars[sidebarName]
|
||||
: undefined;
|
||||
const [hiddenSidebarContainer, setHiddenSidebarContainer] = useState(false);
|
||||
const [hiddenSidebar, setHiddenSidebar] = useState(false);
|
||||
const toggleSidebar = useCallback(() => {
|
||||
@@ -63,14 +37,15 @@ function DocPageContent({currentDocRoute, versionMetadata, children}) {
|
||||
}, [hiddenSidebar]);
|
||||
return (
|
||||
<Layout
|
||||
key={isClient}
|
||||
wrapperClassName={ThemeClassNames.wrapper.docPages}
|
||||
pageClassName={ThemeClassNames.page.docPage}
|
||||
pageClassName={ThemeClassNames.page.docsDocPage}
|
||||
searchMetadatas={{
|
||||
version,
|
||||
tag: docVersionSearchTag(pluginId, version),
|
||||
}}>
|
||||
<div className={styles.docPage}>
|
||||
<BackToTopButton />
|
||||
|
||||
{sidebar && (
|
||||
<aside
|
||||
className={clsx(styles.docSidebarContainer, {
|
||||
@@ -95,9 +70,6 @@ function DocPageContent({currentDocRoute, versionMetadata, children}) {
|
||||
}
|
||||
sidebar={sidebar}
|
||||
path={currentDocRoute.path}
|
||||
sidebarCollapsible={
|
||||
siteConfig.themeConfig?.sidebarCollapsible ?? true
|
||||
}
|
||||
onCollapse={toggleSidebar}
|
||||
isHidden={hiddenSidebar}
|
||||
/>
|
||||
@@ -156,7 +128,6 @@ function DocPage(props) {
|
||||
const currentDocRoute = docRoutes.find((docRoute) =>
|
||||
matchPath(location.pathname, docRoute),
|
||||
);
|
||||
const userAgent = ExecutionEnvironment.canUseDOM ? navigator.userAgent : null;
|
||||
|
||||
// DocPage Swizzle
|
||||
const [userAccessStatus, setUserAccessStatus] = useState(
|
||||
@@ -181,7 +152,7 @@ function DocPage(props) {
|
||||
})
|
||||
}, [location.pathname, userAccessStatus])
|
||||
|
||||
if (process.env.OAUTH_ENABLE == 'true' && userAccessStatus?.permission !== true && userAgent !== 'Algolia DocSearch Crawler') {
|
||||
if (process.env.OAUTH_ENABLE == 'true' && userAccessStatus?.permission !== true) {
|
||||
return <DocPageCustom location={location} userAccessStatus={userAccessStatus} setUserAccessStatus={setUserAccessStatus} />
|
||||
}
|
||||
// End DocPageSwizzle
|
||||
|
@@ -20,6 +20,10 @@
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.docSidebarContainer {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (min-width: 997px) {
|
||||
.docMainContainer {
|
||||
flex-grow: 1;
|
||||
@@ -31,6 +35,7 @@
|
||||
}
|
||||
|
||||
.docSidebarContainer {
|
||||
display: block;
|
||||
width: var(--doc-sidebar-width);
|
||||
margin-top: calc(-1 * var(--ifm-navbar-height));
|
||||
border-right: 1px solid var(--ifm-toc-border-color);
|
||||
@@ -78,9 +83,3 @@
|
||||
) !important;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 996px) {
|
||||
.docSidebarContainer {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
@@ -6,19 +6,30 @@
|
||||
*/
|
||||
import React, {useCallback, useState, useEffect} from 'react';
|
||||
import clsx from 'clsx';
|
||||
import Translate from '@docusaurus/Translate';
|
||||
import SearchBar from '@theme/SearchBar';
|
||||
import Toggle from '@theme/Toggle';
|
||||
import useThemeContext from '@theme/hooks/useThemeContext';
|
||||
import {useThemeConfig} from '@docusaurus/theme-common';
|
||||
import {
|
||||
useThemeConfig,
|
||||
useMobileSecondaryMenuRenderer,
|
||||
usePrevious,
|
||||
} from '@docusaurus/theme-common';
|
||||
import useHideableNavbar from '@theme/hooks/useHideableNavbar';
|
||||
import useLockBodyScroll from '@theme/hooks/useLockBodyScroll';
|
||||
import useWindowSize, {windowSizes} from '@theme/hooks/useWindowSize';
|
||||
import useWindowSize from '@theme/hooks/useWindowSize';
|
||||
import {useActivePlugin} from '@theme/hooks/useDocs';
|
||||
import NavbarItem from '@theme/NavbarItem';
|
||||
import Logo from '@theme/Logo';
|
||||
import IconMenu from '@theme/IconMenu';
|
||||
import styles from './styles.module.css'; // retrocompatible with v1
|
||||
|
||||
const DefaultNavItemPosition = 'right'; // If split links by left/right
|
||||
const DefaultNavItemPosition = 'right';
|
||||
|
||||
function useNavbarItems() {
|
||||
// TODO temporary casting until ThemeConfig type is improved
|
||||
return useThemeConfig().navbar.items;
|
||||
} // If split links by left/right
|
||||
// if position is unspecified, fallback to right (as v1)
|
||||
|
||||
function splitNavItemsByPosition(items) {
|
||||
@@ -34,54 +45,173 @@ function splitNavItemsByPosition(items) {
|
||||
};
|
||||
}
|
||||
|
||||
function Navbar() {
|
||||
function useMobileSidebar() {
|
||||
const windowSize = useWindowSize(); // Mobile sidebar not visible on hydration: can avoid SSR rendering
|
||||
|
||||
const shouldRender = windowSize === 'mobile'; // || windowSize === 'ssr';
|
||||
|
||||
const [shown, setShown] = useState(false);
|
||||
const toggle = useCallback(() => {
|
||||
setShown((s) => !s);
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (windowSize === 'desktop') {
|
||||
setShown(false);
|
||||
}
|
||||
}, [windowSize]);
|
||||
return {
|
||||
shouldRender,
|
||||
toggle,
|
||||
shown,
|
||||
};
|
||||
}
|
||||
|
||||
function useColorModeToggle() {
|
||||
const {
|
||||
navbar: {items, hideOnScroll, style},
|
||||
colorMode: {disableSwitch: disableColorModeSwitch},
|
||||
colorMode: {disableSwitch},
|
||||
} = useThemeConfig();
|
||||
const [sidebarShown, setSidebarShown] = useState(false);
|
||||
const {isDarkTheme, setLightTheme, setDarkTheme} = useThemeContext();
|
||||
const {navbarRef, isNavbarVisible} = useHideableNavbar(hideOnScroll);
|
||||
useLockBodyScroll(sidebarShown);
|
||||
const showSidebar = useCallback(() => {
|
||||
setSidebarShown(true);
|
||||
}, [setSidebarShown]);
|
||||
const hideSidebar = useCallback(() => {
|
||||
setSidebarShown(false);
|
||||
}, [setSidebarShown]);
|
||||
const onToggleChange = useCallback(
|
||||
const toggle = useCallback(
|
||||
(e) => (e.target.checked ? setDarkTheme() : setLightTheme()),
|
||||
[setLightTheme, setDarkTheme],
|
||||
);
|
||||
const windowSize = useWindowSize();
|
||||
return {
|
||||
isDarkTheme,
|
||||
toggle,
|
||||
disabled: disableSwitch,
|
||||
};
|
||||
}
|
||||
|
||||
function useSecondaryMenu({sidebarShown, toggleSidebar}) {
|
||||
const content = useMobileSecondaryMenuRenderer()?.({
|
||||
toggleSidebar,
|
||||
});
|
||||
const previousContent = usePrevious(content);
|
||||
const [shown, setShown] = useState(() => {
|
||||
// /!\ content is set with useEffect,
|
||||
// so it's not available on mount anyway
|
||||
// "return !!content" => always returns false
|
||||
return false;
|
||||
}); // When content is become available for the first time (set in useEffect)
|
||||
// we set this content to be shown!
|
||||
|
||||
useEffect(() => {
|
||||
if (windowSize === windowSizes.desktop) {
|
||||
setSidebarShown(false);
|
||||
const contentBecameAvailable = content && !previousContent;
|
||||
|
||||
if (contentBecameAvailable) {
|
||||
setShown(true);
|
||||
}
|
||||
}, [windowSize]);
|
||||
}, [content, previousContent]);
|
||||
const hasContent = !!content; // On sidebar close, secondary menu is set to be shown on next re-opening
|
||||
// (if any secondary menu content available)
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasContent) {
|
||||
setShown(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sidebarShown) {
|
||||
setShown(true);
|
||||
}
|
||||
}, [sidebarShown, hasContent]);
|
||||
const hide = useCallback(() => {
|
||||
setShown(false);
|
||||
}, []);
|
||||
return {
|
||||
shown,
|
||||
hide,
|
||||
content,
|
||||
};
|
||||
}
|
||||
|
||||
function NavbarMobileSidebar({sidebarShown, toggleSidebar}) {
|
||||
useLockBodyScroll(sidebarShown);
|
||||
const items = useNavbarItems();
|
||||
const colorModeToggle = useColorModeToggle();
|
||||
const secondaryMenu = useSecondaryMenu({
|
||||
sidebarShown,
|
||||
toggleSidebar,
|
||||
});
|
||||
return (
|
||||
<div className="navbar-sidebar">
|
||||
<div className="navbar-sidebar__brand">
|
||||
<Logo
|
||||
className="navbar__brand"
|
||||
imageClassName="navbar__logo"
|
||||
titleClassName="navbar__title"
|
||||
/>
|
||||
{!colorModeToggle.disabled && sidebarShown && (
|
||||
<Toggle
|
||||
checked={colorModeToggle.isDarkTheme}
|
||||
onChange={colorModeToggle.toggle}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={clsx('navbar-sidebar__items', {
|
||||
'navbar-sidebar__items--show-secondary': secondaryMenu.shown,
|
||||
})}>
|
||||
<div className="navbar-sidebar__item menu">
|
||||
<ul className="menu__list">
|
||||
{items.map((item, i) => (
|
||||
<NavbarItem mobile {...item} onClick={toggleSidebar} key={i} />
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div className="navbar-sidebar__item menu">
|
||||
{items.length > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
className="clean-btn navbar-sidebar__back"
|
||||
onClick={secondaryMenu.hide}>
|
||||
<Translate
|
||||
id="theme.navbar.mobileSidebarSecondaryMenu.backButtonLabel"
|
||||
description="The label of the back button to return to main menu, inside the mobile navbar sidebar secondary menu (notably used to display the docs sidebar)">
|
||||
← Back to main menu
|
||||
</Translate>
|
||||
</button>
|
||||
)}
|
||||
{secondaryMenu.content}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Navbar() {
|
||||
const {
|
||||
navbar: {hideOnScroll, style},
|
||||
} = useThemeConfig();
|
||||
const mobileSidebar = useMobileSidebar();
|
||||
const colorModeToggle = useColorModeToggle();
|
||||
const activeDocPlugin = useActivePlugin();
|
||||
const {navbarRef, isNavbarVisible} = useHideableNavbar(hideOnScroll);
|
||||
const items = useNavbarItems();
|
||||
const hasSearchNavbarItem = items.some((item) => item.type === 'search');
|
||||
const {leftItems, rightItems} = splitNavItemsByPosition(items);
|
||||
const algoliaSearch = rightItems.shift()
|
||||
return (
|
||||
<nav
|
||||
ref={navbarRef}
|
||||
className={clsx('navbar', 'navbar--fixed-top', {
|
||||
'navbar--dark': style === 'dark',
|
||||
'navbar--primary': style === 'primary',
|
||||
'navbar-sidebar--show': sidebarShown,
|
||||
'navbar-sidebar--show': mobileSidebar.shown,
|
||||
[styles.navbarHideable]: hideOnScroll,
|
||||
[styles.navbarHidden]: hideOnScroll && !isNavbarVisible,
|
||||
})}>
|
||||
<div className="navbar__inner">
|
||||
<div className="navbar__items">
|
||||
{items != null && items.length !== 0 && (
|
||||
{(items?.length > 0 || activeDocPlugin) && (
|
||||
<button
|
||||
aria-label="Navigation bar toggle"
|
||||
className="navbar__toggle clean-btn"
|
||||
type="button"
|
||||
tabIndex={0}
|
||||
onClick={showSidebar}
|
||||
onKeyDown={showSidebar}>
|
||||
onClick={mobileSidebar.toggle}
|
||||
onKeyDown={mobileSidebar.toggle}>
|
||||
<IconMenu />
|
||||
</button>
|
||||
)}
|
||||
@@ -95,52 +225,40 @@ function Navbar() {
|
||||
))}
|
||||
</div>
|
||||
<div className="navbar__items navbar__items--right">
|
||||
<NavbarItem {...algoliaSearch} key={999} />
|
||||
{!disableColorModeSwitch && (
|
||||
<Toggle
|
||||
className={styles.displayOnlyInLargeViewport}
|
||||
checked={isDarkTheme}
|
||||
onChange={onToggleChange}
|
||||
/>
|
||||
)}
|
||||
{rightItems.map((item, i) => (
|
||||
<NavbarItem {...item} key={i} />
|
||||
))}
|
||||
{!hasSearchNavbarItem && <SearchBar />}
|
||||
{rightItems.map((item, i) => {
|
||||
if(item.type === "search") {
|
||||
return (
|
||||
<React.Fragment key={i}>
|
||||
<NavbarItem {...item} />
|
||||
{!colorModeToggle.disabled && (
|
||||
<Toggle
|
||||
className={styles.toggle}
|
||||
checked={colorModeToggle.isDarkTheme}
|
||||
onChange={colorModeToggle.toggle}
|
||||
/>
|
||||
)}
|
||||
</React.Fragment>
|
||||
)
|
||||
} else {
|
||||
return <NavbarItem {...item} key={i} />
|
||||
}
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
role="presentation"
|
||||
className="navbar-sidebar__backdrop"
|
||||
onClick={hideSidebar}
|
||||
onClick={mobileSidebar.toggle}
|
||||
/>
|
||||
<div className="navbar-sidebar">
|
||||
<div className="navbar-sidebar__brand">
|
||||
<Logo
|
||||
className="navbar__brand"
|
||||
imageClassName="navbar__logo"
|
||||
titleClassName="navbar__title"
|
||||
onClick={hideSidebar}
|
||||
/>
|
||||
{!disableColorModeSwitch && sidebarShown && (
|
||||
<Toggle checked={isDarkTheme} onChange={onToggleChange} />
|
||||
)}
|
||||
</div>
|
||||
<div className="navbar-sidebar__items">
|
||||
<div className="menu">
|
||||
<ul className="menu__list">
|
||||
{items.map((item, i) => (
|
||||
<NavbarItem
|
||||
mobile
|
||||
{...item} // TODO fix typing
|
||||
onClick={hideSidebar}
|
||||
key={i}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{mobileSidebar.shouldRender && (
|
||||
<NavbarMobileSidebar
|
||||
sidebarShown={mobileSidebar.shown}
|
||||
toggleSidebar={mobileSidebar.toggle}
|
||||
/>
|
||||
)}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
@@ -5,9 +5,12 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/*
|
||||
Hide toggle in small viewports
|
||||
*/
|
||||
@media screen and (max-width: 997px) {
|
||||
.displayOnlyInLargeViewport {
|
||||
display: none !important;
|
||||
.toggle {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -4,64 +4,49 @@
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
import React, { useState, useRef, memo } from 'react';
|
||||
import { useThemeConfig } from '@docusaurus/theme-common';
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
import React, {useState, useRef, memo} from 'react';
|
||||
import {useThemeConfig} from '@docusaurus/theme-common';
|
||||
import useIsBrowser from '@docusaurus/useIsBrowser';
|
||||
import clsx from 'clsx';
|
||||
import './styles.css';
|
||||
import styles from './styles.module.css';
|
||||
import DarkIcon from "./icon_night.svg"
|
||||
import LightIcon from "./icon_day.svg"
|
||||
|
||||
const Dark = ({ icon, style }) => (
|
||||
const Dark = ({icon, style}) => (
|
||||
<span className={clsx(styles.toggle, styles.dark)} style={style}>
|
||||
<DarkIcon />
|
||||
</span>
|
||||
);
|
||||
|
||||
const Light = ({ icon, style }) => (
|
||||
const Light = ({icon, style}) => (
|
||||
<span className={clsx(styles.toggle, styles.light)} style={style}>
|
||||
<LightIcon />
|
||||
</span>
|
||||
); // Based on react-toggle (https://github.com/aaronshaf/react-toggle/).
|
||||
|
||||
const Toggle = memo(
|
||||
({ className, icons, checked: defaultChecked, disabled, onChange }) => {
|
||||
({className, icons, checked: defaultChecked, disabled, onChange}) => {
|
||||
const [checked, setChecked] = useState(defaultChecked);
|
||||
const [focused, setFocused] = useState(false);
|
||||
const inputRef = useRef(null);
|
||||
|
||||
const handleToggle = (e) => {
|
||||
const checkbox = inputRef.current;
|
||||
|
||||
if (!checkbox) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.target !== checkbox) {
|
||||
e.preventDefault();
|
||||
checkbox.focus();
|
||||
checkbox.click();
|
||||
return;
|
||||
}
|
||||
|
||||
setChecked(checkbox?.checked);
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={clsx('react-toggle', className, {
|
||||
'react-toggle--checked': checked,
|
||||
'react-toggle--focus': focused,
|
||||
'react-toggle--disabled': disabled,
|
||||
})}
|
||||
role="button"
|
||||
tabIndex={-1}
|
||||
onClick={handleToggle}>
|
||||
<div className="react-toggle-track">
|
||||
})}>
|
||||
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */}
|
||||
<div
|
||||
className="react-toggle-track"
|
||||
role="button"
|
||||
tabIndex={-1}
|
||||
onClick={() => inputRef.current?.click()}>
|
||||
<div className="react-toggle-track-check">{icons.checked}</div>
|
||||
<div className="react-toggle-track-x">{icons.unchecked}</div>
|
||||
<div className="react-toggle-thumb" />
|
||||
</div>
|
||||
<div className="react-toggle-thumb" />
|
||||
|
||||
<input
|
||||
ref={inputRef}
|
||||
@@ -70,8 +55,14 @@ const Toggle = memo(
|
||||
className="react-toggle-screenreader-only"
|
||||
aria-label="Switch between dark and light mode"
|
||||
onChange={onChange}
|
||||
onClick={() => setChecked(!checked)}
|
||||
onFocus={() => setFocused(true)}
|
||||
onBlur={() => setFocused(false)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
inputRef.current?.click();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
@@ -80,13 +71,13 @@ const Toggle = memo(
|
||||
export default function (props) {
|
||||
const {
|
||||
colorMode: {
|
||||
switchConfig: { darkIcon, darkIconStyle, lightIcon, lightIconStyle },
|
||||
switchConfig: {darkIcon, darkIconStyle, lightIcon, lightIconStyle},
|
||||
},
|
||||
} = useThemeConfig();
|
||||
const { isClient } = useDocusaurusContext();
|
||||
const isBrowser = useIsBrowser();
|
||||
return (
|
||||
<Toggle
|
||||
disabled={!isClient}
|
||||
disabled={!isBrowser}
|
||||
icons={{
|
||||
checked: <Dark icon={darkIcon} style={darkIconStyle} />,
|
||||
unchecked: <Light icon={lightIcon} style={lightIconStyle} />,
|
||||
|
100
website/src/theme/Toggle/styles.css
Normal file
100
website/src/theme/Toggle/styles.css
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Styles for React Toggle
|
||||
* copied over because we want to allow user to swizzle it and modify the css
|
||||
* and also to make sure its compatible with our dark mode
|
||||
* https://github.com/aaronshaf/react-toggle/blob/master/style.css
|
||||
*/
|
||||
.react-toggle {
|
||||
touch-action: pan-x;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
.react-toggle-screenreader-only {
|
||||
border: 0;
|
||||
clip: rect(0 0 0 0);
|
||||
height: 1px;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
}
|
||||
|
||||
.react-toggle--disabled {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.react-toggle-track {
|
||||
width: 55px;
|
||||
height: 24px;
|
||||
border-radius: 30px;
|
||||
background-color: #40b8bb;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.react-toggle-track-check {
|
||||
position: absolute;
|
||||
width: 21px;
|
||||
height: 16px;
|
||||
top: 0px;
|
||||
bottom: 0px;
|
||||
margin: auto 0;
|
||||
left: 6px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.25s ease;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .react-toggle .react-toggle-track-check,
|
||||
.react-toggle--checked .react-toggle-track-check {
|
||||
opacity: 1;
|
||||
transition: opacity 0.25s ease;
|
||||
}
|
||||
|
||||
.react-toggle-track-x {
|
||||
position: absolute;
|
||||
width: 21px;
|
||||
height: 16px;
|
||||
top: 0px;
|
||||
bottom: 0px;
|
||||
margin: auto 0;
|
||||
right: 6px;
|
||||
opacity: 1;
|
||||
transition: opacity 0.25s ease;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .react-toggle .react-toggle-track-x,
|
||||
.react-toggle--checked .react-toggle-track-x {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.react-toggle-thumb {
|
||||
position: absolute;
|
||||
top: -1px;
|
||||
left: 0;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
border: 3px solid var(--ifm-color-primary-dark);
|
||||
border-radius: 50%;
|
||||
background-color: #fafafa;
|
||||
transition: all 0.25s ease;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .react-toggle .react-toggle-thumb,
|
||||
.react-toggle--checked .react-toggle-thumb {
|
||||
left: 31px;
|
||||
}
|
||||
|
||||
.icon_day_svg__mode,
|
||||
.icon_night_svg__mode {
|
||||
height: 26px;
|
||||
width: 26px;
|
||||
}
|
@@ -15,97 +15,3 @@
|
||||
.toggle::before {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
/**
|
||||
* styles for React Toggle
|
||||
* copied over because we want to allow user to swizzle it and modify the css
|
||||
* and also to make sure its compatible with our dark mode
|
||||
* https://github.com/aaronshaf/react-toggle/blob/master/style.css
|
||||
*/
|
||||
:global(.react-toggle) {
|
||||
touch-action: pan-x;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
:global(.react-toggle-screenreader-only) {
|
||||
border: 0;
|
||||
clip: rect(0 0 0 0);
|
||||
height: 1px;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
}
|
||||
|
||||
:global(.react-toggle--disabled) {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
:global(.react-toggle-track) {
|
||||
width: 55px;
|
||||
height: 24px;
|
||||
border-radius: 30px;
|
||||
background-color: #40b8bb;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
:global(.react-toggle-track-check) {
|
||||
position: absolute;
|
||||
width: 21px;
|
||||
height: 16px;
|
||||
top: 0px;
|
||||
bottom: 0px;
|
||||
margin: auto 0;
|
||||
left: 6px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.25s ease;
|
||||
}
|
||||
|
||||
:global([data-theme="dark"] .react-toggle .react-toggle-track-check),
|
||||
:global(.react-toggle--checked .react-toggle-track-check) {
|
||||
opacity: 1;
|
||||
transition: opacity 0.25s ease;
|
||||
}
|
||||
|
||||
:global(.react-toggle-track-x) {
|
||||
position: absolute;
|
||||
width: 21px;
|
||||
height: 16px;
|
||||
top: 0px;
|
||||
bottom: 0px;
|
||||
margin: auto 0;
|
||||
right: 6px;
|
||||
opacity: 1;
|
||||
transition: opacity 0.25s ease;
|
||||
}
|
||||
|
||||
:global([data-theme="dark"] .react-toggle .react-toggle-track-x),
|
||||
:global(.react-toggle--checked .react-toggle-track-x) {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
:global(.react-toggle-thumb) {
|
||||
position: absolute;
|
||||
top: -1px;
|
||||
left: 0;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
border: 3px solid var(--ifm-color-primary-dark);
|
||||
border-radius: 50%;
|
||||
background-color: #fafafa;
|
||||
transition: all 0.25s ease;
|
||||
}
|
||||
|
||||
:global([data-theme="dark"] .react-toggle .react-toggle-thumb),
|
||||
:global(.react-toggle--checked .react-toggle-thumb) {
|
||||
left: 31px;
|
||||
}
|
||||
|
||||
:global(.icon_day_svg__mode),
|
||||
:global(.icon_night_svg__mode) {
|
||||
height: 26px;
|
||||
width: 26px;
|
||||
}
|
||||
|
Reference in New Issue
Block a user