kaleido-ui 0.1.73 → 0.1.74

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.
@@ -1156,7 +1156,8 @@ function dispatch(action) {
1156
1156
  memoryState = reducer(memoryState, action);
1157
1157
  listeners.forEach((listener) => listener(memoryState));
1158
1158
  }
1159
- function toast({ duration = 4e3, ...props }) {
1159
+ function toast({ duration, ...props }) {
1160
+ const effectiveDuration = duration ?? (props.variant === "destructive" ? 12e3 : 4e3);
1160
1161
  const id = genId();
1161
1162
  const update = (props2) => dispatch({ type: "UPDATE_TOAST", toast: { ...props2, id } });
1162
1163
  const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
@@ -1166,14 +1167,14 @@ function toast({ duration = 4e3, ...props }) {
1166
1167
  ...props,
1167
1168
  id,
1168
1169
  open: true,
1169
- duration,
1170
+ duration: effectiveDuration,
1170
1171
  onOpenChange: (open) => {
1171
1172
  if (!open) dismiss();
1172
1173
  }
1173
1174
  }
1174
1175
  });
1175
- if (duration > 0) {
1176
- setTimeout(() => dismiss(), duration);
1176
+ if (effectiveDuration > 0) {
1177
+ setTimeout(() => dismiss(), effectiveDuration);
1177
1178
  }
1178
1179
  return { id, dismiss, update };
1179
1180
  }
@@ -1195,8 +1196,16 @@ function useToast() {
1195
1196
 
1196
1197
  // src/web/primitives/toaster.tsx
1197
1198
  var import_jsx_runtime14 = require("react/jsx-runtime");
1199
+ function toPlainText(node) {
1200
+ if (node == null || node === false) return "";
1201
+ if (typeof node === "string" || typeof node === "number") return String(node);
1202
+ if (Array.isArray(node)) return node.map(toPlainText).join("");
1203
+ const kids = node?.props?.children;
1204
+ return kids != null ? toPlainText(kids) : "";
1205
+ }
1198
1206
  function ToastWithProgress({ id, title, description, action, duration = 4e3, variant, ...props }) {
1199
1207
  const [progress, setProgress] = (0, import_react.useState)(100);
1208
+ const [copied, setCopied] = (0, import_react.useState)(false);
1200
1209
  (0, import_react.useEffect)(() => {
1201
1210
  const interval = 50;
1202
1211
  const decrement = interval / duration * 100;
@@ -1214,16 +1223,36 @@ function ToastWithProgress({ id, title, description, action, duration = 4e3, var
1214
1223
  }
1215
1224
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Icon, { name: "check_circle", size: "md", className: "text-primary" });
1216
1225
  };
1226
+ const showCopy = variant === "destructive";
1227
+ const copyText = () => {
1228
+ const text = [toPlainText(title), toPlainText(description)].filter(Boolean).join("\n");
1229
+ if (!text) return;
1230
+ void Promise.resolve(navigator?.clipboard?.writeText?.(text)).catch(() => {
1231
+ });
1232
+ setCopied(true);
1233
+ setTimeout(() => setCopied(false), 1500);
1234
+ };
1217
1235
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Toast, { ...props, variant, children: [
1218
1236
  /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "flex items-start gap-3 flex-1", children: [
1219
1237
  getIcon(),
1220
1238
  /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "grid gap-1 flex-1", children: [
1221
1239
  title && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ToastTitle, { children: title }),
1222
- description && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ToastDescription, { children: description })
1240
+ description && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ToastDescription, { className: "select-text", children: description })
1223
1241
  ] })
1224
1242
  ] }),
1225
1243
  /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "flex items-center gap-2 shrink-0", children: [
1226
1244
  action,
1245
+ showCopy && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
1246
+ "button",
1247
+ {
1248
+ type: "button",
1249
+ onClick: copyText,
1250
+ "aria-label": copied ? "Copied" : "Copy error",
1251
+ title: copied ? "Copied" : "Copy error",
1252
+ className: "rounded-md p-1 text-foreground/60 hover:text-foreground hover:bg-white/10 transition-colors",
1253
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Icon, { name: copied ? "check" : "content_copy", size: "sm" })
1254
+ }
1255
+ ),
1227
1256
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ToastClose, {})
1228
1257
  ] }),
1229
1258
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "absolute bottom-0 left-0 right-0 h-1 bg-white/10 overflow-hidden", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
package/dist/web/index.js CHANGED
@@ -972,7 +972,8 @@ function dispatch(action) {
972
972
  memoryState = reducer(memoryState, action);
973
973
  listeners.forEach((listener) => listener(memoryState));
974
974
  }
