Skip to content

Commit 43f4632

Browse files
committed
Refactored fix
1 parent 6b1f5a9 commit 43f4632

File tree

3 files changed

+22
-33
lines changed

3 files changed

+22
-33
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"license": "MIT",
4545
"dependencies": {
4646
"@primer/octicons-react": "^13.0.0",
47-
"@primer/primitives": "6.1.0",
47+
"@primer/primitives": "7.0.1",
4848
"@radix-ui/react-polymorphic": "0.0.14",
4949
"@react-aria/ssr": "3.1.0",
5050
"@styled-system/css": "5.1.5",

src/ActionList/Item.tsx

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@ import {useSSRSafeId} from '@react-aria/ssr'
1717
import {ForwardRefComponent as PolymorphicForwardRefComponent} from '@radix-ui/react-polymorphic'
1818
import {AriaRole} from '../utils/types'
1919

20-
const customItemThemes = {
21-
default: {
22-
hover: get('colors.actionListItem.default.hoverBg'),
23-
focus: get('colors.actionListItem.default.focusBg')
24-
},
25-
danger: {
26-
hover: get('colors.actionListItem.danger.hoverBg'),
27-
focus: get('colors.actionListItem.danger.focusBg')
28-
}
29-
} as const
30-
3120
/**
3221
* Contract for props passed to the `Item` component.
3322
*/
@@ -147,14 +136,18 @@ const getItemVariant = (variant = 'default', disabled?: boolean) => {
147136
color: get('colors.danger.fg'),
148137
iconColor: get('colors.danger.fg'),
149138
annotationColor: get('colors.fg.muted'),
150-
hoverCursor: 'pointer'
139+
hoverCursor: 'pointer',
140+
hoverBg: get('colors.actionListItem.danger.hoverBg'),
141+
focusBg: get('colors.actionListItem.danger.activeBg')
151142
}
152143
default:
153144
return {
154145
color: get('colors.fg.default'),
155146
iconColor: get('colors.fg.muted'),
156147
annotationColor: get('colors.fg.muted'),
157-
hoverCursor: 'pointer'
148+
hoverCursor: 'pointer',
149+
hoverBg: get('colors.actionListItem.default.hoverBg'),
150+
focusBg: get('colors.actionListItem.default.activeBg')
158151
}
159152
}
160153
}
@@ -181,8 +174,6 @@ const StyledItem = styled.div<
181174
variant: ItemProps['variant']
182175
showDivider: ItemProps['showDivider']
183176
item?: ItemInput
184-
hoverBackground: string
185-
focusBackground: string
186177
} & SxProp
187178
>`
188179
/* 6px vertical padding + 20px line height = 32px total height
@@ -201,7 +192,10 @@ const StyledItem = styled.div<
201192
@media (hover: hover) and (pointer: fine) {
202193
:hover {
203194
// allow override in case another item in the list is active/focused
204-
background: var(--item-hover-bg-override, ${({hoverBackground}) => hoverBackground});
195+
background: var(
196+
--item-hover-bg-override,
197+
${({variant, item}) => getItemVariant(variant, item?.disabled).hoverBg}
198+
);
205199
cursor: ${({variant, item}) => getItemVariant(variant, item?.disabled).hoverCursor};
206200
}
207201
}
@@ -247,19 +241,19 @@ const StyledItem = styled.div<
247241
248242
// Active Descendant
249243
&[${isActiveDescendantAttribute}='${activeDescendantActivatedDirectly}'] {
250-
background: ${({focusBackground}) => focusBackground};
244+
background: ${({variant, item}) => getItemVariant(variant, item?.disabled).focusBg};
251245
}
252246
&[${isActiveDescendantAttribute}='${activeDescendantActivatedIndirectly}'] {
253-
background: ${({hoverBackground}) => hoverBackground};
247+
background: ${({variant, item}) => getItemVariant(variant, item?.disabled).hoverBg};
254248
}
255249
256250
&:focus {
257-
background: ${({focusBackground}) => focusBackground};
251+
background: ${({variant, item}) => getItemVariant(variant, item?.disabled).focusBg};
258252
outline: none;
259253
}
260254
261255
&:active {
262-
background: ${({focusBackground}) => focusBackground};
256+
background: ${({variant, item}) => getItemVariant(variant, item?.disabled).focusBg};
263257
}
264258
265259
${sx}
@@ -378,9 +372,6 @@ export const Item = React.forwardRef((itemProps, ref) => {
378372
},
379373
[onAction, disabled, itemProps, onClick]
380374
)
381-
const customItemTheme = customItemThemes[variant]
382-
const hoverBackground = customItemTheme.hover
383-
const focusBackground = customItemTheme.focus
384375

385376
const {theme} = useTheme()
386377

@@ -398,8 +389,6 @@ export const Item = React.forwardRef((itemProps, ref) => {
398389
data-id={id}
399390
onKeyPress={keyPressHandler}
400391
onClick={clickHandler}
401-
hoverBackground={disabled ? 'inherit' : hoverBackground}
402-
focusBackground={disabled ? 'inherit' : focusBackground}
403392
>
404393
{!!selected === selected && (
405394
<BaseVisualContainer>

0 commit comments

Comments
 (0)