tw-react-components 0.0.142 → 0.0.145

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.cjs.js CHANGED
@@ -155,11 +155,13 @@ function mergeRefs(refs) {
155
155
  };
156
156
  }
157
157
 
158
- function resolveTargetObject(payload, fieldChain) {
158
+ function resolveTargetObject(payload, fieldChain, defaultValue) {
159
159
  if (!fieldChain.length) {
160
- return payload;
160
+ return payload === null ? payload : payload || defaultValue;
161
161
  }
162
162
  if (typeof payload !== 'object' || !payload) {
163
+ if (defaultValue)
164
+ return defaultValue;
163
165
  throw new Error(`Could not resolve field ${fieldChain[0]} because payload is not an object!`);
164
166
  }
165
167
  const [key, ...rest] = fieldChain;
@@ -171,9 +173,9 @@ function resolveTargetObject(payload, fieldChain) {
171
173
  if (index < 0 || index >= payload.length) {
172
174
  throw new Error('Index out of payload boundaries!');
173
175
  }
174
- return resolveTargetObject(payload[index], rest);
176
+ return resolveTargetObject(payload[index], rest, defaultValue);
175
177
  }
176
- return resolveTargetObject(payload[key], rest);
178
+ return resolveTargetObject(payload[key], rest, defaultValue);
177
179
  }
178
180
 
179
181
  const variantClassNames = {
@@ -1336,7 +1338,7 @@ const SelectInput = react.forwardRef((_a, ref) => {
1336
1338
  }, children: jsxRuntime.jsx("span", { children: renderItem(option, !!selectedMap[option.id]) }) }));
1337
1339
  }, [ItemComponent, handleOnSelect, multiple, renderItem, selectedMap]);
1338
1340
  return (jsxRuntime.jsxs(DropdownMenu, { open: open, onOpenChange: setOpen, children: [jsxRuntime.jsx(DropdownMenu.Trigger, { className: cn('w-full', className), children: jsxRuntime.jsx(TextInput, Object.assign({ className: "[&>div>*]:cursor-pointer", inputClassName: "text-left" }, props, { value: text !== null && text !== void 0 ? text : '', clearable: clearable && !!selectedItems.length, onClear: handleOnClear, suffixIcon: lucideReact.ChevronDownIcon, onSuffixIconClick: () => setOpen((open) => !open), ref: ref, readOnly: true })) }), jsxRuntime.jsxs(DropdownMenu.Content, { className: "flex max-h-80 w-[calc(var(--radix-popper-anchor-width))] flex-col overflow-hidden", children: [search && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(TextInput, { value: searchValue, placeholder: "Search...", size: props.size, onChange: handleOnSearchValueChange, clearable: !!searchValue.length, onClear: clearSearchValue }), jsxRuntime.jsx(DropdownMenu.Separator, { className: "w-full" })] })), filteredItems.length === 0 &&
1339
- (allowAddition && searchValue ? (jsxRuntime.jsxs("button", { className: "rounded bg-slate-100 text-center hover:bg-slate-200 dark:bg-slate-900/30 dark:hover:bg-slate-700/30", onClick: handleOnAddItemClicked, children: ["Add '", searchValue, "'"] })) : (jsxRuntime.jsx("div", { className: "text-center text-slate-500", children: "No items." }))), jsxRuntime.jsx(GroupComponent, { className: "flex flex-col gap-1 overflow-auto", value: !multiple && selectedItems.length ? String(selectedItems[0].id) : undefined, children: filteredItems.map((item, index) => item.group ? (jsxRuntime.jsxs(Flex, { className: "gap-1", direction: "column", fullWidth: true, children: [jsxRuntime.jsx(DropdownMenu.Label, { className: "sticky top-0 z-[51] w-full rounded-md border bg-white py-1 dark:bg-slate-900", children: item.label }), item.items.map((subItem) => (jsxRuntime.jsx(RenderOption, Object.assign({}, subItem), subItem.id))), index < filteredItems.length - 1 && (jsxRuntime.jsx("div", { className: "mb-1 h-px w-full bg-slate-200 dark:bg-slate-700" }))] }, item.id)) : (jsxRuntime.jsx(RenderOption, Object.assign({}, item), item.id))) })] })] }));
1341
+ (allowAddition && searchValue ? (jsxRuntime.jsxs("button", { className: "rounded bg-slate-100 py-1.5 text-center hover:bg-slate-200 dark:bg-slate-900/30 dark:hover:bg-slate-700/30", onClick: handleOnAddItemClicked, children: ["Add '", searchValue, "'"] })) : (jsxRuntime.jsx("div", { className: "py-1.5 text-center text-slate-500", children: "No items." }))), jsxRuntime.jsx(GroupComponent, { className: "flex flex-col gap-1 overflow-auto", value: !multiple && selectedItems.length ? String(selectedItems[0].id) : undefined, children: filteredItems.map((item, index) => item.group ? (jsxRuntime.jsxs(Flex, { className: "gap-1", direction: "column", fullWidth: true, children: [jsxRuntime.jsx(DropdownMenu.Label, { className: "sticky top-0 z-[51] w-full rounded-md border bg-white py-1 dark:bg-slate-900", children: item.label }), item.items.map((subItem) => (jsxRuntime.jsx(RenderOption, Object.assign({}, subItem), subItem.id))), index < filteredItems.length - 1 && (jsxRuntime.jsx("div", { className: "mb-1 h-px w-full bg-slate-200 dark:bg-slate-700" }))] }, item.id)) : (jsxRuntime.jsx(RenderOption, Object.assign({}, item), item.id))) })] })] }));
1340
1342
  });
