@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,355 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
useEffect,
|
|
4
|
+
useId,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
type KeyboardEventHandler,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
type Ref,
|
|
10
|
+
} from 'react';
|
|
11
|
+
import type { NmIconId } from '../../config/nm-icons.ts';
|
|
12
|
+
import {
|
|
13
|
+
NM_FIELD_CLASSES,
|
|
14
|
+
NM_FIELD_KINDS,
|
|
15
|
+
NM_FIELD_LAYOUT,
|
|
16
|
+
type NmFieldKind,
|
|
17
|
+
type NmFieldLayout,
|
|
18
|
+
type NmFieldOption,
|
|
19
|
+
} from '../../config/nm-field.ts';
|
|
20
|
+
import {
|
|
21
|
+
NM_DROPDOWN_ALIGN,
|
|
22
|
+
NM_DROPDOWN_REVEAL,
|
|
23
|
+
NM_DROPDOWN_TRIGGER,
|
|
24
|
+
} from '../../config/nm-dropdown.ts';
|
|
25
|
+
import { NmDropdown, type NmDropdownItem } from '../nm-dropdown/nm-dropdown.tsx';
|
|
26
|
+
import { createLogger } from '../../kit-logger.ts';
|
|
27
|
+
import { NmCombobox, NmComboboxContent, NmComboboxEmpty, NmComboboxInput, NmComboboxItem, NmComboboxList } from '../nm-combobox/nm-combobox.tsx';
|
|
28
|
+
import { NmSelect, NmSelectContent, NmSelectItem, NmSelectTrigger, NmSelectValue } from '../nm-select/nm-select.tsx';
|
|
29
|
+
import { NmColorSwatch } from '../nm-color-picker/nm-color-picker.tsx';
|
|
30
|
+
import { NmIcon } from '../nm-icon/nm-icon.tsx';
|
|
31
|
+
|
|
32
|
+
const logger = createLogger('interface-nm-field');
|
|
33
|
+
|
|
34
|
+
export type NmFieldProps = {
|
|
35
|
+
label: string;
|
|
36
|
+
value: string;
|
|
37
|
+
onChange: (value: string) => void;
|
|
38
|
+
kind?: NmFieldKind;
|
|
39
|
+
layout?: NmFieldLayout;
|
|
40
|
+
caption?: string;
|
|
41
|
+
placeholder?: string;
|
|
42
|
+
icon?: NmIconId;
|
|
43
|
+
/** Mark shown inside the field, before the value. */
|
|
44
|
+
leading?: ReactNode;
|
|
45
|
+
leadingSize?: 'mark' | 'face';
|
|
46
|
+
/** Keeps the value in the primary text color when the field is read-only. */
|
|
47
|
+
emphasis?: boolean;
|
|
48
|
+
trailing?: ReactNode;
|
|
49
|
+
/** Ellipsis menu. Hidden until the field is hovered or focused. */
|
|
50
|
+
menuItems?: readonly NmDropdownItem[];
|
|
51
|
+
menuLabel?: string;
|
|
52
|
+
onMenuSelect?: (id: string) => void;
|
|
53
|
+
options?: readonly NmFieldOption[];
|
|
54
|
+
searchPlaceholder?: string;
|
|
55
|
+
/** What a searchable select says when nothing matches. */
|
|
56
|
+
emptyLabel?: string;
|
|
57
|
+
searchValue?: string;
|
|
58
|
+
onSearchChange?: (value: string) => void;
|
|
59
|
+
onAdd?: () => void;
|
|
60
|
+
addLabel?: string;
|
|
61
|
+
addIcon?: NmIconId;
|
|
62
|
+
testId?: string;
|
|
63
|
+
disabled?: boolean;
|
|
64
|
+
readOnly?: boolean;
|
|
65
|
+
name?: string;
|
|
66
|
+
id?: string;
|
|
67
|
+
autoComplete?: string;
|
|
68
|
+
minLength?: number;
|
|
69
|
+
maxLength?: number;
|
|
70
|
+
className?: string;
|
|
71
|
+
inputRef?: Ref<HTMLInputElement>;
|
|
72
|
+
describedBy?: string;
|
|
73
|
+
invalid?: boolean;
|
|
74
|
+
keyShortcuts?: string;
|
|
75
|
+
onKeyDown?: KeyboardEventHandler<HTMLInputElement>;
|
|
76
|
+
onKeyUp?: KeyboardEventHandler<HTMLInputElement>;
|
|
77
|
+
onFocus?: () => void;
|
|
78
|
+
onBlur?: () => void;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
function OptionSwatches(props: { colors?: readonly string[] }): ReactNode {
|
|
82
|
+
return props.colors?.length ? (
|
|
83
|
+
<span className="nm-field__swatches">
|
|
84
|
+
{props.colors.map((color, index) => <NmColorSwatch key={index} color={color} shape="round" />)}
|
|
85
|
+
</span>
|
|
86
|
+
) : null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const NmField = forwardRef<HTMLDivElement, NmFieldProps>(
|
|
90
|
+
function NmField(props, ref): ReactNode {
|
|
91
|
+
const kind = props.kind ?? NM_FIELD_KINDS.text;
|
|
92
|
+
const layout = props.layout ?? NM_FIELD_LAYOUT.inline;
|
|
93
|
+
const generatedId = useId();
|
|
94
|
+
const controlId = props.id ?? generatedId;
|
|
95
|
+
const [open, setOpen] = useState(false);
|
|
96
|
+
const [searchQuery, setSearchQuery] = useState('');
|
|
97
|
+
logger.debug('render', props.label, { kind, layout, icon: props.icon });
|
|
98
|
+
|
|
99
|
+
if (layout === NM_FIELD_LAYOUT.stack) {
|
|
100
|
+
return (
|
|
101
|
+
<div
|
|
102
|
+
ref={ref}
|
|
103
|
+
className={
|
|
104
|
+
props.className
|
|
105
|
+
? `${NM_FIELD_CLASSES.root} ${NM_FIELD_CLASSES.stack} ${props.className}`
|
|
106
|
+
: `${NM_FIELD_CLASSES.root} ${NM_FIELD_CLASSES.stack}`
|
|
107
|
+
}
|
|
108
|
+
data-kind={kind}
|
|
109
|
+
data-leading={props.leadingSize}
|
|
110
|
+
>
|
|
111
|
+
{props.caption ? (
|
|
112
|
+
<label className={NM_FIELD_CLASSES.caption} htmlFor={controlId}>
|
|
113
|
+
{props.caption}
|
|
114
|
+
</label>
|
|
115
|
+
) : null}
|
|
116
|
+
<div className={NM_FIELD_CLASSES.row}>
|
|
117
|
+
<StackControl
|
|
118
|
+
{...props}
|
|
119
|
+
kind={kind}
|
|
120
|
+
controlId={controlId}
|
|
121
|
+
open={open}
|
|
122
|
+
setOpen={setOpen}
|
|
123
|
+
searchQuery={searchQuery}
|
|
124
|
+
setSearchQuery={setSearchQuery}
|
|
125
|
+
/>
|
|
126
|
+
{props.onAdd ? (
|
|
127
|
+
<button
|
|
128
|
+
className={NM_FIELD_CLASSES.add}
|
|
129
|
+
type="button"
|
|
130
|
+
aria-label={props.addLabel ?? props.label}
|
|
131
|
+
onClick={props.onAdd}
|
|
132
|
+
>
|
|
133
|
+
<NmIcon id={props.addIcon ?? 'plus'} />
|
|
134
|
+
</button>
|
|
135
|
+
) : null}
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<div
|
|
143
|
+
ref={ref}
|
|
144
|
+
className={
|
|
145
|
+
props.className ? `${NM_FIELD_CLASSES.root} ${props.className}` : NM_FIELD_CLASSES.root
|
|
146
|
+
}
|
|
147
|
+
>
|
|
148
|
+
{props.icon ? <NmIcon id={props.icon} className={NM_FIELD_CLASSES.icon} /> : null}
|
|
149
|
+
<input
|
|
150
|
+
ref={props.inputRef}
|
|
151
|
+
className={NM_FIELD_CLASSES.control}
|
|
152
|
+
id={props.id}
|
|
153
|
+
name={props.name}
|
|
154
|
+
type={
|
|
155
|
+
kind === NM_FIELD_KINDS.select || kind === NM_FIELD_KINDS.area
|
|
156
|
+
? NM_FIELD_KINDS.text
|
|
157
|
+
: kind
|
|
158
|
+
}
|
|
159
|
+
value={props.value}
|
|
160
|
+
placeholder={props.placeholder}
|
|
161
|
+
aria-label={props.label}
|
|
162
|
+
aria-describedby={props.describedBy}
|
|
163
|
+
aria-keyshortcuts={props.keyShortcuts}
|
|
164
|
+
disabled={props.disabled}
|
|
165
|
+
readOnly={props.readOnly}
|
|
166
|
+
autoComplete={props.autoComplete}
|
|
167
|
+
minLength={props.minLength}
|
|
168
|
+
maxLength={props.maxLength}
|
|
169
|
+
data-testid={props.testId}
|
|
170
|
+
onChange={(event) => props.onChange(event.target.value)}
|
|
171
|
+
onKeyDown={props.onKeyDown}
|
|
172
|
+
onKeyUp={props.onKeyUp}
|
|
173
|
+
onFocus={props.onFocus}
|
|
174
|
+
onBlur={props.onBlur}
|
|
175
|
+
/>
|
|
176
|
+
{props.trailing != null ? (
|
|
177
|
+
<div className={NM_FIELD_CLASSES.trail}>{props.trailing}</div>
|
|
178
|
+
) : null}
|
|
179
|
+
</div>
|
|
180
|
+
);
|
|
181
|
+
},
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
function StackControl(
|
|
185
|
+
props: NmFieldProps & {
|
|
186
|
+
kind: NmFieldKind;
|
|
187
|
+
controlId: string;
|
|
188
|
+
open: boolean;
|
|
189
|
+
setOpen: (open: boolean) => void;
|
|
190
|
+
searchQuery: string;
|
|
191
|
+
setSearchQuery: (query: string) => void;
|
|
192
|
+
},
|
|
193
|
+
): ReactNode {
|
|
194
|
+
const boxRef = useRef<HTMLDivElement | null>(null);
|
|
195
|
+
/** The list lines up with the whole box of the field, not with the control inside it. */
|
|
196
|
+
const [boxEl, setBoxEl] = useState<HTMLDivElement | null>(null);
|
|
197
|
+
const { open, setOpen, setSearchQuery, onSearchChange } = props;
|
|
198
|
+
|
|
199
|
+
useEffect(() => {
|
|
200
|
+
if (!open) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const onPointer = (event: MouseEvent) => {
|
|
204
|
+
if (boxRef.current && !boxRef.current.contains(event.target as Node)) {
|
|
205
|
+
setOpen(false);
|
|
206
|
+
setSearchQuery('');
|
|
207
|
+
onSearchChange?.('');
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
const onKey = (event: KeyboardEvent) => {
|
|
211
|
+
if (event.key === 'Escape') {
|
|
212
|
+
setOpen(false);
|
|
213
|
+
setSearchQuery('');
|
|
214
|
+
onSearchChange?.('');
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
document.addEventListener('mousedown', onPointer);
|
|
218
|
+
document.addEventListener('keydown', onKey);
|
|
219
|
+
return () => {
|
|
220
|
+
document.removeEventListener('mousedown', onPointer);
|
|
221
|
+
document.removeEventListener('keydown', onKey);
|
|
222
|
+
};
|
|
223
|
+
}, [open, setOpen, setSearchQuery, onSearchChange]);
|
|
224
|
+
|
|
225
|
+
const icon = props.icon ?? (props.kind === NM_FIELD_KINDS.search ? 'search' : undefined);
|
|
226
|
+
const selected = props.options?.find((option) => option.id === props.value);
|
|
227
|
+
const menu =
|
|
228
|
+
props.menuItems != null && props.menuItems.length > 0 ? (
|
|
229
|
+
<NmDropdown
|
|
230
|
+
label={props.menuLabel ?? props.label}
|
|
231
|
+
trigger={NM_DROPDOWN_TRIGGER.iconButton}
|
|
232
|
+
icon="ellipsis"
|
|
233
|
+
align={NM_DROPDOWN_ALIGN.end}
|
|
234
|
+
reveal={NM_DROPDOWN_REVEAL.hover}
|
|
235
|
+
items={props.menuItems}
|
|
236
|
+
onSelect={(id) => props.onMenuSelect?.(id)}
|
|
237
|
+
/>
|
|
238
|
+
) : null;
|
|
239
|
+
let editor: ReactNode;
|
|
240
|
+
if (props.kind === NM_FIELD_KINDS.select && props.searchPlaceholder == null) {
|
|
241
|
+
const options = props.options ?? [];
|
|
242
|
+
const labelOf = (id: string) => {
|
|
243
|
+
const option = options.find((o) => o.id === id);
|
|
244
|
+
return option ? <>{option.label}<OptionSwatches colors={option.swatches} /></> : (props.placeholder ?? props.label);
|
|
245
|
+
};
|
|
246
|
+
editor = (
|
|
247
|
+
<NmSelect value={props.value} onValueChange={(next) => next != null && props.onChange(String(next))} disabled={props.disabled}>
|
|
248
|
+
<NmSelectTrigger bare id={props.controlId} aria-label={props.label} className={NM_FIELD_CLASSES.control} data-testid={props.testId}>
|
|
249
|
+
<NmSelectValue>{(value: string) => <span className="nm-field__value">{value ? labelOf(value) : (props.placeholder ?? props.label)}</span>}</NmSelectValue>
|
|
250
|
+
</NmSelectTrigger>
|
|
251
|
+
<NmSelectContent anchor={boxEl}>
|
|
252
|
+
{options.map((option) => (
|
|
253
|
+
<NmSelectItem key={option.id} value={option.id}>
|
|
254
|
+
{option.label}
|
|
255
|
+
<OptionSwatches colors={option.swatches} />
|
|
256
|
+
</NmSelectItem>
|
|
257
|
+
))}
|
|
258
|
+
</NmSelectContent>
|
|
259
|
+
</NmSelect>
|
|
260
|
+
);
|
|
261
|
+
} else if (props.kind === NM_FIELD_KINDS.select) {
|
|
262
|
+
// A select with a search box is a combobox: type to filter, then choose.
|
|
263
|
+
type Item = { value: string; label: string; swatches?: readonly string[] };
|
|
264
|
+
const items: Item[] = (props.options ?? []).map((o) => ({ value: o.id, label: o.label, swatches: o.swatches }));
|
|
265
|
+
const chosen = items.find((item) => item.value === props.value) ?? null;
|
|
266
|
+
editor = (
|
|
267
|
+
<NmCombobox<Item>
|
|
268
|
+
items={items}
|
|
269
|
+
value={chosen}
|
|
270
|
+
onValueChange={(item) => item != null && props.onChange(item.value)}
|
|
271
|
+
onInputValueChange={(text) => props.onSearchChange?.(text)}
|
|
272
|
+
filter={props.searchValue != null ? null : undefined}
|
|
273
|
+
itemToStringLabel={(item) => item.label}
|
|
274
|
+
isItemEqualToValue={(a, b) => a.value === b.value}
|
|
275
|
+
disabled={props.disabled}
|
|
276
|
+
>
|
|
277
|
+
<NmComboboxInput bare id={props.controlId} aria-label={props.label} placeholder={props.searchPlaceholder} className={NM_FIELD_CLASSES.control} />
|
|
278
|
+
<NmComboboxContent anchor={boxEl}>
|
|
279
|
+
<NmComboboxEmpty>{props.emptyLabel ?? 'No results'}</NmComboboxEmpty>
|
|
280
|
+
<NmComboboxList>
|
|
281
|
+
{(item: Item) => (
|
|
282
|
+
<NmComboboxItem key={item.value} value={item}>
|
|
283
|
+
{item.label}
|
|
284
|
+
<OptionSwatches colors={item.swatches} />
|
|
285
|
+
</NmComboboxItem>
|
|
286
|
+
)}
|
|
287
|
+
</NmComboboxList>
|
|
288
|
+
</NmComboboxContent>
|
|
289
|
+
</NmCombobox>
|
|
290
|
+
);
|
|
291
|
+
} else if (props.kind === NM_FIELD_KINDS.area) {
|
|
292
|
+
editor = (
|
|
293
|
+
<textarea
|
|
294
|
+
className={NM_FIELD_CLASSES.control}
|
|
295
|
+
id={props.controlId}
|
|
296
|
+
name={props.name}
|
|
297
|
+
value={props.value}
|
|
298
|
+
placeholder={props.placeholder}
|
|
299
|
+
aria-label={props.caption ? undefined : props.label}
|
|
300
|
+
disabled={props.disabled}
|
|
301
|
+
readOnly={props.readOnly}
|
|
302
|
+
maxLength={props.maxLength}
|
|
303
|
+
data-testid={props.testId}
|
|
304
|
+
onChange={(event) => props.onChange(event.target.value)}
|
|
305
|
+
/>
|
|
306
|
+
);
|
|
307
|
+
} else {
|
|
308
|
+
editor = (
|
|
309
|
+
<input
|
|
310
|
+
ref={props.inputRef}
|
|
311
|
+
className={NM_FIELD_CLASSES.control}
|
|
312
|
+
id={props.controlId}
|
|
313
|
+
name={props.name}
|
|
314
|
+
type={props.kind}
|
|
315
|
+
value={props.value}
|
|
316
|
+
placeholder={props.placeholder}
|
|
317
|
+
aria-label={props.caption ? undefined : props.label}
|
|
318
|
+
aria-describedby={props.describedBy}
|
|
319
|
+
aria-invalid={props.invalid || undefined}
|
|
320
|
+
data-emphasis={props.emphasis ? 'true' : undefined}
|
|
321
|
+
disabled={props.disabled}
|
|
322
|
+
readOnly={props.readOnly}
|
|
323
|
+
autoComplete={props.autoComplete}
|
|
324
|
+
minLength={props.minLength}
|
|
325
|
+
maxLength={props.maxLength}
|
|
326
|
+
data-testid={props.testId}
|
|
327
|
+
onChange={(event) => props.onChange(event.target.value)}
|
|
328
|
+
onKeyDown={props.onKeyDown}
|
|
329
|
+
onKeyUp={props.onKeyUp}
|
|
330
|
+
onFocus={props.onFocus}
|
|
331
|
+
onBlur={props.onBlur}
|
|
332
|
+
/>
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
return (
|
|
336
|
+
<div ref={(el) => {
|
|
337
|
+
boxRef.current = el;
|
|
338
|
+
setBoxEl(el);
|
|
339
|
+
}} className={NM_FIELD_CLASSES.box} data-nm-menu={menu != null ? '' : undefined}>
|
|
340
|
+
{icon ? <NmIcon id={icon} className={NM_FIELD_CLASSES.icon} /> : null}
|
|
341
|
+
{props.leading != null ? (
|
|
342
|
+
<span className={NM_FIELD_CLASSES.mark}>{props.leading}</span>
|
|
343
|
+
) : null}
|
|
344
|
+
{editor}
|
|
345
|
+
{props.trailing != null || menu != null ? (
|
|
346
|
+
<div className={NM_FIELD_CLASSES.trail}>
|
|
347
|
+
{props.trailing}
|
|
348
|
+
{menu}
|
|
349
|
+
</div>
|
|
350
|
+
) : null}
|
|
351
|
+
</div>
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export { NM_FIELD_KINDS, NM_FIELD_LAYOUT };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
.nm-field-set {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: var(--nm-space-16);
|
|
5
|
+
min-width: 0;
|
|
6
|
+
margin: 0;
|
|
7
|
+
padding: 0;
|
|
8
|
+
border: 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.nm-field-legend {
|
|
12
|
+
margin-bottom: var(--nm-space-4);
|
|
13
|
+
padding: 0;
|
|
14
|
+
color: var(--nm-fg);
|
|
15
|
+
font-family: var(--nm-font);
|
|
16
|
+
font-size: var(--nm-type-body);
|
|
17
|
+
font-weight: var(--nm-weight-medium);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.nm-field-legend[data-variant='label'] {
|
|
21
|
+
font-size: var(--nm-type-ui);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.nm-field-group {
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
27
|
+
gap: var(--nm-space-24);
|
|
28
|
+
width: 100%;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.nm-form-field {
|
|
32
|
+
display: flex;
|
|
33
|
+
flex-direction: column;
|
|
34
|
+
gap: var(--nm-space-8);
|
|
35
|
+
width: 100%;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.nm-form-field[data-orientation='horizontal'] {
|
|
39
|
+
flex-direction: row;
|
|
40
|
+
align-items: flex-start;
|
|
41
|
+
gap: var(--nm-space-12);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.nm-form-field[data-disabled] {
|
|
45
|
+
opacity: 0.5;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.nm-field-content {
|
|
49
|
+
display: flex;
|
|
50
|
+
flex: 1;
|
|
51
|
+
flex-direction: column;
|
|
52
|
+
gap: var(--nm-space-2);
|
|
53
|
+
min-width: 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.nm-field-title {
|
|
57
|
+
color: var(--nm-fg);
|
|
58
|
+
font-family: var(--nm-font);
|
|
59
|
+
font-size: var(--nm-type-ui);
|
|
60
|
+
font-weight: var(--nm-weight-medium);
|
|
61
|
+
line-height: var(--nm-leading-snug);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.nm-field-description {
|
|
65
|
+
margin: 0;
|
|
66
|
+
color: var(--nm-fg-muted);
|
|
67
|
+
font-family: var(--nm-font);
|
|
68
|
+
font-size: var(--nm-type-ui-sm);
|
|
69
|
+
line-height: var(--nm-leading-snug);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.nm-field-error {
|
|
73
|
+
color: var(--nm-destructive);
|
|
74
|
+
font-family: var(--nm-font);
|
|
75
|
+
font-size: var(--nm-type-ui-sm);
|
|
76
|
+
line-height: var(--nm-leading-snug);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Two lines with the text between them. No background is needed, so it sits on any surface. */
|
|
80
|
+
.nm-field-separator {
|
|
81
|
+
display: flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
min-height: var(--nm-space-8);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.nm-field-separator[data-content] {
|
|
87
|
+
gap: var(--nm-space-12);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.nm-field-separator::before,
|
|
91
|
+
.nm-field-separator::after {
|
|
92
|
+
content: '';
|
|
93
|
+
flex: 1;
|
|
94
|
+
height: var(--nm-rule);
|
|
95
|
+
background: var(--nm-line);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.nm-field-separator__text {
|
|
99
|
+
flex-shrink: 0;
|
|
100
|
+
color: var(--nm-fg-subtle);
|
|
101
|
+
font-family: var(--nm-font);
|
|
102
|
+
font-size: var(--nm-type-ui-sm);
|
|
103
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ComponentProps } from 'react';
|
|
2
|
+
import { nmClass } from '../../lib/nm-class.ts';
|
|
3
|
+
import { NmLabel } from '../nm-label/nm-label.tsx';
|
|
4
|
+
|
|
5
|
+
/** The shadcn Field family. NmField is the older all-in-one field. These parts compose any control into a form. */
|
|
6
|
+
export function NmFieldSet({ className, ...props }: ComponentProps<'fieldset'>) {
|
|
7
|
+
return <fieldset data-slot="field-set" className={nmClass('nm-field-set', className)} {...props} />;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function NmFieldLegend({ className, variant = 'legend', ...props }: ComponentProps<'legend'> & { variant?: 'legend' | 'label' }) {
|
|
11
|
+
return <legend data-slot="field-legend" data-variant={variant} className={nmClass('nm-field-legend', className)} {...props} />;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function NmFieldGroup({ className, ...props }: ComponentProps<'div'>) {
|
|
15
|
+
return <div data-slot="field-group" className={nmClass('nm-field-group', className)} {...props} />;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function NmFormField({
|
|
19
|
+
className,
|
|
20
|
+
orientation = 'vertical',
|
|
21
|
+
invalid,
|
|
22
|
+
disabled,
|
|
23
|
+
...props
|
|
24
|
+
}: ComponentProps<'div'> & { orientation?: 'vertical' | 'horizontal'; invalid?: boolean; disabled?: boolean }) {
|
|
25
|
+
return (
|
|
26
|
+
<div
|
|
27
|
+
data-slot="field"
|
|
28
|
+
role="group"
|
|
29
|
+
data-orientation={orientation}
|
|
30
|
+
data-invalid={invalid ? '' : undefined}
|
|
31
|
+
data-disabled={disabled ? '' : undefined}
|
|
32
|
+
className={nmClass('nm-form-field', className)}
|
|
33
|
+
{...props}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function NmFieldContent({ className, ...props }: ComponentProps<'div'>) {
|
|
39
|
+
return <div data-slot="field-content" className={nmClass('nm-field-content', className)} {...props} />;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function NmFieldLabel({ className, ...props }: ComponentProps<'label'>) {
|
|
43
|
+
return <NmLabel data-slot="field-label" className={nmClass('nm-field-label', className)} {...props} />;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function NmFieldTitle({ className, ...props }: ComponentProps<'div'>) {
|
|
47
|
+
return <div data-slot="field-title" className={nmClass('nm-field-title', className)} {...props} />;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function NmFieldDescription({ className, ...props }: ComponentProps<'p'>) {
|
|
51
|
+
return <p data-slot="field-description" className={nmClass('nm-field-description', className)} {...props} />;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function NmFieldError({ className, children, ...props }: ComponentProps<'div'>) {
|
|
55
|
+
if (children == null) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return (
|
|
59
|
+
<div data-slot="field-error" role="alert" className={nmClass('nm-field-error', className)} {...props}>
|
|
60
|
+
{children}
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function NmFieldSeparator({ className, children, ...props }: ComponentProps<'div'>) {
|
|
66
|
+
return (
|
|
67
|
+
<div data-slot="field-separator" data-content={children != null ? '' : undefined} className={nmClass('nm-field-separator', className)} {...props}>
|
|
68
|
+
{children != null ? <span className="nm-field-separator__text">{children}</span> : null}
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
.nm-gallery {
|
|
2
|
+
display: grid;
|
|
3
|
+
grid-template-columns: repeat(auto-fill, minmax(var(--nm-width-tile), 1fr));
|
|
4
|
+
gap: var(--nm-space-12);
|
|
5
|
+
margin: 0;
|
|
6
|
+
padding: 0;
|
|
7
|
+
list-style: none;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.nm-gallery__cell {
|
|
11
|
+
display: flex;
|
|
12
|
+
min-width: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.nm-gallery__item {
|
|
16
|
+
box-sizing: border-box;
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
gap: var(--nm-space-8);
|
|
20
|
+
width: 100%;
|
|
21
|
+
padding: var(--nm-space-8);
|
|
22
|
+
border: var(--nm-rule) solid transparent;
|
|
23
|
+
border-radius: var(--nm-radius-lg);
|
|
24
|
+
background: var(--nm-raised);
|
|
25
|
+
color: var(--nm-fg);
|
|
26
|
+
font: inherit;
|
|
27
|
+
font-size: var(--nm-type-ui-sm);
|
|
28
|
+
text-align: start;
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.nm-gallery__item:hover {
|
|
33
|
+
background: var(--nm-line);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.nm-gallery__item[data-selected] {
|
|
37
|
+
border-color: var(--nm-fg);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.nm-gallery__item:focus-visible {
|
|
41
|
+
outline: var(--nm-rule) solid var(--focus);
|
|
42
|
+
outline-offset: var(--nm-space-2);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.nm-gallery__media {
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
aspect-ratio: 4 / 3;
|
|
50
|
+
overflow: hidden;
|
|
51
|
+
border-radius: var(--nm-radius-md);
|
|
52
|
+
background: var(--nm-inset);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.nm-gallery__media > img {
|
|
56
|
+
width: 100%;
|
|
57
|
+
height: 100%;
|
|
58
|
+
object-fit: cover;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.nm-gallery__label {
|
|
62
|
+
overflow: hidden;
|
|
63
|
+
color: var(--nm-fg-muted);
|
|
64
|
+
text-overflow: ellipsis;
|
|
65
|
+
white-space: nowrap;
|
|
66
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
2
|
+
import { nmClass } from '../../lib/nm-class.ts';
|
|
3
|
+
|
|
4
|
+
/** Images, or any media, in a grid. Each item is a button, so choosing one opens it, for example in the side panel. */
|
|
5
|
+
export function NmGallery({ className, ...props }: ComponentProps<'ul'>) {
|
|
6
|
+
return <ul data-slot="gallery" className={nmClass('nm-gallery', className)} {...props} />;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function NmGalleryItem({
|
|
10
|
+
className,
|
|
11
|
+
label,
|
|
12
|
+
selected,
|
|
13
|
+
children,
|
|
14
|
+
...props
|
|
15
|
+
}: Omit<ComponentProps<'button'>, 'children'> & { label: string; selected?: boolean; children: ReactNode }) {
|
|
16
|
+
return (
|
|
17
|
+
<li className="nm-gallery__cell">
|
|
18
|
+
<button
|
|
19
|
+
type="button"
|
|
20
|
+
data-slot="gallery-item"
|
|
21
|
+
data-selected={selected ? '' : undefined}
|
|
22
|
+
aria-pressed={selected ?? undefined}
|
|
23
|
+
className={nmClass('nm-gallery__item', className)}
|
|
24
|
+
{...props}
|
|
25
|
+
>
|
|
26
|
+
<span className="nm-gallery__media">{children}</span>
|
|
27
|
+
<span className="nm-gallery__label">{label}</span>
|
|
28
|
+
</button>
|
|
29
|
+
</li>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
.nm-hover-card__positioner {
|
|
2
|
+
z-index: var(--nm-menu-z);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.nm-hover-card {
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
gap: var(--nm-space-12);
|
|
10
|
+
width: var(--nm-width-popup-sm);
|
|
11
|
+
padding: var(--nm-panel-pad);
|
|
12
|
+
border: var(--nm-rule) solid var(--nm-line-strong);
|
|
13
|
+
border-radius: var(--nm-control-menu-radius);
|
|
14
|
+
background: var(--nm-panel);
|
|
15
|
+
color: var(--nm-fg);
|
|
16
|
+
font-family: var(--nm-font);
|
|
17
|
+
font-size: var(--nm-type-ui);
|
|
18
|
+
line-height: var(--nm-leading-normal);
|
|
19
|
+
outline: none;
|
|
20
|
+
transition: opacity 0.12s;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.nm-hover-card[data-starting-style],
|
|
24
|
+
.nm-hover-card[data-ending-style] {
|
|
25
|
+
opacity: 0;
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PreviewCard as PreviewCardPrimitive } from '@base-ui/react/preview-card';
|
|
2
|
+
import { nmClass } from '../../lib/nm-class.ts';
|
|
3
|
+
|
|
4
|
+
/** Base UI Preview Card, in the shadcn hover-card composition, styled by NIF tokens. */
|
|
5
|
+
export function NmHoverCard(props: PreviewCardPrimitive.Root.Props) {
|
|
6
|
+
return <PreviewCardPrimitive.Root data-slot="hover-card" {...props} />;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function NmHoverCardTrigger(props: PreviewCardPrimitive.Trigger.Props) {
|
|
10
|
+
return <PreviewCardPrimitive.Trigger data-slot="hover-card-trigger" {...props} />;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function NmHoverCardContent({
|
|
14
|
+
className,
|
|
15
|
+
side = 'bottom',
|
|
16
|
+
sideOffset = 8,
|
|
17
|
+
align = 'center',
|
|
18
|
+
alignOffset = 0,
|
|
19
|
+
...props
|
|
20
|
+
}: PreviewCardPrimitive.Popup.Props & Pick<PreviewCardPrimitive.Positioner.Props, 'align' | 'alignOffset' | 'side' | 'sideOffset'>) {
|
|
21
|
+
return (
|
|
22
|
+
<PreviewCardPrimitive.Portal data-slot="hover-card-portal">
|
|
23
|
+
<PreviewCardPrimitive.Positioner align={align} alignOffset={alignOffset} side={side} sideOffset={sideOffset} className="nm-hover-card__positioner">
|
|
24
|
+
<PreviewCardPrimitive.Popup data-slot="hover-card-content" className={nmClass('nm-hover-card', className as string)} {...props} />
|
|
25
|
+
</PreviewCardPrimitive.Positioner>
|
|
26
|
+
</PreviewCardPrimitive.Portal>
|
|
27
|
+
);
|
|
28
|
+
}
|