about summary refs log tree commit diff
path: root/src/view/screens/Storybook/Toasts.tsx
blob: 4c17f1c332d1fd351e0f22094b05ad5af690eef4 (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
import {Pressable, View} from 'react-native'

import * as Toast from '#/view/com/util/Toast'
import {
  getToastTypeStyles,
  TOAST_TYPE_TO_ICON,
  type ToastType,
} from '#/view/com/util/Toast.style'
import {atoms as a, useTheme} from '#/alf'
import {H1, Text} from '#/components/Typography'

function ToastPreview({message, type}: {message: string; type: ToastType}) {
  const t = useTheme()
  const toastStyles = getToastTypeStyles(t)
  const colors = toastStyles[type as keyof typeof toastStyles]
  const IconComponent =
    TOAST_TYPE_TO_ICON[type as keyof typeof TOAST_TYPE_TO_ICON]

  return (
    <Pressable
      accessibilityRole="button"
      onPress={() => Toast.show(message, type)}
      style={[
        {backgroundColor: colors.backgroundColor},
        a.shadow_sm,
        {borderColor: colors.borderColor},
        a.rounded_sm,
        a.border,
        a.px_sm,
        a.py_sm,
        a.flex_row,
        a.gap_sm,
        a.align_center,
      ]}>
      <View
        style={[
          a.flex_shrink_0,
          a.rounded_full,
          {width: 24, height: 24},
          a.align_center,
          a.justify_center,
          {
            backgroundColor: colors.backgroundColor,
          },
        ]}>
        <IconComponent fill={colors.iconColor} size="xs" />
      </View>
      <View style={[a.flex_1]}>
        <Text
          style={[
            a.text_sm,
            a.font_bold,
            a.leading_snug,
            {color: colors.textColor},
          ]}
          emoji>
          {message}
        </Text>
      </View>
    </Pressable>
  )
}

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

      <View style={[a.gap_md]}>
        <View style={[a.gap_xs]}>
          <ToastPreview message="Default Toast" type="default" />
        </View>

        <View style={[a.gap_xs]}>
          <ToastPreview
            message="Operation completed successfully!"
            type="success"
          />
        </View>

        <View style={[a.gap_xs]}>
          <ToastPreview message="Something went wrong!" type="error" />
        </View>

        <View style={[a.gap_xs]}>
          <ToastPreview message="Please check your input" type="warning" />
        </View>

        <View style={[a.gap_xs]}>
          <ToastPreview message="Here's some helpful information" type="info" />
        </View>

        <View style={[a.gap_xs]}>
          <ToastPreview
            message="This is a longer message to test how the toast handles multiple lines of text content."
            type="info"
          />
        </View>
      </View>
    </View>
  )
}