import classnames from 'classnames'; import xor from 'lodash/xor'; import React, { Ref } from 'react'; import { connectField, HTMLFieldProps } from 'uniforms'; import type { Option } from './types'; import wrapField from './wrapField'; const base64: (string: string) => string = typeof btoa === 'undefined' ? /* istanbul ignore next */ x => Buffer.from(x).toString('base64') : btoa; const escape = (x: string) => base64(encodeURIComponent(x)).replace(/=+$/, ''); export type SelectFieldProps = HTMLFieldProps< string | string[], HTMLDivElement, { options?: Option[]; checkboxes?: boolean; inline?: boolean; inputClassName?: string; inputRef?: Ref; } >; function Select({ options, checkboxes, disabled, error, fieldType, id, inline, inputClassName, inputRef, label, name, onChange, placeholder, readOnly, required, value, ...props }: SelectFieldProps) { const multiple = fieldType === Array; return wrapField( { ...props, disabled, error, id, label, required, }, checkboxes ? ( options?.map(item => (
)) ) : ( ), ); } export default connectField(Select, { kind: 'leaf' });