index.ts 749 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { TUIGlobal } from '@tencentcloud/universal-api';
  2. import TOAST_TYPE from './type';
  3. interface IToast {
  4. message: string;
  5. type?: string;
  6. duration?: number;
  7. }
  8. const Toast = (options: IToast): void => {
  9. TUIGlobal.showToast({
  10. title: options.message || 'Toast',
  11. duration: options.duration || 1500,
  12. icon: handleIconType(options.type),
  13. });
  14. };
  15. const handleIconType = (type: string | undefined) => {
  16. if (!type) {
  17. return 'none';
  18. }
  19. switch (type) {
  20. case TOAST_TYPE.ERROR:
  21. return 'none';
  22. case TOAST_TYPE.WARNING:
  23. return 'none';
  24. case TOAST_TYPE.SUCCESS:
  25. return 'success';
  26. case TOAST_TYPE.NORMAL:
  27. return 'none';
  28. default:
  29. return 'none';
  30. }
  31. };
  32. export { Toast, TOAST_TYPE };