feat: 添加i18n,美化界面
This commit is contained in:
47
packages/components/src/input/index.tsx
Normal file
47
packages/components/src/input/index.tsx
Normal file
@@ -0,0 +1,47 @@
|
||||
import { FormControlLabel, TextField } from '@mui/material';
|
||||
import { useForm, Controller } from 'react-hook-form';
|
||||
export const InputControl = ({ name, value, onChange }: { name: string; value: string; onChange?: (value: string) => void }) => {
|
||||
return (
|
||||
<TextField
|
||||
variant='outlined'
|
||||
size='small'
|
||||
name={name}
|
||||
value={value || ''}
|
||||
onChange={(e) => onChange?.(e.target.value)}
|
||||
sx={{
|
||||
width: '100%',
|
||||
marginBottom: '16px',
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
type FormProps = {
|
||||
onSubmit?: (data: any) => void;
|
||||
children?: React.ReactNode;
|
||||
};
|
||||
export const FormDemo = (props: FormProps) => {
|
||||
const { control, handleSubmit } = useForm();
|
||||
const { onSubmit = () => {}, children } = props;
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<Controller
|
||||
name='name'
|
||||
control={control}
|
||||
defaultValue=''
|
||||
rules={{ required: 'Name is required' }}
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<TextField
|
||||
{...field}
|
||||
label='Name'
|
||||
variant='outlined'
|
||||
margin='normal'
|
||||
fullWidth //
|
||||
error={!!error}
|
||||
helperText={<>{error?.message}</>}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user