@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,312 @@
|
|
|
1
|
+
.nm-dropdown {
|
|
2
|
+
position: relative;
|
|
3
|
+
display: inline-flex;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.nm-dropdown__trigger {
|
|
7
|
+
display: inline-flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
gap: var(--nm-space-8);
|
|
10
|
+
padding: 0;
|
|
11
|
+
border: 0;
|
|
12
|
+
background: transparent;
|
|
13
|
+
font-family: var(--nm-font);
|
|
14
|
+
font-size: var(--nm-type-ui);
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.nm-dropdown__trigger--icon {
|
|
19
|
+
gap: 0;
|
|
20
|
+
padding: var(--nm-icon-pad);
|
|
21
|
+
border-radius: var(--nm-control-radius);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.nm-dropdown__trigger--chip {
|
|
25
|
+
gap: var(--nm-space-8);
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
min-height: var(--nm-ui-chip-min-height, var(--nm-icon-control));
|
|
28
|
+
padding: var(--nm-icon-pad) var(--nm-space-12);
|
|
29
|
+
border: 0;
|
|
30
|
+
border-radius: calc(var(--nm-ui-chip-min-height, var(--nm-icon-control)) / 2);
|
|
31
|
+
font-size: var(--nm-type-ui);
|
|
32
|
+
font-weight: var(--nm-weight-medium);
|
|
33
|
+
line-height: var(--nm-type-ui);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.nm-dropdown__label {
|
|
37
|
+
font-size: inherit;
|
|
38
|
+
line-height: inherit;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.nm-dropdown__trigger--chip-icon-only {
|
|
42
|
+
gap: 0;
|
|
43
|
+
justify-content: center;
|
|
44
|
+
width: var(--nm-ui-chip-min-height, var(--nm-icon-control));
|
|
45
|
+
min-width: var(--nm-ui-chip-min-height, var(--nm-icon-control));
|
|
46
|
+
padding: var(--nm-icon-pad);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.nm-dropdown__trigger--filled {
|
|
50
|
+
background: var(--nm-panel);
|
|
51
|
+
color: var(--nm-fg);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.nm-dropdown__trigger--outline {
|
|
55
|
+
background: transparent;
|
|
56
|
+
color: var(--nm-fg-subtle);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.nm-dropdown__trigger--chip:hover:not(:disabled),
|
|
60
|
+
.nm-dropdown__trigger--chip:focus-visible:not(:disabled),
|
|
61
|
+
.nm-dropdown__trigger--chip[aria-expanded='true']:not(:disabled) {
|
|
62
|
+
background: var(--nm-panel);
|
|
63
|
+
color: var(--nm-fg);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.nm-dropdown__lead,
|
|
67
|
+
.nm-dropdown__chevron,
|
|
68
|
+
.nm-dropdown__trigger .nm-icon,
|
|
69
|
+
.nm-dropdown__trigger img {
|
|
70
|
+
display: block;
|
|
71
|
+
width: var(--nm-icon-button);
|
|
72
|
+
height: var(--nm-icon-button);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.nm-dropdown__panel,
|
|
76
|
+
.nm-dropdown__subpanel {
|
|
77
|
+
z-index: var(--nm-menu-z);
|
|
78
|
+
display: flex;
|
|
79
|
+
flex-direction: column;
|
|
80
|
+
gap: var(--nm-space-4);
|
|
81
|
+
min-width: 13.5rem;
|
|
82
|
+
max-height: var(--nm-dropdown-max);
|
|
83
|
+
margin: 0;
|
|
84
|
+
padding: var(--nm-list-pad);
|
|
85
|
+
border: var(--nm-rule) solid var(--nm-line-strong);
|
|
86
|
+
border-radius: var(--nm-menu-radius);
|
|
87
|
+
background: var(--nm-panel);
|
|
88
|
+
color: var(--nm-fg);
|
|
89
|
+
list-style: none;
|
|
90
|
+
box-shadow: none;
|
|
91
|
+
scrollbar-width: none;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.nm-dropdown__panel,
|
|
95
|
+
.nm-dropdown__subpanel {
|
|
96
|
+
overflow-x: hidden;
|
|
97
|
+
overflow-y: auto;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.nm-dropdown__panel[data-scrolling='true'],
|
|
101
|
+
.nm-dropdown__subpanel[data-scrolling='true'] {
|
|
102
|
+
scrollbar-width: thin;
|
|
103
|
+
scrollbar-color: var(--nm-stroke) transparent;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.nm-dropdown__panel::-webkit-scrollbar,
|
|
107
|
+
.nm-dropdown__subpanel::-webkit-scrollbar {
|
|
108
|
+
width: 0;
|
|
109
|
+
height: 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.nm-dropdown__panel[data-scrolling='true']::-webkit-scrollbar,
|
|
113
|
+
.nm-dropdown__subpanel[data-scrolling='true']::-webkit-scrollbar {
|
|
114
|
+
width: var(--nm-rail-scrollbar);
|
|
115
|
+
height: var(--nm-rail-scrollbar);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.nm-dropdown__panel[data-scrolling='true']::-webkit-scrollbar-thumb,
|
|
119
|
+
.nm-dropdown__subpanel[data-scrolling='true']::-webkit-scrollbar-thumb {
|
|
120
|
+
background: var(--nm-stroke);
|
|
121
|
+
border-radius: var(--nm-radius-sm);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.nm-dropdown__panel {
|
|
125
|
+
position: absolute;
|
|
126
|
+
top: calc(100% + var(--nm-space-8));
|
|
127
|
+
left: 0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.nm-dropdown__panel--end {
|
|
131
|
+
left: auto;
|
|
132
|
+
right: 0;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.nm-dropdown__panel--portal {
|
|
136
|
+
position: fixed;
|
|
137
|
+
z-index: calc(var(--nm-menu-z) + 2);
|
|
138
|
+
top: var(--nm-dropdown-top);
|
|
139
|
+
left: var(--nm-dropdown-left, auto);
|
|
140
|
+
right: var(--nm-dropdown-right, auto);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.nm-dropdown__panel--row {
|
|
144
|
+
box-sizing: border-box;
|
|
145
|
+
width: var(--nm-dropdown-width, auto);
|
|
146
|
+
min-width: 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.nm-dropdown__branch {
|
|
150
|
+
position: relative;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.nm-dropdown__subpanel {
|
|
154
|
+
position: fixed;
|
|
155
|
+
z-index: calc(var(--nm-menu-z) + 3);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.nm-dropdown__separator.nm-dropdown__separator {
|
|
159
|
+
height: 0;
|
|
160
|
+
margin: var(--nm-space-8) 0;
|
|
161
|
+
border: 0;
|
|
162
|
+
border-top: var(--nm-rule) solid var(--nm-line);
|
|
163
|
+
background: transparent;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* One item metric. The repeated class wins over utility padding on the same node. */
|
|
167
|
+
.nm-dropdown__item.nm-dropdown__item {
|
|
168
|
+
display: flex;
|
|
169
|
+
align-items: center;
|
|
170
|
+
gap: var(--nm-space-8);
|
|
171
|
+
width: 100%;
|
|
172
|
+
box-sizing: border-box;
|
|
173
|
+
min-height: var(--nm-icon-control);
|
|
174
|
+
justify-content: space-between;
|
|
175
|
+
padding: var(--nm-icon-pad);
|
|
176
|
+
border: 0;
|
|
177
|
+
border-radius: var(--nm-panel-item-radius);
|
|
178
|
+
background: transparent;
|
|
179
|
+
color: var(--nm-fg);
|
|
180
|
+
font-family: var(--nm-font);
|
|
181
|
+
font-size: var(--nm-type-ui);
|
|
182
|
+
font-weight: var(--nm-weight-medium);
|
|
183
|
+
line-height: var(--nm-leading-tight);
|
|
184
|
+
text-align: left;
|
|
185
|
+
white-space: nowrap;
|
|
186
|
+
cursor: pointer;
|
|
187
|
+
outline: none;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.nm-dropdown__item.nm-dropdown__item:hover,
|
|
191
|
+
.nm-dropdown__item.nm-dropdown__item:focus,
|
|
192
|
+
.nm-dropdown__item.nm-dropdown__item:focus-visible,
|
|
193
|
+
.nm-dropdown__item.nm-dropdown__item[aria-selected='true'],
|
|
194
|
+
.nm-dropdown__item.nm-dropdown__item[data-highlighted],
|
|
195
|
+
.nm-dropdown__item.nm-dropdown__item[data-state='open'] {
|
|
196
|
+
background: var(--nm-line);
|
|
197
|
+
color: var(--nm-fg);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.nm-dropdown__item.nm-dropdown__item--danger {
|
|
201
|
+
color: rgb(var(--nm-destructive-rgb));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.nm-dropdown__item.nm-dropdown__item--disabled,
|
|
205
|
+
.nm-dropdown__item.nm-dropdown__item[data-disabled] {
|
|
206
|
+
cursor: default;
|
|
207
|
+
opacity: 0.5;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.nm-dropdown__item.nm-dropdown__item--quiet,
|
|
211
|
+
.nm-dropdown__item.nm-dropdown__item--quiet:hover,
|
|
212
|
+
.nm-dropdown__item.nm-dropdown__item--quiet:focus,
|
|
213
|
+
.nm-dropdown__item.nm-dropdown__item--quiet:focus-visible,
|
|
214
|
+
.nm-dropdown__item.nm-dropdown__item--quiet[data-highlighted] {
|
|
215
|
+
background: transparent;
|
|
216
|
+
color: var(--nm-fg-subtle);
|
|
217
|
+
cursor: default;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.nm-dropdown__mark {
|
|
221
|
+
width: var(--nm-space-8);
|
|
222
|
+
height: var(--nm-space-8);
|
|
223
|
+
flex-shrink: 0;
|
|
224
|
+
border-radius: 50%;
|
|
225
|
+
background: var(--nm-status-idle);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.nm-dropdown__mark--busy {
|
|
229
|
+
background: var(--nm-status-busy);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.nm-dropdown__mark--live {
|
|
233
|
+
background: var(--nm-status-live);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.nm-dropdown__icon {
|
|
237
|
+
display: inline-flex;
|
|
238
|
+
align-items: center;
|
|
239
|
+
justify-content: center;
|
|
240
|
+
width: var(--nm-icon-button);
|
|
241
|
+
height: var(--nm-icon-button);
|
|
242
|
+
flex-shrink: 0;
|
|
243
|
+
color: inherit;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.nm-dropdown__icon img,
|
|
247
|
+
.nm-dropdown__icon svg,
|
|
248
|
+
.nm-dropdown__icon .nm-icon {
|
|
249
|
+
display: block;
|
|
250
|
+
width: var(--nm-icon-button);
|
|
251
|
+
height: var(--nm-icon-button);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.nm-dropdown__copy {
|
|
255
|
+
display: flex;
|
|
256
|
+
min-width: 0;
|
|
257
|
+
flex: 1 1 auto;
|
|
258
|
+
flex-direction: row;
|
|
259
|
+
align-items: center;
|
|
260
|
+
justify-content: space-between;
|
|
261
|
+
gap: var(--nm-space-16);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.nm-dropdown__item .nm-dropdown__label {
|
|
265
|
+
line-height: var(--nm-leading-tight);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.nm-dropdown__detail {
|
|
269
|
+
color: var(--nm-stroke);
|
|
270
|
+
font-size: var(--nm-type-ui);
|
|
271
|
+
font-weight: var(--nm-weight-medium);
|
|
272
|
+
text-align: right;
|
|
273
|
+
white-space: nowrap;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
.nm-dropdown__trailing {
|
|
277
|
+
display: inline-flex;
|
|
278
|
+
align-items: center;
|
|
279
|
+
gap: var(--nm-space-8);
|
|
280
|
+
margin-inline-start: auto;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.nm-dropdown__shortcut {
|
|
284
|
+
padding: 0;
|
|
285
|
+
color: var(--nm-stroke);
|
|
286
|
+
font: inherit;
|
|
287
|
+
line-height: inherit;
|
|
288
|
+
white-space: nowrap;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
.nm-dropdown__check {
|
|
292
|
+
display: none;
|
|
293
|
+
flex-shrink: 0;
|
|
294
|
+
margin-inline-start: auto;
|
|
295
|
+
width: var(--nm-icon-button);
|
|
296
|
+
height: var(--nm-icon-button);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.nm-dropdown__item--branch .nm-dropdown__check {
|
|
300
|
+
display: block;
|
|
301
|
+
transform: rotate(-90deg);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.nm-dropdown--hover {
|
|
305
|
+
display: none;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
[data-nm-menu]:hover .nm-dropdown--hover,
|
|
309
|
+
[data-nm-menu]:focus-within .nm-dropdown--hover,
|
|
310
|
+
.nm-dropdown--hover[data-open='true'] {
|
|
311
|
+
display: inline-flex;
|
|
312
|
+
}
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useId,
|
|
5
|
+
useLayoutEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
type MouseEvent as ReactMouseEvent,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
type Ref,
|
|
11
|
+
} from 'react';
|
|
12
|
+
import { createPortal } from 'react-dom';
|
|
13
|
+
import type { NmIconId } from '../../config/nm-icons.ts';
|
|
14
|
+
import {
|
|
15
|
+
NM_DROPDOWN_ALIGN,
|
|
16
|
+
NM_DROPDOWN_CLASSES,
|
|
17
|
+
NM_DROPDOWN_REVEAL,
|
|
18
|
+
NM_DROPDOWN_SCROLL_IDLE_MS,
|
|
19
|
+
NM_DROPDOWN_TONE,
|
|
20
|
+
NM_DROPDOWN_TRIGGER,
|
|
21
|
+
} from '../../config/nm-dropdown.ts';
|
|
22
|
+
import {
|
|
23
|
+
dropdownPortalHost,
|
|
24
|
+
placeNmDropdownPanel,
|
|
25
|
+
placeNmDropdownRowPanel,
|
|
26
|
+
} from './nm-dropdown-placement';
|
|
27
|
+
import { NordmanIconButton } from '../nordman-icon-button/nordman-icon-button.tsx';
|
|
28
|
+
import { openDropdownBranch, type NmDropdownItem } from './nm-dropdown-item';
|
|
29
|
+
import { findDropdownItem, NmDropdownOptions } from './nm-dropdown-options';
|
|
30
|
+
import { NM_ICON_BUTTON_TONES } from '../../config/nm-icon-button.ts';
|
|
31
|
+
import { NmDropdownPanel } from './nm-dropdown-panel';
|
|
32
|
+
import { createLogger } from '../../kit-logger.ts';
|
|
33
|
+
import { NmIcon } from '../nm-icon/nm-icon.tsx';
|
|
34
|
+
|
|
35
|
+
const logger = createLogger('interface-nm-dropdown');
|
|
36
|
+
|
|
37
|
+
function dropdownGlyph(
|
|
38
|
+
imageSrc: string | undefined,
|
|
39
|
+
icon: NmIconId | undefined,
|
|
40
|
+
iconClass?: string,
|
|
41
|
+
): ReactNode {
|
|
42
|
+
if (imageSrc) {
|
|
43
|
+
return <img src={imageSrc} alt="" />;
|
|
44
|
+
}
|
|
45
|
+
if (icon) {
|
|
46
|
+
return <NmIcon id={icon} className={iconClass} />;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type { NmDropdownItem };
|
|
52
|
+
|
|
53
|
+
export type NmDropdownProps = {
|
|
54
|
+
label: string;
|
|
55
|
+
items?: readonly NmDropdownItem[];
|
|
56
|
+
selected?: string | null;
|
|
57
|
+
testId?: string;
|
|
58
|
+
trigger?: (typeof NM_DROPDOWN_TRIGGER)[keyof typeof NM_DROPDOWN_TRIGGER];
|
|
59
|
+
tone?: (typeof NM_DROPDOWN_TONE)[keyof typeof NM_DROPDOWN_TONE];
|
|
60
|
+
align?: (typeof NM_DROPDOWN_ALIGN)[keyof typeof NM_DROPDOWN_ALIGN];
|
|
61
|
+
icon?: NmIconId;
|
|
62
|
+
imageSrc?: string;
|
|
63
|
+
displayLabel?: string;
|
|
64
|
+
/** Chip/text triggers show only the lead icon; `label` stays for accessibility. */
|
|
65
|
+
iconOnly?: boolean;
|
|
66
|
+
portal?: boolean;
|
|
67
|
+
portalRoot?: HTMLElement | null;
|
|
68
|
+
disabled?: boolean;
|
|
69
|
+
/** `hover` hides the trigger until the host with `data-nm-menu` is hovered or focused. */
|
|
70
|
+
reveal?: (typeof NM_DROPDOWN_REVEAL)[keyof typeof NM_DROPDOWN_REVEAL];
|
|
71
|
+
open?: boolean;
|
|
72
|
+
triggerClassName?: string;
|
|
73
|
+
triggerRef?: Ref<HTMLButtonElement>;
|
|
74
|
+
onOpenChange?: (open: boolean) => void;
|
|
75
|
+
onSelect?: (id: string) => void;
|
|
76
|
+
onBranchExpand?: (id: string) => void;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function isIconTrigger(trigger: NmDropdownProps['trigger']): boolean {
|
|
80
|
+
return trigger === NM_DROPDOWN_TRIGGER.icon || trigger === NM_DROPDOWN_TRIGGER.iconButton;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function assignTriggerRef(ref: Ref<HTMLButtonElement> | undefined, node: HTMLButtonElement | null) {
|
|
84
|
+
if (ref == null) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (typeof ref === 'function') {
|
|
88
|
+
ref(node);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
(ref as { current: HTMLButtonElement | null }).current = node;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function NmDropdown(props: NmDropdownProps): ReactNode {
|
|
95
|
+
const panelId = useId();
|
|
96
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
97
|
+
const panelRef = useRef<HTMLUListElement>(null);
|
|
98
|
+
const triggerNodeRef = useRef<HTMLButtonElement | null>(null);
|
|
99
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
100
|
+
const [expandedIds, setExpandedIds] = useState<readonly string[]>([]);
|
|
101
|
+
const alignName = props.align === NM_DROPDOWN_ALIGN.end ? 'end' : 'start';
|
|
102
|
+
const [motionPlacement, setMotionPlacement] = useState(`bottom-${alignName}`);
|
|
103
|
+
const { open: openProp, onOpenChange } = props;
|
|
104
|
+
const open = openProp ?? uncontrolledOpen;
|
|
105
|
+
const setOpen = useCallback(
|
|
106
|
+
(next: boolean): void => {
|
|
107
|
+
if (openProp === undefined) {
|
|
108
|
+
setUncontrolledOpen(next);
|
|
109
|
+
}
|
|
110
|
+
onOpenChange?.(next);
|
|
111
|
+
},
|
|
112
|
+
[openProp, onOpenChange],
|
|
113
|
+
);
|
|
114
|
+
const items = props.items ?? [];
|
|
115
|
+
const selected = findDropdownItem(items, props.selected);
|
|
116
|
+
const triggerLabel = props.displayLabel ?? selected?.label ?? props.label;
|
|
117
|
+
const leadIcon = selected?.icon ?? props.icon;
|
|
118
|
+
const chip = props.tone != null;
|
|
119
|
+
const iconOnlyTrigger = props.iconOnly === true;
|
|
120
|
+
const iconTrigger = isIconTrigger(props.trigger);
|
|
121
|
+
const iconButton = props.trigger === NM_DROPDOWN_TRIGGER.iconButton;
|
|
122
|
+
const portal = props.portal ?? iconTrigger;
|
|
123
|
+
const triggerClass = [
|
|
124
|
+
NM_DROPDOWN_CLASSES.trigger,
|
|
125
|
+
props.trigger === NM_DROPDOWN_TRIGGER.icon ? NM_DROPDOWN_CLASSES.triggerIcon : '',
|
|
126
|
+
chip ? NM_DROPDOWN_CLASSES.triggerChip : '',
|
|
127
|
+
chip && iconOnlyTrigger ? NM_DROPDOWN_CLASSES.triggerChipIconOnly : '',
|
|
128
|
+
props.tone === NM_DROPDOWN_TONE.filled ? NM_DROPDOWN_CLASSES.triggerFilled : '',
|
|
129
|
+
props.tone === NM_DROPDOWN_TONE.outline ? NM_DROPDOWN_CLASSES.triggerOutline : '',
|
|
130
|
+
props.triggerClassName ?? '',
|
|
131
|
+
]
|
|
132
|
+
.filter((value) => value !== '')
|
|
133
|
+
.join(' ');
|
|
134
|
+
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
const panel = panelRef.current;
|
|
137
|
+
if (!open || panel == null) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
let idle = 0;
|
|
141
|
+
const onScroll = (event: Event) => {
|
|
142
|
+
const target = event.target;
|
|
143
|
+
if (!(target instanceof HTMLElement)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const inSubmenu = target.closest(`.${NM_DROPDOWN_CLASSES.subpanel}`) != null;
|
|
147
|
+
const inPanel = panel.contains(target);
|
|
148
|
+
if (!inSubmenu && !inPanel) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (inPanel && !inSubmenu) {
|
|
152
|
+
setExpandedIds((current) => (current.length === 0 ? current : []));
|
|
153
|
+
}
|
|
154
|
+
target.dataset.scrolling = 'true';
|
|
155
|
+
window.clearTimeout(idle);
|
|
156
|
+
idle = window.setTimeout(() => {
|
|
157
|
+
delete target.dataset.scrolling;
|
|
158
|
+
}, NM_DROPDOWN_SCROLL_IDLE_MS);
|
|
159
|
+
};
|
|
160
|
+
document.addEventListener('scroll', onScroll, true);
|
|
161
|
+
return () => {
|
|
162
|
+
document.removeEventListener('scroll', onScroll, true);
|
|
163
|
+
window.clearTimeout(idle);
|
|
164
|
+
delete panel.dataset.scrolling;
|
|
165
|
+
};
|
|
166
|
+
}, [open]);
|
|
167
|
+
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (!open) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
function onPointer(event: MouseEvent): void {
|
|
173
|
+
const target = event.target;
|
|
174
|
+
if (!(target instanceof Node)) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const inSubmenu =
|
|
178
|
+
target instanceof Element && target.closest(`.${NM_DROPDOWN_CLASSES.subpanel}`) != null;
|
|
179
|
+
if (rootRef.current?.contains(target) || panelRef.current?.contains(target) || inSubmenu) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
setOpen(false);
|
|
183
|
+
setExpandedIds([]);
|
|
184
|
+
}
|
|
185
|
+
function onKey(event: KeyboardEvent): void {
|
|
186
|
+
if (event.key === 'Escape') {
|
|
187
|
+
setOpen(false);
|
|
188
|
+
setExpandedIds([]);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
document.addEventListener('mousedown', onPointer);
|
|
192
|
+
document.addEventListener('keydown', onKey);
|
|
193
|
+
return () => {
|
|
194
|
+
document.removeEventListener('mousedown', onPointer);
|
|
195
|
+
document.removeEventListener('keydown', onKey);
|
|
196
|
+
};
|
|
197
|
+
}, [open, setOpen]);
|
|
198
|
+
|
|
199
|
+
useLayoutEffect(() => {
|
|
200
|
+
if (!open || !portal) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
function applyPlacement(): void {
|
|
204
|
+
const trigger = triggerNodeRef.current;
|
|
205
|
+
const panel = panelRef.current;
|
|
206
|
+
if (trigger == null || panel == null) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const rect = trigger.getBoundingClientRect();
|
|
210
|
+
const viewport = { width: window.innerWidth, height: window.innerHeight };
|
|
211
|
+
const rowEl = props.align === NM_DROPDOWN_ALIGN.row ? trigger.closest('.nm-rail__row') : null;
|
|
212
|
+
if (rowEl instanceof HTMLElement) {
|
|
213
|
+
const rowRect = rowEl.getBoundingClientRect();
|
|
214
|
+
const placement = placeNmDropdownRowPanel({
|
|
215
|
+
row: {
|
|
216
|
+
top: rowRect.top,
|
|
217
|
+
left: rowRect.left,
|
|
218
|
+
right: rowRect.right,
|
|
219
|
+
bottom: rowRect.bottom,
|
|
220
|
+
width: rowRect.width,
|
|
221
|
+
height: rowRect.height,
|
|
222
|
+
},
|
|
223
|
+
panel: { height: panel.offsetHeight },
|
|
224
|
+
viewport,
|
|
225
|
+
});
|
|
226
|
+
panel.style.setProperty('--nm-dropdown-top', `${placement.top}px`);
|
|
227
|
+
panel.style.setProperty('--nm-dropdown-left', `${placement.left}px`);
|
|
228
|
+
panel.style.setProperty('--nm-dropdown-right', 'auto');
|
|
229
|
+
panel.style.setProperty('--nm-dropdown-width', `${placement.width}px`);
|
|
230
|
+
panel.style.width = `${placement.width}px`;
|
|
231
|
+
logger.debug('place-row', triggerLabel, placement);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const placement = placeNmDropdownPanel({
|
|
236
|
+
trigger: {
|
|
237
|
+
top: rect.top,
|
|
238
|
+
left: rect.left,
|
|
239
|
+
right: rect.right,
|
|
240
|
+
bottom: rect.bottom,
|
|
241
|
+
width: rect.width,
|
|
242
|
+
height: rect.height,
|
|
243
|
+
},
|
|
244
|
+
panel: { width: panel.offsetWidth, height: panel.offsetHeight },
|
|
245
|
+
viewport,
|
|
246
|
+
align: props.align ?? NM_DROPDOWN_ALIGN.start,
|
|
247
|
+
});
|
|
248
|
+
panel.style.removeProperty('--nm-dropdown-width');
|
|
249
|
+
panel.style.removeProperty('width');
|
|
250
|
+
panel.style.setProperty('--nm-dropdown-top', `${placement.top}px`);
|
|
251
|
+
panel.style.setProperty('--nm-dropdown-left', `${placement.left}px`);
|
|
252
|
+
panel.style.setProperty('--nm-dropdown-right', 'auto');
|
|
253
|
+
logger.debug('place', triggerLabel, placement);
|
|
254
|
+
}
|
|
255
|
+
applyPlacement();
|
|
256
|
+
window.addEventListener('resize', applyPlacement);
|
|
257
|
+
window.addEventListener('scroll', applyPlacement, true);
|
|
258
|
+
return () => {
|
|
259
|
+
window.removeEventListener('resize', applyPlacement);
|
|
260
|
+
window.removeEventListener('scroll', applyPlacement, true);
|
|
261
|
+
};
|
|
262
|
+
}, [open, portal, props.align, alignName, items.length, expandedIds, triggerLabel]);
|
|
263
|
+
|
|
264
|
+
logger.debug('render', triggerLabel, { open, items: items.length });
|
|
265
|
+
|
|
266
|
+
const panelClass = [
|
|
267
|
+
NM_DROPDOWN_CLASSES.panel,
|
|
268
|
+
props.align === NM_DROPDOWN_ALIGN.end ? NM_DROPDOWN_CLASSES.panelEnd : '',
|
|
269
|
+
props.align === NM_DROPDOWN_ALIGN.row ? NM_DROPDOWN_CLASSES.panelRow : '',
|
|
270
|
+
portal ? NM_DROPDOWN_CLASSES.panelPortal : '',
|
|
271
|
+
]
|
|
272
|
+
.filter((value) => value !== '')
|
|
273
|
+
.join(' ');
|
|
274
|
+
|
|
275
|
+
const panel = (
|
|
276
|
+
<NmDropdownPanel
|
|
277
|
+
open={open}
|
|
278
|
+
placement={motionPlacement}
|
|
279
|
+
className={panelClass}
|
|
280
|
+
id={panelId}
|
|
281
|
+
label={props.label}
|
|
282
|
+
panelRef={panelRef}
|
|
283
|
+
>
|
|
284
|
+
<NmDropdownOptions
|
|
285
|
+
items={items}
|
|
286
|
+
selected={props.selected}
|
|
287
|
+
expandedIds={expandedIds}
|
|
288
|
+
onOpenBranch={(id) => {
|
|
289
|
+
setExpandedIds((current) => {
|
|
290
|
+
const next = openDropdownBranch(items, id);
|
|
291
|
+
const same =
|
|
292
|
+
next.length === current.length &&
|
|
293
|
+
next.every((value, index) => value === current[index]);
|
|
294
|
+
if (same) {
|
|
295
|
+
return current;
|
|
296
|
+
}
|
|
297
|
+
logger.debug('hover', id);
|
|
298
|
+
props.onBranchExpand?.(id);
|
|
299
|
+
return next;
|
|
300
|
+
});
|
|
301
|
+
}}
|
|
302
|
+
onCloseBranches={() => {
|
|
303
|
+
setExpandedIds((current) => (current.length === 0 ? current : []));
|
|
304
|
+
}}
|
|
305
|
+
onSelect={(id) => {
|
|
306
|
+
logger.debug('select', id);
|
|
307
|
+
props.onSelect?.(id);
|
|
308
|
+
setOpen(false);
|
|
309
|
+
setExpandedIds([]);
|
|
310
|
+
}}
|
|
311
|
+
/>
|
|
312
|
+
</NmDropdownPanel>
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
const bindTrigger = (node: HTMLButtonElement | null) => {
|
|
316
|
+
triggerNodeRef.current = node;
|
|
317
|
+
assignTriggerRef(props.triggerRef, node);
|
|
318
|
+
};
|
|
319
|
+
const toggle = (event: ReactMouseEvent<HTMLButtonElement>) => {
|
|
320
|
+
event.stopPropagation();
|
|
321
|
+
if (!open) {
|
|
322
|
+
const rect = triggerNodeRef.current?.getBoundingClientRect();
|
|
323
|
+
if (rect != null) {
|
|
324
|
+
const side = rect.bottom + 120 > window.innerHeight ? 'top' : 'bottom';
|
|
325
|
+
setMotionPlacement(`${side}-${alignName}`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
setOpen(!open);
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const rootClass = [
|
|
332
|
+
NM_DROPDOWN_CLASSES.root,
|
|
333
|
+
props.reveal === NM_DROPDOWN_REVEAL.hover ? NM_DROPDOWN_CLASSES.revealHover : '',
|
|
334
|
+
]
|
|
335
|
+
.filter((value) => value !== '')
|
|
336
|
+
.join(' ');
|
|
337
|
+
|
|
338
|
+
let triggerElement: JSX.Element;
|
|
339
|
+
if (props.trigger === NM_DROPDOWN_TRIGGER.icon) {
|
|
340
|
+
triggerElement = (
|
|
341
|
+
<NordmanIconButton
|
|
342
|
+
label={props.label}
|
|
343
|
+
glyph={props.imageSrc == null ? (props.icon ?? 'ellipsis') : undefined}
|
|
344
|
+
imageSrc={props.imageSrc}
|
|
345
|
+
tone={NM_ICON_BUTTON_TONES.subtle}
|
|
346
|
+
disabled={props.disabled}
|
|
347
|
+
expanded={open}
|
|
348
|
+
popup="listbox"
|
|
349
|
+
controls={panelId}
|
|
350
|
+
ref={bindTrigger}
|
|
351
|
+
onClick={toggle}
|
|
352
|
+
/>
|
|
353
|
+
);
|
|
354
|
+
} else if (iconButton) {
|
|
355
|
+
triggerElement = (
|
|
356
|
+
<NordmanIconButton
|
|
357
|
+
glyph={props.icon ?? 'ellipsis'}
|
|
358
|
+
label={props.label}
|
|
359
|
+
className={props.triggerClassName}
|
|
360
|
+
aria-haspopup="listbox"
|
|
361
|
+
aria-expanded={open}
|
|
362
|
+
aria-controls={panelId}
|
|
363
|
+
ref={bindTrigger}
|
|
364
|
+
onClick={toggle}
|
|
365
|
+
/>
|
|
366
|
+
);
|
|
367
|
+
} else {
|
|
368
|
+
triggerElement = (
|
|
369
|
+
<button
|
|
370
|
+
className={triggerClass}
|
|
371
|
+
type="button"
|
|
372
|
+
aria-haspopup="listbox"
|
|
373
|
+
aria-expanded={open}
|
|
374
|
+
aria-controls={panelId}
|
|
375
|
+
aria-label={props.label}
|
|
376
|
+
ref={bindTrigger}
|
|
377
|
+
onClick={toggle}
|
|
378
|
+
>
|
|
379
|
+
{iconOnlyTrigger ? (
|
|
380
|
+
dropdownGlyph(
|
|
381
|
+
props.imageSrc,
|
|
382
|
+
iconOnlyTrigger ? (leadIcon ?? props.icon ?? 'ellipsis') : (props.icon ?? 'ellipsis'),
|
|
383
|
+
iconOnlyTrigger ? NM_DROPDOWN_CLASSES.lead : undefined,
|
|
384
|
+
)
|
|
385
|
+
) : (
|
|
386
|
+
<>
|
|
387
|
+
{dropdownGlyph(props.imageSrc, leadIcon, NM_DROPDOWN_CLASSES.lead)}
|
|
388
|
+
<span className={NM_DROPDOWN_CLASSES.label}>{triggerLabel}</span>
|
|
389
|
+
</>
|
|
390
|
+
)}
|
|
391
|
+
{chip || iconTrigger ? null : (
|
|
392
|
+
<NmIcon id="chevron" className={NM_DROPDOWN_CLASSES.chevron} />
|
|
393
|
+
)}
|
|
394
|
+
</button>
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return (
|
|
399
|
+
<div
|
|
400
|
+
className={rootClass}
|
|
401
|
+
ref={rootRef}
|
|
402
|
+
data-testid={props.testId}
|
|
403
|
+
data-open={open ? 'true' : undefined}
|
|
404
|
+
data-reveal={props.reveal}
|
|
405
|
+
>
|
|
406
|
+
{triggerElement}
|
|
407
|
+
{portal && typeof document !== 'undefined'
|
|
408
|
+
? createPortal(panel, dropdownPortalHost(props.portalRoot, triggerNodeRef.current))
|
|
409
|
+
: panel}
|
|
410
|
+
</div>
|
|
411
|
+
);
|
|
412
|
+
}
|