@@ -2,6 +2,7 @@ import React from 'react';
2
2
import PropTypes from 'prop-types' ;
3
3
import DualListSelectCommon from '@data-driven-forms/common/dual-list-select' ;
4
4
import clsx from 'clsx' ;
5
+ import { createUseStyles } from 'react-jss' ;
5
6
6
7
import { Grid , Row , Column , Button , FormGroup , Search , TooltipIcon } from 'carbon-components-react' ;
7
8
import { CheckmarkFilled16 , ChevronRight32 , ChevronLeft32 , CaretSortDown32 , CaretSortUp32 } from '@carbon/icons-react' ;
@@ -14,7 +15,42 @@ import {
14
15
} from 'carbon-components-react/lib/components/StructuredList/StructuredList' ;
15
16
16
17
import { buildLabel } from '../prepare-props' ;
17
- import './dual-list-select.scss' ;
18
+
19
+ const useStyles = createUseStyles ( {
20
+ dualList : {
21
+ maxHeight : 500 ,
22
+ overflow : 'auto' ,
23
+ display : 'block' ,
24
+ marginBottom : 0
25
+ } ,
26
+ dualListBody : {
27
+ width : '100%' ,
28
+ display : 'inline-table'
29
+ } ,
30
+ buttonWrapper : {
31
+ flexDirection : 'column' ,
32
+ padding : '8px !important' ,
33
+ paddingTop : '8px !important' ,
34
+ button : {
35
+ width : '100%' ,
36
+ maxWidth : '100%' ,
37
+ '@media (max-width: 1055px)' : {
38
+ svg : {
39
+ transform : 'rotate(90deg)'
40
+ }
41
+ }
42
+ } ,
43
+ '& button:not(:last-child)' : {
44
+ marginBottom : 8
45
+ }
46
+ } ,
47
+ toolbar : {
48
+ display : 'flex'
49
+ } ,
50
+ tooltipButton : {
51
+ background : '#c2c1c1 !important'
52
+ }
53
+ } ) ;
18
54
19
55
const EmptyList = ( { message } ) => (
20
56
< StructuredListWrapper >
@@ -30,10 +66,12 @@ EmptyList.propTypes = {
30
66
message : PropTypes . string
31
67
} ;
32
68
33
- const List = ( { options, selectedValues, handleOptionsClick, noTitle, ListProps, BodyProps } ) =>
34
- options . length > 0 ? (
35
- < StructuredListWrapper selection { ...ListProps } className = { clsx ( 'ddorg__carbon-dual-list' , ListProps . className ) } >
36
- < StructuredListBody { ...BodyProps } className = { clsx ( 'ddorg__carbon-dual-list-body' , BodyProps . className ) } >
69
+ const List = ( { options, selectedValues, handleOptionsClick, noTitle, ListProps, BodyProps } ) => {
70
+ const { dualList, dualListBody } = useStyles ( ) ;
71
+
72
+ return options . length > 0 ? (
73
+ < StructuredListWrapper selection { ...ListProps } className = { clsx ( dualList , ListProps . className ) } >
74
+ < StructuredListBody { ...BodyProps } className = { clsx ( dualListBody , BodyProps . className ) } >
37
75
{ options . map ( ( { value, label, ListRowProps, ListCellProps, GridProps, RowProps, LabelProps, CheckmarkProps } ) => (
38
76
< StructuredListRow key = { value } { ...ListRowProps } onClick = { ( e ) => handleOptionsClick ( { ...e , ctrlKey : true } , value ) } >
39
77
< StructuredListCell { ...ListCellProps } >
@@ -55,6 +93,7 @@ const List = ({ options, selectedValues, handleOptionsClick, noTitle, ListProps,
55
93
) : (
56
94
< EmptyList message = { noTitle } />
57
95
) ;
96
+ } ;
58
97
59
98
List . propTypes = {
60
99
options : PropTypes . array ,
@@ -65,19 +104,18 @@ List.propTypes = {
65
104
BodyProps : PropTypes . object
66
105
} ;
67
106
68
- const Toolbar = ( { sortTitle, onFilter, onSort, sortDirection, placeholder, ToolbarProps, SearchProps, SortProps } ) => (
69
- < div { ...ToolbarProps } className = { clsx ( 'ddorg__carbon-dual-list-toolbar' , ToolbarProps . className ) } >
70
- < Search onChange = { ( e ) => onFilter ( e . target . value ) } labelText = "" placeHolderText = { placeholder } { ...SearchProps } />
71
- < TooltipIcon
72
- onClick = { onSort }
73
- tooltipText = { sortTitle }
74
- { ...SortProps }
75
- className = { clsx ( 'ddorg__carbon-dual-list-tooltipbutton' , SortProps . className ) }
76
- >
77
- { sortDirection ? < CaretSortDown32 /> : < CaretSortUp32 /> }
78
- </ TooltipIcon >
79
- </ div >
80
- ) ;
107
+ const Toolbar = ( { sortTitle, onFilter, onSort, sortDirection, placeholder, ToolbarProps, SearchProps, SortProps } ) => {
108
+ const { toolbar, tooltipButton } = useStyles ( ) ;
109
+
110
+ return (
111
+ < div { ...ToolbarProps } className = { clsx ( toolbar , ToolbarProps . className ) } >
112
+ < Search onChange = { ( e ) => onFilter ( e . target . value ) } labelText = "" placeHolderText = { placeholder } { ...SearchProps } />
113
+ < TooltipIcon onClick = { onSort } tooltipText = { sortTitle } { ...SortProps } className = { clsx ( tooltipButton , SortProps . className ) } >
114
+ { sortDirection ? < CaretSortDown32 /> : < CaretSortUp32 /> }
115
+ </ TooltipIcon >
116
+ </ div >
117
+ ) ;
118
+ } ;
81
119
82
120
Toolbar . propTypes = {
83
121
sortTitle : PropTypes . string ,
@@ -146,82 +184,86 @@ const DualListSelectInner = ({
146
184
LeftBodyProps,
147
185
RightListProps,
148
186
RightBodyProps
149
- } ) => (
150
- < FormGroup legendText = { buildLabel ( label || '' , isRequired ) } { ...FormGroupProps } >
151
- < Grid { ...GridProps } >
152
- < Row condensed { ...RowProps } >
153
- < Column sm = { 4 } md = { 8 } lg = { 5 } { ...OptionsColumnProps } >
154
- { React . createElement ( LeftTitleElement , LeftTitleProps , leftTitle ) }
155
- < Toolbar
156
- onFilter = { filterOptions }
157
- placeholder = { filterOptionsTitle }
158
- sortDirection = { state . sortLeftDesc }
159
- onSort = { sortOptions }
160
- sortTitle = { sortOptionsTitle }
161
- ToolbarProps = { LeftToolbarProps }
162
- SearchProps = { LeftSearchProps }
163
- SortProps = { LeftSortProps }
164
- />
165
- < List
166
- ListProps = { LeftListProps }
167
- BodyProps = { LeftBodyProps }
168
- options = { leftValues }
169
- selectedValues = { state . selectedLeftValues }
170
- handleOptionsClick = { handleOptionsClick }
171
- noTitle = { state . filterOptions ? filterOptionsText : noOptionsTitle }
172
- />
173
- </ Column >
174
- < Column sm = { 4 } md = { 8 } lg = { 2 } { ...ButtonColumnProps } className = { clsx ( 'ddorg__carbon-dual-list-button-wrapper' , ButtonColumnProps . className ) } >
175
- < Button
176
- id = "move-right"
177
- renderIcon = { ChevronRight32 }
178
- onClick = { handleMoveRight }
179
- disabled = { isEmpty ( state . selectedLeftValues ) }
180
- { ...AddButtonProps }
181
- >
182
- { moveRightTitle }
183
- </ Button >
184
- < Button id = "move-all-right" onClick = { handleClearLeftValues } disabled = { isEmpty ( leftValues ) } { ...AddAllButtonProps } >
185
- { moveAllRightTitle }
186
- </ Button >
187
- < Button id = "move-all-left" onClick = { handleClearRightValues } disabled = { isEmpty ( rightValues ) } { ...RemoveAllButtonProps } >
188
- { moveAllLeftTitle }
189
- </ Button >
190
- < Button
191
- id = "move-left"
192
- renderIcon = { ChevronLeft32 }
193
- onClick = { handleMoveLeft }
194
- disabled = { isEmpty ( state . selectedRightValues ) }
195
- { ...RemoveButtonProps }
196
- >
197
- { moveLeftTitle }
198
- </ Button >
199
- </ Column >
200
- < Column sm = { 4 } md = { 8 } lg = { 5 } { ...ValuesColumnProps } >
201
- { React . createElement ( RightTitleElement , RightTitleProps , rightTitle ) }
202
- < Toolbar
203
- onFilter = { filterValues }
204
- placeholder = { filterValuesTitle }
205
- sortDirection = { state . sortRightDesc }
206
- onSort = { sortValues }
207
- sortTitle = { sortValuesTitle }
208
- ToolbarProps = { RightToolbarProps }
209
- SearchProps = { RightSearchProps }
210
- SortProps = { RightSortProps }
211
- />
212
- < List
213
- ListProps = { RightListProps }
214
- BodyProps = { RightBodyProps }
215
- options = { rightValues }
216
- selectedValues = { state . selectedRightValues }
217
- handleOptionsClick = { handleValuesClick }
218
- noTitle = { state . filterValue ? filterValueText : noValueTitle }
219
- />
220
- </ Column >
221
- </ Row >
222
- </ Grid >
223
- </ FormGroup >
224
- ) ;
187
+ } ) => {
188
+ const { buttonWrapper } = useStyles ( ) ;
189
+
190
+ return (
191
+ < FormGroup legendText = { buildLabel ( label || '' , isRequired ) } { ...FormGroupProps } >
192
+ < Grid { ...GridProps } >
193
+ < Row condensed { ...RowProps } >
194
+ < Column sm = { 4 } md = { 8 } lg = { 5 } { ...OptionsColumnProps } >
195
+ { React . createElement ( LeftTitleElement , LeftTitleProps , leftTitle ) }
196
+ < Toolbar
197
+ onFilter = { filterOptions }
198
+ placeholder = { filterOptionsTitle }
199
+ sortDirection = { state . sortLeftDesc }
200
+ onSort = { sortOptions }
201
+ sortTitle = { sortOptionsTitle }
202
+ ToolbarProps = { LeftToolbarProps }
203
+ SearchProps = { LeftSearchProps }
204
+ SortProps = { LeftSortProps }
205
+ />
206
+ < List
207
+ ListProps = { LeftListProps }
208
+ BodyProps = { LeftBodyProps }
209
+ options = { leftValues }
210
+ selectedValues = { state . selectedLeftValues }
211
+ handleOptionsClick = { handleOptionsClick }
212
+ noTitle = { state . filterOptions ? filterOptionsText : noOptionsTitle }
213
+ />
214
+ </ Column >
215
+ < Column sm = { 4 } md = { 8 } lg = { 2 } { ...ButtonColumnProps } className = { clsx ( buttonWrapper , ButtonColumnProps . className ) } >
216
+ < Button
217
+ id = "move-right"
218
+ renderIcon = { ChevronRight32 }
219
+ onClick = { handleMoveRight }
220
+ disabled = { isEmpty ( state . selectedLeftValues ) }
221
+ { ...AddButtonProps }
222
+ >
223
+ { moveRightTitle }
224
+ </ Button >
225
+ < Button id = "move-all-right" onClick = { handleClearLeftValues } disabled = { isEmpty ( leftValues ) } { ...AddAllButtonProps } >
226
+ { moveAllRightTitle }
227
+ </ Button >
228
+ < Button id = "move-all-left" onClick = { handleClearRightValues } disabled = { isEmpty ( rightValues ) } { ...RemoveAllButtonProps } >
229
+ { moveAllLeftTitle }
230
+ </ Button >
231
+ < Button
232
+ id = "move-left"
233
+ renderIcon = { ChevronLeft32 }
234
+ onClick = { handleMoveLeft }
235
+ disabled = { isEmpty ( state . selectedRightValues ) }
236
+ { ...RemoveButtonProps }
237
+ >
238
+ { moveLeftTitle }
239
+ </ Button >
240
+ </ Column >
241
+ < Column sm = { 4 } md = { 8 } lg = { 5 } { ...ValuesColumnProps } >
242
+ { React . createElement ( RightTitleElement , RightTitleProps , rightTitle ) }
243
+ < Toolbar
244
+ onFilter = { filterValues }
245
+ placeholder = { filterValuesTitle }
246
+ sortDirection = { state . sortRightDesc }
247
+ onSort = { sortValues }
248
+ sortTitle = { sortValuesTitle }
249
+ ToolbarProps = { RightToolbarProps }
250
+ SearchProps = { RightSearchProps }
251
+ SortProps = { RightSortProps }
252
+ />
253
+ < List
254
+ ListProps = { RightListProps }
255
+ BodyProps = { RightBodyProps }
256
+ options = { rightValues }
257
+ selectedValues = { state . selectedRightValues }
258
+ handleOptionsClick = { handleValuesClick }
259
+ noTitle = { state . filterValue ? filterValueText : noValueTitle }
260
+ />
261
+ </ Column >
262
+ </ Row >
263
+ </ Grid >
264
+ </ FormGroup >
265
+ ) ;
266
+ } ;
225
267
226
268
DualListSelectInner . propTypes = {
227
269
leftValues : PropTypes . array ,
0 commit comments