From 29994ae4cdfea7ca2842a542e7e4579263b0651e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Mon, 7 Oct 2024 11:05:10 +0200 Subject: [PATCH 1/4] v1.0.0-alpha.3 (#709) --- CHANGELOG.md | 78 ++++++++++++++++++++++++++++++++++ package.json | 2 +- packages/mui-base/package.json | 2 +- 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb7912268f..3fd8ded130 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,83 @@ # Versions +## v1.0.0-alpha.3 + +_Oct 7, 2024_ + +A big thanks to the 7 contributors who made this release possible. Here are some highlights ✨: + +- ⭐ We added several new components: CheckboxGroup, RadioGroup, Form, Separator +- ⭐ Menu has new parts: CheckboxItem, RadioItem, and Group + +### `@base_ui/react@1.0.0-alpha.3` + +- [AlertDialog] Move types to namespaces (#591) @michaldudak +- [Checkbox] Modernize implementation (#594) @atomiks +- [CheckboxGroup] Implement components and hooks (#458) @atomiks +- [Collapsible] Add Collapsible components and hooks (#481) @mj12albert +- [Dialog] Move types to namespaces (#697) @michaldudak +- [Dialog][Collapsible] Fix style prop merging (#641) @michaldudak +- [Form] Create new `Form` component (#589) @atomiks +- [Menu] CheckboxItem component (#533) @michaldudak +- [Menu] Do not select an item when space is pressed during typeahead (#542) @michaldudak +- [Menu] Fix custom anchor positioning (#609) @michaldudak +- [Menu] Group and Separator components (#535) @michaldudak +- [Menu] Increase test timeout (#592) @michaldudak +- [Menu] RadioItem component (#534) @michaldudak +- [Menu] Remove the unused prop (#647) @michaldudak +- [Menu] Remove wrong default value from docs (#549) @sai6855 +- [Menu][Popover][PreviewCard][Tooltip] Add default value as `clippingAncestors` to collisionBoundary prop (#580) @sai6855 +- [NumberField] Modernize implementation (#590) @atomiks +- [Popover] Modernize implementation (#607) @atomiks +- [PreviewCard] Modernize implementation (#626) @atomiks +- [RadioGroup] Create new `RadioGroup` component (#487) @atomiks +- [Slider] Fix Home / End regression (#526) @sai6855 +- [Tooltip] Modernize implementation (#606) @atomiks +- [useButton] Modernize implementation (#643) @michaldudak +- [useScrollLock] Avoid scrollbar layout shift issues (#604) @atomiks + +### Docs + +- [docs] Fix 301 redirections in docs @oliviertassinari +- [docs] Make the readme specific to @base_ui/react (#633) @michaldudak +- [docs] Copy vale-action.yml from main repo @oliviertassinari +- [docs] Fix 301 to chromium (#636) @oliviertassinari +- [docs] Avoid dead links in demos (#610) @oliviertassinari +- [docs] Fix rel attribute on edit GitHub links (#614) @oliviertassinari +- [docs] Fix pnpm docs:link-check script (#552) @oliviertassinari +- [docs] Fix Stack Overflow issue canned response @oliviertassinari +- [docs] Fix outdated link to support page @oliviertassinari +- [docs] Clarify contribution guide references @oliviertassinari + +### Core + +- [code-infra] Remove custom playwright installation steps (#646) @Janpot +- [core] Fix 301 link to Next.js and git diff @oliviertassinari +- [core] Fix package.json repository rule @oliviertassinari +- [core] MUI X repository moved to a new location @oliviertassinari +- [core] React 19 compatibility (#605) @michaldudak +- [core] Reference `ownerDocument` (#660) @atomiks +- [core] Remove 'use client' from index files (#331) @michaldudak +- [core] Remove /.yarn (#596) @oliviertassinari +- [core] Remove Material UI dependency (#585) @michaldudak +- [core] Remove the legacy components from the repo (#584) @michaldudak +- [core] Rename positionStrategy to positionMethod (#704) @michaldudak +- [docs-infra] Fix double // (#613) @oliviertassinari +- [docs-infra] Strengthen CSP (#595) @oliviertassinari +- [infra] Adds reusable workflow for closing message on issues (#598) @michelengelen +- [infra] Adds reusable workflow for issue cleanup (#597) @michelengelen +- [infra] Fix line break in Stack Overflow message @oliviertassinari +- [test] Fix tests on Safari (#546) @michaldudak +- [test] Fix the test_types_next CI job (#703) @michaldudak +- [test] Improve visual screenshot canva (#708) +- [test] Point Istanbul to correct URL (#657) @sai6855 +- [test] Run Browserstack tests on master only (#578) @michaldudak +- [test] Use `waitFor` instead of fixed timeout in tests (#632) @michaldudak +- [website] Improve utm_source strategy @oliviertassinari +- [website] Modernize the Base UI website (#538) @michaldudak + +All contributors of this release in alphabetical order: @atomiks, @Janpot, @michaldudak, @michelengelen, @mj12albert, @oliviertassinari, @sai6855 + ## v1.0.0-alpha.2 _Aug 19, 2024_ diff --git a/package.json b/package.json index 7fdca89621..d25331dc22 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@base_ui/monorepo", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "private": true, "scripts": { "preinstall": "npx only-allow pnpm", diff --git a/packages/mui-base/package.json b/packages/mui-base/package.json index e922305204..e936c416a3 100644 --- a/packages/mui-base/package.json +++ b/packages/mui-base/package.json @@ -1,6 +1,6 @@ { "name": "@base_ui/react", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "private": false, "author": "MUI Team", "description": "Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.", From 2d712572504248528ed0ea352624b92c2dac74eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Mon, 7 Oct 2024 11:22:48 +0200 Subject: [PATCH 2/4] [Switch] Modernize implementation (#640) --- docs/data/api/switch-root.json | 1 - .../css-modules/index.js | 127 ++---------------- .../css-modules/index.tsx | 127 ++---------------- .../css-modules/styles.module.css | 80 +++++++++++ .../tailwind/index.tsx | 6 +- .../api-docs/switch-root/switch-root.json | 1 - .../mui-base/src/Switch/Root/SwitchContext.ts | 5 - .../mui-base/src/Switch/Root/SwitchRoot.tsx | 64 ++++----- .../src/Switch/Root/SwitchRoot.types.ts | 87 ------------ .../src/Switch/Root/SwitchRootContext.ts | 15 +++ .../mui-base/src/Switch/Root/useSwitchRoot.ts | 88 ++++++++++-- .../src/Switch/Root/useSwitchStyleHooks.ts | 14 -- .../src/Switch/Thumb/SwitchThumb.test.tsx | 8 +- .../mui-base/src/Switch/Thumb/SwitchThumb.tsx | 50 +++---- .../src/Switch/Thumb/SwitchThumb.types.ts | 4 - packages/mui-base/src/Switch/index.barrel.ts | 11 -- packages/mui-base/src/Switch/index.ts | 11 -- packages/mui-base/src/Switch/styleHooks.ts | 6 + 18 files changed, 257 insertions(+), 448 deletions(-) create mode 100644 docs/data/components/switch/UnstyledSwitchIntroduction/css-modules/styles.module.css delete mode 100644 packages/mui-base/src/Switch/Root/SwitchContext.ts delete mode 100644 packages/mui-base/src/Switch/Root/SwitchRoot.types.ts create mode 100644 packages/mui-base/src/Switch/Root/SwitchRootContext.ts delete mode 100644 packages/mui-base/src/Switch/Root/useSwitchStyleHooks.ts delete mode 100644 packages/mui-base/src/Switch/Thumb/SwitchThumb.types.ts create mode 100644 packages/mui-base/src/Switch/styleHooks.ts 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/translations/api-docs/switch-root/switch-root.json b/docs/data/translations/api-docs/switch-root/switch-root.json index 36b79335c1..401676fbbc 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 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