1341
1343
 
1342
1344
  const FileInput = react.forwardRef((_a, ref) => {
@@ -1522,7 +1524,7 @@ const Table = Object.assign($Table, {
1522
1524
 
1523
1525
  const possiblePageSize = [5, 10, 25, 50, 100, 500, 1000];
1524
1526
  function defaultRender(item, field) {
1525
- return resolveTargetObject(item, field.split('.'));
1527
+ return resolveTargetObject(item, field.split('.'), '-');
1526
1528
  }
1527
1529
  function DataTable({ className, columns, rows, sorting, pagination, actions = [], isLoading, rowExtraContent, noDataMessage, onRowClick, rowClassName, }) {
1528
1530
  var _a;
@@ -2053,7 +2055,11 @@ const Navbar = ({ className, sidebarTriggerClassName, leftSlot, rightSlot, }) =>
2053
2055
 
2054
2056
  const Layout = (_a) => {
2055
2057
  var { children, className } = _a, _b = _a.sidebarProps, { basePath, header, items, footer } = _b, sidebarProps = __rest(_b, ["basePath", "header", "items", "footer"]), { navbarProps } = _a;
2056
- return (jsxRuntime.jsxs(Flex, { className: "h-screen w-screen gap-0 text-black dark:bg-slate-900 dark:text-white", children: [jsxRuntime.jsxs(Sidebar, Object.assign({ collapsible: "icon" }, sidebarProps, { children: [header && (jsxRuntime.jsx(Sidebar.Header, { children: jsxRuntime.jsx(Sidebar.Menu, { children: jsxRuntime.jsx(Sidebar.MenuItem, { children: header }) }) })), jsxRuntime.jsx(Sidebar.Content, { className: "gap-0", children: items.map((item, index) => item.type === 'item' ? (jsxRuntime.jsx(Sidebar.Group, { children: jsxRuntime.jsx(Sidebar.Menu, { children: jsxRuntime.jsx(RenderSideBarItem, Object.assign({ basePath: basePath }, item)) }) }, index)) : (jsxRuntime.jsxs(Sidebar.Group, { children: [item.title && jsxRuntime.jsx(Sidebar.GroupLabel, { children: item.title }), jsxRuntime.jsx(Sidebar.GroupContent, { children: jsxRuntime.jsx(Sidebar.Menu, { children: item.items.map((item, index) => (jsxRuntime.jsx(RenderSideBarItem, Object.assign({ basePath: basePath }, item), index))) }) })] }, index))) }), footer && (jsxRuntime.jsx(Sidebar.Footer, { children: jsxRuntime.jsx(Sidebar.Menu, { children: jsxRuntime.jsx(Sidebar.MenuItem, { children: footer }) }) })), jsxRuntime.jsx(Sidebar.Rail, {})] })), jsxRuntime.jsxs(Flex, { className: "gap-0 overflow-hidden", direction: "column", fullHeight: true, fullWidth: true, children: [navbarProps && jsxRuntime.jsx(Navbar, Object.assign({}, navbarProps)), jsxRuntime.jsx(Flex, { className: cn('overflow-hidden p-3', className), direction: "column", fullWidth: true, fullHeight: true, children: children })] })] }));
2058
+ return (jsxRuntime.jsxs(Flex, { className: "h-screen w-screen gap-0 text-black dark:bg-slate-900 dark:text-white", children: [jsxRuntime.jsxs(Sidebar, Object.assign({ collapsible: "icon" }, sidebarProps, { children: [header && (jsxRuntime.jsx(Sidebar.Header, { children: jsxRuntime.jsx(Sidebar.Menu, { children: jsxRuntime.jsx(Sidebar.MenuItem, { children: header }) }) })), jsxRuntime.jsx(Sidebar.Content, { className: "gap-0", children: items
2059
+ .filter((item) => !item.hidden)
2060
+ .map((item, index) => item.type === 'item' ? (jsxRuntime.jsx(Sidebar.Group, { children: jsxRuntime.jsx(Sidebar.Menu, { children: jsxRuntime.jsx(RenderSideBarItem, Object.assign({ basePath: basePath }, item)) }) }, index)) : (jsxRuntime.jsxs(Sidebar.Group, { children: [item.title && jsxRuntime.jsx(Sidebar.GroupLabel, { children: item.title }), jsxRuntime.jsx(Sidebar.GroupContent, { children: jsxRuntime.jsx(Sidebar.Menu, { children: item.items
2061
+ .filter((subItem) => !subItem.hidden)
2062
+ .map((subItem, index) => (jsxRuntime.jsx(RenderSideBarItem, Object.assign({ basePath: basePath }, subItem), index))) }) })] }, index))) }), footer && (jsxRuntime.jsx(Sidebar.Footer, { children: jsxRuntime.jsx(Sidebar.Menu, { children: jsxRuntime.jsx(Sidebar.MenuItem, { children: footer }) }) })), jsxRuntime.jsx(Sidebar.Rail, {})] })), jsxRuntime.jsxs(Flex, { className: "gap-0 overflow-hidden", direction: "column", fullHeight: true, fullWidth: true, children: [navbarProps && jsxRuntime.jsx(Navbar, Object.assign({}, navbarProps)), jsxRuntime.jsx(Flex, { className: cn('overflow-hidden p-3', className), direction: "column", fullWidth: true, fullHeight: true, children: children })] })] }));
2057
2063
  };
2058
2064
  const RenderSideBarItem = ({ basePath = '/', pathname, title, Icon, items, }) => {
2059
2065
  const location = reactRouterDom.useLocation();
@@ -2062,7 +2068,9 @@ const RenderSideBarItem = ({ basePath = '/', pathname, title, Icon, items, }) =>
2062
2068
  return (jsxRuntime.jsxs(Sidebar.MenuItem, { children: [jsxRuntime.jsx(Sidebar.MenuButton, { asChild: true, tooltip: title, isActive: isLinkStartsWithPathname(currentPath, pathname) &&
2063
2069
  (!items ||
2064
2070
  (!open &&
2065
- items.some((item) => isLinkStartsWithPathname(currentPath, `${pathname}/${item.pathname}`)))), children: jsxRuntime.jsxs(reactRouterDom.Link, { to: pathname, className: "font-medium", children: [Icon && jsxRuntime.jsx(Icon, {}), title] }) }), items && (jsxRuntime.jsx(Sidebar.MenuSub, { children: items.map((subItem, index) => (jsxRuntime.jsx(Sidebar.MenuSubItem, { children: jsxRuntime.jsx(Sidebar.MenuSubButton, { asChild: true, isActive: isLinkStartsWithPathname(currentPath, `${pathname}/${subItem.pathname}`), children: jsxRuntime.jsx(reactRouterDom.Link, { to: `${pathname}/${subItem.pathname}`, children: subItem.title }) }) }, index))) }))] }));
2071
+ items.some((item) => isLinkStartsWithPathname(currentPath, `${pathname}/${item.pathname}`)))), children: jsxRuntime.jsxs(reactRouterDom.Link, { to: pathname, className: "font-medium", children: [Icon && jsxRuntime.jsx(Icon, {}), title] }) }), items && (jsxRuntime.jsx(Sidebar.MenuSub, { children: items
2072
+ .filter((subItem) => !subItem.hidden)
2073
+ .map((subItem, index) => (jsxRuntime.jsx(Sidebar.MenuSubItem, { children: jsxRuntime.jsx(Sidebar.MenuSubButton, { asChild: true, isActive: isLinkStartsWithPathname(currentPath, `${pathname}/${subItem.pathname}`), children: jsxRuntime.jsx(reactRouterDom.Link, { to: `${pathname}/${subItem.pathname}`, children: subItem.title }) }) }, index))) }))] }));
2066
2074
  };
