Skip to content

Commit c0ec10d

Browse files
committed
feat: use Alert instead
1 parent cb2c0d3 commit c0ec10d

3 files changed

Lines changed: 7 additions & 48 deletions

File tree

src/components/Toast/Toast.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ ToastProvider should inserted at the top-level component so that it displays fro
1515

1616
You could additionally wrap the container component with `overflow="hidden"` so that it disappears correctly
1717

18+
Composes `Alert`
19+
1820
<Playground>
1921
<ToastProvider>
2022
<ToastConsumer>

src/components/Toast/Toast.tsx

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as React from 'react';
2-
import { Animated, View } from 'react-native';
2+
import { Animated } from 'react-native';
33

44
import { Intent } from '../../constants/Intent';
55
import { Theme, withTheme } from '../../theme';
6-
import { Text } from '../Typography';
6+
import { Alert } from '../Alert';
77

88
// Animation taken from https://medium.com/@norbajunior/react-native-facebook-and-instagram-like-top-bar-notifications-with-animated-api-43c48d0443dd
99
export type ToastId = string;
@@ -13,7 +13,6 @@ export interface ToastSettings {
1313
title?: string;
1414
description?: string;
1515
offset?: number;
16-
duration?: number;
1716
/* custom component, will take precedence over title and description */
1817
component?: React.ReactNode;
1918
/* will override */
@@ -65,15 +64,7 @@ class ToastBase extends React.Component<ToastProps, ToastState> {
6564
}
6665

6766
public render() {
68-
const {
69-
theme,
70-
component,
71-
title,
72-
description,
73-
intent = 'info',
74-
} = this.props;
75-
76-
const { toastStyle, textStyle } = theme.getToastStyles(intent);
67+
const { component, title, description, intent = 'info' } = this.props;
7768

7869
return (
7970
<Animated.View
@@ -82,12 +73,7 @@ class ToastBase extends React.Component<ToastProps, ToastState> {
8273
}}
8374
>
8475
{component || (
85-
<View style={toastStyle}>
86-
<Text dangerouslySetInlineStyle={{ textStyle }} size="large">
87-
{title}
88-
</Text>
89-
<Text dangerouslySetInlineStyle={{ textStyle }}>{description}</Text>
90-
</View>
76+
<Alert title={title} description={description} intent={intent} />
9177
)}
9278
</Animated.View>
9379
);
Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TextStyle, ViewStyle } from 'react-native';
1+
import { ViewStyle } from 'react-native';
22

33
import { Intent } from '../../constants/Intent';
44
import { ToastVariables } from '../component-variables/toastVariables';
@@ -7,41 +7,12 @@ export type GetToastStyles = (
77
intent: Intent,
88
) => {
99
containerStyle: ViewStyle;
10-
toastStyle: ViewStyle;
11-
textStyle: TextStyle;
1210
};
1311

1412
export const getToastStyles = (
1513
toastVariables: ToastVariables,
1614
): GetToastStyles => intent => {
17-
let toastStyle: ViewStyle;
18-
let textStyle: TextStyle;
19-
20-
switch (intent) {
21-
case 'success':
22-
toastStyle = toastVariables.backgroundSuccess;
23-
textStyle = toastVariables.textSuccess;
24-
break;
25-
case 'warning':
26-
toastStyle = toastVariables.backgroundWarning;
27-
textStyle = toastVariables.textWarning;
28-
break;
29-
case 'danger':
30-
toastStyle = toastVariables.backgroundDanger;
31-
textStyle = toastVariables.textDanger;
32-
break;
33-
default:
34-
toastStyle = toastVariables.backgroundInfo;
35-
textStyle = toastVariables.textInfo;
36-
break;
37-
}
38-
3915
return {
4016
containerStyle: toastVariables.container,
41-
textStyle,
42-
toastStyle: {
43-
...toastVariables.base,
44-
...toastStyle,
45-
},
4617
};
4718
};

0 commit comments

Comments
 (0)