File size: 1,582 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
{
  "type": "composition",
  "npmDependencies": [],
  "fileDependencies": [],
  "id": "native-select",
  "file": {
    "name": "native-select.tsx",
    "content": "\"use client\"\n\nimport { NativeSelect as Select } from \"@chakra-ui/react\"\nimport * as React from \"react\"\n\ninterface NativeSelectRootProps extends Select.RootProps {\n  icon?: React.ReactNode\n}\n\nexport const NativeSelectRoot = React.forwardRef<\n  HTMLDivElement,\n  NativeSelectRootProps\n>(function NativeSelect(props, ref) {\n  const { icon, children, ...rest } = props\n  return (\n    <Select.Root ref={ref} {...rest}>\n      {children}\n      <Select.Indicator>{icon}</Select.Indicator>\n    </Select.Root>\n  )\n})\n\ninterface NativeSelectItem {\n  value: string\n  label: string\n  disabled?: boolean\n}\n\ninterface NativeSelectField extends Select.FieldProps {\n  items?: Array<string | NativeSelectItem>\n}\n\nexport const NativeSelectField = React.forwardRef<\n  HTMLSelectElement,\n  NativeSelectField\n>(function NativeSelectField(props, ref) {\n  const { items: itemsProp, children, ...rest } = props\n\n  const items = React.useMemo(\n    () =>\n      itemsProp?.map((item) =>\n        typeof item === \"string\" ? { label: item, value: item } : item,\n      ),\n    [itemsProp],\n  )\n\n  return (\n    <Select.Field ref={ref} {...rest}>\n      {children}\n      {items?.map((item) => (\n        <option key={item.value} value={item.value} disabled={item.disabled}>\n          {item.label}\n        </option>\n      ))}\n    </Select.Field>\n  )\n})\n"
  },
  "component": "NativeSelect"
}