2067
2075
  function isLinkStartsWithPathname(link, pathname) {
2068
2076
  return pathname === '' ? link === pathname : link.startsWith(pathname);
@@ -2112,8 +2120,11 @@ const LayoutContext = react.createContext(undefined);
2112
2120
  const THEME_MEDIA_QUERY = '(prefers-color-scheme: dark)';
2113
2121
  const THEME_COOKIE_NAME = 'theme:state';
2114
2122
  const THEME_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
2123
+ const SHOW_IDS_COOKIE_NAME = 'show-ids:state';
2124
+ const SHOW_IDS_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
2115
2125
  const LayoutContextProvider = ({ children }) => {
2116
2126
  const [theme, _setTheme] = react.useState(getValueFromCookie(THEME_COOKIE_NAME, 'system'));
2127
+ const [showIds, _setShowIds] = react.useState(getValueFromCookie(SHOW_IDS_COOKIE_NAME, false));
2117
2128
  const [resolvedTheme, setResolvedTheme] = react.useState(() => theme === 'system' ? getSystemTheme() : theme);
2118
2129
  react.useEffect(() => {
2119
2130
  if (resolvedTheme === 'dark') {
@@ -2139,7 +2150,13 @@ const LayoutContextProvider = ({ children }) => {
2139
2150
  // This sets the cookie to keep the theme state.
2140
2151
  document.cookie = `${THEME_COOKIE_NAME}=${theme}; path=/; max-age=${THEME_COOKIE_MAX_AGE}`;
2141
2152
  };
2142
- return (jsxRuntime.jsx(LayoutContext.Provider, { value: { theme, resolvedTheme, setTheme }, children: children }));
2153
+ const toggleShowIds = () => _setShowIds((showIds) => {
2154
+ const newValue = !showIds;
2155
+ // This sets the cookie to keep the showIds state.
2156
+ document.cookie = `${SHOW_IDS_COOKIE_NAME}=${newValue}; path=/; max-age=${SHOW_IDS_COOKIE_MAX_AGE}`;
2157
+ return newValue;
2158
+ });
2159
+ return (jsxRuntime.jsx(LayoutContext.Provider, { value: { theme, resolvedTheme, setTheme, showIds, toggleShowIds }, children: children }));
2143
2160
  };
2144
2161
  function useLayoutContext() {
2145
2162
  const context = react.useContext(LayoutContext);
@@ -2191,6 +2208,8 @@ exports.Pagination = Pagination;
2191
2208
  exports.PasswordInput = PasswordInput;
2192
2209
  exports.PdfViewerDialog = PdfViewerDialog;
2193
2210
  exports.Popover = Popover;
2211
+ exports.SHOW_IDS_COOKIE_MAX_AGE = SHOW_IDS_COOKIE_MAX_AGE;
2212
+ exports.SHOW_IDS_COOKIE_NAME = SHOW_IDS_COOKIE_NAME;
2194
2213
  exports.SIDEBAR_COOKIE_MAX_AGE = SIDEBAR_COOKIE_MAX_AGE;
2195
2214
  exports.SIDEBAR_COOKIE_NAME = SIDEBAR_COOKIE_NAME;
2196
2215
  exports.SIDEBAR_KEYBOARD_SHORTCUT = SIDEBAR_KEYBOARD_SHORTCUT;
package/index.esm.js CHANGED
@@ -128,11 +128,13 @@ function mergeRefs(refs) {
128
128
  };
129
129
  }
130
130
 
131
- function resolveTargetObject(payload, fieldChain) {
131
+ function resolveTargetObject(payload, fieldChain, defaultValue) {
132
132
  if (!fieldChain.length) {
133
- return payload;
133
+ return payload === null ? payload : payload || defaultValue;
134
134
  }
135
135
  if (typeof payload !== 'object' || !payload) {
136
+ if (defaultValue)
137
+ return defaultValue;
136
138
  throw new Error(`Could not resolve field ${fieldChain[0]} because payload is not an object!`);
137
139
  }
138
140
  const [key, ...rest] = fieldChain;
@@ -144,9 +146,9 @@ function resolveTargetObject(payload, fieldChain) {
144
146
  if (index < 0 || index >= payload.length) {
145
147
  throw new Error('Index out of payload boundaries!');
146
148
  }
147
- return resolveTargetObject(payload[index], rest);
149
+ return resolveTargetObject(payload[index], rest, defaultValue);
148
150
  }
149
- return resolveTargetObject(payload[key], rest);
151
+ return resolveTargetObject(payload[key], rest, defaultValue);
150
152
  }
151
153
 
152
154
  const variantClassNames = {
@@ -1309,7 +1311,7 @@ const SelectInput = forwardRef((_a, ref) => {
1309
1311
  }, children: jsx("span", { children: renderItem(option, !!selectedMap[option.id]) }) }));
1310
1312
  }, [ItemComponent, handleOnSelect, multiple, renderItem, selectedMap]);
1311
1313
  return (jsxs(DropdownMenu, { open: open, onOpenChange: setOpen, children: [jsx(DropdownMenu.Trigger, { className: cn('w-full', className), children: jsx(TextInput, Object.assign({ className: "[&>div>*]:cursor-pointer", inputClassName: "text-left" }, props, { value: text !== null && text !== void 0 ? text : '', clearable: clearable && !!selectedItems.length, onClear: handleOnClear, suffixIcon: ChevronDownIcon, onSuffixIconClick: () => setOpen((open) => !open), ref: ref, readOnly: true })) }), jsxs(DropdownMenu.Content, { className: "flex max-h-80 w-[calc(var(--radix-popper-anchor-width))] flex-col overflow-hidden", children: [search && (jsxs(Fragment, { children: [jsx(TextInput, { value: searchValue, placeholder: "Search...", size: props.size, onChange: handleOnSearchValueChange, clearable: !!searchValue.length, onClear: clearSearchValue }), jsx(DropdownMenu.Separator, { className: "w-full" })] })), filteredItems.length === 0 &&
1312
- (allowAddition && searchValue ? (jsxs("button", { className: "rounded bg-slate-100 text-center hover:bg-slate-200 dark:bg-slate-900/30 dark:hover:bg-slate-700/30", onClick: handleOnAddItemClicked, children: ["Add '", searchValue, "'"] })) : (jsx("div", { className: "text-center text-slate-500", children: "No items." }))), jsx(GroupComponent, { className: "flex flex-col gap-1 overflow-auto", value: !multiple && selectedItems.length ? String(selectedItems[0].id) : undefined, children: filteredItems.map((item, index) => item.group ? (jsxs(Flex, { className: "gap-1", direction: "column", fullWidth: true, children: [jsx(DropdownMenu.Label, { className: "sticky top-0 z-[51] w-full rounded-md border bg-white py-1 dark:bg-slate-900", children: item.label }), item.items.map((subItem) => (jsx(RenderOption, Object.assign({}, subItem), subItem.id))), index < filteredItems.length - 1 && (jsx("div", { className: "mb-1 h-px w-full bg-slate-200 dark:bg-slate-700" }))] }, item.id)) : (jsx(RenderOption, Object.assign({}, item), item.id))) })] })] }));
1314
+ (allowAddition && searchValue ? (jsxs("button", { className: "rounded bg-slate-100 py-1.5 text-center hover:bg-slate-200 dark:bg-slate-900/30 dark:hover:bg-slate-700/30", onClick: handleOnAddItemClicked, children: ["Add '", searchValue, "'"] })) : (jsx("div", { className: "py-1.5 text-center text-slate-500", children: "No items." }))), jsx(GroupComponent, { className: "flex flex-col gap-1 overflow-auto", value: !multiple && selectedItems.length ? String(selectedItems[0].id) : undefined, children: filteredItems.map((item, index) => item.group ? (jsxs(Flex, { className: "gap-1", direction: "column", fullWidth: true, children: [jsx(DropdownMenu.Label, { className: "sticky top-0 z-[51] w-full rounded-md border bg-white py-1 dark:bg-slate-900", children: item.label }), item.items.map((subItem) => (jsx(RenderOption, Object.assign({}, subItem), subItem.id))), index < filteredItems.length - 1 && (jsx("div", { className: "mb-1 h-px w-full bg-slate-200 dark:bg-slate-700" }))] }, item.id)) : (jsx(RenderOption, Object.assign({}, item), item.id))) })] })] }));
1313
1315
  });
