"use client"; import { FieldValues, Path, RegisterOptions, UseFormReturn, } from "react-hook-form"; import SelectTemplate, { Props as SelectTemplateProps, StylesConfig, } from "react-select"; import { cn } from "../../../helper/cn"; import dynamic from "next/dynamic"; import { CSSProperties } from "react"; interface SelectProps extends Omit { label?: any; name: Path; form: UseFormReturn | any; formOptions?: RegisterOptions; // eslint-disable-next-line @typescript-eslint/no-explicit-any } const customStyles: StylesConfig = { control: (provided) => ({ ...provided, backgroundColor: "var(--color-base-100)", borderColor: "color-mix(in oklab, var(--color-base-content) 20%, #0000);", borderRadius: "0.5rem", padding: "0.25rem", boxShadow: "none", "&:hover": { borderColor: "color-mix(in oklab, var(--color-base-content) 20%, #0000);", }, }), option: (provided, state) => ({ ...provided, backgroundColor: state.isSelected ? "hsl(var(--p))" : "hsl(var(--b1))", color: "var(--color-primary-content)", "&:hover": { backgroundColor: "var(--color-base-200)" }, // DaisyUI secondary color }), multiValueLabel: (provided) => ({ ...provided, color: "var(--color-primary-content)", }), singleValue: (provided) => ({ ...provided, color: "var(--color-primary-content)", }), multiValue: (provided) => ({ ...provided, backgroundColor: "var(--color-base-300)", }), menu: (provided) => ({ ...provided, backgroundColor: "var(--color-base-100)", borderRadius: "0.5rem", }), }; const SelectCom = ({ name, label = name, placeholder = label, form, formOptions, className, ...inputProps }: SelectProps) => { return (
{label} { if (Array.isArray(newValue)) { form.setValue(name, newValue.map((v: any) => v.value) as any); } else { form.setValue(name, newValue.value); } form.trigger(name); }} value={ (inputProps as any)?.isMulti ? (inputProps as any).options?.filter((o: any) => form.watch(name)?.includes(o.value), ) : (inputProps as any).options?.find( (o: any) => o.value === form.watch(name), ) } styles={customStyles as any} className={cn("w-full placeholder:text-neutral-600", className)} placeholder={placeholder} {...inputProps} /> {form.formState.errors[name]?.message && (

{form.formState.errors[name].message as string}

)}
); }; const SelectWrapper = (props: SelectProps) => ( ); export const Select = dynamic(() => Promise.resolve(SelectWrapper), { ssr: false, });