@sqrzro/ui 4.0.0-alpha.4 → 4.0.0-alpha.41
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/addon/config.d.ts +5 -0
- package/dist/addon/config.js +12 -0
- package/dist/addon/defaults.d.ts +3 -0
- package/dist/addon/defaults.js +6 -0
- package/dist/addon/index.d.ts +5 -0
- package/dist/addon/index.js +8 -0
- package/dist/addon/interfaces.d.ts +8 -0
- package/dist/components/buttons/ActionButton/index.d.ts +8 -6
- package/dist/components/buttons/ActionButton/index.js +3 -27
- package/dist/components/buttons/Button/index.d.ts +5 -5
- package/dist/components/buttons/Button/index.js +7 -17
- package/dist/components/collections/Collection/index.d.ts +9 -3
- package/dist/components/collections/Collection/index.js +8 -7
- package/dist/components/collections/DataTable/index.d.ts +14 -0
- package/dist/components/collections/DataTable/index.js +14 -0
- package/dist/components/collections/EmptyMessage/index.d.ts +1 -1
- package/dist/components/collections/EmptyMessage/index.js +6 -4
- package/dist/components/collections/EmptyMessageAction/index.d.ts +2 -2
- package/dist/components/collections/EmptyMessageAction/index.js +1 -1
- package/dist/components/collections/List/index.d.ts +6 -4
- package/dist/components/collections/List/index.js +2 -2
- package/dist/components/collections/ListClientComponent/index.d.ts +7 -4
- package/dist/components/collections/ListClientComponent/index.js +8 -5
- package/dist/components/collections/ListItem/index.d.ts +10 -3
- package/dist/components/collections/ListItem/index.js +15 -23
- package/dist/components/collections/ListItemMenu/index.d.ts +8 -0
- package/dist/components/collections/ListItemMenu/index.js +7 -0
- package/dist/components/collections/ListItemMeta/index.d.ts +6 -4
- package/dist/components/collections/ListItemMeta/index.js +13 -7
- package/dist/components/collections/ListItemSecondary/index.d.ts +5 -3
- package/dist/components/collections/ListItemSecondary/index.js +5 -5
- package/dist/components/collections/Pagination/index.d.ts +1 -1
- package/dist/components/collections/Pagination/index.js +6 -7
- package/dist/components/collections/PaginationLink/index.d.ts +9 -0
- package/dist/components/collections/PaginationLink/index.js +9 -0
- package/dist/components/collections/Table/index.d.ts +4 -5
- package/dist/components/collections/Table/index.js +2 -8
- package/dist/components/collections/TableClientComponent/index.d.ts +7 -6
- package/dist/components/collections/TableClientComponent/index.js +11 -26
- package/dist/components/collections/TableRow/index.d.ts +13 -0
- package/dist/components/collections/TableRow/index.js +15 -0
- package/dist/components/collections/interfaces.d.ts +41 -34
- package/dist/components/collections/utility/is-right-aligned.d.ts +3 -0
- package/dist/components/collections/utility/is-right-aligned.js +11 -0
- package/dist/components/collections/utility/normalize-href.d.ts +2 -0
- package/dist/components/collections/utility/normalize-href.js +8 -0
- package/dist/components/collections/utility/render-cell.d.ts +5 -0
- package/dist/components/collections/utility/render-cell.js +33 -0
- package/dist/components/elements/Badge/index.d.ts +12 -0
- package/dist/components/elements/Badge/index.js +9 -0
- package/dist/components/elements/InfoPanel/index.d.ts +11 -0
- package/dist/components/elements/InfoPanel/index.js +9 -0
- package/dist/components/{utility → elements}/Link/index.d.ts +1 -1
- package/dist/components/{utility → elements}/Link/index.js +6 -7
- package/dist/components/elements/Menu/index.d.ts +19 -0
- package/dist/components/elements/Menu/index.js +17 -0
- package/dist/components/elements/MenuItem/index.d.ts +7 -0
- package/dist/components/elements/MenuItem/index.js +12 -0
- package/dist/components/elements/Page/index.d.ts +19 -0
- package/dist/components/elements/Page/index.js +18 -0
- package/dist/components/elements/Reference/index.d.ts +9 -0
- package/dist/components/elements/Reference/index.js +16 -0
- package/dist/components/elements/Summary/index.d.ts +13 -0
- package/dist/components/elements/Summary/index.js +22 -0
- package/dist/components/errors/AppError/index.d.ts +19 -0
- package/dist/components/errors/AppError/index.js +9 -0
- package/dist/components/errors/AppForbiddenError/index.d.ts +7 -0
- package/dist/components/errors/AppForbiddenError/index.js +6 -0
- package/dist/components/errors/AppNotFoundError/index.d.ts +7 -0
- package/dist/components/errors/AppNotFoundError/index.js +6 -0
- package/dist/components/errors/AppServerError/index.d.ts +8 -0
- package/dist/components/errors/AppServerError/index.js +17 -0
- package/dist/components/index.d.ts +37 -6
- package/dist/components/index.js +18 -3
- package/dist/components/mail/Mail/index.d.ts +7 -0
- package/dist/components/mail/Mail/index.js +113 -0
- package/dist/components/mail/MailBlock/index.d.ts +5 -0
- package/dist/components/mail/MailBlock/index.js +5 -0
- package/dist/components/mail/MailButton/index.d.ts +7 -0
- package/dist/components/mail/MailButton/index.js +38 -0
- package/dist/components/mail/MailTable/index.d.ts +9 -0
- package/dist/components/mail/MailTable/index.js +7 -0
- package/dist/components/modals/ConfirmModal/index.d.ts +5 -3
- package/dist/components/modals/ConfirmModal/index.js +3 -3
- package/dist/components/modals/Modal/index.d.ts +4 -4
- package/dist/components/modals/Modal/index.js +3 -3
- package/dist/components/modals/ModalActions/index.d.ts +3 -3
- package/dist/components/modals/ModalActions/index.js +4 -3
- package/dist/components/utility/Action/index.d.ts +11 -0
- package/dist/components/utility/Action/index.js +48 -0
- package/dist/components/utility/ActionList/index.d.ts +5 -5
- package/dist/components/utility/ActionList/index.js +5 -3
- package/dist/components/utility/AppBody/index.d.ts +5 -0
- package/dist/components/utility/AppBody/index.js +9 -0
- package/dist/components/utility/Calendar/index.d.ts +32 -0
- package/dist/components/utility/Calendar/index.js +67 -0
- package/dist/components/utility/CalendarDay/index.d.ts +11 -0
- package/dist/components/utility/CalendarDay/index.js +23 -0
- package/dist/components/utility/Confirmable/index.d.ts +9 -0
- package/dist/components/utility/Confirmable/index.js +14 -0
- package/dist/components/utility/Container/index.d.ts +1 -1
- package/dist/components/utility/Container/index.js +2 -2
- package/dist/components/utility/Loader/index.d.ts +1 -1
- package/dist/components/utility/Loader/index.js +5 -4
- package/dist/components/utility/Popover/index.d.ts +1 -1
- package/dist/components/utility/Popover/index.js +5 -5
- package/dist/components/utility/Toast/index.d.ts +2 -2
- package/dist/components/utility/Toast/index.js +6 -4
- package/dist/components/utility/Toaster/index.js +5 -5
- package/dist/filters/components/FilterBar/index.d.ts +5 -2
- package/dist/filters/components/FilterBarClientComponent/index.d.ts +2 -4
- package/dist/filters/components/FilterBarClientComponent/index.js +3 -43
- package/dist/filters/components/FilterClearButton/index.d.ts +7 -2
- package/dist/filters/components/FilterClearButton/index.js +8 -4
- package/dist/filters/components/FilterControl/index.d.ts +1 -1
- package/dist/filters/components/FilterControl/index.js +11 -4
- package/dist/filters/components/FilterItem/index.d.ts +2 -1
- package/dist/filters/components/FilterItem/index.js +3 -7
- package/dist/filters/components/FilterPanel/index.d.ts +1 -1
- package/dist/filters/{utility/filter.d.ts → filter.d.ts} +1 -1
- package/dist/filters/{utility/filter.js → filter.js} +8 -8
- package/dist/filters/filters/BooleanFilter/index.js +1 -1
- package/dist/filters/filters/CalendarFilter/index.js +3 -2
- package/dist/filters/filters/DateFilter/index.d.ts +1 -1
- package/dist/filters/filters/DateFilter/index.js +9 -4
- package/dist/filters/filters/DropdownFilter/index.js +1 -1
- package/dist/filters/filters/Filter/index.d.ts +5 -4
- package/dist/filters/filters/Filter/index.js +7 -7
- package/dist/filters/filters/SearchFilter/index.d.ts +7 -2
- package/dist/filters/filters/SearchFilter/index.js +8 -8
- package/dist/filters/filters/interfaces.d.ts +0 -2
- package/dist/filters/index.d.ts +2 -1
- package/dist/filters/index.js +2 -1
- package/dist/filters/interfaces.d.ts +4 -4
- package/dist/filters/utility/parse-filters.d.ts +1 -1
- package/dist/filters/utility/parse-filters.js +3 -2
- package/dist/filters/utility/render-value.js +4 -4
- package/dist/filters/utility/transform-boolean.d.ts +1 -1
- package/dist/filters/utility/transform-date.d.ts +1 -1
- package/dist/filters/utility/transform-multi.d.ts +1 -1
- package/dist/forms/components/Autocomplete/index.d.ts +11 -0
- package/dist/forms/components/Autocomplete/index.js +37 -0
- package/dist/forms/components/CSVInput/index.d.ts +11 -0
- package/dist/forms/components/CSVInput/index.js +32 -0
- package/dist/forms/components/Dropdown/index.d.ts +1 -1
- package/dist/forms/components/Dropdown/index.js +8 -7
- package/dist/forms/components/DropdownItem/index.d.ts +9 -0
- package/dist/forms/components/DropdownItem/index.js +9 -0
- package/dist/forms/components/DropdownList/index.d.ts +1 -1
- package/dist/forms/components/DropdownList/index.js +7 -9
- package/dist/forms/components/EditableForm/index.d.ts +3 -3
- package/dist/forms/components/EditableForm/index.js +9 -9
- package/dist/forms/components/EditableFormField/index.d.ts +1 -1
- package/dist/forms/components/EditableFormField/index.js +3 -3
- package/dist/forms/components/EditableFormFields/index.d.ts +3 -0
- package/dist/forms/components/EditableFormFields/index.js +6 -0
- package/dist/forms/components/Form/index.d.ts +3 -2
- package/dist/forms/components/Form/index.js +5 -5
- package/dist/forms/components/FormError/index.d.ts +2 -2
- package/dist/forms/components/FormError/index.js +4 -3
- package/dist/forms/components/FormField/index.d.ts +4 -4
- package/dist/forms/components/FormField/index.js +8 -6
- package/dist/forms/components/FormFields/index.d.ts +14 -0
- package/dist/forms/components/FormFields/index.js +30 -0
- package/dist/forms/components/FormLabel/index.d.ts +1 -1
- package/dist/forms/components/FormLabel/index.js +4 -3
- package/dist/forms/components/ModalForm/index.js +1 -1
- package/dist/forms/components/NumberInput/index.d.ts +7 -0
- package/dist/forms/components/NumberInput/index.js +27 -0
- package/dist/forms/components/PasswordComplexity/index.d.ts +16 -0
- package/dist/forms/components/PasswordComplexity/index.js +14 -0
- package/dist/forms/components/PasswordComplexityItem/index.d.ts +8 -0
- package/dist/forms/components/PasswordComplexityItem/index.js +10 -0
- package/dist/forms/components/PasswordInput/index.d.ts +1 -1
- package/dist/forms/components/PasswordInput/index.js +6 -6
- package/dist/forms/components/PointsInput/index.d.ts +5 -0
- package/dist/forms/components/PointsInput/index.js +22 -0
- package/dist/forms/components/RangeCalendarInput/index.d.ts +5 -0
- package/dist/forms/components/RangeCalendarInput/index.js +10 -0
- package/dist/forms/components/StaticTextInput/index.d.ts +2 -3
- package/dist/forms/components/StaticTextInput/index.js +8 -8
- package/dist/forms/components/Switch/index.d.ts +1 -1
- package/dist/forms/components/Switch/index.js +5 -4
- package/dist/forms/components/TextArea/index.d.ts +14 -0
- package/dist/forms/components/TextArea/index.js +15 -0
- package/dist/forms/components/TextInput/index.d.ts +2 -2
- package/dist/forms/components/TextInput/index.js +7 -6
- package/dist/forms/hooks/useAutocomplete.d.ts +9 -0
- package/dist/forms/hooks/useAutocomplete.js +31 -0
- package/dist/forms/hooks/useDropdown.d.ts +2 -2
- package/dist/forms/hooks/useForm.d.ts +3 -5
- package/dist/forms/hooks/useForm.js +14 -24
- package/dist/forms/hooks/useModalForm.d.ts +2 -2
- package/dist/forms/index.d.ts +26 -4
- package/dist/forms/index.js +11 -3
- package/dist/forms/interfaces.d.ts +1 -0
- package/dist/forms/utility/format-file-size.d.ts +2 -0
- package/dist/forms/utility/format-file-size.js +11 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.js +3 -0
- package/dist/hooks/useConfirmable.d.ts +21 -0
- package/dist/hooks/useConfirmable.js +58 -0
- package/dist/hooks/useDownload.d.ts +2 -0
- package/dist/hooks/useDownload.js +18 -0
- package/dist/hooks/usePopover.d.ts +12 -0
- package/dist/hooks/usePopover.js +24 -0
- package/dist/hooks/useSelected.d.ts +12 -0
- package/dist/hooks/useSelected.js +35 -0
- package/dist/hooks/useServerAction.d.ts +10 -0
- package/dist/hooks/useServerAction.js +17 -0
- package/dist/hooks/useSuccess.d.ts +10 -0
- package/dist/hooks/useSuccess.js +22 -0
- package/dist/navigation/components/AppNavigation/index.d.ts +3 -1
- package/dist/navigation/components/AppNavigation/index.js +4 -4
- package/dist/navigation/components/AppNavigationItem/index.d.ts +5 -3
- package/dist/navigation/components/AppNavigationItem/index.js +16 -7
- package/dist/navigation/components/Tabs/index.js +1 -4
- package/dist/navigation/hooks/useNavigation.d.ts +3 -3
- package/dist/navigation/hooks/useNavigation.js +5 -5
- package/dist/styles/classnames/config.d.ts +87 -0
- package/dist/styles/classnames/config.js +1 -0
- package/dist/styles/classnames/interfaces.d.ts +56 -0
- package/dist/styles/classnames/interfaces.js +1 -0
- package/dist/styles/classnames/utility/apply-sizes.d.ts +3 -0
- package/dist/styles/classnames/utility/apply-sizes.js +21 -0
- package/dist/styles/classnames/utility/apply-variants.d.ts +3 -0
- package/dist/styles/classnames/utility/apply-variants.js +26 -0
- package/dist/styles/classnames/utility/is-classname-object.d.ts +3 -0
- package/dist/styles/classnames/utility/is-classname-object.js +7 -0
- package/dist/styles/classnames/utility/parse-classnames.d.ts +6 -0
- package/dist/styles/classnames/utility/parse-classnames.js +33 -0
- package/dist/styles/context.d.ts +28 -0
- package/dist/styles/context.js +19 -0
- package/dist/styles/icons/config.d.ts +20 -0
- package/dist/styles/icons/config.js +1 -0
- package/dist/styles/icons/interfaces.d.ts +4 -0
- package/dist/styles/icons/interfaces.js +1 -0
- package/dist/styles/index.d.ts +6 -2
- package/dist/styles/index.js +2 -1
- package/dist/styles/styles.css +60 -0
- package/dist/utility/compare-dates.d.ts +2 -0
- package/dist/utility/compare-dates.js +13 -0
- package/dist/utility/convert-to-datauri.d.ts +2 -0
- package/dist/utility/convert-to-datauri.js +16 -0
- package/dist/utility/get-days.d.ts +2 -0
- package/dist/utility/get-days.js +5 -0
- package/dist/utility/get-weeks.d.ts +2 -0
- package/dist/utility/get-weeks.js +31 -0
- package/dist/utility/index.d.ts +1 -1
- package/dist/utility/interfaces.d.ts +33 -17
- package/dist/utility/is-data-object-array.d.ts +3 -0
- package/dist/utility/is-data-object-array.js +5 -0
- package/dist/utility/is-data-object.d.ts +3 -0
- package/dist/utility/is-data-object.js +4 -0
- package/dist/utility/is-date-highlighted.d.ts +2 -0
- package/dist/utility/is-date-highlighted.js +8 -0
- package/dist/utility/is-date-selected.d.ts +2 -0
- package/dist/utility/is-date-selected.js +16 -0
- package/package.json +28 -16
- package/dist/components/buttons/ConfirmableButton/index.d.ts +0 -7
- package/dist/components/buttons/ConfirmableButton/index.js +0 -13
- package/dist/components/collections/utility/filter-columns.d.ts +0 -3
- package/dist/components/collections/utility/filter-columns.js +0 -8
- package/dist/components/collections/utility/get-selected-from-search-params.d.ts +0 -2
- package/dist/components/collections/utility/get-selected-from-search-params.js +0 -5
- package/dist/components/collections/utility/set-selected-to-search-params.d.ts +0 -2
- package/dist/components/collections/utility/set-selected-to-search-params.js +0 -4
- package/dist/components/utility/ClassNames/index.d.ts +0 -6
- package/dist/components/utility/ClassNames/index.js +0 -7
- package/dist/components/utility/Page/index.d.ts +0 -18
- package/dist/components/utility/Page/index.js +0 -34
- package/dist/components/utility/RootLayout/index.d.ts +0 -12
- package/dist/components/utility/RootLayout/index.js +0 -14
- package/dist/styles/config.d.ts +0 -64
- package/dist/styles/config.js +0 -43
- package/dist/styles/icons.d.ts +0 -15
- package/dist/styles/icons.js +0 -7
- package/dist/styles/interfaces.d.ts +0 -41
- /package/dist/{styles → addon}/interfaces.js +0 -0
- /package/dist/styles/{tw.d.ts → classnames/utility/tw.d.ts} +0 -0
- /package/dist/styles/{tw.js → classnames/utility/tw.js} +0 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AppConfig } from '@sqrzro/config';
|
|
2
|
+
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
3
|
+
import type { UIAddonConfigObject, BaseUIAddonConfigObject } from './interfaces';
|
|
4
|
+
export declare function setConfig(db: NodePgDatabase, appConfig: AppConfig, cfg?: Partial<BaseUIAddonConfigObject>): void;
|
|
5
|
+
export declare function getConfig(): UIAddonConfigObject;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MissingConfigError } from '@sqrzro/addons';
|
|
2
|
+
import applyDefaults from './defaults';
|
|
3
|
+
let config = null;
|
|
4
|
+
export function setConfig(db, appConfig, cfg) {
|
|
5
|
+
config = { ...applyDefaults(cfg), db, app: appConfig };
|
|
6
|
+
}
|
|
7
|
+
export function getConfig() {
|
|
8
|
+
if (!config) {
|
|
9
|
+
throw new MissingConfigError('ui');
|
|
10
|
+
}
|
|
11
|
+
return config;
|
|
12
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AppConfig } from '@sqrzro/config';
|
|
2
|
+
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
3
|
+
export interface BaseUIAddonConfigObject {
|
|
4
|
+
}
|
|
5
|
+
export interface UIAddonConfigObject extends BaseUIAddonConfigObject {
|
|
6
|
+
app: AppConfig;
|
|
7
|
+
db: NodePgDatabase;
|
|
8
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { ButtonClassNames } from '../../../components/buttons/Button';
|
|
2
|
+
import { ActionComponentProps } from '../../../components/utility/Action';
|
|
3
|
+
import type { ClassNameProps } from '../../../styles/classnames/interfaces';
|
|
4
|
+
export interface ActionButtonProps<Data, Response> extends ClassNameProps<ButtonClassNames>, Omit<ActionComponentProps<Data, Response>, 'children'> {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
label?: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
declare function ActionButton<Data, Response>({ classNameProps, isSubmittable, ...props }: ActionButtonProps<Data, Response>): React.ReactElement;
|
|
7
9
|
export default ActionButton;
|
|
@@ -1,33 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import Button from '../../../components/buttons/Button';
|
|
4
|
-
import
|
|
4
|
+
import Action from '../../../components/utility/Action';
|
|
5
5
|
import FormSubmit from '../../../forms/components/FormSubmit';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function ActionButtonComponent({ action, children, confirmable, href, icon, isDisabled, isLoading, isSubmittable, label, onClick, variant, }) {
|
|
9
|
-
const { setSearchParamsHref } = useSearchParamsHref();
|
|
10
|
-
function handleClick() {
|
|
11
|
-
onClick?.();
|
|
12
|
-
if (action) {
|
|
13
|
-
setSearchParamsHref({ action });
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
const componentProps = {
|
|
17
|
-
children: children ?? label,
|
|
18
|
-
href,
|
|
19
|
-
icon,
|
|
20
|
-
isDisabled: Boolean(isDisabled || isLoading),
|
|
21
|
-
isLoading: isLoading && (isSubmittable || variant === 'primary'),
|
|
22
|
-
onClick: handleClick,
|
|
23
|
-
variant,
|
|
24
|
-
};
|
|
25
|
-
if (confirmable) {
|
|
26
|
-
return _jsx(ConfirmableButton, { ...componentProps, confirmable: confirmable });
|
|
27
|
-
}
|
|
28
|
-
return isSubmittable ? _jsx(FormSubmit, { ...componentProps }) : _jsx(Button, { ...componentProps });
|
|
29
|
-
}
|
|
30
|
-
function ActionButton(props) {
|
|
31
|
-
return (_jsx(Suspense, { children: _jsx(ActionButtonComponent, { ...props }) }));
|
|
6
|
+
function ActionButton({ classNameProps, isSubmittable, ...props }) {
|
|
7
|
+
return (_jsx(Action, { ...props, render: (renderProps) => isSubmittable ? (_jsx(FormSubmit, { ...renderProps, classNameProps: classNameProps })) : (_jsx(Button, { ...renderProps, classNameProps: classNameProps })) }));
|
|
32
8
|
}
|
|
33
9
|
export default ActionButton;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ClassNameProps
|
|
2
|
-
import {
|
|
1
|
+
import type { ClassNameProps } from '../../../styles/classnames/interfaces';
|
|
2
|
+
import type { ActionEvent, StyleVariant } from '../../../utility/interfaces';
|
|
3
3
|
export interface ButtonClassNames {
|
|
4
|
-
root:
|
|
4
|
+
root: string;
|
|
5
5
|
icon: string;
|
|
6
6
|
}
|
|
7
7
|
export interface ButtonProps extends ClassNameProps<ButtonClassNames> {
|
|
@@ -30,7 +30,7 @@ export interface ButtonProps extends ClassNameProps<ButtonClassNames> {
|
|
|
30
30
|
/** Used in situations where the button needs to be identified by name */
|
|
31
31
|
readonly name?: string;
|
|
32
32
|
/** An event handler for when the button is clicked */
|
|
33
|
-
readonly onClick?:
|
|
33
|
+
readonly onClick?: (event?: ActionEvent) => void;
|
|
34
34
|
/** If specified, a Popover component can be anchored to the target element with this ID */
|
|
35
35
|
readonly popoverTarget?: string;
|
|
36
36
|
readonly scroll?: boolean;
|
|
@@ -40,7 +40,7 @@ export interface ButtonProps extends ClassNameProps<ButtonClassNames> {
|
|
|
40
40
|
/** Used in situations where a button value needs to be submitted with a form */
|
|
41
41
|
readonly value?: string;
|
|
42
42
|
/** A set of predefined variants that can be passed to the classNames config to customize the button's appearance */
|
|
43
|
-
readonly variant?:
|
|
43
|
+
readonly variant?: StyleVariant[] | StyleVariant;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* Either a `Link` component or a `button` element, depending on whether a `href` prop is specified.
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useRef } from 'react';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
function getVariantClassName(className, variant) {
|
|
9
|
-
if (!className || !variant) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
return className[variant] || null;
|
|
13
|
-
}
|
|
4
|
+
import { useClassNames } from '../../../styles/context';
|
|
5
|
+
import applyVariants from '../../../styles/classnames/utility/apply-variants';
|
|
6
|
+
import tw from '../../../styles/classnames/utility/tw';
|
|
7
|
+
import Link from '../../elements/Link';
|
|
14
8
|
/**
|
|
15
9
|
* Either a `Link` component or a `button` element, depending on whether a `href` prop is specified.
|
|
16
10
|
*
|
|
@@ -32,12 +26,8 @@ function getVariantClassName(className, variant) {
|
|
|
32
26
|
*/
|
|
33
27
|
function Button({ children, classNames, classNameProps, form, hasAssistiveLabel, href, icon, id, isDisabled, isFullWidth, isLoading, isNewWindow, isText, name, onClick, popoverTarget, scroll, style, type, value, variant, }) {
|
|
34
28
|
const ref = useRef(null);
|
|
35
|
-
const componentClassNames = classNames
|
|
36
|
-
|
|
37
|
-
...(classNameProps || {}),
|
|
38
|
-
hasAssistiveLabel,
|
|
39
|
-
});
|
|
40
|
-
const className = tw('flex cursor-pointer items-center justify-center whitespace-nowrap', isDisabled || isLoading ? 'pointer-events-none opacity-30' : null, isFullWidth ? 'w-full' : null, componentClassNames?.root?.default, getVariantClassName(componentClassNames?.root, variant));
|
|
29
|
+
const componentClassNames = useClassNames(isText ? 'textButton' : 'button', { props: { ...classNameProps, ...applyVariants(variant) } }, classNames);
|
|
30
|
+
const className = tw('relative flex cursor-pointer items-center justify-center whitespace-nowrap', isDisabled || isLoading ? 'pointer-events-none opacity-30' : null, isFullWidth ? 'w-full' : null, componentClassNames?.root);
|
|
41
31
|
/*
|
|
42
32
|
* Link uses classNames, whereas button uses className. This is because Link can also be used
|
|
43
33
|
* headless in other applications, and so should have consistency.
|
|
@@ -45,6 +35,6 @@ function Button({ children, classNames, classNameProps, form, hasAssistiveLabel,
|
|
|
45
35
|
if (href) {
|
|
46
36
|
return (_jsx(Link, { className: className, href: href, id: id, isNewWindow: isNewWindow, onClick: onClick, scroll: scroll, style: style, children: _jsxs("span", { className: "flex items-center gap-2", children: [icon ? (_jsx("span", { className: tw('flex-none', componentClassNames?.icon), children: icon })) : null, _jsx("span", { className: tw(hasAssistiveLabel ? 'sr-only' : null), children: children })] }) }));
|
|
47
37
|
}
|
|
48
|
-
return (_jsxs("button", { ref: ref, className: className, disabled: isDisabled || isLoading || false, form: form, id: id, name: name, onClick: onClick, popoverTarget: popoverTarget, style: style, type: type === 'submit' ? 'submit' : 'button', value: value, children: [isLoading ? (_jsx("div", { className: "absolute left-1/2 top-1/2 -translate-x-2/4 -translate-y-2/4", children:
|
|
38
|
+
return (_jsxs("button", { ref: ref, className: className, disabled: isDisabled || isLoading || false, form: form, id: id, name: name, onClick: onClick, popoverTarget: popoverTarget, style: style, type: type === 'submit' ? 'submit' : 'button', value: value, children: [isLoading ? (_jsx("div", { className: "absolute left-1/2 top-1/2 -translate-x-2/4 -translate-y-2/4", children: "\u2022\u2022\u2022" })) : null, _jsxs("span", { className: "flex items-center gap-2", children: [icon ? (_jsx("span", { className: tw('flex-none', componentClassNames?.icon), children: icon })) : null, _jsx("span", { className: tw(hasAssistiveLabel ? 'sr-only' : null, isLoading ? 'text-transparent' : null), children: children })] })] }));
|
|
49
39
|
}
|
|
50
40
|
export default Button;
|
|
@@ -2,14 +2,20 @@ import type { FilterMap } from '../../../filters/interfaces';
|
|
|
2
2
|
import type { NextPageProps } from '../../../utility/interfaces';
|
|
3
3
|
import type { EmptyMessageProps } from '../EmptyMessage';
|
|
4
4
|
import type { ListFunctionConfig, Paginated } from '../interfaces';
|
|
5
|
-
export interface
|
|
5
|
+
export interface CollectionComponentProps<Item, Transformed, Filters> {
|
|
6
6
|
readonly data?: Item[] | Paginated<Item>;
|
|
7
|
+
readonly defaultFilters?: Partial<Filters>;
|
|
7
8
|
readonly emptyMessageProps?: EmptyMessageProps;
|
|
8
9
|
readonly filterMap?: FilterMap<Filters>;
|
|
9
10
|
readonly fn?: (config: ListFunctionConfig<Filters>) => Promise<Item[]> | Promise<Paginated<Item>>;
|
|
10
11
|
readonly pageProps?: NextPageProps;
|
|
11
|
-
readonly
|
|
12
|
+
readonly renderFilters?: (props: {
|
|
13
|
+
map: FilterMap<Filters>;
|
|
14
|
+
}) => React.ReactElement;
|
|
12
15
|
readonly transformer: (item: Item) => Transformed;
|
|
13
16
|
}
|
|
14
|
-
|
|
17
|
+
export interface CollectionProps<Item, Transformed, Filters> extends CollectionComponentProps<Item, Transformed, Filters> {
|
|
18
|
+
readonly render: (data: Transformed[]) => React.ReactElement;
|
|
19
|
+
}
|
|
20
|
+
declare function Collection<Item, Transformed, Filters>({ filterMap, renderFilters, ...props }: CollectionProps<Item, Transformed, Filters>): React.ReactElement;
|
|
15
21
|
export default Collection;
|
|
@@ -5,13 +5,11 @@ import FilterBar from '../../../filters/components/FilterBar';
|
|
|
5
5
|
import checkHasFilters from '../../../filters/utility/check-has-filters';
|
|
6
6
|
import parseFilters from '../../../filters/utility/parse-filters';
|
|
7
7
|
import parsePage from '../../../filters/utility/parse-page';
|
|
8
|
-
import { getIcon } from '../../../styles/icons';
|
|
9
8
|
import EmptyMessage from '../EmptyMessage';
|
|
10
9
|
import Pagination from '../Pagination';
|
|
11
10
|
import isPaginated from '../utility/is-paginated';
|
|
12
11
|
import { messages } from '../lang';
|
|
13
|
-
async function CollectionComponent({ data, emptyMessageProps, filterMap, fn, pageProps, render, transformer, }) {
|
|
14
|
-
const EmptyIcon = getIcon('collection.empty');
|
|
12
|
+
async function CollectionComponent({ data, defaultFilters, emptyMessageProps, filterMap, fn, pageProps, render, transformer, }) {
|
|
15
13
|
const awaitedParams = pageProps?.params ? await pageProps.params : null;
|
|
16
14
|
const awaitedSearchParams = pageProps?.searchParams ? await pageProps.searchParams : null;
|
|
17
15
|
async function getResponse() {
|
|
@@ -23,14 +21,17 @@ async function CollectionComponent({ data, emptyMessageProps, filterMap, fn, pag
|
|
|
23
21
|
}
|
|
24
22
|
const filters = parseFilters(awaitedSearchParams, filterMap);
|
|
25
23
|
const page = parsePage(awaitedSearchParams);
|
|
26
|
-
return fn({
|
|
24
|
+
return fn({
|
|
25
|
+
filters: { ...defaultFilters, ...filters },
|
|
26
|
+
page,
|
|
27
|
+
params: awaitedParams,
|
|
28
|
+
});
|
|
27
29
|
}
|
|
28
30
|
const response = await getResponse();
|
|
29
31
|
const dynamicData = (isPaginated(response) ? response.data : response).map(transformer);
|
|
30
32
|
const componentEmptyMessageProps = checkHasFilters(awaitedSearchParams)
|
|
31
33
|
? {
|
|
32
34
|
children: messages.EMPTY_FILTER_DESCRIPTION,
|
|
33
|
-
icon: EmptyIcon ? _jsx(EmptyIcon, {}) : null,
|
|
34
35
|
title: messages.EMPTY_FILTER_TITLE,
|
|
35
36
|
}
|
|
36
37
|
: emptyMessageProps;
|
|
@@ -39,7 +40,7 @@ async function CollectionComponent({ data, emptyMessageProps, filterMap, fn, pag
|
|
|
39
40
|
}
|
|
40
41
|
return (_jsxs(Fragment, { children: [render(dynamicData), isPaginated(response) ? (_jsx(Pagination, { ...response.meta, nextLabel: "Next \u2192", previousLabel: "\u2190 Previous" })) : null] }));
|
|
41
42
|
}
|
|
42
|
-
function Collection({ filterMap, ...props }) {
|
|
43
|
-
return (_jsxs(Fragment, { children: [filterMap ?
|
|
43
|
+
function Collection({ filterMap, renderFilters = FilterBar, ...props }) {
|
|
44
|
+
return (_jsxs(Fragment, { children: [filterMap ? renderFilters({ map: filterMap }) : null, _jsx(Suspense, { fallback: _jsx("div", { className: "flex justify-center p-16", children: _jsx(Loader, {}) }), children: _jsx(CollectionComponent, { ...props, filterMap: filterMap }) })] }));
|
|
44
45
|
}
|
|
45
46
|
export default Collection;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ClassNameProps } from '../../../styles/classnames/interfaces';
|
|
2
|
+
import type { DataObject } from '../../../utility/interfaces';
|
|
3
|
+
export interface DataTableClassNames {
|
|
4
|
+
root: string;
|
|
5
|
+
row: string;
|
|
6
|
+
cell: string;
|
|
7
|
+
label: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
export interface DataTableProps extends ClassNameProps<DataTableClassNames> {
|
|
11
|
+
readonly data: (DataObject | null)[];
|
|
12
|
+
}
|
|
13
|
+
declare function DataTable({ classNameProps, classNames, data, }: DataTableProps): React.ReactElement | null;
|
|
14
|
+
export default DataTable;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { filterNull } from '@sqrzro/utility';
|
|
4
|
+
import { useClassNames } from '../../../styles/context';
|
|
5
|
+
import tw from '../../../styles/classnames/utility/tw';
|
|
6
|
+
function DataTable({ classNameProps, classNames, data, }) {
|
|
7
|
+
const componentClassNames = useClassNames('dataTable', { props: classNameProps }, classNames);
|
|
8
|
+
const filtered = filterNull(data);
|
|
9
|
+
if (!filtered.length) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return (_jsx("table", { className: tw('w-full', componentClassNames?.root), children: _jsx("tbody", { children: filterNull(data).map(({ label, value }, index) => (_jsxs("tr", { className: componentClassNames?.row, children: [_jsx("th", { className: tw(componentClassNames?.cell, componentClassNames?.label), children: label }), _jsx("td", { className: tw(componentClassNames?.cell, componentClassNames?.value), children: value })] }, index))) }) }));
|
|
13
|
+
}
|
|
14
|
+
export default DataTable;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClassNameProps, StylableClassName } from '../../../styles/interfaces';
|
|
1
|
+
import type { ClassNameProps, StylableClassName } from '../../../styles/classnames/interfaces';
|
|
2
2
|
import { StyleVariant } from '../../../utility/interfaces';
|
|
3
3
|
import type { EmptyMessageActionProps } from '../EmptyMessageAction';
|
|
4
4
|
export interface EmptyMessageClassNames {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
3
|
+
import { useClassNames, useIcon } from '../../../styles/context';
|
|
4
|
+
import applyVariants from '../../../styles/classnames/utility/apply-variants';
|
|
5
5
|
import EmptyMessageAction from '../EmptyMessageAction';
|
|
6
6
|
export const DEFAULT_TITLE = 'No results found';
|
|
7
7
|
export const DEFAULT_CHILDREN = 'If you think this is an error, please contact the site administrator.';
|
|
@@ -11,7 +11,9 @@ export const DEFAULT_CHILDREN = 'If you think this is an error, please contact t
|
|
|
11
11
|
* component to be used for any situation where a standout message is required.
|
|
12
12
|
*/
|
|
13
13
|
function EmptyMessage({ action, children = DEFAULT_CHILDREN, classNameProps, classNames, icon, title = DEFAULT_TITLE, variant, }) {
|
|
14
|
-
const componentClassNames =
|
|
15
|
-
|
|
14
|
+
const componentClassNames = useClassNames('emptyMessage', { props: { ...classNameProps, ...applyVariants(variant) } }, classNames);
|
|
15
|
+
const DefaultIcon = useIcon('collection.empty');
|
|
16
|
+
const iconComponent = icon ?? (DefaultIcon ? _jsx(DefaultIcon, {}) : null);
|
|
17
|
+
return (_jsxs("section", { className: componentClassNames?.root, children: [iconComponent ? (_jsx("div", { className: componentClassNames?.icon, children: iconComponent })) : null, _jsx("h2", { className: componentClassNames?.title, children: title }), _jsx("div", { className: componentClassNames?.description, children: children }), action ? (_jsx("div", { className: componentClassNames?.action, children: _jsx(EmptyMessageAction, { action: action }) })) : null] }));
|
|
16
18
|
}
|
|
17
19
|
export default EmptyMessage;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SimpleActionObject } from '../../../utility/interfaces';
|
|
2
2
|
export interface EmptyMessageActionProps {
|
|
3
|
-
action:
|
|
3
|
+
action: SimpleActionObject | React.ReactElement;
|
|
4
4
|
}
|
|
5
5
|
declare function EmptyMessageAction({ action }: Readonly<EmptyMessageActionProps>): React.ReactElement;
|
|
6
6
|
export default EmptyMessageAction;
|
|
@@ -13,7 +13,7 @@ function EmptyMessageAction({ action }) {
|
|
|
13
13
|
action.onClick();
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
const href = action.
|
|
16
|
+
const href = action.searchParams ? getSearchParamsHref(action.searchParams) : action.href;
|
|
17
17
|
return (_jsx(Button, { href: href, isDisabled: Boolean(action.isDisabled), onClick: handleClick, variant: "primary", children: action.label }));
|
|
18
18
|
}
|
|
19
19
|
export default EmptyMessageAction;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ClassNameProps } from '../../../styles/classnames/interfaces';
|
|
2
|
+
import type { CollectionComponentProps } from '../Collection';
|
|
3
|
+
import type { ListClassNames } from '../ListClientComponent';
|
|
2
4
|
import type { ListItemObject } from '../interfaces';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
declare function List<Item
|
|
5
|
+
export type { ListClassNames } from '../ListClientComponent';
|
|
6
|
+
export type ListProps<Item, Filters, Data, Response> = ClassNameProps<ListClassNames> & CollectionComponentProps<Item, ListItemObject<Data, Response>, Filters>;
|
|
7
|
+
declare function List<Item, Filters, Data, Response>({ classNameProps, classNames, ...props }: ListProps<Item, Filters, Data, Response>): React.ReactElement;
|
|
6
8
|
export default List;
|
|
@@ -7,7 +7,7 @@ function defaultTransformer(item) {
|
|
|
7
7
|
title: 'title' in item ? String(item.title) : '',
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
|
-
function List(props) {
|
|
11
|
-
return (_jsx(Collection, { ...props, render: (data) => _jsx(ListClientComponent, { data: data }), transformer: props.transformer ?? defaultTransformer }));
|
|
10
|
+
function List({ classNameProps, classNames, ...props }) {
|
|
11
|
+
return (_jsx(Collection, { ...props, render: (data) => (_jsx(ListClientComponent, { classNameProps: classNameProps, classNames: classNames, data: data })), transformer: props.transformer ?? defaultTransformer }));
|
|
12
12
|
}
|
|
13
13
|
export default List;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { ClassNameProps } from '../../../styles/classnames/interfaces';
|
|
1
2
|
import type { ListItemObject } from '../interfaces';
|
|
2
|
-
export interface
|
|
3
|
-
|
|
4
|
-
renderItem?: (props: ListItemObject<Data>) => React.ReactElement;
|
|
3
|
+
export interface ListClassNames {
|
|
4
|
+
root: string;
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
interface ListClientComponentProps<Data, Response> extends ClassNameProps<ListClassNames> {
|
|
7
|
+
data: ListItemObject<Data, Response>[];
|
|
8
|
+
}
|
|
9
|
+
declare function ListClientComponent<Data, Response>({ classNameProps, classNames, data, }: ListClientComponentProps<Data, Response>): React.ReactElement;
|
|
7
10
|
export default ListClientComponent;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
+
import useSelected from '../../../hooks/useSelected';
|
|
4
|
+
import { useClassNames } from '../../../styles/context';
|
|
3
5
|
import ListItem from '../ListItem';
|
|
4
|
-
function ListClientComponent({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
function ListClientComponent({ classNameProps, classNames, data, }) {
|
|
7
|
+
const componentClassNames = useClassNames('list', { props: classNameProps }, classNames);
|
|
8
|
+
const { checkSelected, onSelect } = useSelected(data);
|
|
9
|
+
const hasActions = data.some((item) => item.actions?.length);
|
|
10
|
+
return (_jsx("ul", { className: componentClassNames?.root, children: data.map((item) => (_jsx(ListItem, { classNameProps: classNameProps, classNames: classNames, data: item, hasActions: hasActions, isSelected: checkSelected(item.id), onSelect: onSelect }, item.id))) }));
|
|
8
11
|
}
|
|
9
12
|
export default ListClientComponent;
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { InputEvent } from '../../../forms/interfaces';
|
|
2
|
+
import type { ClassNameProps, StylableClassName } from '../../../styles/classnames/interfaces';
|
|
2
3
|
import type { ListItemObject } from '../interfaces';
|
|
3
4
|
export interface ListItemClassNames {
|
|
5
|
+
actions: string;
|
|
4
6
|
description: string;
|
|
5
7
|
primary: string;
|
|
6
8
|
root: StylableClassName;
|
|
7
9
|
secondary: string;
|
|
10
|
+
select: string;
|
|
8
11
|
tertiary: string;
|
|
9
12
|
title: StylableClassName;
|
|
10
13
|
}
|
|
11
|
-
export interface ListItemProps<Data
|
|
14
|
+
export interface ListItemProps<Data, Response> extends ClassNameProps<ListItemClassNames> {
|
|
15
|
+
data: ListItemObject<Data, Response>;
|
|
16
|
+
hasActions: boolean;
|
|
17
|
+
isSelected: boolean;
|
|
18
|
+
onSelect: (event: InputEvent<boolean>) => void;
|
|
12
19
|
}
|
|
13
|
-
declare function ListItem<Data
|
|
20
|
+
declare function ListItem<Data, Response>({ classNameProps, classNames, data, hasActions, isSelected, onSelect, }: Readonly<ListItemProps<Data, Response>>): React.ReactElement;
|
|
14
21
|
export default ListItem;
|
|
@@ -1,28 +1,20 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import { filterNull } from '@sqrzro/utility';
|
|
4
|
+
import { usePathname } from 'next/navigation';
|
|
5
|
+
import Switch from '../../../forms/components/Switch';
|
|
6
|
+
import { useClassNames } from '../../../styles/context';
|
|
7
|
+
import tw from '../../../styles/classnames/utility/tw';
|
|
8
|
+
import Link from '../../elements/Link';
|
|
9
|
+
import normalizeHref from '../utility/normalize-href';
|
|
6
10
|
import ListItemSecondary from '../ListItemSecondary';
|
|
7
11
|
import ListItemMeta from '../ListItemMeta';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return colMap[count];
|
|
16
|
-
}
|
|
17
|
-
function ListItem({
|
|
18
|
-
// actions,
|
|
19
|
-
classNames, classNameProps, description, href, id, isLoading, meta, secondary, tertiary, title, variant, }) {
|
|
20
|
-
const componentClassNames = classNames || getClassNames('listItem')?.(classNameProps);
|
|
21
|
-
const hasPrimary = Boolean(title || description || meta);
|
|
22
|
-
const hasSecondary = Boolean(secondary);
|
|
23
|
-
const hasTertiary = Boolean(tertiary);
|
|
24
|
-
return (_jsx("li", { className: tw('@container relative grid', componentClassNames?.root?.default, variant ? componentClassNames?.root?.[variant] : null, isLoading ? 'pointer-events-none animate-pulse' : null
|
|
25
|
-
// typeof actions === 'function' ? 'grid-cols-[1fr_auto] gap-4' : 'grid-cols-1'
|
|
26
|
-
), children: _jsx("article", { className: "contents", children: _jsxs("div", { className: tw('grid gap-x-6 gap-y-4', getLayout([hasPrimary, hasSecondary, hasTertiary])), children: [_jsxs("div", { className: componentClassNames?.primary, children: [title ? (_jsx("h2", { className: tw(componentClassNames?.title?.default, variant ? componentClassNames?.title?.[variant] : null), children: href ? (_jsx(Link, { className: "hover:text-link", href: href, children: title })) : (title) })) : null, description ? (_jsx("div", { className: componentClassNames?.description, children: description })) : null, _jsx(ListItemMeta, { classNameProps: classNameProps, data: meta?.data, id: id })] }), tertiary ? (_jsx("div", { className: componentClassNames?.tertiary, children: tertiary })) : null, _jsx(ListItemSecondary, { classNameProps: classNameProps, classNames: classNames, data: secondary?.data, variant: variant })] }) }) }));
|
|
12
|
+
import ListItemMenu from '../ListItemMenu';
|
|
13
|
+
function ListItem({ classNameProps, classNames, data, hasActions, isSelected, onSelect, }) {
|
|
14
|
+
const pathname = usePathname();
|
|
15
|
+
const componentClassNames = useClassNames('listItem', { props: { ...classNameProps, isSelected } }, classNames);
|
|
16
|
+
const filteredActions = filterNull(data.actions || []);
|
|
17
|
+
//filteredActions.length ? 'grid-cols-[1fr_auto] gap-4' : 'grid-cols-1'
|
|
18
|
+
return (_jsx("li", { className: tw('relative grid', componentClassNames?.root), children: _jsx("article", { className: "contents", children: _jsxs("div", { className: "grid gap-6 has-[>:nth-child(2)]:grid-cols-[max-content_auto]", children: [data.isSelectable ? (_jsx("div", { className: componentClassNames?.select, children: _jsx(Switch, { name: data.id, onChange: onSelect, value: isSelected }) })) : null, _jsxs("div", { className: "grid gap-6 has-[>:nth-child(2)]:grid-cols-[auto_max-content]", children: [_jsxs("div", { className: 'grid grid-cols-1 gap-6 has-[>:nth-child(2)]:grid-cols-[1fr_1fr] has-[>:nth-child(3)]:grid-cols-[2fr_1fr_1fr]', children: [_jsxs("div", { className: componentClassNames?.primary, children: [data.title ? (_jsx("h2", { className: componentClassNames?.title, children: data.href ? (_jsx(Link, { className: "hover:text-link", href: normalizeHref(data.href, pathname), children: data.title })) : (data.title) })) : null, data.description ? (_jsx("div", { className: componentClassNames?.description, children: data.description })) : null, _jsx(ListItemMeta, { classNameProps: classNameProps, data: data.meta })] }), data.tertiary ? (_jsx("div", { className: componentClassNames?.tertiary, children: data.tertiary })) : null, _jsx(ListItemSecondary, { classNameProps: classNameProps, classNames: classNames, data: data.secondary })] }), hasActions ? (_jsx("div", { className: componentClassNames?.actions, children: _jsx(ListItemMenu, { actions: filteredActions, data: data.$data, isDisabled: !filteredActions.length }) })) : null] })] }) }) }));
|
|
27
19
|
}
|
|
28
20
|
export default ListItem;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ActionObject } from '../../../utility/interfaces';
|
|
2
|
+
interface ListItemMenuProps<Data, Response> {
|
|
3
|
+
actions: ActionObject<Data, Response>[];
|
|
4
|
+
data?: Data;
|
|
5
|
+
isDisabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare function ListItemMenu<Data, Response>(props: ListItemMenuProps<Data, Response>): React.ReactElement;
|
|
8
|
+
export default ListItemMenu;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { ClassNameProps } from '../../../styles/interfaces';
|
|
2
|
-
import type {
|
|
1
|
+
import type { ClassNameProps } from '../../../styles/classnames/interfaces';
|
|
2
|
+
import type { DataObject } from '../../../utility/interfaces';
|
|
3
3
|
export interface ListItemMetaClassNames {
|
|
4
4
|
root: string;
|
|
5
5
|
row: string;
|
|
6
6
|
title: string;
|
|
7
7
|
value: string;
|
|
8
8
|
}
|
|
9
|
-
export type ListItemMetaProps = ClassNameProps<ListItemMetaClassNames> &
|
|
10
|
-
|
|
9
|
+
export type ListItemMetaProps = ClassNameProps<ListItemMetaClassNames> & {
|
|
10
|
+
data?: React.ReactNode[] | (DataObject | null)[];
|
|
11
|
+
};
|
|
12
|
+
declare function ListItemMeta({ classNameProps, classNames, data, }: Readonly<ListItemMetaProps>): React.ReactElement | null;
|
|
11
13
|
export default ListItemMeta;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
3
|
import { isValidElement } from 'react';
|
|
3
4
|
import { filterNull } from '@sqrzro/utility';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
5
|
+
import { useClassNames } from '../../../styles/context';
|
|
6
|
+
import isDataTableArray from '../../../utility/is-data-object-array';
|
|
7
|
+
import DataTable from '../DataTable';
|
|
6
8
|
function getKey(item) {
|
|
7
9
|
if (isValidElement(item)) {
|
|
8
10
|
return item.key || '-';
|
|
@@ -12,11 +14,15 @@ function getKey(item) {
|
|
|
12
14
|
}
|
|
13
15
|
return String(item);
|
|
14
16
|
}
|
|
15
|
-
function ListItemMeta({ classNameProps, classNames,
|
|
16
|
-
const componentClassNames =
|
|
17
|
-
if (!data) {
|
|
17
|
+
function ListItemMeta({ classNameProps, classNames, data, }) {
|
|
18
|
+
const componentClassNames = useClassNames('listItemMeta', { props: classNameProps }, classNames);
|
|
19
|
+
if (!data?.length) {
|
|
18
20
|
return null;
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
const filteredData = filterNull(data);
|
|
23
|
+
if (isDataTableArray(filteredData)) {
|
|
24
|
+
return _jsx(DataTable, { data: filteredData });
|
|
25
|
+
}
|
|
26
|
+
return (_jsx("ul", { className: componentClassNames?.root, children: filteredData.map((item) => (_jsx("li", { className: "whitespace-nowrap", children: item }, getKey(item)))) }));
|
|
21
27
|
}
|
|
22
28
|
export default ListItemMeta;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import type { ClassNameProps } from '../../../styles/interfaces';
|
|
1
|
+
import type { ClassNameProps } from '../../../styles/classnames/interfaces';
|
|
2
2
|
import type { ListItemClassNames } from '../ListItem';
|
|
3
3
|
import type { ListItemObject } from '../interfaces';
|
|
4
|
-
export type ListItemSecondaryProps = ClassNameProps<ListItemClassNames> &
|
|
5
|
-
|
|
4
|
+
export type ListItemSecondaryProps<Data, Response> = ClassNameProps<ListItemClassNames> & {
|
|
5
|
+
data: ListItemObject<Data, Response>['secondary'];
|
|
6
|
+
};
|
|
7
|
+
declare function ListItemSecondary<Data, Response>({ classNameProps, classNames, data, }: Readonly<ListItemSecondaryProps<Data, Response>>): React.ReactElement | null;
|
|
6
8
|
export default ListItemSecondary;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
3
|
import { isValidElement } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import tw from '../../../styles/tw';
|
|
4
|
+
import { useClassNames } from '../../../styles/context';
|
|
5
5
|
import ListItemMeta from '../ListItemMeta';
|
|
6
|
-
function ListItemSecondary({ classNameProps, classNames, data,
|
|
7
|
-
const componentClassNames =
|
|
6
|
+
function ListItemSecondary({ classNameProps, classNames, data, }) {
|
|
7
|
+
const componentClassNames = useClassNames('listItem', { props: classNameProps }, classNames);
|
|
8
8
|
if (!data) {
|
|
9
9
|
return null;
|
|
10
10
|
}
|
|
11
11
|
if (isValidElement(data)) {
|
|
12
12
|
return _jsx("div", { className: componentClassNames?.secondary, children: data });
|
|
13
13
|
}
|
|
14
|
-
return (_jsxs("div", { className: componentClassNames?.secondary, children: [data.title ?
|
|
14
|
+
return (_jsxs("div", { className: componentClassNames?.secondary, children: [data.title ? _jsx("p", { className: componentClassNames?.title, children: data.title }) : null, data.description ? (_jsx("div", { className: componentClassNames?.description, children: data.description })) : null, _jsx(ListItemMeta, { classNameProps: { ...classNameProps, isSecondary: true }, data: data.meta })] }));
|
|
15
15
|
}
|
|
16
16
|
export default ListItemSecondary;
|