@@ -7,6 +7,37 @@ import {ItemInput} from './List'
77import styled from 'styled-components'
88import { StyledHeader } from './Header'
99import { 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
1041
1142/**
1243 * Contract for props passed to the `Item` component.
@@ -95,7 +126,6 @@ const getItemVariant = (variant = 'default', disabled?: boolean) => {
95126 color : get ( 'colors.text.disabled' ) ,
96127 iconColor : get ( 'colors.text.disabled' ) ,
97128 annotationColor : get ( 'colors.text.disabled' ) ,
98- hoverBackground : 'inherit' ,
99129 hoverCursor : 'default'
100130 }
101131 }
@@ -106,15 +136,13 @@ const getItemVariant = (variant = 'default', disabled?: boolean) => {
106136 color : get ( 'colors.text.danger' ) ,
107137 iconColor : get ( 'colors.icon.danger' ) ,
108138 annotationColor : get ( 'colors.text.disabled' ) ,
109- hoverBackground : get ( 'colors.bg.danger' ) ,
110139 hoverCursor : 'pointer'
111140 }
112141 default :
113142 return {
114143 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' ) ,
118146 hoverCursor : 'pointer'
119147 }
120148 }
@@ -125,7 +153,13 @@ const StyledItemContent = styled.div`
125153`
126154
127155const 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
129163> `
130164 /* 6px vertical padding + 20px line height = 32px total height
131165 *
@@ -139,7 +173,7 @@ const StyledItem = styled.div<
139173
140174 @media (hover: hover) and (pointer: fine) {
141175 :hover {
142- background: ${ ( { variant , item } ) => getItemVariant ( variant , item ?. disabled ) . hoverBackground } ;
176+ background: ${ ( { hoverBackground } ) => hoverBackground } ;
143177 cursor: ${ ( { variant, item} ) => getItemVariant ( variant , item ?. disabled ) . hoverCursor } ;
144178 }
145179 }
@@ -159,6 +193,11 @@ const StyledItem = styled.div<
159193 }
160194 }
161195
196+ &:focus {
197+ background: ${ ( { focusBackground} ) => focusBackground } ;
198+ outline: none;
199+ }
200+
162201 ${ sx }
163202`
164203
@@ -176,18 +215,21 @@ const BaseVisualContainer = styled.div<{variant?: ItemProps['variant']; disabled
176215 flex-shrink: 0;
177216 display: flex;
178217 flex-direction: column;
218+ flex-shrink: 0;
179219 justify-content: center;
180220 margin-right: ${ get ( 'space.2' ) } ;
221+ `
181222
223+ const ColoredVisualContainer = styled ( BaseVisualContainer ) `
182224 svg {
183225 fill: ${ ( { variant, disabled} ) => getItemVariant ( variant , disabled ) . iconColor } ;
184226 font-size: ${ get ( 'fontSizes.0' ) } ;
185227 }
186228`
187229
188- const LeadingVisualContainer = styled ( BaseVisualContainer ) ``
230+ const LeadingVisualContainer = styled ( ColoredVisualContainer ) ``
189231
190- const TrailingVisualContainer = styled ( BaseVisualContainer ) `
232+ const TrailingVisualContainer = styled ( ColoredVisualContainer ) `
191233 color: ${ ( { variant, disabled} ) => getItemVariant ( variant , disabled ) . annotationColor } };
192234 margin-left: auto;
193235 margin-right: 0;
@@ -260,6 +302,12 @@ export function Item(itemProps: Partial<ItemProps> & {item?: ItemInput}): JSX.El
260302 [ onAction , disabled , itemProps , onClick ]
261303 )
262304
305+ const customItemTheme = customItemThemes [ variant ]
306+ const hoverBackground = useColorSchemeVar ( customItemTheme . hover , 'inherit' )
307+ const focusBackground = useColorSchemeVar ( customItemTheme . focus , 'inherit' )
308+
309+ const { theme} = useTheme ( )
310+
263311 return (
264312 < StyledItem
265313 tabIndex = { disabled ? undefined : - 1 }
@@ -270,9 +318,11 @@ export function Item(itemProps: Partial<ItemProps> & {item?: ItemInput}): JSX.El
270318 data-id = { id }
271319 onKeyPress = { keyPressHandler }
272320 onClick = { clickHandler }
321+ hoverBackground = { disabled ? 'inherit' : hoverBackground }
322+ focusBackground = { disabled ? 'inherit' : focusBackground }
273323 >
274324 { ! ! selected === selected && (
275- < LeadingVisualContainer >
325+ < BaseVisualContainer >
276326 { selectionVariant === 'multiple' ? (
277327 < >
278328 { /*
@@ -282,9 +332,9 @@ export function Item(itemProps: Partial<ItemProps> & {item?: ItemInput}): JSX.El
282332 < input type = "checkbox" checked = { selected } aria-label = { text } readOnly aria-readonly = "false" />
283333 </ >
284334 ) : (
285- selected && < CheckIcon />
335+ selected && < CheckIcon fill = { theme ?. colors . text . primary } />
286336 ) }
287- </ LeadingVisualContainer >
337+ </ BaseVisualContainer >
288338 ) }
289339 { LeadingVisual && (
290340 < LeadingVisualContainer variant = { variant } disabled = { disabled } >
0 commit comments