@@ -9,12 +9,19 @@ import { checkCircle2Icon } from '@keystar/ui/icon/icons/checkCircle2Icon';
99import { infoIcon } from '@keystar/ui/icon/icons/infoIcon' ;
1010import { alertTriangleIcon } from '@keystar/ui/icon/icons/alertTriangleIcon' ;
1111import { 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' ;
1319import { Text } from '@keystar/ui/typography' ;
1420import { isReactText } from '@keystar/ui/utils' ;
1521
1622import intlMessages from './l10n' ;
1723import { ToastProps } from './types' ;
24+ import { useProvider } from '../core' ;
1825
1926const 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+
163181let _Toast = forwardRef ( Toast ) ;
164182export { _Toast as Toast } ;
0 commit comments