import { PropOptions, PropType } from "vue"; import { ToastContent, CommonOptions, PluginOptions, ToastID, ToastOptions, ToastOptionsAndRequiredContent, } from "../types"; import { TYPE, POSITION, VT_NAMESPACE } from "./constants"; import { RecordPropsDefinition } from "vue/types/options"; const COMMON = { type: { type: String, default: TYPE.DEFAULT, } as PropOptions, classNames: { type: [String, Array], default: () => [], } as PropOptions, trueBoolean: { type: Boolean, default: true, } as PropOptions, }; const ICON = { type: COMMON.type, customIcon: { type: [String, Boolean, Object, Function], default: true, } as PropOptions>, }; const CLOSE_BUTTON = { component: { type: [String, Object, Function, Boolean], default: "button" as keyof HTMLElementTagNameMap, } as PropOptions>, classNames: COMMON.classNames, showOnHover: Boolean as PropType, ariaLabel: { type: String, default: "close", } as PropOptions, }; const PROGRESS_BAR = { timeout: { type: [Number, Boolean], default: 5000, } as PropOptions, hideProgressBar: Boolean as PropType, isRunning: Boolean as PropType, }; const TRANSITION = { transition: { type: [Object, String], default: `${VT_NAMESPACE}__bounce`, } as PropOptions>, transitionDuration: { type: [Number, Object], default: 750, } as PropOptions>, }; type CommonOptionsType = Required; const CORE_TOAST: RecordPropsDefinition = { position: { type: String, default: POSITION.TOP_RIGHT, } as PropOptions, draggable: COMMON.trueBoolean, draggablePercent: { type: Number, default: 0.6, } as PropOptions, pauseOnFocusLoss: COMMON.trueBoolean, pauseOnHover: COMMON.trueBoolean, closeOnClick: COMMON.trueBoolean, timeout: PROGRESS_BAR.timeout, hideProgressBar: PROGRESS_BAR.hideProgressBar, toastClassName: COMMON.classNames, bodyClassName: COMMON.classNames, icon: ICON.customIcon, closeButton: CLOSE_BUTTON.component, closeButtonClassName: CLOSE_BUTTON.classNames, showCloseButtonOnHover: CLOSE_BUTTON.showOnHover, accessibility: { type: Object, default: () => ({ toastRole: "alert", closeButtonLabel: "close", }), } as PropOptions>, rtl: Boolean as PropType, eventBus: Object as PropOptions>, }; type ToastOptionsType = Required< Omit >; const TOAST: RecordPropsDefinition = { id: { type: [String, Number], required: true, } as PropOptions, type: COMMON.type, content: { type: [String, Object, Function], required: true, } as PropOptions, onClick: Function as PropType>, onClose: Function as PropType>, }; export type PluginOptionsType = Required< Omit >; const CONTAINER: RecordPropsDefinition = { container: { type: undefined, default: () => document.body, } as PropOptions>, newestOnTop: COMMON.trueBoolean, maxToasts: { type: Number, default: 20, } as PropOptions, transition: TRANSITION.transition, transitionDuration: TRANSITION.transitionDuration, toastDefaults: Object as PropType< NonNullable >, filterBeforeCreate: { type: Function, default: (toast: ToastOptionsAndRequiredContent) => toast, } as PropOptions>, filterToasts: { type: Function, default: (toasts: ToastOptionsAndRequiredContent[]) => toasts, } as PropOptions>, containerClassName: COMMON.classNames, onMounted: Function as PropType>, }; export default { CORE_TOAST, TOAST, CONTAINER, PROGRESS_BAR, ICON, TRANSITION, CLOSE_BUTTON, };