Skip to content

Commit 63c767b

Browse files
jossmacemmatown
andauthored
Improve Toast appearance of "neutral" variant (#1449)
Co-authored-by: Emma Hamilton <[email protected]>
1 parent 57ace77 commit 63c767b

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

.changeset/strong-bikes-cheer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@keystar/ui': patch
3+
---
4+
5+
Improve "neutral" `Toast` appearance, esp. for dark mode.

design-system/pkg/src/toast/Toast.tsx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ import { checkCircle2Icon } from '@keystar/ui/icon/icons/checkCircle2Icon';
99
import { infoIcon } from '@keystar/ui/icon/icons/infoIcon';
1010
import { alertTriangleIcon } from '@keystar/ui/icon/icons/alertTriangleIcon';
1111
import { SlotProvider } from '@keystar/ui/slots';
12-
import { classNames, css, tokenSchema, useStyleProps } from '@keystar/ui/style';
12+
import {
13+
classNames,
14+
css,
15+
tokenSchema,
16+
useMediaQuery,
17+
useStyleProps,
18+
} from '@keystar/ui/style';
1319
import { Text } from '@keystar/ui/typography';
1420
import { isReactText } from '@keystar/ui/utils';
1521

1622
import intlMessages from './l10n';
1723
import { ToastProps } from './types';
24+
import { useProvider } from '../core';
1825

1926
const ICONS = {
2027
info: infoIcon,
@@ -45,6 +52,10 @@ function Toast(props: ToastProps, ref: ForwardedRef<HTMLDivElement>) {
4552
tone && tone !== 'neutral' ? stringFormatter.format(tone) : null;
4653
let icon = tone && tone !== 'neutral' ? ICONS[tone] : null;
4754

55+
const colorScheme = useColorScheme();
56+
const staticColor =
57+
tone === 'neutral' && colorScheme === 'dark' ? 'dark' : 'light';
58+
4859
const handleAction = () => {
4960
if (onAction) {
5061
onAction();
@@ -83,7 +94,8 @@ function Toast(props: ToastProps, ref: ForwardedRef<HTMLDivElement>) {
8394
// tones
8495
color: tokenSchema.color.foreground.onEmphasis,
8596
'&[data-tone=neutral]': {
86-
background: tokenSchema.color.scale['slate9'],
97+
backgroundColor: tokenSchema.color.background.inverse,
98+
color: tokenSchema.color.foreground.inverse,
8799
},
88100
'&[data-tone=info]': {
89101
background: tokenSchema.color.background.accentEmphasis,
@@ -135,30 +147,36 @@ function Toast(props: ToastProps, ref: ForwardedRef<HTMLDivElement>) {
135147
{isReactText(children) ? <Text>{children}</Text> : children}
136148
</div>
137149
{actionLabel && (
138-
<Button
139-
onPress={handleAction}
140-
// prominence="low"
141-
static="light"
142-
// tone="secondary"
143-
// staticColor="white"
144-
>
150+
<Button onPress={handleAction} static={staticColor}>
145151
{actionLabel}
146152
</Button>
147153
)}
148154
</div>
149155
</div>
150156
<div
151157
className={css({
152-
borderInlineStart: `${tokenSchema.size.border.regular} solid #fff3`,
158+
borderInlineStart: `${tokenSchema.size.border.regular} solid var(--divider)`,
153159
paddingInlineStart: tokenSchema.size.space.regular,
160+
'--divider': 'color-mix(in srgb, transparent, currentColor 20%)',
154161
})}
155162
>
156-
<ClearButton static="light" {...closeButtonProps} />
163+
<ClearButton static={staticColor} {...closeButtonProps} />
157164
</div>
158165
</SlotProvider>
159166
</div>
160167
);
161168
}
162169

170+
function useColorScheme() {
171+
const prefersDark = useMediaQuery('(prefers-color-scheme: dark)');
172+
const preferred = useProvider();
173+
174+
if (preferred.colorScheme === 'auto') {
175+
return prefersDark ? 'dark' : 'light';
176+
}
177+
178+
return preferred.colorScheme;
179+
}
180+
163181
let _Toast = forwardRef(Toast);
164182
export { _Toast as Toast };

0 commit comments

Comments
 (0)