@sqrzro/admin 2.1.0-bz.18 → 2.1.0-bz.19

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.
Files changed (101) hide show
  1. package/dist/components/AppLayout/index.d.ts +9 -0
  2. package/dist/components/AppLayout/index.js +14 -0
  3. package/dist/components/AppNavigation/index.d.ts +6 -0
  4. package/dist/components/AppNavigation/index.js +8 -0
  5. package/dist/components/AppNavigationComponent/index.d.ts +12 -0
  6. package/dist/components/AppNavigationComponent/index.js +19 -0
  7. package/dist/components/Auth/index.d.ts +10 -0
  8. package/dist/components/Auth/index.js +10 -0
  9. package/dist/components/Badge/index.d.ts +8 -0
  10. package/dist/components/Badge/index.js +20 -0
  11. package/dist/components/BooleanFilter/index.d.ts +5 -0
  12. package/dist/components/BooleanFilter/index.js +19 -0
  13. package/dist/components/Config/index.d.ts +6 -0
  14. package/dist/components/Config/index.js +9 -0
  15. package/dist/components/Dashboard/index.d.ts +7 -0
  16. package/dist/components/Dashboard/index.js +5 -0
  17. package/dist/components/DateFilter/index.d.ts +6 -0
  18. package/dist/components/DateFilter/index.js +31 -0
  19. package/dist/components/DropdownFilter/index.d.ts +6 -0
  20. package/dist/components/DropdownFilter/index.js +9 -0
  21. package/dist/components/FilterBar/index.d.ts +10 -0
  22. package/dist/components/FilterBar/index.js +39 -0
  23. package/dist/components/FilterBarClearButton/index.d.ts +6 -0
  24. package/dist/components/FilterBarClearButton/index.js +5 -0
  25. package/dist/components/FilterBarItem/index.d.ts +17 -0
  26. package/dist/components/FilterBarItem/index.js +32 -0
  27. package/dist/components/GridList/index.d.ts +5 -0
  28. package/dist/components/GridList/index.js +7 -0
  29. package/dist/components/GridListItem/index.d.ts +4 -0
  30. package/dist/components/GridListItem/index.js +8 -0
  31. package/dist/components/InfoPanel/index.d.ts +8 -0
  32. package/dist/components/InfoPanel/index.js +18 -0
  33. package/dist/components/List/index.d.ts +8 -0
  34. package/dist/components/List/index.js +23 -0
  35. package/dist/components/ListAction/index.d.ts +7 -0
  36. package/dist/components/ListAction/index.js +9 -0
  37. package/dist/components/ListActions/index.d.ts +11 -0
  38. package/dist/components/ListActions/index.js +19 -0
  39. package/dist/components/ListClientComponent/index.d.ts +15 -0
  40. package/dist/components/ListClientComponent/index.js +14 -0
  41. package/dist/components/ListComponent/index.d.ts +14 -0
  42. package/dist/components/ListComponent/index.js +21 -0
  43. package/dist/components/ListItem/index.d.ts +23 -0
  44. package/dist/components/ListItem/index.js +26 -0
  45. package/dist/components/ListSkeleton/index.d.ts +5 -0
  46. package/dist/components/ListSkeleton/index.js +5 -0
  47. package/dist/components/MeActions/index.d.ts +3 -0
  48. package/dist/components/MeActions/index.js +6 -0
  49. package/dist/components/MePanel/index.d.ts +9 -0
  50. package/dist/components/MePanel/index.js +7 -0
  51. package/dist/components/Menu/index.d.ts +8 -0
  52. package/dist/components/Menu/index.js +7 -0
  53. package/dist/components/MenuItem/index.d.ts +5 -0
  54. package/dist/components/MenuItem/index.js +20 -0
  55. package/dist/components/Page/index.d.ts +14 -0
  56. package/dist/components/Page/index.js +11 -0
  57. package/dist/components/PageActions/index.d.ts +6 -0
  58. package/dist/components/PageActions/index.js +13 -0
  59. package/dist/components/Panel/index.d.ts +9 -0
  60. package/dist/components/Panel/index.js +6 -0
  61. package/dist/components/RootLayout/index.d.ts +10 -0
  62. package/dist/components/RootLayout/index.js +15 -0
  63. package/dist/components/SettingsForm/index.d.ts +7 -0
  64. package/dist/components/SettingsForm/index.js +14 -0
  65. package/dist/components/SettingsPage/index.d.ts +3 -0
  66. package/dist/components/SettingsPage/index.js +9 -0
  67. package/dist/components/Table/index.d.ts +9 -0
  68. package/dist/components/Table/index.js +17 -0
  69. package/dist/components/TableClientComponent/index.d.ts +16 -0
  70. package/dist/components/TableClientComponent/index.js +49 -0
  71. package/dist/components/Tabs/index.d.ts +4 -0
  72. package/dist/components/Tabs/index.js +8 -0
  73. package/dist/components/TabsComponent/index.d.ts +8 -0
  74. package/dist/components/TabsComponent/index.js +9 -0
  75. package/dist/components/index.d.ts +33 -0
  76. package/dist/components/index.js +17 -0
  77. package/dist/hooks/useNavigation.d.ts +11 -0
  78. package/dist/hooks/useNavigation.js +27 -0
  79. package/dist/index.cjs +1166 -105
  80. package/dist/index.cjs.map +1 -1
  81. package/dist/index.d.ts +3 -169
  82. package/dist/index.js +3 -16
  83. package/dist/index.js.map +1 -1
  84. package/dist/interfaces.d.ts +10 -0
  85. package/dist/interfaces.js +1 -0
  86. package/dist/services/ConfigService.d.ts +17 -0
  87. package/dist/services/ConfigService.js +14 -0
  88. package/dist/services/PermissionService.d.ts +3 -0
  89. package/dist/services/PermissionService.js +25 -0
  90. package/dist/services/SettingsService.d.ts +8 -0
  91. package/dist/services/SettingsService.js +9 -0
  92. package/dist/styles/config.d.ts +3 -0
  93. package/dist/styles/config.js +184 -0
  94. package/dist/styles/postcss.d.ts +6 -0
  95. package/dist/styles/postcss.js +4 -0
  96. package/dist/styles/tailwind.d.ts +10 -0
  97. package/dist/styles/tailwind.js +76 -0
  98. package/package.json +18 -21
  99. package/dist/index.d.cts +0 -169
  100. /package/{postcss.js → postcss.cjs} +0 -0
  101. /package/{tailwind.js → tailwind.cjs} +0 -0
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { isValidElement } from 'react';
3
+ import { Link, tw } from '@sqrzro/components';
4
+ import { filterNull } from '@sqrzro/utility';
5
+ import ListActions from '../ListActions';
6
+ function getKey(item) {
7
+ if (isValidElement(item)) {
8
+ return item.key;
9
+ }
10
+ return String(item);
11
+ }
12
+ export function renderMeta(id, meta) {
13
+ if (!meta) {
14
+ return null;
15
+ }
16
+ if (Array.isArray(meta)) {
17
+ return (_jsx("ul", { className: "flex items-center gap-4 text-xs text-slate-500", "data-testid": `list-item-meta--${id}`, children: filterNull(meta).map((item) => (_jsx("li", { children: item }, getKey(item)))) }));
18
+ }
19
+ return (_jsx("table", { className: "w-full text-xs", children: _jsx("tbody", { children: Object.entries(meta).map(([key, value]) => (_jsxs("tr", { className: "odd:bg-slate-100", children: [_jsx("th", { className: "p-2 font-semibold", children: key }), _jsx("td", { className: "p-2 text-right", children: value || '-' })] }, key))) }) }));
20
+ }
21
+ function ListItem({ actions, description, href, id, isMinimal, meta, secondary, tertiary, title, }) {
22
+ return (_jsx("li", { children: _jsx("article", { className: tw('@container', isMinimal
23
+ ? 'border-b border-slate-200 pb-4'
24
+ : 'bg-panel rounded p-4 shadow-[0px_0px_0px_1px_rgba(9,9,11,0.07),0px_2px_2px_0px_rgba(9,9,11,0.05)]'), "data-testid": `list-item-root--${id}`, children: _jsxs("div", { className: "grid grid-cols-[3fr_2fr_2fr_auto]", children: [_jsxs("div", { children: [title ? (_jsx("h2", { className: "text-base font-semibold", "data-testid": `list-item-title--${id}`, children: href ? _jsx(Link, { href: href, children: title }) : title })) : null, description, meta ? (_jsx("div", { className: tw(isMinimal ? 'mt-1' : 'mt-2 flex items-center justify-between'), children: meta ? renderMeta(id, meta) : null })) : null] }), tertiary ? (_jsx("div", { className: "flex h-full flex-col justify-center", children: tertiary })) : null, secondary ? (_jsxs("div", { className: "col-start-3 text-right", children: [secondary.title ? (_jsx("p", { className: "text-base font-semibold", children: secondary.title })) : null, secondary.description ? (_jsx("div", { className: "text-xs text-slate-500", children: secondary.description })) : null, secondary.meta ? (_jsx("ul", { className: "flex items-center justify-end gap-4 text-xs text-slate-500", children: filterNull(secondary.meta).map((item) => (_jsx("li", { children: item }, getKey(item)))) })) : null] })) : null, actions ? (_jsx("div", { className: "h-5 self-center pl-6", children: _jsx(ListActions, { actions: actions, id: id }) })) : null] }) }) }));
25
+ }
26
+ export default ListItem;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ interface ListSkeletonProps {
3
+ }
4
+ declare function ListSkeleton({}: Readonly<ListSkeletonProps>): React.ReactElement;
5
+ export default ListSkeleton;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ function ListSkeleton({}) {
3
+ return (_jsx("div", { className: "relative flex flex-col gap-4", children: Array.from({ length: 4 }).map((item, index) => (_jsxs("div", { className: "grid grid-cols-[auto_auto] grid-rows-[auto_auto] gap-2 rounded bg-white p-4 shadow-[0px_0px_0px_1px_rgba(9,9,11,0.07),0px_2px_2px_0px_rgba(9,9,11,0.05)]", children: [_jsx("div", { className: "h-7 w-64 bg-slate-200" }), _jsx("div", { className: "row-start-2 h-4 w-24 bg-slate-200" }), _jsx("div", { className: "col-start-2 flex justify-end", children: _jsx("div", { className: "col-start-2 h-7 w-24 bg-slate-200" }) }), _jsx("div", { className: "col-start-2 row-start-2 flex justify-end", children: _jsx("div", { className: "h-4 w-36 bg-slate-200" }) })] }, index))) }));
4
+ }
5
+ export default ListSkeleton;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare function MeActions(): React.ReactElement;
3
+ export default MeActions;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Link } from '@sqrzro/components';
3
+ function MeActions() {
4
+ return (_jsxs("ul", { className: "flex gap-2 text-xs text-slate-300", children: [_jsx("li", { children: _jsx(Link, { href: "/settings", children: "Settings" }) }), _jsx("li", {})] }));
5
+ }
6
+ export default MeActions;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ interface MePanelProps {
3
+ layout?: string;
4
+ user?: {
5
+ name: string;
6
+ } | null;
7
+ }
8
+ declare function MePanel({ layout, user }: Readonly<MePanelProps>): React.ReactElement;
9
+ export default MePanel;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { tw } from '@sqrzro/components';
3
+ import MeActions from '../MeActions';
4
+ function MePanel({ layout, user }) {
5
+ return (_jsxs("div", { className: tw('flex gap-3', layout === 'sidebar' ? 'w-full p-4' : 'ml-auto items-center'), children: [_jsxs("div", { className: tw('flex flex-col gap-0.5 text-white', layout === 'sidebar' ? '' : 'items-end'), children: [_jsx("strong", { children: user?.name }), _jsx(MeActions, {})] }), layout === 'sidebar' ? null : (_jsx("div", { className: "h-9 w-9 flex-none rounded-full border-4 border-slate-500" }))] }));
6
+ }
7
+ export default MePanel;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import type { ConfirmableAction, LinkableAction } from '@sqrzro/interfaces';
3
+ interface MenuProps {
4
+ actions: (ConfirmableAction & LinkableAction)[];
5
+ align: 'left' | 'right';
6
+ }
7
+ declare function Menu({ actions, align }: Readonly<MenuProps>): React.ReactElement;
8
+ export default Menu;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { InputPanel } from '@sqrzro/components';
3
+ import MenuItem from '../MenuItem';
4
+ function Menu({ actions, align }) {
5
+ return (_jsx(InputPanel, { align: align, children: _jsx("ul", { children: actions.map((item) => (_jsx("li", { children: _jsx(MenuItem, { ...item }) }, item.label))) }) }));
6
+ }
7
+ export default Menu;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import type { ConfirmableAction, LinkableAction } from '@sqrzro/interfaces';
3
+ type MenuItemProps = ConfirmableAction & LinkableAction;
4
+ declare function MenuItem({ href, isConfirmable, label, onClick, variant, }: Readonly<MenuItemProps>): React.ReactElement;
5
+ export default MenuItem;
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ConfirmableButton, Link, tw } from '@sqrzro/components';
3
+ const classMap = {
4
+ danger: 'text-red-700',
5
+ error: 'text-red-700',
6
+ info: 'text-sky-700',
7
+ warning: 'text-yellow-700',
8
+ success: 'text-green-700',
9
+ };
10
+ function MenuItem({ href, isConfirmable, label, onClick, variant, }) {
11
+ const classNames = tw('whitespace-nowrap p-2 px-3 text-sm text-slate-700', variant ? classMap[variant] : null);
12
+ if (!href) {
13
+ if (isConfirmable) {
14
+ return (_jsx(ConfirmableButton, { classNames: { root: { default: classNames } }, onClick: onClick, type: "button", children: label }));
15
+ }
16
+ return (_jsx("button", { className: classNames, onClick: onClick, type: "button", children: label }));
17
+ }
18
+ return (_jsx(Link, { className: classNames, href: href, onClick: onClick, children: label }));
19
+ }
20
+ export default MenuItem;
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import type { LinkableAction } from '@sqrzro/interfaces';
3
+ import type { NavigationAction } from '../../interfaces';
4
+ export interface PageProps {
5
+ actions?: LinkableAction[];
6
+ basePath?: string;
7
+ children: React.ReactNode;
8
+ icon?: string;
9
+ isFullWidth?: boolean;
10
+ tabs?: (NavigationAction | null)[];
11
+ title: string;
12
+ }
13
+ declare function Page({ basePath, children, icon, isFullWidth, tabs, title, }: Readonly<PageProps>): Promise<React.ReactElement>;
14
+ export default Page;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Fragment } from 'react';
3
+ import { Container, tw } from '@sqrzro/components';
4
+ import { filterNull } from '@sqrzro/utility';
5
+ import { getLayout } from '../../services/SettingsService';
6
+ import Tabs from '../Tabs';
7
+ async function Page({ basePath, children, icon, isFullWidth, tabs, title, }) {
8
+ const layout = await getLayout();
9
+ return (_jsxs(Fragment, { children: [_jsx("header", { className: tw(layout === 'sidebar' ? 'bg-slate-200' : 'bg-slate-800 pb-16 text-white'), children: _jsxs(Container, { isFullWidth: layout === 'sidebar' || isFullWidth, children: [_jsxs("div", { className: tw('flex items-center justify-between', layout === 'sidebar' ? 'py-8' : 'py-10'), children: [_jsxs("h1", { className: "flex min-h-10 items-center text-3xl font-semibold", children: [icon ? (_jsx("i", { className: tw('mr-3 h-10 w-10 rounded-full border-4 border-blue-300/50 bg-blue-300 bg-clip-padding', icon) })) : null, title] }), _jsx("div", { className: "flex gap-2", id: "page-actions" })] }), tabs ? (_jsx("div", { className: tw('', layout === 'sidebar' ? '' : '-mt-4 mb-8 border-b border-slate-700'), children: _jsx(Tabs, { basePath: basePath, data: filterNull(tabs) }) })) : null] }) }), _jsx(Container, { isFullWidth: layout === 'sidebar' || isFullWidth, children: _jsx("div", { className: tw('@container flex flex-col gap-8', layout === 'sidebar' ? 'mt-8' : '-mt-16'), children: children }) })] }));
10
+ }
11
+ export default Page;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export interface PageActionsProps {
3
+ children: React.ReactNode;
4
+ }
5
+ declare function PageActions({ children }: Readonly<PageActionsProps>): React.ReactElement | null;
6
+ export default PageActions;
@@ -0,0 +1,13 @@
1
+ 'use client';
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { createPortal } from 'react-dom';
4
+ function PageActions({ children }) {
5
+ const ref = useRef(null);
6
+ const [mounted, setMounted] = useState(false);
7
+ useEffect(() => {
8
+ ref.current = document.getElementById('page-actions');
9
+ setMounted(true);
10
+ }, []);
11
+ return mounted && ref.current ? createPortal(children, ref.current) : null;
12
+ }
13
+ export default PageActions;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import type { LinkableAction } from '@sqrzro/interfaces';
3
+ export interface PanelProps {
4
+ action?: LinkableAction;
5
+ children: React.ReactNode;
6
+ title?: string;
7
+ }
8
+ declare function Panel({ action, children, title }: Readonly<PanelProps>): React.ReactElement;
9
+ export default Panel;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button } from '@sqrzro/components';
3
+ function Panel({ action, children, title }) {
4
+ return (_jsxs("article", { className: "@container bg-panel relative rounded p-6 shadow-[0px_0px_0px_1px_rgba(9,9,11,0.07),0px_2px_2px_0px_rgba(9,9,11,0.05)]", children: [title ? (_jsxs("header", { className: "mb-4 flex justify-between border-b border-slate-200", children: [_jsx("h3", { className: "pb-3 text-lg font-semibold leading-none", children: title }), action ? _jsx(Button, { href: action.href, children: action.label }) : null] })) : null, children] }));
5
+ }
6
+ export default Panel;
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import type { Config as ConfigObject } from '../../services/ConfigService';
3
+ export interface RootLayoutProps {
4
+ children: React.ReactNode;
5
+ config?: ConfigObject;
6
+ font?: string;
7
+ logo?: () => React.ReactElement;
8
+ }
9
+ declare function RootLayout({ children, config, font, logo, }: Readonly<RootLayoutProps>): React.ReactElement;
10
+ export default RootLayout;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /* eslint-disable react/no-danger */
3
+ import { ClassNames, Toaster, tw } from '@sqrzro/components';
4
+ import { setConfig } from '../../services/ConfigService';
5
+ import classNames from '../../styles/config';
6
+ import Config from '../Config';
7
+ function RootLayout({ children, config, font, logo, }) {
8
+ if (config) {
9
+ setConfig(config, logo);
10
+ }
11
+ return (_jsxs("html", { lang: "en", children: [_jsx("head", {}), _jsxs("body", { className: tw(font, 'overflow-x-hidden overflow-y-scroll bg-slate-50 font-sans text-sm text-slate-800 has-[[data-modal][open]]:overflow-hidden'), children: [_jsx("script", { dangerouslySetInnerHTML: {
12
+ __html: "(function(d){var v=d.createElement('div'),t=d.createElement('style'),s=v.style;s.overflowY='scroll';s.width='50';s.height='50';d.body.append(v);t.innerHTML='body:has([data-modal][open]){padding-right:'+(v.offsetWidth-v.clientWidth)+'px}';d.body.append(t);v.remove()}(document))",
13
+ } }), _jsx(Config, { data: config }), _jsx(ClassNames, { data: classNames }), children, _jsx(Toaster, {})] })] }));
14
+ }
15
+ export default RootLayout;
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import type { SettingsFormFields } from '../../services/SettingsService';
3
+ interface SettingsFormProps {
4
+ defaults: Partial<SettingsFormFields>;
5
+ }
6
+ declare function SettingsForm({ defaults }: Readonly<SettingsFormProps>): JSX.Element;
7
+ export default SettingsForm;
@@ -0,0 +1,14 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { EditableForm, EditableRadioFormField, EditableSwitchFormField } from '@sqrzro/components';
4
+ import { useEditableForm } from '@sqrzro/hooks';
5
+ import { submitSettingsForm } from '../../services/SettingsService';
6
+ const options = { sidebar: 'Side bar', topbar: 'Top bar' };
7
+ function SettingsForm({ defaults }) {
8
+ const { fieldProps, formProps } = useEditableForm({
9
+ defaults,
10
+ onSubmit: submitSettingsForm,
11
+ });
12
+ return (_jsxs(EditableForm, { title: "Appearance", ...formProps, children: [_jsx(EditableRadioFormField, { ...fieldProps('layout'), options: options, renderValue: (value) => (value ? options[value] || '-' : '-') }), _jsx(EditableSwitchFormField, { ...fieldProps('isDark'), label: "Dark mode" })] }));
13
+ }
14
+ export default SettingsForm;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare function SettingsPage(): Promise<React.ReactElement>;
3
+ export default SettingsPage;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { getLayout } from '../../services/SettingsService';
3
+ import Page from '../Page';
4
+ import SettingsForm from '../SettingsForm';
5
+ async function SettingsPage() {
6
+ const layout = await getLayout();
7
+ return (_jsx(Page, { title: "Settings", children: _jsx("div", { className: "flex flex-col gap-6", children: _jsx(SettingsForm, { defaults: { layout } }) }) }));
8
+ }
9
+ export default SettingsPage;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import type { Errorable } from '@sqrzro/interfaces';
3
+ import type { TableClientComponentProps } from '../TableClientComponent';
4
+ export interface TableProps<T> extends Omit<TableClientComponentProps, 'data'> {
5
+ fn: (filters?: Record<string, string>) => Promise<Errorable<T[]>>;
6
+ searchParams?: Record<string, string>;
7
+ }
8
+ declare function Table<T>({ columns, fn, searchParams, }: Readonly<TableProps<T>>): Promise<React.ReactElement>;
9
+ export default Table;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import TableClientComponent from '../TableClientComponent';
3
+ function defaultTransformer(item) {
4
+ return {
5
+ id: item.id,
6
+ ...item,
7
+ };
8
+ }
9
+ async function Table({ columns, fn, searchParams, }) {
10
+ const [response, error] = await fn(searchParams);
11
+ if (error) {
12
+ return _jsx("div", { children: "Error" });
13
+ }
14
+ const data = response.map(defaultTransformer);
15
+ return _jsx(TableClientComponent, { columns: columns, data: data });
16
+ }
17
+ export default Table;
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ export interface TableItemObject {
3
+ [key: string]: string;
4
+ id: string;
5
+ }
6
+ export interface TableColumnObject {
7
+ key: string;
8
+ title?: string;
9
+ type?: 'number' | 'string';
10
+ }
11
+ export interface TableClientComponentProps {
12
+ columns: string[] | TableColumnObject[];
13
+ data: TableItemObject[];
14
+ }
15
+ declare function TableClientComponent({ columns, data, }: Readonly<TableClientComponentProps>): React.ReactElement;
16
+ export default TableClientComponent;
@@ -0,0 +1,49 @@
1
+ 'use client';
2
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
3
+ import { Link, tw } from '@sqrzro/components';
4
+ import { usePathname, useSearchParams } from 'next/navigation';
5
+ function createFilterLink(pathname, searchParams, filters) {
6
+ const updatedSearchParams = new URLSearchParams({
7
+ ...Object.fromEntries(searchParams),
8
+ ...filters,
9
+ });
10
+ return `${pathname}?${updatedSearchParams.toString()}`;
11
+ }
12
+ function getDir(currentDir, isSortActive) {
13
+ if (isSortActive) {
14
+ return currentDir === 'asc' ? 'desc' : 'asc';
15
+ }
16
+ return 'asc';
17
+ }
18
+ function createSortLink(pathname, searchParams, sort) {
19
+ const dir = getDir(searchParams.get('dir'), searchParams.get('sort') === sort);
20
+ return createFilterLink(pathname, searchParams, { sort, dir });
21
+ }
22
+ function getSortIconProps(searchParams, sort) {
23
+ if (searchParams.get('sort') === sort) {
24
+ return { dir: searchParams.get('dir') };
25
+ }
26
+ return { dir: null };
27
+ }
28
+ function isStringArray(array) {
29
+ return array.every((item) => typeof item === 'string');
30
+ }
31
+ function parseColumns(columns) {
32
+ if (columns.length === 0) {
33
+ return [];
34
+ }
35
+ if (isStringArray(columns)) {
36
+ return columns.map((key) => ({ key }));
37
+ }
38
+ return columns;
39
+ }
40
+ function TableClientComponent({ columns, data, }) {
41
+ const pathname = usePathname();
42
+ const searchParams = useSearchParams();
43
+ const parsedColumns = parseColumns(columns);
44
+ const hasTitles = parsedColumns.some((column) => column.title);
45
+ return (_jsx("div", { className: "bg-white shadow-sm", children: _jsxs("table", { className: "w-full", children: [hasTitles ? (_jsx("thead", { children: _jsx("tr", { children: parsedColumns.map((column) => (_jsx("th", { className: tw('p-4', column.type === 'number' ? 'text-right' : 'text-left'), children: column.title ? (_jsxs(Link, { href: createSortLink(pathname, searchParams, column.key), children: [column.title, ' '] })) : null }, column.key))) }) })) : null, _jsx("tbody", { children: data.map((item) => (_jsx("tr", { className: "odd:bg-slate-100", children: parsedColumns.map((column) => (_jsx("td", { className: tw('border-x border-transparent p-4', getSortIconProps(searchParams, column.key).dir
46
+ ? 'border-sky-300 bg-sky-300/10'
47
+ : '', column.type === 'number' ? 'text-right' : 'text-left'), children: item[column.key] }, column.key))) }, item.id))) })] }) }));
48
+ }
49
+ export default TableClientComponent;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { TabsComponentProps } from '../TabsComponent';
3
+ declare function Tabs({ basePath, data }: Readonly<TabsComponentProps>): Promise<React.ReactElement>;
4
+ export default Tabs;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { filterNull } from '@sqrzro/utility';
3
+ import { filterList } from '../../services/PermissionService';
4
+ import TabsComponent from '../TabsComponent';
5
+ async function Tabs({ basePath, data }) {
6
+ return _jsx(TabsComponent, { basePath: basePath, data: await filterList(filterNull(data)) });
7
+ }
8
+ export default Tabs;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import type { NavigationAction } from '../../interfaces';
3
+ export interface TabsComponentProps {
4
+ basePath?: string;
5
+ data: NavigationAction[];
6
+ }
7
+ declare function TabsComponent({ basePath, data }: Readonly<TabsComponentProps>): React.ReactElement;
8
+ export default TabsComponent;
@@ -0,0 +1,9 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Link, tw } from '@sqrzro/components';
4
+ import useNavigation from '../../hooks/useNavigation';
5
+ function TabsComponent({ basePath = '', data }) {
6
+ const navigation = useNavigation(data, { basePath });
7
+ return (_jsx("nav", { children: _jsx("ul", { className: "flex gap-4", children: navigation.map(({ href, isActive, label }) => (_jsx("li", { children: _jsx(Link, { className: tw('block border-b-4 border-transparent px-1 pb-2 font-semibold', isActive ? 'border-primary' : 'opacity-80 hover:opacity-100'), href: href, children: label }) }, href))) }) }));
8
+ }
9
+ export default TabsComponent;
@@ -0,0 +1,33 @@
1
+ export { Autocomplete, AutocompleteFormField, Button, CalendarInput, CheckboxInput, ConfirmableButton, ConfirmableForm, ContentFormField, DateFormField, DateInput, DefinitionList, Dropdown, DropdownFormField, EditableAutocompleteFormField, EditableDateFormField, EditableDropdownFormField, EditableForm, EditableFormField, EditableMultiFormField, EditableNumberFormField, EditableSwitchFormField, EditableTextAreaFormField, EditableTextFormField, EmptyMessage, Fieldset, Form, FormField, FormSubmit, ImageInput, ImageFormField, Link, LoadingModal, Modal, ModalActions, ModalForm, MoneyFormField, MoneyInput, MultiFormField, NumberFormField, NumberInput, ObjectFormField, RadioInput, Switch, SwitchFormField, TextArea, TextAreaFormField, TextFormField, TextInput, Toaster, } from '@sqrzro/components';
2
+ export type { DropdownItem, EditableFormFieldProps, FormFieldProps, LinkProps, NumberInputProps, } from '@sqrzro/components';
3
+ export type { AppLayoutProps } from './AppLayout';
4
+ export { default as AppLayout } from './AppLayout';
5
+ export type { BadgeProps } from './Badge';
6
+ export { default as Badge } from './Badge';
7
+ export type { DashboardProps } from './Dashboard';
8
+ export { default as Dashboard } from './Dashboard';
9
+ export type { FilterBarProps, FilterObject } from './FilterBar';
10
+ export { default as FilterBar } from './FilterBar';
11
+ export type { GridListProps } from './GridList';
12
+ export { default as GridList } from './GridList';
13
+ export type { InfoPanelProps } from './InfoPanel';
14
+ export { default as InfoPanel } from './InfoPanel';
15
+ export type { ListProps } from './List';
16
+ export { default as List } from './List';
17
+ export type { ListClientComponentProps } from './ListClientComponent';
18
+ export { default as ListClientComponent } from './ListClientComponent';
19
+ export type { ListObject } from './ListItem';
20
+ export type { ListActionsProps } from './ListActions';
21
+ export { default as ListActions } from './ListActions';
22
+ export type { PageProps } from './Page';
23
+ export { default as Page } from './Page';
24
+ export type { PanelProps } from './Panel';
25
+ export { default as Panel } from './Panel';
26
+ export type { PageActionsProps } from './PageActions';
27
+ export { default as PageActions } from './PageActions';
28
+ export type { RootLayoutProps } from './RootLayout';
29
+ export { default as RootLayout } from './RootLayout';
30
+ export { default as SettingsPage } from './SettingsPage';
31
+ export type { TableColumnObject } from './TableClientComponent';
32
+ export type { TableProps } from './Table';
33
+ export { default as Table } from './Table';
@@ -0,0 +1,17 @@
1
+ // Exported from @sqrzro/components
2
+ export { Autocomplete, AutocompleteFormField, Button, CalendarInput, CheckboxInput, ConfirmableButton, ConfirmableForm, ContentFormField, DateFormField, DateInput, DefinitionList, Dropdown, DropdownFormField, EditableAutocompleteFormField, EditableDateFormField, EditableDropdownFormField, EditableForm, EditableFormField, EditableMultiFormField, EditableNumberFormField, EditableSwitchFormField, EditableTextAreaFormField, EditableTextFormField, EmptyMessage, Fieldset, Form, FormField, FormSubmit, ImageInput, ImageFormField, Link, LoadingModal, Modal, ModalActions, ModalForm, MoneyFormField, MoneyInput, MultiFormField, NumberFormField, NumberInput, ObjectFormField, RadioInput, Switch, SwitchFormField, TextArea, TextAreaFormField, TextFormField, TextInput, Toaster, } from '@sqrzro/components';
3
+ export { default as AppLayout } from './AppLayout';
4
+ export { default as Badge } from './Badge';
5
+ export { default as Dashboard } from './Dashboard';
6
+ export { default as FilterBar } from './FilterBar';
7
+ export { default as GridList } from './GridList';
8
+ export { default as InfoPanel } from './InfoPanel';
9
+ export { default as List } from './List';
10
+ export { default as ListClientComponent } from './ListClientComponent';
11
+ export { default as ListActions } from './ListActions';
12
+ export { default as Page } from './Page';
13
+ export { default as Panel } from './Panel';
14
+ export { default as PageActions } from './PageActions';
15
+ export { default as RootLayout } from './RootLayout';
16
+ export { default as SettingsPage } from './SettingsPage';
17
+ export { default as Table } from './Table';
@@ -0,0 +1,11 @@
1
+ import type { NavigationAction } from '../interfaces';
2
+ interface NavigationObject {
3
+ href: string;
4
+ isActive: boolean;
5
+ label: string;
6
+ }
7
+ interface UseNavigationOptions {
8
+ basePath?: string;
9
+ }
10
+ declare function useNavigation(data: NavigationAction[], options?: UseNavigationOptions): NavigationObject[];
11
+ export default useNavigation;
@@ -0,0 +1,27 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { joinUrl } from '@sqrzro/utility';
3
+ import { usePathname } from 'next/navigation';
4
+ function getActiveHref(pathname, hrefs) {
5
+ return (hrefs
6
+ .filter((href) => href && pathname.startsWith(`/${href.replace(/^\//u, '')}`))
7
+ .sort((first, second) => {
8
+ if (!first || !second) {
9
+ return 0;
10
+ }
11
+ return second.length - first.length;
12
+ })[0] || '');
13
+ }
14
+ function useNavigation(data, options) {
15
+ const [activeHref, setActiveHref] = useState('');
16
+ const pathname = usePathname();
17
+ const hrefs = data.map(({ href }) => joinUrl(options?.basePath, href));
18
+ useEffect(() => {
19
+ setActiveHref(getActiveHref(pathname, hrefs));
20
+ }, [pathname]);
21
+ return data.map(({ href, label }) => ({
22
+ href: joinUrl(options?.basePath, href),
23
+ isActive: joinUrl(options?.basePath, href) === activeHref,
24
+ label,
25
+ }));
26
+ }
27
+ export default useNavigation;