135 lines
4.2 KiB
TypeScript
135 lines
4.2 KiB
TypeScript
"use client";
|
|||
|
|
|
||
|
|
import * as React from "react";
|
||
|
|
import * as SelectPrimitive from "@radix-ui/react-select";
|
||
|
|
import { Check, ChevronDown, ChevronUp } from "lucide-react";
|
||
|
|
import inputStyles from "./Input.module.css";
|
||
|
|
import styles from "./Select.module.css";
|
||
|
|
|
||
|
|
const Select = SelectPrimitive.Root;
|
||
|
|
|
||
|
|
const SelectGroup = SelectPrimitive.Group;
|
||
|
|
|
||
|
|
const SelectValue = SelectPrimitive.Value;
|
||
|
|
|
||
|
|
const SelectTrigger = React.forwardRef<
|
||
|
|
React.ElementRef<typeof SelectPrimitive.Trigger>,
|
||
|
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
|
||
|
|
>(({ children, className, ...props }, ref) => (
|
||
|
|
<SelectPrimitive.Trigger
|
||
|
|
ref={ref}
|
||
|
|
className={`${inputStyles.input} ${styles.selectTrigger} ${className || ""}`}
|
||
|
|
{...props}
|
||
|
|
>
|
||
|
|
{children}
|
||
|
|
<SelectPrimitive.Icon asChild>
|
||
|
|
<ChevronDown className={styles.selectIcon} />
|
||
|
|
</SelectPrimitive.Icon>
|
||
|
|
</SelectPrimitive.Trigger>
|
||
|
|
));
|
||
|
|
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
|
||
|
|
|
||
|
|
const SelectScrollUpButton = React.forwardRef<
|
||
|
|
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
|
||
|
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
|
||
|
|
>(({ className, ...props }, ref) => (
|
||
|
|
<SelectPrimitive.ScrollUpButton
|
||
|
|
ref={ref}
|
||
|
|
className={`${styles.scrollButton} ${className || ""}`}
|
||
|
|
{...props}
|
||
|
|
>
|
||
|
|
<ChevronUp className={styles.scrollIcon} />
|
||
|
|
</SelectPrimitive.ScrollUpButton>
|
||
|
|
));
|
||
|
|
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
|
||
|
|
|
||
|
|
const SelectScrollDownButton = React.forwardRef<
|
||
|
|
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
|
||
|
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
|
||
|
|
>(({ className, ...props }, ref) => (
|
||
|
|
<SelectPrimitive.ScrollDownButton
|
||
|
|
ref={ref}
|
||
|
|
className={`${styles.scrollButton} ${className || ""}`}
|
||
|
|
{...props}
|
||
|
|
>
|
||
|
|
<ChevronDown className={styles.scrollIcon} />
|
||
|
|
</SelectPrimitive.ScrollDownButton>
|
||
|
|
));
|
||
|
|
SelectScrollDownButton.displayName =
|
||
|
|
SelectPrimitive.ScrollDownButton.displayName;
|
||
|
|
|
||
|
|
const SelectContent = React.forwardRef<
|
||
|
|
React.ElementRef<typeof SelectPrimitive.Content>,
|
||
|
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
|
||
|
|
>(({ children, position = "popper", className, ...props }, ref) => (
|
||
|
|
<SelectPrimitive.Portal>
|
||
|
|
<SelectPrimitive.Content
|
||
|
|
ref={ref}
|
||
|
|
position={position}
|
||
|
|
className={`${styles.selectContent} ${className || ""}`}
|
||
|
|
{...props}
|
||
|
|
>
|
||
|
|
<SelectScrollUpButton />
|
||
|
|
<SelectPrimitive.Viewport className={styles.selectViewport}>
|
||
|
|
{children}
|
||
|
|
</SelectPrimitive.Viewport>
|
||
|
|
<SelectScrollDownButton />
|
||
|
|
</SelectPrimitive.Content>
|
||
|
|
</SelectPrimitive.Portal>
|
||
|
|
));
|
||
|
|
SelectContent.displayName = SelectPrimitive.Content.displayName;
|
||
|
|
|
||
|
|
const SelectLabel = React.forwardRef<
|
||
|
|
React.ElementRef<typeof SelectPrimitive.Label>,
|
||
|
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
|
||
|
|
>(({ className, ...props }, ref) => (
|
||
|
|
<SelectPrimitive.Label
|
||
|
|
ref={ref}
|
||
|
|
className={`${styles.selectLabel} ${className || ""}`}
|
||
|
|
{...props}
|
||
|
|
/>
|
||
|
|
));
|
||
|
|
SelectLabel.displayName = SelectPrimitive.Label.displayName;
|
||
|
|
|
||
|
|
const SelectItem = React.forwardRef<
|
||
|
|
React.ElementRef<typeof SelectPrimitive.Item>,
|
||
|
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
|
||
|
|
>(({ children, className, ...props }, ref) => (
|
||
|
|
<SelectPrimitive.Item
|
||
|
|
ref={ref}
|
||
|
|
className={`${styles.selectItem} ${className || ""}`}
|
||
|
|
{...props}
|
||
|
|
>
|
||
|
|
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||
|
|
<SelectPrimitive.ItemIndicator className={styles.selectItemIndicator}>
|
||
|
|
<Check className={styles.checkIcon} />
|
||
|
|
</SelectPrimitive.ItemIndicator>
|
||
|
|
</SelectPrimitive.Item>
|
||
|
|
));
|
||
|
|
SelectItem.displayName = SelectPrimitive.Item.displayName;
|
||
|
|
|
||
|
|
const SelectSeparator = React.forwardRef<
|
||
|
|
React.ElementRef<typeof SelectPrimitive.Separator>,
|
||
|
|
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
|
||
|
|
>(({ className, ...props }, ref) => (
|
||
|
|
<SelectPrimitive.Separator
|
||
|
|
ref={ref}
|
||
|
|
className={`${styles.selectSeparator} ${className || ""}`}
|
||
|
|
{...props}
|
||
|
|
/>
|
||
|
|
));
|
||
|
|
SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
|
||
|
|
|
||
|
|
export {
|
||
|
|
Select,
|
||
|
|
SelectGroup,
|
||
|
|
SelectValue,
|
||
|
|
SelectTrigger,
|
||
|
|
SelectContent,
|
||
|
|
SelectLabel,
|
||
|
|
SelectItem,
|
||
|
|
SelectSeparator,
|
||
|
|
SelectScrollUpButton,
|
||
|
|
SelectScrollDownButton,
|
||
|
|
};
|