975
- function toast({ duration = 4e3, ...props }) {
975
+ function toast({ duration, ...props }) {
976
+ const effectiveDuration = duration ?? (props.variant === "destructive" ? 12e3 : 4e3);
976
977
  const id = genId();
977
978
  const update = (props2) => dispatch({ type: "UPDATE_TOAST", toast: { ...props2, id } });
978
979
  const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
@@ -982,14 +983,14 @@ function toast({ duration = 4e3, ...props }) {
982
983
  ...props,
983
984
  id,
984
985
  open: true,
985
- duration,
986
+ duration: effectiveDuration,
986
987
  onOpenChange: (open) => {
987
988
  if (!open) dismiss();
988
989
  }
989
990
  }
990
991
  });
991
- if (duration > 0) {
992
- setTimeout(() => dismiss(), duration);
992
+ if (effectiveDuration > 0) {
993
+ setTimeout(() => dismiss(), effectiveDuration);
993
994
  }
994
995
  return { id, dismiss, update };
995
996
  }
@@ -1011,8 +1012,16 @@ function useToast() {
1011
1012
 
1012
1013
  // src/web/primitives/toaster.tsx
1013
1014
  import { jsx as jsx14, jsxs as jsxs5 } from "react/jsx-runtime";
1015
+ function toPlainText(node) {
1016
+ if (node == null || node === false) return "";
1017
+ if (typeof node === "string" || typeof node === "number") return String(node);
1018
+ if (Array.isArray(node)) return node.map(toPlainText).join("");
1019
+ const kids = node?.props?.children;
1020
+ return kids != null ? toPlainText(kids) : "";
1021
+ }
1014
1022
  function ToastWithProgress({ id, title, description, action, duration = 4e3, variant, ...props }) {
1015
1023
  const [progress, setProgress] = useState2(100);
1024
+ const [copied, setCopied] = useState2(false);
1016
1025
  useEffect2(() => {
1017
1026
  const interval = 50;
1018
1027
  const decrement = interval / duration * 100;
@@ -1030,16 +1039,36 @@ function ToastWithProgress({ id, title, description, action, duration = 4e3, var
1030
1039
  }
1031
1040
  return /* @__PURE__ */ jsx14(Icon, { name: "check_circle", size: "md", className: "text-primary" });
1032
1041
  };
1042
+ const showCopy = variant === "destructive";
1043
+ const copyText = () => {
1044
+ const text = [toPlainText(title), toPlainText(description)].filter(Boolean).join("\n");
1045
+ if (!text) return;
1046
+ void Promise.resolve(navigator?.clipboard?.writeText?.(text)).catch(() => {
1047
+ });
1048
+ setCopied(true);
1049
+ setTimeout(() => setCopied(false), 1500);
1050
+ };
1033
1051
  return /* @__PURE__ */ jsxs5(Toast, { ...props, variant, children: [
1034
1052
  /* @__PURE__ */ jsxs5("div", { className: "flex items-start gap-3 flex-1", children: [
1035
1053
  getIcon(),
1036
1054
  /* @__PURE__ */ jsxs5("div", { className: "grid gap-1 flex-1", children: [
1037
1055
  title && /* @__PURE__ */ jsx14(ToastTitle, { children: title }),
1038
- description && /* @__PURE__ */ jsx14(ToastDescription, { children: description })
1056
+ description && /* @__PURE__ */ jsx14(ToastDescription, { className: "select-text", children: description })
1039
1057
  ] })
1040
1058
  ] }),
1041
1059
  /* @__PURE__ */ jsxs5("div", { className: "flex items-center gap-2 shrink-0", children: [
1042
1060
  action,
1061
+ showCopy && /* @__PURE__ */ jsx14(
1062
+ "button",
1063
+ {
1064
+ type: "button",
1065
+ onClick: copyText,
1066
+ "aria-label": copied ? "Copied" : "Copy error",
1067
+ title: copied ? "Copied" : "Copy error",
1068
+ className: "rounded-md p-1 text-foreground/60 hover:text-foreground hover:bg-white/10 transition-colors",
1069
+ children: /* @__PURE__ */ jsx14(Icon, { name: copied ? "check" : "content_copy", size: "sm" })
1070
+ }
1071
+ ),
1043
1072
  /* @__PURE__ */ jsx14(ToastClose, {})
1044
1073
  ] }),
1045
1074
  /* @__PURE__ */ jsx14("div", { className: "absolute bottom-0 left-0 right-0 h-1 bg-white/10 overflow-hidden", children: /* @__PURE__ */ jsx14(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaleido-ui",
3
- "version": "0.1.73",
3
+ "version": "0.1.74",
4
4
  "description": "KaleidoSwap shared UI library — design tokens, web components (Tailwind + Radix), and React Native components extending WDK UI Kit",
5
5
  "license": "MIT",
6
6
  "type": "module",