diff options
Diffstat (limited to 'src/components/Toast/Toast.tsx')
-rw-r--r-- | src/components/Toast/Toast.tsx | 146 |
1 files changed, 53 insertions, 93 deletions
diff --git a/src/components/Toast/Toast.tsx b/src/components/Toast/Toast.tsx index 0dc9d4b07..2d1ea4261 100644 --- a/src/components/Toast/Toast.tsx +++ b/src/components/Toast/Toast.tsx @@ -1,21 +1,21 @@ import {createContext, useContext, useMemo} from 'react' import {View} from 'react-native' -import {atoms as a, select, useTheme} from '#/alf' -import {Check_Stroke2_Corner0_Rounded as SuccessIcon} from '#/components/icons/Check' +import {atoms as a, select, useAlf, useTheme} from '#/alf' import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo' import {CircleInfo_Stroke2_Corner0_Rounded as ErrorIcon} from '#/components/icons/CircleInfo' import {Warning_Stroke2_Corner0_Rounded as WarningIcon} from '#/components/icons/Warning' import {type ToastType} from '#/components/Toast/types' import {Text} from '#/components/Typography' +import {CircleCheck_Stroke2_Corner0_Rounded as CircleCheck} from '../icons/CircleCheck' type ContextType = { type: ToastType } export const ICONS = { - default: SuccessIcon, - success: SuccessIcon, + default: CircleCheck, + success: CircleCheck, error: ErrorIcon, warning: WarningIcon, info: CircleInfo, @@ -32,9 +32,19 @@ export function Toast({ type: ToastType content: React.ReactNode }) { + const {fonts} = useAlf() const t = useTheme() const styles = useToastStyles({type}) const Icon = ICONS[type] + /** + * Vibes-based number, adjusts `top` of `View` that wraps the text to + * compensate for different type sizes and keep the first line of text + * aligned with the icon. - esb + */ + const fontScaleCompensation = useMemo( + () => parseInt(fonts.scale) * -1 * 0.65, + [fonts.scale], + ) return ( <Context.Provider value={useMemo(() => ({type}), [type])}> @@ -56,7 +66,13 @@ export function Toast({ ]}> <Icon size="md" fill={styles.iconColor} /> - <View style={[a.flex_1]}> + <View + style={[ + a.flex_1, + { + top: fontScaleCompensation, + }, + ]}> {typeof content === 'string' ? ( <ToastText>{content}</ToastText> ) : ( @@ -91,114 +107,58 @@ function useToastStyles({type}: {type: ToastType}) { return useMemo(() => { return { default: { - backgroundColor: select(t.name, { - light: t.atoms.bg_contrast_25.backgroundColor, - dim: t.atoms.bg_contrast_100.backgroundColor, - dark: t.atoms.bg_contrast_100.backgroundColor, - }), - borderColor: select(t.name, { - light: t.atoms.border_contrast_low.borderColor, - dim: t.atoms.border_contrast_high.borderColor, - dark: t.atoms.border_contrast_high.borderColor, - }), - iconColor: select(t.name, { - light: t.atoms.text_contrast_medium.color, - dim: t.atoms.text_contrast_medium.color, - dark: t.atoms.text_contrast_medium.color, - }), - textColor: select(t.name, { - light: t.atoms.text_contrast_medium.color, - dim: t.atoms.text_contrast_medium.color, - dark: t.atoms.text_contrast_medium.color, - }), + backgroundColor: t.atoms.bg_contrast_25.backgroundColor, + borderColor: t.atoms.border_contrast_low.borderColor, + iconColor: t.atoms.text.color, + textColor: t.atoms.text.color, }, success: { - backgroundColor: select(t.name, { - light: t.palette.primary_100, - dim: t.palette.primary_100, - dark: t.palette.primary_50, - }), + backgroundColor: t.palette.primary_25, borderColor: select(t.name, { - light: t.palette.primary_500, - dim: t.palette.primary_500, - dark: t.palette.primary_500, + light: t.palette.primary_300, + dim: t.palette.primary_200, + dark: t.palette.primary_100, }), iconColor: select(t.name, { - light: t.palette.primary_500, - dim: t.palette.primary_600, - dark: t.palette.primary_600, + light: t.palette.primary_600, + dim: t.palette.primary_700, + dark: t.palette.primary_700, }), textColor: select(t.name, { - light: t.palette.primary_500, - dim: t.palette.primary_600, - dark: t.palette.primary_600, + light: t.palette.primary_600, + dim: t.palette.primary_700, + dark: t.palette.primary_700, }), }, error: { - backgroundColor: select(t.name, { - light: t.palette.negative_200, - dim: t.palette.negative_25, - dark: t.palette.negative_25, - }), + backgroundColor: t.palette.negative_25, borderColor: select(t.name, { - light: t.palette.negative_300, - dim: t.palette.negative_300, - dark: t.palette.negative_300, + light: t.palette.negative_200, + dim: t.palette.negative_200, + dark: t.palette.negative_100, }), iconColor: select(t.name, { - light: t.palette.negative_600, - dim: t.palette.negative_600, - dark: t.palette.negative_600, + light: t.palette.negative_700, + dim: t.palette.negative_900, + dark: t.palette.negative_900, }), textColor: select(t.name, { - light: t.palette.negative_600, - dim: t.palette.negative_600, - dark: t.palette.negative_600, + light: t.palette.negative_700, + dim: t.palette.negative_900, + dark: t.palette.negative_900, }), }, warning: { - backgroundColor: select(t.name, { - light: t.atoms.bg_contrast_25.backgroundColor, - dim: t.atoms.bg_contrast_100.backgroundColor, - dark: t.atoms.bg_contrast_100.backgroundColor, - }), - borderColor: select(t.name, { - light: t.atoms.border_contrast_low.borderColor, - dim: t.atoms.border_contrast_high.borderColor, - dark: t.atoms.border_contrast_high.borderColor, - }), - iconColor: select(t.name, { - light: t.atoms.text_contrast_medium.color, - dim: t.atoms.text_contrast_medium.color, - dark: t.atoms.text_contrast_medium.color, - }), - textColor: select(t.name, { - light: t.atoms.text_contrast_medium.color, - dim: t.atoms.text_contrast_medium.color, - dark: t.atoms.text_contrast_medium.color, - }), + backgroundColor: t.atoms.bg_contrast_25.backgroundColor, + borderColor: t.atoms.border_contrast_low.borderColor, + iconColor: t.atoms.text.color, + textColor: t.atoms.text.color, }, info: { - backgroundColor: select(t.name, { - light: t.atoms.bg_contrast_25.backgroundColor, - dim: t.atoms.bg_contrast_100.backgroundColor, - dark: t.atoms.bg_contrast_100.backgroundColor, - }), - borderColor: select(t.name, { - light: t.atoms.border_contrast_low.borderColor, - dim: t.atoms.border_contrast_high.borderColor, - dark: t.atoms.border_contrast_high.borderColor, - }), - iconColor: select(t.name, { - light: t.atoms.text_contrast_medium.color, - dim: t.atoms.text_contrast_medium.color, - dark: t.atoms.text_contrast_medium.color, - }), - textColor: select(t.name, { - light: t.atoms.text_contrast_medium.color, - dim: t.atoms.text_contrast_medium.color, - dark: t.atoms.text_contrast_medium.color, - }), + backgroundColor: t.atoms.bg_contrast_25.backgroundColor, + borderColor: t.atoms.border_contrast_low.borderColor, + iconColor: t.atoms.text.color, + textColor: t.atoms.text.color, }, }[type] }, [t, type]) |