diff --git a/docs/data/api/switch-root.json b/docs/data/api/switch-root.json index b63432c278..ab1c15cd36 100644 --- a/docs/data/api/switch-root.json +++ b/docs/data/api/switch-root.json @@ -4,7 +4,6 @@ "className": { "type": { "name": "union", "description": "func
| string" } }, "defaultChecked": { "type": { "name": "bool" } }, "disabled": { "type": { "name": "bool" }, "default": "false" }, - "id": { "type": { "name": "string" } }, "inputRef": { "type": { "name": "custom", "description": "ref" } }, "name": { "type": { "name": "string" } }, "onCheckedChange": { diff --git a/docs/data/components/switch/UnstyledSwitchIntroduction/css-modules/index.js b/docs/data/components/switch/UnstyledSwitchIntroduction/css-modules/index.js index ca04551ec5..d48f24dbea 100644 --- a/docs/data/components/switch/UnstyledSwitchIntroduction/css-modules/index.js +++ b/docs/data/components/switch/UnstyledSwitchIntroduction/css-modules/index.js @@ -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/index.tsx b/docs/data/components/switch/UnstyledSwitchIntroduction/css-modules/index.tsx index ca04551ec5..d48f24dbea 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 0000000000..d0b25a5991 --- /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 f7443c9756..d3c6a6a13f 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/components/tabs/UnstyledTabsIntroduction/tailwind/index.tsx b/docs/data/components/tabs/UnstyledTabsIntroduction/tailwind/index.tsx index 4eb2e98f54..92957ad454 100644 --- a/docs/data/components/tabs/UnstyledTabsIntroduction/tailwind/index.tsx +++ b/docs/data/components/tabs/UnstyledTabsIntroduction/tailwind/index.tsx @@ -29,7 +29,7 @@ export default function UnstyledTabsIntroduction() { ); } -const TabsList = React.forwardRef((props, ref) => { +const TabsList = React.forwardRef((props, ref) => { const { className, ...other } = props; return ( ((props, ref) = ); }); -const Tab = React.forwardRef((props, ref) => { +const Tab = React.forwardRef((props, ref) => { const { className, ...other } = props; return ( ((props, ref) => { ); }); -const TabPanel = React.forwardRef((props, ref) => { +const TabPanel = React.forwardRef((props, ref) => { const { className, ...other } = props; return ( 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/docs/src/blocks/PackageManagerSnippet/PackageManagerSnippetRoot.tsx b/docs/src/blocks/PackageManagerSnippet/PackageManagerSnippetRoot.tsx index eae7177cd5..a9d8e6c234 100644 --- a/docs/src/blocks/PackageManagerSnippet/PackageManagerSnippetRoot.tsx +++ b/docs/src/blocks/PackageManagerSnippet/PackageManagerSnippetRoot.tsx @@ -44,7 +44,7 @@ export namespace PackageManagerSnippetRoot { export type Props = { children: React.ReactNode; options: Array<{ value: string; label: string }>; - renderTab?: Tabs.TabProps['render']; - renderTabsList?: Tabs.ListProps['render']; + renderTab?: Tabs.Tab.Props['render']; + renderTabsList?: Tabs.List.Props['render']; }; } 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 c2366b6127..0000000000 --- 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 f467e55059..0c72e0152d 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