@starasia/date 2.0.0 → 2.0.2

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.
package/dist/date.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsxs as $, jsx as l, Fragment as G } from "react/jsx-runtime";
2
- import { useState as F, useRef as E, useEffect as D, forwardRef as j } from "react";
2
+ import { useState as F, useRef as T, useEffect as D, forwardRef as j } from "react";
3
3
  const S = `@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
4
4
 
5
5
  * {
@@ -13,10 +13,10 @@ const S = `@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wg
13
13
  --sa-date-radius: var(--sa-radii-md, 0.5rem);
14
14
  --sa-date-radius-lg: var(--sa-radii-lg, 0.75rem);
15
15
  --sa-date-bg: var(--sa-background-primary, #ffffff);
16
- --sa-date-border-color: rgba(120, 134, 127, 0.2);
17
- --sa-date-border-disabled: rgba(120, 134, 127, 0.2);
18
- --sa-date-bg-disabled: rgba(120, 134, 127, 0.1);
19
- --sa-date-shadow: var(--sa-shadow-md, 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1));
16
+ --sa-date-border-color: var(--sa-color-gray-alpha-a20, #78867f33);
17
+ --sa-date-border-disabled: var(--sa-color-gray-alpha-a20, #78867f33);
18
+ --sa-date-bg-disabled: var(--sa-color-gray-alpha-a10, #78867f1a);
19
+ --sa-date-shadow: var(--sa-shadow-md, 0 4px 6px -1px #0000001a, 0 2px 4px -2px #0000001a);
20
20
  --sa-date-text-primary: var(--sa-color-gray-700, #6b6e76);
21
21
  --sa-date-text-subtle: var(--sa-color-gray-500, #8c8f97);
22
22
  --sa-date-text-muted: var(--sa-color-gray-300, #dddee1);
@@ -254,7 +254,7 @@ const S = `@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wg
254
254
  .starasia-calendar-input-container-warning {
255
255
  border-color: var(--sa-date-border-warning) !important;
256
256
  }
257
- `, A = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], N = [
257
+ `, J = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], N = [
258
258
  "January",
259
259
  "February",
260
260
  "March",
@@ -281,8 +281,8 @@ const S = `@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wg
281
281
  "Nov",
282
282
  "Dec"
283
283
  ];
284
- function J(a) {
285
- const [e, t] = F(a), s = E(null), o = (g) => {
284
+ function A(a) {
285
+ const [e, t] = F(a), s = T(null), o = (g) => {
286
286
  s.current && !s.current.contains(g.target) && t(!1);
287
287
  };
288
288
  return D(() => (document.addEventListener("click", o, !0), () => {
@@ -296,7 +296,7 @@ const z = "starasia-calendar-input-styles", q = (a) => {
296
296
  }
297
297
  };
298
298
  q(S);
299
- const T = (a) => {
299
+ const E = (a) => {
300
300
  if (a === "sm")
301
301
  return 16;
302
302
  if (a === "md")
@@ -304,7 +304,7 @@ const T = (a) => {
304
304
  if (a === "lg")
305
305
  return 20;
306
306
  }, K = (a) => {
307
- const { size: e = "md", status: t = "default", variant: s = "outline", ...o } = a, g = E(null), f = () => {
307
+ const { size: e = "md", status: t = "default", variant: s = "outline", ...o } = a, g = T(null), f = () => {
308
308
  g.current && o.onClick && (g.current.focus(), o.onClick(""));
309
309
  };
310
310
  return /* @__PURE__ */ $(
@@ -317,15 +317,15 @@ const T = (a) => {
317
317
  "svg",
318
318
  {
319
319
  xmlns: "http://www.w3.org/2000/svg",
320
- width: T(e),
321
- height: T(e),
320
+ width: E(e),
321
+ height: E(e),
322
322
  viewBox: "0 0 20 20",
323
323
  fill: "none",
324
324
  children: /* @__PURE__ */ l(
325
325
  "path",
326
326
  {
327
327
  d: "M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",
328
- stroke: "#939E99",
328
+ stroke: "var(--sa-color-gray-500, #8c8f97)",
329
329
  strokeWidth: "1.5",
330
330
  strokeLinecap: "round",
331
331
  strokeLinejoin: "round"
@@ -347,15 +347,15 @@ const T = (a) => {
347
347
  "svg",
348
348
  {
349
349
  xmlns: "http://www.w3.org/2000/svg",
350
- width: T(e),
351
- height: T(e),
350
+ width: E(e),
351
+ height: E(e),
352
352
  viewBox: "0 0 20 20",
353
353
  fill: "none",
354
354
  children: /* @__PURE__ */ l(
355
355
  "path",
356
356
  {
357
357
  d: "M3.33331 7.5L9.99998 14.1667L16.6666 7.5",
358
- stroke: "#939E99",
358
+ stroke: "var(--sa-color-gray-500, #8c8f97)",
359
359
  strokeWidth: "1.5",
360
360
  strokeLinecap: "round",
361
361
  strokeLinejoin: "round"
@@ -374,17 +374,17 @@ const T = (a) => {
374
374
  onChange: o,
375
375
  minDate: g,
376
376
  maxDate: f,
377
- input: v
377
+ input: b
378
378
  }) => {
379
379
  var u, r, d;
380
380
  let h = new Date(a.getFullYear(), a.getMonth(), 1), n = h.getDay(), w = [];
381
- const b = a.getMonth();
381
+ const v = a.getMonth();
382
382
  for (let c = 0; c < 42; c++) {
383
383
  c === 0 && n === 0 ? h.setDate(h.getDate() - 7) : c === 0 ? h.setDate(
384
384
  h.getDate() + (c - n)
385
385
  ) : h.setDate(h.getDate() + 1);
386
- let m = {
387
- currentMonth: h.getMonth() === b,
386
+ let y = {
387
+ currentMonth: h.getMonth() === v,
388
388
  date: new Date(h),
389
389
  month: h.getMonth(),
390
390
  number: h.getDate(),
@@ -392,24 +392,24 @@ const T = (a) => {
392
392
  year: h.getFullYear(),
393
393
  isDisabled: g && h < g || f && h > f
394
394
  };
395
- w.push(m);
395
+ w.push(y);
396
396
  }
397
397
  const x = (c) => {
398
398
  e(c);
399
399
  }, M = (c) => {
400
400
  var i;
401
- let m = { ...t };
402
- if (m.from && m.to)
403
- m = { from: c, to: null };
401
+ let y = { ...t };
402
+ if (y.from && y.to)
403
+ y = { from: c, to: null };
404
404
  else {
405
- const p = ((i = m.from) == null ? void 0 : i.getTime()) || 0;
406
- c.getTime() > p ? m = { from: m.from, to: c } : m = { from: c, to: m.from };
405
+ const p = ((i = y.from) == null ? void 0 : i.getTime()) || 0;
406
+ c.getTime() > p ? y = { from: y.from, to: c } : y = { from: c, to: y.from };
407
407
  }
408
- s(m), o(m);
408
+ s(y), o(y);
409
409
  };
410
410
  return /* @__PURE__ */ $("div", { className: "starasia-calendar-days-preivew", children: [
411
- /* @__PURE__ */ l("div", { className: "starasia-calendar-days-name-preivew", children: A.map((c, m) => /* @__PURE__ */ l("p", { children: c }, m)) }),
412
- /* @__PURE__ */ l("div", { className: "starasia-calendar-days-number-preivew", children: w.map((c, m) => {
411
+ /* @__PURE__ */ l("div", { className: "starasia-calendar-days-name-preivew", children: J.map((c, y) => /* @__PURE__ */ l("p", { children: c }, y)) }),
412
+ /* @__PURE__ */ l("div", { className: "starasia-calendar-days-number-preivew", children: w.map((c, y) => {
413
413
  var C;
414
414
  const i = c.date.getTime() > t.from.getTime() && c.date.getTime() < (((C = t.to) == null ? void 0 : C.getTime()) || t.from.getTime()), p = c.isDisabled;
415
415
  return /* @__PURE__ */ l(
@@ -417,18 +417,18 @@ const T = (a) => {
417
417
  {
418
418
  className: `${c.currentMonth ? "starasia-calendar-days-current" : "starasia-calendar-days"} ${c.selected ? "starasia-calendar-days-active" : ""}`,
419
419
  style: {
420
- backgroundColor: i ? "rgba(100, 181, 246, 0.1)" : "",
420
+ backgroundColor: i ? "var(--sa-color-info-alpha-a10, #64b5f61a)" : "",
421
421
  pointerEvents: p ? "none" : void 0,
422
422
  cursor: p ? "not-allowed" : "pointer",
423
- color: p ? "#ccc" : i ? "#b0b0b0" : "",
424
- ...v ? {} : { width: "100%" }
423
+ color: p ? "var(--sa-color-gray-400, #b7b9be)" : i ? "var(--sa-color-gray-500, #8c8f97)" : "",
424
+ ...b ? {} : { width: "100%" }
425
425
  },
426
426
  onClick: () => {
427
427
  p || (x(c.date), M(c.date));
428
428
  },
429
429
  children: c.number
430
430
  },
431
- m
431
+ y
432
432
  );
433
433
  }) })
434
434
  ] });
@@ -440,11 +440,11 @@ const T = (a) => {
440
440
  dateRange: o,
441
441
  setDateRange: g,
442
442
  onChange: f,
443
- minDate: v,
443
+ minDate: b,
444
444
  maxDate: h,
445
445
  input: n
446
446
  }) => {
447
- const w = o.from.getFullYear(), b = a.getFullYear(), x = (u) => {
447
+ const w = o.from.getFullYear(), v = a.getFullYear(), x = (u) => {
448
448
  t ? (M(u), e(u)) : (s("days"), e(u));
449
449
  }, M = (u) => {
450
450
  var d;
@@ -458,21 +458,21 @@ const T = (a) => {
458
458
  g(r), f(r);
459
459
  };
460
460
  return /* @__PURE__ */ l("div", { className: "starasia-calendar-months-preview", children: N.map((u, r) => {
461
- var m, i, p;
462
- const d = new Date(b, r).getTime() > o.from.getTime() && new Date(b, r).getTime() < (((m = o.to) == null ? void 0 : m.getTime()) || o.from.getTime()), c = v && new Date(b, r) < v || h && new Date(b, r) > h;
461
+ var y, i, p;
462
+ const d = new Date(v, r).getTime() > o.from.getTime() && new Date(v, r).getTime() < (((y = o.to) == null ? void 0 : y.getTime()) || o.from.getTime()), c = b && new Date(v, r) < b || h && new Date(v, r) > h;
463
463
  return /* @__PURE__ */ l(
464
464
  "p",
465
465
  {
466
- className: w === b && (r === ((i = o.from) == null ? void 0 : i.getMonth()) || r === ((p = o.to) == null ? void 0 : p.getMonth())) ? "starasia-calendar-months-active" : "",
466
+ className: w === v && (r === ((i = o.from) == null ? void 0 : i.getMonth()) || r === ((p = o.to) == null ? void 0 : p.getMonth())) ? "starasia-calendar-months-active" : "",
467
467
  style: {
468
- backgroundColor: d ? "rgba(100, 181, 246, 0.1)" : "",
468
+ backgroundColor: d ? "var(--sa-color-info-alpha-a10, #64b5f61a)" : "",
469
469
  pointerEvents: c ? "none" : void 0,
470
470
  cursor: c ? "not-allowed" : "pointer",
471
- color: c ? "#ccc" : d ? "#b0b0b0" : "",
471
+ color: c ? "var(--sa-color-gray-400, #b7b9be)" : d ? "var(--sa-color-gray-500, #8c8f97)" : "",
472
472
  ...n ? {} : { width: "100%" }
473
473
  },
474
474
  onClick: () => {
475
- c || x(new Date(b, r));
475
+ c || x(new Date(v, r));
476
476
  },
477
477
  children: u.slice(0, 3)
478
478
  },
@@ -490,19 +490,19 @@ const T = (a) => {
490
490
  dateRange: o,
491
491
  setDateRange: g,
492
492
  onChange: f,
493
- minDate: v,
493
+ minDate: b,
494
494
  maxDate: h,
495
495
  input: n
496
496
  }) => {
497
- var m;
497
+ var y;
498
498
  let w = [];
499
- const b = a.getFullYear(), { start: x, end: M } = B(b), u = o.from.getFullYear(), r = (m = o.to) == null ? void 0 : m.getFullYear();
499
+ const v = a.getFullYear(), { start: x, end: M } = B(v), u = o.from.getFullYear(), r = (y = o.to) == null ? void 0 : y.getFullYear();
500
500
  for (let i = x; i < M; i++) {
501
- const p = new Date(i, 0), C = (!v || p >= v) && (!h || p <= h), k = i === u || i === r, y = p > o.from && p < o.to;
501
+ const p = new Date(i, 0), C = (!b || p >= b) && (!h || p <= h), k = i === u || i === r, m = p > o.from && p < o.to;
502
502
  w.push({
503
503
  year: i,
504
504
  active: k && C,
505
- highlight: y && C,
505
+ highlight: m && C,
506
506
  disabled: !C
507
507
  });
508
508
  }
@@ -527,8 +527,8 @@ const T = (a) => {
527
527
  i.disabled || d(new Date(i.year, 0));
528
528
  },
529
529
  style: {
530
- backgroundColor: i.highlight ? "rgba(100, 181, 246, 0.1)" : "",
531
- color: i.highlight ? "#b0b0b0" : i.active ? "" : i.disabled ? "#ccc" : "",
530
+ backgroundColor: i.highlight ? "var(--sa-color-info-alpha-a10, #64b5f61a)" : "",
531
+ color: i.highlight ? "var(--sa-color-gray-500, #8c8f97)" : i.active ? "" : i.disabled ? "var(--sa-color-gray-400, #b7b9be)" : "",
532
532
  cursor: i.disabled ? "not-allowed" : "pointer",
533
533
  pointerEvents: i.disbled ? "none" : "all",
534
534
  ...n ? {} : { width: "100%" }
@@ -550,7 +550,7 @@ const T = (a) => {
550
550
  "path",
551
551
  {
552
552
  d: "M12.5 3.33334L5.83337 10L12.5 16.6667",
553
- stroke: "#001A72",
553
+ stroke: "var(--sa-color-brand-700, #031f43)",
554
554
  strokeWidth: "1.5",
555
555
  strokeLinecap: "round",
556
556
  strokeLinejoin: "round"
@@ -570,7 +570,7 @@ const T = (a) => {
570
570
  "path",
571
571
  {
572
572
  d: "M7.5 16.6667L14.1667 10L7.5 3.33334",
573
- stroke: "#001A72",
573
+ stroke: "var(--sa-color-brand-700, #031f43)",
574
574
  strokeWidth: "1.5",
575
575
  strokeLinecap: "round",
576
576
  strokeLinejoin: "round"
@@ -596,7 +596,7 @@ const T = (a) => {
596
596
  return;
597
597
  }
598
598
  o((n) => new Date(n.getFullYear(), n.getMonth() + 1));
599
- }, v = () => {
599
+ }, b = () => {
600
600
  if (e === "years") {
601
601
  o((n) => new Date(n.getFullYear() - 10, 0));
602
602
  return;
@@ -613,7 +613,7 @@ const T = (a) => {
613
613
  );
614
614
  };
615
615
  return /* @__PURE__ */ $("div", { className: "starasia-calendar-header", children: [
616
- /* @__PURE__ */ l(P, { onClick: () => v() }),
616
+ /* @__PURE__ */ l(P, { onClick: () => b() }),
617
617
  /* @__PURE__ */ l("div", { style: { cursor: "pointer" }, onClick: g, children: (() => {
618
618
  if (e === "days")
619
619
  return `${N[s.getMonth()]} ${s.getFullYear()}`;
@@ -645,16 +645,16 @@ const ne = j(
645
645
  disabled: o,
646
646
  minDate: g,
647
647
  maxDate: f,
648
- placeholder: v,
648
+ placeholder: b,
649
649
  size: h,
650
650
  status: n
651
651
  }, w) => {
652
- const { ref: b, isComponentVisible: x, setIsComponentVisible: M } = J(!1), u = E(null), [r, d] = F("days"), [c, m] = F(/* @__PURE__ */ new Date()), [i, p] = F({
652
+ const { ref: v, isComponentVisible: x, setIsComponentVisible: M } = A(!1), u = T(null), [r, d] = F("days"), [c, y] = F(/* @__PURE__ */ new Date()), [i, p] = F({
653
653
  from: (a == null ? void 0 : a.from) || /* @__PURE__ */ new Date(),
654
654
  to: (a == null ? void 0 : a.to) || /* @__PURE__ */ new Date()
655
655
  });
656
656
  D(() => {
657
- a ? (m(a.from), p(a)) : (m(/* @__PURE__ */ new Date()), p({
657
+ a ? (y(a.from), p(a)) : (y(/* @__PURE__ */ new Date()), p({
658
658
  from: /* @__PURE__ */ new Date(),
659
659
  to: /* @__PURE__ */ new Date()
660
660
  }));
@@ -666,7 +666,7 @@ const ne = j(
666
666
  s || M(!0);
667
667
  }, [s]);
668
668
  const C = () => {
669
- var y, Y;
669
+ var m, Y;
670
670
  if (!a)
671
671
  return "";
672
672
  if (t) {
@@ -675,28 +675,28 @@ const ne = j(
675
675
  if (r === "months")
676
676
  return `${N[i.from.getMonth()]} ~ ${i.to ? N[i.to.getMonth()] : "-"}`;
677
677
  if (r === "years")
678
- return `${(y = i.from) == null ? void 0 : y.getFullYear()} ~ ${((Y = i.to) == null ? void 0 : Y.getFullYear()) || "-"}`;
678
+ return `${(m = i.from) == null ? void 0 : m.getFullYear()} ~ ${((Y = i.to) == null ? void 0 : Y.getFullYear()) || "-"}`;
679
679
  } else
680
680
  return `${L(i.from)} ~ ${L(i.to || i.from) || "-"}`;
681
681
  }, k = () => {
682
- if (u.current && b.current && s) {
683
- const y = b.current.getBoundingClientRect(), Y = u.current.getBoundingClientRect();
684
- window.innerWidth < y.left + Y.width ? u.current.style.left = `${y.left - Y.width + y.width}px` : u.current.style.left = `${y.left}px`, y.top + Y.height > window.innerHeight ? u.current.style.top = `${y.y - (y.height + Y.height - 28)}px` : u.current.style.top = `${y.y + y.height}px`;
682
+ if (u.current && v.current && s) {
683
+ const m = v.current.getBoundingClientRect(), Y = u.current.getBoundingClientRect();
684
+ window.innerWidth < m.left + Y.width ? u.current.style.left = `${m.left - Y.width + m.width}px` : u.current.style.left = `${m.left}px`, m.top + Y.height > window.innerHeight ? u.current.style.top = `${m.y - (m.height + Y.height - 28)}px` : u.current.style.top = `${m.y + m.height}px`;
685
685
  }
686
686
  };
687
687
  return D(() => {
688
- u.current && b.current && s && k();
689
- }, [u, b, x]), D(() => {
690
- const y = w == null ? void 0 : w.current;
691
- return y && y.addEventListener("scroll", k), window.addEventListener("scroll", k), () => {
692
- y && y.removeEventListener("scroll", k), window.removeEventListener("scroll", k);
688
+ u.current && v.current && s && k();
689
+ }, [u, v, x]), D(() => {
690
+ const m = w == null ? void 0 : w.current;
691
+ return m && m.addEventListener("scroll", k), window.addEventListener("scroll", k), () => {
692
+ m && m.removeEventListener("scroll", k), window.removeEventListener("scroll", k);
693
693
  };
694
694
  }, []), /* @__PURE__ */ $(
695
695
  "div",
696
696
  {
697
697
  className: "starasia-calendar-wrapper",
698
698
  style: { height: s ? "auto" : "100%" },
699
- ref: s ? b : null,
699
+ ref: s ? v : null,
700
700
  children: [
701
701
  s ? /* @__PURE__ */ l(
702
702
  K,
@@ -709,7 +709,7 @@ const ne = j(
709
709
  onChange: () => {
710
710
  },
711
711
  disabled: o,
712
- placeholder: v,
712
+ placeholder: b,
713
713
  size: h,
714
714
  status: n
715
715
  }
@@ -727,14 +727,14 @@ const ne = j(
727
727
  views: r,
728
728
  filter: t,
729
729
  date: c,
730
- setDate: m
730
+ setDate: y
731
731
  }
732
732
  ),
733
733
  /* @__PURE__ */ l("div", { className: "starasia-calendar-body", children: r === "days" ? /* @__PURE__ */ l(
734
734
  Q,
735
735
  {
736
736
  date: c,
737
- setDate: m,
737
+ setDate: y,
738
738
  setIsComponentVisible: M,
739
739
  dateRange: i,
740
740
  setDateRange: p,
@@ -747,7 +747,7 @@ const ne = j(
747
747
  X,
748
748
  {
749
749
  date: c,
750
- setDate: m,
750
+ setDate: y,
751
751
  filter: t,
752
752
  setViews: d,
753
753
  dateRange: i,
@@ -762,7 +762,7 @@ const ne = j(
762
762
  Z,
763
763
  {
764
764
  date: c,
765
- setDate: m,
765
+ setDate: y,
766
766
  filter: t,
767
767
  setViews: d,
768
768
  dateRange: i,
@@ -796,7 +796,7 @@ const I = (a) => {
796
796
  if (a === "lg")
797
797
  return 20;
798
798
  }, re = (a) => {
799
- const { size: e = "md", status: t = "default", variant: s = "outline", ...o } = a, g = E(null), f = () => {
799
+ const { size: e = "md", status: t = "default", variant: s = "outline", ...o } = a, g = T(null), f = () => {
800
800
  g.current && o.onClick && (g.current.focus(), o.onClick(""));
801
801
  };
802
802
  return /* @__PURE__ */ $(
@@ -817,7 +817,7 @@ const I = (a) => {
817
817
  "path",
818
818
  {
819
819
  d: "M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",
820
- stroke: "#939E99",
820
+ stroke: "var(--sa-color-gray-500, #8c8f97)",
821
821
  strokeWidth: "1.5",
822
822
  strokeLinecap: "round",
823
823
  strokeLinejoin: "round"
@@ -847,7 +847,7 @@ const I = (a) => {
847
847
  "path",
848
848
  {
849
849
  d: "M3.33331 7.5L9.99998 14.1667L16.6666 7.5",
850
- stroke: "#939E99",
850
+ stroke: "var(--sa-color-gray-500, #8c8f97)",
851
851
  strokeWidth: "1.5",
852
852
  strokeLinecap: "round",
853
853
  strokeLinejoin: "round"
@@ -866,14 +866,14 @@ const I = (a) => {
866
866
  setIsComponentVisible: o,
867
867
  minDate: g,
868
868
  maxDate: f,
869
- input: v,
869
+ input: b,
870
870
  onChange: h
871
871
  }) => {
872
872
  let n = new Date(
873
873
  t.getFullYear(),
874
874
  t.getMonth(),
875
875
  1
876
- ), w = n.getDay(), b = [];
876
+ ), w = n.getDay(), v = [];
877
877
  const x = a.toDateString(), M = t.getMonth();
878
878
  for (let r = 0; r < 42; r++) {
879
879
  r === 0 && w === 0 ? n.setDate(n.getDate() - 7) : r === 0 ? n.setDate(
@@ -888,14 +888,14 @@ const I = (a) => {
888
888
  year: n.getFullYear(),
889
889
  isDisabled: g && n < g || f && n > f
890
890
  };
891
- b.push(d);
891
+ v.push(d);
892
892
  }
893
893
  const u = (r) => {
894
- (!g || r >= g) && (!f || r <= f) && (e(r), h(r), s(r), v && o(!1));
894
+ (!g || r >= g) && (!f || r <= f) && (e(r), h(r), s(r), b && o(!1));
895
895
  };
896
896
  return /* @__PURE__ */ $("div", { className: "starasia-calendar-days-preivew", children: [
897
- /* @__PURE__ */ l("div", { className: "starasia-calendar-days-name-preivew", children: A.map((r, d) => /* @__PURE__ */ l("p", { children: r }, d)) }),
898
- /* @__PURE__ */ l("div", { className: "starasia-calendar-days-number-preivew", children: b.map((r, d) => {
897
+ /* @__PURE__ */ l("div", { className: "starasia-calendar-days-name-preivew", children: J.map((r, d) => /* @__PURE__ */ l("p", { children: r }, d)) }),
898
+ /* @__PURE__ */ l("div", { className: "starasia-calendar-days-number-preivew", children: v.map((r, d) => {
899
899
  const c = r.isDisabled;
900
900
  return /* @__PURE__ */ l(
901
901
  "p",
@@ -905,7 +905,7 @@ const I = (a) => {
905
905
  color: c ? "#ccc" : void 0,
906
906
  pointerEvents: c ? "none" : void 0,
907
907
  cursor: c ? "not-allowed" : "pointer",
908
- ...v ? {} : { width: "100%" }
908
+ ...b ? {} : { width: "100%" }
909
909
  },
910
910
  onClick: () => {
911
911
  c || u(r.date);
@@ -924,19 +924,19 @@ const I = (a) => {
924
924
  onChange: o,
925
925
  previewDate: g,
926
926
  setPreviewDate: f,
927
- minDate: v,
927
+ minDate: b,
928
928
  maxDate: h,
929
929
  input: n
930
930
  }) => {
931
- const w = a.getMonth(), b = a.getFullYear(), x = g.getFullYear(), M = (u) => {
932
- (!v || u >= v) && (!h || u <= h) && (t ? (o(u), e(u), f(u)) : (s("days"), f(u)));
931
+ const w = a.getMonth(), v = a.getFullYear(), x = g.getFullYear(), M = (u) => {
932
+ (!b || u >= b) && (!h || u <= h) && (t ? (o(u), e(u), f(u)) : (s("days"), f(u)));
933
933
  };
934
934
  return /* @__PURE__ */ l("div", { className: "starasia-calendar-months-preview", children: N.map((u, r) => {
935
- const d = v && new Date(x, r, 1) < v || h && new Date(x, r + 1, 0) > h;
935
+ const d = b && new Date(x, r, 1) < b || h && new Date(x, r + 1, 0) > h;
936
936
  return /* @__PURE__ */ l(
937
937
  "p",
938
938
  {
939
- className: r === w && x === b ? "starasia-calendar-months-active" : "",
939
+ className: r === w && x === v ? "starasia-calendar-months-active" : "",
940
940
  style: {
941
941
  color: d ? "#ccc" : void 0,
942
942
  pointerEvents: d ? "none" : void 0,
@@ -962,18 +962,18 @@ const I = (a) => {
962
962
  onChange: o,
963
963
  previewDate: g,
964
964
  setPreviewDate: f,
965
- minDate: v,
965
+ minDate: b,
966
966
  maxDate: h,
967
967
  input: n
968
968
  }) => {
969
969
  let w = [];
970
- const b = g.getFullYear(), { start: x, end: M } = V(b), u = a.getFullYear();
970
+ const v = g.getFullYear(), { start: x, end: M } = V(v), u = a.getFullYear();
971
971
  for (let d = x; d < M; d++) {
972
- let c = v && new Date(d, 0, 1) < v || h && new Date(d, 11, 31) > h;
972
+ let c = b && new Date(d, 0, 1) < b || h && new Date(d, 11, 31) > h;
973
973
  w.push({ year: d, active: d === u, isDisabled: c });
974
974
  }
975
975
  const r = (d) => {
976
- (!v || d >= v) && (!h || d <= h) && (e ? (o(d), s(d), f(d)) : (t("months"), f(d)));
976
+ (!b || d >= b) && (!h || d <= h) && (e ? (o(d), s(d), f(d)) : (t("months"), f(d)));
977
977
  };
978
978
  return /* @__PURE__ */ l("div", { className: "starasia-calendar-years-preview", children: w.map((d, c) => /* @__PURE__ */ l(
979
979
  "p",
@@ -1013,7 +1013,7 @@ const I = (a) => {
1013
1013
  return;
1014
1014
  }
1015
1015
  o((n) => new Date(n.getFullYear(), n.getMonth() + 1));
1016
- }, v = () => {
1016
+ }, b = () => {
1017
1017
  if (e === "years") {
1018
1018
  o((n) => new Date(n.getFullYear() - 10, 0));
1019
1019
  return;
@@ -1032,7 +1032,7 @@ const I = (a) => {
1032
1032
  );
1033
1033
  };
1034
1034
  return /* @__PURE__ */ $("div", { className: "starasia-calendar-header", children: [
1035
- /* @__PURE__ */ l(P, { onClick: () => v() }),
1035
+ /* @__PURE__ */ l(P, { onClick: () => b() }),
1036
1036
  /* @__PURE__ */ l("div", { style: { cursor: "pointer" }, onClick: g, children: (() => {
1037
1037
  if (e === "days")
1038
1038
  return `${N[s.getMonth()]} ${s.getFullYear()}`;
@@ -1059,13 +1059,13 @@ const de = j(
1059
1059
  disabled: o,
1060
1060
  minDate: g,
1061
1061
  maxDate: f,
1062
- placeholder: v,
1062
+ placeholder: b,
1063
1063
  size: h,
1064
1064
  status: n
1065
1065
  }, w) => {
1066
- const { ref: b, isComponentVisible: x, setIsComponentVisible: M } = J(!1), u = E(null), [r, d] = F("days"), [c, m] = F(/* @__PURE__ */ new Date()), [i, p] = F(/* @__PURE__ */ new Date());
1066
+ const { ref: v, isComponentVisible: x, setIsComponentVisible: M } = A(!1), u = T(null), [r, d] = F("days"), [c, y] = F(/* @__PURE__ */ new Date()), [i, p] = F(/* @__PURE__ */ new Date());
1067
1067
  D(() => {
1068
- a ? (m(a), p(a)) : (m(/* @__PURE__ */ new Date()), p(/* @__PURE__ */ new Date()));
1068
+ a ? (y(a), p(a)) : (y(/* @__PURE__ */ new Date()), p(/* @__PURE__ */ new Date()));
1069
1069
  }, [a]), D(() => {
1070
1070
  t && d(t);
1071
1071
  }, [t]), D(() => {
@@ -1074,24 +1074,24 @@ const de = j(
1074
1074
  s || M(!0);
1075
1075
  }, [s]);
1076
1076
  const C = () => a ? t === "days" ? L(c) : t === "months" ? `${N[c.getMonth()]} ${c.getFullYear()}` : t === "years" ? c.getFullYear() : L(c) : "", k = () => {
1077
- if (u.current && b.current && s) {
1078
- const y = b.current.getBoundingClientRect(), Y = u.current.getBoundingClientRect();
1079
- window.innerWidth < y.left + Y.width ? u.current.style.left = `${y.left - Y.width + y.width}px` : u.current.style.left = `${y.left}px`, y.top + Y.height > window.innerHeight ? u.current.style.top = `${y.y - (y.height + Y.height - 28)}px` : u.current.style.top = `${y.y + y.height}px`;
1077
+ if (u.current && v.current && s) {
1078
+ const m = v.current.getBoundingClientRect(), Y = u.current.getBoundingClientRect();
1079
+ window.innerWidth < m.left + Y.width ? u.current.style.left = `${m.left - Y.width + m.width}px` : u.current.style.left = `${m.left}px`, m.top + Y.height > window.innerHeight ? u.current.style.top = `${m.y - (m.height + Y.height - 28)}px` : u.current.style.top = `${m.y + m.height}px`;
1080
1080
  }
1081
1081
  };
1082
1082
  return D(() => {
1083
- u.current && b.current && s && k();
1084
- }, [u, b, x]), D(() => {
1085
- const y = w == null ? void 0 : w.current;
1086
- return y && y.addEventListener("scroll", k), window.addEventListener("scroll", k), () => {
1087
- y && y.removeEventListener("scroll", k), window.removeEventListener("scroll", k);
1083
+ u.current && v.current && s && k();
1084
+ }, [u, v, x]), D(() => {
1085
+ const m = w == null ? void 0 : w.current;
1086
+ return m && m.addEventListener("scroll", k), window.addEventListener("scroll", k), () => {
1087
+ m && m.removeEventListener("scroll", k), window.removeEventListener("scroll", k);
1088
1088
  };
1089
1089
  }, []), /* @__PURE__ */ $(
1090
1090
  "div",
1091
1091
  {
1092
1092
  className: "starasia-calendar-wrapper",
1093
1093
  style: { height: s ? "auto" : "100%" },
1094
- ref: s ? b : null,
1094
+ ref: s ? v : null,
1095
1095
  children: [
1096
1096
  s ? /* @__PURE__ */ l(
1097
1097
  re,
@@ -1100,7 +1100,7 @@ const de = j(
1100
1100
  onClick: () => M(!0),
1101
1101
  onChange: () => {
1102
1102
  },
1103
- placeholder: v,
1103
+ placeholder: b,
1104
1104
  disabled: o,
1105
1105
  size: h,
1106
1106
  status: n,
@@ -1128,7 +1128,7 @@ const de = j(
1128
1128
  te,
1129
1129
  {
1130
1130
  date: c,
1131
- setDate: m,
1131
+ setDate: y,
1132
1132
  previewDate: i,
1133
1133
  setPreviewDate: p,
1134
1134
  setIsComponentVisible: M,
@@ -1141,7 +1141,7 @@ const de = j(
1141
1141
  se,
1142
1142
  {
1143
1143
  date: c,
1144
- setDate: m,
1144
+ setDate: y,
1145
1145
  previewDate: i,
1146
1146
  setPreviewDate: p,
1147
1147
  filter: t,
@@ -1155,7 +1155,7 @@ const de = j(
1155
1155
  oe,
1156
1156
  {
1157
1157
  date: c,
1158
- setDate: m,
1158
+ setDate: y,
1159
1159
  previewDate: i,
1160
1160
  setPreviewDate: p,
1161
1161
  filter: t,
@@ -1182,11 +1182,11 @@ const de = j(
1182
1182
  rangedDate: o,
1183
1183
  disabled: g,
1184
1184
  minDate: f,
1185
- maxDate: v,
1185
+ maxDate: b,
1186
1186
  placeholder: h,
1187
1187
  size: n,
1188
1188
  status: w
1189
- }, b) => /* @__PURE__ */ l(G, { children: o ? /* @__PURE__ */ l(
1189
+ }, v) => /* @__PURE__ */ l(G, { children: o ? /* @__PURE__ */ l(
1190
1190
  ne,
1191
1191
  {
1192
1192
  onChange: e,
@@ -1194,9 +1194,9 @@ const de = j(
1194
1194
  input: s,
1195
1195
  filter: t,
1196
1196
  disabled: g,
1197
- ref: b,
1197
+ ref: v,
1198
1198
  minDate: f,
1199
- maxDate: v,
1199
+ maxDate: b,
1200
1200
  placeholder: h,
1201
1201
  size: n,
1202
1202
  status: w
@@ -1209,9 +1209,9 @@ const de = j(
1209
1209
  input: s,
1210
1210
  filter: t,
1211
1211
  disabled: g,
1212
- ref: b,
1212
+ ref: v,
1213
1213
  minDate: f,
1214
- maxDate: v,
1214
+ maxDate: b,
1215
1215
  placeholder: h,
1216
1216
  size: n,
1217
1217
  status: w
package/dist/date.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(Y,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],a):(Y=typeof globalThis<"u"?globalThis:Y||self,a(Y.Date={},Y.jsxRuntime,Y.React))})(this,function(Y,a,m){"use strict";const N=`@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
1
+ (function(Y,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(Y=typeof globalThis<"u"?globalThis:Y||self,n(Y.Date={},Y.jsxRuntime,Y.React))})(this,function(Y,n,m){"use strict";const E=`@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap");
2
2
 
3
3
  * {
4
4
  margin: 0;
@@ -11,10 +11,10 @@
11
11
  --sa-date-radius: var(--sa-radii-md, 0.5rem);
12
12
  --sa-date-radius-lg: var(--sa-radii-lg, 0.75rem);
13
13
  --sa-date-bg: var(--sa-background-primary, #ffffff);
14
- --sa-date-border-color: rgba(120, 134, 127, 0.2);
15
- --sa-date-border-disabled: rgba(120, 134, 127, 0.2);
16
- --sa-date-bg-disabled: rgba(120, 134, 127, 0.1);
17
- --sa-date-shadow: var(--sa-shadow-md, 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1));
14
+ --sa-date-border-color: var(--sa-color-gray-alpha-a20, #78867f33);
15
+ --sa-date-border-disabled: var(--sa-color-gray-alpha-a20, #78867f33);
16
+ --sa-date-bg-disabled: var(--sa-color-gray-alpha-a10, #78867f1a);
17
+ --sa-date-shadow: var(--sa-shadow-md, 0 4px 6px -1px #0000001a, 0 2px 4px -2px #0000001a);
18
18
  --sa-date-text-primary: var(--sa-color-gray-700, #6b6e76);
19
19
  --sa-date-text-subtle: var(--sa-color-gray-500, #8c8f97);
20
20
  --sa-date-text-muted: var(--sa-color-gray-300, #dddee1);
@@ -252,4 +252,4 @@
252
252
  .starasia-calendar-input-container-warning {
253
253
  border-color: var(--sa-date-border-warning) !important;
254
254
  }
255
- `,j=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],F=["January","February","March","April","May","June","July","August","September","October","November","December"],J=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function B(r){const[e,s]=m.useState(r),o=m.useRef(null),i=g=>{o.current&&!o.current.contains(g.target)&&s(!1)};return m.useEffect(()=>(document.addEventListener("click",i,!0),()=>{document.removeEventListener("click",i,!0)}),[]),{ref:o,isComponentVisible:e,setIsComponentVisible:s}}const V="starasia-calendar-input-styles";(r=>{if(!document.getElementById(V)){const e=document.createElement("style");e.id=V,e.textContent=r,document.head.appendChild(e)}})(N);const S=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},P=r=>{const{size:e="md",status:s="default",variant:o="outline",...i}=r,g=m.useRef(null),p=()=>{g.current&&i.onClick&&(g.current.focus(),i.onClick(""))};return a.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${o} starasia-calendar-input-container-${s} ${e} `,onClick:p,children:[a.jsx("div",{className:"starasia-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("div",{className:"starasia-calendar-input-preview-container",children:a.jsx("input",{className:"starasia-calendar-input",...i,disabled:s==="disable"?!0:i.disabled,value:i.value,ref:g})}),a.jsx("div",{className:"starasia-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},q=({date:r,setDate:e,dateRange:s,setDateRange:o,onChange:i,minDate:g,maxDate:p,input:v})=>{var h,t,d;let u=new Date(r.getFullYear(),r.getMonth(),1),n=u.getDay(),x=[];const w=r.getMonth();for(let c=0;c<42;c++){c===0&&n===0?u.setDate(u.getDate()-7):c===0?u.setDate(u.getDate()+(c-n)):u.setDate(u.getDate()+1);let y={currentMonth:u.getMonth()===w,date:new Date(u),month:u.getMonth(),number:u.getDate(),selected:u.toDateString()===((h=s.from)==null?void 0:h.toDateString())||u.toDateString()===(((t=s.to)==null?void 0:t.toDateString())||((d=s.from)==null?void 0:d.toDateString())),year:u.getFullYear(),isDisabled:g&&u<g||p&&u>p};x.push(y)}const M=c=>{e(c)},k=c=>{var l;let y={...s};if(y.from&&y.to)y={from:c,to:null};else{const f=((l=y.from)==null?void 0:l.getTime())||0;c.getTime()>f?y={from:y.from,to:c}:y={from:c,to:y.from}}o(y),i(y)};return a.jsxs("div",{className:"starasia-calendar-days-preivew",children:[a.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((c,y)=>a.jsx("p",{children:c},y))}),a.jsx("div",{className:"starasia-calendar-days-number-preivew",children:x.map((c,y)=>{var D;const l=c.date.getTime()>s.from.getTime()&&c.date.getTime()<(((D=s.to)==null?void 0:D.getTime())||s.from.getTime()),f=c.isDisabled;return a.jsx("p",{className:`${c.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${c.selected?"starasia-calendar-days-active":""}`,style:{backgroundColor:l?"rgba(100, 181, 246, 0.1)":"",pointerEvents:f?"none":void 0,cursor:f?"not-allowed":"pointer",color:f?"#ccc":l?"#b0b0b0":"",...v?{}:{width:"100%"}},onClick:()=>{f||(M(c.date),k(c.date))},children:c.number},y)})})]})},G=({date:r,setDate:e,filter:s,setViews:o,dateRange:i,setDateRange:g,onChange:p,minDate:v,maxDate:u,input:n})=>{const x=i.from.getFullYear(),w=r.getFullYear(),M=h=>{s?(k(h),e(h)):(o("days"),e(h))},k=h=>{var d;let t={...i};if(t.from&&t.to)t={from:h,to:null};else{const c=((d=t.from)==null?void 0:d.getTime())||0;h.getTime()>c?t={from:t.from,to:h}:t={from:h,to:t.from}}g(t),p(t)};return a.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((h,t)=>{var y,l,f;const d=new Date(w,t).getTime()>i.from.getTime()&&new Date(w,t).getTime()<(((y=i.to)==null?void 0:y.getTime())||i.from.getTime()),c=v&&new Date(w,t)<v||u&&new Date(w,t)>u;return a.jsx("p",{className:x===w&&(t===((l=i.from)==null?void 0:l.getMonth())||t===((f=i.to)==null?void 0:f.getMonth()))?"starasia-calendar-months-active":"",style:{backgroundColor:d?"rgba(100, 181, 246, 0.1)":"",pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",color:c?"#ccc":d?"#b0b0b0":"",...n?{}:{width:"100%"}},onClick:()=>{c||M(new Date(w,t))},children:h.slice(0,3)},t)})})},T=r=>{const e=Math.floor(r/10)*10,s=e+10;return{start:e,end:s}},U=({date:r,filter:e,setViews:s,setDate:o,dateRange:i,setDateRange:g,onChange:p,minDate:v,maxDate:u,input:n})=>{var y;let x=[];const w=r.getFullYear(),{start:M,end:k}=T(w),h=i.from.getFullYear(),t=(y=i.to)==null?void 0:y.getFullYear();for(let l=M;l<k;l++){const f=new Date(l,0),D=(!v||f>=v)&&(!u||f<=u),C=l===h||l===t,b=f>i.from&&f<i.to;x.push({year:l,active:C&&D,highlight:b&&D,disabled:!D})}const d=l=>{e?(c(l),o(l)):(o(l),s("months"))},c=l=>{var D;let f={...i};if(f.from&&f.to)f={from:l,to:null};else{const C=((D=f.from)==null?void 0:D.getTime())||0;l.getTime()>C?f={from:f.from,to:l}:f={from:l,to:f.from}}g(f),p(f)};return a.jsx("div",{className:"starasia-calendar-years-preview",children:x.map((l,f)=>a.jsx("p",{className:`${l.active?"starasia-calendar-months-active":""} ${l.highlight?"starasia-calendar-months-highlight":""} ${l.disabled?"starasia-calendar-disabled":""}`,onClick:()=>{l.disabled||d(new Date(l.year,0))},style:{backgroundColor:l.highlight?"rgba(100, 181, 246, 0.1)":"",color:l.highlight?"#b0b0b0":l.active?"":l.disabled?"#ccc":"",cursor:l.disabled?"not-allowed":"pointer",pointerEvents:l.disbled?"none":"all",...n?{}:{width:"100%"}},children:l.year},f))})},z=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"#001A72",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),O=({...r})=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:a.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"#001A72",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),K=({setViews:r,views:e,filter:s,date:o,setDate:i})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},p=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()+1,n.getMonth()));return}i(n=>new Date(n.getFullYear(),n.getMonth()+1))},v=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()-1,n.getMonth()));return}i(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${T(o.getFullYear()).start} ~ ${T(o.getFullYear()).end}`};return a.jsxs("div",{className:"starasia-calendar-header",children:[a.jsx(z,{onClick:()=>v()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.jsx(O,{onClick:()=>p()})]})};function E(r){const e=new Date(r),s=e.getFullYear(),o=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${J[o]} ${s}`}const W="starasia-calendar-styles";(r=>{if(!document.getElementById(W)){const e=document.createElement("style");e.id=W,e.textContent=r,document.head.appendChild(e)}})(N);const Q=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:i,minDate:g,maxDate:p,placeholder:v,size:u,status:n},x)=>{const{ref:w,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,d]=m.useState("days"),[c,y]=m.useState(new Date),[l,f]=m.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});m.useEffect(()=>{r?(y(r.from),f(r)):(y(new Date),f({from:new Date,to:new Date}))},[r]),m.useEffect(()=>{s&&d(s)},[s]),m.useEffect(()=>{s||d("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>{var b,$;if(!r)return"";if(s){if(t==="days")return`${E(l.from)} ~ ${E(l.to||l.from)||"-"}`;if(t==="months")return`${F[l.from.getMonth()]} ~ ${l.to?F[l.to.getMonth()]:"-"}`;if(t==="years")return`${(b=l.from)==null?void 0:b.getFullYear()} ~ ${(($=l.to)==null?void 0:$.getFullYear())||"-"}`}else return`${E(l.from)} ~ ${E(l.to||l.from)||"-"}`},C=()=>{if(h.current&&w.current&&o){const b=w.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<b.left+$.width?h.current.style.left=`${b.left-$.width+b.width}px`:h.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?h.current.style.top=`${b.y-(b.height+$.height-28)}px`:h.current.style.top=`${b.y+b.height}px`}};return m.useEffect(()=>{h.current&&w.current&&o&&C()},[h,w,M]),m.useEffect(()=>{const b=x==null?void 0:x.current;return b&&b.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{b&&b.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),a.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?w:null,children:[o?a.jsx(P,{value:D(),inputMode:"none",onClick:()=>{k(!0)},onChange:()=>{},disabled:i,placeholder:v,size:u,status:n}):null,M?a.jsxs("div",{className:`starasia-calendar ${o?"":"starasia-calendar-no-input"}`,ref:h,children:[a.jsx(K,{setViews:d,views:t,filter:s,date:c,setDate:y}),a.jsx("div",{className:"starasia-calendar-body",children:t==="days"?a.jsx(q,{date:c,setDate:y,setIsComponentVisible:k,dateRange:l,setDateRange:f,input:o,onChange:e,minDate:g,maxDate:p}):t==="months"?a.jsx(G,{date:c,setDate:y,filter:s,setViews:d,dateRange:l,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p}):a.jsx(U,{date:c,setDate:y,filter:s,setViews:d,dateRange:l,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p})})]}):null]})}),H="starasia-calendar-input-styles";(r=>{if(!document.getElementById(H)){const e=document.createElement("style");e.id=H,e.textContent=r,document.head.appendChild(e)}})(N);const L=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},X=r=>{const{size:e="md",status:s="default",variant:o="outline",...i}=r,g=m.useRef(null),p=()=>{g.current&&i.onClick&&(g.current.focus(),i.onClick(""))};return a.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${o} starasia-calendar-input-container-${s} ${e} `,onClick:p,children:[a.jsx("div",{className:"starasia-calendar-input-container-icon-left",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),a.jsx("div",{className:"starasia-calendar-input-preview-container",children:a.jsx("input",{className:"starasia-calendar-input",...i,disabled:s==="disable"?!0:i.disabled,value:i.value,ref:g})}),a.jsx("div",{className:"starasia-calendar-input-container-icon-right",children:a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:a.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"#939E99",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Z=({date:r,setDate:e,previewDate:s,setPreviewDate:o,setIsComponentVisible:i,minDate:g,maxDate:p,input:v,onChange:u})=>{let n=new Date(s.getFullYear(),s.getMonth(),1),x=n.getDay(),w=[];const M=r.toDateString(),k=s.getMonth();for(let t=0;t<42;t++){t===0&&x===0?n.setDate(n.getDate()-7):t===0?n.setDate(n.getDate()+(t-x)):n.setDate(n.getDate()+1);let d={currentMonth:n.getMonth()===k,date:new Date(n),month:n.getMonth(),number:n.getDate(),selected:n.toDateString()===M,year:n.getFullYear(),isDisabled:g&&n<g||p&&n>p};w.push(d)}const h=t=>{(!g||t>=g)&&(!p||t<=p)&&(e(t),u(t),o(t),v&&i(!1))};return a.jsxs("div",{className:"starasia-calendar-days-preivew",children:[a.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((t,d)=>a.jsx("p",{children:t},d))}),a.jsx("div",{className:"starasia-calendar-days-number-preivew",children:w.map((t,d)=>{const c=t.isDisabled;return a.jsx("p",{className:`${t.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${t.selected?"starasia-calendar-days-active":""}`,style:{color:c?"#ccc":void 0,pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",...v?{}:{width:"100%"}},onClick:()=>{c||h(t.date)},children:t.number},d)})})]})},_=({date:r,setDate:e,filter:s,setViews:o,onChange:i,previewDate:g,setPreviewDate:p,minDate:v,maxDate:u,input:n})=>{const x=r.getMonth(),w=r.getFullYear(),M=g.getFullYear(),k=h=>{(!v||h>=v)&&(!u||h<=u)&&(s?(i(h),e(h),p(h)):(o("days"),p(h)))};return a.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((h,t)=>{const d=v&&new Date(M,t,1)<v||u&&new Date(M,t+1,0)>u;return a.jsx("p",{className:t===x&&M===w?"starasia-calendar-months-active":"",style:{color:d?"#ccc":void 0,pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{d||k(new Date(M,t))},children:h.slice(0,3)},t)})})},I=r=>{const e=Math.floor(r/10)*10,s=e+10;return{start:e,end:s}},R=({date:r,filter:e,setViews:s,setDate:o,onChange:i,previewDate:g,setPreviewDate:p,minDate:v,maxDate:u,input:n})=>{let x=[];const w=g.getFullYear(),{start:M,end:k}=I(w),h=r.getFullYear();for(let d=M;d<k;d++){let c=v&&new Date(d,0,1)<v||u&&new Date(d,11,31)>u;x.push({year:d,active:d===h,isDisabled:c})}const t=d=>{(!v||d>=v)&&(!u||d<=u)&&(e?(i(d),o(d),p(d)):(s("months"),p(d)))};return a.jsx("div",{className:"starasia-calendar-years-preview",children:x.map((d,c)=>a.jsx("p",{className:d.active?"starasia-calendar-months-active":"",style:{color:d.isDisabled?"#ccc":void 0,pointerEvents:d.isDisabled?"none":void 0,cursor:d.isDisabled?"not-allowed":"pointer",...n?{}:{width:"100%"}},onClick:()=>{d.isDisabled||t(new Date(d.year,0))},children:d.year},c))})},ee=({setViews:r,views:e,filter:s,previewDate:o,setPreviewDate:i})=>{const g=()=>{s||r(n=>n==="days"?"months":n==="months"?"years":"days")},p=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()+10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()+1,n.getMonth()));return}i(n=>new Date(n.getFullYear(),n.getMonth()+1))},v=()=>{if(e==="years"){i(n=>new Date(n.getFullYear()-10,0));return}if(e==="months"){i(n=>new Date(n.getFullYear()-1,n.getMonth()));return}i(n=>new Date(n.getMonth()===0?n.getFullYear()-1:n.getFullYear(),n.getMonth()===0?11:n.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${I(o.getFullYear()).start} ~ ${I(o.getFullYear()).end}`};return a.jsxs("div",{className:"starasia-calendar-header",children:[a.jsx(z,{onClick:()=>v()}),a.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),a.jsx(O,{onClick:()=>p()})]})},A="starasia-calendar-styles";(r=>{if(!document.getElementById(A)){const e=document.createElement("style");e.id=A,e.textContent=r,document.head.appendChild(e)}})(N);const ne=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:i,minDate:g,maxDate:p,placeholder:v,size:u,status:n},x)=>{const{ref:w,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,d]=m.useState("days"),[c,y]=m.useState(new Date),[l,f]=m.useState(new Date);m.useEffect(()=>{r?(y(r),f(r)):(y(new Date),f(new Date))},[r]),m.useEffect(()=>{s&&d(s)},[s]),m.useEffect(()=>{s||d("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>r?s==="days"?E(c):s==="months"?`${F[c.getMonth()]} ${c.getFullYear()}`:s==="years"?c.getFullYear():E(c):"",C=()=>{if(h.current&&w.current&&o){const b=w.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<b.left+$.width?h.current.style.left=`${b.left-$.width+b.width}px`:h.current.style.left=`${b.left}px`,b.top+$.height>window.innerHeight?h.current.style.top=`${b.y-(b.height+$.height-28)}px`:h.current.style.top=`${b.y+b.height}px`}};return m.useEffect(()=>{h.current&&w.current&&o&&C()},[h,w,M]),m.useEffect(()=>{const b=x==null?void 0:x.current;return b&&b.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{b&&b.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),a.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?w:null,children:[o?a.jsx(X,{value:D(),onClick:()=>k(!0),onChange:()=>{},placeholder:v,disabled:i,size:u,status:n,inputMode:"none"}):null,M?a.jsxs("div",{className:`starasia-calendar ${o?"":"starasia-calendar-no-input"}`,ref:h,children:[a.jsx(ee,{setViews:d,views:t,filter:s,previewDate:l,setPreviewDate:f,isComponentVisible:M}),a.jsx("div",{className:"starasia-calendar-body",children:t==="days"?a.jsx(Z,{date:c,setDate:y,previewDate:l,setPreviewDate:f,setIsComponentVisible:k,input:o,minDate:g,maxDate:p,onChange:e}):t==="months"?a.jsx(_,{date:c,setDate:y,previewDate:l,setPreviewDate:f,filter:s,setViews:d,onChange:e,minDate:g,maxDate:p,input:o}):a.jsx(R,{date:c,setDate:y,previewDate:l,setPreviewDate:f,filter:s,setViews:d,onChange:e,minDate:g,maxDate:p,input:o})})]}):null]})}),ae=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,rangedDate:i,disabled:g,minDate:p,maxDate:v,placeholder:u,size:n,status:x},w)=>a.jsx(a.Fragment,{children:i?a.jsx(Q,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:w,minDate:p,maxDate:v,placeholder:u,size:n,status:x}):a.jsx(ne,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:w,minDate:p,maxDate:v,placeholder:u,size:n,status:x})}));Y.StarasiaDate=ae,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
255
+ `,j=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],F=["January","February","March","April","May","June","July","August","September","October","November","December"],A=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function B(r){const[e,s]=m.useState(r),o=m.useRef(null),l=g=>{o.current&&!o.current.contains(g.target)&&s(!1)};return m.useEffect(()=>(document.addEventListener("click",l,!0),()=>{document.removeEventListener("click",l,!0)}),[]),{ref:o,isComponentVisible:e,setIsComponentVisible:s}}const V="starasia-calendar-input-styles";(r=>{if(!document.getElementById(V)){const e=document.createElement("style");e.id=V,e.textContent=r,document.head.appendChild(e)}})(E);const S=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},P=r=>{const{size:e="md",status:s="default",variant:o="outline",...l}=r,g=m.useRef(null),p=()=>{g.current&&l.onClick&&(g.current.focus(),l.onClick(""))};return n.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${o} starasia-calendar-input-container-${s} ${e} `,onClick:p,children:[n.jsx("div",{className:"starasia-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("div",{className:"starasia-calendar-input-preview-container",children:n.jsx("input",{className:"starasia-calendar-input",...l,disabled:s==="disable"?!0:l.disabled,value:l.value,ref:g})}),n.jsx("div",{className:"starasia-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:S(e),height:S(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},q=({date:r,setDate:e,dateRange:s,setDateRange:o,onChange:l,minDate:g,maxDate:p,input:w})=>{var h,t,d;let u=new Date(r.getFullYear(),r.getMonth(),1),a=u.getDay(),x=[];const b=r.getMonth();for(let c=0;c<42;c++){c===0&&a===0?u.setDate(u.getDate()-7):c===0?u.setDate(u.getDate()+(c-a)):u.setDate(u.getDate()+1);let y={currentMonth:u.getMonth()===b,date:new Date(u),month:u.getMonth(),number:u.getDate(),selected:u.toDateString()===((h=s.from)==null?void 0:h.toDateString())||u.toDateString()===(((t=s.to)==null?void 0:t.toDateString())||((d=s.from)==null?void 0:d.toDateString())),year:u.getFullYear(),isDisabled:g&&u<g||p&&u>p};x.push(y)}const M=c=>{e(c)},k=c=>{var i;let y={...s};if(y.from&&y.to)y={from:c,to:null};else{const f=((i=y.from)==null?void 0:i.getTime())||0;c.getTime()>f?y={from:y.from,to:c}:y={from:c,to:y.from}}o(y),l(y)};return n.jsxs("div",{className:"starasia-calendar-days-preivew",children:[n.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((c,y)=>n.jsx("p",{children:c},y))}),n.jsx("div",{className:"starasia-calendar-days-number-preivew",children:x.map((c,y)=>{var D;const i=c.date.getTime()>s.from.getTime()&&c.date.getTime()<(((D=s.to)==null?void 0:D.getTime())||s.from.getTime()),f=c.isDisabled;return n.jsx("p",{className:`${c.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${c.selected?"starasia-calendar-days-active":""}`,style:{backgroundColor:i?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:f?"none":void 0,cursor:f?"not-allowed":"pointer",color:f?"var(--sa-color-gray-400, #b7b9be)":i?"var(--sa-color-gray-500, #8c8f97)":"",...w?{}:{width:"100%"}},onClick:()=>{f||(M(c.date),k(c.date))},children:c.number},y)})})]})},G=({date:r,setDate:e,filter:s,setViews:o,dateRange:l,setDateRange:g,onChange:p,minDate:w,maxDate:u,input:a})=>{const x=l.from.getFullYear(),b=r.getFullYear(),M=h=>{s?(k(h),e(h)):(o("days"),e(h))},k=h=>{var d;let t={...l};if(t.from&&t.to)t={from:h,to:null};else{const c=((d=t.from)==null?void 0:d.getTime())||0;h.getTime()>c?t={from:t.from,to:h}:t={from:h,to:t.from}}g(t),p(t)};return n.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((h,t)=>{var y,i,f;const d=new Date(b,t).getTime()>l.from.getTime()&&new Date(b,t).getTime()<(((y=l.to)==null?void 0:y.getTime())||l.from.getTime()),c=w&&new Date(b,t)<w||u&&new Date(b,t)>u;return n.jsx("p",{className:x===b&&(t===((i=l.from)==null?void 0:i.getMonth())||t===((f=l.to)==null?void 0:f.getMonth()))?"starasia-calendar-months-active":"",style:{backgroundColor:d?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",color:c?"var(--sa-color-gray-400, #b7b9be)":d?"var(--sa-color-gray-500, #8c8f97)":"",...a?{}:{width:"100%"}},onClick:()=>{c||M(new Date(b,t))},children:h.slice(0,3)},t)})})},T=r=>{const e=Math.floor(r/10)*10,s=e+10;return{start:e,end:s}},U=({date:r,filter:e,setViews:s,setDate:o,dateRange:l,setDateRange:g,onChange:p,minDate:w,maxDate:u,input:a})=>{var y;let x=[];const b=r.getFullYear(),{start:M,end:k}=T(b),h=l.from.getFullYear(),t=(y=l.to)==null?void 0:y.getFullYear();for(let i=M;i<k;i++){const f=new Date(i,0),D=(!w||f>=w)&&(!u||f<=u),C=i===h||i===t,v=f>l.from&&f<l.to;x.push({year:i,active:C&&D,highlight:v&&D,disabled:!D})}const d=i=>{e?(c(i),o(i)):(o(i),s("months"))},c=i=>{var D;let f={...l};if(f.from&&f.to)f={from:i,to:null};else{const C=((D=f.from)==null?void 0:D.getTime())||0;i.getTime()>C?f={from:f.from,to:i}:f={from:i,to:f.from}}g(f),p(f)};return n.jsx("div",{className:"starasia-calendar-years-preview",children:x.map((i,f)=>n.jsx("p",{className:`${i.active?"starasia-calendar-months-active":""} ${i.highlight?"starasia-calendar-months-highlight":""} ${i.disabled?"starasia-calendar-disabled":""}`,onClick:()=>{i.disabled||d(new Date(i.year,0))},style:{backgroundColor:i.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:i.highlight?"var(--sa-color-gray-500, #8c8f97)":i.active?"":i.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:i.disabled?"not-allowed":"pointer",pointerEvents:i.disbled?"none":"all",...a?{}:{width:"100%"}},children:i.year},f))})},z=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:n.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),O=({...r})=>n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...r,children:n.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),K=({setViews:r,views:e,filter:s,date:o,setDate:l})=>{const g=()=>{s||r(a=>a==="days"?"months":a==="months"?"years":"days")},p=()=>{if(e==="years"){l(a=>new Date(a.getFullYear()+10,0));return}if(e==="months"){l(a=>new Date(a.getFullYear()+1,a.getMonth()));return}l(a=>new Date(a.getFullYear(),a.getMonth()+1))},w=()=>{if(e==="years"){l(a=>new Date(a.getFullYear()-10,0));return}if(e==="months"){l(a=>new Date(a.getFullYear()-1,a.getMonth()));return}l(a=>new Date(a.getMonth()===0?a.getFullYear()-1:a.getFullYear(),a.getMonth()===0?11:a.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${T(o.getFullYear()).start} ~ ${T(o.getFullYear()).end}`};return n.jsxs("div",{className:"starasia-calendar-header",children:[n.jsx(z,{onClick:()=>w()}),n.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),n.jsx(O,{onClick:()=>p()})]})};function N(r){const e=new Date(r),s=e.getFullYear(),o=e.getMonth();return`${e.getDate().toString().padStart(2,"0")} ${A[o]} ${s}`}const W="starasia-calendar-styles";(r=>{if(!document.getElementById(W)){const e=document.createElement("style");e.id=W,e.textContent=r,document.head.appendChild(e)}})(E);const Q=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:l,minDate:g,maxDate:p,placeholder:w,size:u,status:a},x)=>{const{ref:b,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,d]=m.useState("days"),[c,y]=m.useState(new Date),[i,f]=m.useState({from:(r==null?void 0:r.from)||new Date,to:(r==null?void 0:r.to)||new Date});m.useEffect(()=>{r?(y(r.from),f(r)):(y(new Date),f({from:new Date,to:new Date}))},[r]),m.useEffect(()=>{s&&d(s)},[s]),m.useEffect(()=>{s||d("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>{var v,$;if(!r)return"";if(s){if(t==="days")return`${N(i.from)} ~ ${N(i.to||i.from)||"-"}`;if(t==="months")return`${F[i.from.getMonth()]} ~ ${i.to?F[i.to.getMonth()]:"-"}`;if(t==="years")return`${(v=i.from)==null?void 0:v.getFullYear()} ~ ${(($=i.to)==null?void 0:$.getFullYear())||"-"}`}else return`${N(i.from)} ~ ${N(i.to||i.from)||"-"}`},C=()=>{if(h.current&&b.current&&o){const v=b.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<v.left+$.width?h.current.style.left=`${v.left-$.width+v.width}px`:h.current.style.left=`${v.left}px`,v.top+$.height>window.innerHeight?h.current.style.top=`${v.y-(v.height+$.height-28)}px`:h.current.style.top=`${v.y+v.height}px`}};return m.useEffect(()=>{h.current&&b.current&&o&&C()},[h,b,M]),m.useEffect(()=>{const v=x==null?void 0:x.current;return v&&v.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{v&&v.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),n.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?n.jsx(P,{value:D(),inputMode:"none",onClick:()=>{k(!0)},onChange:()=>{},disabled:l,placeholder:w,size:u,status:a}):null,M?n.jsxs("div",{className:`starasia-calendar ${o?"":"starasia-calendar-no-input"}`,ref:h,children:[n.jsx(K,{setViews:d,views:t,filter:s,date:c,setDate:y}),n.jsx("div",{className:"starasia-calendar-body",children:t==="days"?n.jsx(q,{date:c,setDate:y,setIsComponentVisible:k,dateRange:i,setDateRange:f,input:o,onChange:e,minDate:g,maxDate:p}):t==="months"?n.jsx(G,{date:c,setDate:y,filter:s,setViews:d,dateRange:i,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p}):n.jsx(U,{date:c,setDate:y,filter:s,setViews:d,dateRange:i,setDateRange:f,setIsComponentVisible:k,input:o,onChange:e,minDate:g,maxDate:p})})]}):null]})}),H="starasia-calendar-input-styles";(r=>{if(!document.getElementById(H)){const e=document.createElement("style");e.id=H,e.textContent=r,document.head.appendChild(e)}})(E);const L=r=>{if(r==="sm")return 16;if(r==="md")return 16;if(r==="lg")return 20},X=r=>{const{size:e="md",status:s="default",variant:o="outline",...l}=r,g=m.useRef(null),p=()=>{g.current&&l.onClick&&(g.current.focus(),l.onClick(""))};return n.jsxs("div",{className:`starasia-calendar-input-container starasia-calendar-input-${o} starasia-calendar-input-container-${s} ${e} `,onClick:p,children:[n.jsx("div",{className:"starasia-calendar-input-container-icon-left",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),n.jsx("div",{className:"starasia-calendar-input-preview-container",children:n.jsx("input",{className:"starasia-calendar-input",...l,disabled:s==="disable"?!0:l.disabled,value:l.value,ref:g})}),n.jsx("div",{className:"starasia-calendar-input-container-icon-right",children:n.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:L(e),height:L(e),viewBox:"0 0 20 20",fill:"none",children:n.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Z=({date:r,setDate:e,previewDate:s,setPreviewDate:o,setIsComponentVisible:l,minDate:g,maxDate:p,input:w,onChange:u})=>{let a=new Date(s.getFullYear(),s.getMonth(),1),x=a.getDay(),b=[];const M=r.toDateString(),k=s.getMonth();for(let t=0;t<42;t++){t===0&&x===0?a.setDate(a.getDate()-7):t===0?a.setDate(a.getDate()+(t-x)):a.setDate(a.getDate()+1);let d={currentMonth:a.getMonth()===k,date:new Date(a),month:a.getMonth(),number:a.getDate(),selected:a.toDateString()===M,year:a.getFullYear(),isDisabled:g&&a<g||p&&a>p};b.push(d)}const h=t=>{(!g||t>=g)&&(!p||t<=p)&&(e(t),u(t),o(t),w&&l(!1))};return n.jsxs("div",{className:"starasia-calendar-days-preivew",children:[n.jsx("div",{className:"starasia-calendar-days-name-preivew",children:j.map((t,d)=>n.jsx("p",{children:t},d))}),n.jsx("div",{className:"starasia-calendar-days-number-preivew",children:b.map((t,d)=>{const c=t.isDisabled;return n.jsx("p",{className:`${t.currentMonth?"starasia-calendar-days-current":"starasia-calendar-days"} ${t.selected?"starasia-calendar-days-active":""}`,style:{color:c?"#ccc":void 0,pointerEvents:c?"none":void 0,cursor:c?"not-allowed":"pointer",...w?{}:{width:"100%"}},onClick:()=>{c||h(t.date)},children:t.number},d)})})]})},_=({date:r,setDate:e,filter:s,setViews:o,onChange:l,previewDate:g,setPreviewDate:p,minDate:w,maxDate:u,input:a})=>{const x=r.getMonth(),b=r.getFullYear(),M=g.getFullYear(),k=h=>{(!w||h>=w)&&(!u||h<=u)&&(s?(l(h),e(h),p(h)):(o("days"),p(h)))};return n.jsx("div",{className:"starasia-calendar-months-preview",children:F.map((h,t)=>{const d=w&&new Date(M,t,1)<w||u&&new Date(M,t+1,0)>u;return n.jsx("p",{className:t===x&&M===b?"starasia-calendar-months-active":"",style:{color:d?"#ccc":void 0,pointerEvents:d?"none":void 0,cursor:d?"not-allowed":"pointer",...a?{}:{width:"100%"}},onClick:()=>{d||k(new Date(M,t))},children:h.slice(0,3)},t)})})},I=r=>{const e=Math.floor(r/10)*10,s=e+10;return{start:e,end:s}},R=({date:r,filter:e,setViews:s,setDate:o,onChange:l,previewDate:g,setPreviewDate:p,minDate:w,maxDate:u,input:a})=>{let x=[];const b=g.getFullYear(),{start:M,end:k}=I(b),h=r.getFullYear();for(let d=M;d<k;d++){let c=w&&new Date(d,0,1)<w||u&&new Date(d,11,31)>u;x.push({year:d,active:d===h,isDisabled:c})}const t=d=>{(!w||d>=w)&&(!u||d<=u)&&(e?(l(d),o(d),p(d)):(s("months"),p(d)))};return n.jsx("div",{className:"starasia-calendar-years-preview",children:x.map((d,c)=>n.jsx("p",{className:d.active?"starasia-calendar-months-active":"",style:{color:d.isDisabled?"#ccc":void 0,pointerEvents:d.isDisabled?"none":void 0,cursor:d.isDisabled?"not-allowed":"pointer",...a?{}:{width:"100%"}},onClick:()=>{d.isDisabled||t(new Date(d.year,0))},children:d.year},c))})},ee=({setViews:r,views:e,filter:s,previewDate:o,setPreviewDate:l})=>{const g=()=>{s||r(a=>a==="days"?"months":a==="months"?"years":"days")},p=()=>{if(e==="years"){l(a=>new Date(a.getFullYear()+10,0));return}if(e==="months"){l(a=>new Date(a.getFullYear()+1,a.getMonth()));return}l(a=>new Date(a.getFullYear(),a.getMonth()+1))},w=()=>{if(e==="years"){l(a=>new Date(a.getFullYear()-10,0));return}if(e==="months"){l(a=>new Date(a.getFullYear()-1,a.getMonth()));return}l(a=>new Date(a.getMonth()===0?a.getFullYear()-1:a.getFullYear(),a.getMonth()===0?11:a.getMonth()-1))},u=()=>{if(e==="days")return`${F[o.getMonth()]} ${o.getFullYear()}`;if(e==="months")return`${o.getFullYear()}`;if(e==="years")return`${I(o.getFullYear()).start} ~ ${I(o.getFullYear()).end}`};return n.jsxs("div",{className:"starasia-calendar-header",children:[n.jsx(z,{onClick:()=>w()}),n.jsx("div",{style:{cursor:"pointer"},onClick:g,children:u()}),n.jsx(O,{onClick:()=>p()})]})},J="starasia-calendar-styles";(r=>{if(!document.getElementById(J)){const e=document.createElement("style");e.id=J,e.textContent=r,document.head.appendChild(e)}})(E);const ae=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,disabled:l,minDate:g,maxDate:p,placeholder:w,size:u,status:a},x)=>{const{ref:b,isComponentVisible:M,setIsComponentVisible:k}=B(!1),h=m.useRef(null),[t,d]=m.useState("days"),[c,y]=m.useState(new Date),[i,f]=m.useState(new Date);m.useEffect(()=>{r?(y(r),f(r)):(y(new Date),f(new Date))},[r]),m.useEffect(()=>{s&&d(s)},[s]),m.useEffect(()=>{s||d("days")},[M]),m.useEffect(()=>{o||k(!0)},[o]);const D=()=>r?s==="days"?N(c):s==="months"?`${F[c.getMonth()]} ${c.getFullYear()}`:s==="years"?c.getFullYear():N(c):"",C=()=>{if(h.current&&b.current&&o){const v=b.current.getBoundingClientRect(),$=h.current.getBoundingClientRect();window.innerWidth<v.left+$.width?h.current.style.left=`${v.left-$.width+v.width}px`:h.current.style.left=`${v.left}px`,v.top+$.height>window.innerHeight?h.current.style.top=`${v.y-(v.height+$.height-28)}px`:h.current.style.top=`${v.y+v.height}px`}};return m.useEffect(()=>{h.current&&b.current&&o&&C()},[h,b,M]),m.useEffect(()=>{const v=x==null?void 0:x.current;return v&&v.addEventListener("scroll",C),window.addEventListener("scroll",C),()=>{v&&v.removeEventListener("scroll",C),window.removeEventListener("scroll",C)}},[]),n.jsxs("div",{className:"starasia-calendar-wrapper",style:{height:o?"auto":"100%"},ref:o?b:null,children:[o?n.jsx(X,{value:D(),onClick:()=>k(!0),onChange:()=>{},placeholder:w,disabled:l,size:u,status:a,inputMode:"none"}):null,M?n.jsxs("div",{className:`starasia-calendar ${o?"":"starasia-calendar-no-input"}`,ref:h,children:[n.jsx(ee,{setViews:d,views:t,filter:s,previewDate:i,setPreviewDate:f,isComponentVisible:M}),n.jsx("div",{className:"starasia-calendar-body",children:t==="days"?n.jsx(Z,{date:c,setDate:y,previewDate:i,setPreviewDate:f,setIsComponentVisible:k,input:o,minDate:g,maxDate:p,onChange:e}):t==="months"?n.jsx(_,{date:c,setDate:y,previewDate:i,setPreviewDate:f,filter:s,setViews:d,onChange:e,minDate:g,maxDate:p,input:o}):n.jsx(R,{date:c,setDate:y,previewDate:i,setPreviewDate:f,filter:s,setViews:d,onChange:e,minDate:g,maxDate:p,input:o})})]}):null]})}),ne=m.forwardRef(({value:r,onChange:e,filter:s,input:o=!0,rangedDate:l,disabled:g,minDate:p,maxDate:w,placeholder:u,size:a,status:x},b)=>n.jsx(n.Fragment,{children:l?n.jsx(Q,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:b,minDate:p,maxDate:w,placeholder:u,size:a,status:x}):n.jsx(ae,{onChange:e,value:r,input:o,filter:s,disabled:g,ref:b,minDate:p,maxDate:w,placeholder:u,size:a,status:x})}));Y.StarasiaDate=ne,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/date",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "date component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/date.umd.js",
@@ -12,10 +12,6 @@
12
12
  "dist/*.map",
13
13
  "dist/*.css"
14
14
  ],
15
- "scripts": {
16
- "dev": "vite --config vite.config.ts --port 3000",
17
- "build": "vite build --config vite.config.ts"
18
- },
19
15
  "keywords": [],
20
16
  "license": "ISC",
21
17
  "type": "module",
@@ -37,5 +33,9 @@
37
33
  "react-dom": "^18.2.0",
38
34
  "@types/react": "^18.2.55",
39
35
  "@types/react-dom": "^18.2.19"
36
+ },
37
+ "scripts": {
38
+ "dev": "vite --config vite.config.ts --port 3000",
39
+ "build": "vite build --config vite.config.ts"
40
40
  }
41
- }
41
+ }