@eztrak/shared 0.16.6 → 0.17.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.
@@ -318,7 +318,144 @@ function classifyError(error) {
318
318
  };
319
319
  }
320
320
  var BRAND_ORANGE = "#FF7335";
321
- var CANCEL_RED = "#ff0000";
321
+ var DANGER_RED = "#DC2626";
322
+ var DANGER_ICON_BG = "#FEE2E2";
323
+ var CANCEL_BG = "#ffffff";
324
+ var CANCEL_TEXT = "#374151";
325
+ var CONFIRM_STYLE_ID = "eztrak-confirm-alert-styles";
326
+ function cssSize(value, fallback) {
327
+ if (value === void 0) return fallback;
328
+ return typeof value === "number" ? `${value}px` : value;
329
+ }
330
+ var DEFAULT_CONFIRM_ICONS = {
331
+ warning: `
332
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
333
+ <path d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z" />
334
+ </svg>
335
+ `.trim()
336
+ };
337
+ var VARIANT_DEFAULTS = {
338
+ brand: {
339
+ confirmButtonText: "Yes",
340
+ confirmButtonColor: BRAND_ORANGE,
341
+ confirmButtonTextColor: "#ffffff",
342
+ cancelButtonColor: CANCEL_BG,
343
+ cancelButtonTextColor: CANCEL_TEXT,
344
+ iconColor: BRAND_ORANGE,
345
+ iconBgColor: "#FFEDD5",
346
+ iconHtml: DEFAULT_CONFIRM_ICONS.warning,
347
+ icon: "warning"
348
+ },
349
+ danger: {
350
+ title: "Delete this item",
351
+ confirmButtonText: "Yes, delete it!",
352
+ confirmButtonColor: DANGER_RED,
353
+ confirmButtonTextColor: "#ffffff",
354
+ cancelButtonColor: CANCEL_BG,
355
+ cancelButtonTextColor: CANCEL_TEXT,
356
+ iconColor: DANGER_RED,
357
+ iconBgColor: DANGER_ICON_BG,
358
+ iconHtml: DEFAULT_CONFIRM_ICONS.warning,
359
+ icon: "warning",
360
+ showLoaderOnConfirm: true
361
+ }
362
+ };
363
+ function ensureConfirmAlertStyles() {
364
+ if (typeof document === "undefined") return;
365
+ if (document.getElementById(CONFIRM_STYLE_ID)) return;
366
+ const style = document.createElement("style");
367
+ style.id = CONFIRM_STYLE_ID;
368
+ style.textContent = `
369
+ .ez-confirm-popup {
370
+ border-radius: var(--ez-confirm-radius, 1rem) !important;
371
+ padding: 1.5rem !important;
372
+ max-width: 24rem !important;
373
+ width: var(--ez-confirm-width, 100%) !important;
374
+ box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25) !important;
375
+ }
376
+ .ez-confirm-title {
377
+ font-size: 1.125rem !important;
378
+ font-weight: 600 !important;
379
+ color: #111827 !important;
380
+ margin: 0 0 0.25rem !important;
381
+ padding: 0 !important;
382
+ }
383
+ .ez-confirm-html {
384
+ font-size: 0.875rem !important;
385
+ color: #6b7280 !important;
386
+ margin: 0 0 1.5rem !important;
387
+ }
388
+ .ez-confirm-icon {
389
+ border: none !important;
390
+ background: var(--ez-confirm-icon-bg, #fee2e2) !important;
391
+ color: var(--ez-confirm-icon-color, #dc2626) !important;
392
+ width: 3rem !important;
393
+ height: 3rem !important;
394
+ margin: 0 auto 1rem !important;
395
+ border-radius: 9999px !important;
396
+ }
397
+ .ez-confirm-icon .swal2-icon-content {
398
+ font-size: inherit !important;
399
+ display: flex !important;
400
+ align-items: center !important;
401
+ justify-content: center !important;
402
+ color: inherit !important;
403
+ }
404
+ .ez-confirm-actions {
405
+ width: 100% !important;
406
+ margin: 0 !important;
407
+ gap: 0.75rem !important;
408
+ }
409
+ .ez-confirm-confirm,
410
+ .ez-confirm-cancel {
411
+ flex: 1 1 0 !important;
412
+ margin: 0 !important;
413
+ border-radius: var(--ez-confirm-btn-radius, 0.5rem) !important;
414
+ font-size: 0.875rem !important;
415
+ font-weight: 500 !important;
416
+ padding: 0.625rem 1rem !important;
417
+ box-shadow: none !important;
418
+ }
419
+ .ez-confirm-confirm {
420
+ background: var(--ez-confirm-confirm-bg, #ff7335) !important;
421
+ color: var(--ez-confirm-confirm-fg, #fff) !important;
422
+ border: none !important;
423
+ }
424
+ .ez-confirm-confirm:hover {
425
+ filter: brightness(0.95);
426
+ }
427
+ .ez-confirm-cancel {
428
+ background: var(--ez-confirm-cancel-bg, #fff) !important;
429
+ color: var(--ez-confirm-cancel-fg, #374151) !important;
430
+ border: 1px solid #d1d5db !important;
431
+ }
432
+ .ez-confirm-cancel:hover {
433
+ background: #f9fafb !important;
434
+ }
435
+ .ez-confirm-popup .swal2-input {
436
+ margin-top: var(--ez-confirm-input-mt, 0) !important;
437
+ margin-right: var(--ez-confirm-input-mr, 0) !important;
438
+ margin-bottom: var(--ez-confirm-input-mb, 1.25rem) !important;
439
+ margin-left: var(--ez-confirm-input-ml, 0) !important;
440
+ }
441
+ `;
442
+ document.head.appendChild(style);
443
+ }
444
+ function pick(explicit, fromVariant, fallback) {
445
+ if (explicit !== void 0) return explicit;
446
+ if (fromVariant !== void 0) return fromVariant;
447
+ return fallback;
448
+ }
449
+ function mergeCustomClass(base, extra) {
450
+ if (!extra || typeof extra !== "object") return base;
451
+ const merged = { ...base };
452
+ for (const [key, value] of Object.entries(extra)) {
453
+ if (typeof value === "string" && value) {
454
+ merged[key] = merged[key] ? `${merged[key]} ${value}` : value;
455
+ }
456
+ }
457
+ return merged;
458
+ }
322
459
  function getConfirmErrorMessage(error) {
323
460
  if (error && typeof error === "object") {
324
461
  const err = error;
@@ -327,23 +464,63 @@ function getConfirmErrorMessage(error) {
327
464
  return "Something went wrong. Please try again.";
328
465
  }
329
466
  function confirmationAlert(onConfirm, options = {}) {
330
- const {
331
- title = options.inputExpectedValue ? "Confirmation Required" : "Are you sure?",
332
- text,
333
- html,
334
- icon = "warning",
335
- confirmButtonText = "Yes",
336
- cancelButtonText = "Cancel",
337
- confirmButtonColor = BRAND_ORANGE,
338
- cancelButtonColor = CANCEL_RED,
339
- showLoaderOnConfirm = false,
340
- inputExpectedValue,
341
- inputPlaceholder = "Type confirmation text to proceed",
342
- reverseButtons,
343
- focusCancel,
344
- zIndex
345
- } = options;
467
+ ensureConfirmAlertStyles();
468
+ const variant = options.variant ?? "brand";
469
+ const vd = VARIANT_DEFAULTS[variant];
470
+ const inputExpectedValue = options.inputExpectedValue;
346
471
  const hasInput = Boolean(inputExpectedValue);
472
+ const title = pick(
473
+ options.title,
474
+ vd.title,
475
+ hasInput ? "Confirmation Required" : "Delete this item"
476
+ );
477
+ const text = options.text;
478
+ const html = options.html ?? options.children;
479
+ const icon = pick(options.icon, vd.icon, "warning");
480
+ const iconHtml = pick(options.iconHtml, vd.iconHtml, void 0);
481
+ const iconColor = pick(options.iconColor, vd.iconColor, BRAND_ORANGE);
482
+ const iconBgColor = pick(options.iconBgColor, vd.iconBgColor, "#FFEDD5");
483
+ const showIcon = options.showIcon !== false;
484
+ const confirmButtonText = pick(options.confirmButtonText, vd.confirmButtonText, "Yes");
485
+ const cancelButtonText = options.cancelButtonText ?? "Cancel";
486
+ const confirmButtonColor = pick(
487
+ options.confirmButtonColor,
488
+ vd.confirmButtonColor,
489
+ BRAND_ORANGE
490
+ );
491
+ const cancelButtonColor = pick(
492
+ options.cancelButtonColor,
493
+ vd.cancelButtonColor,
494
+ CANCEL_BG
495
+ );
496
+ const confirmButtonTextColor = pick(
497
+ options.confirmButtonTextColor,
498
+ vd.confirmButtonTextColor,
499
+ "#ffffff"
500
+ );
501
+ const cancelButtonTextColor = pick(
502
+ options.cancelButtonTextColor,
503
+ vd.cancelButtonTextColor,
504
+ CANCEL_TEXT
505
+ );
506
+ const showCancelButton = options.showCancelButton !== false;
507
+ const showLoaderOnConfirm = pick(
508
+ options.showLoaderOnConfirm,
509
+ vd.showLoaderOnConfirm,
510
+ false
511
+ );
512
+ const inputPlaceholder = options.inputPlaceholder ?? "Type confirmation text to proceed";
513
+ const reverseButtons = options.reverseButtons ?? false;
514
+ const focusCancel = options.focusCancel;
515
+ const zIndex = options.zIndex;
516
+ const width = options.width;
517
+ const borderRadius = cssSize(options.borderRadius, "1rem");
518
+ const buttonBorderRadius = cssSize(options.buttonBorderRadius, "0.5rem");
519
+ const inputMarginTop = cssSize(options.inputMarginTop, "0");
520
+ const inputMarginRight = cssSize(options.inputMarginRight, "0");
521
+ const inputMarginBottom = cssSize(options.inputMarginBottom, "1.25rem");
522
+ const inputMarginLeft = cssSize(options.inputMarginLeft, "0");
523
+ const onCancel = options.onCancel;
347
524
  const useLoader = showLoaderOnConfirm || hasInput;
348
525
  const inputHtml = html ?? (hasInput ? `
349
526
  ${text ? `<p style="margin-bottom: 15px;">${text}</p>` : ""}
@@ -351,24 +528,60 @@ function confirmationAlert(onConfirm, options = {}) {
351
528
  Please type "<span style="color: ${BRAND_ORANGE}; font-weight: bold;">${inputExpectedValue}</span>" to confirm:
352
529
  </p>
353
530
  ` : void 0);
531
+ const baseCustomClass = {
532
+ popup: "ez-confirm-popup",
533
+ title: "ez-confirm-title",
534
+ htmlContainer: "ez-confirm-html",
535
+ actions: "ez-confirm-actions",
536
+ confirmButton: "ez-confirm-confirm",
537
+ cancelButton: "ez-confirm-cancel",
538
+ icon: "ez-confirm-icon"
539
+ };
354
540
  const swalOptions = {
355
541
  title,
356
- icon,
357
- showCancelButton: true,
542
+ showCancelButton,
358
543
  confirmButtonText,
359
544
  cancelButtonText,
360
545
  confirmButtonColor,
361
546
  cancelButtonColor,
362
547
  reverseButtons,
363
548
  focusCancel,
549
+ customClass: mergeCustomClass(baseCustomClass, options.customClass),
364
550
  allowOutsideClick: () => !import_sweetalert2.default.isLoading(),
365
551
  allowEscapeKey: () => !import_sweetalert2.default.isLoading(),
366
552
  didOpen: () => {
553
+ const popup = import_sweetalert2.default.getPopup();
554
+ if (popup) {
555
+ popup.style.setProperty("--ez-confirm-confirm-bg", confirmButtonColor);
556
+ popup.style.setProperty("--ez-confirm-confirm-fg", confirmButtonTextColor);
557
+ popup.style.setProperty("--ez-confirm-cancel-bg", cancelButtonColor);
558
+ popup.style.setProperty("--ez-confirm-cancel-fg", cancelButtonTextColor);
559
+ popup.style.setProperty("--ez-confirm-icon-color", iconColor);
560
+ popup.style.setProperty("--ez-confirm-icon-bg", iconBgColor);
561
+ popup.style.setProperty("--ez-confirm-radius", borderRadius);
562
+ popup.style.setProperty("--ez-confirm-btn-radius", buttonBorderRadius);
563
+ popup.style.setProperty("--ez-confirm-input-mt", inputMarginTop);
564
+ popup.style.setProperty("--ez-confirm-input-mr", inputMarginRight);
565
+ popup.style.setProperty("--ez-confirm-input-mb", inputMarginBottom);
566
+ popup.style.setProperty("--ez-confirm-input-ml", inputMarginLeft);
567
+ if (width != null) {
568
+ popup.style.setProperty(
569
+ "--ez-confirm-width",
570
+ typeof width === "number" ? `${width}px` : String(width)
571
+ );
572
+ }
573
+ }
367
574
  if (zIndex == null) return;
368
575
  const container = import_sweetalert2.default.getContainer();
369
576
  if (container) container.style.zIndex = String(zIndex);
370
577
  }
371
578
  };
579
+ if (showIcon) {
580
+ swalOptions.icon = icon;
581
+ if (iconHtml) {
582
+ swalOptions.iconHtml = iconHtml;
583
+ }
584
+ }
372
585
  if (hasInput) {
373
586
  swalOptions.html = inputHtml;
374
587
  swalOptions.input = "text";
@@ -403,6 +616,10 @@ function confirmationAlert(onConfirm, options = {}) {
403
616
  void import_sweetalert2.default.fire(swalOptions).then((result) => {
404
617
  if (result.isConfirmed && !useLoader) {
405
618
  void Promise.resolve(onConfirm());
619
+ return;
620
+ }
621
+ if (result.isDismissed) {
622
+ onCancel?.();
406
623
  }
407
624
  });
408
625
  }
@@ -1826,10 +2043,7 @@ function Sidebar({
1826
2043
  "div",
1827
2044
  {
1828
2045
  "data-sidebar-item": item.name,
1829
- className: cn(
1830
- "has-sub-items max-w-full min-w-0 flex flex-col",
1831
- collapsed ? "my-1" : "my-2"
1832
- ),
2046
+ className: "has-sub-items max-w-full min-w-0 flex flex-col",
1833
2047
  children: [
1834
2048
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1835
2049
  ToolTip,