about summary refs log tree commit diff
path: root/src/view/com/util/Toast.style.tsx
blob: 3869e6890bdd3ba538057d1eb98ce06fe5beff12 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import {select, type Theme} from '#/alf'
import {Check_Stroke2_Corner0_Rounded as SuccessIcon} from '#/components/icons/Check'
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'

export type ToastType = 'default' | 'success' | 'error' | 'warning' | 'info'

export type LegacyToastType =
  | 'xmark'
  | 'exclamation-circle'
  | 'check'
  | 'clipboard-check'
  | 'circle-exclamation'

export const convertLegacyToastType = (
  type: ToastType | LegacyToastType,
): ToastType => {
  switch (type) {
    // these ones are fine
    case 'default':
    case 'success':
    case 'error':
    case 'warning':
    case 'info':
      return type
    // legacy ones need conversion
    case 'xmark':
      return 'error'
    case 'exclamation-circle':
      return 'warning'
    case 'check':
      return 'success'
    case 'clipboard-check':
      return 'success'
    case 'circle-exclamation':
      return 'warning'
    default:
      return 'default'
  }
}

export const TOAST_ANIMATION_CONFIG = {
  duration: 300,
  damping: 15,
  stiffness: 150,
  mass: 0.8,
  overshootClamping: false,
  restSpeedThreshold: 0.01,
  restDisplacementThreshold: 0.01,
}

export const TOAST_TYPE_TO_ICON = {
  default: SuccessIcon,
  success: SuccessIcon,
  error: ErrorIcon,
  warning: WarningIcon,
  info: CircleInfo,
}

export const getToastTypeStyles = (t: Theme) => ({
  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,
    }),
  },
  success: {
    backgroundColor: select(t.name, {
      light: t.palette.primary_100,
      dim: t.palette.primary_100,
      dark: t.palette.primary_50,
    }),
    borderColor: select(t.name, {
      light: t.palette.primary_500,
      dim: t.palette.primary_500,
      dark: t.palette.primary_500,
    }),
    iconColor: select(t.name, {
      light: t.palette.primary_500,
      dim: t.palette.primary_600,
      dark: t.palette.primary_600,
    }),
    textColor: select(t.name, {
      light: t.palette.primary_500,
      dim: t.palette.primary_600,
      dark: t.palette.primary_600,
    }),
  },
  error: {
    backgroundColor: select(t.name, {
      light: t.palette.negative_200,
      dim: t.palette.negative_25,
      dark: t.palette.negative_25,
    }),
    borderColor: select(t.name, {
      light: t.palette.negative_300,
      dim: t.palette.negative_300,
      dark: t.palette.negative_300,
    }),
    iconColor: select(t.name, {
      light: t.palette.negative_600,
      dim: t.palette.negative_600,
      dark: t.palette.negative_600,
    }),
    textColor: select(t.name, {
      light: t.palette.negative_600,
      dim: t.palette.negative_600,
      dark: t.palette.negative_600,
    }),
  },
  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,
    }),
  },
  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,
    }),
  },
})

export const getToastWebAnimationStyles = () => ({
  entering: {
    animation: 'toastFadeIn 0.3s ease-out forwards',
  },
  exiting: {
    animation: 'toastFadeOut 0.2s ease-in forwards',
  },
})

export const TOAST_WEB_KEYFRAMES = `
  @keyframes toastFadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  @keyframes toastFadeOut {
    from {
      opacity: 1;
    }
    to {
      opacity: 0;
    }
  }
`