@particle-academy/react-fancy 1.3.4 → 1.4.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.
package/dist/index.cjs CHANGED
@@ -4506,6 +4506,13 @@ var Callout = react.forwardRef(
4506
4506
  }
4507
4507
  );
4508
4508
  Callout.displayName = "Callout";
4509
+ var TimelineContext = react.createContext({
4510
+ orientation: "vertical",
4511
+ index: 0
4512
+ });
4513
+ function useTimeline() {
4514
+ return react.useContext(TimelineContext);
4515
+ }
4509
4516
  var dotColorClasses2 = {
4510
4517
  blue: "bg-blue-500 dark:bg-blue-400",
4511
4518
  green: "bg-green-500 dark:bg-green-400",
@@ -4527,6 +4534,34 @@ var ringColorClasses = {
4527
4534
  red: "ring-red-500/30 dark:ring-red-400/30",
4528
4535
  zinc: "ring-zinc-400/30 dark:ring-zinc-500/30"
4529
4536
  };
4537
+ function Dot({ icon, color, active }) {
4538
+ const c = color ?? "zinc";
4539
+ if (icon) {
4540
+ return /* @__PURE__ */ jsxRuntime.jsx(
4541
+ "span",
4542
+ {
4543
+ className: cn(
4544
+ "flex h-6 w-6 items-center justify-center rounded-full bg-white dark:bg-zinc-900",
4545
+ iconColorClasses2[c],
4546
+ active && "ring-4",
4547
+ active && ringColorClasses[c]
4548
+ ),
4549
+ children: icon
4550
+ }
4551
+ );
4552
+ }
4553
+ return /* @__PURE__ */ jsxRuntime.jsx(
4554
+ "span",
4555
+ {
4556
+ className: cn(
4557
+ "h-3 w-3 rounded-full",
4558
+ dotColorClasses2[c],
4559
+ active && "ring-4",
4560
+ active && ringColorClasses[c]
4561
+ )
4562
+ }
4563
+ );
4564
+ }
4530
4565
  var TimelineItem = react.forwardRef(
4531
4566
  ({
4532
4567
  children,
@@ -4535,6 +4570,28 @@ var TimelineItem = react.forwardRef(
4535
4570
  active = false,
4536
4571
  className
4537
4572
  }, ref) => {
4573
+ const { orientation, index } = useTimeline();
4574
+ if (orientation === "horizontal") {
4575
+ const isTop = index % 2 === 0;
4576
+ return /* @__PURE__ */ jsxRuntime.jsxs(
4577
+ "div",
4578
+ {
4579
+ ref,
4580
+ "data-react-fancy-timeline-item": "",
4581
+ className: cn("relative flex flex-col items-center", className),
4582
+ style: { minWidth: 120 },
4583
+ children: [
4584
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("flex min-h-[4rem] items-end pb-2", !isTop && "invisible"), children: isTop && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-w-0 text-center", children }) }),
4585
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative flex w-full items-center justify-center", children: [
4586
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-px flex-1 bg-zinc-200 dark:bg-zinc-700" }),
4587
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative z-10 flex shrink-0 items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(Dot, { icon, color, active }) }),
4588
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-px flex-1 bg-zinc-200 dark:bg-zinc-700" })
4589
+ ] }),
4590
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("flex min-h-[4rem] items-start pt-2", isTop && "invisible"), children: !isTop && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-w-0 text-center", children }) })
4591
+ ]
4592
+ }
4593
+ );
4594
+ }
4538
4595
  return /* @__PURE__ */ jsxRuntime.jsxs(
4539
4596
  "div",
4540
4597
  {
@@ -4543,28 +4600,7 @@ var TimelineItem = react.forwardRef(
4543
4600
  className: cn("relative flex gap-4 pb-8 last:pb-0", className),
4544
4601
  children: [
4545
4602
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute left-[11px] top-6 bottom-0 w-px bg-zinc-200 last:hidden dark:bg-zinc-700" }),
4546
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative z-10 flex shrink-0", children: icon ? /* @__PURE__ */ jsxRuntime.jsx(
4547
- "span",
4548
- {
4549
- className: cn(
4550
- "flex h-6 w-6 items-center justify-center rounded-full bg-white dark:bg-zinc-900",
4551
- iconColorClasses2[color],
4552
- active && "ring-4",
4553
- active && ringColorClasses[color]
4554
- ),
4555
- children: icon
4556
- }
4557
- ) : /* @__PURE__ */ jsxRuntime.jsx(
4558
- "span",
4559
- {
4560
- className: cn(
4561
- "mt-1.5 h-3 w-3 rounded-full",
4562
- dotColorClasses2[color],
4563
- active && "ring-4",
4564
- active && ringColorClasses[color]
4565
- )
4566
- }
4567
- ) }),
4603
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative z-10 flex shrink-0 mt-1.5", children: /* @__PURE__ */ jsxRuntime.jsx(Dot, { icon, color, active }) }),
4568
4604
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-w-0 flex-1 pt-0.5", children })
4569
4605
  ]
