From 81e380437c63adb98b0ce73e3eaa08918d06c8bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 9 Aug 2024 05:04:24 +0200 Subject: [PATCH] Extract `ToggleStateProps` type to use only what is needed in `useToggleState` (#3836) * Extract `ToggleStateProps` type to use only what is needed in `useToggleState` --- .../@react-stately/toggle/src/useToggleState.ts | 4 ++-- packages/@react-types/checkbox/src/index.d.ts | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/@react-stately/toggle/src/useToggleState.ts b/packages/@react-stately/toggle/src/useToggleState.ts index 38fd3b71a3e..c3a6ca0a06a 100644 --- a/packages/@react-stately/toggle/src/useToggleState.ts +++ b/packages/@react-stately/toggle/src/useToggleState.ts @@ -10,10 +10,10 @@ * governing permissions and limitations under the License. */ -import {ToggleProps} from '@react-types/checkbox'; +import {ToggleStateOptions} from '@react-types/checkbox'; import {useControlledState} from '@react-stately/utils'; -export interface ToggleStateOptions extends Omit {} +export type {ToggleStateOptions}; export interface ToggleState { /** Whether the toggle is selected. */ diff --git a/packages/@react-types/checkbox/src/index.d.ts b/packages/@react-types/checkbox/src/index.d.ts index 656e867df1d..ef61aaf24cb 100644 --- a/packages/@react-types/checkbox/src/index.d.ts +++ b/packages/@react-types/checkbox/src/index.d.ts @@ -30,11 +30,7 @@ import { } from '@react-types/shared'; import {ReactElement, ReactNode} from 'react'; -export interface ToggleProps extends InputBase, Validation, FocusableProps { - /** - * The label for the element. - */ - children?: ReactNode, +export interface ToggleStateOptions extends InputBase { /** * Whether the element should be selected (uncontrolled). */ @@ -46,7 +42,14 @@ export interface ToggleProps extends InputBase, Validation, FocusablePr /** * Handler that is called when the element's selection state changes. */ - onChange?: (isSelected: boolean) => void, + onChange?: (isSelected: boolean) => void +} + +export interface ToggleProps extends ToggleStateOptions, Validation, FocusableProps { + /** + * The label for the element. + */ + children?: ReactNode, /** * The value of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefvalue). */