@tmllak-erp/ui 0.0.0-stage → 0.1.0
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/README.md +509 -3
- package/dist/account/account-menu/AccountMenu.d.ts +14 -0
- package/dist/account/account-menu/AccountMenu.js +10 -0
- package/dist/account/account-menu/AccountMenu.js.map +1 -0
- package/dist/account/account-menu/account-menu.css +15 -0
- package/dist/account/appearance/Appearance.d.ts +52 -0
- package/dist/account/appearance/Appearance.js +67 -0
- package/dist/account/appearance/Appearance.js.map +1 -0
- package/dist/account/appearance/appearance.css +89 -0
- package/dist/account/index.d.ts +4 -0
- package/dist/account/index.js +5 -0
- package/dist/account/index.js.map +1 -0
- package/dist/account/notifications/Notifications.d.ts +60 -0
- package/dist/account/notifications/Notifications.js +50 -0
- package/dist/account/notifications/Notifications.js.map +1 -0
- package/dist/account/notifications/notifications.css +148 -0
- package/dist/account/security/Security.d.ts +78 -0
- package/dist/account/security/Security.js +52 -0
- package/dist/account/security/Security.js.map +1 -0
- package/dist/account/security/security.css +116 -0
- package/dist/data/calendar/CalendarGrid.d.ts +60 -0
- package/dist/data/calendar/CalendarGrid.js +124 -0
- package/dist/data/calendar/CalendarGrid.js.map +1 -0
- package/dist/data/calendar/calendar-grid.css +168 -0
- package/dist/data/charts/BarChart.d.ts +17 -0
- package/dist/data/charts/BarChart.js +58 -0
- package/dist/data/charts/BarChart.js.map +1 -0
- package/dist/data/charts/DonutChart.d.ts +23 -0
- package/dist/data/charts/DonutChart.js +48 -0
- package/dist/data/charts/DonutChart.js.map +1 -0
- package/dist/data/charts/LineChart.d.ts +14 -0
- package/dist/data/charts/LineChart.js +45 -0
- package/dist/data/charts/LineChart.js.map +1 -0
- package/dist/data/charts/chart-utils.d.ts +68 -0
- package/dist/data/charts/chart-utils.js +85 -0
- package/dist/data/charts/chart-utils.js.map +1 -0
- package/dist/data/charts/charts.css +251 -0
- package/dist/data/conversation/Conversation.d.ts +52 -0
- package/dist/data/conversation/Conversation.js +64 -0
- package/dist/data/conversation/Conversation.js.map +1 -0
- package/dist/data/conversation/conversation.css +188 -0
- package/dist/data/hero-card/HeroCard.d.ts +21 -0
- package/dist/data/hero-card/HeroCard.js +9 -0
- package/dist/data/hero-card/HeroCard.js.map +1 -0
- package/dist/data/hero-card/hero-card.css +51 -0
- package/dist/data/index.d.ts +16 -0
- package/dist/data/index.js +17 -0
- package/dist/data/index.js.map +1 -0
- package/dist/data/kanban/KanbanBoard.d.ts +53 -0
- package/dist/data/kanban/KanbanBoard.js +169 -0
- package/dist/data/kanban/KanbanBoard.js.map +1 -0
- package/dist/data/kanban/kanban.css +160 -0
- package/dist/data/kpi/KpiCard.d.ts +35 -0
- package/dist/data/kpi/KpiCard.js +26 -0
- package/dist/data/kpi/KpiCard.js.map +1 -0
- package/dist/data/kpi/kpi-card.css +109 -0
- package/dist/data/lists/Lists.d.ts +79 -0
- package/dist/data/lists/Lists.js +50 -0
- package/dist/data/lists/Lists.js.map +1 -0
- package/dist/data/lists/lists.css +206 -0
- package/dist/data/pagination/Pagination.d.ts +21 -0
- package/dist/data/pagination/Pagination.js +34 -0
- package/dist/data/pagination/Pagination.js.map +1 -0
- package/dist/data/pagination/pagination.css +67 -0
- package/dist/data/record-card/RecordCard.d.ts +35 -0
- package/dist/data/record-card/RecordCard.js +18 -0
- package/dist/data/record-card/RecordCard.js.map +1 -0
- package/dist/data/record-card/record-card.css +111 -0
- package/dist/data/table/DataTable.d.ts +86 -0
- package/dist/data/table/DataTable.js +109 -0
- package/dist/data/table/DataTable.js.map +1 -0
- package/dist/data/table/data-table.css +194 -0
- package/dist/data/toolbar/DataToolbar.d.ts +34 -0
- package/dist/data/toolbar/DataToolbar.js +22 -0
- package/dist/data/toolbar/DataToolbar.js.map +1 -0
- package/dist/data/toolbar/data-toolbar.css +48 -0
- package/dist/feedback/FeedbackProvider.d.ts +44 -0
- package/dist/feedback/FeedbackProvider.js +106 -0
- package/dist/feedback/FeedbackProvider.js.map +1 -0
- package/dist/feedback/banner/Banner.d.ts +20 -0
- package/dist/feedback/banner/Banner.js +15 -0
- package/dist/feedback/banner/Banner.js.map +1 -0
- package/dist/feedback/banner/banner.css +60 -0
- package/dist/feedback/banner/nextPageBanner.d.ts +14 -0
- package/dist/feedback/banner/nextPageBanner.js +35 -0
- package/dist/feedback/banner/nextPageBanner.js.map +1 -0
- package/dist/feedback/index.d.ts +6 -0
- package/dist/feedback/index.js +6 -0
- package/dist/feedback/index.js.map +1 -0
- package/dist/feedback/moduleFeedback.d.ts +38 -0
- package/dist/feedback/moduleFeedback.js +27 -0
- package/dist/feedback/moduleFeedback.js.map +1 -0
- package/dist/feedback/toast/ToastItem.d.ts +8 -0
- package/dist/feedback/toast/ToastItem.js +53 -0
- package/dist/feedback/toast/ToastItem.js.map +1 -0
- package/dist/feedback/toast/ToastProvider.d.ts +17 -0
- package/dist/feedback/toast/ToastProvider.js +133 -0
- package/dist/feedback/toast/ToastProvider.js.map +1 -0
- package/dist/feedback/toast/toast.css +114 -0
- package/dist/feedback/toast/types.d.ts +42 -0
- package/dist/feedback/toast/types.js +2 -0
- package/dist/feedback/toast/types.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/Modal.d.ts +22 -0
- package/dist/internal/Modal.js +42 -0
- package/dist/internal/Modal.js.map +1 -0
- package/dist/internal/Portal.d.ts +5 -0
- package/dist/internal/Portal.js +8 -0
- package/dist/internal/Portal.js.map +1 -0
- package/dist/internal/calendar.d.ts +16 -0
- package/dist/internal/calendar.js +37 -0
- package/dist/internal/calendar.js.map +1 -0
- package/dist/internal/cx.d.ts +1 -0
- package/dist/internal/cx.js +4 -0
- package/dist/internal/cx.js.map +1 -0
- package/dist/internal/focus.d.ts +6 -0
- package/dist/internal/focus.js +57 -0
- package/dist/internal/focus.js.map +1 -0
- package/dist/internal/hooks.d.ts +17 -0
- package/dist/internal/hooks.js +79 -0
- package/dist/internal/hooks.js.map +1 -0
- package/dist/internal/icons.d.ts +36 -0
- package/dist/internal/icons.js +38 -0
- package/dist/internal/icons.js.map +1 -0
- package/dist/internal/react-compat.d.ts +7 -0
- package/dist/internal/react-compat.js +18 -0
- package/dist/internal/react-compat.js.map +1 -0
- package/dist/internal/styles/base.css +67 -0
- package/dist/internal/styles/modal.css +132 -0
- package/dist/locale/ErpProvider.d.ts +37 -0
- package/dist/locale/ErpProvider.js +114 -0
- package/dist/locale/ErpProvider.js.map +1 -0
- package/dist/navigation/app-shell/AppShell.d.ts +26 -0
- package/dist/navigation/app-shell/AppShell.js +38 -0
- package/dist/navigation/app-shell/AppShell.js.map +1 -0
- package/dist/navigation/app-shell/app-shell.css +87 -0
- package/dist/navigation/breadcrumb/Breadcrumb.d.ts +15 -0
- package/dist/navigation/breadcrumb/Breadcrumb.js +13 -0
- package/dist/navigation/breadcrumb/Breadcrumb.js.map +1 -0
- package/dist/navigation/breadcrumb/breadcrumb.css +37 -0
- package/dist/navigation/index.d.ts +7 -0
- package/dist/navigation/index.js +8 -0
- package/dist/navigation/index.js.map +1 -0
- package/dist/navigation/page-header/PageHeader.d.ts +15 -0
- package/dist/navigation/page-header/PageHeader.js +9 -0
- package/dist/navigation/page-header/PageHeader.js.map +1 -0
- package/dist/navigation/page-header/page-header.css +39 -0
- package/dist/navigation/portal/ModuleTile.d.ts +31 -0
- package/dist/navigation/portal/ModuleTile.js +20 -0
- package/dist/navigation/portal/ModuleTile.js.map +1 -0
- package/dist/navigation/portal/portal.css +121 -0
- package/dist/navigation/sidebar/Sidebar.d.ts +38 -0
- package/dist/navigation/sidebar/Sidebar.js +71 -0
- package/dist/navigation/sidebar/Sidebar.js.map +1 -0
- package/dist/navigation/sidebar/sidebar.css +164 -0
- package/dist/navigation/top-bar/TopBar.d.ts +30 -0
- package/dist/navigation/top-bar/TopBar.js +27 -0
- package/dist/navigation/top-bar/TopBar.js.map +1 -0
- package/dist/navigation/top-bar/top-bar.css +83 -0
- package/dist/navigation/types.d.ts +41 -0
- package/dist/navigation/types.js +38 -0
- package/dist/navigation/types.js.map +1 -0
- package/dist/overlays/confirm-dialog/ConfirmDialog.d.ts +40 -0
- package/dist/overlays/confirm-dialog/ConfirmDialog.js +67 -0
- package/dist/overlays/confirm-dialog/ConfirmDialog.js.map +1 -0
- package/dist/overlays/confirm-dialog/confirm-dialog.css +52 -0
- package/dist/overlays/date-picker/DatePicker.d.ts +28 -0
- package/dist/overlays/date-picker/DatePicker.js +106 -0
- package/dist/overlays/date-picker/DatePicker.js.map +1 -0
- package/dist/overlays/date-picker/date-picker.css +90 -0
- package/dist/overlays/dialog/Dialog.d.ts +53 -0
- package/dist/overlays/dialog/Dialog.js +48 -0
- package/dist/overlays/dialog/Dialog.js.map +1 -0
- package/dist/overlays/dialog/dialog.css +119 -0
- package/dist/overlays/drawer/Drawer.d.ts +21 -0
- package/dist/overlays/drawer/Drawer.js +17 -0
- package/dist/overlays/drawer/Drawer.js.map +1 -0
- package/dist/overlays/dropdown-menu/DropdownMenu.d.ts +44 -0
- package/dist/overlays/dropdown-menu/DropdownMenu.js +135 -0
- package/dist/overlays/dropdown-menu/DropdownMenu.js.map +1 -0
- package/dist/overlays/dropdown-menu/dropdown-menu.css +62 -0
- package/dist/overlays/export/Export.d.ts +33 -0
- package/dist/overlays/export/Export.js +33 -0
- package/dist/overlays/export/Export.js.map +1 -0
- package/dist/overlays/index.d.ts +16 -0
- package/dist/overlays/index.js +17 -0
- package/dist/overlays/index.js.map +1 -0
- package/dist/overlays/info-popover/InfoPopover.d.ts +20 -0
- package/dist/overlays/info-popover/InfoPopover.js +10 -0
- package/dist/overlays/info-popover/InfoPopover.js.map +1 -0
- package/dist/overlays/info-popover/info-popover.css +24 -0
- package/dist/overlays/person-picker/PersonPicker.d.ts +39 -0
- package/dist/overlays/person-picker/PersonPicker.js +109 -0
- package/dist/overlays/person-picker/PersonPicker.js.map +1 -0
- package/dist/overlays/person-picker/person-picker.css +37 -0
- package/dist/overlays/popover/Popover.d.ts +35 -0
- package/dist/overlays/popover/Popover.js +72 -0
- package/dist/overlays/popover/Popover.js.map +1 -0
- package/dist/overlays/popover/popover.css +48 -0
- package/dist/overlays/record-details/RecordDetails.d.ts +41 -0
- package/dist/overlays/record-details/RecordDetails.js +14 -0
- package/dist/overlays/record-details/RecordDetails.js.map +1 -0
- package/dist/overlays/result-dialog/CopyButton.d.ts +9 -0
- package/dist/overlays/result-dialog/CopyButton.js +47 -0
- package/dist/overlays/result-dialog/CopyButton.js.map +1 -0
- package/dist/overlays/result-dialog/ResultDialog.d.ts +39 -0
- package/dist/overlays/result-dialog/ResultDialog.js +32 -0
- package/dist/overlays/result-dialog/ResultDialog.js.map +1 -0
- package/dist/overlays/result-dialog/result-dialog.css +69 -0
- package/dist/overlays/stepper/StageProgress.d.ts +11 -0
- package/dist/overlays/stepper/StageProgress.js +13 -0
- package/dist/overlays/stepper/StageProgress.js.map +1 -0
- package/dist/overlays/stepper/Stepper.d.ts +16 -0
- package/dist/overlays/stepper/Stepper.js +15 -0
- package/dist/overlays/stepper/Stepper.js.map +1 -0
- package/dist/overlays/stepper/Wizard.d.ts +24 -0
- package/dist/overlays/stepper/Wizard.js +52 -0
- package/dist/overlays/stepper/Wizard.js.map +1 -0
- package/dist/overlays/stepper/stepper.css +135 -0
- package/dist/overlays/time-picker/TimePicker.d.ts +27 -0
- package/dist/overlays/time-picker/TimePicker.js +27 -0
- package/dist/overlays/time-picker/TimePicker.js.map +1 -0
- package/dist/primitives/avatar/Avatar.d.ts +27 -0
- package/dist/primitives/avatar/Avatar.js +29 -0
- package/dist/primitives/avatar/Avatar.js.map +1 -0
- package/dist/primitives/avatar/avatar.css +59 -0
- package/dist/primitives/badge/badges.css +160 -0
- package/dist/primitives/badge/badges.d.ts +47 -0
- package/dist/primitives/badge/badges.js +27 -0
- package/dist/primitives/badge/badges.js.map +1 -0
- package/dist/primitives/button/Button.d.ts +32 -0
- package/dist/primitives/button/Button.js +17 -0
- package/dist/primitives/button/Button.js.map +1 -0
- package/dist/primitives/button/button.css +149 -0
- package/dist/primitives/card/Card.d.ts +18 -0
- package/dist/primitives/card/Card.js +13 -0
- package/dist/primitives/card/Card.js.map +1 -0
- package/dist/primitives/card/card.css +70 -0
- package/dist/primitives/choice/Checkbox.d.ts +11 -0
- package/dist/primitives/choice/Checkbox.js +20 -0
- package/dist/primitives/choice/Checkbox.js.map +1 -0
- package/dist/primitives/choice/Switch.d.ts +16 -0
- package/dist/primitives/choice/Switch.js +14 -0
- package/dist/primitives/choice/Switch.js.map +1 -0
- package/dist/primitives/choice/choice.css +138 -0
- package/dist/primitives/empty-state/EmptyState.d.ts +14 -0
- package/dist/primitives/empty-state/EmptyState.js +10 -0
- package/dist/primitives/empty-state/EmptyState.js.map +1 -0
- package/dist/primitives/empty-state/empty-state.css +41 -0
- package/dist/primitives/field/Field.d.ts +26 -0
- package/dist/primitives/field/Field.js +18 -0
- package/dist/primitives/field/Field.js.map +1 -0
- package/dist/primitives/field/TextField.d.ts +29 -0
- package/dist/primitives/field/TextField.js +28 -0
- package/dist/primitives/field/TextField.js.map +1 -0
- package/dist/primitives/field/field.css +139 -0
- package/dist/primitives/filter-chips/FilterChips.d.ts +30 -0
- package/dist/primitives/filter-chips/FilterChips.js +38 -0
- package/dist/primitives/filter-chips/FilterChips.js.map +1 -0
- package/dist/primitives/filter-chips/filter-chips.css +60 -0
- package/dist/primitives/icon/Icon.d.ts +15 -0
- package/dist/primitives/icon/Icon.js +9 -0
- package/dist/primitives/icon/Icon.js.map +1 -0
- package/dist/primitives/index.d.ts +17 -0
- package/dist/primitives/index.js +18 -0
- package/dist/primitives/index.js.map +1 -0
- package/dist/primitives/progress/ProgressBar.d.ts +19 -0
- package/dist/primitives/progress/ProgressBar.js +18 -0
- package/dist/primitives/progress/ProgressBar.js.map +1 -0
- package/dist/primitives/progress/Spinner.d.ts +8 -0
- package/dist/primitives/progress/Spinner.js +10 -0
- package/dist/primitives/progress/Spinner.js.map +1 -0
- package/dist/primitives/progress/progress.css +85 -0
- package/dist/primitives/segmented/SegmentedControl.d.ts +28 -0
- package/dist/primitives/segmented/SegmentedControl.js +34 -0
- package/dist/primitives/segmented/SegmentedControl.js.map +1 -0
- package/dist/primitives/segmented/segmented.css +67 -0
- package/dist/primitives/select/Select.d.ts +35 -0
- package/dist/primitives/select/Select.js +153 -0
- package/dist/primitives/select/Select.js.map +1 -0
- package/dist/primitives/select/select.css +100 -0
- package/dist/primitives/tabs/Tabs.d.ts +23 -0
- package/dist/primitives/tabs/Tabs.js +43 -0
- package/dist/primitives/tabs/Tabs.js.map +1 -0
- package/dist/primitives/tabs/tabs.css +59 -0
- package/dist/primitives/tooltip/Tooltip.d.ts +27 -0
- package/dist/primitives/tooltip/Tooltip.js +66 -0
- package/dist/primitives/tooltip/Tooltip.js.map +1 -0
- package/dist/primitives/tooltip/tooltip.css +24 -0
- package/package.json +38 -6
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
const FOCUSABLE = [
|
|
4
|
+
'a[href]',
|
|
5
|
+
'button:not([disabled])',
|
|
6
|
+
'input:not([disabled]):not([type="hidden"])',
|
|
7
|
+
'select:not([disabled])',
|
|
8
|
+
'textarea:not([disabled])',
|
|
9
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
10
|
+
].join(',');
|
|
11
|
+
export function focusableWithin(root) {
|
|
12
|
+
return [...root.querySelectorAll(FOCUSABLE)].filter((el) => !el.hasAttribute('inert'));
|
|
13
|
+
}
|
|
14
|
+
/** Keeps Tab and Shift+Tab cycling inside `ref` while `active`. */
|
|
15
|
+
export function useFocusTrap(ref, active) {
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const root = ref.current;
|
|
18
|
+
if (!active || !root)
|
|
19
|
+
return;
|
|
20
|
+
const onKeyDown = (event) => {
|
|
21
|
+
if (event.key !== 'Tab')
|
|
22
|
+
return;
|
|
23
|
+
const items = focusableWithin(root);
|
|
24
|
+
if (items.length === 0) {
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
root.focus();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const first = items[0];
|
|
30
|
+
const last = items[items.length - 1];
|
|
31
|
+
const current = document.activeElement;
|
|
32
|
+
if (event.shiftKey && (current === first || current === root)) {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
last.focus();
|
|
35
|
+
}
|
|
36
|
+
else if (!event.shiftKey && current === last) {
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
first.focus();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
root.addEventListener('keydown', onKeyDown);
|
|
42
|
+
return () => root.removeEventListener('keydown', onKeyDown);
|
|
43
|
+
}, [ref, active]);
|
|
44
|
+
}
|
|
45
|
+
/** Restores focus to whatever was focused before `active` became true. */
|
|
46
|
+
export function useRestoreFocus(active) {
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!active)
|
|
49
|
+
return;
|
|
50
|
+
const previous = document.activeElement;
|
|
51
|
+
return () => {
|
|
52
|
+
if (previous && previous.isConnected)
|
|
53
|
+
previous.focus();
|
|
54
|
+
};
|
|
55
|
+
}, [active]);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=focus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focus.js","sourceRoot":"","sources":["../../src/internal/focus.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAkB,MAAM,OAAO,CAAC;AAElD,MAAM,SAAS,GAAG;IAChB,SAAS;IACT,wBAAwB;IACxB,4CAA4C;IAC5C,wBAAwB;IACxB,0BAA0B;IAC1B,iCAAiC;CAClC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ,MAAM,UAAU,eAAe,CAAC,IAAiB;IAC/C,OAAO,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAc,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EA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AAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC9D,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;AACpB,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,eAAe,CAAC,MAAe;IAC7C,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM;YAAE,OAAO;QACpB,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAmC,CAAC;QAC9D,OAAO,GAAG,EAAE;YACV,IAAI,QAAQ,IAAI,QAAQ,CAAC,WAAW;gBAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;QACzD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AACf,CAAC","sourcesContent":["'use client';\r\n\r\nimport { useEffect, type RefObject } from 'react';\r\n\r\nconst FOCUSABLE = [\r\n 'a[href]',\r\n 'button:not([disabled])',\r\n 'input:not([disabled]):not([type=\"hidden\"])',\r\n 'select:not([disabled])',\r\n 'textarea:not([disabled])',\r\n '[tabindex]:not([tabindex=\"-1\"])',\r\n].join(',');\r\n\r\nexport function focusableWithin(root: HTMLElement): HTMLElement[] {\r\n return [...root.querySelectorAll<HTMLElement>(FOCUSABLE)].filter((el) => !el.hasAttribute('inert'));\r\n}\r\n\r\n/** Keeps Tab and Shift+Tab cycling inside `ref` while `active`. */\r\nexport function useFocusTrap(ref: RefObject<HTMLElement | null>, active: boolean): void {\r\n useEffect(() => {\r\n const root = ref.current;\r\n if (!active || !root) return;\r\n const onKeyDown = (event: KeyboardEvent) => {\r\n if (event.key !== 'Tab') return;\r\n const items = focusableWithin(root);\r\n if (items.length === 0) {\r\n event.preventDefault();\r\n root.focus();\r\n return;\r\n }\r\n const first = items[0]!;\r\n const last = items[items.length - 1]!;\r\n const current = document.activeElement;\r\n if (event.shiftKey && (current === first || current === root)) {\r\n event.preventDefault();\r\n last.focus();\r\n } else if (!event.shiftKey && current === last) {\r\n event.preventDefault();\r\n first.focus();\r\n }\r\n };\r\n root.addEventListener('keydown', onKeyDown);\r\n return () => root.removeEventListener('keydown', onKeyDown);\r\n }, [ref, active]);\r\n}\r\n\r\n/** Restores focus to whatever was focused before `active` became true. */\r\nexport function useRestoreFocus(active: boolean): void {\r\n useEffect(() => {\r\n if (!active) return;\r\n const previous = document.activeElement as HTMLElement | null;\r\n return () => {\r\n if (previous && previous.isConnected) previous.focus();\r\n };\r\n }, [active]);\r\n}\r\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, type Ref, type RefObject } from 'react';
|
|
2
|
+
/** `useLayoutEffect` in the browser, `useEffect` on the server, where layout effects never run and React 18 warns. */
|
|
3
|
+
export declare const useIsomorphicLayoutEffect: typeof useEffect;
|
|
4
|
+
/** Controlled when `value` is defined, otherwise keeps internal state; `onChange` fires in both modes. */
|
|
5
|
+
export declare function useControllableState<T>(value: T | undefined, defaultValue: T, onChange?: (next: T) => void): readonly [T, (next: T) => void];
|
|
6
|
+
/** Calls `handler` on pointer-down outside every given element while `active`. */
|
|
7
|
+
export declare function useOutsideClick(refs: RefObject<HTMLElement | null>[], handler: () => void, active: boolean): void;
|
|
8
|
+
/** Tracks a media query; false when matchMedia is unavailable (tests, SSR). */
|
|
9
|
+
export declare function useMediaQuery(query: string): boolean;
|
|
10
|
+
export declare function mergeRefs<T>(...refs: (Ref<T> | undefined)[]): (node: T | null) => void;
|
|
11
|
+
export type Direction = 'rtl' | 'ltr';
|
|
12
|
+
/** Resolves the writing direction of an element; the product default is RTL. */
|
|
13
|
+
export declare function directionOf(element: Element | null | undefined): Direction;
|
|
14
|
+
/** Maps a horizontal arrow key to a logical step: in RTL, ArrowLeft moves forward. */
|
|
15
|
+
export declare function horizontalStep(key: string, dir: Direction): 1 | -1 | 0;
|
|
16
|
+
/** Index after moving `step` places through `count` items, wrapping around. */
|
|
17
|
+
export declare function wrapIndex(index: number, step: number, count: number): number;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
/** `useLayoutEffect` in the browser, `useEffect` on the server, where layout effects never run and React 18 warns. */
|
|
4
|
+
export const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
5
|
+
/** Controlled when `value` is defined, otherwise keeps internal state; `onChange` fires in both modes. */
|
|
6
|
+
export function useControllableState(value, defaultValue, onChange) {
|
|
7
|
+
const [internal, setInternal] = useState(defaultValue);
|
|
8
|
+
const controlled = value !== undefined;
|
|
9
|
+
const current = controlled ? value : internal;
|
|
10
|
+
const set = useCallback((next) => {
|
|
11
|
+
if (!controlled)
|
|
12
|
+
setInternal(next);
|
|
13
|
+
onChange?.(next);
|
|
14
|
+
}, [controlled, onChange]);
|
|
15
|
+
return [current, set];
|
|
16
|
+
}
|
|
17
|
+
/** Calls `handler` on pointer-down outside every given element while `active`. */
|
|
18
|
+
export function useOutsideClick(refs, handler, active) {
|
|
19
|
+
const latest = useRef(handler);
|
|
20
|
+
useIsomorphicLayoutEffect(() => {
|
|
21
|
+
latest.current = handler;
|
|
22
|
+
});
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!active)
|
|
25
|
+
return;
|
|
26
|
+
const onPointerDown = (event) => {
|
|
27
|
+
const target = event.target;
|
|
28
|
+
if (refs.every((r) => !r.current?.contains(target)))
|
|
29
|
+
latest.current();
|
|
30
|
+
};
|
|
31
|
+
document.addEventListener('pointerdown', onPointerDown);
|
|
32
|
+
return () => document.removeEventListener('pointerdown', onPointerDown);
|
|
33
|
+
// refs are stable objects created by useRef
|
|
34
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
+
}, [active]);
|
|
36
|
+
}
|
|
37
|
+
/** Tracks a media query; false when matchMedia is unavailable (tests, SSR). */
|
|
38
|
+
export function useMediaQuery(query) {
|
|
39
|
+
const get = () => typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia(query).matches;
|
|
40
|
+
const [matches, setMatches] = useState(get);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
|
|
43
|
+
return;
|
|
44
|
+
const list = window.matchMedia(query);
|
|
45
|
+
const onChange = () => setMatches(list.matches);
|
|
46
|
+
onChange();
|
|
47
|
+
list.addEventListener('change', onChange);
|
|
48
|
+
return () => list.removeEventListener('change', onChange);
|
|
49
|
+
}, [query]);
|
|
50
|
+
return matches;
|
|
51
|
+
}
|
|
52
|
+
export function mergeRefs(...refs) {
|
|
53
|
+
return (node) => {
|
|
54
|
+
for (const ref of refs) {
|
|
55
|
+
if (typeof ref === 'function')
|
|
56
|
+
ref(node);
|
|
57
|
+
else if (ref)
|
|
58
|
+
ref.current = node;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Resolves the writing direction of an element; the product default is RTL. */
|
|
63
|
+
export function directionOf(element) {
|
|
64
|
+
const dir = element?.closest('[dir]')?.getAttribute('dir') ?? (typeof document === 'undefined' ? null : document.documentElement.getAttribute('dir'));
|
|
65
|
+
return dir === 'ltr' ? 'ltr' : 'rtl';
|
|
66
|
+
}
|
|
67
|
+
/** Maps a horizontal arrow key to a logical step: in RTL, ArrowLeft moves forward. */
|
|
68
|
+
export function horizontalStep(key, dir) {
|
|
69
|
+
if (key === 'ArrowLeft')
|
|
70
|
+
return dir === 'rtl' ? 1 : -1;
|
|
71
|
+
if (key === 'ArrowRight')
|
|
72
|
+
return dir === 'rtl' ? -1 : 1;
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
/** Index after moving `step` places through `count` items, wrapping around. */
|
|
76
|
+
export function wrapIndex(index, step, count) {
|
|
77
|
+
return (index + step + count) % count;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../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Content":["'use client';\r\n\r\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState, type Ref, type RefObject } from 'react';\r\n\r\n/** `useLayoutEffect` in the browser, `useEffect` on the server, where layout effects never run and React 18 warns. */\r\nexport const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\r\n\r\n/** Controlled when `value` is defined, otherwise keeps internal state; `onChange` fires in both modes. */\r\nexport function useControllableState<T>(value: T | undefined, defaultValue: T, onChange?: (next: T) => void) {\r\n const [internal, setInternal] = useState(defaultValue);\r\n const controlled = value !== undefined;\r\n const current = controlled ? value : internal;\r\n const set = useCallback(\r\n (next: T) => {\r\n if (!controlled) setInternal(next);\r\n onChange?.(next);\r\n },\r\n [controlled, onChange],\r\n );\r\n return [current, set] as const;\r\n}\r\n\r\n/** Calls `handler` on pointer-down outside every given element while `active`. */\r\nexport function useOutsideClick(refs: RefObject<HTMLElement | null>[], handler: () => void, active: boolean) {\r\n const latest = useRef(handler);\r\n useIsomorphicLayoutEffect(() => {\r\n latest.current = handler;\r\n });\r\n useEffect(() => {\r\n if (!active) return;\r\n const onPointerDown = (event: PointerEvent) => {\r\n const target = event.target as Node;\r\n if (refs.every((r) => !r.current?.contains(target))) latest.current();\r\n };\r\n document.addEventListener('pointerdown', onPointerDown);\r\n return () => document.removeEventListener('pointerdown', onPointerDown);\r\n // refs are stable objects created by useRef\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, [active]);\r\n}\r\n\r\n/** Tracks a media query; false when matchMedia is unavailable (tests, SSR). */\r\nexport function useMediaQuery(query: string): boolean {\r\n const get = () => typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia(query).matches;\r\n const [matches, setMatches] = useState(get);\r\n useEffect(() => {\r\n if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;\r\n const list = window.matchMedia(query);\r\n const onChange = () => setMatches(list.matches);\r\n onChange();\r\n list.addEventListener('change', onChange);\r\n return () => list.removeEventListener('change', onChange);\r\n }, [query]);\r\n return matches;\r\n}\r\n\r\nexport function mergeRefs<T>(...refs: (Ref<T> | undefined)[]) {\r\n return (node: T | null) => {\r\n for (const ref of refs) {\r\n if (typeof ref === 'function') ref(node);\r\n else if (ref) (ref as { current: T | null }).current = node;\r\n }\r\n };\r\n}\r\n\r\nexport type Direction = 'rtl' | 'ltr';\r\n\r\n/** Resolves the writing direction of an element; the product default is RTL. */\r\nexport function directionOf(element: Element | null | undefined): Direction {\r\n const dir = element?.closest('[dir]')?.getAttribute('dir') ?? (typeof document === 'undefined' ? null : document.documentElement.getAttribute('dir'));\r\n return dir === 'ltr' ? 'ltr' : 'rtl';\r\n}\r\n\r\n/** Maps a horizontal arrow key to a logical step: in RTL, ArrowLeft moves forward. */\r\nexport function horizontalStep(key: string, dir: Direction): 1 | -1 | 0 {\r\n if (key === 'ArrowLeft') return dir === 'rtl' ? 1 : -1;\r\n if (key === 'ArrowRight') return dir === 'rtl' ? -1 : 1;\r\n return 0;\r\n}\r\n\r\n/** Index after moving `step` places through `count` items, wrapping around. */\r\nexport function wrapIndex(index: number, step: number, count: number): number {\r\n return (index + step + count) % count;\r\n}\r\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type FeedbackTone } from '@tmllak-erp/messages';
|
|
2
|
+
import { type LucideProps } from 'lucide-react';
|
|
3
|
+
import type { JSX } from 'react';
|
|
4
|
+
type IconProps = Omit<LucideProps, 'ref'>;
|
|
5
|
+
export declare const SuccessIcon: {
|
|
6
|
+
(props: IconProps): JSX.Element;
|
|
7
|
+
displayName: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const InfoIcon: {
|
|
10
|
+
(props: IconProps): JSX.Element;
|
|
11
|
+
displayName: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const WarningIcon: {
|
|
14
|
+
(props: IconProps): JSX.Element;
|
|
15
|
+
displayName: string;
|
|
16
|
+
};
|
|
17
|
+
export declare const DangerIcon: {
|
|
18
|
+
(props: IconProps): JSX.Element;
|
|
19
|
+
displayName: string;
|
|
20
|
+
};
|
|
21
|
+
export declare const CloseIcon: {
|
|
22
|
+
(props: IconProps): JSX.Element;
|
|
23
|
+
displayName: string;
|
|
24
|
+
};
|
|
25
|
+
export declare const CopyIcon: {
|
|
26
|
+
(props: IconProps): JSX.Element;
|
|
27
|
+
displayName: string;
|
|
28
|
+
};
|
|
29
|
+
export declare const CheckIcon: {
|
|
30
|
+
(props: IconProps): JSX.Element;
|
|
31
|
+
displayName: string;
|
|
32
|
+
};
|
|
33
|
+
export declare const TONE_ICONS: Record<FeedbackTone, (p: IconProps) => JSX.Element>;
|
|
34
|
+
/** Spoken before the message so the tone never depends on color or icon alone. Follows the active locale. */
|
|
35
|
+
export declare const TONE_LABELS: Record<FeedbackTone, string>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { UI_COPY } from '@tmllak-erp/messages';
|
|
3
|
+
import { Check, CircleCheck, CircleX, Copy, Info, TriangleAlert, X } from 'lucide-react';
|
|
4
|
+
/** Inline icons sized by the surrounding font-size; decorative unless an accessible name is given elsewhere. */
|
|
5
|
+
function inline(Component) {
|
|
6
|
+
const InlineIcon = (props) => _jsx(Component, { size: "1em", strokeWidth: 2, "aria-hidden": "true", focusable: "false", ...props });
|
|
7
|
+
InlineIcon.displayName = `Inline${Component.displayName ?? 'Icon'}`;
|
|
8
|
+
return InlineIcon;
|
|
9
|
+
}
|
|
10
|
+
export const SuccessIcon = inline(CircleCheck);
|
|
11
|
+
export const InfoIcon = inline(Info);
|
|
12
|
+
export const WarningIcon = inline(TriangleAlert);
|
|
13
|
+
export const DangerIcon = inline(CircleX);
|
|
14
|
+
export const CloseIcon = inline(X);
|
|
15
|
+
export const CopyIcon = inline(Copy);
|
|
16
|
+
export const CheckIcon = inline(Check);
|
|
17
|
+
export const TONE_ICONS = {
|
|
18
|
+
success: SuccessIcon,
|
|
19
|
+
info: InfoIcon,
|
|
20
|
+
warning: WarningIcon,
|
|
21
|
+
danger: DangerIcon,
|
|
22
|
+
};
|
|
23
|
+
/** Spoken before the message so the tone never depends on color or icon alone. Follows the active locale. */
|
|
24
|
+
export const TONE_LABELS = {
|
|
25
|
+
get success() {
|
|
26
|
+
return UI_COPY.tone.success;
|
|
27
|
+
},
|
|
28
|
+
get info() {
|
|
29
|
+
return UI_COPY.tone.info;
|
|
30
|
+
},
|
|
31
|
+
get warning() {
|
|
32
|
+
return UI_COPY.tone.warning;
|
|
33
|
+
},
|
|
34
|
+
get danger() {
|
|
35
|
+
return UI_COPY.tone.danger;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=icons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icons.js","sourceRoot":"","sources":["../../src/internal/icons.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAqB,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,EAAqC,MAAM,cAAc,CAAC;AAK5H,gHAAgH;AAChH,SAAS,MAAM,CAAC,SAAqB;IACnC,MAAM,UAAU,GAAG,CAAC,KAAgB,EAAE,EAAE,CAAC,KAAC,SAAS,IAAC,IAAI,EAAC,KAAK,EAAC,WAAW,EAAE,CAAC,iBAAc,MAAM,EAAC,SAAS,EAAC,OAAO,KAAK,KAAK,GAAI,CAAC;IAClI,UAAU,CAAC,WAAW,GAAG,SAAS,SAAS,CAAC,WAAW,IAAI,MAAM,EAAE,CAAC;IACpE,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAC/C,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AACjD,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;AAC1C,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AACrC,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAEvC,MAAM,CAAC,MAAM,UAAU,GAAwD;IAC7E,OAAO,EAAE,WAAW;IACpB,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,WAAW;IACpB,MAAM,EAAE,UAAU;CACnB,CAAC;AAEF,6GAA6G;AAC7G,MAAM,CAAC,MAAM,WAAW,GAAiC;IACvD,IAAI,OAAO;QACT,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IAC9B,CAAC;IACD,IAAI,IAAI;QACN,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;IAC3B,CAAC;IACD,IAAI,OAAO;QACT,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IAC9B,CAAC;IACD,IAAI,MAAM;QACR,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;IAC7B,CAAC;CACF,CAAC","sourcesContent":["import { UI_COPY, type FeedbackTone } from '@tmllak-erp/messages';\r\nimport { Check, CircleCheck, CircleX, Copy, Info, TriangleAlert, X, type LucideIcon, type LucideProps } from 'lucide-react';\r\nimport type { JSX } from 'react';\r\n\r\ntype IconProps = Omit<LucideProps, 'ref'>;\r\n\r\n/** Inline icons sized by the surrounding font-size; decorative unless an accessible name is given elsewhere. */\r\nfunction inline(Component: LucideIcon) {\r\n const InlineIcon = (props: IconProps) => <Component size=\"1em\" strokeWidth={2} aria-hidden=\"true\" focusable=\"false\" {...props} />;\r\n InlineIcon.displayName = `Inline${Component.displayName ?? 'Icon'}`;\r\n return InlineIcon;\r\n}\r\n\r\nexport const SuccessIcon = inline(CircleCheck);\r\nexport const InfoIcon = inline(Info);\r\nexport const WarningIcon = inline(TriangleAlert);\r\nexport const DangerIcon = inline(CircleX);\r\nexport const CloseIcon = inline(X);\r\nexport const CopyIcon = inline(Copy);\r\nexport const CheckIcon = inline(Check);\r\n\r\nexport const TONE_ICONS: Record<FeedbackTone, (p: IconProps) => JSX.Element> = {\r\n success: SuccessIcon,\r\n info: InfoIcon,\r\n warning: WarningIcon,\r\n danger: DangerIcon,\r\n};\r\n\r\n/** Spoken before the message so the tone never depends on color or icon alone. Follows the active locale. */\r\nexport const TONE_LABELS: Record<FeedbackTone, string> = {\r\n get success() {\r\n return UI_COPY.tone.success;\r\n },\r\n get info() {\r\n return UI_COPY.tone.info;\r\n },\r\n get warning() {\r\n return UI_COPY.tone.warning;\r\n },\r\n get danger() {\r\n return UI_COPY.tone.danger;\r\n },\r\n};\r\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactElement, type Ref } from 'react';
|
|
2
|
+
/** The ref already attached to an element, wherever the running React version keeps it. */
|
|
3
|
+
export declare function elementRef<T>(element: ReactElement): Ref<T> | undefined;
|
|
4
|
+
/** Props that make a host element inert: `inert={true}` from React 19, `inert=""` before. */
|
|
5
|
+
export declare function inertProps(inert: boolean): {
|
|
6
|
+
inert?: boolean;
|
|
7
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { version } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* React 19 keeps an element's `ref` in `props` (reading `element.ref` warns) and treats `inert` as a
|
|
4
|
+
* boolean attribute. React 18 keeps `ref` on the element and drops an unknown boolean `inert`.
|
|
5
|
+
*/
|
|
6
|
+
const REACT_19 = Number.parseInt(version, 10) >= 19;
|
|
7
|
+
/** The ref already attached to an element, wherever the running React version keeps it. */
|
|
8
|
+
export function elementRef(element) {
|
|
9
|
+
const ref = REACT_19 ? element.props.ref : element.ref;
|
|
10
|
+
return ref ?? undefined;
|
|
11
|
+
}
|
|
12
|
+
/** Props that make a host element inert: `inert={true}` from React 19, `inert=""` before. */
|
|
13
|
+
export function inertProps(inert) {
|
|
14
|
+
if (!inert)
|
|
15
|
+
return {};
|
|
16
|
+
return { inert: (REACT_19 ? true : '') };
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=react-compat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-compat.js","sourceRoot":"","sources":["../../src/internal/react-compat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA+B,MAAM,OAAO,CAAC;AAE7D;;;GAGG;AACH,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;AAEpD,2FAA2F;AAC3F,MAAM,UAAU,UAAU,CAAI,OAAqB;IACjD,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAE,OAAO,CAAC,KAA0B,CAAC,GAAG,CAAC,CAAC,CAAE,OAA8C,CAAC,GAAG,CAAC;IACrH,OAAO,GAAG,IAAI,SAAS,CAAC;AAC1B,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,OAAO,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAuB,EAAE,CAAC;AACjE,CAAC","sourcesContent":["import { version, type ReactElement, type Ref } from 'react';\r\n\r\n/**\r\n * React 19 keeps an element's `ref` in `props` (reading `element.ref` warns) and treats `inert` as a\r\n * boolean attribute. React 18 keeps `ref` on the element and drops an unknown boolean `inert`.\r\n */\r\nconst REACT_19 = Number.parseInt(version, 10) >= 19;\r\n\r\n/** The ref already attached to an element, wherever the running React version keeps it. */\r\nexport function elementRef<T>(element: ReactElement): Ref<T> | undefined {\r\n const ref = REACT_19 ? (element.props as { ref?: Ref<T> }).ref : (element as unknown as { ref?: Ref<T> | null }).ref;\r\n return ref ?? undefined;\r\n}\r\n\r\n/** Props that make a host element inert: `inert={true}` from React 19, `inert=\"\"` before. */\r\nexport function inertProps(inert: boolean): { inert?: boolean } {\r\n if (!inert) return {};\r\n return { inert: (REACT_19 ? true : '') as unknown as boolean };\r\n}\r\n"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* Shared primitives for @tmllak-erp/ui. Colors come only from @tmllak-erp/tokens so every theme and brand applies. */
|
|
2
|
+
|
|
3
|
+
/* Components size correctly without relying on the host app's CSS reset; :where() keeps specificity at 0. */
|
|
4
|
+
:where([class^='erp-'], [class*=' erp-']),
|
|
5
|
+
:where([class^='erp-'], [class*=' erp-']) *,
|
|
6
|
+
:where([class^='erp-'], [class*=' erp-']) *::before,
|
|
7
|
+
:where([class^='erp-'], [class*=' erp-']) *::after {
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.erp-visually-hidden {
|
|
12
|
+
position: absolute;
|
|
13
|
+
inline-size: 1px;
|
|
14
|
+
block-size: 1px;
|
|
15
|
+
margin: -1px;
|
|
16
|
+
padding: 0;
|
|
17
|
+
overflow: hidden;
|
|
18
|
+
clip: rect(0 0 0 0);
|
|
19
|
+
white-space: nowrap;
|
|
20
|
+
border: 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/* Status colors never follow the brand; info reuses the «active» blue. */
|
|
24
|
+
.erp-tone-success {
|
|
25
|
+
--erp-tone-fg: var(--erp-status-success-fg);
|
|
26
|
+
--erp-tone-bg: var(--erp-status-success-bg);
|
|
27
|
+
--erp-tone-accent: var(--erp-status-success-dot);
|
|
28
|
+
}
|
|
29
|
+
.erp-tone-info {
|
|
30
|
+
--erp-tone-fg: var(--erp-status-active-fg);
|
|
31
|
+
--erp-tone-bg: var(--erp-status-active-bg);
|
|
32
|
+
--erp-tone-accent: var(--erp-status-active-dot);
|
|
33
|
+
}
|
|
34
|
+
.erp-tone-warning {
|
|
35
|
+
--erp-tone-fg: var(--erp-status-warning-fg);
|
|
36
|
+
--erp-tone-bg: var(--erp-status-warning-bg);
|
|
37
|
+
--erp-tone-accent: var(--erp-status-warning-dot);
|
|
38
|
+
}
|
|
39
|
+
.erp-tone-danger {
|
|
40
|
+
--erp-tone-fg: var(--erp-status-danger-fg);
|
|
41
|
+
--erp-tone-bg: var(--erp-status-danger-bg);
|
|
42
|
+
--erp-tone-accent: var(--erp-status-danger-dot);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* Shared focus ring for custom interactive elements. */
|
|
46
|
+
.erp-focusable:focus-visible {
|
|
47
|
+
outline: 2px solid var(--erp-color-focus-ring);
|
|
48
|
+
outline-offset: 2px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Values that must keep Latin digits and LTR order inside Arabic text (emails, IBANs, ids). */
|
|
52
|
+
.erp-ltr {
|
|
53
|
+
direction: ltr;
|
|
54
|
+
unicode-bidi: isolate;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.erp-numeric {
|
|
58
|
+
font-family: var(--erp-font-family-numeric);
|
|
59
|
+
font-variant-numeric: tabular-nums;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.erp-icon {
|
|
63
|
+
flex: none;
|
|
64
|
+
}
|
|
65
|
+
.erp-icon--mirror:dir(rtl) {
|
|
66
|
+
transform: scaleX(-1);
|
|
67
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
.erp-dialog-backdrop {
|
|
2
|
+
position: fixed;
|
|
3
|
+
inset: 0;
|
|
4
|
+
z-index: var(--erp-z-dialog);
|
|
5
|
+
display: grid;
|
|
6
|
+
grid-template-columns: minmax(0, 1fr);
|
|
7
|
+
place-items: center;
|
|
8
|
+
padding: var(--erp-space-4);
|
|
9
|
+
background: var(--erp-color-scrim);
|
|
10
|
+
animation: erp-fade-in var(--erp-duration-base) var(--erp-easing-standard);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.erp-modal {
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
gap: var(--erp-space-4);
|
|
17
|
+
inline-size: min(100%, var(--erp-width-dialog));
|
|
18
|
+
max-block-size: calc(100dvh - 2 * var(--erp-space-8));
|
|
19
|
+
overflow-y: auto;
|
|
20
|
+
padding: var(--erp-space-6);
|
|
21
|
+
border-radius: var(--erp-radius-lg);
|
|
22
|
+
background: var(--erp-color-bg-surface);
|
|
23
|
+
color: var(--erp-color-text-primary);
|
|
24
|
+
box-shadow: var(--erp-shadow-overlay);
|
|
25
|
+
font-family: var(--erp-font-family-base);
|
|
26
|
+
outline: none;
|
|
27
|
+
animation: erp-dialog-in var(--erp-duration-base) var(--erp-easing-standard);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.erp-modal--form {
|
|
31
|
+
inline-size: min(100%, var(--erp-width-form-dialog));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* Drawer: full height from the inline-end edge (the left in RTL), Figma record details ≈ 520px. */
|
|
35
|
+
.erp-dialog-backdrop--end {
|
|
36
|
+
place-items: stretch end;
|
|
37
|
+
padding: 0;
|
|
38
|
+
}
|
|
39
|
+
.erp-modal--drawer {
|
|
40
|
+
inline-size: min(100%, var(--erp-width-drawer));
|
|
41
|
+
max-block-size: none;
|
|
42
|
+
block-size: 100dvh;
|
|
43
|
+
border-radius: 0;
|
|
44
|
+
border-start-start-radius: var(--erp-radius-lg);
|
|
45
|
+
border-end-start-radius: var(--erp-radius-lg);
|
|
46
|
+
animation: erp-drawer-in var(--erp-duration-slow) var(--erp-easing-standard);
|
|
47
|
+
}
|
|
48
|
+
@keyframes erp-drawer-in {
|
|
49
|
+
from {
|
|
50
|
+
opacity: 0;
|
|
51
|
+
translate: var(--erp-drawer-offset, -24px) 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
[dir='ltr'] .erp-modal--drawer,
|
|
55
|
+
.erp-modal--drawer:dir(ltr) {
|
|
56
|
+
--erp-drawer-offset: 24px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.erp-modal__header {
|
|
60
|
+
display: flex;
|
|
61
|
+
align-items: flex-start;
|
|
62
|
+
gap: var(--erp-space-3);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.erp-modal__icon {
|
|
66
|
+
display: grid;
|
|
67
|
+
place-items: center;
|
|
68
|
+
flex: none;
|
|
69
|
+
inline-size: var(--erp-space-12);
|
|
70
|
+
block-size: var(--erp-space-12);
|
|
71
|
+
border-radius: var(--erp-radius-full);
|
|
72
|
+
background: var(--erp-tone-bg);
|
|
73
|
+
color: var(--erp-tone-fg);
|
|
74
|
+
font-size: var(--erp-font-size-h2);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.erp-modal__title {
|
|
78
|
+
flex: 1;
|
|
79
|
+
margin: 0;
|
|
80
|
+
padding-block-start: var(--erp-space-2-5);
|
|
81
|
+
font-size: var(--erp-font-size-h3);
|
|
82
|
+
line-height: var(--erp-line-height-h3);
|
|
83
|
+
font-weight: var(--erp-font-weight-bold);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.erp-modal__description {
|
|
87
|
+
margin: 0;
|
|
88
|
+
color: var(--erp-color-text-secondary);
|
|
89
|
+
font-size: var(--erp-font-size-body);
|
|
90
|
+
line-height: var(--erp-line-height-body);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.erp-modal__footer {
|
|
94
|
+
display: flex;
|
|
95
|
+
flex-wrap: wrap;
|
|
96
|
+
gap: var(--erp-space-2);
|
|
97
|
+
padding-block-start: var(--erp-space-2);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@keyframes erp-fade-in {
|
|
101
|
+
from {
|
|
102
|
+
opacity: 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
@keyframes erp-dialog-in {
|
|
106
|
+
from {
|
|
107
|
+
opacity: 0;
|
|
108
|
+
transform: scale(0.97);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@media (max-width: 479px) {
|
|
113
|
+
.erp-dialog-backdrop:not(.erp-dialog-backdrop--end) {
|
|
114
|
+
place-items: end stretch;
|
|
115
|
+
padding: var(--erp-space-2);
|
|
116
|
+
}
|
|
117
|
+
.erp-modal--drawer {
|
|
118
|
+
border-radius: 0;
|
|
119
|
+
}
|
|
120
|
+
.erp-modal {
|
|
121
|
+
padding: var(--erp-space-5) var(--erp-space-4);
|
|
122
|
+
}
|
|
123
|
+
.erp-modal__footer .erp-btn {
|
|
124
|
+
flex: 1 1 100%;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@media (forced-colors: active) {
|
|
129
|
+
.erp-modal {
|
|
130
|
+
border: 1px solid CanvasText;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type UiLocale } from '@tmllak-erp/formatters';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { type ReactNode } from 'react';
|
|
4
|
+
import { type Direction } from '../internal/hooks.js';
|
|
5
|
+
export interface ErpContextValue {
|
|
6
|
+
locale: UiLocale;
|
|
7
|
+
direction: Direction;
|
|
8
|
+
/** Switches the interface language. Also sets direction to that language's default unless direction is controlled. */
|
|
9
|
+
setLocale: (locale: UiLocale) => void;
|
|
10
|
+
/** Overrides direction without changing the language. */
|
|
11
|
+
setDirection: (direction: Direction) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface ErpProviderProps {
|
|
14
|
+
/** Controlled language. Omit to let the provider own it, starting from `defaultLocale`. */
|
|
15
|
+
locale?: UiLocale;
|
|
16
|
+
/** Controlled direction. Omit to follow the language (Arabic → RTL, English → LTR). */
|
|
17
|
+
direction?: Direction;
|
|
18
|
+
defaultLocale?: UiLocale;
|
|
19
|
+
/** Start with this direction instead of the language's own. Choosing a language with `setLocale` resets it. */
|
|
20
|
+
defaultDirection?: Direction;
|
|
21
|
+
onLocaleChange?: (locale: UiLocale) => void;
|
|
22
|
+
onDirectionChange?: (direction: Direction) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Mirror `dir`, `lang`, and `data-erp-locale` onto `<html>` so portaled overlays match the page.
|
|
25
|
+
* Storybook turns this off and owns the document attributes itself.
|
|
26
|
+
*/
|
|
27
|
+
syncDocument?: boolean;
|
|
28
|
+
children: ReactNode;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Locale and writing direction for one application root.
|
|
32
|
+
* Sets the active catalog language before children render, and (by default) the document direction
|
|
33
|
+
* so dialogs portaled to `document.body` inherit it. Do not nest providers: the catalog slot is global.
|
|
34
|
+
*/
|
|
35
|
+
export declare function ErpProvider({ locale: localeProp, direction: directionProp, defaultLocale, defaultDirection, onLocaleChange, onDirectionChange, syncDocument, children, }: ErpProviderProps): React.JSX.Element;
|
|
36
|
+
/** The surrounding provider, or Arabic / RTL when the component is rendered on its own. */
|
|
37
|
+
export declare function useErp(): ErpContextValue;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { directionForLocale, registerRenderLocaleReader, setActiveLocale } from '@tmllak-erp/formatters';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { Children, cloneElement, createContext, isValidElement, useCallback, useContext, useMemo, useState } from 'react';
|
|
6
|
+
import { useIsomorphicLayoutEffect } from '../internal/hooks.js';
|
|
7
|
+
const ErpContext = createContext(null);
|
|
8
|
+
/**
|
|
9
|
+
* Server only: the language of the nearest provider for the component being rendered. React restores
|
|
10
|
+
* provider values when it resumes a suspended render, even where the request's async context is lost
|
|
11
|
+
* (Next.js streaming a Suspense boundary from the RSC payload). `use(Context)` exists from React 19;
|
|
12
|
+
* on React 18 this reports nothing and the request-scoped locale applies.
|
|
13
|
+
*
|
|
14
|
+
* `use` may only run while this React instance renders; elsewhere it logs "Invalid hook call". React 19
|
|
15
|
+
* keeps the active dispatcher in `H` of its internals, which is set exactly during a render. If that
|
|
16
|
+
* internal ever changes shape, the reader stays off and the request-scoped locale applies.
|
|
17
|
+
*/
|
|
18
|
+
if (typeof window === 'undefined') {
|
|
19
|
+
const react = React;
|
|
20
|
+
const use = react.use;
|
|
21
|
+
const internals = react.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
|
22
|
+
if (use && internals && 'H' in internals) {
|
|
23
|
+
registerRenderLocaleReader(() => {
|
|
24
|
+
if (!internals.H)
|
|
25
|
+
return undefined;
|
|
26
|
+
try {
|
|
27
|
+
// Reading context never suspends; the catch only covers calls made outside a render.
|
|
28
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
29
|
+
return use(ErpContext)?.locale;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function restoreAttribute(element, name, previous) {
|
|
38
|
+
if (previous === null)
|
|
39
|
+
element.removeAttribute(name);
|
|
40
|
+
else
|
|
41
|
+
element.setAttribute(name, previous);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Locale and writing direction for one application root.
|
|
45
|
+
* Sets the active catalog language before children render, and (by default) the document direction
|
|
46
|
+
* so dialogs portaled to `document.body` inherit it. Do not nest providers: the catalog slot is global.
|
|
47
|
+
*/
|
|
48
|
+
export function ErpProvider({ locale: localeProp, direction: directionProp, defaultLocale = 'ar', defaultDirection, onLocaleChange, onDirectionChange, syncDocument = true, children, }) {
|
|
49
|
+
const [localeState, setLocaleState] = useState(defaultLocale);
|
|
50
|
+
/** A direction chosen apart from the language; otherwise direction follows the active locale. */
|
|
51
|
+
const [directionOverride, setDirectionOverride] = useState(defaultDirection);
|
|
52
|
+
const locale = localeProp ?? localeState;
|
|
53
|
+
const direction = directionProp ?? directionOverride ?? directionForLocale(locale);
|
|
54
|
+
// Catalog reads during this render must see the provider's language.
|
|
55
|
+
setActiveLocale(locale);
|
|
56
|
+
const setLocale = useCallback((next) => {
|
|
57
|
+
onLocaleChange?.(next);
|
|
58
|
+
if (localeProp === undefined)
|
|
59
|
+
setLocaleState(next);
|
|
60
|
+
if (directionProp === undefined) {
|
|
61
|
+
setDirectionOverride(undefined);
|
|
62
|
+
onDirectionChange?.(directionForLocale(next));
|
|
63
|
+
}
|
|
64
|
+
}, [directionProp, localeProp, onDirectionChange, onLocaleChange]);
|
|
65
|
+
const setDirection = useCallback((next) => {
|
|
66
|
+
onDirectionChange?.(next);
|
|
67
|
+
if (directionProp === undefined)
|
|
68
|
+
setDirectionOverride(next);
|
|
69
|
+
}, [directionProp, onDirectionChange]);
|
|
70
|
+
useIsomorphicLayoutEffect(() => {
|
|
71
|
+
setActiveLocale(locale);
|
|
72
|
+
if (!syncDocument || typeof document === 'undefined')
|
|
73
|
+
return;
|
|
74
|
+
const root = document.documentElement;
|
|
75
|
+
const previous = {
|
|
76
|
+
dir: root.getAttribute('dir'),
|
|
77
|
+
lang: root.getAttribute('lang'),
|
|
78
|
+
locale: root.getAttribute('data-erp-locale'),
|
|
79
|
+
};
|
|
80
|
+
root.setAttribute('dir', direction);
|
|
81
|
+
root.setAttribute('lang', locale === 'ar' ? 'ar' : 'en');
|
|
82
|
+
root.setAttribute('data-erp-locale', locale);
|
|
83
|
+
return () => {
|
|
84
|
+
restoreAttribute(root, 'dir', previous.dir);
|
|
85
|
+
restoreAttribute(root, 'lang', previous.lang);
|
|
86
|
+
restoreAttribute(root, 'data-erp-locale', previous.locale);
|
|
87
|
+
};
|
|
88
|
+
}, [direction, locale, syncDocument]);
|
|
89
|
+
const value = useMemo(() => ({ locale, direction, setLocale, setDirection }), [direction, locale, setDirection, setLocale]);
|
|
90
|
+
return (_jsx(ErpContext.Provider, { value: value, children: _jsx(LocaleFrame, { children: children }) }));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Subscribes to the locale context and re-renders descendants.
|
|
94
|
+
* A provider alone does not re-render children that were created outside it, so catalogs
|
|
95
|
+
* read during render would stay on the previous language.
|
|
96
|
+
*/
|
|
97
|
+
function LocaleFrame({ children }) {
|
|
98
|
+
const { locale, direction } = useContext(ErpContext);
|
|
99
|
+
// New element objects so descendants that read catalogs re-render. React skips a child
|
|
100
|
+
// whose element reference was created outside the provider and did not change.
|
|
101
|
+
const refreshed = Children.map(children, (child) => (isValidElement(child) ? cloneElement(child) : child));
|
|
102
|
+
return (_jsx("div", { dir: direction, lang: locale === 'ar' ? 'ar' : 'en', "data-erp-locale": locale, style: { display: 'contents' }, children: refreshed }));
|
|
103
|
+
}
|
|
104
|
+
const fallback = {
|
|
105
|
+
locale: 'ar',
|
|
106
|
+
direction: 'rtl',
|
|
107
|
+
setLocale: () => undefined,
|
|
108
|
+
setDirection: () => undefined,
|
|
109
|
+
};
|
|
110
|
+
/** The surrounding provider, or Arabic / RTL when the component is rendered on its own. */
|
|
111
|
+
export function useErp() {
|
|
112
|
+
return useContext(ErpContext) ?? fallback;
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=ErpProvider.js.map
|