tw-react-components 0.0.149 → 0.0.151

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,7 +16,6 @@ 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, Link } from 'react-router-dom';
20
19
  import { Slot } from '@radix-ui/react-slot';
21
20
  import * as SeparatorPrimitive from '@radix-ui/react-separator';
22
21
  import * as PopoverPrimitive from '@radix-ui/react-popover';
@@ -1791,7 +1790,7 @@ const SidebarContextProvider = forwardRef((_a, ref) => {
1791
1790
  var { defaultOpen = true, open: openProp, onOpenChange: setOpenProp, className, style, children } = _a, props = __rest(_a, ["defaultOpen", "open", "onOpenChange", "className", "style", "children"]);
1792
1791
  const isMobile = useIsMobile();
1793
1792
  const [openMobile, setOpenMobile] = useState(false);
1794
- const screenRef = useRef(document.documentElement);
1793
+ const screenRef = useRef(typeof document === 'undefined' ? null : document.documentElement);
1795
1794
  // This is the internal state of the sidebar.
1796
1795
  // We use openProp and setOpenProp for control from outside the component.
1797
1796
  const [_open, _setOpen] = useState(getValueFromCookie(SIDEBAR_COOKIE_NAME, defaultOpen));
@@ -2039,14 +2038,14 @@ const Sidebar = Object.assign($Sidebar, {
2039
2038
  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] }) }));
2040
2039
 
2041
2040
  const Layout = (_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;
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;
2043
2042
  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
2044
2043
  .filter((item) => !item.hidden)
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
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
2046
2045
  .filter((subItem) => !subItem.hidden)
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 })] })] }));
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 })] })] }));
2048
2047
  };
2049
- const RenderSideBarItem = ({ basePath = '/', pathname, title, Icon, items, }) => {
2048
+ const RenderSideBarItem = ({ basePath = '/', pathname, title, Icon, items, Link, useLocation }) => {
2050
2049
  const location = useLocation();
2051
2050
  const { open } = useSidebar();
2052
2051
  const currentPath = useMemo(() => location.pathname.replace(basePath, '').replace(/^\/*/, ''), [basePath, location.pathname]);
@@ -2113,8 +2112,8 @@ const THEME_COOKIE_NAME = 'theme:state';
2113
2112
  const THEME_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
2114
2113
  const SHOW_IDS_COOKIE_NAME = 'show-ids:state';
2115
2114
  const SHOW_IDS_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
2116
- const LayoutContextProvider = ({ children }) => {
2117
- const [theme, _setTheme] = useState(getValueFromCookie(THEME_COOKIE_NAME, 'system'));
2115
+ const LayoutContextProvider = ({ children, defaultTheme, }) => {
2116
+ const [theme, _setTheme] = useState(defaultTheme !== null && defaultTheme !== void 0 ? defaultTheme : getValueFromCookie(THEME_COOKIE_NAME, 'system'));
2118
2117
  const [showIds, _setShowIds] = useState(getValueFromCookie(SHOW_IDS_COOKIE_NAME, false));
2119
2118
  const [resolvedTheme, setResolvedTheme] = useState(() => theme === 'system' ? getSystemTheme() : theme);
2120
2119
  useEffect(() => {
@@ -2157,6 +2156,8 @@ function useLayoutContext() {
2157
2156
  return context;
2158
2157
  }
2159
2158
  function getSystemTheme(e) {
2159
+ if (typeof window === 'undefined')
2160
+ return 'light';
2160
2161
  if (!e)
2161
2162
  e = window.matchMedia(THEME_MEDIA_QUERY);
2162
2163
  return e.matches ? 'dark' : 'light';
package/package.json CHANGED
@@ -1,9 +1,10 @@
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.149",
4
+ "version": "0.0.151",
5
5
  "license": "MIT",
6
6
  "homepage": "https://bacali95.github.io/tw-react-components",
7
+ "type": "module",
7
8
  "author": {
8
9
  "name": "Nasreddine Bac Ali",
9
10
  "email": "nasreddine.bacali95@gmail.com",
@@ -18,10 +19,8 @@
18
19
  },
19
20
  "exports": {
20
21
  ".": {
21
- "module": "./index.esm.js",
22
- "types": "./index.esm.d.ts",
23
- "import": "./index.cjs.mjs",
24
- "default": "./index.cjs.js"
22
+ "import": "./index.esm.js",
23
+ "types": "./index.esm.d.ts"
25
24
  },
26
25
  "./css": {
27
26
  "default": "./index.css"
@@ -32,6 +31,6 @@
32
31
  "./package.json": "./package.json"
33
32
  },
34
33
  "module": "./index.esm.js",
35
- "main": "./index.cjs.js",
34
+ "main": "./index.esm.js",
36
35
  "types": "./index.esm.d.ts"
37
36
  }
@@ -1,5 +1,6 @@
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';
3
4
  import { NavbarProps } from '../Navbar';
4
5
  import { Sidebar } from '../Sidebar';
5
6
  export type SidebarItem = {
@@ -27,6 +28,8 @@ type Props = {
27
28
  className?: string;
28
29
  sidebarProps: SidebarProps;
29
30
  navbarProps?: NavbarProps;
31
+ Link: FC<LinkProps>;
32
+ useLocation: typeof useLocation;
30
33
  };
31
34
  export declare const Layout: FC<PropsWithChildren<Props>>;
32
35
  export {};
@@ -13,5 +13,7 @@ export declare const THEME_COOKIE_NAME = "theme:state";
13
13
  export declare const THEME_COOKIE_MAX_AGE: number;
14
14
  export declare const SHOW_IDS_COOKIE_NAME = "show-ids:state";
15
15
  export declare const SHOW_IDS_COOKIE_MAX_AGE: number;
16
- export declare const LayoutContextProvider: FC<PropsWithChildren>;
16
+ export declare const LayoutContextProvider: FC<PropsWithChildren<{
17
+ defaultTheme?: ThemeState;
18
+ }>>;
17
19
  export declare function useLayoutContext(): LayoutContext;
package/index.cjs.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";
@@ -1 +0,0 @@
1
- exports._default = require('./index.cjs.js').default;