1314
1316
 
1315
1317
  const FileInput = forwardRef((_a, ref) => {
@@ -1495,7 +1497,7 @@ const Table = Object.assign($Table, {
1495
1497
 
1496
1498
  const possiblePageSize = [5, 10, 25, 50, 100, 500, 1000];
1497
1499
  function defaultRender(item, field) {
1498
- return resolveTargetObject(item, field.split('.'));
1500
+ return resolveTargetObject(item, field.split('.'), '-');
1499
1501
  }
1500
1502
  function DataTable({ className, columns, rows, sorting, pagination, actions = [], isLoading, rowExtraContent, noDataMessage, onRowClick, rowClassName, }) {
1501
1503
  var _a;
@@ -2026,7 +2028,11 @@ const Navbar = ({ className, sidebarTriggerClassName, leftSlot, rightSlot, }) =>
2026
2028
 
2027
2029
  const Layout = (_a) => {
2028
2030
  var { children, className } = _a, _b = _a.sidebarProps, { basePath, header, items, footer } = _b, sidebarProps = __rest(_b, ["basePath", "header", "items", "footer"]), { navbarProps } = _a;
2029
- 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 }) }) })), jsx(Sidebar.Content, { className: "gap-0", children: items.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.map((item, index) => (jsx(RenderSideBarItem, Object.assign({ basePath: basePath }, item), index))) }) })] }, index))) }), 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 })] })] }));
2031
+ 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 }) }) })), jsx(Sidebar.Content, { className: "gap-0", children: items
2032
+ .filter((item) => !item.hidden)
2033
+ .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
2034
+ .filter((subItem) => !subItem.hidden)
2035
+ .map((subItem, index) => (jsx(RenderSideBarItem, Object.assign({ basePath: basePath }, subItem), index))) }) })] }, index))) }), 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 })] })] }));
2030
2036
  };
