baaz-custom-components 3.1.19 → 3.1.21

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.js CHANGED
@@ -676,6 +676,33 @@ function isLeaf(value) {
676
676
  function normalizePath(path) {
677
677
  return path.startsWith("/") ? path : `/${path}`;
678
678
  }
679
+ function extractPathname(urlOrPath) {
680
+ try {
681
+ if (urlOrPath.startsWith("http://") || urlOrPath.startsWith("https://")) {
682
+ return new URL(urlOrPath).pathname;
683
+ }
684
+ } catch (_) {
685
+ }
686
+ return urlOrPath;
687
+ }
688
+ function treeContainsPath({
689
+ data,
690
+ base,
691
+ pathname
692
+ }) {
693
+ for (const [, value] of Object.entries(data)) {
694
+ if (isLeaf(value)) {
695
+ const full = base + normalizePath(value);
696
+ const onlyPath = extractPathname(full);
697
+ if (onlyPath === pathname) return true;
698
+ continue;
699
+ }
700
+ if (treeContainsPath({ data: value, base, pathname })) {
701
+ return true;
702
+ }
703
+ }
704
+ return false;
705
+ }
679
706
  function MenuItems({
680
707
  data,
681
708
  base,
@@ -684,7 +711,7 @@ function MenuItems({
684
711
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: Object.entries(data).map(([label, value]) => {
685
712
  if (isLeaf(value)) {
686
713
  const fullPath = base + normalizePath(value);
687
- const active = fullPath === router.pathname;
714
+ const active = extractPathname(fullPath) === router.pathname;
688
715
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
689
716
  MenubarItem,
690
717
  {
@@ -716,24 +743,34 @@ function MenuList({
716
743
  router
717
744
  }) {
718
745
  const { name, url, routes } = entry;
746
+ const isGroupActive = treeContainsPath({ data: routes, base: url, pathname: router.pathname });
719
747
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Menubar, { className: "bg-transparent border-none", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(MenubarMenu, { children: [
720
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(MenubarTrigger, { className: "cursor-pointer group inline-flex items-center", children: [
721
- name,
722
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
723
- import_lucide_react5.ChevronDown,
724
- {
725
- size: 16,
726
- className: "ml-1 group-data-[state=open]:hidden"
727
- }
728
- ),
729
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
730
- import_lucide_react5.ChevronUp,
731
- {
732
- size: 16,
733
- className: "ml-1 group-data-[state=open]:inline hidden"
734
- }
735
- )
736
- ] }),
748
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
749
+ MenubarTrigger,
750
+ {
751
+ className: cn(
752
+ "cursor-pointer group inline-flex items-center",
753
+ isGroupActive && "bg-accent text-accent-foreground"
754
+ ),
755
+ children: [
756
+ name,
757
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
758
+ import_lucide_react5.ChevronDown,
759
+ {
760
+ size: 16,
761
+ className: "ml-1 group-data-[state=open]:hidden"
762
+ }
763
+ ),
764
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
765
+ import_lucide_react5.ChevronUp,
766
+ {
767
+ size: 16,
768
+ className: "ml-1 group-data-[state=open]:inline hidden"
769
+ }
770
+ )
771
+ ]
772
+ }
773
+ ),
737
774
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MenubarContent, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
738
775
  MenuItems,
739
776
  {
package/dist/index.mjs CHANGED
@@ -642,6 +642,33 @@ function isLeaf(value) {
642
642
  function normalizePath(path) {
643
643
  return path.startsWith("/") ? path : `/${path}`;
644
644
  }
645
+ function extractPathname(urlOrPath) {
646
+ try {
647
+ if (urlOrPath.startsWith("http://") || urlOrPath.startsWith("https://")) {
648
+ return new URL(urlOrPath).pathname;
649
+ }
650
+ } catch (_) {
651
+ }
652
+ return urlOrPath;
653
+ }
654
+ function treeContainsPath({
655
+ data,
656
+ base,
657
+ pathname
658
+ }) {
659
+ for (const [, value] of Object.entries(data)) {
660
+ if (isLeaf(value)) {
661
+ const full = base + normalizePath(value);
662
+ const onlyPath = extractPathname(full);
663
+ if (onlyPath === pathname) return true;
664
+ continue;
665
+ }
666
+ if (treeContainsPath({ data: value, base, pathname })) {
667
+ return true;
668
+ }
669
+ }
670
+ return false;
671
+ }
645
672
  function MenuItems({
646
673
  data,
647
674
  base,
@@ -650,7 +677,7 @@ function MenuItems({
650
677
  return /* @__PURE__ */ jsx9(Fragment, { children: Object.entries(data).map(([label, value]) => {
651
678
  if (isLeaf(value)) {
652
679
  const fullPath = base + normalizePath(value);
653
- const active = fullPath === router.pathname;
680
+ const active = extractPathname(fullPath) === router.pathname;
654
681
  return /* @__PURE__ */ jsx9(
655
682
  MenubarItem,
656
683
  {
@@ -682,24 +709,34 @@ function MenuList({
682
709
  router
683
710
  }) {
684
711
  const { name, url, routes } = entry;
712
+ const isGroupActive = treeContainsPath({ data: routes, base: url, pathname: router.pathname });
685
713
  return /* @__PURE__ */ jsx9(Menubar, { className: "bg-transparent border-none", children: /* @__PURE__ */ jsxs7(MenubarMenu, { children: [
686
- /* @__PURE__ */ jsxs7(MenubarTrigger, { className: "cursor-pointer group inline-flex items-center", children: [
687
- name,
688
- /* @__PURE__ */ jsx9(
689
- ChevronDown,
690
- {
691
- size: 16,
692
- className: "ml-1 group-data-[state=open]:hidden"
693
- }
694
- ),
695
- /* @__PURE__ */ jsx9(
696
- ChevronUp,
697
- {
698
- size: 16,
699
- className: "ml-1 group-data-[state=open]:inline hidden"
700
- }
701
- )
702
- ] }),
714
+ /* @__PURE__ */ jsxs7(
715
+ MenubarTrigger,
716
+ {
717
+ className: cn(
718
+ "cursor-pointer group inline-flex items-center",
719
+ isGroupActive && "bg-accent text-accent-foreground"
720
+ ),
721
+ children: [
722
+ name,
723
+ /* @__PURE__ */ jsx9(
724
+ ChevronDown,
725
+ {
726
+ size: 16,
727
+ className: "ml-1 group-data-[state=open]:hidden"
728
+ }
729
+ ),
730
+ /* @__PURE__ */ jsx9(
731
+ ChevronUp,
732
+ {
733
+ size: 16,
734
+ className: "ml-1 group-data-[state=open]:inline hidden"
735
+ }
736
+ )
737
+ ]
738
+ }
739
+ ),
703
740
  /* @__PURE__ */ jsx9(MenubarContent, { children: /* @__PURE__ */ jsx9(
704
741
  MenuItems,
705
742
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "baaz-custom-components",
3
- "version": "3.1.19",
3
+ "version": "3.1.21",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "main": "dist/index.js",