@eclass/ui-kit 1.55.5 → 1.56.0

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.
@@ -1,6 +1,6 @@
1
- import { extendTheme, Box, CircularProgress, Icon, Button, useMediaQuery, Tooltip, Flex, Stack, Center, Image, Text as Text$1, HStack, Heading, List, ListItem, Link, Modal as Modal$1, ModalContent as ModalContent$1, ModalHeader, ModalCloseButton, ModalBody, ModalFooter, ModalOverlay, useDisclosure, LinkBox, LinkOverlay, MenuButton, MenuGroup, Menu, MenuList } from "@chakra-ui/react";
1
+ import { extendTheme, Box, CircularProgress, Icon, Button, useMediaQuery, Tooltip, Flex, Stack, Center, Image, Text as Text$1, HStack, Heading, List, ListItem, Link, Modal as Modal$1, ModalContent as ModalContent$1, ModalHeader, ModalCloseButton, ModalBody, ModalFooter, ModalOverlay, useDisclosure, LinkBox, LinkOverlay, Portal, MenuButton, MenuGroup, Menu, MenuList } from "@chakra-ui/react";
2
2
  import * as React$1 from "react";
3
- import React__default, { useEffect, useRef, useCallback, useState } from "react";
3
+ import React__default, { useEffect, useCallback, useState } from "react";
4
4
  const main = {
5
5
  deepSkyBlue: "#0189FF",
6
6
  azureRadiance: "#017BE5",
@@ -6766,7 +6766,8 @@ function Alert({
6766
6766
  m: m2,
6767
6767
  endTextLink,
6768
6768
  onClickLink,
6769
- sx
6769
+ sx,
6770
+ width
6770
6771
  }) {
6771
6772
  const [isMobile] = useMediaQuery("(max-width: 425px)");
6772
6773
  const handleClick = () => {
@@ -6787,8 +6788,9 @@ function Alert({
6787
6788
  gap: !isFlash ? "16px" : void 0,
6788
6789
  justifyContent: !isMobile ? "space-between" : void 0,
6789
6790
  margin: m2,
6790
- width: maxContent ? "max-content" : fullWidth ? "100%" : "fit-content",
6791
- maxWidth: fullWidth ? "none" : "796px",
6791
+ mx: isFlash ? "auto" : void 0,
6792
+ width: width != null ? width : maxContent ? "max-content" : fullWidth ? "100%" : "fit-content",
6793
+ maxWidth: fullWidth ? "none" : (width != null ? width : maxContent) ? "none" : "796px",
6792
6794
  p: "1rem",
6793
6795
  pr: canDismiss ? "1.75rem" : "1rem",
6794
6796
  position: "relative",
@@ -6977,6 +6979,17 @@ var S = /* @__PURE__ */ new Map(), X = 1e3, $ = (e2) => {
6977
6979
  P = v(P, e2), A.forEach((t2) => {
6978
6980
  t2(P);
6979
6981
  });
6982
+ }, Y = { blank: 4e3, error: 4e3, success: 2e3, loading: 1 / 0, custom: 4e3 }, I = (e2 = {}) => {
6983
+ let [t2, o2] = useState(P);
6984
+ useEffect(() => (A.push(o2), () => {
6985
+ let a2 = A.indexOf(o2);
6986
+ a2 > -1 && A.splice(a2, 1);
6987
+ }), [t2]);
6988
+ let s2 = t2.toasts.map((a2) => {
6989
+ var r, c2;
6990
+ return { ...e2, ...e2[a2.type], ...a2, duration: a2.duration || ((r = e2[a2.type]) == null ? void 0 : r.duration) || (e2 == null ? void 0 : e2.duration) || Y[a2.type], style: { ...e2.style, ...(c2 = e2[a2.type]) == null ? void 0 : c2.style, ...a2.style } };
6991
+ });
6992
+ return { ...t2, toasts: s2 };
6980
6993
  };
6981
6994
  var G = (e2, t2 = "blank", o2) => ({ createdAt: Date.now(), visible: true, type: t2, ariaProps: { role: "status", "aria-live": "polite" }, message: e2, pauseDuration: 0, ...o2, id: (o2 == null ? void 0 : o2.id) || U() }), h = (e2) => (t2, o2) => {
6982
6995
  let s2 = G(t2, e2, o2);
@@ -6996,6 +7009,37 @@ n.promise = (e2, t2, o2) => {
6996
7009
  n.error(T(t2.error, a2), { id: s2, ...o2, ...o2 == null ? void 0 : o2.error });
6997
7010
  }), e2;
6998
7011
  };
7012
+ var Z = (e2, t2) => {
7013
+ u({ type: 1, toast: { id: e2, height: t2 } });
7014
+ }, ee = () => {
7015
+ u({ type: 5, time: Date.now() });
7016
+ }, D = (e2) => {
7017
+ let { toasts: t2, pausedAt: o2 } = I(e2);
7018
+ useEffect(() => {
7019
+ if (o2)
7020
+ return;
7021
+ let r = Date.now(), c2 = t2.map((i2) => {
7022
+ if (i2.duration === 1 / 0)
7023
+ return;
7024
+ let d2 = (i2.duration || 0) + i2.pauseDuration - (r - i2.createdAt);
7025
+ if (d2 < 0) {
7026
+ i2.visible && n.dismiss(i2.id);
7027
+ return;
7028
+ }
7029
+ return setTimeout(() => n.dismiss(i2.id), d2);
7030
+ });
7031
+ return () => {
7032
+ c2.forEach((i2) => i2 && clearTimeout(i2));
7033
+ };
7034
+ }, [t2, o2]);
7035
+ let s2 = useCallback(() => {
7036
+ o2 && u({ type: 6, time: Date.now() });
7037
+ }, [o2]), a2 = useCallback((r, c2) => {
7038
+ let { reverseOrder: i2 = false, gutter: d2 = 8, defaultPosition: p2 } = c2 || {}, g2 = t2.filter((m2) => (m2.position || p2) === (r.position || p2) && m2.height), E = g2.findIndex((m2) => m2.id === r.id), x = g2.filter((m2, R) => R < E && m2.visible).length;
7039
+ return g2.filter((m2) => m2.visible).slice(...i2 ? [x + 1] : [0, x]).reduce((m2, R) => m2 + (R.height || 0) + d2, 0);
7040
+ }, [t2]);
7041
+ return { toasts: t2, handlers: { updateHeight: Z, startPause: ee, endPause: s2, calculateOffset: a2 } };
7042
+ };
6999
7043
  var oe = h$1`
7000
7044
  from {
7001
7045
  transform: scale(0) rotate(45deg);
@@ -7177,75 +7221,101 @@ var ye = (e2) => `
7177
7221
  `, Ae = (e2, t2) => {
7178
7222
  let s2 = e2.includes("top") ? 1 : -1, [a2, r] = b() ? [he, xe] : [ye(s2), ge(s2)];
7179
7223
  return { animation: t2 ? `${h$1(a2)} 0.35s cubic-bezier(.21,1.02,.73,1) forwards` : `${h$1(r)} 0.4s forwards cubic-bezier(.06,.71,.55,1)` };
7180
- };
7181
- React$1.memo(({ toast: e2, position: t2, style: o2, children: s2 }) => {
7224
+ }, F = React$1.memo(({ toast: e2, position: t2, style: o2, children: s2 }) => {
7182
7225
  let a2 = e2.height ? Ae(e2.position || t2 || "top-center", e2.visible) : { opacity: 0 }, r = React$1.createElement(M, { toast: e2 }), c2 = React$1.createElement(Se, { ...e2.ariaProps }, T(e2.message, e2));
7183
7226
  return React$1.createElement(be, { className: e2.className, style: { ...a2, ...o2, ...e2.style } }, typeof s2 == "function" ? s2({ icon: r, message: c2 }) : React$1.createElement(React$1.Fragment, null, r, c2));
7184
7227
  });
7185
7228
  m(React$1.createElement);
7186
- u$1`
7229
+ var Ee = ({ id: e2, className: t2, style: o2, onHeightUpdate: s2, children: a2 }) => {
7230
+ let r = React$1.useCallback((c2) => {
7231
+ if (c2) {
7232
+ let i2 = () => {
7233
+ let d2 = c2.getBoundingClientRect().height;
7234
+ s2(e2, d2);
7235
+ };
7236
+ i2(), new MutationObserver(i2).observe(c2, { subtree: true, childList: true, characterData: true });
7237
+ }
7238
+ }, [e2, s2]);
7239
+ return React$1.createElement("div", { ref: r, className: t2, style: o2 }, a2);
7240
+ }, Re = (e2, t2) => {
7241
+ let o2 = e2.includes("top"), s2 = o2 ? { top: 0 } : { bottom: 0 }, a2 = e2.includes("center") ? { justifyContent: "center" } : e2.includes("right") ? { justifyContent: "flex-end" } : {};
7242
+ return { left: 0, right: 0, display: "flex", position: "absolute", transition: b() ? void 0 : "all 230ms cubic-bezier(.21,1.02,.73,1)", transform: `translateY(${t2 * (o2 ? 1 : -1)}px)`, ...s2, ...a2 };
7243
+ }, ve = u$1`
7187
7244
  z-index: 9999;
7188
7245
  > * {
7189
7246
  pointer-events: auto;
7190
7247
  }
7191
- `;
7248
+ `, O = 16, Ie = ({ reverseOrder: e2, position: t2 = "top-center", toastOptions: o2, gutter: s2, children: a2, containerStyle: r, containerClassName: c2 }) => {
7249
+ let { toasts: i2, handlers: d2 } = D(o2);
7250
+ return React$1.createElement("div", { style: { position: "fixed", zIndex: 9999, top: O, left: O, right: O, bottom: O, pointerEvents: "none", ...r }, className: c2, onMouseEnter: d2.startPause, onMouseLeave: d2.endPause }, i2.map((p2) => {
7251
+ let g2 = p2.position || t2, E = d2.calculateOffset(p2, { reverseOrder: e2, gutter: s2, defaultPosition: t2 }), x = Re(g2, E);
7252
+ return React$1.createElement(Ee, { id: p2.id, key: p2.id, onHeightUpdate: d2.updateHeight, className: p2.visible ? ve : "", style: x }, p2.type === "custom" ? T(p2.message, p2) : a2 ? a2(p2) : React$1.createElement(F, { toast: p2, position: g2 }));
7253
+ }));
7254
+ };
7192
7255
  const handleTime = (message) => {
7193
- function countWords(input) {
7194
- var _a, _b;
7195
- const wordCount = (_b = (_a = input.match(/(\w+)/g)) == null ? void 0 : _a.length) != null ? _b : 0;
7196
- return wordCount;
7197
- }
7198
- let time = 3e3;
7199
- if (message && countWords(message) > 5) {
7200
- time = 6e3;
7201
- }
7202
- return time;
7256
+ if (!message)
7257
+ return 3e3;
7258
+ const words = message.trim().split(/\s+/).length;
7259
+ const wordsPerMinute = 150;
7260
+ const baseMinutes = words / wordsPerMinute;
7261
+ const totalMs = Math.round(baseMinutes * 60 * 1e3);
7262
+ return Math.max(3e3, totalMs);
7203
7263
  };
7204
7264
  function FlashNotification({
7205
7265
  message,
7206
7266
  state,
7207
7267
  show,
7208
- maxContent
7268
+ m: m2,
7269
+ width
7209
7270
  }) {
7210
- const hasShownRef = useRef(false);
7211
7271
  const showToast = useCallback(() => {
7212
7272
  n((t2) => /* @__PURE__ */ jsx(Alert, {
7213
7273
  isFlash: true,
7214
7274
  state,
7215
7275
  canDismiss: true,
7216
7276
  onClick: () => n.dismiss(t2.id),
7217
- maxContent,
7277
+ width,
7278
+ m: m2,
7218
7279
  children: message
7219
7280
  }), {
7220
- id: alertStates[state].id,
7221
- duration: handleTime(message)
7281
+ duration: state === "success" ? handleTime(message) : Infinity,
7282
+ id: alertStates[state].id
7222
7283
  });
7223
- }, [message, state, maxContent]);
7284
+ }, [message, state, width, m2]);
7224
7285
  useEffect(() => {
7225
- if (show && !hasShownRef.current) {
7286
+ if (show) {
7226
7287
  showToast();
7227
- hasShownRef.current = true;
7228
- }
7229
- if (!show) {
7230
- hasShownRef.current = false;
7231
7288
  }
7232
7289
  }, [show, showToast]);
7233
- return null;
7290
+ return /* @__PURE__ */ jsx(Portal, {
7291
+ children: /* @__PURE__ */ jsx(Ie, {
7292
+ position: "top-center",
7293
+ toastOptions: {
7294
+ className: "toastContainer",
7295
+ style: {
7296
+ background: "transparent",
7297
+ boxShadow: "none"
7298
+ }
7299
+ }
7300
+ })
7301
+ });
7234
7302
  }
7235
7303
  const useFlashNotification = ({
7236
7304
  state,
7237
7305
  message,
7238
- maxContent
7306
+ maxContent,
7307
+ width
7239
7308
  }) => {
7240
7309
  const [show, setShow] = useState(false);
7241
7310
  useEffect(() => {
7242
7311
  if (show) {
7312
+ const duration = state === "success" ? handleTime(message) : 1e3;
7243
7313
  const timeOut = setTimeout(() => {
7244
7314
  setShow(false);
7245
- }, handleTime(message));
7315
+ }, duration);
7246
7316
  return () => clearTimeout(timeOut);
7247
7317
  }
7248
- }, [message, show]);
7318
+ }, [message, show, state]);
7249
7319
  const active = () => {
7250
7320
  if (!show) {
7251
7321
  setShow(true);
@@ -7257,7 +7327,8 @@ const useFlashNotification = ({
7257
7327
  config: {
7258
7328
  state,
7259
7329
  message,
7260
- maxContent
7330
+ maxContent,
7331
+ width
7261
7332
  }
7262
7333
  };
7263
7334
  };