UNPKG

compote-ui

Version:

An opinionated UI component library for Svelte, built on top of [Ark UI](https://ark-ui.com) with additional components and features not available in the core Ark UI library.

23 lines (22 loc) • 852 B
import { createToaster } from '@ark-ui/svelte/toast'; const toaster = createToaster({ placement: 'bottom-end', pauseOnPageIdle: true, duration: 5000 }); const typeDurations = { success: 4000, error: 10000 }; function shorthand(type) { const duration = typeDurations[type]; // Only set when defined: an explicit `duration: undefined` would override the global default. const defaults = duration === undefined ? {} : { duration }; return (title, options) => typeof title === 'string' ? toaster.create({ ...defaults, ...options, title, type }) : toaster.create({ ...defaults, ...title, type }); } export const toast = Object.assign(toaster, { info: shorthand('info'), success: shorthand('success'), warning: shorthand('warning'), error: shorthand('error'), loading: shorthand('loading') });