switch.tsx 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import { Switch as Kobalte } from "@kobalte/core/switch"
  2. import { Show, splitProps } from "solid-js"
  3. import type { ComponentProps, ParentProps } from "solid-js"
  4. export interface SwitchProps extends ParentProps<ComponentProps<typeof Kobalte>> {
  5. hideLabel?: boolean
  6. description?: string
  7. }
  8. export function Switch(props: SwitchProps) {
  9. const [local, others] = splitProps(props, ["children", "class", "hideLabel", "description"])
  10. return (
  11. <Kobalte {...others} data-component="switch">
  12. <Kobalte.Input data-slot="switch-input" />
  13. <Show when={local.children}>
  14. <Kobalte.Label data-slot="switch-label" classList={{ "sr-only": local.hideLabel }}>
  15. {local.children}
  16. </Kobalte.Label>
  17. </Show>
  18. <Show when={local.description}>
  19. <Kobalte.Description data-slot="switch-description">{local.description}</Kobalte.Description>
  20. </Show>
  21. <Kobalte.ErrorMessage data-slot="switch-error" />
  22. <Kobalte.Control data-slot="switch-control">
  23. <Kobalte.Thumb data-slot="switch-thumb" />
  24. </Kobalte.Control>
  25. </Kobalte>
  26. )
  27. }