4570
4606
  }
@@ -4594,14 +4630,19 @@ var TimelineBlock = react.forwardRef(
4594
4630
  );
4595
4631
  TimelineBlock.displayName = "TimelineBlock";
4596
4632
  var TimelineRoot = react.forwardRef(
4597
- ({ children, className }, ref) => {
4633
+ ({ children, orientation = "vertical", className }, ref) => {
4634
+ const items = react.Children.toArray(children);
4598
4635
  return /* @__PURE__ */ jsxRuntime.jsx(
4599
4636
  "div",
4600
4637
  {
4601
4638
  ref,
4602
4639
  "data-react-fancy-timeline": "",
4603
- className: cn("flex flex-col", className),
4604
- children
4640
+ "data-orientation": orientation,
4641
+ className: cn(
4642
+ orientation === "vertical" ? "flex flex-col" : "flex flex-row items-center overflow-x-auto",
4643
+ className
4644
+ ),
4645
+ children: items.map((child, i) => /* @__PURE__ */ jsxRuntime.jsx(TimelineContext.Provider, { value: { orientation, index: i }, children: child }, i))
4605
4646
  }
4606
4647
  );
4607
4648
  }
@@ -4767,12 +4808,13 @@ function PopoverTrigger({ children }) {
4767
4808
  });
4768
4809
  }
4769
4810
  PopoverTrigger.displayName = "PopoverTrigger";
4770
- function useOutsideClick(ref, handler, enabled = true) {
4811
+ function useOutsideClick(ref, handler, enabled = true, ignoreRef) {
4771
4812
  react.useEffect(() => {
4772
4813
  if (!enabled) return;
4773
4814
  const listener = (event) => {
4774
4815
  const el = ref.current;
4775
4816
  if (!el || el.contains(event.target)) return;
4817
+ if (ignoreRef?.current?.contains(event.target)) return;
4776
4818
  handler(event);
4777
4819
  };
4778
4820
  document.addEventListener("mousedown", listener);
@@ -4781,7 +4823,7 @@ function useOutsideClick(ref, handler, enabled = true) {
4781
4823
  document.removeEventListener("mousedown", listener);
4782
4824
  document.removeEventListener("touchstart", listener);
4783
4825
  };
4784
- }, [ref, handler, enabled]);
4826
+ }, [ref, handler, enabled, ignoreRef]);
4785
4827
  }
4786
4828
  function useEscapeKey(handler, enabled = true) {
4787
4829
  react.useEffect(() => {
@@ -4835,7 +4877,7 @@ function PopoverContent({ children, className }) {
4835
4877
  enabled: open
4836
4878
  });
4837
4879
  const close = react.useCallback(() => setOpen(false), [setOpen]);
4838
- useOutsideClick(outsideRef, close, open);
4880
+ useOutsideClick(outsideRef, close, open, anchorRef);
4839
4881
  useEscapeKey(close, open);
4840
4882
  const { mounted, className: animClass, ref: animRef } = useAnimation({
4841
4883
  open,
@@ -4920,7 +4962,7 @@ function DropdownItems({ children, className }) {
4920
4962
  setOpen(false);
4921
4963
  setActiveIndex(-1);
4922
4964
  }, [setOpen, setActiveIndex]);
4923
- useOutsideClick(outsideRef, close, open);
4965
+ useOutsideClick(outsideRef, close, open, anchorRef);
4924
4966
  useEscapeKey(close, open);
4925
4967
  const { mounted, className: animClass, ref: animRef } = useAnimation({
4926
4968
  open,