Add loading state for select dropdown

This commit is contained in:
Jonathan
2025-06-13 23:39:25 +02:00
committed by Bryan Frimin
parent 2107713a3e
commit f709eda08c
3 changed files with 28 additions and 2 deletions

View File

@@ -20,7 +20,7 @@ export function PeopleSelectField({
return ( return (
<Field {...props}> <Field {...props}>
<Suspense <Suspense
fallback={<Select variant="editor" disabled placeholder="Loading..." />} fallback={<Select variant="editor" loading placeholder="Loading..." />}
> >
<PeopleSelectWithQuery <PeopleSelectWithQuery
organizationId={organizationId} organizationId={organizationId}

View File

@@ -37,3 +37,17 @@ export const Invalid: Story = {
invalid: true, invalid: true,
}, },
}; };
export const Loading: Story = {
args: {
...Default.args,
loading: true,
},
};
export const Disabled: Story = {
args: {
...Default.args,
disabled: true,
},
};

View File

@@ -15,6 +15,7 @@ import { IconChevronGrabberVertical } from "../Icons/IconChevronGrabberVertical.
import { tv } from "tailwind-variants"; import { tv } from "tailwind-variants";
import { Children, type ComponentProps, type PropsWithChildren } from "react"; import { Children, type ComponentProps, type PropsWithChildren } from "react";
import { IconMagnifyingGlass } from "../Icons/IconMagnifyingGlass.tsx"; import { IconMagnifyingGlass } from "../Icons/IconMagnifyingGlass.tsx";
import { Spinner } from "../Spinner/Spinner.tsx";
type Props<T> = PropsWithChildren< type Props<T> = PropsWithChildren<
{ {
@@ -29,6 +30,7 @@ type Props<T> = PropsWithChildren<
searchValue?: string; searchValue?: string;
onSearch?: (s: string) => void; onSearch?: (s: string) => void;
searchPlaceholder?: string; searchPlaceholder?: string;
loading?: boolean;
} & Omit<ComponentProps<typeof Root>, "onChange" | "value"> } & Omit<ComponentProps<typeof Root>, "onChange" | "value">
>; >;
@@ -51,6 +53,11 @@ const select = tv({
trigger: "opacity-60", trigger: "opacity-60",
}, },
}, },
loading: {
true: {
trigger: "opacity-60",
},
},
variant: { variant: {
dashed: { dashed: {
trigger: input({ trigger: input({
@@ -88,6 +95,7 @@ export function Select<T>({
searchValue, searchValue,
onSearch, onSearch,
searchPlaceholder, searchPlaceholder,
loading,
...props ...props
}: Props<T>) { }: Props<T>) {
const { trigger, content, icon } = select({ const { trigger, content, icon } = select({
@@ -105,7 +113,11 @@ export function Select<T>({
> >
<Value placeholder={placeholder} /> <Value placeholder={placeholder} />
<Icon className={icon()}> <Icon className={icon()}>
<IconChevronGrabberVertical size={16} /> {loading ? (
<Spinner size={16} />
) : (
<IconChevronGrabberVertical size={16} />
)}
</Icon> </Icon>
</Trigger> </Trigger>
<Portal> <Portal>