|
1 | | -import { Grid, Button, IconButton, TextField } from '@mui/material'; |
| 1 | +import { Grid, IconButton, TextField, InputLabel } from '@mui/material'; |
2 | 2 | import DeleteIcon from '@mui/icons-material/Delete'; |
3 | 3 | import { FieldArrayWithId, UseFieldArrayRemove, UseFormRegister, UseFieldArrayAppend } from 'react-hook-form'; |
| 4 | +import { Box } from '@mui/system'; |
| 5 | +import { NERButton } from './NERButton'; |
4 | 6 |
|
5 | 7 | interface ReactHookEditableListProps { |
6 | 8 | name: string; |
7 | 9 | ls: FieldArrayWithId[]; |
8 | 10 | register: UseFormRegister<any>; |
9 | 11 | append: UseFieldArrayAppend<any, any>; |
10 | 12 | remove: UseFieldArrayRemove; |
| 13 | + bulletName?: string; |
11 | 14 | } |
12 | 15 |
|
13 | | -const ReactHookEditableList: React.FC<ReactHookEditableListProps> = ({ name, ls, register, append, remove }) => { |
| 16 | +const ReactHookEditableList: React.FC<ReactHookEditableListProps> = ({ name, ls, bulletName, register, append, remove }) => { |
14 | 17 | return ( |
15 | 18 | <> |
16 | | - {ls.map((_element, i) => { |
17 | | - return ( |
18 | | - <Grid item sx={{ display: 'flex', alignItems: 'center' }}> |
19 | | - <TextField required autoComplete="off" sx={{ width: 9 / 10 }} {...register(`${name}.${i}.detail`)} /> |
20 | | - <IconButton type="button" onClick={() => remove(i)} sx={{ mx: 1, my: 0 }}> |
21 | | - <DeleteIcon /> |
22 | | - </IconButton> |
23 | | - </Grid> |
24 | | - ); |
25 | | - })} |
26 | | - <Button |
| 19 | + <Grid container columnSpacing={{ xs: 4, sm: 2, md: 3 }}> |
| 20 | + {ls.map((_element, i) => { |
| 21 | + return ( |
| 22 | + <Grid item xs={12} md={6} lg={4} key={`${name}-${i}`}> |
| 23 | + <InputLabel sx={{ marginBottom: '5px', marginTop: '7px' }}> |
| 24 | + {bulletName} {i + 1} |
| 25 | + </InputLabel> |
| 26 | + <Box sx={{ display: 'flex', alignItems: 'start', marginBottom: '10px' }}> |
| 27 | + <TextField |
| 28 | + required |
| 29 | + autoComplete="off" |
| 30 | + placeholder={'Enter ' + bulletName + ' . . .'} |
| 31 | + sx={{ width: 12 / 12 }} |
| 32 | + multiline |
| 33 | + maxRows={3} |
| 34 | + {...register(`${name}.${i}.detail`)} |
| 35 | + /> |
| 36 | + <IconButton |
| 37 | + type="button" |
| 38 | + onClick={() => remove(i)} |
| 39 | + sx={{ mx: 1, color: 'red', marginLeft: '15px', marginTop: '3px', borderRadius: '4px', outline: 'solid' }} |
| 40 | + > |
| 41 | + <DeleteIcon /> |
| 42 | + </IconButton> |
| 43 | + </Box> |
| 44 | + </Grid> |
| 45 | + ); |
| 46 | + })} |
| 47 | + </Grid> |
| 48 | + <NERButton |
27 | 49 | variant="contained" |
28 | | - color="success" |
| 50 | + color="primary" |
29 | 51 | onClick={() => append({ bulletId: -1, detail: '' })} |
30 | | - sx={{ my: 2, width: 'max-content' }} |
| 52 | + sx={{ width: 'max-content', marginBottom: '30px', marginTop: '10px' }} |
31 | 53 | > |
32 | | - + Add New Bullet |
33 | | - </Button> |
| 54 | + {bulletName ? `+ Add ${bulletName}` : '+ Add new bullet'} |
| 55 | + </NERButton> |
34 | 56 | </> |
35 | 57 | ); |
36 | 58 | }; |
|
0 commit comments