@sqrzro/admin 2.1.0-bz.27 → 2.1.0-bz.29
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/components/DataTable/index.d.ts +6 -0
- package/dist/components/DataTable/index.js +5 -0
- package/dist/components/ListItem/index.d.ts +3 -1
- package/dist/components/ListItem/index.js +5 -2
- package/dist/components/Table/index.d.ts +7 -5
- package/dist/components/Table/index.js +5 -5
- package/dist/components/index.d.ts +4 -1
- package/dist/components/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
function DataTable({ data }) {
|
|
3
|
+
return (_jsx("table", { children: _jsx("tbody", { children: Object.entries(data).map(([key, value]) => (_jsxs("tr", { className: "odd:bg-slate-100", children: [_jsx("th", { className: "p-2 font-normal", children: key }), _jsx("td", { className: "p-2 text-right", children: value })] }, key))) }) }));
|
|
4
|
+
}
|
|
5
|
+
export default DataTable;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import type { StyleVariant } from '@sqrzro/interfaces';
|
|
2
3
|
export interface ListObject<Data = Record<string, unknown>> {
|
|
3
4
|
$data?: Data;
|
|
4
5
|
actions?: (data: Data) => React.ReactNode;
|
|
@@ -17,7 +18,8 @@ export interface ListObject<Data = Record<string, unknown>> {
|
|
|
17
18
|
};
|
|
18
19
|
tertiary?: React.ReactNode;
|
|
19
20
|
title?: React.ReactNode;
|
|
21
|
+
variant?: StyleVariant;
|
|
20
22
|
}
|
|
21
23
|
export declare function renderMeta(id: string, meta: ListObject['meta']): React.ReactElement | null;
|
|
22
|
-
declare function ListItem<Data = Record<string, unknown>>({ $data, actions, description, href, id, isMinimal, meta, secondary, tertiary, title, }: Readonly<ListObject<Data>>): React.ReactElement;
|
|
24
|
+
declare function ListItem<Data = Record<string, unknown>>({ $data, actions, description, href, id, isMinimal, meta, secondary, tertiary, title, variant, }: Readonly<ListObject<Data>>): React.ReactElement;
|
|
23
25
|
export default ListItem;
|
|
@@ -2,6 +2,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { isValidElement } from 'react';
|
|
3
3
|
import { Link, tw } from '@sqrzro/components';
|
|
4
4
|
import { filterNull } from '@sqrzro/utility';
|
|
5
|
+
const variantMap = {
|
|
6
|
+
danger: 'text-red-700',
|
|
7
|
+
};
|
|
5
8
|
function getKey(item) {
|
|
6
9
|
if (isValidElement(item)) {
|
|
7
10
|
return item.key;
|
|
@@ -17,9 +20,9 @@ export function renderMeta(id, meta) {
|
|
|
17
20
|
}
|
|
18
21
|
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))) }) }));
|
|
19
22
|
}
|
|
20
|
-
function ListItem({ $data, actions, description, href, id, isMinimal, meta, secondary, tertiary, title, }) {
|
|
23
|
+
function ListItem({ $data, actions, description, href, id, isMinimal, meta, secondary, tertiary, title, variant, }) {
|
|
21
24
|
return (_jsx("li", { children: _jsx("article", { className: tw('', isMinimal
|
|
22
25
|
? 'border-b border-slate-200 pb-4'
|
|
23
|
-
: '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:
|
|
26
|
+
: '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)]', variant ? variantMap[variant] : ''), "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: tw('text-base font-semibold', variant === 'danger' ? 'line-through' : ''), "data-testid": `list-item-title--${id}`, children: href ? _jsx(Link, { href: href, children: title }) : title })) : null, description, meta ? (_jsx("div", { className: tw('mt-1', isMinimal ? '' : '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: tw('text-base font-semibold', variant === 'danger' ? 'line-through' : ''), children: secondary.title })) : null, secondary.description ? (_jsx("div", { className: "mt-1 text-xs text-slate-500", children: secondary.description })) : null, secondary.meta ? (_jsx("ul", { className: "mt-1 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, typeof actions === 'function' ? actions($data) : null] }) }) }));
|
|
24
27
|
}
|
|
25
28
|
export default ListItem;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { Errorable } from '@sqrzro/interfaces';
|
|
3
|
-
import type { TableClientComponentProps } from '../TableClientComponent';
|
|
4
|
-
export interface TableProps<
|
|
5
|
-
fn: (
|
|
6
|
-
|
|
3
|
+
import type { TableClientComponentProps, TableItemObject } from '../TableClientComponent';
|
|
4
|
+
export interface TableProps<Item, Params> extends Omit<TableClientComponentProps, 'data'> {
|
|
5
|
+
fn: (params?: Params, searchParams?: URLSearchParams) => Promise<Errorable<Item[]>>;
|
|
6
|
+
params?: Params;
|
|
7
|
+
searchParams?: URLSearchParams;
|
|
8
|
+
transformer?: (item: Item) => TableItemObject;
|
|
7
9
|
}
|
|
8
|
-
declare function Table<
|
|
10
|
+
declare function Table<Item extends object, Params>({ columns, fn, params, searchParams, transformer, }: Readonly<TableProps<Item, Params>>): Promise<React.ReactElement>;
|
|
9
11
|
export default Table;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import TableClientComponent from '../TableClientComponent';
|
|
3
3
|
function defaultTransformer(item) {
|
|
4
4
|
return {
|
|
@@ -6,12 +6,12 @@ function defaultTransformer(item) {
|
|
|
6
6
|
...item,
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
async function Table({ columns, fn, searchParams, }) {
|
|
10
|
-
const [response, error] = await fn(searchParams);
|
|
9
|
+
async function Table({ columns, fn, params, searchParams, transformer, }) {
|
|
10
|
+
const [response, error] = await fn(params, searchParams);
|
|
11
11
|
if (error) {
|
|
12
|
-
return
|
|
12
|
+
return _jsxs("div", { children: ["Error - ", error.message] });
|
|
13
13
|
}
|
|
14
|
-
const data = response.map(defaultTransformer);
|
|
14
|
+
const data = response.map(transformer || defaultTransformer);
|
|
15
15
|
return _jsx(TableClientComponent, { columns: columns, data: data });
|
|
16
16
|
}
|
|
17
17
|
export default Table;
|
|
@@ -6,6 +6,8 @@ export type { BadgeProps } from './Badge';
|
|
|
6
6
|
export { default as Badge } from './Badge';
|
|
7
7
|
export type { DashboardProps } from './Dashboard';
|
|
8
8
|
export { default as Dashboard } from './Dashboard';
|
|
9
|
+
export type { DataTableProps } from './DataTable';
|
|
10
|
+
export { default as DataTable } from './DataTable';
|
|
9
11
|
export type { FilterBarProps, FilterObject } from './FilterBar';
|
|
10
12
|
export { default as FilterBar } from './FilterBar';
|
|
11
13
|
export type { GridListProps } from './GridList';
|
|
@@ -17,7 +19,7 @@ export { default as List } from './List';
|
|
|
17
19
|
export type { ListClientComponentProps } from './ListClientComponent';
|
|
18
20
|
export { default as ListClientComponent } from './ListClientComponent';
|
|
19
21
|
export type { ListObject } from './ListItem';
|
|
20
|
-
export type { ListActionsProps } from './ListActions';
|
|
22
|
+
export type { ListAction, ListActionsProps } from './ListActions';
|
|
21
23
|
export { default as ListActions } from './ListActions';
|
|
22
24
|
export type { PageProps } from './Page';
|
|
23
25
|
export { default as Page } from './Page';
|
|
@@ -33,3 +35,4 @@ export { default as SettingsPage } from './SettingsPage';
|
|
|
33
35
|
export type { TableColumnObject } from './TableClientComponent';
|
|
34
36
|
export type { TableProps } from './Table';
|
|
35
37
|
export { default as Table } from './Table';
|
|
38
|
+
export type { TableItemObject } from './TableClientComponent';
|
package/dist/components/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { Autocomplete, AutocompleteFormField, Button, CalendarInput, CheckboxInp
|
|
|
3
3
|
export { default as AppLayout } from './AppLayout';
|
|
4
4
|
export { default as Badge } from './Badge';
|
|
5
5
|
export { default as Dashboard } from './Dashboard';
|
|
6
|
+
export { default as DataTable } from './DataTable';
|
|
6
7
|
export { default as FilterBar } from './FilterBar';
|
|
7
8
|
export { default as GridList } from './GridList';
|
|
8
9
|
export { default as InfoPanel } from './InfoPanel';
|