Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions apps/storybook/src/stories/select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,41 @@ export const Default: Story = {
</Select>
),
};

export const WithLoading: Story = {
render: () => (
<Select>
<SelectTrigger loading>
<SelectValue placeholder="Select an option" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Options</SelectLabel>
<SelectItem value="option-1">Option 1</SelectItem>
<SelectItem value="option-2">Option 2</SelectItem>
<SelectItem value="option-3">Option 3</SelectItem>
</SelectGroup>
<SelectSeparator />
<SelectGroup>
<SelectLabel>More Options</SelectLabel>
<SelectItem value="option-4">Option 4</SelectItem>
<SelectItem value="option-5">Option 5</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
),
};

export const WithCustomStyling: Story = {
render: () => (
<Select>
<SelectTrigger className="bg-gray-100 border-gray-300 text-gray-700">
<SelectValue placeholder="Custom styling" />
</SelectTrigger>
<SelectContent>
<SelectItem value="custom-1">Custom Option 1</SelectItem>
<SelectItem value="custom-2">Custom Option 2</SelectItem>
</SelectContent>
</Select>
),
};
16 changes: 12 additions & 4 deletions packages/ui/src/components/atoms/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Check, ChevronDown, ChevronUp } from "lucide-react";

import { cn } from "@repo/ui/lib/utils";
import { baseInputVariants } from "./base-input";
import OrbitingDotsLoading from "./orbitingDotsLoading";

const Select = SelectPrimitive.Root;

Expand All @@ -15,20 +16,27 @@ const SelectValue = SelectPrimitive.Value;

const SelectTrigger = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger> & {
loading?: boolean;
}
>(({ className, children, loading, ...props }, ref) => (
<SelectPrimitive.Trigger
ref={ref}
className={cn(
"flex h-10 w-full items-center justify-between rounded-lg border border-input px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
"flex h-10 w-full items-center justify-between rounded-lg border border-input px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
baseInputVariants({ size: "sm" }),
className,
)}
{...props}
disabled={loading || props.disabled} // Disable select while loading
>
{children}
<SelectPrimitive.Icon asChild>
<ChevronDown className="h-4 w-4 opacity-50" />
{loading ? (
<OrbitingDotsLoading />
) : (
<ChevronDown className="h-4 w-4 opacity-50" />
)}
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
));
Expand Down
Loading