@@ -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
@@ -175,18 +214,21 @@ const BaseVisualContainer = styled.div<{variant?: ItemProps['variant']; disabled
175214 width: ${ get ( 'space.3' ) } ;
176215 display: flex;
177216 flex-direction: column;
217+ flex-shrink: 0;
178218 justify-content: center;
179219 margin-right: ${ get ( 'space.2' ) } ;
220+ `
180221
222+ const ColoredVisualContainer = styled ( BaseVisualContainer ) `
181223 svg {
182224 fill: ${ ( { variant, disabled} ) => getItemVariant ( variant , disabled ) . iconColor } ;
183225 font-size: ${ get ( 'fontSizes.0' ) } ;
184226 }
185227`
186228
187- const LeadingVisualContainer = styled ( BaseVisualContainer ) ``
229+ const LeadingVisualContainer = styled ( ColoredVisualContainer ) ``
188230
189- const TrailingVisualContainer = styled ( BaseVisualContainer ) `
231+ const TrailingVisualContainer = styled ( ColoredVisualContainer ) `
190232 color: ${ ( { variant, disabled} ) => getItemVariant ( variant , disabled ) . annotationColor } };
191233 margin-left: auto;
192234 margin-right: 0;
@@ -259,6 +301,12 @@ export function Item(itemProps: Partial<ItemProps> & {item?: ItemInput}): JSX.El
259301 [ onAction , disabled , itemProps , onClick ]
260302 )
261303
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+
262310 return (
263311 < StyledItem
264312 tabIndex = { disabled ? undefined : - 1 }
@@ -269,9 +317,11 @@ export function Item(itemProps: Partial<ItemProps> & {item?: ItemInput}): JSX.El
269317 data-id = { id }
270318 onKeyPress = { keyPressHandler }
271319 onClick = { clickHandler }
320+ hoverBackground = { disabled ? 'inherit' : hoverBackground }
321+ focusBackground = { disabled ? 'inherit' : focusBackground }
272322 >
273323 { ! ! selected === selected && (
274- < LeadingVisualContainer >
324+ < BaseVisualContainer >
275325 { selectionVariant === 'multiple' ? (
276326 < >
277327 { /*
@@ -281,9 +331,9 @@ export function Item(itemProps: Partial<ItemProps> & {item?: ItemInput}): JSX.El
281331 < input type = "checkbox" checked = { selected } aria-label = { text } readOnly aria-readonly = "false" />
282332 </ >
283333 ) : (
284- selected && < CheckIcon />
334+ selected && < CheckIcon fill = { theme ?. colors . text . primary } />
285335 ) }
286- </ LeadingVisualContainer >
336+ </ BaseVisualContainer >
287337 ) }
288338 { LeadingVisual && (
289339 < LeadingVisualContainer variant = { variant } disabled = { disabled } >
0 commit comments