{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "p-combobox-12",
  "description": "Combobox multiple form",
  "registryDependencies": [
    "@coss/button",
    "@coss/combobox",
    "@coss/field",
    "@coss/form"
  ],
  "files": [
    {
      "path": "registry/default/particles/p-combobox-12.tsx",
      "content": "\"use client\";\n\nimport type { FormEvent } from \"react\";\nimport { useState } from \"react\";\nimport { Button } from \"@/registry/default/ui/button\";\nimport {\n  Combobox,\n  ComboboxChip,\n  ComboboxChips,\n  ComboboxChipsInput,\n  ComboboxEmpty,\n  ComboboxItem,\n  ComboboxList,\n  ComboboxPopup,\n  ComboboxValue,\n} from \"@/registry/default/ui/combobox\";\nimport { Field, FieldError, FieldLabel } from \"@/registry/default/ui/field\";\nimport { Form } from \"@/registry/default/ui/form\";\n\nconst items = [\n  { label: \"Apple\", value: \"apple\" },\n  { label: \"Banana\", value: \"banana\" },\n  { label: \"Orange\", value: \"orange\" },\n  { label: \"Grape\", value: \"grape\" },\n  { label: \"Strawberry\", value: \"strawberry\" },\n  { label: \"Mango\", value: \"mango\" },\n  { label: \"Pineapple\", value: \"pineapple\" },\n  { label: \"Kiwi\", value: \"kiwi\" },\n  { label: \"Peach\", value: \"peach\" },\n  { label: \"Pear\", value: \"pear\" },\n];\n\nexport default function Particle() {\n  const [loading, setLoading] = useState(false);\n  const onSubmit = async (e: FormEvent<HTMLFormElement>) => {\n    e.preventDefault();\n    const formData = new FormData(e.currentTarget);\n    const selectedItems = formData.getAll(\"items\");\n    const itemValues = selectedItems.map(\n      (selectedItem) =>\n        items.find((item) => item.label === selectedItem)?.value ||\n        selectedItem,\n    );\n    setLoading(true);\n    await new Promise((r) => setTimeout(r, 800));\n    setLoading(false);\n    alert(`Favorite items: ${itemValues.join(\", \") || \"\"}`);\n  };\n\n  return (\n    <Form className=\"max-w-64\" onSubmit={onSubmit}>\n      <Field name=\"items\">\n        <FieldLabel>Favorite items</FieldLabel>\n        <Combobox items={items} multiple required>\n          <ComboboxChips>\n            <ComboboxValue>\n              {(value: { value: string; label: string }[]) => (\n                <>\n                  {value?.map((item) => (\n                    <ComboboxChip aria-label={item.label} key={item.value}>\n                      {item.label}\n                    </ComboboxChip>\n                  ))}\n                  <ComboboxChipsInput\n                    placeholder={value.length > 0 ? undefined : \"Select items…\"}\n                  />\n                </>\n              )}\n            </ComboboxValue>\n          </ComboboxChips>\n          <ComboboxPopup>\n            <ComboboxEmpty>No items found.</ComboboxEmpty>\n            <ComboboxList>\n              {(item) => (\n                <ComboboxItem key={item.value} value={item}>\n                  {item.label}\n                </ComboboxItem>\n              )}\n            </ComboboxList>\n          </ComboboxPopup>\n        </Combobox>\n        <FieldError>Please select at least one item.</FieldError>\n      </Field>\n      <Button loading={loading} type=\"submit\">\n        Submit\n      </Button>\n    </Form>\n  );\n}\n",
      "type": "registry:block"
    }
  ],
  "meta": {
    "className": "**:data-[slot=preview]:w-full **:data-[slot=preview]:max-w-64"
  },
  "categories": [
    "combobox",
    "form",
    "input"
  ],
  "type": "registry:block"
}