From f7abe2352d71f68d72895dcaadbf0bef8a63080e Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Mon, 7 Oct 2024 10:06:31 +0200 Subject: [PATCH 01/22] [test] Improve visual screenshot canva (#708) --- test/regressions/TestViewer.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/regressions/TestViewer.js b/test/regressions/TestViewer.js index 24f569d14..f05b77481 100644 --- a/test/regressions/TestViewer.js +++ b/test/regressions/TestViewer.js @@ -70,11 +70,7 @@ function TestViewer(props) { {/* eslint-disable-next-line react/no-danger */} - ); -} diff --git a/docs/data/components/switch/UnstyledSwitchIntroduction/css-modules/index.tsx b/docs/data/components/switch/UnstyledSwitchIntroduction/css-modules/index.tsx index ca04551ec..d48f24dbe 100644 --- a/docs/data/components/switch/UnstyledSwitchIntroduction/css-modules/index.tsx +++ b/docs/data/components/switch/UnstyledSwitchIntroduction/css-modules/index.tsx @@ -1,148 +1,39 @@ 'use client'; import * as React from 'react'; import * as Switch from '@base_ui/react/Switch'; -import { useTheme } from '@mui/system'; +import classes from './styles.module.css'; export default function UnstyledSwitchIntroduction() { return (
- + - + - + - + -
); } - -const cyan = { - 50: '#E9F8FC', - 100: '#BDEBF4', - 200: '#99D8E5', - 300: '#66BACC', - 400: '#1F94AD', - 500: '#0D5463', - 600: '#094855', - 700: '#063C47', - 800: '#043039', - 900: '#022127', -}; - -const grey = { - 50: '#F3F6F9', - 100: '#E5EAF2', - 200: '#DAE2ED', - 300: '#C7D0DD', - 400: '#B0B8C4', - 500: '#9DA8B7', - 600: '#6B7A90', - 700: '#434D5B', - 800: '#303740', - 900: '#1C2025', -}; - -function useIsDarkMode() { - const theme = useTheme(); - return theme.palette.mode === 'dark'; -} - -function Styles() { - // Replace this with your app logic for determining dark modes - const isDarkMode = useIsDarkMode(); - - return ( - - ); -} diff --git a/docs/data/components/switch/UnstyledSwitchIntroduction/css-modules/styles.module.css b/docs/data/components/switch/UnstyledSwitchIntroduction/css-modules/styles.module.css new file mode 100644 index 000000000..d0b25a599 --- /dev/null +++ b/docs/data/components/switch/UnstyledSwitchIntroduction/css-modules/styles.module.css @@ -0,0 +1,80 @@ +.root { + width: 38px; + height: 24px; + margin: 10px; + padding: 0; + box-sizing: border-box; + background: var(--gray-50); + border: 1px solid var(--gray-200); + border-radius: 24px; + display: inline-block; + transition-property: all; + transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); + transition-duration: 120ms; + box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.05); + + :global(.dark) & { + background: var(--gray-900); + border-color: var(--gray-800); + box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.5); + } + + &[data-disabled] { + opacity: 0.4; + cursor: not-allowed; + } + + &:hover:not([data-disabled]) { + background: var(--gray-100); + border-color: var(--gray-300); + + :global(.dark) & { + background: var(--gray-800); + border-color: var(--gray-600); + } + } + + &:focus-visible { + box-shadow: 0 0 0 3px var(--cyan-200); + + :global(.dark) & { + box-shadow: 0 0 0 3px var(--cyan-700); + } + } + + &[data-state='checked'] { + border: none; + background: var(--cyan-500); + } + + &[data-state='checked']:not([data-disabled]):hover { + background: var(--cyan-700); + } +} + +.thumb { + box-sizing: border-box; + border: 1px solid var(--gray-200); + display: block; + width: 16px; + height: 16px; + left: 4px; + border-radius: 16px; + background-color: #fff; + position: relative; + transition-property: all; + transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); + transition-duration: 120ms; + box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.1); + + :global(.dark) & { + border-color: var(--gray-800); + box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.25); + } +} + +.thumb[data-state='checked'] { + left: 18px; + background-color: #fff; + box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3); +} diff --git a/docs/data/components/switch/UnstyledSwitchIntroduction/tailwind/index.tsx b/docs/data/components/switch/UnstyledSwitchIntroduction/tailwind/index.tsx index f7443c975..d3c6a6a13 100644 --- a/docs/data/components/switch/UnstyledSwitchIntroduction/tailwind/index.tsx +++ b/docs/data/components/switch/UnstyledSwitchIntroduction/tailwind/index.tsx @@ -30,9 +30,9 @@ export default function UnstyledSwitchIntroduction() { ); } -const Switch = React.forwardRef( +const Switch = React.forwardRef( function Switch({ className: classNameProp = '', ...props }, ref) { - const className = ({ checked }: BaseSwitch.OwnerState) => + const className = ({ checked }: BaseSwitch.Root.OwnerState) => `group relative inline-block w-[38px] h-[24px] m-2.5 p-0 transition rounded-full border border-solid outline-none border-slate-300 dark:border-gray-700 focus-visible:shadow-outline-switch @@ -48,7 +48,7 @@ const Thumb = React.forwardRef< HTMLSpanElement, React.HTMLAttributes >(function Thumb({ className: classNameProp = '', ...props }, ref) { - const className = ({ checked }: BaseSwitch.OwnerState) => + const className = ({ checked }: BaseSwitch.Root.OwnerState) => `block w-4 h-4 rounded-2xl border border-solid outline-none border-slate-300 dark:border-gray-700 transition shadow-[0_1px_2px_rgb(0_0_0_/_0.1)] dark:shadow-[0_1px_2px_rgb(0_0_0_/_0.25)] relative transition-all diff --git a/docs/data/translations/api-docs/switch-root/switch-root.json b/docs/data/translations/api-docs/switch-root/switch-root.json index 36b79335c..401676fbb 100644 --- a/docs/data/translations/api-docs/switch-root/switch-root.json +++ b/docs/data/translations/api-docs/switch-root/switch-root.json @@ -11,7 +11,6 @@ "disabled": { "description": "If true, the component is disabled and can't be interacted with." }, - "id": { "description": "The id of the switch element." }, "inputRef": { "description": "Ref to the underlying input element." }, "name": { "description": "Name of the underlying input element." }, "onCheckedChange": { diff --git a/packages/mui-base/src/Switch/Root/SwitchContext.ts b/packages/mui-base/src/Switch/Root/SwitchContext.ts deleted file mode 100644 index c2366b612..000000000 --- a/packages/mui-base/src/Switch/Root/SwitchContext.ts +++ /dev/null @@ -1,5 +0,0 @@ -'use client'; -import * as React from 'react'; -import { type SwitchOwnerState } from './SwitchRoot.types'; - -export const SwitchContext = React.createContext(null); diff --git a/packages/mui-base/src/Switch/Root/SwitchRoot.tsx b/packages/mui-base/src/Switch/Root/SwitchRoot.tsx index f467e5505..0c72e0152 100644 --- a/packages/mui-base/src/Switch/Root/SwitchRoot.tsx +++ b/packages/mui-base/src/Switch/Root/SwitchRoot.tsx @@ -3,17 +3,12 @@ import * as React from 'react'; import PropTypes from 'prop-types'; import refType from '@mui/utils/refType'; import { useSwitchRoot } from './useSwitchRoot'; -import { SwitchContext } from './SwitchContext'; -import type { SwitchRootProps, SwitchOwnerState } from './SwitchRoot.types'; -import { resolveClassName } from '../../utils/resolveClassName'; -import { useSwitchStyleHooks } from './useSwitchStyleHooks'; -import { evaluateRenderProp } from '../../utils/evaluateRenderProp'; -import { useRenderPropForkRef } from '../../utils/useRenderPropForkRef'; +import { SwitchRootContext } from './SwitchRootContext'; +import { styleHookMapping } from '../styleHooks'; +import { useComponentRenderer } from '../../utils/useComponentRenderer'; import { useFieldRootContext } from '../../Field/Root/FieldRootContext'; - -function defaultRender(props: React.ComponentPropsWithRef<'button'>) { - return