@stll/ui 0.52.0 → 0.52.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,8 +13,8 @@ import { VariantProps } from "class-variance-authority";
13
13
  */
14
14
  declare const buttonAccessibleDisabledClass = "cursor-not-allowed opacity-64";
15
15
  declare const buttonVariants: (props?: ({
16
- size?: "default" | "sm" | "lg" | "icon" | "xs" | "row" | "chip" | "icon-lg" | "icon-sm" | "icon-xl" | "icon-xs" | "xl" | null | undefined;
17
- variant?: "link" | "default" | "outline" | "destructive" | "muted" | "destructive-outline" | "destructive-ghost" | "ghost" | "secondary" | null | undefined;
16
+ size?: "default" | "sm" | "lg" | "icon" | "chip" | "icon-lg" | "icon-sm" | "icon-xl" | "icon-xs" | "row" | "xl" | "xs" | null | undefined;
17
+ variant?: "link" | "default" | "destructive" | "destructive-outline" | "destructive-ghost" | "ghost" | "muted" | "outline" | "secondary" | null | undefined;
18
18
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
19
19
  type ButtonProps = {
20
20
  variant?: VariantProps<typeof buttonVariants>["variant"];
@@ -5,7 +5,7 @@ import { VariantProps } from "class-variance-authority";
5
5
  //#region src/components/input-group.d.ts
6
6
  declare const InputGroup: ({ className, ...props }: React$1.ComponentProps<"div">) => React$1.JSX.Element;
7
7
  declare const inputGroupAddonVariants: (props?: ({
8
- align?: "inline-start" | "block-end" | "block-start" | "inline-end" | null | undefined;
8
+ align?: "inline-end" | "inline-start" | "block-end" | "block-start" | null | undefined;
9
9
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
10
10
  declare const InputGroupAddon: ({ className, align, ...props }: React$1.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) => React$1.JSX.Element;
11
11
  declare const InputGroupText: ({ className, ...props }: React$1.ComponentProps<"span">) => React$1.JSX.Element;
@@ -3,6 +3,12 @@ import { Toast, ToastManagerAddOptions } from "@base-ui/react/toast";
3
3
  //#region src/components/toast.d.ts
4
4
  type ToastData = {
5
5
  tooltipStyle?: boolean;
6
+ timeoutPolicy?: {
7
+ type: "automatic";
8
+ } | {
9
+ type: "explicit";
10
+ timeout: number;
11
+ };
6
12
  };
7
13
  declare const TOAST_RIGHT_OFFSET_VAR = "--stella-toast-right-offset";
8
14
  declare const TOAST_ICONS: {
@@ -20,7 +26,7 @@ type ToastAction = {
20
26
  };
21
27
  type ToastActionProps = ToastManagerAddOptions<ToastData>["actionProps"];
22
28
  type ToastOptions = Omit<ToastManagerAddOptions<ToastData>, "actionProps" | "title" | "type"> & {
23
- action?: ToastAction;
29
+ action?: ToastAction | undefined;
24
30
  actionProps?: ToastActionProps;
25
31
  };
26
32
  type ToastUpdateOptions = Partial<ToastOptions> & {
@@ -12,6 +12,7 @@ import { Toast } from "@base-ui/react/toast";
12
12
  const toastManager = Toast.createToastManager();
13
13
  const anchoredToastManager = Toast.createToastManager();
14
14
  const TOAST_RIGHT_OFFSET_VAR = "--stella-toast-right-offset";
15
+ const ERROR_TOAST_TIMEOUT_MS = 8e3;
15
16
  const TOAST_ICONS = {
16
17
  error: /* @__PURE__ */ jsx(CircleAlertIcon, { className: "text-destructive" }),
17
18
  info: /* @__PURE__ */ jsx(InfoIcon, { className: "text-info" }),
@@ -51,7 +52,7 @@ const stellaToast = Object.assign((title, options) => addToast(title, void 0, op
51
52
  },
52
53
  success: (title, options) => addToast(title, "success", options),
53
54
  update: (id, options) => {
54
- toastManager.update(id, normalizeToastUpdateOptions(options));
55
+ toastManager.update(id, (previous) => normalizeToastUpdateOptions(options, previous));
55
56
  },
56
57
  warning: (title, options) => addToast(title, "warning", options)
57
58
  });
@@ -242,34 +243,51 @@ const subscribeWindowFocus = (onChange) => {
242
243
  };
243
244
  const readWindowFocus = () => document.hasFocus();
244
245
  const readServerWindowFocus = () => true;
245
- function normalizeToastAddOptions({ action, actionProps, timeout, type, ...options }) {
246
+ function normalizeToastAddOptions(options) {
247
+ const { action, actionProps, data, timeout, type, ...addOptions } = options;
246
248
  return {
247
- ...options,
249
+ ...addOptions,
248
250
  ...normalizeToastActionProps({
249
251
  action,
250
252
  actionProps
251
253
  }),
252
- timeout: normalizeToastTimeout(timeout ?? getDefaultToastTimeout(type)),
254
+ data: {
255
+ ...data,
256
+ timeoutPolicy: toastTimeoutPolicy(timeout)
257
+ },
258
+ timeout: normalizeToastTimeout(timeout ?? getDefaultToastTimeout(options)),
253
259
  type
254
260
  };
255
261
  }
256
- function normalizeToastUpdateOptions(options) {
257
- const { action, actionProps, timeout, type, ...updateOptions } = options;
258
- const normalizedTimeout = timeout === void 0 ? normalizeDefaultToastUpdateTimeout(type) : normalizeToastTimeout(timeout);
259
- return {
262
+ function normalizeToastUpdateOptions(options, previous) {
263
+ const { action, actionProps, data, timeout, type, ...updateOptions } = options;
264
+ const update = {
260
265
  ...updateOptions,
261
266
  ...normalizeToastActionProps({
262
267
  action,
263
268
  actionProps,
264
269
  includeEmptyActionProps: Object.hasOwn(options, "action") || Object.hasOwn(options, "actionProps")
265
270
  }),
266
- ...type === void 0 ? {} : { type },
267
- ...normalizedTimeout === void 0 ? {} : { timeout: normalizedTimeout }
271
+ ...type === void 0 ? {} : { type }
272
+ };
273
+ const timeoutPolicy = timeout === void 0 ? previous.data?.timeoutPolicy ?? toastTimeoutPolicy(void 0) : toastTimeoutPolicy(timeout);
274
+ return {
275
+ ...update,
276
+ data: {
277
+ ...Object.hasOwn(options, "data") ? data : previous.data,
278
+ timeoutPolicy
279
+ },
280
+ timeout: timeoutPolicy.type === "explicit" ? timeoutPolicy.timeout : getDefaultToastTimeout({
281
+ ...previous,
282
+ ...update
283
+ })
268
284
  };
269
285
  }
270
- function normalizeDefaultToastUpdateTimeout(type) {
271
- if (type === void 0) return;
272
- return normalizeToastTimeout(getDefaultToastTimeout(type));
286
+ function toastTimeoutPolicy(timeout) {
287
+ return timeout === void 0 ? { type: "automatic" } : {
288
+ type: "explicit",
289
+ timeout: normalizeToastTimeout(timeout)
290
+ };
273
291
  }
274
292
  function normalizeToastActionProps({ action, actionProps, includeEmptyActionProps = false }) {
275
293
  if (action === void 0) return actionProps === void 0 && !includeEmptyActionProps ? {} : { actionProps };
@@ -279,8 +297,14 @@ function normalizeToastActionProps({ action, actionProps, includeEmptyActionProp
279
297
  onClick: action.onClick
280
298
  } };
281
299
  }
282
- function getDefaultToastTimeout(type) {
283
- if (type === "loading" || type === "error") return 0;
300
+ /**
301
+ * A short plain error closes on its own like any notice. An error that carries
302
+ * detail (a description, rich content such as a provider reason to copy) or an
303
+ * action stays until dismissed, so it is never gone before it can be read.
304
+ */
305
+ function getDefaultToastTimeout({ action, actionProps, description, title, type }) {
306
+ if (type === "loading") return 0;
307
+ if (type === "error") return typeof title === "string" && (description === void 0 || description === null) && action === void 0 && actionProps === void 0 ? ERROR_TOAST_TIMEOUT_MS : 0;
284
308
  if (type === "warning") return 6e3;
285
309
  return 4e3;
286
310
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/ui",
3
- "version": "0.52.0",
3
+ "version": "0.52.1",
4
4
  "description": "Stella's design system: bidi-aware React primitives built on Base UI, the dockable inspector pane, and the Tailwind v4 theme they are styled with.",
5
5
  "keywords": [
6
6
  "base-ui",