input.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { TextField as Kobalte } from "@kobalte/core/text-field"
  2. import { Show, splitProps } from "solid-js"
  3. import type { ComponentProps } from "solid-js"
  4. export interface InputProps
  5. extends ComponentProps<typeof Kobalte.Input>,
  6. Partial<Pick<ComponentProps<typeof Kobalte>, "value" | "onChange" | "onKeyDown">> {
  7. label?: string
  8. hideLabel?: boolean
  9. description?: string
  10. }
  11. export function Input(props: InputProps) {
  12. const [local, others] = splitProps(props, [
  13. "class",
  14. "label",
  15. "hideLabel",
  16. "description",
  17. "value",
  18. "onChange",
  19. "onKeyDown",
  20. ])
  21. return (
  22. <Kobalte data-component="input" value={local.value} onChange={local.onChange} onKeyDown={local.onKeyDown}>
  23. <Show when={local.label}>
  24. <Kobalte.Label data-slot="input-label" classList={{ "sr-only": local.hideLabel }}>
  25. {local.label}
  26. </Kobalte.Label>
  27. </Show>
  28. <Kobalte.Input {...others} data-slot="input-input" class={local.class} />
  29. <Show when={local.description}>
  30. <Kobalte.Description data-slot="input-description">{local.description}</Kobalte.Description>
  31. </Show>
  32. <Kobalte.ErrorMessage data-slot="input-error" />
  33. </Kobalte>
  34. )
  35. }