From 5462ac2ac6b5f9741f37fd0dbe503a3940317fb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Tue, 10 Sep 2024 12:16:08 +0200 Subject: [PATCH 1/9] Move types to namespaces --- .../tailwind/index.tsx | 6 +- .../mui-base/src/Switch/Root/SwitchContext.ts | 4 - .../mui-base/src/Switch/Root/SwitchRoot.tsx | 26 ++++-- .../src/Switch/Root/SwitchRoot.types.ts | 87 ------------------- .../src/Switch/Root/SwitchRootContext.ts | 15 ++++ .../mui-base/src/Switch/Root/useSwitchRoot.ts | 77 +++++++++++++++- .../src/Switch/Root/useSwitchStyleHooks.ts | 4 +- .../src/Switch/Thumb/SwitchThumb.test.tsx | 8 +- .../mui-base/src/Switch/Thumb/SwitchThumb.tsx | 17 ++-- .../src/Switch/Thumb/SwitchThumb.types.ts | 4 - packages/mui-base/src/Switch/index.barrel.ts | 10 --- packages/mui-base/src/Switch/index.ts | 10 --- 12 files changed, 129 insertions(+), 139 deletions(-) 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/Thumb/SwitchThumb.types.ts diff --git a/docs/data/components/switch/UnstyledSwitchIntroduction/tailwind/index.tsx b/docs/data/components/switch/UnstyledSwitchIntroduction/tailwind/index.tsx index 98f1384bf2..79b4d4233d 100644 --- a/docs/data/components/switch/UnstyledSwitchIntroduction/tailwind/index.tsx +++ b/docs/data/components/switch/UnstyledSwitchIntroduction/tailwind/index.tsx @@ -31,9 +31,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 @@ -49,7 +49,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/packages/mui-base/src/Switch/Root/SwitchContext.ts b/packages/mui-base/src/Switch/Root/SwitchContext.ts deleted file mode 100644 index 666310f7c9..0000000000 --- a/packages/mui-base/src/Switch/Root/SwitchContext.ts +++ /dev/null @@ -1,4 +0,0 @@ -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..184280be33 100644 --- a/packages/mui-base/src/Switch/Root/SwitchRoot.tsx +++ b/packages/mui-base/src/Switch/Root/SwitchRoot.tsx @@ -3,13 +3,14 @@ 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 { SwitchRootContext } from './SwitchRootContext'; import { resolveClassName } from '../../utils/resolveClassName'; import { useSwitchStyleHooks } from './useSwitchStyleHooks'; import { evaluateRenderProp } from '../../utils/evaluateRenderProp'; import { useRenderPropForkRef } from '../../utils/useRenderPropForkRef'; import { useFieldRootContext } from '../../Field/Root/FieldRootContext'; +import type { BaseUIComponentProps } from '../../utils/types'; +import type { FieldRootOwnerState } from '../../Field/Root/FieldRoot.types'; function defaultRender(props: React.ComponentPropsWithRef<'button'>) { return