solid-toast
Advanced tools
Comparing version 0.4.0 to 0.4.1-alpha.0
@@ -9,18 +9,5 @@ 'use strict'; | ||
const isFunction = valOrFunction => typeof valOrFunction === 'function'; | ||
const resolveValue = (valOrFunction, arg) => isFunction(valOrFunction) ? valOrFunction(arg) : valOrFunction; | ||
exports.ActionType = void 0; | ||
(function (ActionType) { | ||
ActionType[ActionType["ADD_TOAST"] = 0] = "ADD_TOAST"; | ||
ActionType[ActionType["UPDATE_TOAST"] = 1] = "UPDATE_TOAST"; | ||
ActionType[ActionType["UPSERT_TOAST"] = 2] = "UPSERT_TOAST"; | ||
ActionType[ActionType["DISMISS_TOAST"] = 3] = "DISMISS_TOAST"; | ||
ActionType[ActionType["REMOVE_TOAST"] = 4] = "REMOVE_TOAST"; | ||
ActionType[ActionType["START_PAUSE"] = 5] = "START_PAUSE"; | ||
ActionType[ActionType["END_PAUSE"] = 6] = "END_PAUSE"; | ||
})(exports.ActionType || (exports.ActionType = {})); | ||
store$1.createStore({ | ||
options: [] | ||
}); | ||
const [store, setStore] = store$1.createStore({ | ||
@@ -44,3 +31,3 @@ toasts: [], | ||
dispatch({ | ||
type: exports.ActionType.DISMISS_TOAST, | ||
type: 'dismiss', | ||
toastId: toast.id | ||
@@ -55,3 +42,3 @@ }); | ||
dispatch({ | ||
type: exports.ActionType.DISMISS_TOAST, | ||
type: 'dismiss', | ||
toastId: toast.id | ||
@@ -70,3 +57,3 @@ }); | ||
dispatch({ | ||
type: exports.ActionType.REMOVE_TOAST, | ||
type: 'remove', | ||
toastId | ||
@@ -86,3 +73,3 @@ }); | ||
switch (action.type) { | ||
case exports.ActionType.ADD_TOAST: | ||
case 'add': | ||
setStore('toasts', t => { | ||
@@ -94,3 +81,3 @@ const toasts = t; | ||
case exports.ActionType.DISMISS_TOAST: | ||
case 'dismiss': | ||
const { | ||
@@ -114,3 +101,3 @@ toastId | ||
case exports.ActionType.REMOVE_TOAST: | ||
case 'remove': | ||
if (!action.toastId) { | ||
@@ -127,3 +114,3 @@ setStore('toasts', []); | ||
case exports.ActionType.UPDATE_TOAST: | ||
case 'update': | ||
if (action.toast.id) { | ||
@@ -141,8 +128,8 @@ unscheduleRemoval(action.toast.id); | ||
case exports.ActionType.UPSERT_TOAST: | ||
case 'upsert': | ||
store.toasts.find(t => t.id === action.toast.id) ? dispatch({ | ||
type: exports.ActionType.UPDATE_TOAST, | ||
type: 'update', | ||
toast: action.toast | ||
}) : dispatch({ | ||
type: exports.ActionType.ADD_TOAST, | ||
type: 'add', | ||
toast: action.toast | ||
@@ -152,3 +139,3 @@ }); | ||
case exports.ActionType.START_PAUSE: | ||
case 'start_pause': | ||
setStore(store$1.produce(s => { | ||
@@ -162,3 +149,3 @@ s.pausedAt = Date.now(); | ||
case exports.ActionType.END_PAUSE: | ||
case 'end_pause': | ||
const pauseInterval = action.time - (store.pausedAt || 0); | ||
@@ -258,3 +245,3 @@ setStore(store$1.produce(s => { | ||
dispatch({ | ||
type: exports.ActionType.UPDATE_TOAST, | ||
type: 'update', | ||
toast: { | ||
@@ -319,2 +306,6 @@ id: toast.id, | ||
const isFunction = valOrFunction => typeof valOrFunction === 'function'; | ||
const resolveValue = (valOrFunction, arg) => isFunction(valOrFunction) ? valOrFunction(arg) : valOrFunction; | ||
const [defaultOpts, setDefaultOpts] = solidJs.createSignal(defaultToasterOptions); | ||
@@ -347,3 +338,3 @@ const createToast = (message, type = 'blank', options) => ({ ...defaultToastOptions, | ||
dispatch({ | ||
type: exports.ActionType.UPSERT_TOAST, | ||
type: 'upsert', | ||
toast | ||
@@ -357,3 +348,2 @@ }); | ||
solidJs.untrack(() => toast$1); | ||
toast$1.error = createToastCreator('error'); | ||
@@ -366,3 +356,3 @@ toast$1.success = createToastCreator('success'); | ||
dispatch({ | ||
type: exports.ActionType.DISMISS_TOAST, | ||
type: 'dismiss', | ||
toastId | ||
@@ -392,3 +382,3 @@ }); | ||
dispatch({ | ||
type: exports.ActionType.REMOVE_TOAST, | ||
type: 'remove', | ||
toastId | ||
@@ -593,3 +583,3 @@ }); | ||
_el$.addEventListener("mouseleave", () => dispatch({ | ||
type: exports.ActionType.END_PAUSE, | ||
type: 'end_pause', | ||
time: Date.now() | ||
@@ -599,3 +589,3 @@ })); | ||
_el$.addEventListener("mouseenter", () => dispatch({ | ||
type: exports.ActionType.START_PAUSE, | ||
type: 'start_pause', | ||
time: Date.now() | ||
@@ -602,0 +592,0 @@ })); |
@@ -1,21 +0,8 @@ | ||
import { createSignal, untrack, createRoot, createEffect, onCleanup, For, Switch, Match, createMemo, onMount } from 'solid-js'; | ||
import { createSignal, createRoot, createEffect, onCleanup, For, Switch, Match, createMemo, onMount } from 'solid-js'; | ||
import { createStore, produce } from 'solid-js/store'; | ||
import { insert, createComponent, effect, style, className, template, mergeProps, spread, memo, setAttribute } from 'solid-js/web'; | ||
const isFunction = valOrFunction => typeof valOrFunction === 'function'; | ||
const resolveValue = (valOrFunction, arg) => isFunction(valOrFunction) ? valOrFunction(arg) : valOrFunction; | ||
let ActionType; | ||
(function (ActionType) { | ||
ActionType[ActionType["ADD_TOAST"] = 0] = "ADD_TOAST"; | ||
ActionType[ActionType["UPDATE_TOAST"] = 1] = "UPDATE_TOAST"; | ||
ActionType[ActionType["UPSERT_TOAST"] = 2] = "UPSERT_TOAST"; | ||
ActionType[ActionType["DISMISS_TOAST"] = 3] = "DISMISS_TOAST"; | ||
ActionType[ActionType["REMOVE_TOAST"] = 4] = "REMOVE_TOAST"; | ||
ActionType[ActionType["START_PAUSE"] = 5] = "START_PAUSE"; | ||
ActionType[ActionType["END_PAUSE"] = 6] = "END_PAUSE"; | ||
})(ActionType || (ActionType = {})); | ||
createStore({ | ||
options: [] | ||
}); | ||
const [store, setStore] = createStore({ | ||
@@ -39,3 +26,3 @@ toasts: [], | ||
dispatch({ | ||
type: ActionType.DISMISS_TOAST, | ||
type: 'dismiss', | ||
toastId: toast.id | ||
@@ -50,3 +37,3 @@ }); | ||
dispatch({ | ||
type: ActionType.DISMISS_TOAST, | ||
type: 'dismiss', | ||
toastId: toast.id | ||
@@ -65,3 +52,3 @@ }); | ||
dispatch({ | ||
type: ActionType.REMOVE_TOAST, | ||
type: 'remove', | ||
toastId | ||
@@ -81,3 +68,3 @@ }); | ||
switch (action.type) { | ||
case ActionType.ADD_TOAST: | ||
case 'add': | ||
setStore('toasts', t => { | ||
@@ -89,3 +76,3 @@ const toasts = t; | ||
case ActionType.DISMISS_TOAST: | ||
case 'dismiss': | ||
const { | ||
@@ -109,3 +96,3 @@ toastId | ||
case ActionType.REMOVE_TOAST: | ||
case 'remove': | ||
if (!action.toastId) { | ||
@@ -122,3 +109,3 @@ setStore('toasts', []); | ||
case ActionType.UPDATE_TOAST: | ||
case 'update': | ||
if (action.toast.id) { | ||
@@ -136,8 +123,8 @@ unscheduleRemoval(action.toast.id); | ||
case ActionType.UPSERT_TOAST: | ||
case 'upsert': | ||
store.toasts.find(t => t.id === action.toast.id) ? dispatch({ | ||
type: ActionType.UPDATE_TOAST, | ||
type: 'update', | ||
toast: action.toast | ||
}) : dispatch({ | ||
type: ActionType.ADD_TOAST, | ||
type: 'add', | ||
toast: action.toast | ||
@@ -147,3 +134,3 @@ }); | ||
case ActionType.START_PAUSE: | ||
case 'start_pause': | ||
setStore(produce(s => { | ||
@@ -157,3 +144,3 @@ s.pausedAt = Date.now(); | ||
case ActionType.END_PAUSE: | ||
case 'end_pause': | ||
const pauseInterval = action.time - (store.pausedAt || 0); | ||
@@ -253,3 +240,3 @@ setStore(produce(s => { | ||
dispatch({ | ||
type: ActionType.UPDATE_TOAST, | ||
type: 'update', | ||
toast: { | ||
@@ -314,2 +301,6 @@ id: toast.id, | ||
const isFunction = valOrFunction => typeof valOrFunction === 'function'; | ||
const resolveValue = (valOrFunction, arg) => isFunction(valOrFunction) ? valOrFunction(arg) : valOrFunction; | ||
const [defaultOpts, setDefaultOpts] = createSignal(defaultToasterOptions); | ||
@@ -342,3 +333,3 @@ const createToast = (message, type = 'blank', options) => ({ ...defaultToastOptions, | ||
dispatch({ | ||
type: ActionType.UPSERT_TOAST, | ||
type: 'upsert', | ||
toast | ||
@@ -352,3 +343,2 @@ }); | ||
untrack(() => toast$1); | ||
toast$1.error = createToastCreator('error'); | ||
@@ -361,3 +351,3 @@ toast$1.success = createToastCreator('success'); | ||
dispatch({ | ||
type: ActionType.DISMISS_TOAST, | ||
type: 'dismiss', | ||
toastId | ||
@@ -387,3 +377,3 @@ }); | ||
dispatch({ | ||
type: ActionType.REMOVE_TOAST, | ||
type: 'remove', | ||
toastId | ||
@@ -588,3 +578,3 @@ }); | ||
_el$.addEventListener("mouseleave", () => dispatch({ | ||
type: ActionType.END_PAUSE, | ||
type: 'end_pause', | ||
time: Date.now() | ||
@@ -594,3 +584,3 @@ })); | ||
_el$.addEventListener("mouseenter", () => dispatch({ | ||
type: ActionType.START_PAUSE, | ||
type: 'start_pause', | ||
time: Date.now() | ||
@@ -773,3 +763,3 @@ })); | ||
export { ActionType, Toaster, toast as default, resolveValue, toast$1 as toast }; | ||
export { Toaster, toast as default, resolveValue, toast$1 as toast }; | ||
//# sourceMappingURL=index.js.map |
@@ -18,3 +18,3 @@ import { createEffect, Match, Switch } from 'solid-js'; | ||
fill: 'forwards', | ||
easing: 'cubic-bezier(.21,1.02,.73,1)' | ||
easing: 'cubic-bezier(.21,1.02,.73,1)', | ||
}); | ||
@@ -29,3 +29,3 @@ } | ||
fill: 'forwards', | ||
easing: 'cubic-bezier(.06,.71,.55,1)' | ||
easing: 'cubic-bezier(.06,.71,.55,1)', | ||
}); | ||
@@ -32,0 +32,0 @@ } |
import { createMemo, onMount } from 'solid-js'; | ||
import { defaultToastOptions, dispatch } from '../core'; | ||
import { ActionType, resolveValue } from '../types'; | ||
import { resolveValue } from '../types'; | ||
import { getToastWrapperStyles, getWrapperYAxisOffset, updateToastHeight } from '../util'; | ||
@@ -21,6 +21,6 @@ import { ToastBar } from './ToastBar'; | ||
return (<div ref={el} style={positionStyle()} class={props.toast.visible ? 'sldt-active' : ''} onMouseEnter={() => dispatch({ | ||
type: ActionType.START_PAUSE, | ||
type: 'start_pause', | ||
time: Date.now(), | ||
})} onMouseLeave={() => dispatch({ | ||
type: ActionType.END_PAUSE, | ||
type: 'end_pause', | ||
time: Date.now(), | ||
@@ -27,0 +27,0 @@ })}> |
@@ -1,3 +0,5 @@ | ||
import { ActionType } from '../types'; | ||
import { createStore, produce as p } from 'solid-js/store'; | ||
const [initOptions, setInitOptions] = createStore({ | ||
options: [], | ||
}); | ||
const [store, setStore] = createStore({ | ||
@@ -19,3 +21,3 @@ toasts: [], | ||
dispatch({ | ||
type: ActionType.DISMISS_TOAST, | ||
type: 'dismiss', | ||
toastId: toast.id, | ||
@@ -28,3 +30,3 @@ }); | ||
dispatch({ | ||
type: ActionType.DISMISS_TOAST, | ||
type: 'dismiss', | ||
toastId: toast.id, | ||
@@ -43,3 +45,3 @@ }); | ||
dispatch({ | ||
type: ActionType.REMOVE_TOAST, | ||
type: 'remove', | ||
toastId, | ||
@@ -58,3 +60,3 @@ }); | ||
switch (action.type) { | ||
case ActionType.ADD_TOAST: | ||
case 'add': | ||
setStore('toasts', (t) => { | ||
@@ -65,3 +67,3 @@ const toasts = t; | ||
break; | ||
case ActionType.DISMISS_TOAST: | ||
case 'dismiss': | ||
const { toastId } = action; | ||
@@ -82,3 +84,3 @@ const toasts = store.toasts; | ||
break; | ||
case ActionType.REMOVE_TOAST: | ||
case 'remove': | ||
if (!action.toastId) { | ||
@@ -93,3 +95,3 @@ setStore('toasts', []); | ||
break; | ||
case ActionType.UPDATE_TOAST: | ||
case 'update': | ||
if (action.toast.id) { | ||
@@ -106,8 +108,8 @@ unscheduleRemoval(action.toast.id); | ||
break; | ||
case ActionType.UPSERT_TOAST: | ||
case 'upsert': | ||
store.toasts.find((t) => t.id === action.toast.id) | ||
? dispatch({ type: ActionType.UPDATE_TOAST, toast: action.toast }) | ||
: dispatch({ type: ActionType.ADD_TOAST, toast: action.toast }); | ||
? dispatch({ type: 'update', toast: action.toast }) | ||
: dispatch({ type: 'add', toast: action.toast }); | ||
break; | ||
case ActionType.START_PAUSE: | ||
case 'start_pause': | ||
setStore(p((s) => { | ||
@@ -120,3 +122,3 @@ s.pausedAt = Date.now(); | ||
break; | ||
case ActionType.END_PAUSE: | ||
case 'end_pause': | ||
const pauseInterval = action.time - (store.pausedAt || 0); | ||
@@ -133,2 +135,3 @@ setStore(p((s) => { | ||
}; | ||
export { store }; | ||
export const initOptionsDispatch = (action) => { }; | ||
export { store, initOptions }; |
@@ -1,3 +0,2 @@ | ||
import { createRoot, createSignal, untrack } from 'solid-js'; | ||
import { ActionType } from '../types'; | ||
import { createRoot, createSignal } from 'solid-js'; | ||
import { defaultToasterOptions, defaultToastOptions, defaultTimeouts } from './defaults'; | ||
@@ -31,3 +30,3 @@ import { generateID } from '../util'; | ||
const toast = createToast(message, type, { ...existingToast, duration: undefined, ...options }); | ||
dispatch({ type: ActionType.UPSERT_TOAST, toast }); | ||
dispatch({ type: 'upsert', toast }); | ||
return toast.id; | ||
@@ -37,3 +36,2 @@ }); | ||
const toast = (message, opts) => createToastCreator('blank')(message, opts); | ||
const test = untrack(() => toast); | ||
toast.error = createToastCreator('error'); | ||
@@ -45,3 +43,3 @@ toast.success = createToastCreator('success'); | ||
dispatch({ | ||
type: ActionType.DISMISS_TOAST, | ||
type: 'dismiss', | ||
toastId, | ||
@@ -70,3 +68,3 @@ }); | ||
dispatch({ | ||
type: ActionType.REMOVE_TOAST, | ||
type: 'remove', | ||
toastId, | ||
@@ -73,0 +71,0 @@ }); |
@@ -1,10 +0,1 @@ | ||
export var ActionType; | ||
(function (ActionType) { | ||
ActionType[ActionType["ADD_TOAST"] = 0] = "ADD_TOAST"; | ||
ActionType[ActionType["UPDATE_TOAST"] = 1] = "UPDATE_TOAST"; | ||
ActionType[ActionType["UPSERT_TOAST"] = 2] = "UPSERT_TOAST"; | ||
ActionType[ActionType["DISMISS_TOAST"] = 3] = "DISMISS_TOAST"; | ||
ActionType[ActionType["REMOVE_TOAST"] = 4] = "REMOVE_TOAST"; | ||
ActionType[ActionType["START_PAUSE"] = 5] = "START_PAUSE"; | ||
ActionType[ActionType["END_PAUSE"] = 6] = "END_PAUSE"; | ||
})(ActionType || (ActionType = {})); | ||
export {}; |
import { setDefaultOpts, defaultOpts, store, dispatch, defaultToasterOptions } from '../core'; | ||
import { ActionType } from '../types'; | ||
export const generateID = (() => { | ||
@@ -42,3 +41,3 @@ let count = 0; | ||
dispatch({ | ||
type: ActionType.UPDATE_TOAST, | ||
type: 'update', | ||
toast: { id: toast.id, height: boundingRect.height }, | ||
@@ -45,0 +44,0 @@ }); |
/// <reference types="node" /> | ||
import { State, Action } from '../types'; | ||
import { State, Action, ToastOptions } from '../types'; | ||
declare const initOptions: { | ||
options: ToastOptions[]; | ||
}; | ||
declare const store: State; | ||
export declare const createTimers: () => NodeJS.Timeout[]; | ||
export declare const dispatch: (action: Action) => void; | ||
export { store }; | ||
export declare const initOptionsDispatch: (action: Action) => void; | ||
export { store, initOptions }; |
@@ -1,31 +0,22 @@ | ||
import { Toast } from './'; | ||
export declare enum ActionType { | ||
ADD_TOAST = 0, | ||
UPDATE_TOAST = 1, | ||
UPSERT_TOAST = 2, | ||
DISMISS_TOAST = 3, | ||
REMOVE_TOAST = 4, | ||
START_PAUSE = 5, | ||
END_PAUSE = 6 | ||
} | ||
export declare type Action = { | ||
type: ActionType.ADD_TOAST; | ||
import { Toast, ToastOptions } from './'; | ||
export type Action = { | ||
type: 'add'; | ||
toast: Toast; | ||
} | { | ||
type: ActionType.UPSERT_TOAST; | ||
type: 'upsert'; | ||
toast: Toast; | ||
} | { | ||
type: ActionType.UPDATE_TOAST; | ||
type: 'update'; | ||
toast: Partial<Toast>; | ||
} | { | ||
type: ActionType.DISMISS_TOAST; | ||
type: 'dismiss'; | ||
toastId?: string; | ||
} | { | ||
type: ActionType.REMOVE_TOAST; | ||
type: 'remove'; | ||
toastId?: string; | ||
} | { | ||
type: ActionType.START_PAUSE; | ||
type: 'start_pause'; | ||
time: number; | ||
} | { | ||
type: ActionType.END_PAUSE; | ||
type: 'end_pause'; | ||
time: number; | ||
@@ -37,1 +28,4 @@ }; | ||
} | ||
export interface InitOptions { | ||
options: ToastOptions[]; | ||
} |
import { JSX } from 'solid-js'; | ||
export declare type ToastType = 'success' | 'error' | 'loading' | 'blank' | 'custom'; | ||
export declare type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right'; | ||
export declare type Renderable = JSX.Element | string | null; | ||
export declare type ValueFunction<TValue, TArg> = (arg: TArg) => TValue; | ||
export declare type ValueOrFunction<TValue, TArg> = TValue | ValueFunction<TValue, TArg>; | ||
export type ToastType = 'success' | 'error' | 'loading' | 'blank' | 'custom'; | ||
export type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right'; | ||
export type Renderable = JSX.Element | string | null; | ||
export type ValueFunction<TValue, TArg> = (arg: TArg) => TValue; | ||
export type ValueOrFunction<TValue, TArg> = TValue | ValueFunction<TValue, TArg>; | ||
export declare const resolveValue: <TValue, TArg>(valOrFunction: ValueOrFunction<TValue, TArg>, arg: TArg) => TValue; | ||
@@ -13,10 +13,6 @@ export interface IconTheme { | ||
export interface Toast { | ||
type: ToastType; | ||
id: string; | ||
message: ValueOrFunction<Renderable, Toast>; | ||
icon?: Renderable; | ||
duration?: number; | ||
pauseDuration: number; | ||
paused: boolean; | ||
position?: ToastPosition; | ||
message: ValueOrFunction<Renderable, Toast>; | ||
ariaProps: { | ||
@@ -26,5 +22,10 @@ role: 'status' | 'alert'; | ||
}; | ||
className?: string; | ||
style?: JSX.CSSProperties; | ||
className?: string; | ||
position?: ToastPosition; | ||
unmountDelay: number; | ||
iconTheme?: IconTheme; | ||
pauseDuration: number; | ||
paused: boolean; | ||
type: ToastType; | ||
createdAt: number; | ||
@@ -34,11 +35,10 @@ updatedAt?: number; | ||
height?: number; | ||
unmountDelay: number; | ||
} | ||
export declare type ToastOptions = Partial<Pick<Toast, 'id' | 'icon' | 'duration' | 'ariaProps' | 'className' | 'style' | 'position' | 'unmountDelay' | 'iconTheme'>>; | ||
export declare type ToastTimeouts = { | ||
export type ToastOptions = Partial<Pick<Toast, 'id' | 'icon' | 'duration' | 'ariaProps' | 'className' | 'style' | 'position' | 'unmountDelay' | 'iconTheme'>>; | ||
export type ToastTimeouts = { | ||
[key in ToastType]: number; | ||
}; | ||
export declare type DefaultToastOptions = ToastOptions; | ||
export declare type Message = ValueOrFunction<Renderable, Toast>; | ||
export declare type ToastHandler = (message: Message, options?: ToastOptions) => string; | ||
export type DefaultToastOptions = ToastOptions; | ||
export type Message = ValueOrFunction<Renderable, Toast>; | ||
export type ToastHandler = (message: Message, options?: ToastOptions) => string; | ||
export interface ToasterProps { | ||
@@ -58,2 +58,2 @@ position?: ToastPosition; | ||
} | ||
export declare type IconProps = Partial<IconTheme>; | ||
export type IconProps = Partial<IconTheme>; |
{ | ||
"name": "solid-toast", | ||
"version": "0.4.0", | ||
"version": "0.4.1-alpha.0", | ||
"description": "Customizable Toast Notifications for SolidJS", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
@@ -1,4 +0,10 @@ | ||
import { State, Action, ActionType, Toast } from '../types'; | ||
import { State, Toast, Action, ToastOptions } from '../types'; | ||
import { createStore, produce as p } from 'solid-js/store'; | ||
const [initOptions, setInitOptions] = createStore<{ | ||
options: ToastOptions[]; | ||
}>({ | ||
options: [], | ||
}); | ||
const [store, setStore] = createStore<State>({ | ||
@@ -21,3 +27,3 @@ toasts: [], | ||
dispatch({ | ||
type: ActionType.DISMISS_TOAST, | ||
type: 'dismiss', | ||
toastId: toast.id, | ||
@@ -31,3 +37,3 @@ }); | ||
dispatch({ | ||
type: ActionType.DISMISS_TOAST, | ||
type: 'dismiss', | ||
toastId: toast.id, | ||
@@ -49,3 +55,3 @@ }); | ||
dispatch({ | ||
type: ActionType.REMOVE_TOAST, | ||
type: 'remove', | ||
toastId, | ||
@@ -66,3 +72,3 @@ }); | ||
switch (action.type) { | ||
case ActionType.ADD_TOAST: | ||
case 'add': | ||
setStore('toasts', (t) => { | ||
@@ -73,3 +79,3 @@ const toasts = t as Toast[]; | ||
break; | ||
case ActionType.DISMISS_TOAST: | ||
case 'dismiss': | ||
const { toastId } = action; | ||
@@ -98,3 +104,3 @@ const toasts = store.toasts; | ||
break; | ||
case ActionType.REMOVE_TOAST: | ||
case 'remove': | ||
if (!action.toastId) { | ||
@@ -109,3 +115,3 @@ setStore('toasts', []); | ||
break; | ||
case ActionType.UPDATE_TOAST: | ||
case 'update': | ||
if (action.toast.id) { | ||
@@ -127,16 +133,18 @@ unscheduleRemoval(action.toast.id); | ||
break; | ||
case ActionType.UPSERT_TOAST: | ||
case 'upsert': | ||
store.toasts.find((t) => t.id === action.toast.id) | ||
? dispatch({ type: ActionType.UPDATE_TOAST, toast: action.toast }) | ||
: dispatch({ type: ActionType.ADD_TOAST, toast: action.toast }); | ||
? dispatch({ type: 'update', toast: action.toast }) | ||
: dispatch({ type: 'add', toast: action.toast }); | ||
break; | ||
case ActionType.START_PAUSE: | ||
setStore(p((s) => { | ||
s.pausedAt = Date.now(); | ||
s.toasts.forEach((t) => { | ||
t.paused = true; | ||
}); | ||
})); | ||
case 'start_pause': | ||
setStore( | ||
p((s) => { | ||
s.pausedAt = Date.now(); | ||
s.toasts.forEach((t) => { | ||
t.paused = true; | ||
}); | ||
}) | ||
); | ||
break; | ||
case ActionType.END_PAUSE: | ||
case 'end_pause': | ||
const pauseInterval = action.time - (store.pausedAt || 0); | ||
@@ -156,2 +164,3 @@ setStore( | ||
export { store }; | ||
export const initOptionsDispatch = (action: Action) => {}; | ||
export { store, initOptions }; |
@@ -1,3 +0,3 @@ | ||
import { createRoot, createSignal, untrack } from 'solid-js'; | ||
import { ToasterProps, Message, ToastType, ToastOptions, Toast, ToastHandler, ActionType } from '../types'; | ||
import { createRoot, createSignal } from 'solid-js'; | ||
import { ToasterProps, Message, ToastType, ToastOptions, Toast, ToastHandler } from '../types'; | ||
import { defaultToasterOptions, defaultToastOptions, defaultTimeouts } from './defaults'; | ||
@@ -38,3 +38,3 @@ import { generateID } from '../util'; | ||
const toast = createToast(message, type, { ...existingToast, duration: undefined, ...options }); | ||
dispatch({ type: ActionType.UPSERT_TOAST, toast }); | ||
dispatch({ type: 'upsert', toast }); | ||
return toast.id; | ||
@@ -45,3 +45,2 @@ }); | ||
const toast = (message: Message, opts?: ToastOptions) => createToastCreator('blank')(message, opts); | ||
const test = untrack(() => toast); | ||
@@ -55,3 +54,3 @@ toast.error = createToastCreator('error'); | ||
dispatch({ | ||
type: ActionType.DISMISS_TOAST, | ||
type: 'dismiss', | ||
toastId, | ||
@@ -92,3 +91,3 @@ }); | ||
dispatch({ | ||
type: ActionType.REMOVE_TOAST, | ||
type: 'remove', | ||
toastId, | ||
@@ -95,0 +94,0 @@ }); |
@@ -1,40 +0,30 @@ | ||
import { Toast } from './'; | ||
import { Toast, ToastOptions } from './'; | ||
export enum ActionType { | ||
ADD_TOAST, | ||
UPDATE_TOAST, | ||
UPSERT_TOAST, | ||
DISMISS_TOAST, | ||
REMOVE_TOAST, | ||
START_PAUSE, | ||
END_PAUSE, | ||
} | ||
export type Action = | ||
| { | ||
type: ActionType.ADD_TOAST; | ||
type: 'add'; | ||
toast: Toast; | ||
} | ||
| { | ||
type: ActionType.UPSERT_TOAST; | ||
type: 'upsert'; | ||
toast: Toast; | ||
} | ||
| { | ||
type: ActionType.UPDATE_TOAST; | ||
type: 'update'; | ||
toast: Partial<Toast>; | ||
} | ||
| { | ||
type: ActionType.DISMISS_TOAST; | ||
type: 'dismiss'; | ||
toastId?: string; | ||
} | ||
| { | ||
type: ActionType.REMOVE_TOAST; | ||
type: 'remove'; | ||
toastId?: string; | ||
} | ||
| { | ||
type: ActionType.START_PAUSE; | ||
type: 'start_pause'; | ||
time: number; | ||
} | ||
| { | ||
type: ActionType.END_PAUSE; | ||
type: 'end_pause'; | ||
time: number; | ||
@@ -47,1 +37,5 @@ }; | ||
} | ||
export interface InitOptions { | ||
options: ToastOptions[]; | ||
} |
@@ -24,11 +24,6 @@ import { JSX } from 'solid-js'; | ||
export interface Toast { | ||
type: ToastType; | ||
id: string; | ||
message: ValueOrFunction<Renderable, Toast>; | ||
icon?: Renderable; | ||
duration?: number; | ||
pauseDuration: number; | ||
paused: boolean; | ||
position?: ToastPosition; | ||
message: ValueOrFunction<Renderable, Toast>; | ||
ariaProps: { | ||
@@ -38,8 +33,11 @@ role: 'status' | 'alert'; | ||
}; | ||
className?: string; | ||
style?: JSX.CSSProperties; | ||
className?: string; | ||
position?: ToastPosition; | ||
unmountDelay: number; | ||
iconTheme?: IconTheme; | ||
pauseDuration: number; | ||
paused: boolean; | ||
type: ToastType; | ||
createdAt: number; | ||
@@ -49,3 +47,2 @@ updatedAt?: number; | ||
height?: number; | ||
unmountDelay: number; | ||
} | ||
@@ -52,0 +49,0 @@ |
import { setDefaultOpts, defaultOpts, store, dispatch, defaultToasterOptions } from '../core'; | ||
import { ActionType, Toast, ToasterProps, ToastPosition } from '../types'; | ||
import { Toast, ToasterProps, ToastPosition } from '../types'; | ||
import { JSX } from 'solid-js'; | ||
@@ -47,3 +47,3 @@ | ||
dispatch({ | ||
type: ActionType.UPDATE_TOAST, | ||
type: 'update', | ||
toast: { id: toast.id, height: boundingRect.height }, | ||
@@ -50,0 +50,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
197654
2744