@@ -7,6 +7,37 @@ import {ItemInput} from './List'
7
7
import styled from 'styled-components'
8
8
import { StyledHeader } from './Header'
9
9
import { StyledDivider } from './Divider'
10
+ import { useColorSchemeVar , useTheme } from '../ThemeProvider'
11
+
12
+ /**
13
+ * These colors are not yet in our default theme. Need to remove this once they are added.
14
+ */
15
+ const customItemThemes = {
16
+ default : {
17
+ hover : {
18
+ light : 'rgba(46, 77, 108, 0.06)' ,
19
+ dark : 'rgba(201, 206, 212, 0.12)' ,
20
+ dark_dimmed : 'rgba(201, 206, 212, 0.12)'
21
+ } ,
22
+ focus : {
23
+ light : 'rgba(54, 77, 100, 0.16)' ,
24
+ dark : 'rgba(201, 206, 212, 0.24)' ,
25
+ dark_dimmed : 'rgba(201, 206, 212, 0.24)'
26
+ }
27
+ } ,
28
+ danger : {
29
+ hover : {
30
+ light : 'rgba(234, 74, 90, 0.08)' ,
31
+ dark : 'rgba(248, 81, 73, 0.16)' ,
32
+ dark_dimmed : 'rgba(248, 81, 73, 0.16)'
33
+ } ,
34
+ focus : {
35
+ light : 'rgba(234, 74, 90, 0.14)' ,
36
+ dark : 'rgba(248, 81, 73, 0.24)' ,
37
+ dark_dimmed : 'rgba(248, 81, 73, 0.24)'
38
+ }
39
+ }
40
+ } as const
10
41
11
42
/**
12
43
* Contract for props passed to the `Item` component.
@@ -95,7 +126,6 @@ const getItemVariant = (variant = 'default', disabled?: boolean) => {
95
126
color : get ( 'colors.text.disabled' ) ,
96
127
iconColor : get ( 'colors.text.disabled' ) ,
97
128
annotationColor : get ( 'colors.text.disabled' ) ,
98
- hoverBackground : 'inherit' ,
99
129
hoverCursor : 'default'
100
130
}
101
131
}
@@ -106,15 +136,13 @@ const getItemVariant = (variant = 'default', disabled?: boolean) => {
106
136
color : get ( 'colors.text.danger' ) ,
107
137
iconColor : get ( 'colors.icon.danger' ) ,
108
138
annotationColor : get ( 'colors.text.disabled' ) ,
109
- hoverBackground : get ( 'colors.bg.danger' ) ,
110
139
hoverCursor : 'pointer'
111
140
}
112
141
default :
113
142
return {
114
143
color : 'inherit' ,
115
- iconColor : get ( 'colors.text.disabled' ) ,
116
- annotationColor : get ( 'colors.text.disabled' ) ,
117
- hoverBackground : get ( 'colors.selectMenu.tapHighlight' ) ,
144
+ iconColor : get ( 'colors.text.secondary' ) ,
145
+ annotationColor : get ( 'colors.text.secondary' ) ,
118
146
hoverCursor : 'pointer'
119
147
}
120
148
}
@@ -125,7 +153,13 @@ const StyledItemContent = styled.div`
125
153
`
126
154
127
155
const StyledItem = styled . div <
128
- { variant : ItemProps [ 'variant' ] ; showDivider : ItemProps [ 'showDivider' ] ; item ?: ItemInput } & SxProp
156
+ {
157
+ variant : ItemProps [ 'variant' ]
158
+ showDivider : ItemProps [ 'showDivider' ]
159
+ item ?: ItemInput
160
+ hoverBackground : string
161
+ focusBackground : string
162
+ } & SxProp
129
163
> `
130
164
/* 6px vertical padding + 20px line height = 32px total height
131
165
*
@@ -139,7 +173,7 @@ const StyledItem = styled.div<
139
173
140
174
@media (hover: hover) and (pointer: fine) {
141
175
:hover {
142
- background: ${ ( { variant , item } ) => getItemVariant ( variant , item ?. disabled ) . hoverBackground } ;
176
+ background: ${ ( { hoverBackground } ) => hoverBackground } ;
143
177
cursor: ${ ( { variant, item} ) => getItemVariant ( variant , item ?. disabled ) . hoverCursor } ;
144
178
}
145
179
}
@@ -159,6 +193,11 @@ const StyledItem = styled.div<
159
193
}
160
194
}
161
195
196
+ &:focus {
197
+ background: ${ ( { focusBackground} ) => focusBackground } ;
198
+ outline: none;
199
+ }
200
+
162
201
${ sx }
163
202
`
164
203
@@ -175,18 +214,21 @@ const BaseVisualContainer = styled.div<{variant?: ItemProps['variant']; disabled
175
214
width: ${ get ( 'space.3' ) } ;
176
215
display: flex;
177
216
flex-direction: column;
217
+ flex-shrink: 0;
178
218
justify-content: center;
179
219
margin-right: ${ get ( 'space.2' ) } ;
220
+ `
180
221
222
+ const ColoredVisualContainer = styled ( BaseVisualContainer ) `
181
223
svg {
182
224
fill: ${ ( { variant, disabled} ) => getItemVariant ( variant , disabled ) . iconColor } ;
183
225
font-size: ${ get ( 'fontSizes.0' ) } ;
184
226
}
185
227
`
186
228
187
- const LeadingVisualContainer = styled ( BaseVisualContainer ) ``
229
+ const LeadingVisualContainer = styled ( ColoredVisualContainer ) ``
188
230
189
- const TrailingVisualContainer = styled ( BaseVisualContainer ) `
231
+ const TrailingVisualContainer = styled ( ColoredVisualContainer ) `
190
232
color: ${ ( { variant, disabled} ) => getItemVariant ( variant , disabled ) . annotationColor } };
191
233
margin-left: auto;
192
234
margin-right: 0;
@@ -259,6 +301,12 @@ export function Item(itemProps: Partial<ItemProps> & {item?: ItemInput}): JSX.El
259
301
[ onAction , disabled , itemProps , onClick ]
260
302
)
261
303
304
+ const customItemTheme = customItemThemes [ variant ]
305
+ const hoverBackground = useColorSchemeVar ( customItemTheme . hover , 'inherit' )
306
+ const focusBackground = useColorSchemeVar ( customItemTheme . focus , 'inherit' )
307
+
308
+ const { theme} = useTheme ( )
309
+
262
310
return (
263
311
< StyledItem
264
312
tabIndex = { disabled ? undefined : - 1 }
@@ -269,9 +317,11 @@ export function Item(itemProps: Partial<ItemProps> & {item?: ItemInput}): JSX.El
269
317
data-id = { id }
270
318
onKeyPress = { keyPressHandler }
271
319
onClick = { clickHandler }
320
+ hoverBackground = { disabled ? 'inherit' : hoverBackground }
321
+ focusBackground = { disabled ? 'inherit' : focusBackground }
272
322
>
273
323
{ ! ! selected === selected && (
274
- < LeadingVisualContainer >
324
+ < BaseVisualContainer >
275
325
{ selectionVariant === 'multiple' ? (
276
326
< >
277
327
{ /*
@@ -281,9 +331,9 @@ export function Item(itemProps: Partial<ItemProps> & {item?: ItemInput}): JSX.El
281
331
< input type = "checkbox" checked = { selected } aria-label = { text } readOnly aria-readonly = "false" />
282
332
</ >
283
333
) : (
284
- selected && < CheckIcon />
334
+ selected && < CheckIcon fill = { theme ?. colors . text . primary } />
285
335
) }
286
- </ LeadingVisualContainer >
336
+ </ BaseVisualContainer >
287
337
) }
288
338
{ LeadingVisual && (
289
339
< LeadingVisualContainer variant = { variant } disabled = { disabled } >
0 commit comments