UNPKG

@ark-ui/react

Version:

A collection of unstyled, accessible UI components for React, utilizing state machines for seamless interaction.

34 lines (31 loc) 1.03 kB
'use client'; import { jsx } from 'react/jsx-runtime'; import { mergeProps } from '@zag-js/react'; import { forwardRef } from 'react'; import { createSplitProps } from '../../utils/create-split-props.js'; import { ark } from '../factory.js'; import { useSwitch } from './use-switch.js'; import { SwitchProvider } from './use-switch-context.js'; const splitRootProps = createSplitProps(); const SwitchRoot = forwardRef((props, ref) => { const [useSwitchProps, localProps] = splitRootProps(props, [ "checked", "defaultChecked", "disabled", "form", "id", "ids", "invalid", "label", "name", "onCheckedChange", "readOnly", "required", "value" ]); const switchContext = useSwitch(useSwitchProps); const mergedProps = mergeProps(switchContext.getRootProps(), localProps); return /* @__PURE__ */ jsx(SwitchProvider, { value: switchContext, children: /* @__PURE__ */ jsx(ark.label, { ...mergedProps, ref }) }); }); SwitchRoot.displayName = "SwitchRoot"; export { SwitchRoot };