1
1
import React from 'react' ;
2
+ import { styled } from '@mui/material/styles' ;
2
3
import PropTypes from 'prop-types' ;
3
4
import clsx from 'clsx' ;
4
5
@@ -23,37 +24,53 @@ import {
23
24
24
25
import SortIcon from '@mui/icons-material/ArrowUpward' ;
25
26
26
- import makeStyles from '@mui/styles/makeStyles' ;
27
-
28
27
import DualListSelectCommon from '@data-driven-forms/common/dual-list-select' ;
29
28
30
29
import FormFieldGrid from '../form-field-grid/form-field-grid' ;
31
30
import { validationError } from '../validation-error/validation-error' ;
32
31
33
- const useStyles = makeStyles ( ( theme ) => ( {
34
- allToLeftIcon : {
32
+ const PREFIX = 'DualListSelectWrapper' ;
33
+
34
+ const classes = {
35
+ allToLeftIcon : `${ PREFIX } -allToLeftIcon` ,
36
+ upsideDown : `${ PREFIX } -upsideDown` ,
37
+ list : `${ PREFIX } -list` ,
38
+ button : `${ PREFIX } -button` ,
39
+ buttonsGrid : `${ PREFIX } -buttonsGrid` ,
40
+ filter : `${ PREFIX } -filter` ,
41
+ toolbar : `${ PREFIX } -toolbar` ,
42
+ } ;
43
+
44
+ const StyledDualListSelect = styled ( FormFieldGrid ) ( ( { theme } ) => ( {
45
+ [ `& .${ classes . allToLeftIcon } ` ] : {
35
46
transform : 'scaleX(-1)' ,
36
47
} ,
37
- upsideDown : {
48
+
49
+ [ `& .${ classes . upsideDown } ` ] : {
38
50
transform : 'scaleY(-1)' ,
39
51
} ,
40
- list : {
52
+
53
+ [ `& .${ classes . list } ` ] : {
41
54
height : 300 ,
42
55
overflow : 'auto' ,
43
56
} ,
44
- button : {
57
+
58
+ [ `& .${ classes . button } ` ] : {
45
59
display : 'flex' ,
46
60
justifyContent : 'center' ,
47
61
margin : theme . spacing ( 0.5 , 0 ) ,
48
62
} ,
49
- buttonsGrid : {
63
+
64
+ [ `& .${ classes . buttonsGrid } ` ] : {
50
65
height : '100%' ,
51
66
alignContent : 'center' ,
52
67
} ,
53
- filter : {
68
+
69
+ [ `& .${ classes . filter } ` ] : {
54
70
width : '100%' ,
55
71
} ,
56
- toolbar : {
72
+
73
+ [ `& .${ classes . toolbar } ` ] : {
57
74
paddingLeft : 16 ,
58
75
paddingRight : 16 ,
59
76
} ,
@@ -74,60 +91,56 @@ const ListInternal = ({
74
91
checkboxVariant,
75
92
PaperProps,
76
93
LeftPaperProps,
77
- } ) => {
78
- const classes = useStyles ( ) ;
79
-
80
- return (
81
- < Paper { ...PaperProps } { ...LeftPaperProps } className = { clsx ( PaperProps && PaperProps . className , LeftPaperProps && LeftPaperProps . className ) } >
82
- < List component = "div" role = "list" dense { ...ListProps } className = { clsx ( classes . list , ListProps . className ) } >
83
- { value . length < 1 && (
84
- < ListItem button disabled { ...ListItemProps } >
85
- < ListItemText primary = { filterValue ? filterValueText : noOptionsTitle } />
86
- </ ListItem >
94
+ } ) => (
95
+ < Paper { ...PaperProps } { ...LeftPaperProps } className = { clsx ( PaperProps && PaperProps . className , LeftPaperProps && LeftPaperProps . className ) } >
96
+ < List component = "div" role = "list" dense { ...ListProps } className = { clsx ( classes . list , ListProps . className ) } >
97
+ { value . length < 1 && (
98
+ < ListItem button disabled { ...ListItemProps } >
99
+ < ListItemText primary = { filterValue ? filterValueText : noOptionsTitle } />
100
+ </ ListItem >
101
+ ) }
102
+ { value . length > 0 &&
103
+ value . map (
104
+ ( {
105
+ value,
106
+ label,
107
+ icon,
108
+ isCheckbox,
109
+ secondaryActions,
110
+ ListItemProps : ListItemPropsItem ,
111
+ ListItemIconProps : ListItemIconPropsItem ,
112
+ ListItemTextProps : ListItemTextPropsItem ,
113
+ ListItemSecondaryActionProps : ListItemSecondaryActionPropsItem ,
114
+ } ) => (
115
+ < ListItem
116
+ button
117
+ key = { value }
118
+ selected = { selectedValues . includes ( value ) }
119
+ onClick = { ( e ) => optionClick ( isCheckbox || checkboxVariant ? { ...e , ctrlKey : true } : e , value ) }
120
+ { ...ListItemProps }
121
+ { ...ListItemPropsItem }
122
+ >
123
+ { ( icon || isCheckbox || checkboxVariant ) && (
124
+ < ListItemIcon { ...ListItemIconProps } { ...ListItemIconPropsItem } >
125
+ { isCheckbox || checkboxVariant ? (
126
+ < Checkbox edge = "start" checked = { selectedValues . includes ( value ) } tabIndex = { - 1 } disableRipple />
127
+ ) : (
128
+ icon
129
+ ) }
130
+ </ ListItemIcon >
131
+ ) }
132
+ < ListItemText primary = { label } { ...ListItemTextProps } { ...ListItemTextPropsItem } />
133
+ { secondaryActions && (
134
+ < ListItemSecondaryAction { ...ListItemSecondaryActionProps } { ...ListItemSecondaryActionPropsItem } >
135
+ { secondaryActions }
136
+ </ ListItemSecondaryAction >
137
+ ) }
138
+ </ ListItem >
139
+ )
87
140
) }
88
- { value . length > 0 &&
89
- value . map (
90
- ( {
91
- value,
92
- label,
93
- icon,
94
- isCheckbox,
95
- secondaryActions,
96
- ListItemProps : ListItemPropsItem ,
97
- ListItemIconProps : ListItemIconPropsItem ,
98
- ListItemTextProps : ListItemTextPropsItem ,
99
- ListItemSecondaryActionProps : ListItemSecondaryActionPropsItem ,
100
- } ) => (
101
- < ListItem
102
- button
103
- key = { value }
104
- selected = { selectedValues . includes ( value ) }
105
- onClick = { ( e ) => optionClick ( isCheckbox || checkboxVariant ? { ...e , ctrlKey : true } : e , value ) }
106
- { ...ListItemProps }
107
- { ...ListItemPropsItem }
108
- >
109
- { ( icon || isCheckbox || checkboxVariant ) && (
110
- < ListItemIcon { ...ListItemIconProps } { ...ListItemIconPropsItem } >
111
- { isCheckbox || checkboxVariant ? (
112
- < Checkbox edge = "start" checked = { selectedValues . includes ( value ) } tabIndex = { - 1 } disableRipple />
113
- ) : (
114
- icon
115
- ) }
116
- </ ListItemIcon >
117
- ) }
118
- < ListItemText primary = { label } { ...ListItemTextProps } { ...ListItemTextPropsItem } />
119
- { secondaryActions && (
120
- < ListItemSecondaryAction { ...ListItemSecondaryActionProps } { ...ListItemSecondaryActionPropsItem } >
121
- { secondaryActions }
122
- </ ListItemSecondaryAction >
123
- ) }
124
- </ ListItem >
125
- )
126
- ) }
127
- </ List >
128
- </ Paper >
129
- ) ;
130
- } ;
141
+ </ List >
142
+ </ Paper >
143
+ ) ;
131
144
132
145
ListInternal . propTypes = {
133
146
value : PropTypes . arrayOf (
@@ -170,49 +183,41 @@ const ToolbarInternal = ({
170
183
LeftSortIconButtonProps,
171
184
filter,
172
185
sortDesc,
173
- } ) => {
174
- const classes = useStyles ( ) ;
175
-
176
- return (
177
- < Toolbar
178
- variant = "dense"
179
- { ...ToolbarProps }
180
- { ...LeftToolbarProps }
181
- className = { clsx ( classes . toolbar , ToolbarProps && ToolbarProps . className , LeftToolbarProps && LeftToolbarProps . className ) }
186
+ } ) => (
187
+ < Toolbar
188
+ variant = "dense"
189
+ { ...ToolbarProps }
190
+ { ...LeftToolbarProps }
191
+ className = { clsx ( classes . toolbar , ToolbarProps && ToolbarProps . className , LeftToolbarProps && LeftToolbarProps . className ) }
192
+ >
193
+ < TextField
194
+ edge = "start"
195
+ id = "options-search"
196
+ label = { filterOptionsTitle }
197
+ onChange = { ( { target : { value } } ) => filterOptions ( value ) }
198
+ value = { filter }
199
+ type = "search"
200
+ { ...FilterFieldProps }
201
+ { ...LeftFilterFieldProps }
202
+ className = { clsx ( classes . filter , FilterFieldProps && FilterFieldProps . className , LeftFilterFieldProps && LeftFilterFieldProps . className ) }
203
+ />
204
+ < IconButton
205
+ aria-label = "sort options"
206
+ edge = "end"
207
+ onClick = { sortOptions }
208
+ color = "inherit"
209
+ { ...SortIconButtonProps }
210
+ { ...LeftSortIconButtonProps }
211
+ size = "large"
182
212
>
183
- < TextField
184
- edge = "start"
185
- id = "options-search"
186
- label = { filterOptionsTitle }
187
- onChange = { ( { target : { value } } ) => filterOptions ( value ) }
188
- value = { filter }
189
- type = "search"
190
- { ...FilterFieldProps }
191
- { ...LeftFilterFieldProps }
192
- className = { clsx ( classes . filter , FilterFieldProps && FilterFieldProps . className , LeftFilterFieldProps && LeftFilterFieldProps . className ) }
213
+ < SortIcon
214
+ { ...SortIconProps }
215
+ { ...LeftSortIconProps }
216
+ className = { clsx ( ! sortDesc && classes . upsideDown , SortIconProps && SortIconProps . className , LeftSortIconProps && LeftSortIconProps . className ) }
193
217
/>
194
- < IconButton
195
- aria-label = "sort options"
196
- edge = "end"
197
- onClick = { sortOptions }
198
- color = "inherit"
199
- { ...SortIconButtonProps }
200
- { ...LeftSortIconButtonProps }
201
- size = "large"
202
- >
203
- < SortIcon
204
- { ...SortIconProps }
205
- { ...LeftSortIconProps }
206
- className = { clsx (
207
- ! sortDesc && classes . upsideDown ,
208
- SortIconProps && SortIconProps . className ,
209
- LeftSortIconProps && LeftSortIconProps . className
210
- ) }
211
- />
212
- </ IconButton >
213
- </ Toolbar >
214
- ) ;
215
- } ;
218
+ </ IconButton >
219
+ </ Toolbar >
220
+ ) ;
216
221
217
222
ToolbarInternal . propTypes = {
218
223
ToolbarProps : PropTypes . object ,
@@ -322,12 +327,11 @@ const DualListSelect = ({
322
327
LeftPaperProps,
323
328
RightPaperProps,
324
329
} ) => {
325
- const classes = useStyles ( ) ;
326
330
const invalid = validationError ( meta , validateOnMount ) ;
327
331
const text = invalid || ( ( meta . touched || validateOnMount ) && meta . warning ) || helperText || description ;
328
332
329
333
return (
330
- < FormFieldGrid { ...FormFieldGridProps } >
334
+ < StyledDualListSelect { ...FormFieldGridProps } >
331
335
< FormControl fullWidth required = { isRequired } error = { ! ! invalid } component = "fieldset" { ...FormControlProps } >
332
336
< FormLabel component = "legend" { ...FormLabelProps } >
333
337
{ label }
@@ -508,7 +512,7 @@ const DualListSelect = ({
508
512
</ Grid >
509
513
{ text && < FormHelperText { ...FormHelperTextProps } > { text } </ FormHelperText > }
510
514
</ FormControl >
511
- </ FormFieldGrid >
515
+ </ StyledDualListSelect >
512
516
) ;
513
517
} ;
514
518
0 commit comments