diff options
author | Eric Bailey <git@esb.lol> | 2025-08-26 16:54:43 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-26 16:54:43 -0500 |
commit | 9f7c920346f3e650f530930cd22ca241fc6cbd7f (patch) | |
tree | 8b93e3b299030379d2af425cd825196199fffe7f /src/components/Toast/Toast.tsx | |
parent | 0555d3623cf5eea744bd26b4343c60ec66e43aa3 (diff) | |
download | voidsky-9f7c920346f3e650f530930cd22ca241fc6cbd7f.tar.zst |
Fix toast type (#8909)
* Fix confusing toast API * Provide all exports to e2e file * Fix first usage in Composer * Loosen type, add Trans tag
Diffstat (limited to 'src/components/Toast/Toast.tsx')
-rw-r--r-- | src/components/Toast/Toast.tsx | 91 |
1 files changed, 32 insertions, 59 deletions
diff --git a/src/components/Toast/Toast.tsx b/src/components/Toast/Toast.tsx index 53d5e5115..ac5bc4889 100644 --- a/src/components/Toast/Toast.tsx +++ b/src/components/Toast/Toast.tsx @@ -16,19 +16,6 @@ import {dismiss} from '#/components/Toast/sonner' import {type ToastType} from '#/components/Toast/types' import {Text as BaseText} from '#/components/Typography' -type ToastConfigContextType = { - id: string -} - -type ToastThemeContextType = { - type: ToastType -} - -export type ToastComponentProps = { - type?: ToastType - content: string -} - export const ICONS = { default: CircleCheck, success: CircleCheck, @@ -37,81 +24,67 @@ export const ICONS = { info: CircleInfo, } -const ToastConfigContext = createContext<ToastConfigContextType>({ +const ToastConfigContext = createContext<{ + id: string + type: ToastType +}>({ id: '', + type: 'default', }) ToastConfigContext.displayName = 'ToastConfigContext' export function ToastConfigProvider({ children, id, + type, }: { children: React.ReactNode id: string + type: ToastType }) { return ( - <ToastConfigContext.Provider value={useMemo(() => ({id}), [id])}> + <ToastConfigContext.Provider + value={useMemo(() => ({id, type}), [id, type])}> {children} </ToastConfigContext.Provider> ) } -const ToastThemeContext = createContext<ToastThemeContextType>({ - type: 'default', -}) -ToastThemeContext.displayName = 'ToastThemeContext' - -export function Default({type = 'default', content}: ToastComponentProps) { - return ( - <Outer type={type}> - <Icon /> - <Text>{content}</Text> - </Outer> - ) -} - -export function Outer({ - children, - type = 'default', -}: { - children: React.ReactNode - type?: ToastType -}) { +export function Outer({children}: {children: React.ReactNode}) { const t = useTheme() + const {type} = useContext(ToastConfigContext) const styles = useToastStyles({type}) return ( - <ToastThemeContext.Provider value={useMemo(() => ({type}), [type])}> - <View - style={[ - a.flex_1, - a.p_lg, - a.rounded_md, - a.border, - a.flex_row, - a.gap_sm, - t.atoms.shadow_sm, - { - paddingVertical: 14, // 16 seems too big - backgroundColor: styles.backgroundColor, - borderColor: styles.borderColor, - }, - ]}> - {children} - </View> - </ToastThemeContext.Provider> + <View + style={[ + a.flex_1, + a.p_lg, + a.rounded_md, + a.border, + a.flex_row, + a.gap_sm, + t.atoms.shadow_sm, + { + paddingVertical: 14, // 16 seems too big + backgroundColor: styles.backgroundColor, + borderColor: styles.borderColor, + }, + ]}> + {children} + </View> ) } export function Icon({icon}: {icon?: React.ComponentType<SVGIconProps>}) { - const {type} = useContext(ToastThemeContext) + const {type} = useContext(ToastConfigContext) const styles = useToastStyles({type}) const IconComponent = icon || ICONS[type] return <IconComponent size="md" fill={styles.iconColor} /> } export function Text({children}: {children: React.ReactNode}) { - const {type} = useContext(ToastThemeContext) + const {type} = useContext(ToastConfigContext) const {textColor} = useToastStyles({type}) const {fontScaleCompensation} = useToastFontScaleCompensation() return ( @@ -142,12 +115,12 @@ export function Text({children}: {children: React.ReactNode}) { export function Action( props: Omit<ButtonProps, UninheritableButtonProps | 'children'> & { - children: string + children: React.ReactNode }, ) { const t = useTheme() const {fontScaleCompensation} = useToastFontScaleCompensation() - const {type} = useContext(ToastThemeContext) + const {type} = useContext(ToastConfigContext) const {id} = useContext(ToastConfigContext) const styles = useMemo(() => { const base = { |