@nordmanai/nif 0.1.0 → 0.2.1
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 +18 -0
- package/bin/nif.mjs +196 -0
- package/dist/index.d.ts +30 -1
- package/dist/index.js +9661 -2499
- package/dist/styles.css +1 -1
- package/dist/tokens.css +4 -1
- package/dist/ui/components/nm-ai/nm-ai.d.ts +7 -7
- package/dist/ui/components/nm-brand-logo/nm-brand-logo.d.ts +10 -0
- package/dist/ui/components/nm-breadcrumb/nm-breadcrumb.d.ts +11 -0
- package/dist/ui/components/nm-button/nm-button.d.ts +2 -0
- package/dist/ui/components/nm-button-group/nm-button-group.d.ts +17 -0
- package/dist/ui/components/nm-calendar/nm-calendar.d.ts +3 -0
- package/dist/ui/components/nm-card/nm-card.d.ts +34 -0
- package/dist/ui/components/nm-chip/nm-chip.d.ts +38 -0
- package/dist/ui/components/nm-code-block/nm-code-block.d.ts +55 -0
- package/dist/ui/components/nm-color-picker/nm-color-picker.d.ts +15 -0
- package/dist/ui/components/nm-combobox/nm-combobox.d.ts +26 -0
- package/dist/ui/components/nm-command/nm-command.d.ts +37 -0
- package/dist/ui/components/nm-composer/nm-composer.d.ts +4 -0
- package/dist/ui/components/nm-context-menu/nm-context-menu.d.ts +9 -0
- package/dist/ui/components/nm-date-picker/nm-date-picker.d.ts +35 -0
- package/dist/ui/components/nm-dialog/nm-dialog.d.ts +13 -0
- package/dist/ui/components/nm-field/nm-field.d.ts +2 -0
- package/dist/ui/components/nm-form-field/nm-form-field.d.ts +18 -0
- package/dist/ui/components/nm-gallery/nm-gallery.d.ts +8 -0
- package/dist/ui/components/nm-input/nm-input.d.ts +5 -0
- package/dist/ui/components/nm-input-group/nm-input-group.d.ts +9 -0
- package/dist/ui/components/nm-label/nm-label.d.ts +2 -0
- package/dist/ui/components/nm-menubar/nm-menubar.d.ts +9 -0
- package/dist/ui/components/nm-native-select/nm-native-select.d.ts +5 -0
- package/dist/ui/components/nm-panel/nm-panel.d.ts +14 -0
- package/dist/ui/components/nm-prose/nm-prose.d.ts +6 -0
- package/dist/ui/components/nm-resize-handle/nm-resize-handle.d.ts +18 -0
- package/dist/ui/components/nm-select/nm-select.d.ts +22 -0
- package/dist/ui/components/nm-side-panel/nm-side-panel.d.ts +33 -0
- package/dist/ui/components/nm-slider/nm-slider.d.ts +5 -1
- package/dist/ui/components/nm-status-bar/nm-status-bar.d.ts +8 -0
- package/dist/ui/components/nm-table/nm-table.d.ts +38 -0
- package/dist/ui/components/nm-textarea/nm-textarea.d.ts +2 -0
- package/dist/ui/components/nm-toolbar/nm-toolbar.d.ts +21 -0
- package/dist/ui/config/nm-ai.d.ts +0 -3
- package/dist/ui/config/nm-appearance.d.ts +36 -1
- package/dist/ui/config/nm-button.d.ts +2 -1
- package/dist/ui/config/nm-composer.d.ts +1 -2
- package/dist/ui/config/nm-field.d.ts +2 -0
- package/dist/ui/config/nm-icons.d.ts +13 -1
- package/dist/ui/config/nm-radius.d.ts +4 -4
- package/dist/ui/config/nm-side-panel.d.ts +33 -0
- package/dist/ui/lib/appearance/appearanceState.d.ts +1 -0
- package/dist/ui/lib/appearance/deriveTokens.d.ts +2 -0
- package/package.json +12 -4
- package/registry/index.json +1634 -0
- package/registry/tokens.css +72 -0
- package/registry/ui/components/nm-ai/nm-ai.css +358 -0
- package/registry/ui/components/nm-ai/nm-ai.tsx +632 -0
- package/registry/ui/components/nm-app-panel/nm-app-panel.css +169 -0
- package/registry/ui/components/nm-ask/nm-ask.css +277 -0
- package/registry/ui/components/nm-avatar/nm-avatar.css +85 -0
- package/registry/ui/components/nm-avatar/nm-avatar.tsx +30 -0
- package/registry/ui/components/nm-bar-overflow/nm-bar-overflow.css +43 -0
- package/registry/ui/components/nm-bar-overflow/nm-bar-overflow.tsx +61 -0
- package/registry/ui/components/nm-bar-overflow/use-bar-overflow.ts +92 -0
- package/registry/ui/components/nm-brand-logo/nm-brand-logo.css +20 -0
- package/registry/ui/components/nm-brand-logo/nm-brand-logo.tsx +21 -0
- package/registry/ui/components/nm-breadcrumb/nm-breadcrumb.css +57 -0
- package/registry/ui/components/nm-breadcrumb/nm-breadcrumb.tsx +42 -0
- package/registry/ui/components/nm-button/nm-button.css +106 -0
- package/registry/ui/components/nm-button/nm-button.tsx +58 -0
- package/registry/ui/components/nm-button-group/nm-button-group.css +98 -0
- package/registry/ui/components/nm-button-group/nm-button-group.tsx +32 -0
- package/registry/ui/components/nm-calendar/nm-calendar.css +178 -0
- package/registry/ui/components/nm-calendar/nm-calendar.tsx +43 -0
- package/registry/ui/components/nm-card/nm-card.css +130 -0
- package/registry/ui/components/nm-card/nm-card.tsx +83 -0
- package/registry/ui/components/nm-chatbox/nm-chatbox-icon.tsx +39 -0
- package/registry/ui/components/nm-chatbox/nm-chatbox.css +682 -0
- package/registry/ui/components/nm-chatbox/nm-chatbox.tsx +101 -0
- package/registry/ui/components/nm-checkbox/nm-checkbox.css +61 -0
- package/registry/ui/components/nm-checkbox/nm-checkbox.tsx +14 -0
- package/registry/ui/components/nm-chip/nm-chip.css +112 -0
- package/registry/ui/components/nm-chip/nm-chip.tsx +86 -0
- package/registry/ui/components/nm-code-block/nm-code-block.css +240 -0
- package/registry/ui/components/nm-code-block/nm-code-block.tsx +196 -0
- package/registry/ui/components/nm-collection/nm-collection-bar.tsx +65 -0
- package/registry/ui/components/nm-collection/nm-collection-grid.tsx +69 -0
- package/registry/ui/components/nm-collection/nm-collection-query.tsx +99 -0
- package/registry/ui/components/nm-collection/nm-collection-row-menu.tsx +55 -0
- package/registry/ui/components/nm-collection/nm-collection-table.tsx +99 -0
- package/registry/ui/components/nm-collection/nm-collection-tile-actions.tsx +50 -0
- package/registry/ui/components/nm-collection/nm-collection-title.tsx +25 -0
- package/registry/ui/components/nm-collection/nm-collection.css +353 -0
- package/registry/ui/components/nm-collection/use-collection-scroll-reveal.ts +38 -0
- package/registry/ui/components/nm-color-picker/nm-color-picker.css +67 -0
- package/registry/ui/components/nm-color-picker/nm-color-picker.tsx +79 -0
- package/registry/ui/components/nm-combobox/nm-combobox.css +72 -0
- package/registry/ui/components/nm-combobox/nm-combobox.tsx +80 -0
- package/registry/ui/components/nm-command/nm-command.css +190 -0
- package/registry/ui/components/nm-command/nm-command.tsx +125 -0
- package/registry/ui/components/nm-composer/nm-composer.css +178 -0
- package/registry/ui/components/nm-composer/nm-composer.tsx +151 -0
- package/registry/ui/components/nm-context-menu/nm-context-menu.tsx +25 -0
- package/registry/ui/components/nm-date-picker/nm-date-picker.css +140 -0
- package/registry/ui/components/nm-date-picker/nm-date-picker.tsx +153 -0
- package/registry/ui/components/nm-dialog/nm-dialog.css +84 -0
- package/registry/ui/components/nm-dialog/nm-dialog.tsx +40 -0
- package/registry/ui/components/nm-dropdown/nm-dropdown-item.ts +68 -0
- package/registry/ui/components/nm-dropdown/nm-dropdown-options.tsx +242 -0
- package/registry/ui/components/nm-dropdown/nm-dropdown-panel.tsx +171 -0
- package/registry/ui/components/nm-dropdown/nm-dropdown-placement.ts +157 -0
- package/registry/ui/components/nm-dropdown/nm-dropdown.css +312 -0
- package/registry/ui/components/nm-dropdown/nm-dropdown.tsx +412 -0
- package/registry/ui/components/nm-dropdown-menu/nm-dropdown-menu.css +145 -0
- package/registry/ui/components/nm-dropdown-menu/nm-dropdown-menu.tsx +118 -0
- package/registry/ui/components/nm-field/nm-field.css +356 -0
- package/registry/ui/components/nm-field/nm-field.tsx +355 -0
- package/registry/ui/components/nm-form-field/nm-form-field.css +103 -0
- package/registry/ui/components/nm-form-field/nm-form-field.tsx +71 -0
- package/registry/ui/components/nm-gallery/nm-gallery.css +66 -0
- package/registry/ui/components/nm-gallery/nm-gallery.tsx +31 -0
- package/registry/ui/components/nm-hover-card/nm-hover-card.css +26 -0
- package/registry/ui/components/nm-hover-card/nm-hover-card.tsx +28 -0
- package/registry/ui/components/nm-icon/nm-icon.css +6 -0
- package/registry/ui/components/nm-icon/nm-icon.tsx +69 -0
- package/registry/ui/components/nm-icon/nm-lucide.tsx +180 -0
- package/registry/ui/components/nm-icon-border/nm-icon-border.tsx +56 -0
- package/registry/ui/components/nm-input/nm-input.css +75 -0
- package/registry/ui/components/nm-input/nm-input.tsx +7 -0
- package/registry/ui/components/nm-input-group/nm-input-group.css +66 -0
- package/registry/ui/components/nm-input-group/nm-input-group.tsx +20 -0
- package/registry/ui/components/nm-label/nm-label.css +11 -0
- package/registry/ui/components/nm-label/nm-label.tsx +6 -0
- package/registry/ui/components/nm-list-item/nm-list-item.css +177 -0
- package/registry/ui/components/nm-list-item/nm-list-item.tsx +112 -0
- package/registry/ui/components/nm-menubar/nm-menubar.css +32 -0
- package/registry/ui/components/nm-menubar/nm-menubar.tsx +19 -0
- package/registry/ui/components/nm-message/nm-message-actions.tsx +24 -0
- package/registry/ui/components/nm-message/nm-message-meta.tsx +49 -0
- package/registry/ui/components/nm-message/nm-message.css +686 -0
- package/registry/ui/components/nm-message/nm-text-shimmer.tsx +6 -0
- package/registry/ui/components/nm-message/nm-trace.tsx +219 -0
- package/registry/ui/components/nm-modal/nm-modal.css +763 -0
- package/registry/ui/components/nm-modal/nm-modal.tsx +497 -0
- package/registry/ui/components/nm-native-select/nm-native-select.css +47 -0
- package/registry/ui/components/nm-native-select/nm-native-select.tsx +23 -0
- package/registry/ui/components/nm-panel/nm-panel.css +73 -0
- package/registry/ui/components/nm-panel/nm-panel.tsx +35 -0
- package/registry/ui/components/nm-panel-bar/nm-panel-bar.css +20 -0
- package/registry/ui/components/nm-panel-bar/nm-panel-bar.tsx +48 -0
- package/registry/ui/components/nm-popover/nm-popover.css +43 -0
- package/registry/ui/components/nm-popover/nm-popover.tsx +40 -0
- package/registry/ui/components/nm-progress/nm-progress.css +21 -0
- package/registry/ui/components/nm-progress/nm-progress.tsx +14 -0
- package/registry/ui/components/nm-prose/nm-prose.css +81 -0
- package/registry/ui/components/nm-prose/nm-prose.tsx +10 -0
- package/registry/ui/components/nm-questionnaire/nm-questionnaire.css +182 -0
- package/registry/ui/components/nm-questionnaire/nm-questionnaire.tsx +221 -0
- package/registry/ui/components/nm-radio-group/nm-radio-group.css +48 -0
- package/registry/ui/components/nm-radio-group/nm-radio-group.tsx +15 -0
- package/registry/ui/components/nm-rail-icon/nm-rail-icon.css +6 -0
- package/registry/ui/components/nm-rail-icon/nm-rail-icon.tsx +28 -0
- package/registry/ui/components/nm-resize-handle/nm-resize-handle.css +45 -0
- package/registry/ui/components/nm-resize-handle/nm-resize-handle.tsx +102 -0
- package/registry/ui/components/nm-segmented/nm-segmented.css +104 -0
- package/registry/ui/components/nm-segmented/nm-segmented.tsx +77 -0
- package/registry/ui/components/nm-select/nm-select.css +78 -0
- package/registry/ui/components/nm-select/nm-select.tsx +64 -0
- package/registry/ui/components/nm-separator/nm-separator.css +14 -0
- package/registry/ui/components/nm-separator/nm-separator.tsx +6 -0
- package/registry/ui/components/nm-side-panel/nm-side-panel.css +93 -0
- package/registry/ui/components/nm-side-panel/nm-side-panel.tsx +86 -0
- package/registry/ui/components/nm-slider/nm-slider.css +53 -0
- package/registry/ui/components/nm-slider/nm-slider.tsx +40 -0
- package/registry/ui/components/nm-small-icon-button/nm-small-icon-button.tsx +66 -0
- package/registry/ui/components/nm-status-bar/nm-status-bar.css +50 -0
- package/registry/ui/components/nm-status-bar/nm-status-bar.tsx +28 -0
- package/registry/ui/components/nm-switch/nm-switch.css +45 -0
- package/registry/ui/components/nm-switch/nm-switch.tsx +10 -0
- package/registry/ui/components/nm-table/nm-table.css +155 -0
- package/registry/ui/components/nm-table/nm-table.tsx +95 -0
- package/registry/ui/components/nm-tabs/nm-tabs.css +28 -0
- package/registry/ui/components/nm-tabs/nm-tabs.tsx +32 -0
- package/registry/ui/components/nm-textarea/nm-textarea.css +41 -0
- package/registry/ui/components/nm-textarea/nm-textarea.tsx +6 -0
- package/registry/ui/components/nm-toggle/nm-toggle.css +55 -0
- package/registry/ui/components/nm-toggle/nm-toggle.tsx +16 -0
- package/registry/ui/components/nm-toolbar/nm-toolbar.css +42 -0
- package/registry/ui/components/nm-toolbar/nm-toolbar.tsx +54 -0
- package/registry/ui/components/nm-tooltip/nm-tooltip.css +37 -0
- package/registry/ui/components/nm-tooltip/nm-tooltip.tsx +35 -0
- package/registry/ui/components/nm-top-bar/nm-top-bar.css +29 -0
- package/registry/ui/components/nm-top-bar/nm-top-bar.tsx +34 -0
- package/registry/ui/components/nordman-icon-button/nordman-icon-button.css +119 -0
- package/registry/ui/components/nordman-icon-button/nordman-icon-button.tsx +185 -0
- package/registry/ui/components/nordman-login/nordman-login.css +195 -0
- package/registry/ui/components/nordman-login/nordman-login.tsx +136 -0
- package/registry/ui/components/nordman-login-field/nordman-login-field.tsx +55 -0
- package/registry/ui/components/nordman-login-forgot/nordman-login-forgot.tsx +56 -0
- package/registry/ui/components/nordman-login-google/nordman-login-google.tsx +28 -0
- package/registry/ui/components/nordman-login-hero/nordman-login-hero.tsx +38 -0
- package/registry/ui/components/nordman-login-register/nordman-login-register.tsx +70 -0
- package/registry/ui/components/nordman-login-reset/nordman-login-reset.tsx +71 -0
- package/registry/ui/components/nordman-login-reveal/nordman-login-reveal.tsx +41 -0
- package/registry/ui/components/nordman-login-sign-in/nordman-login-sign-in.tsx +69 -0
- package/registry/ui/components/nordman-toggle/nordman-toggle.css +28 -0
- package/registry/ui/components/nordman-toggle/nordman-toggle.tsx +35 -0
- package/registry/ui/config/nm-ai.ts +59 -0
- package/registry/ui/config/nm-appearance.ts +275 -0
- package/registry/ui/config/nm-bar-overflow.ts +10 -0
- package/registry/ui/config/nm-button.ts +38 -0
- package/registry/ui/config/nm-chatbox-icons.ts +67 -0
- package/registry/ui/config/nm-chatbox.ts +42 -0
- package/registry/ui/config/nm-collection.ts +101 -0
- package/registry/ui/config/nm-composer.ts +39 -0
- package/registry/ui/config/nm-dropdown.ts +62 -0
- package/registry/ui/config/nm-field.ts +43 -0
- package/registry/ui/config/nm-icon-button.ts +35 -0
- package/registry/ui/config/nm-icons.ts +417 -0
- package/registry/ui/config/nm-list-item.ts +14 -0
- package/registry/ui/config/nm-message.ts +106 -0
- package/registry/ui/config/nm-modal.ts +76 -0
- package/registry/ui/config/nm-panel-bar.ts +11 -0
- package/registry/ui/config/nm-questionnaire.ts +53 -0
- package/registry/ui/config/nm-radius.ts +56 -0
- package/registry/ui/config/nm-rail-icons.ts +27 -0
- package/registry/ui/config/nm-segmented.ts +19 -0
- package/registry/ui/config/nm-side-panel.ts +16 -0
- package/registry/ui/config/nm-site-palette.ts +30 -0
- package/registry/ui/config/nm-small-icon-button.ts +17 -0
- package/registry/ui/config/nm-tabs.ts +9 -0
- package/registry/ui/config/nm-top-bar.ts +4 -0
- package/registry/ui/config/nordman-chrome.ts +14 -0
- package/registry/ui/config/nordman-login.ts +28 -0
- package/registry/ui/content/nm-modal.ts +5 -0
- package/registry/ui/content/nordman-login.ts +85 -0
- package/registry/ui/kit-logger.ts +1 -0
- package/registry/ui/lib/appearance/appearanceState.ts +240 -0
- package/registry/ui/lib/appearance/applyAppearance.ts +36 -0
- package/registry/ui/lib/appearance/cloudOrbAppearance.ts +36 -0
- package/registry/ui/lib/appearance/color.ts +96 -0
- package/registry/ui/lib/appearance/deriveTokens.ts +218 -0
- package/registry/ui/lib/appearance/index.ts +6 -0
- package/registry/ui/lib/appearance/markTokens.ts +49 -0
- package/registry/ui/lib/appearance/readLayoutMetrics.ts +28 -0
- package/registry/ui/lib/bar-overflow.ts +41 -0
- package/registry/ui/lib/logger.ts +53 -0
- package/registry/ui/lib/menu-motion.ts +187 -0
- package/registry/ui/lib/nm-class.ts +4 -0
- package/registry/ui/lib/nordman-ui-locale.ts +43 -0
- package/registry/ui/styles/interface-theme.css +196 -0
- package/registry/ui/styles/light-appearance.css +72 -0
- package/registry/ui/styles/tokens.css +424 -0
- package/registry/ui/styles/utilities.css +12 -0
- package/dist/ui/components/nm-accordion/nm-accordion.d.ts +0 -6
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useCallback,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useId,
|
|
7
|
+
useLayoutEffect,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
type KeyboardEvent,
|
|
11
|
+
type ReactNode,
|
|
12
|
+
} from 'react';
|
|
13
|
+
import { createPortal } from 'react-dom';
|
|
14
|
+
import type { NmIconId } from '../../config/nm-icons.ts';
|
|
15
|
+
import {
|
|
16
|
+
NM_MODAL_ACTION,
|
|
17
|
+
NM_MODAL_CLASSES,
|
|
18
|
+
NM_MODAL_FOOTER,
|
|
19
|
+
NM_MODAL_SCROLL_IDLE_MS,
|
|
20
|
+
NM_MODAL_SIZE,
|
|
21
|
+
NM_MODAL_TITLE,
|
|
22
|
+
type NmModalActionTone,
|
|
23
|
+
type NmModalFooter,
|
|
24
|
+
type NmModalSize,
|
|
25
|
+
type NmModalTitleSize,
|
|
26
|
+
} from '../../config/nm-modal.ts';
|
|
27
|
+
import { NordmanIconButton } from '../nordman-icon-button/nordman-icon-button.tsx';
|
|
28
|
+
import { NM_ICON_BUTTON_TONES } from '../../config/nm-icon-button.ts';
|
|
29
|
+
import { nmModalSavedLabel } from '../../content/nm-modal.ts';
|
|
30
|
+
import { createLogger } from '../../kit-logger.ts';
|
|
31
|
+
import { NmIcon } from '../nm-icon/nm-icon.tsx';
|
|
32
|
+
import './nm-modal.css';
|
|
33
|
+
import { useNordmanUiLocale } from '../../lib/nordman-ui-locale.ts';
|
|
34
|
+
|
|
35
|
+
const logger = createLogger('interface-nm-modal');
|
|
36
|
+
const SAVE_CONFIRMED_MS = 1200;
|
|
37
|
+
const SAVE_SPINNER_MS = 400;
|
|
38
|
+
|
|
39
|
+
type SavePhase = 'idle' | 'saving' | 'saved';
|
|
40
|
+
|
|
41
|
+
const SavePhaseContext = createContext<{
|
|
42
|
+
phase: SavePhase;
|
|
43
|
+
track: <T>(work: Promise<T>) => Promise<T>;
|
|
44
|
+
}>({
|
|
45
|
+
phase: 'idle',
|
|
46
|
+
track: async (work) => work,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const openTracks: Array<<T>(work: Promise<T>) => Promise<T>> = [];
|
|
50
|
+
|
|
51
|
+
const SaveDirtyContext = createContext(false);
|
|
52
|
+
const dirtyReporters: Array<(dirty: boolean) => void> = [];
|
|
53
|
+
const dirtyWatchers = new Map<number, boolean>();
|
|
54
|
+
let dirtyWatcherId = 0;
|
|
55
|
+
|
|
56
|
+
function reportedDirty(): boolean {
|
|
57
|
+
return [...dirtyWatchers.values()].some((changed) => changed);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function publishDirty(): void {
|
|
61
|
+
const dirty = reportedDirty();
|
|
62
|
+
dirtyReporters[dirtyReporters.length - 1]?.(dirty);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function useReportSaveDirty(dirty: boolean, enabled = true): void {
|
|
66
|
+
const watcher = useRef(0);
|
|
67
|
+
if (watcher.current === 0) {
|
|
68
|
+
dirtyWatcherId += 1;
|
|
69
|
+
watcher.current = dirtyWatcherId;
|
|
70
|
+
}
|
|
71
|
+
useLayoutEffect(() => {
|
|
72
|
+
const id = watcher.current;
|
|
73
|
+
if (!enabled) {
|
|
74
|
+
dirtyWatchers.delete(id);
|
|
75
|
+
publishDirty();
|
|
76
|
+
return () => {
|
|
77
|
+
dirtyWatchers.delete(id);
|
|
78
|
+
publishDirty();
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
dirtyWatchers.set(id, dirty);
|
|
82
|
+
publishDirty();
|
|
83
|
+
return () => {
|
|
84
|
+
dirtyWatchers.delete(id);
|
|
85
|
+
publishDirty();
|
|
86
|
+
};
|
|
87
|
+
}, [dirty, enabled]);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function useTrackSave(): <T>(work: Promise<T>) => Promise<T> {
|
|
91
|
+
const local = useContext(SavePhaseContext).track;
|
|
92
|
+
return (work) => (openTracks[openTracks.length - 1] ?? local)(work);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function SavePhaseProvider(props: { children: ReactNode }): ReactNode {
|
|
96
|
+
const [phase, setPhase] = useState<SavePhase>('idle');
|
|
97
|
+
const [dirty, setDirty] = useState(false);
|
|
98
|
+
const reportDirty = useCallback((next: boolean) => {
|
|
99
|
+
setDirty((current) => (current === next ? current : next));
|
|
100
|
+
}, []);
|
|
101
|
+
const timer = useRef<number | null>(null);
|
|
102
|
+
|
|
103
|
+
const clearTimer = () => {
|
|
104
|
+
if (timer.current != null) {
|
|
105
|
+
window.clearTimeout(timer.current);
|
|
106
|
+
timer.current = null;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
useEffect(() => clearTimer, []);
|
|
111
|
+
|
|
112
|
+
const track = useCallback(<T,>(work: Promise<T>) => {
|
|
113
|
+
clearTimer();
|
|
114
|
+
setPhase('saving');
|
|
115
|
+
const started = Date.now();
|
|
116
|
+
logger.debug('save', 'start');
|
|
117
|
+
return work.then(
|
|
118
|
+
(value) =>
|
|
119
|
+
new Promise<T>((resolve) => {
|
|
120
|
+
const remaining = Math.max(0, SAVE_SPINNER_MS - (Date.now() - started));
|
|
121
|
+
timer.current = window.setTimeout(() => {
|
|
122
|
+
logger.info('save', 'confirmed');
|
|
123
|
+
setPhase('saved');
|
|
124
|
+
timer.current = window.setTimeout(() => {
|
|
125
|
+
setPhase('idle');
|
|
126
|
+
timer.current = null;
|
|
127
|
+
resolve(value);
|
|
128
|
+
}, SAVE_CONFIRMED_MS);
|
|
129
|
+
}, remaining);
|
|
130
|
+
}),
|
|
131
|
+
(error: unknown) => {
|
|
132
|
+
logger.warn('save', 'failed', { error });
|
|
133
|
+
setPhase('idle');
|
|
134
|
+
throw error;
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
}, []);
|
|
138
|
+
|
|
139
|
+
useEffect(() => {
|
|
140
|
+
openTracks.push(track);
|
|
141
|
+
return () => {
|
|
142
|
+
const index = openTracks.lastIndexOf(track);
|
|
143
|
+
if (index >= 0) {
|
|
144
|
+
openTracks.splice(index, 1);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}, [track]);
|
|
148
|
+
|
|
149
|
+
useLayoutEffect(() => {
|
|
150
|
+
dirtyReporters.push(reportDirty);
|
|
151
|
+
reportDirty(reportedDirty());
|
|
152
|
+
return () => {
|
|
153
|
+
const index = dirtyReporters.lastIndexOf(reportDirty);
|
|
154
|
+
if (index >= 0) {
|
|
155
|
+
dirtyReporters.splice(index, 1);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}, [reportDirty]);
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<SavePhaseContext.Provider value={{ phase, track }}>
|
|
162
|
+
<SaveDirtyContext.Provider value={dirty}>{props.children}</SaveDirtyContext.Provider>
|
|
163
|
+
</SavePhaseContext.Provider>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const FOCUSABLE =
|
|
168
|
+
'a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
169
|
+
|
|
170
|
+
export type NmModalProps = {
|
|
171
|
+
open: boolean;
|
|
172
|
+
title: string;
|
|
173
|
+
titleSize?: NmModalTitleSize;
|
|
174
|
+
size?: NmModalSize;
|
|
175
|
+
footer?: NmModalFooter;
|
|
176
|
+
paneTitle?: ReactNode;
|
|
177
|
+
titleEnd?: ReactNode;
|
|
178
|
+
leading?: ReactNode;
|
|
179
|
+
onClose: () => void;
|
|
180
|
+
children: ReactNode;
|
|
181
|
+
menu?: ReactNode;
|
|
182
|
+
actions?: ReactNode;
|
|
183
|
+
testId?: string;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
function focusableIn(root: HTMLElement): HTMLElement[] {
|
|
187
|
+
return [...root.querySelectorAll<HTMLElement>(FOCUSABLE)].filter((node) => node.tabIndex !== -1);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function NmModal(props: NmModalProps): ReactNode {
|
|
191
|
+
const { open, onClose, title } = props;
|
|
192
|
+
const titleId = useId();
|
|
193
|
+
const panelRef = useRef<HTMLDivElement>(null);
|
|
194
|
+
const restoreFocus = useRef<HTMLElement | null>(null);
|
|
195
|
+
const size = props.size ?? (props.menu != null ? NM_MODAL_SIZE.menu : NM_MODAL_SIZE.simple);
|
|
196
|
+
const footer = props.footer ?? NM_MODAL_FOOTER.modal;
|
|
197
|
+
const titleSize =
|
|
198
|
+
props.titleSize ??
|
|
199
|
+
(size === NM_MODAL_SIZE.simple ? NM_MODAL_TITLE.section : NM_MODAL_TITLE.page);
|
|
200
|
+
const panelClass = [
|
|
201
|
+
NM_MODAL_CLASSES.root,
|
|
202
|
+
size === NM_MODAL_SIZE.simple ? NM_MODAL_CLASSES.simple : '',
|
|
203
|
+
size === NM_MODAL_SIZE.menu || size === NM_MODAL_SIZE.wide ? NM_MODAL_CLASSES.menu : '',
|
|
204
|
+
size === NM_MODAL_SIZE.wide ? NM_MODAL_CLASSES.wide : '',
|
|
205
|
+
]
|
|
206
|
+
.filter((value) => value !== '')
|
|
207
|
+
.join(' ');
|
|
208
|
+
const titleClass = [
|
|
209
|
+
NM_MODAL_CLASSES.title,
|
|
210
|
+
titleSize === NM_MODAL_TITLE.page ? NM_MODAL_CLASSES.titlePage : '',
|
|
211
|
+
]
|
|
212
|
+
.filter((value) => value !== '')
|
|
213
|
+
.join(' ');
|
|
214
|
+
const footerClass = [
|
|
215
|
+
NM_MODAL_CLASSES.footer,
|
|
216
|
+
footer === NM_MODAL_FOOTER.pane ? NM_MODAL_CLASSES.footerPane : '',
|
|
217
|
+
]
|
|
218
|
+
.filter((value) => value !== '')
|
|
219
|
+
.join(' ');
|
|
220
|
+
|
|
221
|
+
useEffect(() => {
|
|
222
|
+
logger.debug('presence', title, { open, size, footer });
|
|
223
|
+
}, [open, title, size, footer]);
|
|
224
|
+
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
const root = panelRef.current;
|
|
227
|
+
if (!open || root == null) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const idle = new Map<HTMLElement, number>();
|
|
231
|
+
const bound = new Set<HTMLElement>();
|
|
232
|
+
const onScroll = (event: Event) => {
|
|
233
|
+
const node = event.currentTarget;
|
|
234
|
+
if (!(node instanceof HTMLElement)) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
node.dataset.scrolling = 'true';
|
|
238
|
+
const pending = idle.get(node);
|
|
239
|
+
if (pending != null) {
|
|
240
|
+
window.clearTimeout(pending);
|
|
241
|
+
}
|
|
242
|
+
idle.set(
|
|
243
|
+
node,
|
|
244
|
+
window.setTimeout(() => {
|
|
245
|
+
delete node.dataset.scrolling;
|
|
246
|
+
idle.delete(node);
|
|
247
|
+
}, NM_MODAL_SCROLL_IDLE_MS),
|
|
248
|
+
);
|
|
249
|
+
};
|
|
250
|
+
const bind = () => {
|
|
251
|
+
const nodes = [
|
|
252
|
+
root,
|
|
253
|
+
...root.querySelectorAll<HTMLElement>(
|
|
254
|
+
'.nm-modal__layout, .nm-modal__menu, .nm-modal__body, .nm-modal__list, .nm-modal__groups, .nm-field__menu',
|
|
255
|
+
),
|
|
256
|
+
];
|
|
257
|
+
for (const node of nodes) {
|
|
258
|
+
if (bound.has(node)) {
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
node.addEventListener('scroll', onScroll);
|
|
262
|
+
bound.add(node);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
bind();
|
|
266
|
+
const observer = new MutationObserver(bind);
|
|
267
|
+
observer.observe(root, { childList: true, subtree: true });
|
|
268
|
+
return () => {
|
|
269
|
+
observer.disconnect();
|
|
270
|
+
for (const node of bound) {
|
|
271
|
+
node.removeEventListener('scroll', onScroll);
|
|
272
|
+
delete node.dataset.scrolling;
|
|
273
|
+
}
|
|
274
|
+
for (const timer of idle.values()) {
|
|
275
|
+
window.clearTimeout(timer);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}, [open]);
|
|
279
|
+
|
|
280
|
+
useEffect(() => {
|
|
281
|
+
if (!open) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const onKey = (event: globalThis.KeyboardEvent) => {
|
|
285
|
+
if (event.key !== 'Escape') {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
event.preventDefault();
|
|
289
|
+
onClose();
|
|
290
|
+
};
|
|
291
|
+
document.addEventListener('keydown', onKey);
|
|
292
|
+
return () => document.removeEventListener('keydown', onKey);
|
|
293
|
+
}, [open, onClose]);
|
|
294
|
+
|
|
295
|
+
useLayoutEffect(() => {
|
|
296
|
+
if (!props.open) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const panel = panelRef.current;
|
|
300
|
+
if (panel == null) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const active = document.activeElement;
|
|
304
|
+
restoreFocus.current = active instanceof HTMLElement ? active : null;
|
|
305
|
+
const first = focusableIn(panel)[0];
|
|
306
|
+
(first ?? panel).focus({ preventScroll: true });
|
|
307
|
+
return () => {
|
|
308
|
+
restoreFocus.current?.focus({ preventScroll: true });
|
|
309
|
+
restoreFocus.current = null;
|
|
310
|
+
};
|
|
311
|
+
}, [props.open]);
|
|
312
|
+
|
|
313
|
+
const hasPaneTitle = props.paneTitle != null;
|
|
314
|
+
useLayoutEffect(() => {
|
|
315
|
+
const panel = panelRef.current;
|
|
316
|
+
if (!props.open || panel == null) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
panel.scrollTop = 0;
|
|
320
|
+
for (const node of panel.querySelectorAll<HTMLElement>('.nm-modal__layout, .nm-modal__body')) {
|
|
321
|
+
node.scrollTop = 0;
|
|
322
|
+
}
|
|
323
|
+
}, [props.open, size, footer, hasPaneTitle]);
|
|
324
|
+
|
|
325
|
+
const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
|
|
326
|
+
if (event.key !== 'Tab') {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
const panel = panelRef.current;
|
|
330
|
+
if (panel == null) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const items = focusableIn(panel);
|
|
334
|
+
if (items.length === 0) {
|
|
335
|
+
event.preventDefault();
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const first = items[0];
|
|
339
|
+
const last = items[items.length - 1];
|
|
340
|
+
if (first == null || last == null) {
|
|
341
|
+
event.preventDefault();
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const active = document.activeElement;
|
|
345
|
+
if (event.shiftKey && (active === first || active === panel)) {
|
|
346
|
+
event.preventDefault();
|
|
347
|
+
last.focus({ preventScroll: true });
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (!event.shiftKey && active === last) {
|
|
351
|
+
event.preventDefault();
|
|
352
|
+
first.focus({ preventScroll: true });
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
if (typeof document === 'undefined') {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const showFooter = props.actions != null || props.leading != null;
|
|
361
|
+
const body = (
|
|
362
|
+
<>
|
|
363
|
+
{props.paneTitle != null ? (
|
|
364
|
+
<div className={NM_MODAL_CLASSES.paneTitle}>{props.paneTitle}</div>
|
|
365
|
+
) : null}
|
|
366
|
+
<div className={NM_MODAL_CLASSES.body}>{props.children}</div>
|
|
367
|
+
</>
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
return createPortal(
|
|
371
|
+
props.open ? (
|
|
372
|
+
<SavePhaseProvider>
|
|
373
|
+
<div className={NM_MODAL_CLASSES.layer}>
|
|
374
|
+
<div
|
|
375
|
+
className={NM_MODAL_CLASSES.backdrop}
|
|
376
|
+
aria-hidden="true"
|
|
377
|
+
onMouseDown={props.onClose}
|
|
378
|
+
/>
|
|
379
|
+
<div
|
|
380
|
+
ref={panelRef}
|
|
381
|
+
role="dialog"
|
|
382
|
+
aria-modal="true"
|
|
383
|
+
aria-labelledby={titleId}
|
|
384
|
+
tabIndex={-1}
|
|
385
|
+
className={panelClass}
|
|
386
|
+
data-testid={props.testId}
|
|
387
|
+
data-size={size}
|
|
388
|
+
data-footer={footer}
|
|
389
|
+
onKeyDown={onKeyDown}
|
|
390
|
+
onMouseDown={(event) => event.stopPropagation()}
|
|
391
|
+
>
|
|
392
|
+
<div className={NM_MODAL_CLASSES.titleBar}>
|
|
393
|
+
<h2 id={titleId} className={titleClass}>
|
|
394
|
+
{props.title}
|
|
395
|
+
</h2>
|
|
396
|
+
{props.titleEnd}
|
|
397
|
+
</div>
|
|
398
|
+
{props.menu != null ? (
|
|
399
|
+
<div className={NM_MODAL_CLASSES.layout}>
|
|
400
|
+
<div className={NM_MODAL_CLASSES.nav}>{props.menu}</div>
|
|
401
|
+
<div className={NM_MODAL_CLASSES.main}>{body}</div>
|
|
402
|
+
</div>
|
|
403
|
+
) : (
|
|
404
|
+
body
|
|
405
|
+
)}
|
|
406
|
+
{showFooter ? (
|
|
407
|
+
<div className={footerClass}>
|
|
408
|
+
{footer === NM_MODAL_FOOTER.pane ? props.leading : null}
|
|
409
|
+
<div className={NM_MODAL_CLASSES.actionsEnd}>{props.actions}</div>
|
|
410
|
+
</div>
|
|
411
|
+
) : null}
|
|
412
|
+
</div>
|
|
413
|
+
</div>
|
|
414
|
+
</SavePhaseProvider>
|
|
415
|
+
) : null,
|
|
416
|
+
document.body,
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export function NmModalAction(props: {
|
|
421
|
+
label?: string;
|
|
422
|
+
accessibleName?: string;
|
|
423
|
+
icon: NmIconId;
|
|
424
|
+
tone?: NmModalActionTone;
|
|
425
|
+
type?: 'button' | 'submit';
|
|
426
|
+
form?: string;
|
|
427
|
+
disabled?: boolean;
|
|
428
|
+
requireChange?: boolean;
|
|
429
|
+
testId?: string;
|
|
430
|
+
onClick?: () => void;
|
|
431
|
+
}): ReactNode {
|
|
432
|
+
useNordmanUiLocale();
|
|
433
|
+
|
|
434
|
+
const tone = props.tone ?? NM_MODAL_ACTION.quiet;
|
|
435
|
+
const phase = useContext(SavePhaseContext).phase;
|
|
436
|
+
const dirty = useContext(SaveDirtyContext);
|
|
437
|
+
const confirmsSave = props.icon === 'check' && tone === NM_MODAL_ACTION.primary;
|
|
438
|
+
const saving = confirmsSave && phase === 'saving';
|
|
439
|
+
const saved = confirmsSave && phase === 'saved';
|
|
440
|
+
const unchanged = Boolean(props.requireChange) && !dirty && !saved;
|
|
441
|
+
const icon = saving ? 'loader' : props.icon;
|
|
442
|
+
const label = saved ? nmModalSavedLabel() : props.label;
|
|
443
|
+
const iconOnly = label == null || label.length === 0;
|
|
444
|
+
const className = [
|
|
445
|
+
NM_MODAL_CLASSES.action,
|
|
446
|
+
iconOnly ? NM_MODAL_CLASSES.actionIcon : '',
|
|
447
|
+
tone === NM_MODAL_ACTION.primary
|
|
448
|
+
? NM_MODAL_CLASSES.actionPrimary
|
|
449
|
+
: NM_MODAL_CLASSES.actionQuiet,
|
|
450
|
+
]
|
|
451
|
+
.filter((value) => value !== '')
|
|
452
|
+
.join(' ');
|
|
453
|
+
let accessibleLabel: string | undefined;
|
|
454
|
+
if (iconOnly) {
|
|
455
|
+
accessibleLabel = props.accessibleName ?? props.icon;
|
|
456
|
+
return (
|
|
457
|
+
<NordmanIconButton
|
|
458
|
+
glyph={icon}
|
|
459
|
+
label={accessibleLabel}
|
|
460
|
+
tone={
|
|
461
|
+
tone === NM_MODAL_ACTION.primary
|
|
462
|
+
? NM_ICON_BUTTON_TONES.invert
|
|
463
|
+
: NM_ICON_BUTTON_TONES.panel
|
|
464
|
+
}
|
|
465
|
+
type={props.type ?? 'button'}
|
|
466
|
+
form={props.form}
|
|
467
|
+
disabled={props.disabled || saving || unchanged}
|
|
468
|
+
data-save={confirmsSave ? phase : undefined}
|
|
469
|
+
testId={props.testId}
|
|
470
|
+
busy={saving || undefined}
|
|
471
|
+
className={NM_MODAL_CLASSES.action}
|
|
472
|
+
onClick={props.onClick}
|
|
473
|
+
/>
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
if (saved) {
|
|
477
|
+
accessibleLabel = label;
|
|
478
|
+
}
|
|
479
|
+
return (
|
|
480
|
+
<button
|
|
481
|
+
className={className}
|
|
482
|
+
type={props.type ?? 'button'}
|
|
483
|
+
form={props.form}
|
|
484
|
+
disabled={props.disabled || saving || unchanged}
|
|
485
|
+
data-save={confirmsSave ? phase : undefined}
|
|
486
|
+
data-testid={props.testId}
|
|
487
|
+
aria-busy={saving || undefined}
|
|
488
|
+
aria-label={accessibleLabel}
|
|
489
|
+
onClick={props.onClick}
|
|
490
|
+
>
|
|
491
|
+
<NmIcon id={icon} />
|
|
492
|
+
{iconOnly ? null : label}
|
|
493
|
+
</button>
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export { NM_MODAL_ACTION, NM_MODAL_CLASSES, NM_MODAL_FOOTER, NM_MODAL_SIZE, NM_MODAL_TITLE };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
.nm-native-select {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 100%;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.nm-native-select__control {
|
|
7
|
+
box-sizing: border-box;
|
|
8
|
+
width: 100%;
|
|
9
|
+
height: var(--nm-field-h);
|
|
10
|
+
padding: 0 calc(var(--control-px) + var(--nm-icon-button) + var(--nm-space-8)) 0 var(--control-px);
|
|
11
|
+
border: var(--nm-rule) solid var(--nm-line-strong);
|
|
12
|
+
border-radius: var(--nm-control-r);
|
|
13
|
+
background: var(--nm-raised);
|
|
14
|
+
color: var(--nm-fg);
|
|
15
|
+
color-scheme: inherit;
|
|
16
|
+
font-family: var(--nm-font);
|
|
17
|
+
font-size: var(--control-fs);
|
|
18
|
+
appearance: none;
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
outline: none;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.nm-native-select__control:hover:not(:disabled) {
|
|
24
|
+
border-color: var(--nm-stroke);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.nm-native-select__control:focus-visible {
|
|
28
|
+
border-color: var(--nm-fg);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.nm-native-select__control:disabled {
|
|
32
|
+
cursor: not-allowed;
|
|
33
|
+
opacity: 0.5;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.nm-native-select__control[aria-invalid='true'] {
|
|
37
|
+
border-color: var(--nm-destructive);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.nm-native-select__icon {
|
|
41
|
+
position: absolute;
|
|
42
|
+
top: 50%;
|
|
43
|
+
right: var(--control-px);
|
|
44
|
+
color: var(--nm-fg-subtle);
|
|
45
|
+
pointer-events: none;
|
|
46
|
+
transform: translateY(-50%);
|
|
47
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ComponentProps } from 'react';
|
|
2
|
+
import { nmClass } from '../../lib/nm-class.ts';
|
|
3
|
+
import { NmIcon } from '../nm-icon/nm-icon.tsx';
|
|
4
|
+
|
|
5
|
+
/** The browser's own select, styled by NIF. Use it where the platform picker is the right control, such as on a phone. */
|
|
6
|
+
export function NmNativeSelect({ className, children, ...props }: ComponentProps<'select'>) {
|
|
7
|
+
return (
|
|
8
|
+
<div className="nm-native-select">
|
|
9
|
+
<select data-slot="native-select" className={nmClass('nm-native-select__control', className)} {...props}>
|
|
10
|
+
{children}
|
|
11
|
+
</select>
|
|
12
|
+
<NmIcon id="chevron" className="nm-native-select__icon" />
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function NmNativeSelectOption(props: ComponentProps<'option'>) {
|
|
18
|
+
return <option data-slot="native-select-option" {...props} />;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function NmNativeSelectOptGroup(props: ComponentProps<'optgroup'>) {
|
|
22
|
+
return <optgroup data-slot="native-select-optgroup" {...props} />;
|
|
23
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
.nm-panel-region {
|
|
2
|
+
box-sizing: border-box;
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
width: 100%;
|
|
6
|
+
min-width: 0;
|
|
7
|
+
min-height: 0;
|
|
8
|
+
overflow: hidden;
|
|
9
|
+
border-radius: var(--nm-radius-lg);
|
|
10
|
+
background: var(--nm-raised);
|
|
11
|
+
color: var(--nm-fg);
|
|
12
|
+
font-family: var(--nm-font);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.nm-panel-region[data-variant='inset'] {
|
|
16
|
+
background: var(--nm-inset);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.nm-panel-region[data-variant='plain'] {
|
|
20
|
+
border-radius: 0;
|
|
21
|
+
background: var(--nm-canvas);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.nm-panel-region__header {
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-shrink: 0;
|
|
27
|
+
align-items: center;
|
|
28
|
+
gap: var(--nm-space-8);
|
|
29
|
+
padding: var(--nm-space-12) var(--nm-space-16);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.nm-panel-region__title {
|
|
33
|
+
min-width: 0;
|
|
34
|
+
margin: 0;
|
|
35
|
+
overflow: hidden;
|
|
36
|
+
font-size: var(--nm-type-ui);
|
|
37
|
+
font-weight: var(--nm-weight-semibold);
|
|
38
|
+
text-overflow: ellipsis;
|
|
39
|
+
white-space: nowrap;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.nm-panel-region__description {
|
|
43
|
+
margin: 0;
|
|
44
|
+
color: var(--nm-fg-muted);
|
|
45
|
+
font-size: var(--nm-type-ui-sm);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.nm-panel-region__actions {
|
|
49
|
+
display: flex;
|
|
50
|
+
flex-shrink: 0;
|
|
51
|
+
align-items: center;
|
|
52
|
+
gap: var(--nm-space-4);
|
|
53
|
+
margin-inline-start: auto;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.nm-panel-region__content {
|
|
57
|
+
flex: 1;
|
|
58
|
+
min-height: 0;
|
|
59
|
+
padding: var(--nm-space-16);
|
|
60
|
+
overflow: auto;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.nm-panel-region__header + .nm-panel-region__content {
|
|
64
|
+
padding-top: 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.nm-panel-region__footer {
|
|
68
|
+
display: flex;
|
|
69
|
+
flex-shrink: 0;
|
|
70
|
+
align-items: center;
|
|
71
|
+
gap: var(--nm-space-8);
|
|
72
|
+
padding: var(--nm-space-12) var(--nm-space-16);
|
|
73
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ComponentProps } from 'react';
|
|
2
|
+
import { nmClass } from '../../lib/nm-class.ts';
|
|
3
|
+
|
|
4
|
+
export const NM_PANEL_VARIANTS = ['default', 'inset', 'plain'] as const;
|
|
5
|
+
export type NmPanelVariant = (typeof NM_PANEL_VARIANTS)[number];
|
|
6
|
+
|
|
7
|
+
/** A region of the app, such as an inspector or a side panel: a header, content that scrolls, and a footer. */
|
|
8
|
+
export function NmPanel({ className, variant = 'default', ...props }: ComponentProps<'section'> & { variant?: NmPanelVariant }) {
|
|
9
|
+
return <section data-slot="panel" data-variant={variant} className={nmClass('nm-panel-region', className)} {...props} />;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function NmPanelHeader({ className, ...props }: ComponentProps<'header'>) {
|
|
13
|
+
return <header data-slot="panel-header" className={nmClass('nm-panel-region__header', className)} {...props} />;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function NmPanelTitle({ className, ...props }: ComponentProps<'h2'>) {
|
|
17
|
+
return <h2 data-slot="panel-title" className={nmClass('nm-panel-region__title', className)} {...props} />;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function NmPanelDescription({ className, ...props }: ComponentProps<'p'>) {
|
|
21
|
+
return <p data-slot="panel-description" className={nmClass('nm-panel-region__description', className)} {...props} />;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Buttons at the end of the header. */
|
|
25
|
+
export function NmPanelActions({ className, ...props }: ComponentProps<'div'>) {
|
|
26
|
+
return <div data-slot="panel-actions" className={nmClass('nm-panel-region__actions', className)} {...props} />;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function NmPanelContent({ className, ...props }: ComponentProps<'div'>) {
|
|
30
|
+
return <div data-slot="panel-content" className={nmClass('nm-panel-region__content', className)} {...props} />;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function NmPanelFooter({ className, ...props }: ComponentProps<'footer'>) {
|
|
34
|
+
return <footer data-slot="panel-footer" className={nmClass('nm-panel-region__footer', className)} {...props} />;
|
|
35
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
.nm-panel-bar {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: space-between;
|
|
5
|
+
flex-shrink: 0;
|
|
6
|
+
padding: var(--nm-space-12) var(--nm-space-24);
|
|
7
|
+
border-bottom: var(--nm-rule) solid var(--nm-raised);
|
|
8
|
+
background: var(--nm-canvas);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.nm-panel-bar--icons {
|
|
12
|
+
padding: var(--nm-space-12);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.nm-panel-bar__actions {
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
gap: var(--nm-space-8);
|
|
19
|
+
}
|
|
20
|
+
|