@@ -49,7 +49,7 @@ export const usePicker = <T extends { id: string; name: string }>({
49
49
} ;
50
50
} ;
51
51
52
- export interface Props < T > {
52
+ export interface CheckboxListProps < T > {
53
53
title : string ;
54
54
items : T [ ] ;
55
55
selected : Array < string > ;
@@ -58,9 +58,31 @@ export interface Props<T> {
58
58
toggle ?: ReactNode ;
59
59
onViewMore ?: ( ) => void ;
60
60
numSelected : number ;
61
+ variant ?: "default" | "emphasize" ;
61
62
}
62
63
63
- const PickerCard = < T extends { id : string ; name : string } > ( {
64
+ const PickerCardContainer = ( {
65
+ title,
66
+ children,
67
+ } : {
68
+ title : string ;
69
+ children : ReactNode ;
70
+ } ) => (
71
+ < Box
72
+ p = { 4 }
73
+ display = "flex"
74
+ alignItems = "flex-start"
75
+ gap = "4px"
76
+ borderRadius = "4px"
77
+ boxShadow = "0px 1px 2px 0px rgba(0, 0, 0, 0.06), 0px 1px 3px 0px rgba(0, 0, 0, 0.1)"
78
+ fontSize = "sm"
79
+ data-testid = { `picker-card-${ title } ` }
80
+ >
81
+ { children }
82
+ </ Box >
83
+ ) ;
84
+
85
+ export const PickerCheckboxList = < T extends { id : string ; name : string } > ( {
64
86
title,
65
87
items,
66
88
selected,
@@ -69,7 +91,8 @@ const PickerCard = <T extends { id: string; name: string }>({
69
91
toggle,
70
92
onViewMore,
71
93
numSelected,
72
- } : Props < T > ) => {
94
+ variant = "default" ,
95
+ } : CheckboxListProps < T > ) => {
73
96
const itemsToShow = onViewMore ? items . slice ( 0 , NUM_TO_SHOW ) : items ;
74
97
75
98
const { allSelected, someSelected, handleToggleAll, handleToggleSelection } =
@@ -80,77 +103,74 @@ const PickerCard = <T extends { id: string; name: string }>({
80
103
} ) ;
81
104
82
105
return (
83
- < Box
84
- p = { 4 }
85
- display = "flex"
86
- alignItems = "flex-start"
87
- gap = "4px"
88
- borderRadius = "4px"
89
- boxShadow = "0px 1px 2px 0px rgba(0, 0, 0, 0.06), 0px 1px 3px 0px rgba(0, 0, 0, 0.1)"
90
- fontSize = "sm"
91
- data-testid = { `picker-card-${ title } ` }
92
- >
93
- < VStack alignItems = "flex-start" spacing = { 3 } width = "100%" height = "100%" >
94
- < Flex justifyContent = "space-between" width = "100%" >
95
- < Checkbox
96
- fontSize = "md"
97
- textTransform = "capitalize"
98
- fontWeight = "semibold"
99
- isChecked = { allSelected }
100
- size = "md"
101
- mr = "2"
102
- onChange = { handleToggleAll }
103
- colorScheme = "complimentary"
104
- data-testid = "select-all"
105
- isIndeterminate = { ! allSelected && someSelected }
106
- >
107
- { title }
108
- </ Checkbox >
106
+ < VStack alignItems = "flex-start" spacing = { 3 } width = "100%" height = "100%" >
107
+ < Flex justifyContent = "space-between" width = "100%" >
108
+ < Checkbox
109
+ fontSize = "md"
110
+ textTransform = { variant === "emphasize" ? "capitalize" : undefined }
111
+ fontWeight = { variant === "emphasize" ? "semibold" : "auto" }
112
+ isChecked = { allSelected }
113
+ size = "md"
114
+ mr = "2"
115
+ onChange = { handleToggleAll }
116
+ colorScheme = "complimentary"
117
+ data-testid = "select-all"
118
+ isIndeterminate = { ! allSelected && someSelected }
119
+ >
120
+ { title }
121
+ </ Checkbox >
109
122
110
- { toggle ?? null }
111
- </ Flex >
112
- { numSelected > 0 ? (
113
- < Badge
114
- colorScheme = "purple"
115
- variant = "solid"
116
- width = "fit-content"
117
- data-testid = "num-selected-badge"
118
- >
119
- { numSelected } selected
120
- </ Badge >
121
- ) : null }
122
- < VStack paddingLeft = "6" fontSize = "sm" alignItems = "start" spacing = "2" >
123
- < CheckboxGroup colorScheme = "complimentary" >
124
- { itemsToShow . map ( ( item ) => (
125
- < Flex key = { item . id } alignItems = "center" gap = "8px" >
126
- < Checkbox
127
- key = { item . id }
128
- isChecked = { selected . includes ( item . id ) }
129
- isIndeterminate = { indeterminate . includes ( item . id ) }
130
- size = "md"
131
- fontWeight = "500"
132
- onChange = { ( ) => handleToggleSelection ( item . id ) }
133
- data-testid = { `${ item . name } -checkbox` }
134
- >
135
- { item . name }
136
- </ Checkbox >
137
- </ Flex >
138
- ) ) }
139
- </ CheckboxGroup >
140
- </ VStack >
141
- { onViewMore ? (
142
- < Button
143
- size = "xs"
144
- variant = "ghost"
145
- onClick = { onViewMore }
146
- data-testid = "view-more-btn"
147
- >
148
- View more
149
- </ Button >
150
- ) : null }
123
+ { toggle ?? null }
124
+ </ Flex >
125
+ { numSelected > 0 ? (
126
+ < Badge
127
+ colorScheme = "purple"
128
+ variant = "solid"
129
+ width = "fit-content"
130
+ data-testid = "num-selected-badge"
131
+ >
132
+ { numSelected } selected
133
+ </ Badge >
134
+ ) : null }
135
+ < VStack paddingLeft = "6" fontSize = "sm" alignItems = "start" spacing = "2" >
136
+ < CheckboxGroup colorScheme = "complimentary" >
137
+ { itemsToShow . map ( ( item ) => (
138
+ < Flex key = { item . id } alignItems = "center" gap = "8px" >
139
+ < Checkbox
140
+ key = { item . id }
141
+ isChecked = { selected . includes ( item . id ) }
142
+ isIndeterminate = { indeterminate . includes ( item . id ) }
143
+ size = "md"
144
+ fontWeight = { variant === "emphasize" ? "500" : "auto" }
145
+ onChange = { ( ) => handleToggleSelection ( item . id ) }
146
+ data-testid = { `${ item . name } -checkbox` }
147
+ >
148
+ { item . name }
149
+ </ Checkbox >
150
+ </ Flex >
151
+ ) ) }
152
+ </ CheckboxGroup >
151
153
</ VStack >
152
- </ Box >
154
+ { onViewMore ? (
155
+ < Button
156
+ size = "xs"
157
+ variant = "ghost"
158
+ onClick = { onViewMore }
159
+ data-testid = "view-more-btn"
160
+ >
161
+ View more
162
+ </ Button >
163
+ ) : null }
164
+ </ VStack >
153
165
) ;
154
166
} ;
155
167
168
+ const PickerCard = < T extends { id : string ; name : string } > ( {
169
+ ...props
170
+ } : CheckboxListProps < T > ) => (
171
+ < PickerCardContainer title = { props . title } >
172
+ < PickerCheckboxList { ...props } variant = "emphasize" />
173
+ </ PickerCardContainer >
174
+ ) ;
175
+
156
176
export default PickerCard ;
0 commit comments