@sqrzro/ui 4.0.0-alpha.2 → 4.0.0-alpha.21
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/buttons/ActionButton/index.d.ts +6 -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 +6 -16
- package/dist/components/collections/Collection/index.d.ts +9 -3
- package/dist/components/collections/Collection/index.js +4 -4
- package/dist/components/collections/DataTable/index.d.ts +14 -0
- package/dist/components/collections/DataTable/index.js +9 -0
- package/dist/components/collections/EmptyMessage/index.d.ts +1 -1
- package/dist/components/collections/EmptyMessage/index.js +3 -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 +5 -3
- package/dist/components/collections/List/index.js +8 -2
- package/dist/components/collections/ListItem/index.d.ts +2 -2
- package/dist/components/collections/ListItem/index.js +6 -10
- package/dist/components/collections/ListItemMenu/index.d.ts +7 -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 +12 -7
- package/dist/components/collections/ListItemSecondary/index.d.ts +1 -1
- package/dist/components/collections/ListItemSecondary/index.js +3 -4
- package/dist/components/collections/Pagination/index.d.ts +1 -1
- package/dist/components/collections/Pagination/index.js +5 -6
- package/dist/components/collections/PaginationLink/index.d.ts +9 -0
- package/dist/components/collections/PaginationLink/index.js +8 -0
- package/dist/components/collections/Table/index.d.ts +3 -3
- package/dist/components/collections/Table/index.js +1 -1
- package/dist/components/collections/TableClientComponent/index.d.ts +4 -4
- package/dist/components/collections/TableClientComponent/index.js +5 -10
- package/dist/components/collections/TableRow/index.d.ts +13 -0
- package/dist/components/collections/TableRow/index.js +9 -0
- package/dist/components/collections/interfaces.d.ts +19 -17
- package/dist/components/collections/utility/is-data-table-array.d.ts +3 -0
- package/dist/components/collections/utility/is-data-table-array.js +5 -0
- package/dist/components/collections/utility/is-data-table-object.d.ts +3 -0
- package/dist/components/collections/utility/is-data-table-object.js +4 -0
- package/dist/components/errors/AppError/index.d.ts +19 -0
- package/dist/components/errors/AppError/index.js +8 -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 +19 -0
- package/dist/components/index.js +9 -0
- package/dist/components/modals/ConfirmModal/index.d.ts +3 -1
- 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 +3 -3
- package/dist/components/utility/Action/index.d.ts +11 -0
- package/dist/components/utility/Action/index.js +44 -0
- package/dist/components/utility/ActionList/index.d.ts +3 -3
- package/dist/components/utility/ActionList/index.js +3 -3
- package/dist/components/utility/ClassNamesClientComponent/index.d.ts +6 -0
- package/dist/components/utility/ClassNamesClientComponent/index.js +7 -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/Link/index.d.ts +1 -1
- package/dist/components/utility/Link/index.js +3 -3
- package/dist/components/utility/Loader/index.d.ts +1 -1
- package/dist/components/utility/Loader/index.js +4 -4
- package/dist/components/utility/Menu/index.d.ts +11 -0
- package/dist/components/utility/Menu/index.js +15 -0
- package/dist/components/utility/MenuItem/index.d.ts +4 -0
- package/dist/components/utility/MenuItem/index.js +9 -0
- package/dist/components/utility/Popover/index.d.ts +1 -1
- package/dist/components/utility/Popover/index.js +4 -4
- package/dist/components/utility/Reference/index.d.ts +9 -0
- package/dist/components/utility/Reference/index.js +15 -0
- package/dist/components/utility/RootLayout/index.d.ts +6 -3
- package/dist/components/utility/RootLayout/index.js +7 -6
- package/dist/components/utility/Toast/index.d.ts +1 -1
- package/dist/components/utility/Toast/index.js +2 -2
- package/dist/filters/components/FilterBarClientComponent/index.d.ts +1 -1
- package/dist/filters/components/FilterBarClientComponent/index.js +2 -2
- package/dist/filters/components/FilterControl/index.d.ts +1 -1
- package/dist/filters/components/FilterControl/index.js +7 -4
- package/dist/filters/components/FilterItem/index.d.ts +1 -1
- package/dist/filters/components/FilterItem/index.js +2 -2
- package/dist/filters/components/FilterPanel/index.d.ts +1 -1
- package/dist/filters/filters/Filter/index.d.ts +1 -1
- package/dist/filters/filters/Filter/index.js +3 -4
- package/dist/filters/filters/SearchFilter/index.js +1 -1
- package/dist/filters/index.d.ts +1 -0
- package/dist/filters/index.js +1 -0
- package/dist/filters/interfaces.d.ts +2 -2
- package/dist/filters/utility/parse-filters.d.ts +1 -1
- package/dist/filters/utility/parse-filters.js +3 -2
- 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/Dropdown/index.d.ts +1 -1
- package/dist/forms/components/Dropdown/index.js +8 -5
- package/dist/forms/components/DropdownItem/index.d.ts +9 -0
- package/dist/forms/components/DropdownItem/index.js +8 -0
- package/dist/forms/components/DropdownList/index.d.ts +1 -1
- package/dist/forms/components/DropdownList/index.js +5 -8
- package/dist/forms/components/EditableForm/index.d.ts +3 -3
- package/dist/forms/components/EditableForm/index.js +3 -4
- package/dist/forms/components/EditableFormField/index.d.ts +1 -1
- package/dist/forms/components/EditableFormField/index.js +2 -2
- 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 +1 -1
- package/dist/forms/components/FormError/index.js +3 -3
- package/dist/forms/components/FormField/index.d.ts +4 -4
- package/dist/forms/components/FormField/index.js +7 -6
- package/dist/forms/components/FormFields/index.d.ts +9 -0
- package/dist/forms/components/FormFields/index.js +18 -0
- package/dist/forms/components/FormLabel/index.d.ts +1 -1
- package/dist/forms/components/FormLabel/index.js +3 -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 +9 -0
- package/dist/forms/components/PasswordComplexity/index.js +10 -0
- package/dist/forms/components/PasswordInput/index.d.ts +1 -1
- package/dist/forms/components/PasswordInput/index.js +4 -5
- package/dist/forms/components/PointsInput/index.d.ts +5 -0
- package/dist/forms/components/PointsInput/index.js +22 -0
- package/dist/forms/components/StaticTextInput/index.d.ts +2 -3
- package/dist/forms/components/StaticTextInput/index.js +5 -8
- package/dist/forms/components/Switch/index.d.ts +1 -1
- package/dist/forms/components/Switch/index.js +4 -4
- package/dist/forms/components/TextInput/index.d.ts +2 -2
- package/dist/forms/components/TextInput/index.js +6 -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 +1 -1
- package/dist/forms/hooks/useForm.js +5 -4
- package/dist/forms/hooks/useModalForm.d.ts +2 -2
- package/dist/forms/index.d.ts +18 -2
- package/dist/forms/index.js +7 -2
- package/dist/forms/interfaces.d.ts +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -1
- package/dist/hooks/useConfirmable.d.ts +21 -0
- package/dist/hooks/useConfirmable.js +58 -0
- package/dist/hooks/usePopover.d.ts +11 -0
- package/dist/hooks/usePopover.js +17 -0
- package/dist/hooks/useServerAction.d.ts +9 -0
- package/dist/hooks/useServerAction.js +15 -0
- package/dist/navigation/components/AppNavigation/index.d.ts +2 -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 +13 -6
- 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/apply-variants.d.ts +3 -0
- package/dist/styles/classnames/apply-variants.js +25 -0
- package/dist/styles/classnames/config.d.ts +69 -0
- package/dist/styles/classnames/index.d.ts +7 -0
- package/dist/styles/classnames/index.js +37 -0
- package/dist/styles/classnames/interfaces.d.ts +56 -0
- package/dist/styles/classnames/interfaces.js +1 -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/icons/config.d.ts +9 -0
- package/dist/styles/icons/config.js +1 -0
- package/dist/styles/icons/index.d.ts +4 -0
- package/dist/styles/icons/interfaces.d.ts +4 -0
- package/dist/styles/icons/interfaces.js +1 -0
- package/dist/styles/index.d.ts +2 -2
- package/dist/styles/index.js +1 -1
- package/dist/styles/styles.css +59 -0
- package/dist/utility/interfaces.d.ts +19 -8
- package/package.json +9 -4
- package/dist/components/buttons/ConfirmableButton/index.d.ts +0 -7
- package/dist/components/buttons/ConfirmableButton/index.js +0 -13
- package/dist/components/collections/ListClientComponent/index.d.ts +0 -7
- package/dist/components/collections/ListClientComponent/index.js +0 -9
- package/dist/components/collections/utility/filter-columns.d.ts +0 -3
- package/dist/components/collections/utility/filter-columns.js +0 -8
- package/dist/components/utility/ClassNames/index.d.ts +0 -6
- package/dist/components/utility/ClassNames/index.js +0 -7
- 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/interfaces.d.ts +0 -41
- /package/dist/styles/{interfaces.js → classnames/config.js} +0 -0
- /package/dist/styles/{tw.d.ts → classnames/tw.d.ts} +0 -0
- /package/dist/styles/{tw.js → classnames/tw.js} +0 -0
- /package/dist/styles/{icons.js → icons/index.js} +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useRouter } from 'next/navigation';
|
|
4
|
+
function useConfirmable({ isLoading, onBeforeConfirm, onConfirm, onSuccess, redirectOnSuccess, refreshOnSuccess, }) {
|
|
5
|
+
const ref = useRef(null);
|
|
6
|
+
const router = useRouter();
|
|
7
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
8
|
+
const [isConfirmed, setIsConfirmed] = useState(false);
|
|
9
|
+
const [refEvent, setRefEvent] = useState();
|
|
10
|
+
function handle(event) {
|
|
11
|
+
onBeforeConfirm?.();
|
|
12
|
+
if (!isConfirmed) {
|
|
13
|
+
event?.preventDefault();
|
|
14
|
+
setIsModalOpen(true);
|
|
15
|
+
}
|
|
16
|
+
setRefEvent(event);
|
|
17
|
+
setIsConfirmed(false);
|
|
18
|
+
}
|
|
19
|
+
function handleConfirm() {
|
|
20
|
+
setIsConfirmed(true);
|
|
21
|
+
setTimeout(() => {
|
|
22
|
+
if (refEvent) {
|
|
23
|
+
onConfirm(refEvent, ref.current);
|
|
24
|
+
}
|
|
25
|
+
// If `isLoading` hasn't been set, we can just close the modal now. If it has, by
|
|
26
|
+
// setting `isConfirmed` to true above, we trigger the useEffect below to wait until
|
|
27
|
+
// after loading to close the modal.
|
|
28
|
+
if (typeof isLoading === 'undefined') {
|
|
29
|
+
setIsConfirmed(false);
|
|
30
|
+
setIsModalOpen(false);
|
|
31
|
+
}
|
|
32
|
+
}, 0);
|
|
33
|
+
}
|
|
34
|
+
function handleCancel() {
|
|
35
|
+
setIsModalOpen(false);
|
|
36
|
+
}
|
|
37
|
+
function handleSuccess() {
|
|
38
|
+
setIsConfirmed(false);
|
|
39
|
+
setIsModalOpen(false);
|
|
40
|
+
router.refresh();
|
|
41
|
+
}
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!isLoading && isConfirmed) {
|
|
44
|
+
handleSuccess();
|
|
45
|
+
}
|
|
46
|
+
}, [isLoading]);
|
|
47
|
+
return {
|
|
48
|
+
handle,
|
|
49
|
+
isOpen: isModalOpen,
|
|
50
|
+
modalProps: {
|
|
51
|
+
isLoading: isLoading ?? false,
|
|
52
|
+
onCancel: handleCancel,
|
|
53
|
+
onConfirm: handleConfirm,
|
|
54
|
+
},
|
|
55
|
+
ref,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export default useConfirmable;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface UsePopoverReturn<T extends HTMLElement = HTMLElement> {
|
|
2
|
+
controlProps: {
|
|
3
|
+
onClick: () => void;
|
|
4
|
+
};
|
|
5
|
+
ref: React.RefObject<T | null>;
|
|
6
|
+
targetProps: {
|
|
7
|
+
isOpen: boolean;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
declare function usePopover<T extends HTMLElement = HTMLElement>(): UsePopoverReturn<T>;
|
|
11
|
+
export default usePopover;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import useClickOutside from './useClickOutside';
|
|
2
|
+
function usePopover() {
|
|
3
|
+
const [isOpen, setIsOpen, ref] = useClickOutside();
|
|
4
|
+
function toggleIsOpen() {
|
|
5
|
+
setIsOpen(!isOpen);
|
|
6
|
+
}
|
|
7
|
+
return {
|
|
8
|
+
controlProps: {
|
|
9
|
+
onClick: toggleIsOpen,
|
|
10
|
+
},
|
|
11
|
+
ref,
|
|
12
|
+
targetProps: {
|
|
13
|
+
isOpen,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export default usePopover;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface UseServerActionArgs {
|
|
2
|
+
onSuccess?: () => void;
|
|
3
|
+
}
|
|
4
|
+
interface UseServerActionReturn {
|
|
5
|
+
handleClick: () => void;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare function useServerAction(fn?: () => Promise<void>, { onSuccess }?: UseServerActionArgs): UseServerActionReturn;
|
|
9
|
+
export default useServerAction;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useTransition } from 'react';
|
|
2
|
+
function useServerAction(fn, { onSuccess } = {}) {
|
|
3
|
+
const [isLoading, startTransition] = useTransition();
|
|
4
|
+
function handleClick() {
|
|
5
|
+
startTransition(async () => {
|
|
6
|
+
if (!fn) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
await fn();
|
|
10
|
+
onSuccess?.();
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return { handleClick, isLoading };
|
|
14
|
+
}
|
|
15
|
+
export default useServerAction;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClassNameProps, HighlightableClassName } from '../../../styles/interfaces';
|
|
1
|
+
import type { ClassNameProps, HighlightableClassName } from '../../../styles/classnames/interfaces';
|
|
2
2
|
import type { NavigationObject } from '../../interfaces';
|
|
3
3
|
export interface AppNavigationClassNames {
|
|
4
4
|
root: string;
|
|
@@ -7,6 +7,7 @@ export interface AppNavigationClassNames {
|
|
|
7
7
|
link: HighlightableClassName;
|
|
8
8
|
}
|
|
9
9
|
export interface AppNavigationProps extends ClassNameProps<AppNavigationClassNames> {
|
|
10
|
+
classNameKey?: 'appNavigation' | 'tabs';
|
|
10
11
|
data: NavigationObject[];
|
|
11
12
|
}
|
|
12
13
|
declare function AppNavigation(props: Readonly<AppNavigationProps>): React.ReactElement;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { Suspense } from 'react';
|
|
4
|
-
import { getClassNames } from '../../../styles/
|
|
4
|
+
import { getClassNames } from '../../../styles/classnames';
|
|
5
5
|
import useNavigation from '../../hooks/useNavigation';
|
|
6
6
|
import AppNavigationItem from '../AppNavigationItem';
|
|
7
|
-
function AppNavigationComponent({ classNameProps, classNames, data, }) {
|
|
8
|
-
const componentClassNames =
|
|
7
|
+
function AppNavigationComponent({ classNameKey, classNameProps, classNames, data, }) {
|
|
8
|
+
const componentClassNames = getClassNames(classNameKey ?? 'appNavigation', { props: classNameProps }, classNames);
|
|
9
9
|
const navigation = useNavigation(data);
|
|
10
|
-
return (_jsx("nav", { className: componentClassNames?.root, children: _jsx("ul", { className: componentClassNames?.list, children: navigation.map((item, index) => (_jsx(AppNavigationItem, { classNames: classNames, ...item }, index))) }) }));
|
|
10
|
+
return (_jsx("nav", { className: componentClassNames?.root, children: _jsx("ul", { className: componentClassNames?.list, children: navigation.map((item, index) => (_jsx(AppNavigationItem, { classNameKey: classNameKey, classNames: classNames, ...item }, index))) }) }));
|
|
11
11
|
}
|
|
12
12
|
function AppNavigation(props) {
|
|
13
13
|
return (_jsx(Suspense, { children: _jsx(AppNavigationComponent, { ...props }) }));
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { NavigationObject } from '../../../navigation/interfaces';
|
|
2
|
-
import type { ClassNameProps } from '../../../styles/interfaces';
|
|
2
|
+
import type { ClassNameProps } from '../../../styles/classnames/interfaces';
|
|
3
3
|
import type { AppNavigationClassNames } from '../AppNavigation';
|
|
4
|
-
export
|
|
5
|
-
|
|
4
|
+
export interface AppNavigationItemProps extends NavigationObject, ClassNameProps<AppNavigationClassNames> {
|
|
5
|
+
classNameKey?: 'appNavigation' | 'tabs';
|
|
6
|
+
}
|
|
7
|
+
declare function AppNavigationItem({ children, classNameKey, classNameProps, classNames, href, isActive, label, }: Readonly<AppNavigationItemProps>): React.ReactElement;
|
|
6
8
|
export default AppNavigationItem;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Action from '../../../components/utility/Action';
|
|
2
3
|
import Link from '../../../components/utility/Link';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import MenuItem from '../../../components/utility/MenuItem';
|
|
5
|
+
import Popover from '../../../components/utility/Popover';
|
|
6
|
+
import usePopover from '../../../hooks/usePopover';
|
|
7
|
+
import { getClassNames } from '../../../styles/classnames';
|
|
8
|
+
function AppNavigationItem({ children, classNameKey, classNameProps, classNames, href, isActive, label, }) {
|
|
9
|
+
const componentClassNames = getClassNames(classNameKey ?? 'appNavigation', { props: classNameProps, states: { isHighlighted: isActive ?? false } }, classNames);
|
|
10
|
+
const { controlProps, ref, targetProps } = usePopover();
|
|
11
|
+
if (children?.length) {
|
|
12
|
+
return (_jsxs("li", { className: componentClassNames?.item, ref: ref, children: [_jsx("button", { className: componentClassNames?.link, type: "button", ...controlProps, children: label }), _jsx(Popover, { align: "left", vAlign: "bottom", ...targetProps, children: _jsx("ul", { children: children.map((item, index) => (_jsx("li", { children: _jsx(Action, { ...item, render: MenuItem }) }, index))) }) })] }));
|
|
13
|
+
}
|
|
14
|
+
return (_jsx("li", { className: componentClassNames?.item, children: _jsx(Link, { className: componentClassNames?.link, href: href, children: label }) }));
|
|
8
15
|
}
|
|
9
16
|
export default AppNavigationItem;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
'use client';
|
|
2
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { getClassNames } from '../../../styles/config';
|
|
4
2
|
import AppNavigation from '../AppNavigation';
|
|
5
3
|
function Tabs({ classNameProps, classNames, ...props }) {
|
|
6
|
-
|
|
7
|
-
return _jsx(AppNavigation, { classNames: componentClassNames ?? {}, ...props });
|
|
4
|
+
return _jsx(AppNavigation, { classNameKey: "tabs", ...props });
|
|
8
5
|
}
|
|
9
6
|
export default Tabs;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ActionObject } from '../../utility/interfaces';
|
|
2
2
|
import type { NavigationObject } from '../interfaces';
|
|
3
|
-
interface NavigationAction extends
|
|
4
|
-
children?:
|
|
3
|
+
interface NavigationAction extends ActionObject {
|
|
4
|
+
children?: ActionObject[];
|
|
5
5
|
}
|
|
6
6
|
interface UseNavigationOptions {
|
|
7
7
|
basePath?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { joinURL } from '@sqrzro/utility';
|
|
2
2
|
import { usePathname, useSelectedLayoutSegments } from 'next/navigation';
|
|
3
3
|
function getActivePath(pathname, hrefs) {
|
|
4
4
|
return (hrefs
|
|
@@ -18,7 +18,7 @@ function getBasePath(pathname, segments) {
|
|
|
18
18
|
function transformChildren(children, basePath) {
|
|
19
19
|
return children.map(({ details, href, label }) => ({
|
|
20
20
|
details,
|
|
21
|
-
href:
|
|
21
|
+
href: joinURL(basePath, href),
|
|
22
22
|
label,
|
|
23
23
|
}));
|
|
24
24
|
}
|
|
@@ -26,13 +26,13 @@ function useNavigation(data, options) {
|
|
|
26
26
|
const pathname = usePathname();
|
|
27
27
|
const segments = useSelectedLayoutSegments();
|
|
28
28
|
const basePath = getBasePath(pathname, segments);
|
|
29
|
-
const hrefs = data.map(({ href }) =>
|
|
29
|
+
const hrefs = data.map(({ href }) => joinURL(basePath, href));
|
|
30
30
|
const activePath = getActivePath(pathname, hrefs);
|
|
31
31
|
return data.map((item) => ({
|
|
32
32
|
...item,
|
|
33
33
|
children: transformChildren(item.children || [], item.href),
|
|
34
|
-
href:
|
|
35
|
-
isActive:
|
|
34
|
+
href: joinURL(basePath, item.href),
|
|
35
|
+
isActive: joinURL(basePath, item.href) === activePath,
|
|
36
36
|
}));
|
|
37
37
|
}
|
|
38
38
|
export default useNavigation;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const keyMap = {
|
|
2
|
+
bordered: 'isBordered',
|
|
3
|
+
danger: 'isDanger',
|
|
4
|
+
error: 'isError',
|
|
5
|
+
info: 'isInfo',
|
|
6
|
+
primary: 'isPrimary',
|
|
7
|
+
secondary: 'isSecondary',
|
|
8
|
+
success: 'isSuccess',
|
|
9
|
+
tertiary: 'isTertiary',
|
|
10
|
+
warning: 'isWarning',
|
|
11
|
+
};
|
|
12
|
+
function applyVariants(variants) {
|
|
13
|
+
if (!variants) {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
const variantArray = Array.isArray(variants) ? variants : [variants];
|
|
17
|
+
return variantArray.reduce((acc, variant) => {
|
|
18
|
+
const key = keyMap[variant];
|
|
19
|
+
if (key) {
|
|
20
|
+
acc[key] = true;
|
|
21
|
+
}
|
|
22
|
+
return acc;
|
|
23
|
+
}, {});
|
|
24
|
+
}
|
|
25
|
+
export default applyVariants;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { ButtonClassNames } from '../../components/buttons/Button';
|
|
2
|
+
import type { TextButtonClassNames } from '../../components/buttons/TextButton';
|
|
3
|
+
import type { DataTableClassNames } from '../../components/collections/DataTable';
|
|
4
|
+
import type { EmptyMessageClassNames } from '../../components/collections/EmptyMessage';
|
|
5
|
+
import type { ListClassNames } from '../../components/collections/List';
|
|
6
|
+
import type { ListItemClassNames } from '../../components/collections/ListItem';
|
|
7
|
+
import type { ListItemMetaClassNames } from '../../components/collections/ListItemMeta';
|
|
8
|
+
import type { PaginationClassNames } from '../../components/collections/Pagination';
|
|
9
|
+
import type { TableClassNames } from '../../components/collections/Table';
|
|
10
|
+
import type { AppErrorClassNames } from '../../components/errors/AppError';
|
|
11
|
+
import type { ModalClassNames } from '../../components/modals/Modal';
|
|
12
|
+
import type { ActionListClassNames } from '../../components/utility/ActionList';
|
|
13
|
+
import type { ContainerClassNames } from '../../components/utility/Container';
|
|
14
|
+
import type { LinkClassNames } from '../../components/utility/Link';
|
|
15
|
+
import type { LoaderClassNames } from '../../components/utility/Loader';
|
|
16
|
+
import type { PopoverClassNames } from '../../components/utility/Popover';
|
|
17
|
+
import type { ReferenceClassNames } from '../../components/utility/Reference';
|
|
18
|
+
import type { RootLayoutClassNames } from '../../components/utility/RootLayout';
|
|
19
|
+
import type { ToastClassNames } from '../../components/utility/Toast';
|
|
20
|
+
import type { FilterBarClassNames } from '../../filters/components/FilterBar';
|
|
21
|
+
import type { FilterItemClassNames } from '../../filters/components/FilterItem';
|
|
22
|
+
import type { FilterPanelClassNames } from '../../filters/components/FilterPanel';
|
|
23
|
+
import type { DropdownClassNames } from '../../forms/components/Dropdown';
|
|
24
|
+
import type { EditableFormClassNames } from '../../forms/components/EditableForm';
|
|
25
|
+
import type { EditableFormFieldClassNames } from '../../forms/components/EditableFormField';
|
|
26
|
+
import type { FormClassNames } from '../../forms/components/Form';
|
|
27
|
+
import type { FormFieldClassNames } from '../../forms/components/FormField';
|
|
28
|
+
import type { PasswordInputClassNames } from '../../forms/components/PasswordInput';
|
|
29
|
+
import type { StaticTextInputClassNames } from '../../forms/components/StaticTextInput';
|
|
30
|
+
import type { SwitchClassNames } from '../../forms/components/Switch';
|
|
31
|
+
import type { TextInputClassNames } from '../../forms/components/TextInput';
|
|
32
|
+
import type { AppNavigationClassNames } from '../../navigation/components/AppNavigation';
|
|
33
|
+
import type { TabsClassNames } from '../../navigation/components/Tabs';
|
|
34
|
+
import type { ComponentClassNames } from './interfaces';
|
|
35
|
+
export interface RegisteredClassNames {
|
|
36
|
+
actionList?: ComponentClassNames<ActionListClassNames>;
|
|
37
|
+
appError?: ComponentClassNames<AppErrorClassNames>;
|
|
38
|
+
appNavigation?: ComponentClassNames<AppNavigationClassNames>;
|
|
39
|
+
button?: ComponentClassNames<ButtonClassNames>;
|
|
40
|
+
container?: ComponentClassNames<ContainerClassNames>;
|
|
41
|
+
dataTable?: ComponentClassNames<DataTableClassNames>;
|
|
42
|
+
dropdown?: ComponentClassNames<DropdownClassNames>;
|
|
43
|
+
editableForm?: ComponentClassNames<EditableFormClassNames>;
|
|
44
|
+
editableFormField?: ComponentClassNames<EditableFormFieldClassNames>;
|
|
45
|
+
emptyMessage?: ComponentClassNames<EmptyMessageClassNames>;
|
|
46
|
+
filterBar?: ComponentClassNames<FilterBarClassNames>;
|
|
47
|
+
filterItem?: ComponentClassNames<FilterItemClassNames>;
|
|
48
|
+
filterPanel?: ComponentClassNames<FilterPanelClassNames>;
|
|
49
|
+
form?: ComponentClassNames<FormClassNames>;
|
|
50
|
+
formField?: ComponentClassNames<FormFieldClassNames>;
|
|
51
|
+
link?: ComponentClassNames<LinkClassNames>;
|
|
52
|
+
list?: ComponentClassNames<ListClassNames>;
|
|
53
|
+
listItem?: ComponentClassNames<ListItemClassNames>;
|
|
54
|
+
listItemMeta?: ComponentClassNames<ListItemMetaClassNames>;
|
|
55
|
+
loader?: ComponentClassNames<LoaderClassNames>;
|
|
56
|
+
modal?: ComponentClassNames<ModalClassNames>;
|
|
57
|
+
pagination?: ComponentClassNames<PaginationClassNames>;
|
|
58
|
+
passwordInput?: ComponentClassNames<PasswordInputClassNames>;
|
|
59
|
+
popover?: ComponentClassNames<PopoverClassNames>;
|
|
60
|
+
reference?: ComponentClassNames<ReferenceClassNames>;
|
|
61
|
+
rootLayout?: ComponentClassNames<RootLayoutClassNames>;
|
|
62
|
+
staticTextInput?: ComponentClassNames<StaticTextInputClassNames>;
|
|
63
|
+
switch?: ComponentClassNames<SwitchClassNames>;
|
|
64
|
+
table?: ComponentClassNames<TableClassNames>;
|
|
65
|
+
tabs?: ComponentClassNames<TabsClassNames>;
|
|
66
|
+
textButton?: ComponentClassNames<TextButtonClassNames>;
|
|
67
|
+
textInput?: ComponentClassNames<TextInputClassNames>;
|
|
68
|
+
toast?: ComponentClassNames<ToastClassNames>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RegisteredClassNames } from './config';
|
|
2
|
+
import type { ExtractClassNames } from './interfaces';
|
|
3
|
+
export declare function registerClassNames(data: RegisteredClassNames): void;
|
|
4
|
+
export declare function getClassNames<K extends keyof RegisteredClassNames>(component: K, config?: {
|
|
5
|
+
props?: Record<string, boolean>;
|
|
6
|
+
states?: Record<string, boolean>;
|
|
7
|
+
}, overrides?: RegisteredClassNames[K]): ExtractClassNames<RegisteredClassNames[K]>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getEntries } from '@sqrzro/utility';
|
|
2
|
+
import tw from './tw';
|
|
3
|
+
import isClassNameObject from './utility/is-classname-object';
|
|
4
|
+
let registeredClassNames = {};
|
|
5
|
+
export function registerClassNames(data) {
|
|
6
|
+
registeredClassNames = { ...registeredClassNames, ...data };
|
|
7
|
+
}
|
|
8
|
+
export function getClassNames(component, config, overrides) {
|
|
9
|
+
const componentClassNames = registeredClassNames[component];
|
|
10
|
+
if (!componentClassNames) {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
const overridden = { ...componentClassNames, ...overrides };
|
|
14
|
+
return getEntries(overridden).reduce((acc, [key, value]) => {
|
|
15
|
+
if (typeof value === 'string') {
|
|
16
|
+
return { ...acc, [key]: value };
|
|
17
|
+
}
|
|
18
|
+
if (isClassNameObject(value)) {
|
|
19
|
+
const { default: defaultClassName, props, states } = value;
|
|
20
|
+
const propClassNames = props
|
|
21
|
+
? Object.keys(props)
|
|
22
|
+
.filter((key) => config?.props?.[key])
|
|
23
|
+
.map((key) => props[key])
|
|
24
|
+
: [];
|
|
25
|
+
const stateClassNames = states
|
|
26
|
+
? Object.keys(states)
|
|
27
|
+
.filter((key) => config?.states?.[key])
|
|
28
|
+
.map((key) => states[key])
|
|
29
|
+
: [];
|
|
30
|
+
return {
|
|
31
|
+
...acc,
|
|
32
|
+
[key]: tw(defaultClassName, ...propClassNames, ...stateClassNames),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return acc;
|
|
36
|
+
}, {});
|
|
37
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
type ComponentClassNamesValue<T> = T extends string ? string | StatefulClassName : T extends StatefulClassName<infer U> ? StatefulClassName<U> : never;
|
|
2
|
+
export type ComponentClassNames<T> = {
|
|
3
|
+
[K in keyof T]?: ComponentClassNamesValue<T[K]>;
|
|
4
|
+
};
|
|
5
|
+
export type ExtractClassNames<T> = {
|
|
6
|
+
[K in keyof T]?: string;
|
|
7
|
+
};
|
|
8
|
+
export interface ClassNameObject {
|
|
9
|
+
default: string;
|
|
10
|
+
props?: Record<string, string>;
|
|
11
|
+
states?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
export interface ClassNameProps<T> {
|
|
14
|
+
classNames?: Partial<T>;
|
|
15
|
+
classNameProps?: Record<string, boolean>;
|
|
16
|
+
}
|
|
17
|
+
interface StatefulClassName<T = null> {
|
|
18
|
+
default: string;
|
|
19
|
+
props?: Record<string, string>;
|
|
20
|
+
states?: T;
|
|
21
|
+
}
|
|
22
|
+
export type CheckableClassName = string | StatefulClassName<{
|
|
23
|
+
isChecked?: string;
|
|
24
|
+
}>;
|
|
25
|
+
export type ErrorableClassName = string | StatefulClassName<{
|
|
26
|
+
isError?: string;
|
|
27
|
+
}>;
|
|
28
|
+
export type FocusableClassName = string | StatefulClassName<{
|
|
29
|
+
isFocused?: string;
|
|
30
|
+
}>;
|
|
31
|
+
export type HighlightableClassName = string | StatefulClassName<{
|
|
32
|
+
isHighlighted?: string;
|
|
33
|
+
}>;
|
|
34
|
+
export type LoadableClassName = string | StatefulClassName<{
|
|
35
|
+
isLoading?: string;
|
|
36
|
+
}>;
|
|
37
|
+
export type SelectableClassName = string | StatefulClassName<{
|
|
38
|
+
isSelected?: string;
|
|
39
|
+
}>;
|
|
40
|
+
export type SizableClassName = string | StatefulClassName<{
|
|
41
|
+
isLarge?: string;
|
|
42
|
+
isMedium?: string;
|
|
43
|
+
isSmall?: string;
|
|
44
|
+
}>;
|
|
45
|
+
export type StylableClassName = string | StatefulClassName<{
|
|
46
|
+
isBordered?: string;
|
|
47
|
+
isDanger?: string;
|
|
48
|
+
isError?: string;
|
|
49
|
+
isInfo?: string;
|
|
50
|
+
isPrimary?: string;
|
|
51
|
+
isSecondary?: string;
|
|
52
|
+
isSuccess?: string;
|
|
53
|
+
isTertiary?: string;
|
|
54
|
+
isWarning?: string;
|
|
55
|
+
}>;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IconComponent } from './interfaces';
|
|
2
|
+
export interface RegisteredIcons {
|
|
3
|
+
'collection.empty'?: IconComponent;
|
|
4
|
+
'filter.panel'?: IconComponent;
|
|
5
|
+
'filter.search'?: IconComponent;
|
|
6
|
+
password?: IconComponent;
|
|
7
|
+
'utility.success'?: IconComponent;
|
|
8
|
+
'utility.error'?: IconComponent;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/styles/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { RegisteredClassNames } from './config';
|
|
2
|
-
export { default as tw, twx } from './tw';
|
|
1
|
+
export type { RegisteredClassNames } from './classnames/config';
|
|
2
|
+
export { default as tw, twx } from './classnames/tw';
|
package/dist/styles/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as tw, twx } from './tw';
|
|
1
|
+
export { default as tw, twx } from './classnames/tw';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
@theme {
|
|
2
|
+
/* These are defaults that will (probably) be overwritten by the consuming application */
|
|
3
|
+
--color-primary: var(--color-teal-600);
|
|
4
|
+
--color-primary-dark: var(--color-teal-700);
|
|
5
|
+
--color-on-primary: var(--color-white);
|
|
6
|
+
/* End defaults */
|
|
7
|
+
|
|
8
|
+
--color-button-bg: var(--color-primary);
|
|
9
|
+
--color-button-bg-hover: var(--color-primary-dark);
|
|
10
|
+
--color-button-text: var(--color-on-primary);
|
|
11
|
+
--color-link: var(--color-primary);
|
|
12
|
+
--color-panel: var(--color-white);
|
|
13
|
+
|
|
14
|
+
--color-error: var(--color-red-600);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@layer base {
|
|
18
|
+
button {
|
|
19
|
+
@apply cursor-pointer;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
hr {
|
|
23
|
+
@apply border-slate-200;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
input::-webkit-inner-spin-button {
|
|
27
|
+
@apply appearance-none m-0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
input[type=number] {
|
|
31
|
+
-moz-appearance: textfield;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
small {
|
|
35
|
+
@apply text-xs;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
strong {
|
|
39
|
+
@apply font-semibold;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@layer utilities {
|
|
44
|
+
.fade-closed {
|
|
45
|
+
@apply invisible opacity-0 ease-in-out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.fade-open {
|
|
49
|
+
@apply transition-discrete transition-all duration-100 starting:opacity-0 visible opacity-100;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.show-closed {
|
|
53
|
+
@apply invisible opacity-0 ease-in-out scale-90;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.show-open {
|
|
57
|
+
@apply transition-discrete transition-all duration-100 starting:opacity-0 starting:scale-90 visible opacity-100 scale-100;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
export interface ConfirmableObject {
|
|
2
|
-
actions?: Omit<
|
|
2
|
+
actions?: Omit<ActionObject, 'confirmable'>[];
|
|
3
3
|
confirmText?: string;
|
|
4
4
|
description?: React.ReactNode;
|
|
5
5
|
icon?: React.ReactNode;
|
|
6
6
|
isLoading?: boolean;
|
|
7
7
|
modalIcon?: React.ReactNode;
|
|
8
8
|
onBeforeConfirm?: () => void;
|
|
9
|
-
onConfirm
|
|
9
|
+
onConfirm?: () => void;
|
|
10
|
+
onSuccess?: () => Promise<void> | void;
|
|
11
|
+
redirectOnSuccess?: string | false | ((response: Response) => string | false);
|
|
12
|
+
refreshOnSuccess?: boolean;
|
|
10
13
|
submitLabel?: string;
|
|
11
|
-
title?:
|
|
14
|
+
title?: React.ReactNode;
|
|
12
15
|
}
|
|
13
|
-
export
|
|
14
|
-
|
|
16
|
+
export type ActionEvent = React.MouseEvent<HTMLAnchorElement> | React.MouseEvent<HTMLButtonElement>;
|
|
17
|
+
export interface ActionObject<Data extends object | null = null> {
|
|
18
|
+
action?: (data: Data) => Promise<void>;
|
|
15
19
|
confirmable?: ConfirmableObject;
|
|
20
|
+
data?: Data;
|
|
16
21
|
details?: React.ReactNode;
|
|
17
22
|
href?: string;
|
|
18
23
|
icon?: React.ReactNode;
|
|
@@ -20,8 +25,9 @@ export interface Action {
|
|
|
20
25
|
isLoading?: boolean;
|
|
21
26
|
isSubmittable?: boolean;
|
|
22
27
|
label: React.ReactNode;
|
|
23
|
-
onClick?: () => void;
|
|
24
|
-
|
|
28
|
+
onClick?: (event?: ActionEvent) => void;
|
|
29
|
+
searchParams?: Record<string, string>;
|
|
30
|
+
variant?: StyleVariant[] | StyleVariant;
|
|
25
31
|
}
|
|
26
32
|
export interface NextLayoutProps {
|
|
27
33
|
children: React.ReactNode;
|
|
@@ -31,5 +37,10 @@ export interface NextPageProps {
|
|
|
31
37
|
params?: Promise<Record<string, string>> | null;
|
|
32
38
|
searchParams?: Promise<Record<string, string>> | null;
|
|
33
39
|
}
|
|
40
|
+
export type ReferenceObject = {
|
|
41
|
+
id?: string;
|
|
42
|
+
name: string;
|
|
43
|
+
path?: string;
|
|
44
|
+
reference?: string;
|
|
45
|
+
};
|
|
34
46
|
export type StyleVariant = 'bordered' | 'danger' | 'error' | 'info' | 'primary' | 'secondary' | 'success' | 'tertiary' | 'warning';
|
|
35
|
-
export type ButtonVariant = StyleVariant | 'link';
|