@eclass/ui-kit 1.55.5 → 1.57.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
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";
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,106 @@ 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
  };
7264
+ const GLOBAL_TOASTER_FLAG = "_eclass_ui_kit_toaster_mounted";
7204
7265
  function FlashNotification({
7205
7266
  message,
7206
7267
  state,
7207
7268
  show,
7208
- maxContent
7269
+ m: m2,
7270
+ width
7209
7271
  }) {
7210
- const hasShownRef = useRef(false);
7272
+ const [shouldRenderToaster, setShouldRenderToaster] = useState(false);
7273
+ useEffect(() => {
7274
+ if (typeof window !== "undefined" && !window[GLOBAL_TOASTER_FLAG]) {
7275
+ window[GLOBAL_TOASTER_FLAG] = true;
7276
+ setShouldRenderToaster(true);
7277
+ }
7278
+ }, []);
7211
7279
  const showToast = useCallback(() => {
7212
7280
  n((t2) => /* @__PURE__ */ jsx(Alert, {
7213
7281
  isFlash: true,
7214
7282
  state,
7215
7283
  canDismiss: true,
7216
7284
  onClick: () => n.dismiss(t2.id),
7217
- maxContent,
7285
+ width,
7286
+ maxContent: !width,
7287
+ m: m2,
7218
7288
  children: message
7219
7289
  }), {
7220
- id: alertStates[state].id,
7221
- duration: handleTime(message)
7290
+ duration: state === "success" ? handleTime(message) : Infinity,
7291
+ id: alertStates[state].id
7222
7292
  });
7223
- }, [message, state, maxContent]);
7293
+ }, [message, state, width, m2]);
7224
7294
  useEffect(() => {
7225
- if (show && !hasShownRef.current) {
7295
+ if (show) {
7226
7296
  showToast();
7227
- hasShownRef.current = true;
7228
- }
7229
- if (!show) {
7230
- hasShownRef.current = false;
7231
7297
  }
7232
7298
  }, [show, showToast]);
7233
- return null;
7299
+ return /* @__PURE__ */ jsx(Fragment, {
7300
+ children: shouldRenderToaster && /* @__PURE__ */ jsx(Ie, {
7301
+ position: "top-center",
7302
+ toastOptions: {
7303
+ className: "toastContainer",
7304
+ style: {
7305
+ background: "transparent",
7306
+ boxShadow: "none",
7307
+ maxWidth: width != null ? width : "max-content"
7308
+ }
7309
+ }
7310
+ })
7311
+ });
7234
7312
  }
7235
- const useFlashNotification = ({
7236
- state,
7237
- message,
7238
- maxContent
7239
- }) => {
7313
+ const useFlashNotification = ({ state, message, width }) => {
7240
7314
  const [show, setShow] = useState(false);
7241
7315
  useEffect(() => {
7242
7316
  if (show) {
7317
+ const duration = state === "success" ? handleTime(message) : 1e3;
7243
7318
  const timeOut = setTimeout(() => {
7244
7319
  setShow(false);
7245
- }, handleTime(message));
7320
+ }, duration);
7246
7321
  return () => clearTimeout(timeOut);
7247
7322
  }
7248
- }, [message, show]);
7323
+ }, [message, show, state]);
7249
7324
  const active = () => {
7250
7325
  if (!show) {
7251
7326
  setShow(true);
@@ -7257,7 +7332,7 @@ const useFlashNotification = ({
7257
7332
  config: {
7258
7333
  state,
7259
7334
  message,
7260
- maxContent
7335
+ width
7261
7336
  }
7262
7337
  };
7263
7338
  };
@@ -7392,15 +7467,27 @@ const Modal = ({
7392
7467
  scrollBehavior: isInside ? "inside" : "outside",
7393
7468
  autoFocus,
7394
7469
  blockScrollOnMount: false,
7395
- children: [/* @__PURE__ */ jsx(ModalOverlay, {}), /* @__PURE__ */ jsx(ModalContent$1, {
7396
- ...modalConfig.contentProps,
7397
- children: /* @__PURE__ */ jsx(ModalContentBase, {
7398
- fixedButtons,
7399
- withoutMargin,
7400
- title,
7401
- closeOnOverlayClick,
7402
- fixedSubtitle,
7403
- children
7470
+ children: [/* @__PURE__ */ jsx(ModalOverlay, {}), /* @__PURE__ */ jsx(Box, {
7471
+ sx: {
7472
+ ...isInside && {
7473
+ ".uikit-modalContent": {
7474
+ pb: "16px !important"
7475
+ },
7476
+ ".uikit-modalButtons": {
7477
+ boxShadow: "0px 4px 16px 0px #5C5C5C33"
7478
+ }
7479
+ }
7480
+ },
7481
+ children: /* @__PURE__ */ jsx(ModalContent$1, {
7482
+ ...modalConfig.contentProps,
7483
+ children: /* @__PURE__ */ jsx(ModalContentBase, {
7484
+ fixedButtons,
7485
+ withoutMargin,
7486
+ title,
7487
+ closeOnOverlayClick,
7488
+ fixedSubtitle,
7489
+ children
7490
+ })
7404
7491
  })
7405
7492
  })]
7406
7493
  });