@sqrzro/ui 4.0.0-alpha.7 → 4.0.0-alpha.71
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 +8 -6
- package/dist/components/buttons/ActionButton/index.js +3 -27
- package/dist/components/buttons/Button/index.d.ts +7 -6
- package/dist/components/buttons/Button/index.js +9 -19
- package/dist/components/collections/Collection/index.d.ts +7 -3
- package/dist/components/collections/Collection/index.js +9 -7
- package/dist/components/collections/DataTable/index.d.ts +14 -0
- package/dist/components/collections/DataTable/index.js +14 -0
- package/dist/components/collections/DefinitionList/index.d.ts +13 -0
- package/dist/components/collections/DefinitionList/index.js +13 -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 -3
- 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 -17
- package/dist/components/collections/ListItemSecondary/index.d.ts +5 -3
- package/dist/components/collections/ListItemSecondary/index.js +12 -8
- 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 +3 -4
- 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/lang.js +1 -1
- package/dist/components/collections/utility/is-paginated.d.ts +1 -1
- 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/ContentLink/index.d.ts +4 -0
- package/dist/components/elements/ContentLink/index.js +7 -0
- package/dist/components/elements/InfoPanel/index.d.ts +13 -0
- package/dist/components/elements/InfoPanel/index.js +20 -0
- package/dist/components/{utility → elements}/Link/index.d.ts +3 -2
- package/dist/components/{utility → elements}/Link/index.js +10 -9
- 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 +9 -0
- package/dist/components/elements/MenuItem/index.js +14 -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 +35 -6
- package/dist/components/index.js +17 -3
- 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 +66 -0
- package/dist/components/utility/CalendarDay/index.d.ts +11 -0
- package/dist/components/utility/CalendarDay/index.js +22 -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 +2 -2
- package/dist/filters/utility/render-value.js +5 -5
- package/dist/forms/components/Autocomplete/index.d.ts +2 -2
- package/dist/forms/components/Autocomplete/index.js +3 -3
- package/dist/forms/components/AutocompleteList/index.d.ts +7 -0
- package/dist/forms/components/AutocompleteList/index.js +15 -0
- package/dist/forms/components/BaseCalendarInput/index.d.ts +11 -0
- package/dist/forms/components/BaseCalendarInput/index.js +22 -0
- package/dist/forms/components/CSVInput/index.d.ts +11 -0
- package/dist/forms/components/CSVInput/index.js +32 -0
- package/dist/forms/components/CalendarInput/index.d.ts +6 -0
- package/dist/forms/components/CalendarInput/index.js +14 -0
- package/dist/forms/components/ColorInput/index.d.ts +16 -0
- package/dist/forms/components/ColorInput/index.js +14 -0
- package/dist/forms/components/Dropdown/index.d.ts +1 -1
- package/dist/forms/components/Dropdown/index.js +9 -8
- 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 -11
- 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 +12 -0
- package/dist/forms/components/EditableFormFields/index.js +44 -1
- package/dist/forms/components/Form/index.d.ts +4 -2
- package/dist/forms/components/Form/index.js +7 -6
- package/dist/forms/components/FormError/index.d.ts +2 -2
- package/dist/forms/components/FormError/index.js +7 -5
- package/dist/forms/components/FormField/index.d.ts +7 -5
- package/dist/forms/components/FormField/index.js +15 -7
- package/dist/forms/components/FormFields/index.d.ts +22 -2
- package/dist/forms/components/FormFields/index.js +44 -2
- package/dist/forms/components/FormLabel/index.d.ts +1 -1
- package/dist/forms/components/FormLabel/index.js +4 -3
- package/dist/forms/components/ImageInput/index.d.ts +17 -0
- package/dist/forms/components/ImageInput/index.js +46 -0
- package/dist/forms/components/ImageInputPanel/index.d.ts +10 -0
- package/dist/forms/components/ImageInputPanel/index.js +34 -0
- package/dist/forms/components/ModalForm/index.d.ts +3 -2
- package/dist/forms/components/ModalForm/index.js +5 -4
- package/dist/forms/components/NumberInput/index.d.ts +1 -1
- 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/{MoneyInput → PointsInput}/index.js +3 -3
- package/dist/forms/components/RangeCalendarInput/index.d.ts +6 -0
- package/dist/forms/components/RangeCalendarInput/index.js +14 -0
- package/dist/forms/components/StaticTextInput/index.d.ts +2 -2
- package/dist/forms/components/StaticTextInput/index.js +6 -7
- package/dist/forms/components/Switch/index.d.ts +9 -3
- package/dist/forms/components/Switch/index.js +7 -5
- 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 +1 -1
- package/dist/forms/components/TextInput/index.js +5 -4
- package/dist/forms/hooks/useAutocomplete.d.ts +8 -6
- package/dist/forms/hooks/useAutocomplete.js +4 -4
- package/dist/forms/hooks/useDropdown.d.ts +5 -7
- package/dist/forms/hooks/useDropdown.js +5 -5
- package/dist/forms/hooks/useEditableDropdown.d.ts +4 -0
- package/dist/forms/hooks/useEditableDropdown.js +6 -0
- package/dist/forms/hooks/useEditableForm.js +8 -1
- package/dist/forms/hooks/useForm.d.ts +7 -14
- package/dist/forms/hooks/useForm.js +25 -27
- package/dist/forms/hooks/useModalForm.d.ts +2 -2
- package/dist/forms/hooks/useModalForm.js +9 -2
- package/dist/forms/index.d.ts +22 -6
- package/dist/forms/index.js +9 -4
- package/dist/forms/interfaces.d.ts +8 -1
- package/dist/forms/utility/extract-input-props.js +1 -0
- package/dist/forms/utility/format-date-value.d.ts +2 -0
- package/dist/forms/utility/format-date-value.js +13 -0
- package/dist/forms/utility/format-file-size.d.ts +2 -0
- package/dist/forms/utility/format-file-size.js +11 -0
- package/dist/forms/utility/preprocess-image.d.ts +6 -0
- package/dist/forms/utility/preprocess-image.js +58 -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/mail/Mail/index.d.ts +8 -0
- package/dist/mail/Mail/index.js +108 -0
- package/dist/mail/MailBlock/index.d.ts +5 -0
- package/dist/mail/MailBlock/index.js +5 -0
- package/dist/mail/MailButton/index.d.ts +8 -0
- package/dist/mail/MailButton/index.js +28 -0
- package/dist/mail/MailTable/index.d.ts +9 -0
- package/dist/mail/MailTable/index.js +7 -0
- package/dist/mail/index.d.ts +8 -0
- package/dist/mail/index.js +4 -0
- package/dist/mail/utility/convert-to-datauri.d.ts +2 -0
- package/dist/mail/utility/convert-to-datauri.js +37 -0
- package/dist/mail/utility/interfaces.d.ts +23 -0
- package/dist/mail/utility/mail-config.d.ts +4 -0
- package/dist/mail/utility/mail-config.js +42 -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 +93 -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 +28 -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/get-date-state.d.ts +8 -0
- package/dist/utility/get-date-state.js +63 -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/package.json +34 -22
- 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 -15
- package/dist/components/utility/RootLayout/index.js +0 -14
- package/dist/forms/components/MoneyInput/index.d.ts +0 -5
- 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 → mail/utility}/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,21 @@
|
|
|
1
|
+
import type { ActionEvent } from '../utility/interfaces';
|
|
2
|
+
interface UseConfirmableArgs {
|
|
3
|
+
isLoading?: boolean;
|
|
4
|
+
onBeforeConfirm?: () => void;
|
|
5
|
+
onConfirm: (event: ActionEvent, currentRef: HTMLButtonElement | null) => void;
|
|
6
|
+
onSuccess?: () => Promise<void> | void;
|
|
7
|
+
redirectOnSuccess?: string | false | ((response: Response) => string | false);
|
|
8
|
+
refreshOnSuccess?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface UseConfirmableReturn {
|
|
11
|
+
handle: (event?: ActionEvent) => void;
|
|
12
|
+
isOpen: boolean;
|
|
13
|
+
modalProps: {
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
onCancel: () => void;
|
|
16
|
+
onConfirm: () => void;
|
|
17
|
+
};
|
|
18
|
+
ref: React.RefObject<HTMLButtonElement | null>;
|
|
19
|
+
}
|
|
20
|
+
declare function useConfirmable({ isLoading, onBeforeConfirm, onConfirm, onSuccess, redirectOnSuccess, refreshOnSuccess, }: Readonly<UseConfirmableArgs>): UseConfirmableReturn;
|
|
21
|
+
export default useConfirmable;
|
|
@@ -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,18 @@
|
|
|
1
|
+
function download(data, filename) {
|
|
2
|
+
const href = typeof data === 'string' ? data : URL.createObjectURL(data);
|
|
3
|
+
// Create a temporary link element to trigger the download
|
|
4
|
+
const link = document.createElement('a');
|
|
5
|
+
link.href = href;
|
|
6
|
+
link.download = filename;
|
|
7
|
+
document.body.appendChild(link);
|
|
8
|
+
link.click();
|
|
9
|
+
// Clean up
|
|
10
|
+
document.body.removeChild(link);
|
|
11
|
+
if (typeof data !== 'string') {
|
|
12
|
+
URL.revokeObjectURL(href);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function useDownload() {
|
|
16
|
+
return download;
|
|
17
|
+
}
|
|
18
|
+
export default useDownload;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface UsePopoverReturn<T extends HTMLElement = HTMLElement> {
|
|
2
|
+
controlProps: {
|
|
3
|
+
onClick: () => void;
|
|
4
|
+
};
|
|
5
|
+
isOpen: boolean;
|
|
6
|
+
ref: React.RefObject<T | null>;
|
|
7
|
+
targetProps: {
|
|
8
|
+
isOpen: boolean;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
declare function usePopover<T extends HTMLElement = HTMLElement>(): UsePopoverReturn<T>;
|
|
12
|
+
export default usePopover;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import useClickOutside from './useClickOutside';
|
|
3
|
+
import { usePathname } from 'next/navigation';
|
|
4
|
+
function usePopover() {
|
|
5
|
+
const pathname = usePathname();
|
|
6
|
+
const [isOpen, setIsOpen, ref] = useClickOutside();
|
|
7
|
+
function toggleIsOpen() {
|
|
8
|
+
setIsOpen(!isOpen);
|
|
9
|
+
}
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
setIsOpen(false);
|
|
12
|
+
}, [pathname]);
|
|
13
|
+
return {
|
|
14
|
+
controlProps: {
|
|
15
|
+
onClick: toggleIsOpen,
|
|
16
|
+
},
|
|
17
|
+
isOpen,
|
|
18
|
+
ref,
|
|
19
|
+
targetProps: {
|
|
20
|
+
isOpen,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export default usePopover;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InputEvent } from '../forms/interfaces';
|
|
2
|
+
interface UseSelectedReturn {
|
|
3
|
+
checkSelected: (id: string) => boolean;
|
|
4
|
+
isAllSelected: boolean;
|
|
5
|
+
onSelect: (event: InputEvent<boolean>) => void;
|
|
6
|
+
onSelectAll: () => void;
|
|
7
|
+
selected: string[];
|
|
8
|
+
}
|
|
9
|
+
declare function useSelected(data: {
|
|
10
|
+
id: string;
|
|
11
|
+
}[]): UseSelectedReturn;
|
|
12
|
+
export default useSelected;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { toggleArrayItem } from '@sqrzro/utility';
|
|
2
|
+
import { useSearchParams } from 'next/navigation';
|
|
3
|
+
import useSearchParamsHref from './useSearchParamsHref';
|
|
4
|
+
function getSelectedFromSearchParams(searchParams) {
|
|
5
|
+
const selected = searchParams.get('selected');
|
|
6
|
+
return selected ? selected.split('|') : [];
|
|
7
|
+
}
|
|
8
|
+
function setSelectedToSearchParams(selected) {
|
|
9
|
+
return selected.length ? selected.join('|') : null;
|
|
10
|
+
}
|
|
11
|
+
function useSelected(data) {
|
|
12
|
+
const { setSearchParamsHref } = useSearchParamsHref();
|
|
13
|
+
const searchParams = useSearchParams();
|
|
14
|
+
const selected = getSelectedFromSearchParams(searchParams);
|
|
15
|
+
function onSelect(event) {
|
|
16
|
+
const value = toggleArrayItem(selected, event.target.name);
|
|
17
|
+
setSearchParamsHref({ selected: setSelectedToSearchParams(value) });
|
|
18
|
+
}
|
|
19
|
+
function onSelectAll() {
|
|
20
|
+
const value = selected.length === data.length ? [] : data.map((item) => item.id);
|
|
21
|
+
setSearchParamsHref({ selected: setSelectedToSearchParams(value) });
|
|
22
|
+
}
|
|
23
|
+
const isAllSelected = data.length > 0 && selected.length === data.length;
|
|
24
|
+
function checkSelected(id) {
|
|
25
|
+
return selected.includes(id);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
checkSelected,
|
|
29
|
+
isAllSelected,
|
|
30
|
+
onSelect,
|
|
31
|
+
onSelectAll,
|
|
32
|
+
selected,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export default useSelected;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { UseSuccessArgs } from './useSuccess';
|
|
2
|
+
interface UseServerActionArgs<Response> extends UseSuccessArgs<Response> {
|
|
3
|
+
onSuccess?: (response: Response) => void;
|
|
4
|
+
}
|
|
5
|
+
interface UseServerActionReturn {
|
|
6
|
+
handleClick: () => void;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare function useServerAction<Response>(fn?: () => Promise<Response>, args?: UseServerActionArgs<Response>): UseServerActionReturn;
|
|
10
|
+
export default useServerAction;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useTransition } from 'react';
|
|
2
|
+
import useSuccess from './useSuccess';
|
|
3
|
+
function useServerAction(fn, args = {}) {
|
|
4
|
+
const { handleSuccess } = useSuccess(args);
|
|
5
|
+
const [isLoading, startTransition] = useTransition();
|
|
6
|
+
function handleClick() {
|
|
7
|
+
startTransition(async () => {
|
|
8
|
+
if (!fn) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const response = await fn();
|
|
12
|
+
await handleSuccess(response);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return { handleClick, isLoading };
|
|
16
|
+
}
|
|
17
|
+
export default useServerAction;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface UseSuccessArgs<Response> {
|
|
2
|
+
onSuccess?: (response: Response) => Promise<void> | void;
|
|
3
|
+
redirectOnSuccess?: string | false | ((response: Response) => Promise<string | false> | string | false);
|
|
4
|
+
refreshOnSuccess?: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface UseSuccessReturn<Response> {
|
|
7
|
+
handleSuccess: (response: Response) => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
declare function useSuccess<Response>({ onSuccess, redirectOnSuccess, refreshOnSuccess, }: UseSuccessArgs<Response>): UseSuccessReturn<Response>;
|
|
10
|
+
export default useSuccess;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useRouter } from 'next/navigation';
|
|
2
|
+
function useSuccess({ onSuccess, redirectOnSuccess, refreshOnSuccess, }) {
|
|
3
|
+
const router = useRouter();
|
|
4
|
+
async function handleSuccess(response) {
|
|
5
|
+
if (onSuccess) {
|
|
6
|
+
await onSuccess(response);
|
|
7
|
+
}
|
|
8
|
+
if (redirectOnSuccess) {
|
|
9
|
+
const url = typeof redirectOnSuccess === 'function'
|
|
10
|
+
? await redirectOnSuccess(response)
|
|
11
|
+
: redirectOnSuccess;
|
|
12
|
+
if (url) {
|
|
13
|
+
router.push(url);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else if (refreshOnSuccess) {
|
|
17
|
+
router.refresh();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return { handleSuccess };
|
|
21
|
+
}
|
|
22
|
+
export default useSuccess;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DeepPartial } from '@sqrzro/utility';
|
|
2
|
+
import { MailConfigObject } from '../utility/interfaces';
|
|
3
|
+
export interface MailProps extends DeepPartial<MailConfigObject> {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
title?: string;
|
|
6
|
+
}
|
|
7
|
+
declare function Mail({ children, logo, styles, title, }: Readonly<MailProps>): Promise<React.ReactElement>;
|
|
8
|
+
export default Mail;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Fragment } from 'react';
|
|
4
|
+
import { setMailConfig } from '../utility/mail-config';
|
|
5
|
+
const HALF = 2;
|
|
6
|
+
async function Mail({ children, logo, styles, title, }) {
|
|
7
|
+
const mailConfig = setMailConfig({ styles });
|
|
8
|
+
const logoData = await (await import('../utility/convert-to-datauri')).default(logo ?? mailConfig.logo ?? '');
|
|
9
|
+
return (_jsxs("html", { lang: "en", children: [_jsxs("head", { children: [_jsx("meta", { charSet: "utf-8" }), _jsx("style", { dangerouslySetInnerHTML: {
|
|
10
|
+
__html: `
|
|
11
|
+
body {
|
|
12
|
+
color: #0f172b !important;
|
|
13
|
+
font-family: -apple-system, 'SF Pro Display', 'SF Pro Text', 'Helvetica', sans-serif;
|
|
14
|
+
font-size: 16px;
|
|
15
|
+
font-weight:400;
|
|
16
|
+
line-height: 24px;
|
|
17
|
+
margin: 0;
|
|
18
|
+
padding: 0;
|
|
19
|
+
}
|
|
20
|
+
@media print {
|
|
21
|
+
body {
|
|
22
|
+
font-size: 14px !important;
|
|
23
|
+
line-height: 21px !important;
|
|
24
|
+
}
|
|
25
|
+
.container {
|
|
26
|
+
width: 100% !important;
|
|
27
|
+
}
|
|
28
|
+
.padding {
|
|
29
|
+
height: auto !important;
|
|
30
|
+
width: auto !important;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`,
|
|
34
|
+
} })] }), _jsx("body", { children: _jsx("table", { border: 0, cellPadding: 0, cellSpacing: 0, width: "100%", children: _jsxs("tbody", { children: [_jsx("tr", { children: _jsx("td", { className: "padding", colSpan: 3, height: "20", style: { backgroundColor: mailConfig.styles.root.backgroundColor } }) }), _jsxs("tr", { children: [_jsx("td", { className: "padding", style: { backgroundColor: mailConfig.styles.root.backgroundColor }, width: "20" }), _jsx("td", { align: "center", style: { backgroundColor: mailConfig.styles.root.backgroundColor }, children: _jsx("table", { border: 0, cellPadding: 0, cellSpacing: 0, className: "container", width: "650", children: _jsxs("tbody", { children: [_jsxs("tr", { children: [_jsx("td", { className: "padding", height: "20", style: {
|
|
35
|
+
backgroundColor: mailConfig.styles.panel.backgroundColor,
|
|
36
|
+
}, width: "20", children: _jsx("div", { className: "padding", style: {
|
|
37
|
+
backgroundColor: mailConfig.styles.root.backgroundColor,
|
|
38
|
+
height: mailConfig.styles.panel.padding,
|
|
39
|
+
width: mailConfig.styles.panel.padding,
|
|
40
|
+
}, children: _jsx("div", { className: "padding", style: {
|
|
41
|
+
backgroundColor: mailConfig.styles.panel
|
|
42
|
+
.backgroundColor,
|
|
43
|
+
borderTopLeftRadius: mailConfig.styles.panel.padding /
|
|
44
|
+
HALF,
|
|
45
|
+
height: mailConfig.styles.panel.padding,
|
|
46
|
+
width: mailConfig.styles.panel.padding,
|
|
47
|
+
} }) }) }), _jsx("td", { className: "container", style: {
|
|
48
|
+
backgroundColor: mailConfig.styles.panel.backgroundColor,
|
|
49
|
+
}, width: "610" }), _jsx("td", { className: "padding", height: mailConfig.styles.panel.padding, style: {
|
|
50
|
+
backgroundColor: mailConfig.styles.panel.backgroundColor,
|
|
51
|
+
}, width: mailConfig.styles.panel.padding, children: _jsx("div", { className: "padding", style: {
|
|
52
|
+
backgroundColor: mailConfig.styles.root.backgroundColor,
|
|
53
|
+
height: mailConfig.styles.panel.padding,
|
|
54
|
+
width: mailConfig.styles.panel.padding,
|
|
55
|
+
}, children: _jsx("div", { className: "padding", style: {
|
|
56
|
+
backgroundColor: mailConfig.styles.panel
|
|
57
|
+
.backgroundColor,
|
|
58
|
+
borderTopRightRadius: mailConfig.styles.panel.padding /
|
|
59
|
+
HALF,
|
|
60
|
+
height: mailConfig.styles.panel.padding,
|
|
61
|
+
width: mailConfig.styles.panel.padding,
|
|
62
|
+
} }) }) })] }), _jsxs("tr", { children: [_jsx("td", { className: "padding", style: {
|
|
63
|
+
backgroundColor: mailConfig.styles.panel.backgroundColor,
|
|
64
|
+
}, width: mailConfig.styles.panel.padding }), _jsx("td", { style: {
|
|
65
|
+
backgroundColor: mailConfig.styles.panel.backgroundColor,
|
|
66
|
+
}, children: _jsx("table", { border: 0, cellPadding: 0, cellSpacing: 0, width: "100%", children: _jsxs("tbody", { children: [logoData ? (_jsxs(Fragment, { children: [_jsx("tr", { children: _jsx("td", { children: _jsx("table", { border: 0, cellPadding: 0, cellSpacing: 0, width: 240, children: _jsx("tbody", { children: _jsx("tr", { children: _jsx("td", { children: _jsx("img", { alt: "Logo", src: logoData, width: 240 }) }) }) }) }) }) }), _jsx("tr", { children: _jsx("td", { height: mailConfig.styles.panel
|
|
67
|
+
.padding }) })] })) : null, title ? (_jsxs(Fragment, { children: [_jsx("tr", { children: _jsx("td", { style: {
|
|
68
|
+
color: mailConfig.styles
|
|
69
|
+
.title.color,
|
|
70
|
+
fontSize: mailConfig.styles
|
|
71
|
+
.title.fontSize,
|
|
72
|
+
fontWeight: mailConfig.styles
|
|
73
|
+
.title
|
|
74
|
+
.fontWeight,
|
|
75
|
+
}, children: title }) }), _jsx("tr", { children: _jsx("td", { height: mailConfig.styles.panel
|
|
76
|
+
.padding }) })] })) : null, _jsx("tr", { children: _jsx("td", { children: children }) })] }) }) }), _jsx("td", { className: "padding", style: {
|
|
77
|
+
backgroundColor: mailConfig.styles.panel.backgroundColor,
|
|
78
|
+
}, width: mailConfig.styles.panel.padding })] }), _jsxs("tr", { children: [_jsx("td", { className: "padding", height: mailConfig.styles.panel.padding, style: {
|
|
79
|
+
backgroundColor: mailConfig.styles.panel.backgroundColor,
|
|
80
|
+
}, width: mailConfig.styles.panel.padding, children: _jsx("div", { className: "padding", style: {
|
|
81
|
+
backgroundColor: mailConfig.styles.root.backgroundColor,
|
|
82
|
+
height: mailConfig.styles.panel.padding,
|
|
83
|
+
width: mailConfig.styles.panel.padding,
|
|
84
|
+
}, children: _jsx("div", { className: "padding", style: {
|
|
85
|
+
backgroundColor: mailConfig.styles.panel
|
|
86
|
+
.backgroundColor,
|
|
87
|
+
borderBottomLeftRadius: mailConfig.styles.panel.padding /
|
|
88
|
+
HALF,
|
|
89
|
+
height: mailConfig.styles.panel.padding,
|
|
90
|
+
width: mailConfig.styles.panel.padding,
|
|
91
|
+
} }) }) }), _jsx("td", { className: "container", style: {
|
|
92
|
+
backgroundColor: mailConfig.styles.panel.backgroundColor,
|
|
93
|
+
}, width: "610" }), _jsx("td", { className: "padding", height: mailConfig.styles.panel.padding, style: {
|
|
94
|
+
backgroundColor: mailConfig.styles.panel.backgroundColor,
|
|
95
|
+
}, width: mailConfig.styles.panel.padding, children: _jsx("div", { className: "padding", style: {
|
|
96
|
+
backgroundColor: mailConfig.styles.root.backgroundColor,
|
|
97
|
+
height: mailConfig.styles.panel.padding,
|
|
98
|
+
width: mailConfig.styles.panel.padding,
|
|
99
|
+
}, children: _jsx("div", { className: "padding", style: {
|
|
100
|
+
backgroundColor: mailConfig.styles.panel
|
|
101
|
+
.backgroundColor,
|
|
102
|
+
borderBottomRightRadius: mailConfig.styles.panel.padding /
|
|
103
|
+
HALF,
|
|
104
|
+
height: mailConfig.styles.panel.padding,
|
|
105
|
+
width: mailConfig.styles.panel.padding,
|
|
106
|
+
} }) }) })] })] }) }) }), _jsx("td", { className: "padding", style: { backgroundColor: mailConfig.styles.root.backgroundColor }, width: "20" })] }), _jsx("tr", { children: _jsx("td", { className: "padding", colSpan: 3, height: "20", style: { backgroundColor: mailConfig.styles.root.backgroundColor } }) })] }) }) })] }));
|
|
107
|
+
}
|
|
108
|
+
export default Mail;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DeepPartial } from '@sqrzro/utility';
|
|
2
|
+
import { MailConfigObject } from '../utility/interfaces';
|
|
3
|
+
export interface MailButtonProps extends DeepPartial<MailConfigObject> {
|
|
4
|
+
children: string;
|
|
5
|
+
href: string;
|
|
6
|
+
}
|
|
7
|
+
declare function MailButton({ children, href, styles, }: MailButtonProps): Promise<React.ReactElement>;
|
|
8
|
+
export default MailButton;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { getMailConfig } from '../utility/mail-config';
|
|
4
|
+
function calculateWidth(text) {
|
|
5
|
+
const characterWidth = 8;
|
|
6
|
+
const padding = 50;
|
|
7
|
+
return text.length * characterWidth + padding;
|
|
8
|
+
}
|
|
9
|
+
async function MailButton({ children, href, styles, }) {
|
|
10
|
+
const mailConfig = getMailConfig({ styles });
|
|
11
|
+
const calculatedWidth = calculateWidth(children);
|
|
12
|
+
return (_jsx("div", { dangerouslySetInnerHTML: {
|
|
13
|
+
__html: `
|
|
14
|
+
<!--[if mso]>
|
|
15
|
+
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="${href}" style="height:${mailConfig.styles.button.height}px;v-text-anchor:middle;width:${calculatedWidth}px;" arcsize="50%" stroke="f" fillcolor="${mailConfig.styles.button.backgroundColor}">
|
|
16
|
+
<w:anchorlock/>
|
|
17
|
+
<center>
|
|
18
|
+
<![endif]-->
|
|
19
|
+
<a href="${href}"
|
|
20
|
+
style="background-color:${mailConfig.styles.button.backgroundColor};border-radius:${mailConfig.styles.button.borderRadius}px;color:${mailConfig.styles.button.color};display:inline-block;font-weight:bold;line-height:${mailConfig.styles.button.height}px;text-align:center;text-decoration:none;width:${calculatedWidth}px;-webkit-text-size-adjust:none;">${children}</a>
|
|
21
|
+
<!--[if mso]>
|
|
22
|
+
</center>
|
|
23
|
+
</v:roundrect>
|
|
24
|
+
<![endif]-->
|
|
25
|
+
`,
|
|
26
|
+
} }));
|
|
27
|
+
}
|
|
28
|
+
export default MailButton;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment } from 'react';
|
|
3
|
+
const EVEN_NUMBER = 2;
|
|
4
|
+
function MailTable({ data }) {
|
|
5
|
+
return (_jsx("table", { border: 0, cellPadding: 0, cellSpacing: 0, style: { marginBottom: 30 }, width: "100%", children: _jsxs("tbody", { children: [data.map(({ title, value }, index) => (_jsxs(Fragment, { children: [_jsx("tr", { children: _jsx("td", { colSpan: 5, height: 1, style: { backgroundColor: '#cccccc' } }) }), _jsx("tr", { children: _jsx("td", { colSpan: 5, height: 10, style: { backgroundColor: index % EVEN_NUMBER ? '' : '#f7f7f7' } }) }), _jsxs("tr", { children: [_jsx("td", { style: { backgroundColor: index % EVEN_NUMBER ? '' : '#f7f7f7' }, width: 10 }), _jsx("td", { style: { backgroundColor: index % EVEN_NUMBER ? '' : '#f7f7f7' }, children: title }), _jsx("td", { style: { backgroundColor: index % EVEN_NUMBER ? '' : '#f7f7f7' }, width: 20 }), _jsx("td", { align: "right", style: { backgroundColor: index % EVEN_NUMBER ? '' : '#f7f7f7' }, children: value }), _jsx("td", { style: { backgroundColor: index % EVEN_NUMBER ? '' : '#f7f7f7' }, width: 10 })] }), _jsx("tr", { children: _jsx("td", { colSpan: 5, height: 10, style: { backgroundColor: index % EVEN_NUMBER ? '' : '#f7f7f7' } }) })] }, index))), _jsx("tr", { children: _jsx("td", { colSpan: 5, height: 1, style: { backgroundColor: '#cccccc' } }) })] }) }));
|
|
6
|
+
}
|
|
7
|
+
export default MailTable;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { MailProps } from './Mail';
|
|
2
|
+
export { default as Mail } from './Mail';
|
|
3
|
+
export type { MailBlockProps } from './MailBlock';
|
|
4
|
+
export { default as MailBlock } from './MailBlock';
|
|
5
|
+
export type { MailButtonProps } from './MailButton';
|
|
6
|
+
export { default as MailButton } from './MailButton';
|
|
7
|
+
export type { MailTableProps } from './MailTable';
|
|
8
|
+
export { default as MailTable } from './MailTable';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
function isURL(value) {
|
|
5
|
+
try {
|
|
6
|
+
const url = new URL(value);
|
|
7
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async function read(fileName) {
|
|
14
|
+
if (isURL(fileName)) {
|
|
15
|
+
const response = await fetch(fileName);
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
throw new Error(`Failed to fetch ${fileName}: ${response.status}`);
|
|
18
|
+
}
|
|
19
|
+
return Buffer.from(await response.arrayBuffer());
|
|
20
|
+
}
|
|
21
|
+
return fs.readFileSync(fileName);
|
|
22
|
+
}
|
|
23
|
+
async function convertToDataURI(fileName) {
|
|
24
|
+
try {
|
|
25
|
+
const filePath = path.isAbsolute(fileName) || isURL(fileName)
|
|
26
|
+
? fileName
|
|
27
|
+
: path.join(process.cwd(), fileName);
|
|
28
|
+
const mimeType = 'image/' + path.extname(filePath).slice(1);
|
|
29
|
+
const imageData = await read(filePath);
|
|
30
|
+
const base64Image = Buffer.from(imageData).toString('base64');
|
|
31
|
+
return Promise.resolve(`data:${mimeType};base64,${base64Image}`);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export default convertToDataURI;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface MailConfigObject {
|
|
2
|
+
logo?: string;
|
|
3
|
+
styles: {
|
|
4
|
+
root: {
|
|
5
|
+
backgroundColor: string;
|
|
6
|
+
};
|
|
7
|
+
panel: {
|
|
8
|
+
backgroundColor: string;
|
|
9
|
+
padding: number;
|
|
10
|
+
};
|
|
11
|
+
button: {
|
|
12
|
+
backgroundColor: string;
|
|
13
|
+
borderRadius: number;
|
|
14
|
+
color: string;
|
|
15
|
+
height: number;
|
|
16
|
+
};
|
|
17
|
+
title: {
|
|
18
|
+
color: string;
|
|
19
|
+
fontSize: number;
|
|
20
|
+
fontWeight: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DeepPartial } from '@sqrzro/utility';
|
|
2
|
+
import type { MailConfigObject } from './interfaces';
|
|
3
|
+
export declare function setMailConfig(overrides?: DeepPartial<MailConfigObject>): MailConfigObject;
|
|
4
|
+
export declare function getMailConfig(overrides?: DeepPartial<MailConfigObject>): MailConfigObject;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { deepMerge } from '@sqrzro/utility';
|
|
2
|
+
import { cache } from 'react';
|
|
3
|
+
const DEFAULT_STYLES = {
|
|
4
|
+
styles: {
|
|
5
|
+
button: {
|
|
6
|
+
backgroundColor: '#0f172b',
|
|
7
|
+
borderRadius: 4,
|
|
8
|
+
color: '#ffffff',
|
|
9
|
+
height: 40,
|
|
10
|
+
},
|
|
11
|
+
panel: {
|
|
12
|
+
backgroundColor: '#ffffff',
|
|
13
|
+
padding: 40,
|
|
14
|
+
},
|
|
15
|
+
root: {
|
|
16
|
+
backgroundColor: '#f5f5f5',
|
|
17
|
+
},
|
|
18
|
+
title: {
|
|
19
|
+
color: '#62748e',
|
|
20
|
+
fontSize: 20,
|
|
21
|
+
fontWeight: 'bold',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const context = cache(() => new Map());
|
|
26
|
+
const global = context();
|
|
27
|
+
export function setMailConfig(overrides) {
|
|
28
|
+
const string = process.env.MAIL_CONFIG || '{}';
|
|
29
|
+
try {
|
|
30
|
+
const object = JSON.parse(string);
|
|
31
|
+
global.set('mail', deepMerge(DEFAULT_STYLES, object, overrides || {}));
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
global.set('mail', deepMerge(DEFAULT_STYLES, overrides || {}));
|
|
35
|
+
}
|
|
36
|
+
return global.get('mail');
|
|
37
|
+
}
|
|
38
|
+
export function getMailConfig(overrides) {
|
|
39
|
+
return global.has('mail')
|
|
40
|
+
? deepMerge(DEFAULT_STYLES, global.get('mail'), overrides || {})
|
|
41
|
+
: deepMerge(DEFAULT_STYLES, overrides || {});
|
|
42
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { ClassNameProps, HighlightableClassName } from '../../../styles/interfaces';
|
|
1
|
+
import type { ClassNameProps, HighlightableClassName, SelectableClassName } from '../../../styles/classnames/interfaces';
|
|
2
2
|
import type { NavigationObject } from '../../interfaces';
|
|
3
3
|
export interface AppNavigationClassNames {
|
|
4
4
|
root: string;
|
|
5
5
|
list: string;
|
|
6
6
|
item: HighlightableClassName;
|
|
7
7
|
link: HighlightableClassName;
|
|
8
|
+
icon: SelectableClassName;
|
|
8
9
|
}
|
|
9
10
|
export interface AppNavigationProps extends ClassNameProps<AppNavigationClassNames> {
|
|
11
|
+
classNameKey?: 'appNavigation' | 'tabs';
|
|
10
12
|
data: NavigationObject[];
|
|
11
13
|
}
|
|
12
14
|
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 {
|
|
4
|
+
import { useClassNames } from '../../../styles/context';
|
|
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 = useClassNames(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;
|