import { Tooltip } from '@components/common/form/Tooltip.js'; import { getNestedError } from '@components/common/form/utils/getNestedError.js'; import { Field, FieldError, FieldLabel } from '@components/common/ui/Field.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import { cn } from '@evershop/evershop/lib/util/cn'; import React from 'react'; import { Controller, FieldPath, FieldValues, RegisterOptions, useFormContext } from 'react-hook-form'; import Select, { Props as ReactSelectProps } from 'react-select'; interface SelectOption { value: any; label: string; [key: string]: any; } interface ReactSelectFieldProps extends Omit, 'name' | 'value' | 'onChange'> { name: FieldPath; label?: string; error?: string; helperText?: string; required?: boolean; validation?: RegisterOptions; options: SelectOption[]; className?: string; wrapperClassName?: string; defaultValue?: any; } export function ReactSelectField({ name, label, error, wrapperClassName = 'form-field', helperText, required, validation, options, className, isMulti = false, defaultValue, ...selectProps }: ReactSelectFieldProps) { const { control, formState: { errors } } = useFormContext(); const fieldError = getNestedError(name, errors, error); const fieldId = `field-${name}`; const validationRules = { ...validation, ...(required && !validation?.required && { required: _('${field} is required', { field: label || name }) }) }; return ( {label && ( <> {label} {required && *} {helperText && } )} (