import React from 'react'; import { Form, FormInputProps, FormTextAreaProps, Label, LabelProps, Checkbox } from 'semantic-ui-react'; import { FormikProps } from 'formik'; import LabelWithHelp from './LabelWithHelp'; import { FormErrorLabelsProps } from './errorHandling'; import { formatBalance } from '@polkadot/util'; import styled from 'styled-components'; /* * Generic form field components * * The idea is to provide an easy way of introducing new logic, * that will affect all of the exsiting form fields (or all fields of given type) * and to easily switch the structure/display of a typical form field. */ type InputFormFieldProps = Omit & { help?: string; unit?: string; error?: LabelProps; }; export function InputFormField (props: InputFormFieldProps) { const { unit } = props; const fieldProps = { ...props, label: undefined, error: undefined }; return ( { unit &&
{unit}
}
); } type TextareaFormFieldProps = Omit & { help?: string; error?: LabelProps; }; export function TextareaFormField (props: TextareaFormFieldProps) { const fieldProps = { ...props, label: undefined, error: undefined }; return ( ); } type FormFieldProps = Omit<(InputFormFieldProps | TextareaFormFieldProps), 'error'> & { error?: LabelProps; showErrorMsg?: boolean; }; const StyledFormField = styled(Form.Field)` & .field { margin-bottom: 0 !important; } `; export function FormField (props: React.PropsWithChildren) { const { error, showErrorMsg = false, label, help, children } = props; return ( { (label && help) ? : (label ? : null) } { children } { Boolean(showErrorMsg && error) && ); } type ReawrdPolicyFieldsType = { rewardAmount: string; rewardNextBlock: string; rewardRecurring: boolean; rewardInterval: string; } type RewardPolicyFieldsProps = Pick, 'values' | 'handleChange' | 'setFieldValue'> & { errorLabelsProps: FormErrorLabelsProps; }; export function RewardPolicyFields ({ values, errorLabelsProps, handleChange, setFieldValue }: RewardPolicyFieldsProps) { return ( <> { setFieldValue('rewardRecurring', data.checked); }} label={'Recurring'} checked={values.rewardRecurring}/> { values.rewardRecurring && ( ) } ); } export default FormField;