Switch API

API documentation for Switch component

Switch#

Props#

State#

Exposes#

Events#

Interfaces#

Types#

SwitchControl#

Props#

Defines valid properties in SwitchControl component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: SwitchControlInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: SwitchControlInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<SwitchControlPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: SwitchControlInstance) => ReactNode)
null
The children to render.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

Exposes#

Defines the methods and properties exposed by SwitchControl component.

nametypedefaultdescription
switchSwitchRootInstance
null
The Switch component instance.

Interfaces#

Defines passthrough(pt) options of SwitchControl component.

nametypedefaultdescription
rootSwitchControlPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the root's DOM element.

Types#

Instance of SwitchControl component.

values
ComponentInstance<SwitchControlProps, SwitchControlState, SwitchControlExposes>

SwitchThumb#

Props#

Defines valid properties in SwitchThumb component.

nametypedefaultdescription
refRef<unknown>
null
The reference to the component instance.
pIfboolean
true
Whether the component should be rendered.
styleCSSProperties | ((instance?: SwitchThumbInstance) => CSSProperties)
null
The style to apply to the component.
classNamestring | ((instance?: SwitchThumbInstance) => string)
null
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>
null
The component type to render.
asChildboolean
false
Whether the component should be rendered as a child component.
ptSafeRecord<SwitchThumbPassThrough>
null
The pass-through props to pass to the component
ptOptionsPassThroughOptions
null
The pass-through options to pass to the component
unstyledboolean
null
Whether the component should be rendered without classes.
dtunknown
null
The design token to use for the component.
stylesStylesOptions<ComponentInstance>
null
The styles to use for the component.
childrenReactNode | ((instance: SwitchThumbInstance) => ReactNode)
null
The children to render.
[key: string]any
null
pt-{optionName}-*-
null
Pass through attributes for customizing component. For more info, see Pass Through tab.

Exposes#

Defines the methods and properties exposed by SwitchThumb component.

nametypedefaultdescription
switchSwitchRootInstance
null
The Switch component instance.

Interfaces#

Defines passthrough(pt) options of SwitchThumb component.

nametypedefaultdescription
rootSwitchThumbPassThroughType<HTMLAttributes<HTMLDivElement>>
null
Used to pass attributes to the root's DOM element.

Types#

Instance of SwitchThumb component.

values
ComponentInstance<SwitchThumbProps, SwitchThumbState, SwitchThumbExposes>

useSwitch#

Props#

Defines valid properties in useSwitch.

nametypedefaultdescription
checkedboolean
null
When present, it specifies the input's checked state.
defaultCheckedboolean
null
The default value for the input when not controlled by `checked` and `onCheckedChange` .
onCheckedChange(event: useSwitchChangeEvent) => void
null
Callback fired when the switch's checked state changes.

State#

Defines valid state in useSwitch.

nametypedefaultdescription
checkedboolean
null
The checked state of the useSwitch.

Exposes#

Defines the methods and properties exposed by useSwitch.

nametypedefaultdescription
stateuseSwitchState
null
The state of the useSwitch.
onChange(event: useSwitchChangeEvent) => void
null
Callback fired when the useSwitch's checked state changes.

Events#

Event fired when the switch's checked state changes.

nametypedescription
originalEventEThe original event that triggered the change.
checkedbooleanThe checked state of the switch.

Types#

Instance of useSwitch headless.

values
HeadlessInstance<useSwitchProps, useSwitchState, useSwitchExposes>