Added some small enchances

This commit is contained in:
Oleksandr Prokhorenko
2026-09-24 22:41:06 +03:00
parent 9ccbac4aca
commit 7f3a56a4ca
21 changed files with 441 additions and 211 deletions
@@ -1,54 +0,0 @@
import * as React from 'react';
import { cn } from '@merchantflow/ui/lib/utils';
import { ChevronDownIcon } from 'lucide-react';
type NativeSelectProps = Omit<React.ComponentProps<'select'>, 'size'> & {
size?: 'sm' | 'default';
};
function NativeSelect({ className, size = 'default', ...props }: NativeSelectProps) {
return (
<div
className={cn(
'group/native-select relative w-fit has-[select:disabled]:opacity-50',
className,
)}
data-slot="native-select-wrapper"
data-size={size}
>
<select
data-slot="native-select"
data-size={size}
className="h-11 w-full min-w-0 appearance-none rounded-lg border border-input bg-transparent py-1 pr-8 pl-2.5 text-base transition-colors outline-none select-none selection:bg-primary selection:text-primary-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-[size=sm]:h-11 data-[size=sm]:rounded-[min(var(--radius-md),10px)] data-[size=sm]:py-0.5 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40"
{...props}
/>
<ChevronDownIcon
className="pointer-events-none absolute top-1/2 right-2.5 size-4 -translate-y-1/2 text-muted-foreground select-none"
aria-hidden="true"
data-slot="native-select-icon"
/>
</div>
);
}
function NativeSelectOption({ className, ...props }: React.ComponentProps<'option'>) {
return (
<option
data-slot="native-select-option"
className={cn('bg-[Canvas] text-[CanvasText]', className)}
{...props}
/>
);
}
function NativeSelectOptGroup({ className, ...props }: React.ComponentProps<'optgroup'>) {
return (
<optgroup
data-slot="native-select-optgroup"
className={cn('bg-[Canvas] text-[CanvasText]', className)}
{...props}
/>
);
}
export { NativeSelect, NativeSelectOptGroup, NativeSelectOption };
+91
View File
@@ -0,0 +1,91 @@
import * as React from 'react';
import { Select as SelectPrimitive } from '@base-ui/react/select';
import { CheckIcon, ChevronDownIcon } from 'lucide-react';
import { cn } from '@merchantflow/ui/lib/utils';
type SelectProps = Omit<React.ComponentProps<'button'>, 'value' | 'defaultValue' | 'onChange'> & {
value: string;
onValueChange: (value: string) => void;
autoComplete?: string;
};
function Select({
children,
className,
value,
onValueChange,
name,
autoComplete,
disabled,
id,
...props
}: SelectProps) {
const items = React.Children.toArray(children)
.filter(React.isValidElement<{ value: string; children: React.ReactNode }>)
.map((child) => ({ value: child.props.value, label: child.props.children }));
return (
<SelectPrimitive.Root
items={items}
value={value}
onValueChange={(next) => {
if (next !== null) onValueChange(next);
}}
name={name}
autoComplete={autoComplete}
disabled={disabled}
id={id}
>
<SelectPrimitive.Trigger
{...props}
data-slot="select-trigger"
className={cn(
'flex h-11 w-full min-w-0 items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-3 py-1 text-left text-base text-foreground outline-none transition-colors focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20',
className,
)}
>
<SelectPrimitive.Value className="min-w-0 truncate" />
<SelectPrimitive.Icon className="shrink-0 text-muted-foreground">
<ChevronDownIcon className="size-4" aria-hidden="true" />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
<SelectPrimitive.Portal>
<SelectPrimitive.Positioner
sideOffset={6}
align="start"
alignItemWithTrigger={false}
className="z-[60]"
>
<SelectPrimitive.Popup className="max-h-[min(20rem,var(--available-height))] w-[var(--anchor-width)] min-w-32 max-w-[var(--available-width)] overflow-y-auto overscroll-contain rounded-lg border bg-popover p-1 text-popover-foreground shadow-lg outline-none">
<SelectPrimitive.List>{children}</SelectPrimitive.List>
</SelectPrimitive.Popup>
</SelectPrimitive.Positioner>
</SelectPrimitive.Portal>
</SelectPrimitive.Root>
);
}
function SelectOption({
value,
children,
disabled,
}: {
value: string;
children: React.ReactNode;
disabled?: boolean;
}) {
return (
<SelectPrimitive.Item
value={value}
disabled={disabled}
data-value={value}
className="relative flex min-h-11 cursor-pointer items-center rounded-md py-2 pr-8 pl-3 text-sm outline-none select-none data-highlighted:bg-accent data-selected:font-medium data-disabled:pointer-events-none data-disabled:opacity-50"
>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
<SelectPrimitive.ItemIndicator className="absolute right-2.5">
<CheckIcon className="size-4" aria-hidden="true" />
</SelectPrimitive.ItemIndicator>
</SelectPrimitive.Item>
);
}
export { Select, SelectOption };