import * as React from 'react'; import * as PropTypes from 'prop-types'; // @ts-ignore import _omit from 'lodash/omit'; import FieldWrapper, { LocalFieldWrapperProps, fieldWrapperPropTypes, fieldWrapperDefaultProps } from '../FieldWrapper/FieldWrapper'; import { Omit } from '../types'; import { formikField, reduxFormField } from '../adaptors/fields'; import Switch, { LocalSwitchProps, SwitchProps, switchPropTypes, switchDefaultProps } from './Switch'; export type LocalSwitchFieldProps = Omit & LocalSwitchProps & { a11yId?: string; /** Switch label */ switchLabel?: string; switchProps?: LocalSwitchProps; }; export type SwitchFieldProps = LocalSwitchFieldProps & SwitchProps; export type SwitchFieldComponents = { Formik: React.FunctionComponent; ReduxForm: React.FunctionComponent; }; export const SwitchField: React.FunctionComponent & SwitchFieldComponents = ({ a11yId, description, hint, isOptional, isRequired, label, switchLabel, state, validationText, autoFocus, checked, className, defaultChecked, disabled, id, name, palette, switchRef, value, onBlur, onChange, onFocus, ...props }) => ( {({ elementProps }) => ( )} ); SwitchField.Formik = formikField(SwitchField, { hasFieldWrapper: true, isCheckbox: true }); SwitchField.ReduxForm = reduxFormField(SwitchField, { hasFieldWrapper: true, isCheckbox: true }); export const switchFieldPropTypes = { a11yId: PropTypes.string, switchLabel: PropTypes.string, switchProps: PropTypes.shape(switchPropTypes), ..._omit(fieldWrapperPropTypes, 'children'), ...switchPropTypes }; SwitchField.propTypes = switchFieldPropTypes; export const switchFieldDefaultProps = { a11yId: undefined, switchLabel: undefined, switchProps: {}, ...fieldWrapperDefaultProps, ...switchDefaultProps }; SwitchField.defaultProps = switchFieldDefaultProps; // @ts-ignore const C: React.FunctionComponent & SwitchFieldComponents = SwitchField; export default C;