@nex-ui/react
Version:
🎉 A beautiful, modern, and reliable React component library.
92 lines (89 loc) • 2.63 kB
TypeScript
import { ElementType, ReactNode } from 'react';
import { ClassValue } from 'clsx';
import { Interpolation } from '@nex-ui/system';
import { OverrideProps, ComponentSlotClasses, ComponentPropsWithCommonProps } from '../../types/utils.js';
import { SwitchVariants } from '../../theme/recipes/switch.js';
interface SwitchPropsOverrides {
}
type SwitchSlotProps = {
root?: ComponentPropsWithCommonProps<'label'>;
track?: ComponentPropsWithCommonProps<'span'>;
startIcon?: ComponentPropsWithCommonProps<'span'>;
endIcon?: ComponentPropsWithCommonProps<'span'>;
thumb?: ComponentPropsWithCommonProps<'span'>;
label?: ComponentPropsWithCommonProps<'span'>;
};
type SwitchOwnProps<SwitchComponent extends ElementType> = {
/**
* The component or element to render as the input.
*
* @default 'input'
*/
as?: SwitchComponent;
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: Interpolation;
/**
* The label of the Switch.
*/
children?: ReactNode;
/**
* Additional class names to apply to the root.
*/
className?: ClassValue;
/**
* The element placed before the children.
*/
startIcon?: ReactNode;
/**
* The element placed after the children.
*/
endIcon?: ReactNode;
/**
* The props used for each slot.
*/
slotProps?: SwitchSlotProps;
/**
* The className used for each slot.
*/
classNames?: ComponentSlotClasses<keyof SwitchSlotProps>;
/**
* The icon to display when the Switch is checked.
*/
thumbIcon?: ReactNode | ((ownerState: SwitchProps<SwitchComponent>) => ReactNode);
/**
* Handler that is called when the element's checked state changes.
*/
onCheckedChange?: (checked: boolean) => void;
/**
* If true, the Switch is checked.(controlled)
*/
checked?: boolean;
/**
* If true, the Switch is disabled.
*
* @default false
*/
disabled?: boolean;
/**
* The size of the Switch.
*
* @default 'md'
*/
size?: SwitchVariants['size'];
/**
* The color of the Switch.
*
* @default primaryThemeColor
*/
color?: SwitchVariants['color'];
/**
* The default checked state. (uncontrolled)
*
* @default false
*/
defaultChecked?: boolean;
};
type SwitchProps<SwitchComponent extends ElementType = 'input'> = OverrideProps<SwitchComponent, SwitchOwnProps<SwitchComponent>, SwitchPropsOverrides>;
export type { SwitchOwnProps, SwitchProps, SwitchPropsOverrides };