tw-react-components 0.0.155 → 0.0.157

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/index.esm.js CHANGED
@@ -16,6 +16,7 @@ import { useSensors, useSensor, PointerSensor, KeyboardSensor, DndContext, close
16
16
  import { restrictToFirstScrollableAncestor } from '@dnd-kit/modifiers';
17
17
  import { sortableKeyboardCoordinates, SortableContext, verticalListSortingStrategy, useSortable } from '@dnd-kit/sortable';
18
18
  import { CSS } from '@dnd-kit/utilities';
19
+ import { useLocation, NavLink } from 'react-router';
19
20
  import { Slot } from '@radix-ui/react-slot';
20
21
  import * as SeparatorPrimitive from '@radix-ui/react-separator';
21
22
  import * as PopoverPrimitive from '@radix-ui/react-popover';
@@ -2038,29 +2039,24 @@ const Sidebar = Object.assign($Sidebar, {
2038
2039
  const Navbar = ({ className, sidebarTriggerClassName, leftSlot, rightSlot, }) => (jsx(Block, { className: cn('border-b p-3 dark:border-slate-700', className), fullWidth: true, children: jsxs(Flex, { align: "center", justify: "between", children: [jsxs(Flex, { align: "center", children: [jsx(Sidebar.Trigger, { className: sidebarTriggerClassName }), leftSlot] }), rightSlot] }) }));
2039
2040
 
2040
2041
  const Layout = (_a) => {
2041
- var { children, className } = _a, _b = _a.sidebarProps, { basePath, header, items, extraContent, footer } = _b, sidebarProps = __rest(_b, ["basePath", "header", "items", "extraContent", "footer"]), { navbarProps, Link, useLocation } = _a;
2042
+ var { children, className } = _a, _b = _a.sidebarProps, { basePath, header, items, extraContent, footer } = _b, sidebarProps = __rest(_b, ["basePath", "header", "items", "extraContent", "footer"]), { navbarProps } = _a;
2042
2043
  return (jsxs(Flex, { className: "h-screen w-screen gap-0 text-black dark:bg-slate-900 dark:text-white", children: [jsxs(Sidebar, Object.assign({ collapsible: "icon" }, sidebarProps, { children: [header && (jsx(Sidebar.Header, { children: jsx(Sidebar.Menu, { children: jsx(Sidebar.MenuItem, { children: header }) }) })), jsxs(Sidebar.Content, { className: "gap-0", children: [items
2043
2044
  .filter((item) => !item.hidden)
2044
- .map((item, index) => item.type === 'item' ? (jsx(Sidebar.Group, { children: jsx(Sidebar.Menu, { children: jsx(RenderSideBarItem, Object.assign({ basePath: basePath, Link: Link, useLocation: useLocation }, item)) }) }, index)) : (jsxs(Sidebar.Group, { children: [item.title && jsx(Sidebar.GroupLabel, { children: item.title }), jsx(Sidebar.GroupContent, { children: jsx(Sidebar.Menu, { children: item.items
2045
+ .map((item, index) => item.type === 'item' ? (jsx(Sidebar.Group, { children: jsx(Sidebar.Menu, { children: jsx(RenderSideBarItem, Object.assign({ basePath: basePath }, item)) }) }, index)) : (jsxs(Sidebar.Group, { children: [item.title && jsx(Sidebar.GroupLabel, { children: item.title }), jsx(Sidebar.GroupContent, { children: jsx(Sidebar.Menu, { children: item.items
2045
2046
  .filter((subItem) => !subItem.hidden)
2046
- .map((subItem, index) => (jsx(RenderSideBarItem, Object.assign({ basePath: basePath, Link: Link, useLocation: useLocation }, subItem), index))) }) })] }, index))), extraContent] }), footer && (jsx(Sidebar.Footer, { children: jsx(Sidebar.Menu, { children: jsx(Sidebar.MenuItem, { children: footer }) }) })), jsx(Sidebar.Rail, {})] })), jsxs(Flex, { className: "gap-0 overflow-hidden", direction: "column", fullHeight: true, fullWidth: true, children: [navbarProps && jsx(Navbar, Object.assign({}, navbarProps)), jsx(Flex, { className: cn('overflow-hidden p-3', className), direction: "column", fullWidth: true, fullHeight: true, children: children })] })] }));
2047
+ .map((subItem, index) => (jsx(RenderSideBarItem, Object.assign({ basePath: basePath }, subItem), index))) }) })] }, index))), extraContent] }), footer && (jsx(Sidebar.Footer, { children: jsx(Sidebar.Menu, { children: jsx(Sidebar.MenuItem, { children: footer }) }) })), jsx(Sidebar.Rail, {})] })), jsxs(Flex, { className: "gap-0 overflow-hidden", direction: "column", fullHeight: true, fullWidth: true, children: [navbarProps && jsx(Navbar, Object.assign({}, navbarProps)), jsx(Flex, { className: cn('overflow-hidden p-3', className), direction: "column", fullWidth: true, fullHeight: true, children: children })] })] }));
2047
2048
  };
