diff --git a/src/components/IconButton/IconButton.module.scss b/src/components/IconButton/IconButton.module.scss new file mode 100644 index 0000000..9ce3a4d --- /dev/null +++ b/src/components/IconButton/IconButton.module.scss @@ -0,0 +1,17 @@ +.root { + -webkit-tap-highlight-color: transparent; + align-items: center; + display: flex; + justify-content: center; + width: 100%; + height: 100%; + border-radius: 50%; + transition: background var(--ifm-transition-fast); + + width: 2rem; + height: 2rem; +} + +.root:hover { + background: var(--ifm-color-emphasis-200); +} diff --git a/src/components/IconButton/IconButton.tsx b/src/components/IconButton/IconButton.tsx new file mode 100644 index 0000000..ed96c23 --- /dev/null +++ b/src/components/IconButton/IconButton.tsx @@ -0,0 +1,20 @@ +import clsx from 'clsx' +import React from 'react' +import styles from './IconButton.module.scss' + +export const IconButton: React.FC< + React.DetailedHTMLProps< + React.ButtonHTMLAttributes, + HTMLButtonElement + > & {} +> = ({ children, className, ...props }) => { + return ( + + ) +} diff --git a/src/components/IconButton/index.ts b/src/components/IconButton/index.ts new file mode 100644 index 0000000..a37a7fc --- /dev/null +++ b/src/components/IconButton/index.ts @@ -0,0 +1 @@ +export * from './IconButton' diff --git a/src/theme/ColorModeToggle/index.tsx b/src/theme/ColorModeToggle/index.tsx new file mode 100644 index 0000000..7531f4d --- /dev/null +++ b/src/theme/ColorModeToggle/index.tsx @@ -0,0 +1,56 @@ +import { translate } from '@docusaurus/Translate' +import useIsBrowser from '@docusaurus/useIsBrowser' +import { IconButton } from '@site/src/components/IconButton' +import type { Props } from '@theme/ColorModeToggle' +import IconDarkMode from '@theme/Icon/DarkMode' +import IconLightMode from '@theme/Icon/LightMode' +import clsx from 'clsx' +import React from 'react' +import styles from './styles.module.css' + +function ColorModeToggle({ className, value, onChange }: Props): JSX.Element { + const isBrowser = useIsBrowser() + + const title = translate( + { + message: 'Switch between dark and light mode (currently {mode})', + id: 'theme.colorToggle.ariaLabel', + description: 'The ARIA label for the navbar color mode toggle', + }, + { + mode: + value === 'dark' + ? translate({ + message: 'dark mode', + id: 'theme.colorToggle.ariaLabel.mode.dark', + description: 'The name for the dark color mode', + }) + : translate({ + message: 'light mode', + id: 'theme.colorToggle.ariaLabel.mode.light', + description: 'The name for the light color mode', + }), + }, + ) + + return ( +
+ onChange(value === 'dark' ? 'light' : 'dark')} + > + + + +
+ ) +} + +export default React.memo(ColorModeToggle) diff --git a/src/theme/ColorModeToggle/styles.module.css b/src/theme/ColorModeToggle/styles.module.css new file mode 100644 index 0000000..d94cb13 --- /dev/null +++ b/src/theme/ColorModeToggle/styles.module.css @@ -0,0 +1,8 @@ +[data-theme='light'] .darkToggleIcon, +[data-theme='dark'] .lightToggleIcon { + display: none; +} + +.toggleButtonDisabled { + cursor: not-allowed; +}