Skip to content

Commit fa7cf7a

Browse files
committed
💄(frontend) add a theme focus visible on BoxButton
We want to improve the accessibility of our BoxButton component by adding a theme focus visible style. This will help users who navigate using the keyboard to easily identify which button is currently focused. To do so we have to move some theme styles to the Box component to be able to use them in BoxButton.
1 parent 6523165 commit fa7cf7a

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

src/frontend/apps/impress/src/components/Box.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,30 @@ export interface BoxProps {
3636
$position?: CSSProperties['position'];
3737
$radius?: CSSProperties['borderRadius'];
3838
$shrink?: CSSProperties['flexShrink'];
39+
$theme?:
40+
| 'primary'
41+
| 'primary-text'
42+
| 'secondary'
43+
| 'secondary-text'
44+
| 'info'
45+
| 'success'
46+
| 'warning'
47+
| 'danger'
48+
| 'greyscale';
3949
$transition?: CSSProperties['transition'];
50+
$variation?:
51+
| 'text'
52+
| '000'
53+
| '100'
54+
| '200'
55+
| '300'
56+
| '400'
57+
| '500'
58+
| '600'
59+
| '700'
60+
| '800'
61+
| '900'
62+
| '1000';
4063
$width?: CSSProperties['width'];
4164
$wrap?: CSSProperties['flexWrap'];
4265
$zIndex?: CSSProperties['zIndex'];
@@ -73,6 +96,12 @@ export const Box = styled('div')<BoxProps>`
7396
${({ $position }) => $position && `position: ${$position};`}
7497
${({ $radius }) => $radius && `border-radius: ${$radius};`}
7598
${({ $shrink }) => $shrink && `flex-shrink: ${$shrink};`}
99+
${({ $theme, $variation }) => {
100+
if (!$theme || !$variation) {
101+
return '';
102+
}
103+
return `color: var(--c--theme--colors--${$theme}-${$variation});`;
104+
}}
76105
${({ $transition }) => $transition && `transition: ${$transition};`}
77106
${({ $width }) => $width && `width: ${$width};`}
78107
${({ $wrap }) => $wrap && `flex-wrap: ${$wrap};`}

src/frontend/apps/impress/src/components/BoxButton.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export type BoxButtonType = BoxType & {
2424
*/
2525
const BoxButton = forwardRef<HTMLDivElement, BoxButtonType>(
2626
({ $css, ...props }, ref) => {
27+
const theme = props.$theme || 'greyscale';
28+
const variation = props.$variation || '400';
29+
2730
return (
2831
<Box
2932
ref={ref}
@@ -37,10 +40,16 @@ const BoxButton = forwardRef<HTMLDivElement, BoxButtonType>(
3740
border: none;
3841
outline: none;
3942
font-family: inherit;
40-
4143
color: ${props.disabled
42-
? 'var(--c--theme--colors--greyscale-400) !important'
43-
: 'inherit'};
44+
? `var(--c--theme--colors--${theme}-400) !important`
45+
: `inherit`};
46+
47+
&:focus-visible {
48+
transition: none;
49+
outline: 2px solid var(--c--theme--colors--${theme}-${variation});
50+
border-radius: 1px;
51+
outline-offset: 4px;
52+
}
4453
${$css || ''}
4554
`}
4655
{...props}

src/frontend/apps/impress/src/components/Text.tsx

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,6 @@ export interface TextProps extends BoxProps {
1515
$textAlign?: CSSProperties['textAlign'];
1616
$textTransform?: CSSProperties['textTransform'];
1717
$size?: TextSizes | (string & {});
18-
$theme?:
19-
| 'primary'
20-
| 'primary-text'
21-
| 'secondary'
22-
| 'secondary-text'
23-
| 'info'
24-
| 'success'
25-
| 'warning'
26-
| 'danger'
27-
| 'greyscale';
28-
$variation?:
29-
| 'text'
30-
| '000'
31-
| '100'
32-
| '200'
33-
| '300'
34-
| '400'
35-
| '500'
36-
| '600'
37-
| '700'
38-
| '800'
39-
| '900'
40-
| '1000';
4118
}
4219

4320
export type TextType = ComponentPropsWithRef<typeof Text>;
@@ -50,8 +27,6 @@ export const TextStyled = styled(Box)<TextProps>`
5027
${({ $size }) =>
5128
$size &&
5229
`font-size: ${$size in sizes ? sizes[$size as TextSizes] : $size};`}
53-
${({ $theme, $variation }) =>
54-
`color: var(--c--theme--colors--${$theme}-${$variation});`}
5530
${({ $color }) => $color && `color: ${$color};`}
5631
${({ $ellipsis }) =>
5732
$ellipsis &&

src/frontend/apps/impress/src/features/docs/doc-header/components/AlertRestore.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ export const AlertRestore = ({ doc }: { doc: Doc }) => {
8080
}
8181
$direction="row"
8282
$gap="0.2rem"
83+
$theme="danger"
84+
$variation="600"
8385
$align="center"
8486
>
8587
<Icon

0 commit comments

Comments
 (0)