2031
2037
  const RenderSideBarItem = ({ basePath = '/', pathname, title, Icon, items, }) => {
2032
2038
  const location = useLocation();
@@ -2035,7 +2041,9 @@ const RenderSideBarItem = ({ basePath = '/', pathname, title, Icon, items, }) =>
2035
2041
  return (jsxs(Sidebar.MenuItem, { children: [jsx(Sidebar.MenuButton, { asChild: true, tooltip: title, isActive: isLinkStartsWithPathname(currentPath, pathname) &&
2036
2042
  (!items ||
2037
2043
  (!open &&
2038
- items.some((item) => isLinkStartsWithPathname(currentPath, `${pathname}/${item.pathname}`)))), children: jsxs(Link, { to: pathname, className: "font-medium", children: [Icon && jsx(Icon, {}), title] }) }), items && (jsx(Sidebar.MenuSub, { children: items.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))) }))] }));
2044
+ items.some((item) => isLinkStartsWithPathname(currentPath, `${pathname}/${item.pathname}`)))), children: jsxs(Link, { to: pathname, className: "font-medium", children: [Icon && jsx(Icon, {}), title] }) }), items && (jsx(Sidebar.MenuSub, { children: items
2045
+ .filter((subItem) => !subItem.hidden)
2046
+ .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))) }))] }));
2039
2047
  };
