diff --git a/src/components/extenders/Select.tsx b/src/components/extenders/Select.tsx index 8c0b0fdd..8eecc5c7 100644 --- a/src/components/extenders/Select.tsx +++ b/src/components/extenders/Select.tsx @@ -17,7 +17,8 @@ export const selectStyles = tv({ "text-main-11 rounded-sm flex items-center dim focus-visible:outline-main-12 !leading-none justify-between text-nowrap font-text font-semibold", ], slots: { - dropdown: "outline-0 z-50 origin-top animate-drop animate-stretch mt-sm min-w-[var(--popover-anchor-width)]", + dropdown: + "outline-0 z-50 origin-top animate-drop animate-stretch mt-sm min-w-[var(--popover-anchor-width)]", item: "rounded-sm flex justify-between items-center gap-lg cursor-pointer select-none p-sm outline-offset-0 outline-0 text-nowrap focus-visible:outline-main-12", icon: "flex items-center", value: "flex gap-sm items-center", @@ -137,12 +138,14 @@ export type SelectProps = Component<{ }> & RadixSelect.SelectProps; -type MaybeArray = IsArray extends true ? T[] : T; +type MaybeArray = IsArray extends true + ? T[] + : T; export default function Select< T extends string | number, Multiple extends undefined | boolean, - Value extends MaybeArray, + Value extends MaybeArray >({ look, size, @@ -174,35 +177,45 @@ export default function Select< }); const value = useMemo(() => getter ?? internal, [getter, internal]); - const setValue = useCallback((v: Value) => setter?.(v) ?? setInternal(v), [setter]); + const setValue = useCallback( + (v: Value) => setter?.(v) ?? setInternal(v), + [setter] + ); const [searchInput, setSearch] = useState(); const matches = useMemo(() => { if (!search) return Object.keys(options ?? {}); // const textToMatch = Object.keys(options ?? {}).map(option => `${option}_${options[option]?.props?.children?.filter(a => typeof a !== "object").join(" ")}`) - const textToMatch = Object.keys(options ?? {}).reduce( - (matches, option) => { - const opt = options?.[option]; - const key = - typeof opt === "string" - ? opt - : ( - options?.[option] as Exclude> - )?.props?.children - ?.filter?.((a: unknown) => typeof a !== "object") - ?.join(" "); + const textToMatch = Object.keys(options ?? {}).reduce((matches, option) => { + const opt = options?.[option]; + const key = + typeof opt === "string" + ? opt + : ( + options?.[option] as Exclude< + ReactNode, + string | number | boolean | Iterable + > + )?.props?.children + ?.filter?.((a: unknown) => typeof a !== "object") + ?.join(" "); - return Object.assign(matches, { [`${option}`]: option }, { [`${key}`]: option }); - }, - {} as { [key: string]: keyof typeof options }, - ); - const searchMatches = matchSorter(Object.keys(textToMatch), searchInput ?? "").map(key => textToMatch[key]); + return Object.assign( + matches, + { [`${option}`]: option }, + { [`${key}`]: option } + ); + }, {} as { [key: string]: keyof typeof options }); + const searchMatches = matchSorter( + Object.keys(textToMatch), + searchInput ?? "" + ).map((key) => textToMatch[key]); const uniqueOptionMatches = Array.from( searchMatches.reduce((set, option) => { set.add(option); return set; - }, new Set()), + }, new Set()) ) as (typeof value)[]; return uniqueOptionMatches; @@ -211,7 +224,9 @@ export default function Select< const label = useMemo(() => { if ( value && - (typeof value === "number" || typeof value === "string" || typeof value === "symbol") && + (typeof value === "number" || + typeof value === "string" || + typeof value === "symbol") && options?.[value] ) return options?.[value]; @@ -221,8 +236,9 @@ export default function Select< + "w-[1.2em] h-[1.2em] flex items-center justify-center rounded-full bg-main-6 text-main-12" + )} + > {value.length} {" "} {placeholder} @@ -234,17 +250,23 @@ export default function Select< return ( { + setValue={(value) => { setSearch(value); - }}> + }} + > setValue(v as Value)} + setValue={(v) => setValue(v as Value)} value={value as string} - defaultValue={multiple ? [] : undefined}> + defaultValue={multiple ? [] : undefined} + >
{label}
- {loading ? : } + {loading ? ( + + ) : ( + + )}
@@ -254,7 +276,11 @@ export default function Select< )} @@ -277,7 +303,11 @@ export default function Select< key="select" className={mergeClass( check(), - !((typeof value === "object" && value?.length > 0) || value === undefined) && "opacity-0", + !( + (typeof value === "object" && + value?.length > 0) || + value === undefined + ) && "opacity-0" )} size="sm" remix="RiCheckFill" @@ -287,7 +317,7 @@ export default function Select< } /> )} - {matches?.map(_value => ( + {matches?.map((_value) => ( = Component< @@ -44,9 +51,16 @@ export type InputProps = Component< function Input({ look, size, state, className, ...props }: InputProps) { const { header, footer, prefix, suffix, label, hint, ...rest } = props; - if (extensions.some(extension => !!props?.[extension])) + if (extensions.some((extension) => !!props?.[extension])) return ( -