about summary refs log tree commit diff
path: root/src/view/com/util/Toast.tsx
blob: 820c9f9d719b2589c6b306f0572e0409b24e8b8d (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
import * as toast from '#/components/Toast'
import {type ToastType} from '#/components/Toast/types'

/**
 * @deprecated use {@link ToastType} and {@link toast} instead
 */
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'
  }
}

/**
 * @deprecated use {@link toast} instead
 */
export function show(
  message: string,
  type: ToastType | LegacyToastType = 'default',
): void {
  const convertedType = convertLegacyToastType(type)
  toast.show(message, {type: convertedType})
}