Skip to content

Commit eea3bb7

Browse files
committed
Background styles for focused action list item
1 parent 909ada5 commit eea3bb7

File tree

4 files changed

+68
-18
lines changed

4 files changed

+68
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"author": "GitHub, Inc.",
4747
"license": "MIT",
4848
"dependencies": {
49-
"@primer/octicons-react": "^11.3.0",
49+
"@primer/octicons-react": "^13.0.0",
5050
"@primer/primitives": "0.0.0-202121782215",
5151
"@styled-system/css": "5.1.5",
5252
"@styled-system/props": "5.1.4",

src/ActionList/Item.tsx

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,37 @@ import {ItemInput} from './List'
77
import styled from 'styled-components'
88
import {StyledHeader} from './Header'
99
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
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

127155
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
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}>

src/ThemeProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export function useTheme() {
9090
return React.useContext(ThemeContext)
9191
}
9292

93-
export function useColorSchemeVar(values: Partial<Record<string, string>>, fallback?: string) {
93+
export function useColorSchemeVar(values: Partial<Record<string, string>>, fallback: string) {
9494
const {colorScheme = ''} = useTheme()
9595
return values[colorScheme] ?? fallback
9696
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,10 +1833,10 @@
18331833
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.7.2.tgz#00644825ce478065101954bdb2f7f2d062365b7f"
18341834
integrity sha512-3LC1/M2ZFcmDrSkD1byT/hZzoPehZkDucbDShLnZ+/Gwkr6CAxiQ2kWy1UtJeLGADe58hTWkx22YEHqjPGUKzw==
18351835

1836-
"@primer/octicons-react@^11.3.0":
1837-
version "11.3.0"
1838-
resolved "https://registry.yarnpkg.com/@primer/octicons-react/-/octicons-react-11.3.0.tgz#794641d95ff5749a9438a2e0c201956b2a377b60"
1839-
integrity sha512-4sVhkrBKuj3h+PFw69yOyO/l3nQB/mm95V+Kz7LRSlIrbZr6hZarZD5Ft4ewdONPROkIHQM/6KSK90+OAimxsQ==
1836+
"@primer/octicons-react@^13.0.0":
1837+
version "13.0.0"
1838+
resolved "https://registry.yarnpkg.com/@primer/octicons-react/-/octicons-react-13.0.0.tgz#a7f2288fd9cf9cabc1e75553a0dd9f00d74b68c1"
1839+
integrity sha512-j5XppNRCvgaMZLPsVvvmp6GSh7P5pq6PUbsfLNBWi2Kz3KYDeoGDWbPr5MjoxFOGUn6Hjnt6qjHPRxahd11vLQ==
18401840

18411841
"@primer/primitives@0.0.0-202121782215":
18421842
version "0.0.0-202121782215"

0 commit comments

Comments
 (0)