MCPcopy Create free account
hub / github.com/adobe/react-spectrum / addToast

Function addToast

packages/@react-spectrum/s2/src/Toast.tsx:118–140  ·  view source on GitHub ↗
(
  children: string,
  variant: SpectrumToastValue['variant'],
  options: ToastOptions = {}
)

Source from the content-addressed store, hash-verified

116}
117
118function addToast(
119 children: string,
120 variant: SpectrumToastValue['variant'],
121 options: ToastOptions = {}
122) {
123 let value = {
124 children,
125 variant,
126 actionLabel: options.actionLabel,
127 onAction: options.onAction,
128 shouldCloseOnAction: options.shouldCloseOnAction,
129 ...filterDOMProps(options)
130 };
131
132 // Minimum time of 5s from https://spectrum.adobe.com/page/toast/#Auto-dismissible
133 // Actionable toasts cannot be auto dismissed. That would fail WCAG SC 2.2.1.
134 // It is debatable whether non-actionable toasts would also fail.
135 let timeout =
136 options.timeout && !options.actionLabel ? Math.max(options.timeout, 5000) : undefined;
137 let queue = getGlobalToastQueue();
138 let key = queue.add(value, {timeout, onClose: options.onClose});
139 return () => queue.close(key);
140}
141
142type CloseFunction = () => void;
143

Callers 4

neutralFunction · 0.70
positiveFunction · 0.70
negativeFunction · 0.70
infoFunction · 0.70

Calls 4

filterDOMPropsFunction · 0.90
getGlobalToastQueueFunction · 0.70
addMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected