# Select

A raised trigger that presses in while open, and a floating board of options. The highlighted option lifts.

Docs: https://cozy-ui.solo.engineer/docs/components/select/

Install: `npx shadcn@latest add @cozy/select`

### Usage

```tsx
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@/components/ui/select"
```

### Example

```tsx
import { Label } from "@/components/ui/label";
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue } from "@/components/ui/select";

export default function SelectDemo() {
  return (
    <div className="grid w-full max-w-xs gap-2">
      <Label>Crop to plant</Label>
      <Select>
        <SelectTrigger aria-label="Crop"><SelectValue placeholder="Pick a crop…" /></SelectTrigger>
        <SelectContent>
          <SelectGroup>
            <SelectLabel>Fields</SelectLabel>
            <SelectItem value="rice">Rice</SelectItem>
            <SelectItem value="corn">Corn</SelectItem>
            <SelectItem value="sweet-potato">Sweet potato</SelectItem>
          </SelectGroup>
          <SelectSeparator />
          <SelectGroup>
            <SelectLabel>Garden</SelectLabel>
            <SelectItem value="luffa">Luffa gourd</SelectItem>
            <SelectItem value="spinach">Water spinach</SelectItem>
            <SelectItem value="pumpkin" disabled>Pumpkin (level 9)</SelectItem>
          </SelectGroup>
        </SelectContent>
      </Select>
    </div>
  );
}
```

### Source (components/ui/select.tsx)

```tsx
import * as React from "react";
import { Select as SelectPrimitive } from "radix-ui";
import { cn } from "@/lib/utils";
import { CheckGlyph, ChevronGlyph } from "./glyphs";

function Select(props: React.ComponentProps<typeof SelectPrimitive.Root>) {
  return <SelectPrimitive.Root data-slot="select" {...props} />;
}
function SelectGroup(props: React.ComponentProps<typeof SelectPrimitive.Group>) {
  return <SelectPrimitive.Group data-slot="select-group" {...props} />;
}
function SelectValue(props: React.ComponentProps<typeof SelectPrimitive.Value>) {
  return <SelectPrimitive.Value data-slot="select-value" {...props} />;
}
function SelectTrigger({ className, children, ...props }: React.ComponentProps<typeof SelectPrimitive.Trigger>) {
  return (
    <SelectPrimitive.Trigger data-slot="select-trigger" className={cn("cz-select", className)} {...props}>
      {children}
      <SelectPrimitive.Icon asChild>
        <ChevronGlyph />
      </SelectPrimitive.Icon>
    </SelectPrimitive.Trigger>
  );
}
function SelectContent({ className, children, position = "popper", sideOffset = 6, ...props }: React.ComponentProps<typeof SelectPrimitive.Content>) {
  return (
    <SelectPrimitive.Portal>
      <SelectPrimitive.Content
        data-slot="select-content"
        position={position}
        sideOffset={sideOffset}
        className={cn("cz-menu", position === "popper" && "cz-menu--select", className)}
        {...props}
      >
        <SelectPrimitive.Viewport>{children}</SelectPrimitive.Viewport>
      </SelectPrimitive.Content>
    </SelectPrimitive.Portal>
  );
}
function SelectLabel({ className, ...props }: React.ComponentProps<typeof SelectPrimitive.Label>) {
  return <SelectPrimitive.Label data-slot="select-label" className={cn("cz-menu__label", className)} {...props} />;
}
function SelectItem({ className, children, ...props }: React.ComponentProps<typeof SelectPrimitive.Item>) {
  return (
    <SelectPrimitive.Item data-slot="select-item" className={cn("cz-menu__item", className)} {...props}>
      <span className="cz-menu__indicator">
        <SelectPrimitive.ItemIndicator>
          <CheckGlyph />
        </SelectPrimitive.ItemIndicator>
      </span>
      <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
    </SelectPrimitive.Item>
  );
}
function SelectSeparator({ className, ...props }: React.ComponentProps<typeof SelectPrimitive.Separator>) {
  return <SelectPrimitive.Separator data-slot="select-separator" className={cn("cz-menu__separator", className)} {...props} />;
}

export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue };
```

npm: `import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue } from "@0xtrou/cozy-ui"` (after `npm install @0xtrou/cozy-ui` and `import "@0xtrou/cozy-ui/styles.css"`).
