import FormControlLabel from '@material-ui/core/FormControlLabel' import FormGroup from '@material-ui/core/FormGroup' import { useTheme } from '@material-ui/core/styles' import MuiSwitch, { SwitchProps as MuiSwitchProps, } from '@material-ui/core/Switch/Switch' import React, { FC, memo } from 'react' import type { FieldRenderProps } from 'react-final-form' import { Field, FieldProps } from '../lib/Field' type SwitchHTMLElement = HTMLButtonElement export type SwitchProps = MuiSwitchProps & { label: string } export type SwitchBaseProps = SwitchProps & FieldRenderProps export type ExposedSwitchProps = SwitchProps & FieldProps const SwitchFieldBase: FC = ({ input: { value, type, ...restInput }, label, ...custom }) => { const theme = useTheme() return ( } label={label} /> ) } const FormSwitchField = memo(SwitchFieldBase) export const SwitchField: FC = ({ type = 'checkbox', color = 'primary', ...props }) => { const render = (renderProps: FieldRenderProps) => ( ) return ( , SwitchHTMLElement> type={type} color={color} render={render} {...props} /> ) } export default SwitchField