Skip to content

Commit

Permalink
Extract ToggleStateProps type to use only what is needed in `useTog…
Browse files Browse the repository at this point in the history
…gleState` (adobe#3836)

* Extract `ToggleStateProps` type to use only what is needed in `useToggleState`
  • Loading branch information
Andarist authored Aug 9, 2024
1 parent 89c42a8 commit 81e3804
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/@react-stately/toggle/src/useToggleState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ToggleProps, 'children'> {}
export type {ToggleStateOptions};

export interface ToggleState {
/** Whether the toggle is selected. */
Expand Down
15 changes: 9 additions & 6 deletions packages/@react-types/checkbox/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ import {
} from '@react-types/shared';
import {ReactElement, ReactNode} from 'react';

export interface ToggleProps extends InputBase, Validation<boolean>, FocusableProps {
/**
* The label for the element.
*/
children?: ReactNode,
export interface ToggleStateOptions extends InputBase {
/**
* Whether the element should be selected (uncontrolled).
*/
Expand All @@ -46,7 +42,14 @@ export interface ToggleProps extends InputBase, Validation<boolean>, 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).
*/
Expand Down

0 comments on commit 81e3804

Please sign in to comment.