11import { Grid , Button , IconButton , TextField , Stack , InputLabel , Box } from '@mui/material' ;
22import DeleteIcon from '@mui/icons-material/Delete' ;
33import { FieldArrayWithId , UseFieldArrayRemove , UseFormRegister , UseFieldArrayAppend } from 'react-hook-form' ;
4+ import { NERButton } from './NERButton' ;
45
56interface ReactHookEditableListProps {
67 name : string ;
@@ -20,54 +21,44 @@ const ReactHookEditableList: React.FC<ReactHookEditableListProps> = ({
2021 bulletName = 'Item'
2122} ) => {
2223 return (
23- < >
24- < Box >
25- < Grid container spacing = { 2 } >
26- {
27- //</Grid><Grid container sx={{ display: 'flex', flexDirection: 'row', flexWrap: 'wrap' }} spacing={2}>
28- }
29- { ls . map ( ( _element , i ) => {
30- return (
31- //Grid container with direction "row", and then each item inside is wrapped in a grid-element
32- //xs argument: number out of 12, takes up that amount of space
33- < Grid item sx = { { alignItems : 'center' } } xs = { 12 } md = { 4 } >
34- < InputLabel > { bulletName + ' ' + ( i + 1 ) } </ InputLabel >
35- < Box sx = { { display : 'flex' } } >
36- < TextField
37- required
38- multiline
39- placeholder = { 'Enter a ' + bulletName + '...' }
40- inputProps = { { style : { fontSize : 14 } } }
41- minRows = { 2 }
42- autoComplete = "off"
43- sx = { { width : 12 / 12 , padding : 0 } }
44- { ...register ( `${ name } .${ i } .detail` ) }
45- />
46- < Stack spacing = { 0 } >
47- < IconButton
48- type = "button"
49- onClick = { ( ) => remove ( i ) }
50- sx = { { mx : 1 , my : 0 , color : 'red' , marginLeft : '15px' , borderRadius : '4px' , outline : 'solid' } }
51- >
52- < DeleteIcon />
53- </ IconButton >
54- < Box > </ Box >
55- </ Stack >
56- </ Box >
57- </ Grid >
58- ) ;
59- } ) }
60- </ Grid >
61- < Button
62- variant = "contained"
63- color = "primary"
64- onClick = { ( ) => append ( { bulletId : - 1 , detail : '' } ) }
65- sx = { { my : 2 , width : 'max-content' , textTransform : 'none' } }
66- >
67- { 'Add ' + bulletName }
68- </ Button >
69- </ Box >
70- </ >
24+ < Box >
25+ < Grid container spacing = { 2 } >
26+ { ls . map ( ( _element , i ) => {
27+ return (
28+ < Grid item sx = { { alignItems : 'center' } } xs = { 12 } md = { 4 } >
29+ < InputLabel > { bulletName + ' ' + ( i + 1 ) } </ InputLabel >
30+ < Box sx = { { display : 'flex' , alignItems : 'start' } } >
31+ < TextField
32+ required
33+ multiline
34+ placeholder = { 'Enter a ' + bulletName + '...' }
35+ inputProps = { { style : { fontSize : 14 } } }
36+ minRows = { 2 }
37+ autoComplete = "off"
38+ sx = { { width : 12 / 12 , padding : 0 } }
39+ { ...register ( `${ name } .${ i } .detail` ) }
40+ />
41+ < IconButton
42+ type = "button"
43+ onClick = { ( ) => remove ( i ) }
44+ sx = { { mx : 1 , color : 'red' , marginLeft : '15px' , borderRadius : '4px' , outline : 'solid' } }
45+ >
46+ < DeleteIcon />
47+ </ IconButton >
48+ </ Box >
49+ </ Grid >
50+ ) ;
51+ } ) }
52+ </ Grid >
53+ < NERButton
54+ variant = "contained"
55+ color = "primary"
56+ onClick = { ( ) => append ( { bulletId : - 1 , detail : '' } ) }
57+ sx = { { my : 2 , width : 'max-content' , textTransform : 'none' } }
58+ >
59+ { 'Add ' + bulletName }
60+ </ NERButton >
61+ </ Box >
7162 ) ;
7263} ;
7364
0 commit comments