2048
- const RenderSideBarItem = ({ basePath = '/', pathname, title, Icon, items, Link, useLocation }) => {
2049
+ const RenderSideBarItem = ({ basePath = '/', pathname, title, Icon, items, }) => {
2049
2050
  const location = useLocation();
2050
2051
  const { open } = useSidebar();
2051
2052
  const currentPath = useMemo(() => location.pathname.replace(basePath, '').replace(/^\/*/, ''), [basePath, location.pathname]);
2052
2053
  if (!(items === null || items === void 0 ? void 0 : items.filter((subItem) => !subItem.hidden).length)) {
2053
- return (jsx(Sidebar.MenuItem, { children: jsx(Sidebar.MenuButton, { asChild: true, isActive: isLinkStartsWithPathname(currentPath, pathname), children: jsxs(Link, { to: pathname, className: "font-medium", children: [Icon && jsx(Icon, {}), title] }) }) }));
2054
+ return (jsx(Sidebar.MenuItem, { children: jsx(NavLink, { to: pathname, className: "font-medium", children: ({ isActive }) => (jsxs(Sidebar.MenuButton, { isActive: isActive, children: [Icon && jsx(Icon, {}), title] })) }) }));
2054
2055
  }
2055
- const isOpen = open &&
2056
- (isLinkStartsWithPathname(currentPath, pathname) ||
2057
- items.some((subItem) => isLinkStartsWithPathname(currentPath, `${pathname}/${subItem.pathname}`)));
2058
- return (jsx(Collapsible, { asChild: true, open: isOpen, className: "group/collapsible", children: jsxs(Sidebar.MenuItem, { children: [jsx(Collapsible.Trigger, { asChild: true, children: jsx(Sidebar.MenuButton, { asChild: true, tooltip: title, isActive: open
2059
- ? currentPath === pathname &&
2060
- !items.some((subItem) => isLinkStartsWithPathname(currentPath, `${pathname}/${subItem.pathname}`))
2061
- : isLinkStartsWithPathname(currentPath, pathname), children: jsxs(Link, { to: pathname, className: "font-medium", children: [Icon && jsx(Icon, {}), title, jsx(ChevronRightIcon, { className: "ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90" })] }) }) }), items && (jsx(Collapsible.Content, { children: jsx(Sidebar.MenuSub, { children: items
2056
+ const isOpen = open && isLinkStartsWithPathname(currentPath, pathname);
2057
+ return (jsx(Collapsible, { asChild: true, open: isOpen, className: "group/collapsible", children: jsxs(Sidebar.MenuItem, { children: [jsx(Collapsible.Trigger, { asChild: true, children: jsx(NavLink, { to: pathname, className: "font-medium", children: ({ isActive }) => (jsxs(Sidebar.MenuButton, { tooltip: title, isActive: !open && isActive, children: [Icon && jsx(Icon, {}), title, jsx(ChevronRightIcon, { className: "ml-auto transition-transform duration-200 group-data-[state=open]/collapsible:rotate-90" })] })) }) }), items && (jsx(Collapsible.Content, { children: jsx(Sidebar.MenuSub, { children: items
2062
2058
  .filter((subItem) => !subItem.hidden)
2063
- .map((subItem, index) => (jsx(Sidebar.MenuSubItem, { children: jsx(Sidebar.MenuSubButton, { asChild: true, isActive: isLinkStartsWithPathname(currentPath, `${pathname}/${subItem.pathname}`), children: jsx(Link, { to: `${pathname}/${subItem.pathname}`, children: subItem.title }) }) }, index))) }) }))] }) }));
2059
+ .map((subItem, index) => (jsx(Sidebar.MenuSubItem, { children: jsx(NavLink, { to: `${pathname}/${subItem.pathname}`, children: ({ isActive }) => (jsx(Sidebar.MenuSubButton, { isActive: isActive, children: subItem.title })) }) }, index))) }) }))] }) }));
2064
2060
  };
2065
2061
  function isLinkStartsWithPathname(link, pathname) {
2066
2062
  return pathname === '' ? link === pathname : link.startsWith(pathname);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tw-react-components",
3
3
  "description": "A set of React components build with TailwindCSS to make a nice dashboard.",
4
- "version": "0.0.155",
4
+ "version": "0.0.157",
5
5
  "license": "MIT",
6
6
  "homepage": "https://bacali95.github.io/tw-react-components",
7
7
  "type": "module",
@@ -1,6 +1,5 @@
1
1
  import { LucideIcon } from 'lucide-react';
2
2
  import { ComponentProps, FC, PropsWithChildren, ReactNode } from 'react';
3
- import type { LinkProps, useLocation } from 'react-router-dom';
4
3
  import { NavbarProps } from '../Navbar';
5
4
  import { Sidebar } from '../Sidebar';
6
5
  export type SidebarItem = {
@@ -28,8 +27,6 @@ type Props = {
28
27
  className?: string;
29
28
  sidebarProps: SidebarProps;
30
29
  navbarProps?: NavbarProps;
31
- Link: FC<LinkProps>;
32
- useLocation: typeof useLocation;
33
30
  };
34
31
  export declare const Layout: FC<PropsWithChildren<Props>>;
35
32
  export {};