about summary refs log tree commit diff
path: root/src/view/screens/Storybook/Toasts.tsx
blob: 319f88e215b6a0a77f0279d4c4798bcad71286a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import {Pressable, View} from 'react-native'

import {show as deprecatedShow} from '#/view/com/util/Toast'
import {atoms as a} from '#/alf'
import {Globe_Stroke2_Corner0_Rounded as GlobeIcon} from '#/components/icons/Globe'
import * as Toast from '#/components/Toast'
import {Default} from '#/components/Toast/Toast'
import {H1} from '#/components/Typography'

function ToastWithAction({type = 'default'}: {type?: Toast.ToastType}) {
  return (
    <Toast.Outer type={type}>
      <Toast.Icon icon={GlobeIcon} />
      <Toast.Text>This toast has an action button</Toast.Text>
      <Toast.Action
        label="Action"
        onPress={() => console.log('Action clicked!')}>
        Action
      </Toast.Action>
    </Toast.Outer>
  )
}

function LongToastWithAction({type = 'default'}: {type?: Toast.ToastType}) {
  return (
    <Toast.Outer type={type}>
      <Toast.Icon icon={GlobeIcon} />
      <Toast.Text>
        This is a longer message to test how the toast handles multiple lines of
        text content.
      </Toast.Text>
      <Toast.Action
        label="Action"
        onPress={() => console.log('Action clicked!')}>
        Action
      </Toast.Action>
    </Toast.Outer>
  )
}

export function Toasts() {
  return (
    <View style={[a.gap_md]}>
      <H1>Toast Examples</H1>

      <View style={[a.gap_md]}>
        <View style={[a.gap_md, {marginHorizontal: a.px_xl.paddingLeft * -1}]}>
          <Pressable
            accessibilityRole="button"
            onPress={() => Toast.show(<ToastWithAction />)}>
            <ToastWithAction />
          </Pressable>
          <Pressable
            accessibilityRole="button"
            onPress={() => Toast.show(<LongToastWithAction />)}>
            <LongToastWithAction />
          </Pressable>
          <Pressable
            accessibilityRole="button"
            onPress={() => Toast.show(<ToastWithAction type="success" />)}>
            <ToastWithAction type="success" />
          </Pressable>
          <Pressable
            accessibilityRole="button"
            onPress={() => Toast.show(<ToastWithAction type="error" />)}>
            <ToastWithAction type="error" />
          </Pressable>
        </View>

        <Pressable
          accessibilityRole="button"
          onPress={() => Toast.show(`Hey I'm a toast!`)}>
          <Default content="Hey I'm a toast!" />
        </Pressable>
        <Pressable
          accessibilityRole="button"
          onPress={() =>
            Toast.show(`This toast will disappear after 6 seconds`, {
              duration: 6e3,
            })
          }>
          <Default content="This toast will disappear after 6 seconds" />
        </Pressable>
        <Pressable
          accessibilityRole="button"
          onPress={() =>
            Toast.show(
              `This is a longer message to test how the toast handles multiple lines of text content.`,
            )
          }>
          <Default content="This is a longer message to test how the toast handles multiple lines of text content." />
        </Pressable>
        <Pressable
          accessibilityRole="button"
          onPress={() =>
            Toast.show(`Success! Yayyyyyyy :)`, {
              type: 'success',
            })
          }>
          <Default content="Success! Yayyyyyyy :)" type="success" />
        </Pressable>
        <Pressable
          accessibilityRole="button"
          onPress={() =>
            Toast.show(`I'm providing info!`, {
              type: 'info',
            })
          }>
          <Default content="I'm providing info!" type="info" />
        </Pressable>
        <Pressable
          accessibilityRole="button"
          onPress={() =>
            Toast.show(`This is a warning toast`, {
              type: 'warning',
            })
          }>
          <Default content="This is a warning toast" type="warning" />
        </Pressable>
        <Pressable
          accessibilityRole="button"
          onPress={() =>
            Toast.show(`This is an error toast :(`, {
              type: 'error',
            })
          }>
          <Default content="This is an error toast :(" type="error" />
        </Pressable>

        <Pressable
          accessibilityRole="button"
          onPress={() =>
            deprecatedShow(
              `This is a test of the deprecated API`,
              'exclamation-circle',
            )
          }>
          <Default
            content="This is a test of the deprecated API"
            type="warning"
          />
        </Pressable>
      </View>
    </View>
  )
}