2040
2048
  function isLinkStartsWithPathname(link, pathname) {
2041
2049
  return pathname === '' ? link === pathname : link.startsWith(pathname);
@@ -2085,8 +2093,11 @@ const LayoutContext = createContext(undefined);
2085
2093
  const THEME_MEDIA_QUERY = '(prefers-color-scheme: dark)';
2086
2094
  const THEME_COOKIE_NAME = 'theme:state';
2087
2095
  const THEME_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
2096
+ const SHOW_IDS_COOKIE_NAME = 'show-ids:state';
2097
+ const SHOW_IDS_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
2088
2098
  const LayoutContextProvider = ({ children }) => {
2089
2099
  const [theme, _setTheme] = useState(getValueFromCookie(THEME_COOKIE_NAME, 'system'));
2100
+ const [showIds, _setShowIds] = useState(getValueFromCookie(SHOW_IDS_COOKIE_NAME, false));
2090
2101
  const [resolvedTheme, setResolvedTheme] = useState(() => theme === 'system' ? getSystemTheme() : theme);
2091
2102
  useEffect(() => {
2092
2103
  if (resolvedTheme === 'dark') {
@@ -2112,7 +2123,13 @@ const LayoutContextProvider = ({ children }) => {
2112
2123
  // This sets the cookie to keep the theme state.
2113
2124
  document.cookie = `${THEME_COOKIE_NAME}=${theme}; path=/; max-age=${THEME_COOKIE_MAX_AGE}`;
2114
2125
  };
2115
- return (jsx(LayoutContext.Provider, { value: { theme, resolvedTheme, setTheme }, children: children }));
2126
+ const toggleShowIds = () => _setShowIds((showIds) => {
2127
+ const newValue = !showIds;
2128
+ // This sets the cookie to keep the showIds state.
2129
+ document.cookie = `${SHOW_IDS_COOKIE_NAME}=${newValue}; path=/; max-age=${SHOW_IDS_COOKIE_MAX_AGE}`;
2130
+ return newValue;
2131
+ });
2132
+ return (jsx(LayoutContext.Provider, { value: { theme, resolvedTheme, setTheme, showIds, toggleShowIds }, children: children }));
2116
2133
  };
2117
2134
  function useLayoutContext() {
2118
2135
  const context = useContext(LayoutContext);
@@ -2132,4 +2149,4 @@ const ThemeSelector = ({ className }) => {
2132
2149
  return (jsxs(DropdownMenu, { children: [jsx(DropdownMenu.Trigger, { asChild: true, children: jsx(Button, { prefixIcon: resolvedTheme === 'dark' ? MoonIcon : SunIcon, className: className, variant: "text" }) }), jsxs(DropdownMenu.Content, { children: [jsxs(DropdownMenu.Item, { onClick: () => setTheme('light'), children: [jsx(DropdownMenu.Icon, { icon: SunIcon }), "Light"] }), jsxs(DropdownMenu.Item, { onClick: () => setTheme('dark'), children: [jsx(DropdownMenu.Icon, { icon: MoonIcon }), "Dark"] }), jsxs(DropdownMenu.Item, { onClick: () => setTheme('system'), children: [jsx(DropdownMenu.Icon, { icon: MonitorIcon }), "System"] })] })] }));
2133
2150
  };
2134
2151
 
2135
- export { Badge, BasicInput, BasicInputExtension, Block, Button, Card, CheckboxInput, ConfirmDialog, DataTable, DateTimeInput, Dialog, DropdownMenu, EmailInput, FileInput, Flex, FormDialog, FormGroup, FormInputs, Hint, Label, Layout, LayoutContext, LayoutContextProvider, List, ListSorter, ListSorterDialog, Navbar, NumberInput, Pagination, PasswordInput, PdfViewerDialog, Popover, SIDEBAR_COOKIE_MAX_AGE, SIDEBAR_COOKIE_NAME, SIDEBAR_KEYBOARD_SHORTCUT, SIDEBAR_WIDTH, SIDEBAR_WIDTH_ICON, SIDEBAR_WIDTH_MOBILE, SelectInput, Separator, Sheet, Sidebar, SidebarContext, SidebarContextProvider, Skeleton, Spinner, Switch, THEME_COOKIE_MAX_AGE, THEME_COOKIE_NAME, THEME_MEDIA_QUERY, Table, Tabs, TextInput, TextareaInput, ThemeSelector, Tooltip, cn, compareDates, generalComparator, getDisplayDate, getValueFromCookie, isEmpty, mergeRefs, resolveTargetObject, useDays, useIsMobile, useLayoutContext, useLongPress, useMonths, useOnSwipe, useOutsideClick, usePagination, useSidebar };
2152
+ export { Badge, BasicInput, BasicInputExtension, Block, Button, Card, CheckboxInput, ConfirmDialog, DataTable, DateTimeInput, Dialog, DropdownMenu, EmailInput, FileInput, Flex, FormDialog, FormGroup, FormInputs, Hint, Label, Layout, LayoutContext, LayoutContextProvider, List, ListSorter, ListSorterDialog, Navbar, NumberInput, Pagination, PasswordInput, PdfViewerDialog, Popover, SHOW_IDS_COOKIE_MAX_AGE, SHOW_IDS_COOKIE_NAME, SIDEBAR_COOKIE_MAX_AGE, SIDEBAR_COOKIE_NAME, SIDEBAR_KEYBOARD_SHORTCUT, SIDEBAR_WIDTH, SIDEBAR_WIDTH_ICON, SIDEBAR_WIDTH_MOBILE, SelectInput, Separator, Sheet, Sidebar, SidebarContext, SidebarContextProvider, Skeleton, Spinner, Switch, THEME_COOKIE_MAX_AGE, THEME_COOKIE_NAME, THEME_MEDIA_QUERY, Table, Tabs, TextInput, TextareaInput, ThemeSelector, Tooltip, cn, compareDates, generalComparator, getDisplayDate, getValueFromCookie, isEmpty, mergeRefs, resolveTargetObject, useDays, useIsMobile, useLayoutContext, useLongPress, useMonths, useOnSwipe, useOutsideClick, usePagination, useSidebar };
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.142",
4
+ "version": "0.0.145",
5
5
  "license": "MIT",
6
6
  "homepage": "https://bacali95.github.io/tw-react-components",
7
7
  "author": {
@@ -17,6 +17,7 @@ export type SidebarProps = ComponentProps<typeof Sidebar> & {
17
17
  } & SidebarItem) | {
18
18
  type: 'group';
19
19
  title?: string;
20
+ hidden?: boolean;
20
21
  items: SidebarItem[];
21
22
  })[];
22
23
  footer?: ReactNode;
@@ -4,10 +4,14 @@ export type LayoutContext = {
4
4
  theme: ThemeState;
5
5
  resolvedTheme: Exclude<ThemeState, 'system'>;
6
6
  setTheme: (theme: ThemeState) => void;
7
+ showIds: boolean;
8
+ toggleShowIds: () => void;
7
9
  };
8
10
  export declare const LayoutContext: import("react").Context<LayoutContext | undefined>;
9
11
  export declare const THEME_MEDIA_QUERY = "(prefers-color-scheme: dark)";
10
12
  export declare const THEME_COOKIE_NAME = "theme:state";
11
13
  export declare const THEME_COOKIE_MAX_AGE: number;
14
+ export declare const SHOW_IDS_COOKIE_NAME = "show-ids:state";
15
+ export declare const SHOW_IDS_COOKIE_MAX_AGE: number;
12
16
  export declare const LayoutContextProvider: FC<PropsWithChildren>;
13
17
  export declare function useLayoutContext(): LayoutContext;
@@ -1 +1 @@
1
- export declare function resolveTargetObject(payload: any, fieldChain: string[]): any;
1
+ export declare function resolveTargetObject(payload: any, fieldChain: string[], defaultValue?: any): any;