@plexui/ui 0.28.1 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/components/Alert/Alert.js +2 -2
- package/dist/es/components/Alert/Alert.js.map +1 -1
- package/dist/es/components/Avatar/Avatar.js +3 -1
- package/dist/es/components/Avatar/Avatar.js.map +1 -1
- package/dist/es/components/Badge/index.js +1 -1
- package/dist/es/components/Badge/index.js.map +1 -1
- package/dist/es/components/Button/Button.js +4 -3
- package/dist/es/components/Button/Button.js.map +1 -1
- package/dist/es/components/Button/NavigationButton.js +10 -0
- package/dist/es/components/Button/NavigationButton.js.map +1 -0
- package/dist/es/components/Button/NavigationGlyph.js +19 -0
- package/dist/es/components/Button/NavigationGlyph.js.map +1 -0
- package/dist/es/components/Button/index.js +1 -0
- package/dist/es/components/Button/index.js.map +1 -1
- package/dist/es/components/Checkbox/Checkbox.js +2 -1
- package/dist/es/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/es/components/ColorPicker/ColorPicker.js +227 -0
- package/dist/es/components/ColorPicker/ColorPicker.js.map +1 -0
- package/dist/es/components/ColorPicker/ColorWell.js +58 -0
- package/dist/es/components/ColorPicker/ColorWell.js.map +1 -0
- package/dist/es/components/ColorPicker/index.js +3 -0
- package/dist/es/components/ColorPicker/index.js.map +1 -0
- package/dist/es/components/ColorPicker/shared.js +132 -0
- package/dist/es/components/ColorPicker/shared.js.map +1 -0
- package/dist/es/components/ContextMenu/ContextMenu.js +164 -0
- package/dist/es/components/ContextMenu/ContextMenu.js.map +1 -0
- package/dist/es/components/ContextMenu/index.js +2 -0
- package/dist/es/components/ContextMenu/index.js.map +1 -0
- package/dist/es/components/ContextMenu/shared.js +56 -0
- package/dist/es/components/ContextMenu/shared.js.map +1 -0
- package/dist/es/components/DateInput/DateInput.js +4 -2
- package/dist/es/components/DateInput/DateInput.js.map +1 -1
- package/dist/es/components/DatePicker/Calendar.js +89 -55
- package/dist/es/components/DatePicker/Calendar.js.map +1 -1
- package/dist/es/components/DatePicker/CalendarNavigationIcon.js +13 -0
- package/dist/es/components/DatePicker/CalendarNavigationIcon.js.map +1 -0
- package/dist/es/components/DatePicker/DatePicker.js +9 -2
- package/dist/es/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/es/components/DatePicker/useCalendarGutter.js +8 -0
- package/dist/es/components/DatePicker/useCalendarGutter.js.map +1 -0
- package/dist/es/components/DateRangePicker/Calendar.js +66 -49
- package/dist/es/components/DateRangePicker/Calendar.js.map +1 -1
- package/dist/es/components/DateRangePicker/DateRangePicker.js +6 -1
- package/dist/es/components/DateRangePicker/DateRangePicker.js.map +1 -1
- package/dist/es/components/DateRangePicker/Trigger.js +1 -1
- package/dist/es/components/DateRangePicker/Trigger.js.map +1 -1
- package/dist/es/components/Dialog/Dialog.js +136 -20
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Dialog/index.js.map +1 -1
- package/dist/es/components/Dialog/sheetDrag.js +77 -24
- package/dist/es/components/Dialog/sheetDrag.js.map +1 -1
- package/dist/es/components/Field/Field.js +51 -4
- package/dist/es/components/Field/Field.js.map +1 -1
- package/dist/es/components/FieldGroup/FieldGroup.js +4 -2
- package/dist/es/components/FieldGroup/FieldGroup.js.map +1 -1
- package/dist/es/components/FileUpload/FileUpload.js +43 -3
- package/dist/es/components/FileUpload/FileUpload.js.map +1 -1
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +18 -16
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js.map +1 -1
- package/dist/es/components/FloatingLabelSelect/FloatingLabelSelect.js +11 -6
- package/dist/es/components/FloatingLabelSelect/FloatingLabelSelect.js.map +1 -1
- package/dist/es/components/Icon/index.js +2 -0
- package/dist/es/components/Icon/index.js.map +1 -1
- package/dist/es/components/Icon/svg/Disclosure.js +5 -0
- package/dist/es/components/Icon/svg/Disclosure.js.map +1 -0
- package/dist/es/components/Icon/svg/Eyedropper.js +6 -0
- package/dist/es/components/Icon/svg/Eyedropper.js.map +1 -0
- package/dist/es/components/Indicator/LoadingIndicator.js +1 -1
- package/dist/es/components/Indicator/LoadingIndicator.js.map +1 -1
- package/dist/es/components/Input/Input.js +3 -3
- package/dist/es/components/Input/Input.js.map +1 -1
- package/dist/es/components/InputGroup/InputGroup.js +3 -1
- package/dist/es/components/InputGroup/InputGroup.js.map +1 -1
- package/dist/es/components/MarkdownEditor/MarkdownEditor.js +95 -93
- package/dist/es/components/MarkdownEditor/MarkdownEditor.js.map +1 -1
- package/dist/es/components/Menu/Menu.js +306 -34
- package/dist/es/components/Menu/Menu.js.map +1 -1
- package/dist/es/components/OTPInput/OTPInput.js +4 -1
- package/dist/es/components/OTPInput/OTPInput.js.map +1 -1
- package/dist/es/components/Page/Page.js +147 -19
- package/dist/es/components/Page/Page.js.map +1 -1
- package/dist/es/components/Page/index.js.map +1 -1
- package/dist/es/components/PageControl/PageControl.js +146 -0
- package/dist/es/components/PageControl/PageControl.js.map +1 -0
- package/dist/es/components/PageControl/index.js +2 -0
- package/dist/es/components/PageControl/index.js.map +1 -0
- package/dist/es/components/Popover/Popover.js +75 -33
- package/dist/es/components/Popover/Popover.js.map +1 -1
- package/dist/es/components/Popover/deferredOutsidePress.js +90 -0
- package/dist/es/components/Popover/deferredOutsidePress.js.map +1 -0
- package/dist/es/components/Popover/usePopoverContext.js.map +1 -1
- package/dist/es/components/RadioGroup/RadioGroup.js +1 -1
- package/dist/es/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/es/components/Select/Select.js +98 -32
- package/dist/es/components/Select/Select.js.map +1 -1
- package/dist/es/components/SelectControl/SelectControl.js +48 -29
- package/dist/es/components/SelectControl/SelectControl.js.map +1 -1
- package/dist/es/components/SelectControl/index.js +1 -1
- package/dist/es/components/SelectControl/index.js.map +1 -1
- package/dist/es/components/ShimmerText/ShimmerText.js +17 -7
- package/dist/es/components/ShimmerText/ShimmerText.js.map +1 -1
- package/dist/es/components/Sidebar/Sidebar.js +21 -8
- package/dist/es/components/Sidebar/Sidebar.js.map +1 -1
- package/dist/es/components/Slider/Slider.js +61 -15
- package/dist/es/components/Slider/Slider.js.map +1 -1
- package/dist/es/components/Sortable/Sortable.js +16 -6
- package/dist/es/components/Sortable/Sortable.js.map +1 -1
- package/dist/es/components/Stepper/Stepper.js +114 -0
- package/dist/es/components/Stepper/Stepper.js.map +1 -0
- package/dist/es/components/Stepper/index.js +2 -0
- package/dist/es/components/Stepper/index.js.map +1 -0
- package/dist/es/components/Switch/Switch.js +2 -2
- package/dist/es/components/Switch/Switch.js.map +1 -1
- package/dist/es/components/TabBar/TabBar.js +128 -0
- package/dist/es/components/TabBar/TabBar.js.map +1 -0
- package/dist/es/components/TabBar/index.js +2 -0
- package/dist/es/components/TabBar/index.js.map +1 -0
- package/dist/es/components/Tabs/Tabs.js +27 -11
- package/dist/es/components/Tabs/Tabs.js.map +1 -1
- package/dist/es/components/TagInput/TagInput.js +40 -4
- package/dist/es/components/TagInput/TagInput.js.map +1 -1
- package/dist/es/components/Textarea/Textarea.js +7 -1
- package/dist/es/components/Textarea/Textarea.js.map +1 -1
- package/dist/es/components/Toast/ToastRenderer.js +86 -0
- package/dist/es/components/Toast/ToastRenderer.js.map +1 -0
- package/dist/es/components/Toast/Toaster.js +31 -16
- package/dist/es/components/Toast/Toaster.js.map +1 -1
- package/dist/es/components/Toast/toastLifecycle.js +283 -0
- package/dist/es/components/Toast/toastLifecycle.js.map +1 -0
- package/dist/es/components/Toolbar/Toolbar.js +92 -0
- package/dist/es/components/Toolbar/Toolbar.js.map +1 -0
- package/dist/es/components/Toolbar/index.js +2 -0
- package/dist/es/components/Toolbar/index.js.map +1 -0
- package/dist/es/components/Tooltip/CopyTooltip.js +37 -11
- package/dist/es/components/Tooltip/CopyTooltip.js.map +1 -1
- package/dist/es/components/Tooltip/Tooltip.js +61 -9
- package/dist/es/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/es/hooks/useFloatingBoundary.js +35 -0
- package/dist/es/hooks/useFloatingBoundary.js.map +1 -0
- package/dist/es/hooks/usePhoneSubmenu.js +22 -0
- package/dist/es/hooks/usePhoneSubmenu.js.map +1 -0
- package/dist/es/lib/copyToClipboard.js +16 -7
- package/dist/es/lib/copyToClipboard.js.map +1 -1
- package/dist/es/lib/fieldRow.js +7 -1
- package/dist/es/lib/fieldRow.js.map +1 -1
- package/dist/es/lib/floatingBoundary.js +90 -0
- package/dist/es/lib/floatingBoundary.js.map +1 -0
- package/dist/es/lib/focusRestore.js +56 -0
- package/dist/es/lib/focusRestore.js.map +1 -0
- package/dist/es/lib/helpers.js +0 -18
- package/dist/es/lib/helpers.js.map +1 -1
- package/dist/es/lib/inputMode.js +9 -0
- package/dist/es/lib/inputMode.js.map +1 -0
- package/dist/es/lib/menuInitialFocus.js +100 -0
- package/dist/es/lib/menuInitialFocus.js.map +1 -0
- package/dist/es/lib/menuSubmenuPlacement.js +264 -0
- package/dist/es/lib/menuSubmenuPlacement.js.map +1 -0
- package/dist/es/lib/menuTriggerCover.js +70 -0
- package/dist/es/lib/menuTriggerCover.js.map +1 -0
- package/dist/es/lib/observeTextareaWidth.js +49 -0
- package/dist/es/lib/observeTextareaWidth.js.map +1 -0
- package/dist/es/lib/scrollEdges.js +34 -0
- package/dist/es/lib/scrollEdges.js.map +1 -0
- package/dist/es/lib/selectPress.js +34 -0
- package/dist/es/lib/selectPress.js.map +1 -0
- package/dist/es/lib/sortable.js +74 -20
- package/dist/es/lib/sortable.js.map +1 -1
- package/dist/es/styles/mobile-materials.css +1 -0
- package/dist/es/styles/mobile-surfaces.css +1 -0
- package/dist/types/components/Button/Button.d.ts +2 -0
- package/dist/types/components/Button/NavigationButton.d.ts +8 -0
- package/dist/types/components/Button/NavigationGlyph.d.ts +7 -0
- package/dist/types/components/Button/index.d.ts +1 -0
- package/dist/types/components/ColorPicker/ColorPicker.d.ts +34 -0
- package/dist/types/components/ColorPicker/ColorWell.d.ts +32 -0
- package/dist/types/components/ColorPicker/index.d.ts +3 -0
- package/dist/types/components/ColorPicker/shared.d.ts +69 -0
- package/dist/types/components/ContextMenu/ContextMenu.d.ts +78 -0
- package/dist/types/components/ContextMenu/index.d.ts +1 -0
- package/dist/types/components/ContextMenu/shared.d.ts +50 -0
- package/dist/types/components/DatePicker/CalendarNavigationIcon.d.ts +5 -0
- package/dist/types/components/DatePicker/DatePicker.d.ts +7 -1
- package/dist/types/components/DatePicker/useCalendarGutter.d.ts +1 -0
- package/dist/types/components/DateRangePicker/DateRangePicker.d.ts +2 -0
- package/dist/types/components/Dialog/Dialog.d.ts +17 -6
- package/dist/types/components/Dialog/index.d.ts +1 -1
- package/dist/types/components/Field/Field.d.ts +12 -2
- package/dist/types/components/FieldGroup/FieldGroup.d.ts +11 -2
- package/dist/types/components/Icon/index.d.ts +2 -0
- package/dist/types/components/Icon/svg/Disclosure.d.ts +6 -0
- package/dist/types/components/Icon/svg/Eyedropper.d.ts +6 -0
- package/dist/types/components/Indicator/LoadingIndicator.d.ts +1 -1
- package/dist/types/components/Menu/Menu.d.ts +74 -9
- package/dist/types/components/Page/Page.d.ts +24 -9
- package/dist/types/components/Page/index.d.ts +1 -1
- package/dist/types/components/PageControl/PageControl.d.ts +52 -0
- package/dist/types/components/PageControl/index.d.ts +1 -0
- package/dist/types/components/Popover/Popover.d.ts +11 -6
- package/dist/types/components/Popover/deferredOutsidePress.d.ts +14 -0
- package/dist/types/components/Popover/usePopoverContext.d.ts +1 -0
- package/dist/types/components/Select/Select.d.ts +3 -3
- package/dist/types/components/SelectControl/SelectControl.d.ts +2 -2
- package/dist/types/components/SelectControl/index.d.ts +1 -1
- package/dist/types/components/Sortable/Sortable.d.ts +1 -1
- package/dist/types/components/Stepper/Stepper.d.ts +56 -0
- package/dist/types/components/Stepper/index.d.ts +1 -0
- package/dist/types/components/Switch/Switch.d.ts +3 -1
- package/dist/types/components/TabBar/TabBar.d.ts +74 -0
- package/dist/types/components/TabBar/index.d.ts +1 -0
- package/dist/types/components/Toast/ToastRenderer.d.ts +3 -0
- package/dist/types/components/Toast/Toaster.d.ts +4 -2
- package/dist/types/components/Toast/toastLifecycle.d.ts +90 -0
- package/dist/types/components/Toolbar/Toolbar.d.ts +93 -0
- package/dist/types/components/Toolbar/index.d.ts +1 -0
- package/dist/types/components/Tooltip/Tooltip.d.ts +2 -2
- package/dist/types/hooks/useFloatingBoundary.d.ts +24 -0
- package/dist/types/hooks/usePhoneSubmenu.d.ts +3 -0
- package/dist/types/lib/fieldRow.d.ts +6 -0
- package/dist/types/lib/floatingBoundary.d.ts +9 -0
- package/dist/types/lib/focusRestore.d.ts +5 -0
- package/dist/types/lib/helpers.d.ts +1 -5
- package/dist/types/lib/inputMode.d.ts +7 -0
- package/dist/types/lib/menuInitialFocus.d.ts +9 -0
- package/dist/types/lib/menuSubmenuPlacement.d.ts +57 -0
- package/dist/types/lib/menuTriggerCover.d.ts +23 -0
- package/dist/types/lib/observeTextareaWidth.d.ts +2 -0
- package/dist/types/lib/scrollEdges.d.ts +16 -0
- package/dist/types/lib/selectPress.d.ts +23 -0
- package/dist/types/lib/sortable.d.ts +1 -1
- package/package.json +6 -2
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import clsx from "clsx";
|
|
4
|
-
import { cloneElement, isValidElement, useId } from "react";
|
|
4
|
+
import { cloneElement, isValidElement, useId, useRef } from "react";
|
|
5
5
|
import { FieldRowContext } from "../../lib/fieldRow.js";
|
|
6
6
|
import { FieldError } from "../FieldError/index.js";
|
|
7
7
|
import s from "@plexui/styles/components/Field/Field.module.css";
|
|
8
8
|
const CONTROL_SIZES = new Set(["3xs", "2xs", "xs", "sm", "md", "lg", "xl", "2xl", "3xl"]);
|
|
9
|
-
export function Field({ label, description, errorMessage, labelAction, action, size: sizeProp, required = false, orientation: orientationProp, row = false, fill = false, opticallyAlign, id: idProp, className, children, ...rest }) {
|
|
10
|
-
const orientation = orientationProp ?? (row ? "horizontal" : "vertical");
|
|
9
|
+
export function Field({ label, hideLabel = false, description, errorMessage, labelAction, action, size: sizeProp, required = false, orientation: orientationProp, row = false, fill = false, opticallyAlign, id: idProp, className, children, ...rest }) {
|
|
10
|
+
const orientation = orientationProp ?? (row && !hideLabel ? "horizontal" : "vertical");
|
|
11
11
|
const generatedId = useId();
|
|
12
|
+
const forwardingRowClick = useRef(false);
|
|
12
13
|
const fieldId = idProp || `field-${generatedId}`;
|
|
13
14
|
const labelId = `${fieldId}-label`;
|
|
14
15
|
const childProps = isValidElement(children) ? children.props : undefined;
|
|
@@ -50,6 +51,52 @@ export function Field({ label, description, errorMessage, labelAction, action, s
|
|
|
50
51
|
resolvedChildren = children;
|
|
51
52
|
}
|
|
52
53
|
const labelElement = (_jsxs("label", { className: s.Label, id: labelId, htmlFor: controlId, children: [label, required && (_jsx("span", { className: s.RequiredIndicator, "aria-hidden": "true", children: "*" }))] }));
|
|
53
|
-
return (_jsx(FieldRowContext.Provider, { value: row && orientation === "horizontal", children: _jsxs("div", { ...(row ? rest : undefined),
|
|
54
|
+
return (_jsx(FieldRowContext.Provider, { value: row && orientation === "horizontal", children: _jsxs("div", { ...(row ? rest : undefined), onClick: row ? (event) => {
|
|
55
|
+
if (forwardingRowClick.current)
|
|
56
|
+
return;
|
|
57
|
+
rest.onClick?.(event);
|
|
58
|
+
if (event.defaultPrevented)
|
|
59
|
+
return;
|
|
60
|
+
const target = event.target;
|
|
61
|
+
const root = event.currentTarget;
|
|
62
|
+
// The linked control remains the keyboard stop and owns its state.
|
|
63
|
+
// Nested actions keep their own click, including a Select's clear button.
|
|
64
|
+
if (!(target instanceof Element) || target.closest("[data-row]") !== root ||
|
|
65
|
+
target.closest('button, a, input, select, textarea, [role="button"], [role="link"], [contenteditable]:not([contenteditable="false"])'))
|
|
66
|
+
return;
|
|
67
|
+
const linkedControl = root.ownerDocument.getElementById(controlId);
|
|
68
|
+
if (!linkedControl || linkedControl.closest("[data-row]") !== root)
|
|
69
|
+
return;
|
|
70
|
+
// Select's id belongs to its hidden form proxy inside the trigger.
|
|
71
|
+
// Never search sibling popups, such as an InputGroup's unit action.
|
|
72
|
+
const control = linkedControl.matches('input[aria-hidden="true"]')
|
|
73
|
+
? linkedControl.closest(':is(button, [role="button"])[aria-haspopup]:not([aria-haspopup="false"])') ?? linkedControl
|
|
74
|
+
: linkedControl;
|
|
75
|
+
if (control.matches(':disabled, [disabled], [data-disabled], [aria-disabled="true"], [data-loading], [aria-busy="true"]'))
|
|
76
|
+
return;
|
|
77
|
+
const label = target.closest("label");
|
|
78
|
+
// Native labels already click their linked form control. A directly
|
|
79
|
+
// linked span trigger, such as DatePicker's, needs forwarding instead.
|
|
80
|
+
if (label && (label.htmlFor !== linkedControl.id || label.control === linkedControl))
|
|
81
|
+
return;
|
|
82
|
+
// The row is the hit area for its plain editor. Focus only: a synthetic
|
|
83
|
+
// click would also run input actions or disturb native text selection.
|
|
84
|
+
if (control.matches('textarea, input:not([type]), input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="tel"], input[type="url"], input[type="number"]') &&
|
|
85
|
+
!control.matches('[hidden], [aria-hidden="true"]')) {
|
|
86
|
+
control.focus({ preventScroll: true });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!control.matches('button[role="radio"], button[role="checkbox"], button[role="switch"], input[type="radio"], input[type="checkbox"], :is(button, [role="button"])[aria-haspopup]:not([aria-haspopup="false"])'))
|
|
90
|
+
return;
|
|
91
|
+
forwardingRowClick.current = true;
|
|
92
|
+
try {
|
|
93
|
+
control.focus({ preventScroll: true });
|
|
94
|
+
control.click();
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
// Form controls can bubble their hidden input click after the render flush.
|
|
98
|
+
queueMicrotask(() => { forwardingRowClick.current = false; });
|
|
99
|
+
}
|
|
100
|
+
} : undefined, className: clsx(s.Field, className), "data-slot": "field", "data-size": size, "data-orientation": orientation, "data-optically-align": opticallyAlign, "data-row": row ? "" : undefined, "data-fill": fill ? "" : undefined, "data-label-hidden": hideLabel ? "" : undefined, children: [_jsxs("div", { className: s.LabelGroup, children: [labelAction ? (_jsxs("div", { className: s.LabelRow, children: [labelElement, _jsx("div", { className: s.LabelAction, children: labelAction })] })) : (labelElement), description && (_jsx("div", { className: s.Description, id: descriptionId, children: description }))] }), _jsxs("div", { className: s.Content, children: [_jsx("div", { className: s.Control, children: resolvedChildren }), errorMessage && (_jsx(FieldError, { id: errorId, children: errorMessage }))] }), row && action ? _jsx("div", { className: s.Action, children: action }) : null] }) }));
|
|
54
101
|
}
|
|
55
102
|
//# sourceMappingURL=Field.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.js","sourceRoot":"","sources":["../../../../src/components/Field/Field.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE1C,OAAO,CAAC,MAAM,kDAAkD,CAAA;AAWhE,MAAM,aAAa,GAAyB,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;AA0F/G,MAAM,UAAU,KAAK,CAAC,EACpB,KAAK,EACL,WAAW,EACX,YAAY,EACZ,WAAW,EACX,MAAM,EACN,IAAI,EAAE,QAAQ,EACd,QAAQ,GAAG,KAAK,EAChB,WAAW,EAAE,eAAe,EAC5B,GAAG,GAAG,KAAK,EACX,IAAI,GAAG,KAAK,EACZ,cAAc,EACd,EAAE,EAAE,MAAM,EACV,SAAS,EACT,QAAQ,EACR,GAAG,IAAI,EACI;IACX,MAAM,WA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,CACL,KAAC,eAAe,CAAC,QAAQ,IAAC,KAAK,EAAE,GAAG,IAAI,WAAW,KAAK,YAAY,YAClE,kBACM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,EAC5B,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,eACxB,IAAI,sBACG,WAAW,0BACP,cAAc,cAC1B,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,eACnB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,aAEhC,eAAK,SAAS,EAAE,CAAC,CAAC,UAAU,aACzB,WAAW,CAAC,CAAC,CAAC,CACb,eAAK,SAAS,EAAE,CAAC,CAAC,QAAQ,aACvB,YAAY,EACb,cAAK,SAAS,EAAE,CAAC,CAAC,WAAW,YAAG,WAAW,GAAO,IAC9C,CACP,CAAC,CAAC,CAAC,CACF,YAAY,CACb,EACA,WAAW,IAAI,CACd,cAAK,SAAS,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,EAAE,aAAa,YAC7C,WAAW,GACR,CACP,IACG,EACN,eAAK,SAAS,EAAE,CAAC,CAAC,OAAO,aACvB,cAAK,SAAS,EAAE,CAAC,CAAC,OAAO,YAAG,gBAAgB,GAAO,EAClD,YAAY,IAAI,CACf,KAAC,UAAU,IAAC,EAAE,EAAE,OAAO,YAAG,YAAY,GAAc,CACrD,IACG,EACL,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,cAAK,SAAS,EAAE,CAAC,CAAC,MAAM,YAAG,MAAM,GAAO,CAAC,CAAC,CAAC,IAAI,IAC5D,GACmB,CAC5B,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { cloneElement, isValidElement, useId } from \"react\"\n\nimport { FieldRowContext } from \"../../lib/fieldRow\"\nimport type { ControlSize } from \"../../types\"\nimport { FieldError } from \"../FieldError\"\n\nimport s from \"@plexui/styles/components/Field/Field.module.css\"\n\nexport type FieldChildProps = {\n id: string\n /** The label's id. Spread onto a control that the label's `for` cannot name, such as a Select trigger. */\n \"aria-labelledby\"?: string\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean\n opticallyAlign?: \"start\" | \"end\"\n}\n\nconst CONTROL_SIZES: ReadonlySet<unknown> = new Set([\"3xs\", \"2xs\", \"xs\", \"sm\", \"md\", \"lg\", \"xl\", \"2xl\", \"3xl\"])\n\nexport type FieldProps = {\n /**\n * Label text for the field\n */\n label: React.ReactNode\n /**\n * Helper/description text displayed below the label.\n * Automatically linked via aria-describedby.\n */\n description?: React.ReactNode\n /**\n * Error message displayed below the control.\n * When provided, the child control receives aria-invalid=\"true\".\n * Uses the existing FieldError component internally.\n */\n errorMessage?: React.ReactNode\n /**\n * Content placed at the end of the label row, such as a link that acts on\n * the field (\"Forgot password?\", \"Replace\").\n */\n labelAction?: React.ReactNode\n /**\n * On a `fill` row, a control at the end of the row, such as a button that adds\n * to a list. It stays on the list's first line, and on a phone it stands beside\n * the label with the list on a line of its own.\n */\n action?: React.ReactNode\n /**\n * Controls the font size of the label to visually match the child control's size.\n * Matches the ControlSize scale used by Input, Select, etc.\n * @default the child control's `size`, else \"md\"\n */\n size?: ControlSize\n /**\n * Display a required indicator (asterisk) after the label.\n * This is purely visual — it does not add the `required` HTML attribute.\n * @default false\n */\n required?: boolean\n /**\n * Layout direction of label and control.\n * - \"vertical\": label stacked above control (default)\n * - \"horizontal\": label beside control\n * @default \"horizontal\" on a `row`, else \"vertical\"\n */\n orientation?: \"vertical\" | \"horizontal\"\n /**\n * One line of a FieldGroup: label at the start, control at the end, an error\n * under both. Other div props reach the root only on a row, so it can carry\n * a click or data attributes.\n * A control at the end of the row is a pill unless its own `pill` says otherwise.\n * @default false\n */\n row?: boolean\n /**\n * On a `row`, the control takes the rest of the line after the label, for a\n * list of tags and the like.\n * @default false\n */\n fill?: boolean\n /**\n * Allows overriding the auto-generated `id`. When provided, this becomes\n * the id set on the child control and the `htmlFor` on the label. A child's\n * own `id` wins over both: it stays, and the label's `htmlFor` follows it.\n */\n id?: string\n /**\n * Applies a negative margin on the child control using its gutter to\n * optically align the control's text with surrounding content.\n * Passed through to the child control via cloneElement / render prop.\n */\n opticallyAlign?: \"start\" | \"end\"\n /**\n * CSS class applied to the root wrapper\n */\n className?: string\n /**\n * The form control(s) to render.\n * - If a single ReactElement, Field clones it with { id, aria-describedby, aria-invalid },\n * keeping an `id` the child already has.\n * A child without its own `aria-label`, `aria-labelledby` or `label` also gets\n * `aria-labelledby` pointing at the label, which names controls the label's\n * `for` cannot reach, such as the Select and DatePicker triggers.\n * - If a function (render prop), it is called with { id, \"aria-labelledby\", \"aria-describedby\", \"aria-invalid\" }.\n */\n children: React.ReactElement | ((fieldProps: FieldChildProps) => React.ReactNode)\n} & Omit<React.ComponentProps<\"div\">, \"children\" | \"id\" | \"className\">\n\nexport function Field({\n label,\n description,\n errorMessage,\n labelAction,\n action,\n size: sizeProp,\n required = false,\n orientation: orientationProp,\n row = false,\n fill = false,\n opticallyAlign,\n id: idProp,\n className,\n children,\n ...rest\n}: FieldProps) {\n const orientation = orientationProp ?? (row ? \"horizontal\" : \"vertical\")\n const generatedId = useId()\n const fieldId = idProp || `field-${generatedId}`\n const labelId = `${fieldId}-label`\n const childProps = isValidElement<{ size?: unknown; id?: string }>(children) ? children.props : undefined\n const childSize = childProps?.size\n const size = sizeProp ?? (CONTROL_SIZES.has(childSize) ? (childSize as ControlSize) : \"md\")\n // The control's id, which the label's `htmlFor` has to match\n const controlId = childProps?.id || fieldId\n const descriptionId = description ? `${fieldId}-description` : undefined\n const errorId = errorMessage ? `${fieldId}-error` : undefined\n\n // Build aria-describedby from description + error IDs\n const ariaDescribedBy =\n [descriptionId, errorId].filter(Boolean).join(\" \") || undefined\n\n const invalid = !!errorMessage\n\n // Props to inject into the child control (`aria-labelledby` is added below:\n // to a render prop's props, and to a cloned child without a name of its own)\n const fieldChildProps: FieldChildProps = {\n id: controlId,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": invalid || undefined,\n ...(opticallyAlign && { opticallyAlign }),\n }\n\n // Resolve the children\n let resolvedChildren: React.ReactNode\n if (typeof children === \"function\") {\n resolvedChildren = children({ ...fieldChildProps, \"aria-labelledby\": labelId })\n } else if (isValidElement(children)) {\n const child = children as React.ReactElement<Record<string, unknown>>\n // Merge with the child's own associations instead of overwriting them\n const childDescribedBy = child.props[\"aria-describedby\"] as string | undefined\n const childNamed =\n child.props[\"aria-label\"] != null || child.props[\"aria-labelledby\"] != null || child.props.label != null\n resolvedChildren = cloneElement(child, {\n ...fieldChildProps,\n \"aria-describedby\":\n [childDescribedBy, ariaDescribedBy].filter(Boolean).join(\" \") || undefined,\n \"aria-invalid\": child.props[\"aria-invalid\"] ?? fieldChildProps[\"aria-invalid\"],\n ...(!childNamed && { \"aria-labelledby\": labelId }),\n })\n } else {\n resolvedChildren = children\n }\n\n const labelElement = (\n <label className={s.Label} id={labelId} htmlFor={controlId}>\n {label}\n {required && (\n <span className={s.RequiredIndicator} aria-hidden=\"true\">\n *\n </span>\n )}\n </label>\n )\n\n return (\n <FieldRowContext.Provider value={row && orientation === \"horizontal\"}>\n <div\n {...(row ? rest : undefined)}\n className={clsx(s.Field, className)}\n data-size={size}\n data-orientation={orientation}\n data-optically-align={opticallyAlign}\n data-row={row ? \"\" : undefined}\n data-fill={fill ? \"\" : undefined}\n >\n <div className={s.LabelGroup}>\n {labelAction ? (\n <div className={s.LabelRow}>\n {labelElement}\n <div className={s.LabelAction}>{labelAction}</div>\n </div>\n ) : (\n labelElement\n )}\n {description && (\n <div className={s.Description} id={descriptionId}>\n {description}\n </div>\n )}\n </div>\n <div className={s.Content}>\n <div className={s.Control}>{resolvedChildren}</div>\n {errorMessage && (\n <FieldError id={errorId}>{errorMessage}</FieldError>\n )}\n </div>\n {row && action ? <div className={s.Action}>{action}</div> : null}\n </div>\n </FieldRowContext.Provider>\n )\n}\n"]}
|
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Y,IAAI,CACf,KAAC,UAAU,IAAC,EAAE,EAAE,OAAO,YAAG,YAAY,GAAc,CACrD,IACG,EACL,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,cAAK,SAAS,EAAE,CAAC,CAAC,MAAM,YAAG,MAAM,GAAO,CAAC,CAAC,CAAC,IAAI,IAC5D,GACmB,CAC5B,CAAA;AACH,CAAC","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { cloneElement, isValidElement, useId, useRef } from \"react\"\n\nimport { FieldRowContext } from \"../../lib/fieldRow\"\nimport type { ControlSize } from \"../../types\"\nimport { FieldError } from \"../FieldError\"\n\nimport s from \"@plexui/styles/components/Field/Field.module.css\"\n\nexport type FieldChildProps = {\n id: string\n /** The label's id. Spread onto a control that the label's `for` cannot name, such as a Select trigger. */\n \"aria-labelledby\"?: string\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean\n opticallyAlign?: \"start\" | \"end\"\n}\n\nconst CONTROL_SIZES: ReadonlySet<unknown> = new Set([\"3xs\", \"2xs\", \"xs\", \"sm\", \"md\", \"lg\", \"xl\", \"2xl\", \"3xl\"])\n\nexport type FieldProps = {\n /**\n * Label text for the field\n */\n label: React.ReactNode\n /**\n * Helper/description text displayed below the label.\n * Automatically linked via aria-describedby.\n */\n description?: React.ReactNode\n /**\n * Hides the label from view; it still names the control for assistive technology.\n * On a `row` the value or placeholder then starts at the row's edge, as an iOS cell that\n * shows only its placeholder or value (Notes, a title, a server's address), so the row is\n * vertical unless `orientation` says otherwise. Words that explain the field go in the\n * FieldGroup's `footer`.\n * @default false\n */\n hideLabel?: boolean\n /**\n * Error message displayed below the control.\n * When provided, the child control receives aria-invalid=\"true\".\n * Uses the existing FieldError component internally.\n */\n errorMessage?: React.ReactNode\n /**\n * Content placed at the end of the label row, such as a link that acts on\n * the field (\"Forgot password?\", \"Replace\").\n */\n labelAction?: React.ReactNode\n /**\n * On a `fill` row, a control at the end of the row, such as a button that adds\n * to a list. It stays on the list's first line, and on a phone it stands beside\n * the label with the list on a line of its own.\n */\n action?: React.ReactNode\n /**\n * Controls the font size of the label to visually match the child control's size.\n * Matches the ControlSize scale used by Input, Select, etc.\n * @default the child control's `size`, else \"md\"\n */\n size?: ControlSize\n /**\n * Display a required indicator (asterisk) after the label.\n * This is purely visual — it does not add the `required` HTML attribute.\n * @default false\n */\n required?: boolean\n /**\n * Layout direction of label and control.\n * - \"vertical\": label stacked above control (default)\n * - \"horizontal\": label beside control\n * @default \"horizontal\" on a `row` with a visible label, else \"vertical\"\n */\n orientation?: \"vertical\" | \"horizontal\"\n /**\n * One line of a FieldGroup: label at the start, control at the end, an error\n * under both. Other div props reach the root only on a row, so it can carry\n * a click or data attributes.\n * Clicking a non-interactive part of the row focuses its text editor or activates its choice control or popup trigger.\n * A control at the end of the row is a pill unless its own `pill` says otherwise.\n * @default false\n */\n row?: boolean\n /**\n * On a `row`, the control takes the rest of the line after the label, for a\n * list of tags and the like.\n * @default false\n */\n fill?: boolean\n /**\n * Allows overriding the auto-generated `id`. When provided, this becomes\n * the id set on the child control and the `htmlFor` on the label. A child's\n * own `id` wins over both: it stays, and the label's `htmlFor` follows it.\n */\n id?: string\n /**\n * Applies a negative margin on the child control using its gutter to\n * optically align the control's text with surrounding content.\n * Passed through to the child control via cloneElement / render prop.\n */\n opticallyAlign?: \"start\" | \"end\"\n /**\n * CSS class applied to the root wrapper\n */\n className?: string\n /**\n * The form control(s) to render.\n * - If a single ReactElement, Field clones it with { id, aria-describedby, aria-invalid },\n * keeping an `id` the child already has.\n * A child without its own `aria-label`, `aria-labelledby` or `label` also gets\n * `aria-labelledby` pointing at the label, which names controls the label's\n * `for` cannot reach, such as the Select and DatePicker triggers.\n * - If a function (render prop), it is called with { id, \"aria-labelledby\", \"aria-describedby\", \"aria-invalid\" }.\n */\n children: React.ReactElement | ((fieldProps: FieldChildProps) => React.ReactNode)\n} & Omit<React.ComponentProps<\"div\">, \"children\" | \"id\" | \"className\">\n\nexport function Field({\n label,\n hideLabel = false,\n description,\n errorMessage,\n labelAction,\n action,\n size: sizeProp,\n required = false,\n orientation: orientationProp,\n row = false,\n fill = false,\n opticallyAlign,\n id: idProp,\n className,\n children,\n ...rest\n}: FieldProps) {\n const orientation = orientationProp ?? (row && !hideLabel ? \"horizontal\" : \"vertical\")\n const generatedId = useId()\n const forwardingRowClick = useRef(false)\n const fieldId = idProp || `field-${generatedId}`\n const labelId = `${fieldId}-label`\n const childProps = isValidElement<{ size?: unknown; id?: string }>(children) ? children.props : undefined\n const childSize = childProps?.size\n const size = sizeProp ?? (CONTROL_SIZES.has(childSize) ? (childSize as ControlSize) : \"md\")\n // The control's id, which the label's `htmlFor` has to match\n const controlId = childProps?.id || fieldId\n const descriptionId = description ? `${fieldId}-description` : undefined\n const errorId = errorMessage ? `${fieldId}-error` : undefined\n\n // Build aria-describedby from description + error IDs\n const ariaDescribedBy =\n [descriptionId, errorId].filter(Boolean).join(\" \") || undefined\n\n const invalid = !!errorMessage\n\n // Props to inject into the child control (`aria-labelledby` is added below:\n // to a render prop's props, and to a cloned child without a name of its own)\n const fieldChildProps: FieldChildProps = {\n id: controlId,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": invalid || undefined,\n ...(opticallyAlign && { opticallyAlign }),\n }\n\n // Resolve the children\n let resolvedChildren: React.ReactNode\n if (typeof children === \"function\") {\n resolvedChildren = children({ ...fieldChildProps, \"aria-labelledby\": labelId })\n } else if (isValidElement(children)) {\n const child = children as React.ReactElement<Record<string, unknown>>\n // Merge with the child's own associations instead of overwriting them\n const childDescribedBy = child.props[\"aria-describedby\"] as string | undefined\n const childNamed =\n child.props[\"aria-label\"] != null || child.props[\"aria-labelledby\"] != null || child.props.label != null\n resolvedChildren = cloneElement(child, {\n ...fieldChildProps,\n \"aria-describedby\":\n [childDescribedBy, ariaDescribedBy].filter(Boolean).join(\" \") || undefined,\n \"aria-invalid\": child.props[\"aria-invalid\"] ?? fieldChildProps[\"aria-invalid\"],\n ...(!childNamed && { \"aria-labelledby\": labelId }),\n })\n } else {\n resolvedChildren = children\n }\n\n const labelElement = (\n <label className={s.Label} id={labelId} htmlFor={controlId}>\n {label}\n {required && (\n <span className={s.RequiredIndicator} aria-hidden=\"true\">\n *\n </span>\n )}\n </label>\n )\n\n return (\n <FieldRowContext.Provider value={row && orientation === \"horizontal\"}>\n <div\n {...(row ? rest : undefined)}\n onClick={row ? (event) => {\n if (forwardingRowClick.current) return\n rest.onClick?.(event)\n if (event.defaultPrevented) return\n const target = event.target\n const root = event.currentTarget\n // The linked control remains the keyboard stop and owns its state.\n // Nested actions keep their own click, including a Select's clear button.\n if (!(target instanceof Element) || target.closest(\"[data-row]\") !== root ||\n target.closest('button, a, input, select, textarea, [role=\"button\"], [role=\"link\"], [contenteditable]:not([contenteditable=\"false\"])')) return\n const linkedControl = root.ownerDocument.getElementById(controlId)\n if (!linkedControl || linkedControl.closest(\"[data-row]\") !== root) return\n // Select's id belongs to its hidden form proxy inside the trigger.\n // Never search sibling popups, such as an InputGroup's unit action.\n const control = linkedControl.matches('input[aria-hidden=\"true\"]')\n ? linkedControl.closest<HTMLElement>(':is(button, [role=\"button\"])[aria-haspopup]:not([aria-haspopup=\"false\"])') ?? linkedControl\n : linkedControl\n if (control.matches(':disabled, [disabled], [data-disabled], [aria-disabled=\"true\"], [data-loading], [aria-busy=\"true\"]')) return\n const label = target.closest(\"label\")\n // Native labels already click their linked form control. A directly\n // linked span trigger, such as DatePicker's, needs forwarding instead.\n if (label && (label.htmlFor !== linkedControl.id || label.control === linkedControl)) return\n // The row is the hit area for its plain editor. Focus only: a synthetic\n // click would also run input actions or disturb native text selection.\n if (control.matches('textarea, input:not([type]), input[type=\"text\"], input[type=\"email\"], input[type=\"password\"], input[type=\"search\"], input[type=\"tel\"], input[type=\"url\"], input[type=\"number\"]') &&\n !control.matches('[hidden], [aria-hidden=\"true\"]')) {\n control.focus({ preventScroll: true })\n return\n }\n if (!control.matches('button[role=\"radio\"], button[role=\"checkbox\"], button[role=\"switch\"], input[type=\"radio\"], input[type=\"checkbox\"], :is(button, [role=\"button\"])[aria-haspopup]:not([aria-haspopup=\"false\"])')) return\n forwardingRowClick.current = true\n try {\n control.focus({ preventScroll: true })\n control.click()\n } finally {\n // Form controls can bubble their hidden input click after the render flush.\n queueMicrotask(() => { forwardingRowClick.current = false })\n }\n } : undefined}\n className={clsx(s.Field, className)}\n data-slot=\"field\"\n data-size={size}\n data-orientation={orientation}\n data-optically-align={opticallyAlign}\n data-row={row ? \"\" : undefined}\n data-fill={fill ? \"\" : undefined}\n data-label-hidden={hideLabel ? \"\" : undefined}\n >\n <div className={s.LabelGroup}>\n {labelAction ? (\n <div className={s.LabelRow}>\n {labelElement}\n <div className={s.LabelAction}>{labelAction}</div>\n </div>\n ) : (\n labelElement\n )}\n {description && (\n <div className={s.Description} id={descriptionId}>\n {description}\n </div>\n )}\n </div>\n <div className={s.Content}>\n <div className={s.Control}>{resolvedChildren}</div>\n {errorMessage && (\n <FieldError id={errorId}>{errorMessage}</FieldError>\n )}\n </div>\n {row && action ? <div className={s.Action}>{action}</div> : null}\n </div>\n </FieldRowContext.Provider>\n )\n}\n"]}
|
|
@@ -3,9 +3,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import clsx from "clsx";
|
|
4
4
|
import { useId } from "react";
|
|
5
5
|
import s from "@plexui/styles/components/FieldGroup/FieldGroup.module.css";
|
|
6
|
+
import { FieldColumnsContext } from "../../lib/fieldRow.js";
|
|
6
7
|
/** A titled block of rows: `Field row` lines with hairlines between them. */
|
|
7
|
-
export function FieldGroup({ title, description, action, footer, columns = false, bodyClassName, className, children, ...rest }) {
|
|
8
|
+
export function FieldGroup({ title, headerProminence = "standard", description, action, footer, columns = false, bodyClassName, className, children, ...rest }) {
|
|
8
9
|
const titleId = `field-group-${useId()}`;
|
|
9
|
-
|
|
10
|
+
const descriptionId = `${titleId}-description`;
|
|
11
|
+
return (_jsxs("section", { role: "group", "aria-labelledby": title ? titleId : undefined, "aria-describedby": description ? descriptionId : undefined, "data-field-columns": columns ? "" : undefined, "data-header-prominence": headerProminence === "increased" ? "increased" : undefined, ...rest, className: clsx(s.FieldGroup, className), children: [(title || description || action) && (_jsxs("div", { className: s.Header, children: [_jsxs("div", { className: s.HeaderText, children: [title && (_jsx("h2", { className: s.Title, id: titleId, children: title })), description && _jsx("p", { className: s.Description, id: descriptionId, children: description })] }), action] })), _jsx("div", { className: clsx(s.Body, bodyClassName), children: _jsx(FieldColumnsContext.Provider, { value: columns, children: children }) }), footer != null && typeof footer !== "boolean" && footer !== "" && (_jsx("div", { className: s.Footer, children: footer }))] }));
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=FieldGroup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldGroup.js","sourceRoot":"","sources":["../../../../src/components/FieldGroup/FieldGroup.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAE7B,OAAO,CAAC,MAAM,4DAA4D,CAAA;
|
|
1
|
+
{"version":3,"file":"FieldGroup.js","sourceRoot":"","sources":["../../../../src/components/FieldGroup/FieldGroup.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAE7B,OAAO,CAAC,MAAM,4DAA4D,CAAA;AAE1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AA4CxD,6EAA6E;AAC7E,MAAM,UAAU,UAAU,CAAC,EACzB,KAAK,EACL,gBAAgB,GAAG,UAAU,EAC7B,WAAW,EACX,MAAM,EACN,MAAM,EACN,OAAO,GAAG,KAAK,EACf,aAAa,EACb,SAAS,EACT,QAAQ,EACR,GAAG,IAAI,EACS;IAChB,MAAM,OAAO,GAAG,eAA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ieldGroup/FieldGroup.module.css\"\n\nimport { FieldColumnsContext } from \"../../lib/fieldRow\"\n\nexport type FieldGroupProps = {\n /**\n * Heading over the block. It names the group.\n */\n title?: React.ReactNode\n /**\n * How much the title stands out. \"standard\" is a quiet heading over the rows (on a\n * phone the kit's Nested list header: 17 Semibold, secondary). \"increased\" leads its\n * content, as a section of a page does (the kit's Prominent header: 20 Semibold,\n * primary).\n * @default \"standard\"\n */\n headerProminence?: \"standard\" | \"increased\"\n /**\n * Line under the title.\n */\n description?: React.ReactNode\n /**\n * Content at the end of the header, such as a button. On a phone a ghost text button\n * reads as the list header's action: tinted text on the title's last line.\n */\n action?: React.ReactNode\n /**\n * Content under the block, such as a note.\n */\n footer?: React.ReactNode\n /**\n * Every value starts at one column, `--field-row-column-width` into the row, on the\n * web and on a phone. Off, values end at the row's edge.\n * @default false\n */\n columns?: boolean\n /**\n * CSS class for the block that holds the rows.\n */\n bodyClassName?: string\n /**\n * The rows: `Field row`, or rows of your own.\n */\n children?: React.ReactNode\n} & Omit<React.ComponentProps<\"section\">, \"title\" | \"children\">\n\n/** A titled block of rows: `Field row` lines with hairlines between them. */\nexport function FieldGroup({\n title,\n headerProminence = \"standard\",\n description,\n action,\n footer,\n columns = false,\n bodyClassName,\n className,\n children,\n ...rest\n}: FieldGroupProps) {\n const titleId = `field-group-${useId()}`\n const descriptionId = `${titleId}-description`\n\n return (\n <section\n role=\"group\"\n aria-labelledby={title ? titleId : undefined}\n aria-describedby={description ? descriptionId : undefined}\n data-field-columns={columns ? \"\" : undefined}\n data-header-prominence={headerProminence === \"increased\" ? \"increased\" : undefined}\n {...rest}\n className={clsx(s.FieldGroup, className)}\n >\n {(title || description || action) && (\n <div className={s.Header}>\n <div className={s.HeaderText}>\n {title && (\n <h2 className={s.Title} id={titleId}>\n {title}\n </h2>\n )}\n {description && <p className={s.Description} id={descriptionId}>{description}</p>}\n </div>\n {action}\n </div>\n )}\n <div className={clsx(s.Body, bodyClassName)}>\n <FieldColumnsContext.Provider value={columns}>{children}</FieldColumnsContext.Provider>\n </div>\n {footer != null && typeof footer !== \"boolean\" && footer !== \"\" && (\n <div className={s.Footer}>{footer}</div>\n )}\n </section>\n )\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import clsx from "clsx";
|
|
4
|
-
import { useCallback, useId, useRef, useState } from "react";
|
|
4
|
+
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
5
5
|
import { FileDocument, ImageSquare, FileBlank, UploadDocuments, X, } from "../Icon/index.js";
|
|
6
6
|
import { Button } from "../Button/index.js";
|
|
7
7
|
import { FieldError } from "../FieldError/index.js";
|
|
@@ -66,6 +66,9 @@ export const FileUpload = (props) => {
|
|
|
66
66
|
const { variant = "compact", label, description, accept, multiple = false, maxFiles, maxSize, value: controlledValue, onValueChange, onFileReject, errorMessage, "invalid": invalidProp, disabled = false, className, id: idProp, "aria-describedby": ariaDescribedByProp, "aria-invalid": ariaInvalidProp, } = props;
|
|
67
67
|
const [internalFiles, setInternalFiles] = useState([]);
|
|
68
68
|
const inputRef = useRef(null);
|
|
69
|
+
const rootRef = useRef(null);
|
|
70
|
+
const listRef = useRef(null);
|
|
71
|
+
const pendingRemovalFocus = useRef(null);
|
|
69
72
|
const generatedId = useId();
|
|
70
73
|
const inputId = idProp || `file-upload-${generatedId}`;
|
|
71
74
|
const errorId = `${inputId}-error`;
|
|
@@ -73,6 +76,38 @@ export const FileUpload = (props) => {
|
|
|
73
76
|
const isControlled = controlledValue !== undefined;
|
|
74
77
|
const invalid = invalidProp ?? !!errorMessage;
|
|
75
78
|
const ariaInvalid = ariaInvalidProp ?? (invalid || undefined);
|
|
79
|
+
// Restore only after the owner accepts deletion. A later user interaction
|
|
80
|
+
// cancels the request, even if focus subsequently returns to the document body.
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const doc = rootRef.current?.ownerDocument;
|
|
83
|
+
if (!doc)
|
|
84
|
+
return;
|
|
85
|
+
const cancelAfterMoving = (event) => {
|
|
86
|
+
const pending = pendingRemovalFocus.current;
|
|
87
|
+
if (pending && event.target instanceof Node && !pending.source.contains(event.target)) {
|
|
88
|
+
pendingRemovalFocus.current = null;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
doc.addEventListener("focusin", cancelAfterMoving, true);
|
|
92
|
+
doc.addEventListener("pointerdown", cancelAfterMoving, true);
|
|
93
|
+
return () => {
|
|
94
|
+
doc.removeEventListener("focusin", cancelAfterMoving, true);
|
|
95
|
+
doc.removeEventListener("pointerdown", cancelAfterMoving, true);
|
|
96
|
+
};
|
|
97
|
+
}, []);
|
|
98
|
+
useLayoutEffect(() => {
|
|
99
|
+
const pending = pendingRemovalFocus.current;
|
|
100
|
+
if (!pending || files.includes(pending.file))
|
|
101
|
+
return;
|
|
102
|
+
pendingRemovalFocus.current = null;
|
|
103
|
+
const doc = pending.source.ownerDocument;
|
|
104
|
+
if (disabled || (doc.activeElement !== doc.body && !pending.source.contains(doc.activeElement)))
|
|
105
|
+
return;
|
|
106
|
+
const buttons = Array.from(listRef.current?.querySelectorAll("button:not(:disabled)") ?? []);
|
|
107
|
+
const target = buttons[Math.min(pending.index, buttons.length - 1)]
|
|
108
|
+
?? rootRef.current?.querySelector("button:not(:disabled):not([aria-disabled=true])");
|
|
109
|
+
target?.focus({ preventScroll: true });
|
|
110
|
+
}, [files, disabled]);
|
|
76
111
|
const ariaDescribedBy = [ariaDescribedByProp, errorMessage ? errorId : undefined].filter(Boolean).join(" ") ||
|
|
77
112
|
undefined;
|
|
78
113
|
const updateFiles = useCallback((next) => {
|
|
@@ -107,13 +142,18 @@ export const FileUpload = (props) => {
|
|
|
107
142
|
e.target.value = "";
|
|
108
143
|
}, [accept, maxSize, maxFiles, multiple, files, updateFiles, onFileReject]);
|
|
109
144
|
const removeFile = useCallback((index) => {
|
|
145
|
+
const file = files[index];
|
|
146
|
+
const source = listRef.current?.querySelectorAll("button")[index];
|
|
147
|
+
if (file && source?.contains(source.ownerDocument.activeElement)) {
|
|
148
|
+
pendingRemovalFocus.current = { file, index, source };
|
|
149
|
+
}
|
|
110
150
|
const next = files.filter((_, i) => i !== index);
|
|
111
151
|
updateFiles(next);
|
|
112
152
|
}, [files, updateFiles]);
|
|
113
153
|
const openPicker = useCallback(() => {
|
|
114
154
|
inputRef.current?.click();
|
|
115
155
|
}, []);
|
|
116
|
-
const atLimit = !!maxFiles && files.length >= maxFiles;
|
|
117
|
-
return (_jsxs("div", { className: clsx(s.Root, className), children: [variant === "area" ? (_jsxs("button", { type: "button", className: s.AreaTrigger, "data-invalid": invalid ? "" : undefined, onClick: openPicker, disabled: disabled || atLimit, "aria-describedby": ariaDescribedBy,
|
|
156
|
+
const atLimit = multiple && !!maxFiles && files.length >= maxFiles;
|
|
157
|
+
return (_jsxs("div", { ref: rootRef, className: clsx(s.Root, className), role: "group", "aria-describedby": ariaDescribedBy, children: [variant === "area" ? (_jsxs("button", { type: "button", className: s.AreaTrigger, "data-invalid": invalid ? "" : undefined, onClick: openPicker, disabled: disabled || atLimit, "aria-describedby": ariaDescribedBy, children: [_jsx(UploadDocuments, { className: s.AreaIcon }), _jsx("span", { className: s.AreaLabel, children: label || "Tap to upload files" }), description && _jsx("span", { className: s.AreaDescription, children: description })] })) : (_jsx(Button, { color: "secondary", variant: "soft", size: "3xl", pill: true, block: true, disabled: disabled || atLimit, onClick: openPicker, "aria-describedby": ariaDescribedBy, children: label || "Upload file" })), files.length > 0 && (_jsx("ul", { ref: listRef, className: s.FileList, "data-variant": variant, "aria-label": "Attached files", children: files.map((file, index) => (_jsx("li", { children: _jsx(FileCard, { file: file, onRemove: () => removeFile(index), disabled: disabled }) }, `${file.name}-${file.size}-${file.lastModified}`))) })), _jsx("input", { ref: inputRef, type: "file", className: s.HiddenInput, accept: accept, multiple: multiple, onChange: handleFileSelect, disabled: disabled, id: inputId, "aria-label": label || (variant === "area" ? "Tap to upload files" : "Upload file"), "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, tabIndex: -1 }), errorMessage && (_jsx(FieldError, { id: errorId, className: s.ErrorMessage, children: errorMessage }))] }));
|
|
118
158
|
};
|
|
119
159
|
//# sourceMappingURL=FileUpload.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileUpload.js","sourceRoot":"","sources":["../../../../src/components/FileUpload/FileUpload.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC5D,OAAO,EACL,YAAY,EACZ,WAAW,EACX,SAAS,EACT,eAAe,EACf,CAAC,GACF,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,CAAC,MAAM,4DAA4D,CAAA;AAsB1E,SAAS,WAAW,CAAC,IAAU;IAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;IACtB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAA;IAEpC,IACE,IAAI,KAAK,iBAAiB;QAC1B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QACtB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EACrB,CAAC;QACD,OAAO,KAAC,YAAY,KAAG,CAAA;IACzB,CAAC;IAED,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,qCAAqC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;Q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,EAClB,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,OAAO,sBACO,eAAe,EACjC,QAAQ,EAAE,CAAC,CAAC,GACZ,EAED,YAAY,IAAI,CACf,KAAC,UAAU,IAAC,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,YAAY,YAC/C,YAAY,GACF,CACd,IACG,CACP,CAAA;AACH,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { useCallback, useId, useRef, useState } from \"react\"\nimport {\n FileDocument,\n ImageSquare,\n FileBlank,\n UploadDocuments,\n X,\n} from \"../Icon\"\nimport { Button } from \"../Button\"\nimport { FieldError } from \"../FieldError\"\nimport s from \"@plexui/styles/components/FileUpload/FileUpload.module.css\"\n\nexport type FileUploadProps = {\n variant?: \"compact\" | \"area\"\n label?: string\n description?: string\n accept?: string\n multiple?: boolean\n maxFiles?: number\n maxSize?: number\n value?: File[]\n onValueChange?: (files: File[]) => void\n onFileReject?: (file: File, reason: string) => void\n errorMessage?: string\n invalid?: boolean\n disabled?: boolean\n id?: string\n className?: string\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean\n}\n\nfunction getFileIcon(file: File) {\n const type = file.type\n const name = file.name.toLowerCase()\n\n if (\n type === \"application/pdf\" ||\n name.endsWith(\".pdf\") ||\n name.endsWith(\".doc\") ||\n name.endsWith(\".docx\") ||\n name.endsWith(\".txt\") ||\n name.endsWith(\".rtf\")\n ) {\n return <FileDocument />\n }\n\n if (type.startsWith(\"image/\") || /\\.(png|jpe?g|gif|svg|webp|bmp|ico)$/.test(name)) {\n return <ImageSquare />\n }\n\n return <FileBlank />\n}\n\nfunction formatFileSize(bytes: number): string {\n if (bytes === 0) return \"0 B\"\n if (bytes < 1024) return `${bytes} B`\n if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`\n return `${(bytes / (1024 * 1024)).toFixed(1)} MB`\n}\n\nfunction splitFileName(name: string): { stem: string; ext: string } {\n const lastDot = name.lastIndexOf(\".\")\n if (lastDot <= 0) return { stem: name, ext: \"\" }\n return {\n stem: name.slice(0, lastDot),\n ext: name.slice(lastDot),\n }\n}\n\nexport type FileCardGroupProps = {\n children: React.ReactNode\n className?: string\n}\n\nexport const FileCardGroup = ({ children, className }: FileCardGroupProps) => {\n return <div className={clsx(s.FileCardGroup, className)}>{children}</div>\n}\n\nexport type FileCardProps = {\n file: File\n onRemove?: () => void\n disabled?: boolean\n className?: string\n}\n\nexport const FileCard = ({ file, onRemove, disabled, className }: FileCardProps) => {\n const { stem, ext } = splitFileName(file.name)\n\n return (\n <div className={clsx(s.FileItem, className)}>\n <div className={s.FileIcon}>{getFileIcon(file)}</div>\n <div className={s.FileInfo}>\n <div className={s.FileNameRow}>\n <span className={s.FileNameStem}>{stem}</span>\n {ext && <span className={s.FileNameExt}>{ext}</span>}\n </div>\n <span className={s.FileSize}>{formatFileSize(file.size)}</span>\n </div>\n {onRemove && (\n <button\n type=\"button\"\n className={s.FileRemove}\n onClick={onRemove}\n aria-label={`Remove ${file.name}`}\n disabled={disabled}\n >\n <X />\n </button>\n )}\n </div>\n )\n}\n\nfunction matchesAccept(file: File, accept: string): boolean {\n const acceptTypes = accept.split(\",\").map((t) => t.trim().toLowerCase())\n const fileName = file.name.toLowerCase()\n const fileType = file.type.toLowerCase()\n\n return acceptTypes.some((acceptType) => {\n if (acceptType.startsWith(\".\")) {\n return fileName.endsWith(acceptType)\n }\n if (acceptType.endsWith(\"/*\")) {\n const prefix = acceptType.slice(0, -1)\n return fileType.startsWith(prefix)\n }\n return fileType === acceptType\n })\n}\n\nexport const FileUpload = (props: FileUploadProps) => {\n const {\n variant = \"compact\",\n label,\n description,\n accept,\n multiple = false,\n maxFiles,\n maxSize,\n value: controlledValue,\n onValueChange,\n onFileReject,\n errorMessage,\n \"invalid\": invalidProp,\n disabled = false,\n className,\n id: idProp,\n \"aria-describedby\": ariaDescribedByProp,\n \"aria-invalid\": ariaInvalidProp,\n } = props\n\n const [internalFiles, setInternalFiles] = useState<File[]>([])\n const inputRef = useRef<HTMLInputElement>(null)\n const generatedId = useId()\n const inputId = idProp || `file-upload-${generatedId}`\n const errorId = `${inputId}-error`\n\n const files = controlledValue ?? internalFiles\n const isControlled = controlledValue !== undefined\n const invalid = invalidProp ?? !!errorMessage\n const ariaInvalid = ariaInvalidProp ?? (invalid || undefined)\n\n const ariaDescribedBy =\n [ariaDescribedByProp, errorMessage ? errorId : undefined].filter(Boolean).join(\" \") ||\n undefined\n\n const updateFiles = useCallback(\n (next: File[]) => {\n onValueChange?.(next)\n if (!isControlled) {\n setInternalFiles(next)\n }\n },\n [onValueChange, isControlled],\n )\n\n const handleFileSelect = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const selected = Array.from(e.target.files || [])\n // Without `multiple`, a pick replaces the file instead of adding to it\n const kept = multiple ? files : []\n const accepted: File[] = []\n\n for (const file of selected) {\n if (accept && !matchesAccept(file, accept)) {\n onFileReject?.(file, `File type not accepted: ${file.name}`)\n continue\n }\n if (maxSize && file.size > maxSize) {\n onFileReject?.(file, `File too large: ${file.name} (${formatFileSize(file.size)})`)\n continue\n }\n if (maxFiles && kept.length + accepted.length >= maxFiles) {\n onFileReject?.(file, `Maximum ${maxFiles} files allowed`)\n continue\n }\n accepted.push(file)\n }\n\n if (accepted.length > 0) {\n updateFiles([...kept, ...accepted])\n }\n\n e.target.value = \"\"\n },\n [accept, maxSize, maxFiles, multiple, files, updateFiles, onFileReject],\n )\n\n const removeFile = useCallback(\n (index: number) => {\n const next = files.filter((_, i) => i !== index)\n updateFiles(next)\n },\n [files, updateFiles],\n )\n\n const openPicker = useCallback(() => {\n inputRef.current?.click()\n }, [])\n\n const atLimit = !!maxFiles && files.length >= maxFiles\n\n return (\n <div className={clsx(s.Root, className)}>\n {variant === \"area\" ? (\n <button\n type=\"button\"\n className={s.AreaTrigger}\n data-invalid={invalid ? \"\" : undefined}\n onClick={openPicker}\n disabled={disabled || atLimit}\n // The visible trigger is what keyboard and screen-reader users reach\n aria-describedby={ariaDescribedBy}\n aria-invalid={ariaInvalid}\n >\n <UploadDocuments className={s.AreaIcon} />\n <span className={s.AreaLabel}>{label || \"Tap to upload files\"}</span>\n {description && <span className={s.AreaDescription}>{description}</span>}\n </button>\n ) : (\n <Button\n color=\"secondary\"\n variant=\"soft\"\n size=\"3xl\"\n pill\n block\n disabled={disabled || atLimit}\n onClick={openPicker}\n className=\"h-[3.25rem]\"\n aria-describedby={ariaDescribedBy}\n aria-invalid={ariaInvalid}\n >\n {label || \"Upload file\"}\n </Button>\n )}\n\n {files.length > 0 && (\n <ul\n className={s.FileList}\n data-variant={variant}\n aria-label=\"Attached files\"\n >\n {files.map((file, index) => (\n <li key={`${file.name}-${file.size}-${file.lastModified}`}>\n <FileCard\n file={file}\n onRemove={() => removeFile(index)}\n disabled={disabled}\n />\n </li>\n ))}\n </ul>\n )}\n\n <input\n ref={inputRef}\n type=\"file\"\n className={s.HiddenInput}\n accept={accept}\n multiple={multiple}\n onChange={handleFileSelect}\n disabled={disabled}\n id={inputId}\n aria-describedby={ariaDescribedBy}\n tabIndex={-1}\n />\n\n {errorMessage && (\n <FieldError id={errorId} className={s.ErrorMessage}>\n {errorMessage}\n </FieldError>\n )}\n </div>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"FileUpload.js","sourceRoot":"","sources":["../../../../src/components/FileUpload/FileUpload.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACxF,OAAO,EACL,YAAY,EACZ,WAAW,EACX,SAAS,EACT,eAAe,EACf,CAAC,GACF,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,UA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,OAAO,gBACV,gBAAgB,YAE1B,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAC1B,uBACE,KAAC,QAAQ,IACP,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EACjC,QAAQ,EAAE,QAAQ,GAClB,IALK,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,YAAY,EAAE,CAMpD,CACN,CAAC,GACC,CACN,EAED,gBACE,GAAG,EAAE,QAAQ,EACb,IAAI,EAAC,MAAM,EACX,SAAS,EAAE,CAAC,CAAC,WAAW,EACxB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,OAAO,gBACC,KAAK,IAAI,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,aAAa,CAAC,kBACnE,WAAW,sBACP,eAAe,EACjC,QAAQ,EAAE,CAAC,CAAC,GACZ,EAED,YAAY,IAAI,CACf,KAAC,UAAU,IAAC,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,YAAY,YAC/C,YAAY,GACF,CACd,IACG,CACP,CAAA;AACH,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from \"react\"\nimport {\n FileDocument,\n ImageSquare,\n FileBlank,\n UploadDocuments,\n X,\n} from \"../Icon\"\nimport { Button } from \"../Button\"\nimport { FieldError } from \"../FieldError\"\nimport s from \"@plexui/styles/components/FileUpload/FileUpload.module.css\"\n\nexport type FileUploadProps = {\n variant?: \"compact\" | \"area\"\n label?: string\n description?: string\n accept?: string\n multiple?: boolean\n maxFiles?: number\n maxSize?: number\n value?: File[]\n onValueChange?: (files: File[]) => void\n onFileReject?: (file: File, reason: string) => void\n errorMessage?: string\n invalid?: boolean\n disabled?: boolean\n id?: string\n className?: string\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean\n}\n\nfunction getFileIcon(file: File) {\n const type = file.type\n const name = file.name.toLowerCase()\n\n if (\n type === \"application/pdf\" ||\n name.endsWith(\".pdf\") ||\n name.endsWith(\".doc\") ||\n name.endsWith(\".docx\") ||\n name.endsWith(\".txt\") ||\n name.endsWith(\".rtf\")\n ) {\n return <FileDocument />\n }\n\n if (type.startsWith(\"image/\") || /\\.(png|jpe?g|gif|svg|webp|bmp|ico)$/.test(name)) {\n return <ImageSquare />\n }\n\n return <FileBlank />\n}\n\nfunction formatFileSize(bytes: number): string {\n if (bytes === 0) return \"0 B\"\n if (bytes < 1024) return `${bytes} B`\n if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`\n return `${(bytes / (1024 * 1024)).toFixed(1)} MB`\n}\n\nfunction splitFileName(name: string): { stem: string; ext: string } {\n const lastDot = name.lastIndexOf(\".\")\n if (lastDot <= 0) return { stem: name, ext: \"\" }\n return {\n stem: name.slice(0, lastDot),\n ext: name.slice(lastDot),\n }\n}\n\nexport type FileCardGroupProps = {\n children: React.ReactNode\n className?: string\n}\n\nexport const FileCardGroup = ({ children, className }: FileCardGroupProps) => {\n return <div className={clsx(s.FileCardGroup, className)}>{children}</div>\n}\n\nexport type FileCardProps = {\n file: File\n onRemove?: () => void\n disabled?: boolean\n className?: string\n}\n\nexport const FileCard = ({ file, onRemove, disabled, className }: FileCardProps) => {\n const { stem, ext } = splitFileName(file.name)\n\n return (\n <div className={clsx(s.FileItem, className)}>\n <div className={s.FileIcon}>{getFileIcon(file)}</div>\n <div className={s.FileInfo}>\n <div className={s.FileNameRow}>\n <span className={s.FileNameStem}>{stem}</span>\n {ext && <span className={s.FileNameExt}>{ext}</span>}\n </div>\n <span className={s.FileSize}>{formatFileSize(file.size)}</span>\n </div>\n {onRemove && (\n <button\n type=\"button\"\n className={s.FileRemove}\n onClick={onRemove}\n aria-label={`Remove ${file.name}`}\n disabled={disabled}\n >\n <X />\n </button>\n )}\n </div>\n )\n}\n\nfunction matchesAccept(file: File, accept: string): boolean {\n const acceptTypes = accept.split(\",\").map((t) => t.trim().toLowerCase())\n const fileName = file.name.toLowerCase()\n const fileType = file.type.toLowerCase()\n\n return acceptTypes.some((acceptType) => {\n if (acceptType.startsWith(\".\")) {\n return fileName.endsWith(acceptType)\n }\n if (acceptType.endsWith(\"/*\")) {\n const prefix = acceptType.slice(0, -1)\n return fileType.startsWith(prefix)\n }\n return fileType === acceptType\n })\n}\n\nexport const FileUpload = (props: FileUploadProps) => {\n const {\n variant = \"compact\",\n label,\n description,\n accept,\n multiple = false,\n maxFiles,\n maxSize,\n value: controlledValue,\n onValueChange,\n onFileReject,\n errorMessage,\n \"invalid\": invalidProp,\n disabled = false,\n className,\n id: idProp,\n \"aria-describedby\": ariaDescribedByProp,\n \"aria-invalid\": ariaInvalidProp,\n } = props\n\n const [internalFiles, setInternalFiles] = useState<File[]>([])\n const inputRef = useRef<HTMLInputElement>(null)\n const rootRef = useRef<HTMLDivElement>(null)\n const listRef = useRef<HTMLUListElement>(null)\n const pendingRemovalFocus = useRef<{ file: File; index: number; source: HTMLButtonElement } | null>(null)\n const generatedId = useId()\n const inputId = idProp || `file-upload-${generatedId}`\n const errorId = `${inputId}-error`\n\n const files = controlledValue ?? internalFiles\n const isControlled = controlledValue !== undefined\n const invalid = invalidProp ?? !!errorMessage\n const ariaInvalid = ariaInvalidProp ?? (invalid || undefined)\n\n // Restore only after the owner accepts deletion. A later user interaction\n // cancels the request, even if focus subsequently returns to the document body.\n useEffect(() => {\n const doc = rootRef.current?.ownerDocument\n if (!doc) return\n const cancelAfterMoving = (event: Event) => {\n const pending = pendingRemovalFocus.current\n if (pending && event.target instanceof Node && !pending.source.contains(event.target)) {\n pendingRemovalFocus.current = null\n }\n }\n doc.addEventListener(\"focusin\", cancelAfterMoving, true)\n doc.addEventListener(\"pointerdown\", cancelAfterMoving, true)\n return () => {\n doc.removeEventListener(\"focusin\", cancelAfterMoving, true)\n doc.removeEventListener(\"pointerdown\", cancelAfterMoving, true)\n }\n }, [])\n\n useLayoutEffect(() => {\n const pending = pendingRemovalFocus.current\n if (!pending || files.includes(pending.file)) return\n pendingRemovalFocus.current = null\n const doc = pending.source.ownerDocument\n if (disabled || (doc.activeElement !== doc.body && !pending.source.contains(doc.activeElement))) return\n const buttons = Array.from(listRef.current?.querySelectorAll<HTMLButtonElement>(\"button:not(:disabled)\") ?? [])\n const target = buttons[Math.min(pending.index, buttons.length - 1)]\n ?? rootRef.current?.querySelector<HTMLButtonElement>(\"button:not(:disabled):not([aria-disabled=true])\")\n target?.focus({ preventScroll: true })\n }, [files, disabled])\n\n const ariaDescribedBy =\n [ariaDescribedByProp, errorMessage ? errorId : undefined].filter(Boolean).join(\" \") ||\n undefined\n\n const updateFiles = useCallback(\n (next: File[]) => {\n onValueChange?.(next)\n if (!isControlled) {\n setInternalFiles(next)\n }\n },\n [onValueChange, isControlled],\n )\n\n const handleFileSelect = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>) => {\n const selected = Array.from(e.target.files || [])\n // Without `multiple`, a pick replaces the file instead of adding to it\n const kept = multiple ? files : []\n const accepted: File[] = []\n\n for (const file of selected) {\n if (accept && !matchesAccept(file, accept)) {\n onFileReject?.(file, `File type not accepted: ${file.name}`)\n continue\n }\n if (maxSize && file.size > maxSize) {\n onFileReject?.(file, `File too large: ${file.name} (${formatFileSize(file.size)})`)\n continue\n }\n if (maxFiles && kept.length + accepted.length >= maxFiles) {\n onFileReject?.(file, `Maximum ${maxFiles} files allowed`)\n continue\n }\n accepted.push(file)\n }\n\n if (accepted.length > 0) {\n updateFiles([...kept, ...accepted])\n }\n\n e.target.value = \"\"\n },\n [accept, maxSize, maxFiles, multiple, files, updateFiles, onFileReject],\n )\n\n const removeFile = useCallback(\n (index: number) => {\n const file = files[index]\n const source = listRef.current?.querySelectorAll<HTMLButtonElement>(\"button\")[index]\n if (file && source?.contains(source.ownerDocument.activeElement)) {\n pendingRemovalFocus.current = { file, index, source }\n }\n const next = files.filter((_, i) => i !== index)\n updateFiles(next)\n },\n [files, updateFiles],\n )\n\n const openPicker = useCallback(() => {\n inputRef.current?.click()\n }, [])\n\n const atLimit = multiple && !!maxFiles && files.length >= maxFiles\n\n return (\n <div ref={rootRef} className={clsx(s.Root, className)} role=\"group\" aria-describedby={ariaDescribedBy}>\n {variant === \"area\" ? (\n <button\n type=\"button\"\n className={s.AreaTrigger}\n data-invalid={invalid ? \"\" : undefined}\n onClick={openPicker}\n disabled={disabled || atLimit}\n // Announce the error from the action; invalid belongs to the file input.\n aria-describedby={ariaDescribedBy}\n >\n <UploadDocuments className={s.AreaIcon} />\n <span className={s.AreaLabel}>{label || \"Tap to upload files\"}</span>\n {description && <span className={s.AreaDescription}>{description}</span>}\n </button>\n ) : (\n <Button\n color=\"secondary\"\n variant=\"soft\"\n size=\"3xl\"\n pill\n block\n disabled={disabled || atLimit}\n onClick={openPicker}\n aria-describedby={ariaDescribedBy}\n >\n {label || \"Upload file\"}\n </Button>\n )}\n\n {files.length > 0 && (\n <ul\n ref={listRef}\n className={s.FileList}\n data-variant={variant}\n aria-label=\"Attached files\"\n >\n {files.map((file, index) => (\n <li key={`${file.name}-${file.size}-${file.lastModified}`}>\n <FileCard\n file={file}\n onRemove={() => removeFile(index)}\n disabled={disabled}\n />\n </li>\n ))}\n </ul>\n )}\n\n <input\n ref={inputRef}\n type=\"file\"\n className={s.HiddenInput}\n accept={accept}\n multiple={multiple}\n onChange={handleFileSelect}\n disabled={disabled}\n id={inputId}\n aria-label={label || (variant === \"area\" ? \"Tap to upload files\" : \"Upload file\")}\n aria-invalid={ariaInvalid}\n aria-describedby={ariaDescribedBy}\n tabIndex={-1}\n />\n\n {errorMessage && (\n <FieldError id={errorId} className={s.ErrorMessage}>\n {errorMessage}\n </FieldError>\n )}\n </div>\n )\n}\n"]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import clsx from "clsx";
|
|
4
|
-
import { forwardRef, useCallback,
|
|
4
|
+
import { forwardRef, useCallback, useId, useLayoutEffect, useRef, useState } from "react";
|
|
5
5
|
import { mergeRefs } from "react-merge-refs";
|
|
6
|
-
import {
|
|
6
|
+
import { observeTextareaWidth } from "../../lib/observeTextareaWidth.js";
|
|
7
|
+
import { Eye, EyeOff, X, XCircleFilled } from "../Icon/index.js";
|
|
8
|
+
import { FieldError } from "../FieldError/index.js";
|
|
7
9
|
import s from "@plexui/styles/components/FloatingLabelInput/FloatingLabelInput.module.css";
|
|
8
10
|
// Attributes that only mean something on <input>; everything else (required,
|
|
9
11
|
// maxLength, placeholder, key and clipboard handlers, aria-*, data-*) also
|
|
@@ -27,16 +29,12 @@ export const FloatingLabelInput = forwardRef(function FloatingLabelInput(props,
|
|
|
27
29
|
const descriptionId = description ? `${inputId}-description` : undefined;
|
|
28
30
|
const errorId = errorMessage ? `${inputId}-error` : undefined;
|
|
29
31
|
const [focused, setFocused] = useState(false);
|
|
30
|
-
const [
|
|
31
|
-
return
|
|
32
|
+
const [hasUncontrolledValue, setHasValue] = useState(() => {
|
|
33
|
+
return String((value !== undefined ? value : defaultValue) ?? "") !== "";
|
|
32
34
|
});
|
|
33
35
|
const [revealed, setRevealed] = useState(false);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (value !== undefined) {
|
|
37
|
-
setHasValue(!!value);
|
|
38
|
-
}
|
|
39
|
-
}, [value]);
|
|
36
|
+
const revealedRef = useRef(false);
|
|
37
|
+
const hasValue = value !== undefined ? String(value ?? "") !== "" : hasUncontrolledValue;
|
|
40
38
|
const autoResize = useCallback(() => {
|
|
41
39
|
const el = inputRef.current;
|
|
42
40
|
if (!multiline || !el)
|
|
@@ -44,6 +42,11 @@ export const FloatingLabelInput = forwardRef(function FloatingLabelInput(props,
|
|
|
44
42
|
el.style.height = "auto";
|
|
45
43
|
el.style.height = `${el.scrollHeight}px`;
|
|
46
44
|
}, [multiline]);
|
|
45
|
+
useLayoutEffect(() => {
|
|
46
|
+
if (!multiline || !inputRef.current)
|
|
47
|
+
return;
|
|
48
|
+
return observeTextareaWidth(inputRef.current, autoResize);
|
|
49
|
+
}, [multiline, autoResize]);
|
|
47
50
|
// Also resize when a controlled value or rows changes without a keystroke
|
|
48
51
|
useLayoutEffect(() => {
|
|
49
52
|
autoResize();
|
|
@@ -109,15 +112,14 @@ export const FloatingLabelInput = forwardRef(function FloatingLabelInput(props,
|
|
|
109
112
|
}
|
|
110
113
|
}, [onAnimationStart, onAutofill]);
|
|
111
114
|
const handleRevealToggle = useCallback(() => {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
115
|
+
const next = !revealedRef.current;
|
|
116
|
+
revealedRef.current = next;
|
|
117
|
+
setRevealed(next);
|
|
118
|
+
onRevealedChange?.(next);
|
|
117
119
|
}, [onRevealedChange]);
|
|
118
120
|
return (_jsxs("div", { className: clsx(s.Root, className), "data-label-placement": labelPlacement === "inside" ? "inside" : undefined, "data-pill": pill && labelPlacement !== "inside" ? "" : undefined, children: [_jsxs("div", { className: clsx(s.FieldFootprint, {
|
|
119
121
|
[s.HasValue]: hasValue || !!startAdornment,
|
|
120
|
-
}), "data-focused": focused ? "" : undefined, "data-has-value": hasValue ? "" : undefined, "data-invalid": invalid ? "" : undefined, "data-disabled": disabled ? "" : undefined, "data-readonly": readOnly ? "" : undefined, "data-multiline": multiline ? "" : undefined, onMouseDown: handleContainerMouseDown, children: [_jsx("label", { className: s.TypeableLabel, htmlFor: inputId, children: _jsx("div", { className: s.LabelPositioner, children: _jsx("div", { className: s.LabelText, children: label }) }) }), startAdornment && (_jsx("div", { className: s.StartAdornment, children: startAdornment })), multiline ? (_jsx("textarea", { ...textareaProps(restProps), ref: mergeRefs([ref, inputRef]), id: inputId, name: name, rows: rows, className: s.Textarea, value: value, defaultValue: defaultValue, disabled: disabled, readOnly: readOnly, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur })) : (_jsx("input", { ...restProps, ref: mergeRefs([ref, inputRef]), id: inputId, name: name, type: effectiveType, className: s.Input, value: value, defaultValue: defaultValue, disabled: disabled, readOnly: readOnly, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur, onAnimationStart: handleAnimationStart, "data-lpignore": allowAutofillExtensions ? undefined : true, "data-1p-ignore": allowAutofillExtensions ? undefined : true })), endAdornment && (_jsx("div", { className: s.EndAdornment, children: endAdornment })), showClearButton && (
|
|
122
|
+
}), "data-focused": focused ? "" : undefined, "data-has-value": hasValue ? "" : undefined, "data-invalid": invalid ? "" : undefined, "data-disabled": disabled ? "" : undefined, "data-readonly": readOnly ? "" : undefined, "data-multiline": multiline ? "" : undefined, onMouseDown: handleContainerMouseDown, children: [_jsx("label", { className: s.TypeableLabel, htmlFor: inputId, children: _jsx("div", { className: s.LabelPositioner, children: _jsx("div", { className: s.LabelText, children: label }) }) }), startAdornment && (_jsx("div", { className: s.StartAdornment, children: startAdornment })), multiline ? (_jsx("textarea", { ...textareaProps(restProps), ref: mergeRefs([ref, inputRef]), id: inputId, name: name, rows: rows, className: s.Textarea, value: value, defaultValue: defaultValue, disabled: disabled, readOnly: readOnly, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur })) : (_jsx("input", { ...restProps, ref: mergeRefs([ref, inputRef]), id: inputId, name: name, type: effectiveType, className: s.Input, value: value, defaultValue: defaultValue, disabled: disabled, readOnly: readOnly, "aria-invalid": ariaInvalid, "aria-describedby": ariaDescribedBy, onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur, onAnimationStart: handleAnimationStart, "data-lpignore": allowAutofillExtensions ? undefined : true, "data-1p-ignore": allowAutofillExtensions ? undefined : true })), endAdornment && (_jsx("div", { className: s.EndAdornment, children: endAdornment })), showClearButton && (_jsxs("button", { type: "button", "aria-label": "Clear input", className: s.ClearButton, onClick: handleClear, children: [_jsx(X, { className: s.ClearIcon }), _jsx(XCircleFilled, { className: s.ClearPhoneIcon })] })), showRevealButton && (_jsx("button", { type: "button", "aria-label": revealed ? "Hide" : "Show", className: s.RevealButton, onClick: handleRevealToggle, children: revealed ? _jsx(EyeOff, {}) : _jsx(Eye, {}) }))] }), errorMessage && (_jsx(FieldError, { id: errorId, className: s.ErrorMessage, children: errorMessage })), description && (_jsx("div", { id: descriptionId, className: s.Description, children: description }))] }));
|
|
121
123
|
});
|
|
122
124
|
FloatingLabelInput.displayName = "FloatingLabelInput";
|
|
123
125
|
//# sourceMappingURL=FloatingLabelInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FloatingLabelInput.js","sourceRoot":"","sources":["../../../../src/components/FloatingLabelInput/FloatingLabelInput.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE5C,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,SAAS,CAAA;AAExC,OAAO,CAAC,MAAM,4EAA4E,CAAA;AAyF1F,6EAA6E;AAC7E,2EAA2E;AAC3E,sCAAsC;AACtC,MAAM,gBAAgB,GAAG;IACvB,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU;IACjF,SAAS,EAAE,MAAM,EAAE,KAA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AAC,SAAS,CAAC,CAAC,CAAC,IAAI,oBACzC,uBAAuB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,GAC1D,CACH,EACA,YAAY,IAAI,CACf,cAAK,SAAS,EAAE,CAAC,CAAC,YAAY,YAC3B,YAAY,GACT,CACP,EACA,eAAe,IAAI,CAClB,iBACE,IAAI,EAAC,QAAQ,gBACF,aAAa,EACxB,SAAS,EAAE,CAAC,CAAC,WAAW,EACxB,OAAO,EAAE,WAAW,YAEpB,KAAC,CAAC,KAAG,GACE,CACV,EACA,gBAAgB,IAAI,CACnB,iBACE,IAAI,EAAC,QAAQ,gBACD,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EACtC,SAAS,EAAE,CAAC,CAAC,YAAY,EACzB,OAAO,EAAE,kBAAkB,YAE1B,QAAQ,CAAC,CAAC,CAAC,KAAC,MAAM,KAAG,CAAC,CAAC,CAAC,KAAC,GAAG,KAAG,GACzB,CACV,IACG,EACL,YAAY,IAAI,CACf,cAAK,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,YAAY,EAAE,IAAI,EAAC,OAAO,YACtD,YAAY,GACT,CACP,EACA,WAAW,IAAI,CACd,cAAK,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC,CAAC,WAAW,YAC7C,WAAW,GACR,CACP,IACG,CACP,CAAA;AACH,CAAC,CACF,CAAA;AAED,kBAAkB,CAAC,WAAW,GAAG,oBAAoB,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { forwardRef, useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from \"react\"\nimport { mergeRefs } from \"react-merge-refs\"\n\nimport { Eye, EyeOff, X } from \"../Icon\"\n\nimport s from \"@plexui/styles/components/FloatingLabelInput/FloatingLabelInput.module.css\"\n\nexport type FloatingLabelInputProps = {\n /**\n * Label text for the floating label\n */\n label: string\n /**\n * Error message to display below the input\n */\n errorMessage?: string\n /**\n * Mark the input as invalid\n * @default false (or true if errorMessage is provided)\n */\n invalid?: boolean\n /**\n * Disables the input visually and from interactions\n * @default false\n */\n disabled?: boolean\n /**\n * Makes the input read-only\n * @default false\n */\n readOnly?: boolean\n /**\n * Callback invoked when the clear button is clicked\n */\n onClear?: () => void\n /**\n * Callback invoked when the input is autofilled by the browser\n */\n onAutofill?: () => void\n /**\n * Allow autofill extensions to appear in the input\n * @default false\n */\n allowAutofillExtensions?: boolean\n /**\n * Helper/description text displayed below the input.\n * Shown alongside the error message when both are present.\n */\n description?: React.ReactNode\n /**\n * Content rendered before the input.\n */\n startAdornment?: React.ReactNode\n /**\n * Content rendered after the input, before the clear button.\n * For password fields the reveal toggle is built in — see `revealable`.\n */\n endAdornment?: React.ReactNode\n /**\n * Render a built-in reveal/hide toggle (eye icon) inside the field.\n * For `type=\"password\"` it swaps the input between `password` and `text`.\n * Defaults to `true` for password inputs that don't supply their own\n * `endAdornment`. Pass it explicitly to add the toggle to other sensitive\n * fields (e.g. a masked SSN) and react to it via `onRevealedChange`.\n * @default true when type=\"password\" and no endAdornment is provided\n */\n revealable?: boolean\n /**\n * Called with the new revealed state each time the reveal toggle is clicked.\n */\n onRevealedChange?: (revealed: boolean) => void\n /**\n * Render as a multi-line textarea instead of a single-line input.\n * @default false\n */\n multiline?: boolean\n /**\n * Number of visible text lines when `multiline` is true.\n * @default 2\n */\n rows?: number\n /**\n * Where the label rests once it floats: on the border, or inside the box\n * with the value under it. `inside` always takes the rounded box.\n * @default \"border\"\n */\n labelPlacement?: \"border\" | \"inside\"\n /**\n * Pill shape. `false` takes the rounded box of the other fields.\n * @default true\n */\n pill?: boolean\n} & React.InputHTMLAttributes<HTMLInputElement>\n\n// Attributes that only mean something on <input>; everything else (required,\n// maxLength, placeholder, key and clipboard handlers, aria-*, data-*) also\n// applies to the multiline <textarea>\nconst INPUT_ONLY_PROPS = [\n \"accept\", \"alt\", \"capture\", \"checked\", \"height\", \"list\", \"max\", \"min\", \"multiple\",\n \"pattern\", \"size\", \"src\", \"step\", \"width\", \"formAction\", \"formEncType\",\n \"formMethod\", \"formNoValidate\", \"formTarget\",\n] as const\n\nconst textareaProps = (props: Record<string, unknown>) => {\n const rest = { ...props }\n for (const key of INPUT_ONLY_PROPS) delete rest[key]\n return rest\n}\n\nexport const FloatingLabelInput = forwardRef<HTMLInputElement, FloatingLabelInputProps>(\n function FloatingLabelInput(props, ref) {\n const {\n label,\n description,\n errorMessage,\n \"invalid\": invalidProp,\n disabled = false,\n readOnly = false,\n onClear,\n onAutofill,\n allowAutofillExtensions = false,\n startAdornment,\n endAdornment,\n revealable: revealableProp,\n onRevealedChange,\n multiline = false,\n rows = 2,\n labelPlacement = \"border\",\n pill = true,\n className,\n \"id\": idProp,\n name,\n type = \"text\",\n value,\n defaultValue,\n onChange,\n onFocus,\n onBlur,\n onAnimationStart,\n \"aria-describedby\": ariaDescribedByProp,\n ...restProps\n } = props\n\n const inputRef = useRef<HTMLInputElement | null>(null)\n const generatedId = useId()\n const inputId = idProp || `floating-label-input-${generatedId}`\n const descriptionId = description ? `${inputId}-description` : undefined\n const errorId = errorMessage ? `${inputId}-error` : undefined\n\n const [focused, setFocused] = useState(false)\n const [hasValue, setHasValue] = useState(() => {\n return !!(value !== undefined ? value : defaultValue)\n })\n const [revealed, setRevealed] = useState(false)\n\n // Sync hasValue with controlled value prop\n useEffect(() => {\n if (value !== undefined) {\n setHasValue(!!value)\n }\n }, [value])\n\n const autoResize = useCallback(() => {\n const el = inputRef.current\n if (!multiline || !el) return\n el.style.height = \"auto\"\n el.style.height = `${el.scrollHeight}px`\n }, [multiline])\n\n // Also resize when a controlled value or rows changes without a keystroke\n useLayoutEffect(() => {\n autoResize()\n }, [autoResize, value, rows])\n\n const invalid = invalidProp ?? !!errorMessage\n\n // Determine if clear button should be shown\n const showClearButton = !!onClear && hasValue && !disabled && !readOnly\n\n // Built-in password reveal toggle\n const isPassword = type === \"password\"\n const revealable = revealableProp ?? (isPassword && !endAdornment)\n const showRevealButton = revealable && !disabled\n const effectiveType = isPassword && revealed ? \"text\" : type\n\n // Merge aria-describedby with error id\n const ariaDescribedBy =\n [ariaDescribedByProp, errorId, descriptionId].filter(Boolean).join(\" \") || undefined\n // An explicit aria-invalid (e.g. from Field) wins over the computed state\n const ariaInvalid = restProps[\"aria-invalid\"] ?? (invalid ? true : undefined)\n\n // Handle clicks on the container to focus the input\n const handleContainerMouseDown = useCallback((evt: React.MouseEvent<HTMLDivElement>) => {\n const input = inputRef.current\n if (!evt.target || !(evt.target instanceof Element) || !input) {\n return\n }\n if (input.contains(evt.target)) {\n return\n }\n if (evt.target.closest(\"button, [type='button'], [role='button']\")) {\n return\n }\n evt.preventDefault()\n if (document.activeElement !== input) {\n input.focus()\n }\n // email, number and other types without the selection API throw on setSelectionRange\n if (input.selectionStart === null) return\n const length = input.value.length\n input.setSelectionRange(length, length)\n }, [])\n\n // The clear button unmounts once the value is gone, so keep focus in the field\n const handleClear = useCallback(\n (evt: React.MouseEvent<HTMLButtonElement>) => {\n inputRef.current?.focus()\n ;(onClear as React.MouseEventHandler<HTMLButtonElement> | undefined)?.(evt)\n },\n [onClear],\n )\n\n const handleFocus = useCallback(\n (evt: React.FocusEvent<HTMLInputElement>) => {\n setFocused(true)\n onFocus?.(evt)\n },\n [onFocus],\n )\n\n const handleBlur = useCallback(\n (evt: React.FocusEvent<HTMLInputElement>) => {\n setFocused(false)\n onBlur?.(evt)\n },\n [onBlur],\n )\n\n const handleChange = useCallback(\n (evt: React.ChangeEvent<HTMLInputElement>) => {\n setHasValue(!!evt.currentTarget.value)\n onChange?.(evt)\n autoResize()\n },\n [onChange, autoResize],\n )\n\n const handleAnimationStart = useCallback(\n (evt: React.AnimationEvent<HTMLInputElement>) => {\n onAnimationStart?.(evt)\n // Detect browser autofill\n if (evt.animationName === \"native-autofill-in\") {\n setHasValue(true)\n onAutofill?.()\n }\n },\n [onAnimationStart, onAutofill],\n )\n\n const handleRevealToggle = useCallback(() => {\n setRevealed((prev) => {\n const next = !prev\n onRevealedChange?.(next)\n return next\n })\n }, [onRevealedChange])\n\n return (\n <div\n className={clsx(s.Root, className)}\n data-label-placement={labelPlacement === \"inside\" ? \"inside\" : undefined}\n data-pill={pill && labelPlacement !== \"inside\" ? \"\" : undefined}\n >\n <div\n className={clsx(s.FieldFootprint, {\n [s.HasValue]: hasValue || !!startAdornment,\n })}\n data-focused={focused ? \"\" : undefined}\n data-has-value={hasValue ? \"\" : undefined}\n data-invalid={invalid ? \"\" : undefined}\n data-disabled={disabled ? \"\" : undefined}\n data-readonly={readOnly ? \"\" : undefined}\n data-multiline={multiline ? \"\" : undefined}\n onMouseDown={handleContainerMouseDown}\n >\n <label className={s.TypeableLabel} htmlFor={inputId}>\n <div className={s.LabelPositioner}>\n <div className={s.LabelText}>{label}</div>\n </div>\n </label>\n {startAdornment && (\n <div className={s.StartAdornment}>{startAdornment}</div>\n )}\n {multiline ? (\n <textarea\n {...(textareaProps(restProps) as React.TextareaHTMLAttributes<HTMLTextAreaElement>)}\n ref={mergeRefs([ref, inputRef]) as React.Ref<HTMLTextAreaElement>}\n id={inputId}\n name={name}\n rows={rows}\n className={s.Textarea}\n value={value}\n defaultValue={defaultValue}\n disabled={disabled}\n readOnly={readOnly}\n aria-invalid={ariaInvalid}\n aria-describedby={ariaDescribedBy}\n onChange={handleChange as unknown as React.ChangeEventHandler<HTMLTextAreaElement>}\n onFocus={handleFocus as unknown as React.FocusEventHandler<HTMLTextAreaElement>}\n onBlur={handleBlur as unknown as React.FocusEventHandler<HTMLTextAreaElement>}\n />\n ) : (\n <input\n {...restProps}\n ref={mergeRefs([ref, inputRef])}\n id={inputId}\n name={name}\n type={effectiveType}\n className={s.Input}\n value={value}\n defaultValue={defaultValue}\n disabled={disabled}\n readOnly={readOnly}\n aria-invalid={ariaInvalid}\n aria-describedby={ariaDescribedBy}\n onChange={handleChange}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onAnimationStart={handleAnimationStart}\n data-lpignore={allowAutofillExtensions ? undefined : true}\n data-1p-ignore={allowAutofillExtensions ? undefined : true}\n />\n )}\n {endAdornment && (\n <div className={s.EndAdornment}>\n {endAdornment}\n </div>\n )}\n {showClearButton && (\n <button\n type=\"button\"\n aria-label=\"Clear input\"\n className={s.ClearButton}\n onClick={handleClear}\n >\n <X />\n </button>\n )}\n {showRevealButton && (\n <button\n type=\"button\"\n aria-label={revealed ? \"Hide\" : \"Show\"}\n className={s.RevealButton}\n onClick={handleRevealToggle}\n >\n {revealed ? <EyeOff /> : <Eye />}\n </button>\n )}\n </div>\n {errorMessage && (\n <div id={errorId} className={s.ErrorMessage} role=\"alert\">\n {errorMessage}\n </div>\n )}\n {description && (\n <div id={descriptionId} className={s.Description}>\n {description}\n </div>\n )}\n </div>\n )\n },\n)\n\nFloatingLabelInput.displayName = \"FloatingLabelInput\"\n"]}
|
|
1
|
+
{"version":3,"file":"FloatingLabelInput.js","sourceRoot":"","sources":["../../../../src/components/FloatingLabelInput/FloatingLabelInput.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACzF,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAA;AAErE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE1C,OAAO,CAAC,MAAM,4EAA4E,CAAA;AAyF1F,6EAA6E;AAC7E,2EAA2E;AAC3E,sCAAsC;AACtC,MAAM,gBAAgB,GAAG;IACvB,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,KA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,CAAC,CAAC,WAAW,YAC7C,WAAW,GACR,CACP,IACG,CACP,CAAA;AACH,CAAC,CACF,CAAA;AAED,kBAAkB,CAAC,WAAW,GAAG,oBAAoB,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { forwardRef, useCallback, useId, useLayoutEffect, useRef, useState } from \"react\"\nimport { mergeRefs } from \"react-merge-refs\"\nimport { observeTextareaWidth } from \"../../lib/observeTextareaWidth\"\n\nimport { Eye, EyeOff, X, XCircleFilled } from \"../Icon\"\nimport { FieldError } from \"../FieldError\"\n\nimport s from \"@plexui/styles/components/FloatingLabelInput/FloatingLabelInput.module.css\"\n\nexport type FloatingLabelInputProps = {\n /**\n * Label text for the floating label\n */\n label: string\n /**\n * Error message to display below the input\n */\n errorMessage?: string\n /**\n * Mark the input as invalid\n * @default false (or true if errorMessage is provided)\n */\n invalid?: boolean\n /**\n * Disables the input visually and from interactions\n * @default false\n */\n disabled?: boolean\n /**\n * Makes the input read-only\n * @default false\n */\n readOnly?: boolean\n /**\n * Callback invoked when the clear button is clicked\n */\n onClear?: () => void\n /**\n * Callback invoked when the input is autofilled by the browser\n */\n onAutofill?: () => void\n /**\n * Allow autofill extensions to appear in the input\n * @default false\n */\n allowAutofillExtensions?: boolean\n /**\n * Helper/description text displayed below the input.\n * Shown alongside the error message when both are present.\n */\n description?: React.ReactNode\n /**\n * Content rendered before the input.\n */\n startAdornment?: React.ReactNode\n /**\n * Content rendered after the input, before the clear button.\n * For password fields the reveal toggle is built in — see `revealable`.\n */\n endAdornment?: React.ReactNode\n /**\n * Render a built-in reveal/hide toggle (eye icon) inside the field.\n * For `type=\"password\"` it swaps the input between `password` and `text`.\n * Defaults to `true` for password inputs that don't supply their own\n * `endAdornment`. Pass it explicitly to add the toggle to other sensitive\n * fields (e.g. a masked SSN) and react to it via `onRevealedChange`.\n * @default true when type=\"password\" and no endAdornment is provided\n */\n revealable?: boolean\n /**\n * Called with the new revealed state each time the reveal toggle is clicked.\n */\n onRevealedChange?: (revealed: boolean) => void\n /**\n * Render as a multi-line textarea instead of a single-line input.\n * @default false\n */\n multiline?: boolean\n /**\n * Number of visible text lines when `multiline` is true.\n * @default 2\n */\n rows?: number\n /**\n * Where the label rests once it floats: on the border, or inside the box\n * with the value under it. `inside` always takes the rounded box.\n * @default \"border\"\n */\n labelPlacement?: \"border\" | \"inside\"\n /**\n * Pill shape. `false` takes the rounded box of the other fields.\n * @default true\n */\n pill?: boolean\n} & React.InputHTMLAttributes<HTMLInputElement>\n\n// Attributes that only mean something on <input>; everything else (required,\n// maxLength, placeholder, key and clipboard handlers, aria-*, data-*) also\n// applies to the multiline <textarea>\nconst INPUT_ONLY_PROPS = [\n \"accept\", \"alt\", \"capture\", \"checked\", \"height\", \"list\", \"max\", \"min\", \"multiple\",\n \"pattern\", \"size\", \"src\", \"step\", \"width\", \"formAction\", \"formEncType\",\n \"formMethod\", \"formNoValidate\", \"formTarget\",\n] as const\n\nconst textareaProps = (props: Record<string, unknown>) => {\n const rest = { ...props }\n for (const key of INPUT_ONLY_PROPS) delete rest[key]\n return rest\n}\n\nexport const FloatingLabelInput = forwardRef<HTMLInputElement, FloatingLabelInputProps>(\n function FloatingLabelInput(props, ref) {\n const {\n label,\n description,\n errorMessage,\n \"invalid\": invalidProp,\n disabled = false,\n readOnly = false,\n onClear,\n onAutofill,\n allowAutofillExtensions = false,\n startAdornment,\n endAdornment,\n revealable: revealableProp,\n onRevealedChange,\n multiline = false,\n rows = 2,\n labelPlacement = \"border\",\n pill = true,\n className,\n \"id\": idProp,\n name,\n type = \"text\",\n value,\n defaultValue,\n onChange,\n onFocus,\n onBlur,\n onAnimationStart,\n \"aria-describedby\": ariaDescribedByProp,\n ...restProps\n } = props\n\n const inputRef = useRef<HTMLInputElement | null>(null)\n const generatedId = useId()\n const inputId = idProp || `floating-label-input-${generatedId}`\n const descriptionId = description ? `${inputId}-description` : undefined\n const errorId = errorMessage ? `${inputId}-error` : undefined\n\n const [focused, setFocused] = useState(false)\n const [hasUncontrolledValue, setHasValue] = useState(() => {\n return String((value !== undefined ? value : defaultValue) ?? \"\") !== \"\"\n })\n const [revealed, setRevealed] = useState(false)\n const revealedRef = useRef(false)\n\n const hasValue = value !== undefined ? String(value ?? \"\") !== \"\" : hasUncontrolledValue\n\n const autoResize = useCallback(() => {\n const el = inputRef.current\n if (!multiline || !el) return\n el.style.height = \"auto\"\n el.style.height = `${el.scrollHeight}px`\n }, [multiline])\n\n useLayoutEffect(() => {\n if (!multiline || !inputRef.current) return\n return observeTextareaWidth(inputRef.current, autoResize)\n }, [multiline, autoResize])\n\n // Also resize when a controlled value or rows changes without a keystroke\n useLayoutEffect(() => {\n autoResize()\n }, [autoResize, value, rows])\n\n const invalid = invalidProp ?? !!errorMessage\n\n // Determine if clear button should be shown\n const showClearButton = !!onClear && hasValue && !disabled && !readOnly\n\n // Built-in password reveal toggle\n const isPassword = type === \"password\"\n const revealable = revealableProp ?? (isPassword && !endAdornment)\n const showRevealButton = revealable && !disabled\n const effectiveType = isPassword && revealed ? \"text\" : type\n\n // Merge aria-describedby with error id\n const ariaDescribedBy =\n [ariaDescribedByProp, errorId, descriptionId].filter(Boolean).join(\" \") || undefined\n // An explicit aria-invalid (e.g. from Field) wins over the computed state\n const ariaInvalid = restProps[\"aria-invalid\"] ?? (invalid ? true : undefined)\n\n // Handle clicks on the container to focus the input\n const handleContainerMouseDown = useCallback((evt: React.MouseEvent<HTMLDivElement>) => {\n const input = inputRef.current\n if (!evt.target || !(evt.target instanceof Element) || !input) {\n return\n }\n if (input.contains(evt.target)) {\n return\n }\n if (evt.target.closest(\"button, [type='button'], [role='button']\")) {\n return\n }\n evt.preventDefault()\n if (document.activeElement !== input) {\n input.focus()\n }\n // email, number and other types without the selection API throw on setSelectionRange\n if (input.selectionStart === null) return\n const length = input.value.length\n input.setSelectionRange(length, length)\n }, [])\n\n // The clear button unmounts once the value is gone, so keep focus in the field\n const handleClear = useCallback(\n (evt: React.MouseEvent<HTMLButtonElement>) => {\n inputRef.current?.focus()\n ;(onClear as React.MouseEventHandler<HTMLButtonElement> | undefined)?.(evt)\n },\n [onClear],\n )\n\n const handleFocus = useCallback(\n (evt: React.FocusEvent<HTMLInputElement>) => {\n setFocused(true)\n onFocus?.(evt)\n },\n [onFocus],\n )\n\n const handleBlur = useCallback(\n (evt: React.FocusEvent<HTMLInputElement>) => {\n setFocused(false)\n onBlur?.(evt)\n },\n [onBlur],\n )\n\n const handleChange = useCallback(\n (evt: React.ChangeEvent<HTMLInputElement>) => {\n setHasValue(!!evt.currentTarget.value)\n onChange?.(evt)\n autoResize()\n },\n [onChange, autoResize],\n )\n\n const handleAnimationStart = useCallback(\n (evt: React.AnimationEvent<HTMLInputElement>) => {\n onAnimationStart?.(evt)\n // Detect browser autofill\n if (evt.animationName === \"native-autofill-in\") {\n setHasValue(true)\n onAutofill?.()\n }\n },\n [onAnimationStart, onAutofill],\n )\n\n const handleRevealToggle = useCallback(() => {\n const next = !revealedRef.current\n revealedRef.current = next\n setRevealed(next)\n onRevealedChange?.(next)\n }, [onRevealedChange])\n\n return (\n <div\n className={clsx(s.Root, className)}\n data-label-placement={labelPlacement === \"inside\" ? \"inside\" : undefined}\n data-pill={pill && labelPlacement !== \"inside\" ? \"\" : undefined}\n >\n <div\n className={clsx(s.FieldFootprint, {\n [s.HasValue]: hasValue || !!startAdornment,\n })}\n data-focused={focused ? \"\" : undefined}\n data-has-value={hasValue ? \"\" : undefined}\n data-invalid={invalid ? \"\" : undefined}\n data-disabled={disabled ? \"\" : undefined}\n data-readonly={readOnly ? \"\" : undefined}\n data-multiline={multiline ? \"\" : undefined}\n onMouseDown={handleContainerMouseDown}\n >\n <label className={s.TypeableLabel} htmlFor={inputId}>\n <div className={s.LabelPositioner}>\n <div className={s.LabelText}>{label}</div>\n </div>\n </label>\n {startAdornment && (\n <div className={s.StartAdornment}>{startAdornment}</div>\n )}\n {multiline ? (\n <textarea\n {...(textareaProps(restProps) as React.TextareaHTMLAttributes<HTMLTextAreaElement>)}\n ref={mergeRefs([ref, inputRef]) as React.Ref<HTMLTextAreaElement>}\n id={inputId}\n name={name}\n rows={rows}\n className={s.Textarea}\n value={value}\n defaultValue={defaultValue}\n disabled={disabled}\n readOnly={readOnly}\n aria-invalid={ariaInvalid}\n aria-describedby={ariaDescribedBy}\n onChange={handleChange as unknown as React.ChangeEventHandler<HTMLTextAreaElement>}\n onFocus={handleFocus as unknown as React.FocusEventHandler<HTMLTextAreaElement>}\n onBlur={handleBlur as unknown as React.FocusEventHandler<HTMLTextAreaElement>}\n />\n ) : (\n <input\n {...restProps}\n ref={mergeRefs([ref, inputRef])}\n id={inputId}\n name={name}\n type={effectiveType}\n className={s.Input}\n value={value}\n defaultValue={defaultValue}\n disabled={disabled}\n readOnly={readOnly}\n aria-invalid={ariaInvalid}\n aria-describedby={ariaDescribedBy}\n onChange={handleChange}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onAnimationStart={handleAnimationStart}\n data-lpignore={allowAutofillExtensions ? undefined : true}\n data-1p-ignore={allowAutofillExtensions ? undefined : true}\n />\n )}\n {endAdornment && (\n <div className={s.EndAdornment}>\n {endAdornment}\n </div>\n )}\n {showClearButton && (\n <button\n type=\"button\"\n aria-label=\"Clear input\"\n className={s.ClearButton}\n onClick={handleClear}\n >\n <X className={s.ClearIcon} />\n <XCircleFilled className={s.ClearPhoneIcon} />\n </button>\n )}\n {showRevealButton && (\n <button\n type=\"button\"\n aria-label={revealed ? \"Hide\" : \"Show\"}\n className={s.RevealButton}\n onClick={handleRevealToggle}\n >\n {revealed ? <EyeOff /> : <Eye />}\n </button>\n )}\n </div>\n {errorMessage && (\n <FieldError id={errorId} className={s.ErrorMessage}>\n {errorMessage}\n </FieldError>\n )}\n {description && (\n <div id={descriptionId} className={s.Description}>\n {description}\n </div>\n )}\n </div>\n )\n },\n)\n\nFloatingLabelInput.displayName = \"FloatingLabelInput\"\n"]}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import clsx from "clsx";
|
|
4
|
-
import { forwardRef, useCallback, useId } from "react";
|
|
4
|
+
import { forwardRef, useCallback, useId, useRef } from "react";
|
|
5
|
+
import { mergeRefs } from "react-merge-refs";
|
|
5
6
|
import { Button } from "../Button/index.js";
|
|
6
7
|
import { Dropdown, X } from "../Icon/index.js";
|
|
8
|
+
import { FieldError } from "../FieldError/index.js";
|
|
7
9
|
import s from "@plexui/styles/components/FloatingLabelSelect/FloatingLabelSelect.module.css";
|
|
8
10
|
export const FloatingLabelSelect = forwardRef(function FloatingLabelSelect(props, ref) {
|
|
9
11
|
const { label, selected = false, errorMessage, "invalid": invalidProp, disabled = false, open = false, onInteract, onClearClick, labelPlacement = "border", pill = true, children, className, "aria-describedby": ariaDescribedByProp, onKeyDown, ...restProps } = props;
|
|
12
|
+
const fieldRef = useRef(null);
|
|
10
13
|
const generatedId = useId();
|
|
11
14
|
const errorId = `floating-label-select-${generatedId}-error`;
|
|
12
15
|
const invalid = invalidProp ?? !!errorMessage;
|
|
@@ -56,15 +59,17 @@ export const FloatingLabelSelect = forwardRef(function FloatingLabelSelect(props
|
|
|
56
59
|
const handleClearClick = useCallback((evt) => {
|
|
57
60
|
evt.stopPropagation();
|
|
58
61
|
evt.preventDefault();
|
|
62
|
+
if (disabled)
|
|
63
|
+
return;
|
|
64
|
+
// Keep focus in the field before its clear button disappears.
|
|
65
|
+
fieldRef.current?.focus({ preventScroll: true });
|
|
59
66
|
onClearClick?.();
|
|
60
|
-
}, [onClearClick]);
|
|
67
|
+
}, [disabled, onClearClick]);
|
|
61
68
|
return (_jsxs("div", { className: clsx(s.Root, className), "data-label-placement": labelPlacement === "inside" ? "inside" : undefined, "data-pill": pill && labelPlacement !== "inside" ? "" : undefined, children: [_jsxs("div", {
|
|
62
69
|
// The ref is the focusable field: a wrapping trigger returns focus to it and anchors to it
|
|
63
|
-
ref: ref, className: clsx(s.FieldFootprint, {
|
|
70
|
+
ref: mergeRefs([fieldRef, ref]), className: clsx(s.FieldFootprint, {
|
|
64
71
|
[s.HasValue]: selected,
|
|
65
|
-
}), role: "button", tabIndex: disabled ? -1 : 0, "data-open": open ? "" : undefined, "data-invalid": invalid ? "" : undefined, "data-disabled": disabled ? "" : undefined, "aria-expanded": open, "aria-haspopup": "listbox", "aria-
|
|
66
|
-
// Same plain line as FloatingLabelInput, so the two read alike on one form
|
|
67
|
-
_jsx("div", { id: errorId, className: s.ErrorMessage, role: "alert", children: errorMessage }))] }));
|
|
72
|
+
}), role: "button", tabIndex: disabled ? -1 : 0, "data-open": open ? "" : undefined, "data-invalid": invalid ? "" : undefined, "data-disabled": disabled ? "" : undefined, "aria-expanded": open, "aria-haspopup": "listbox", "aria-describedby": ariaDescribedBy, "aria-disabled": disabled || undefined, onPointerDown: handlePointerDown, onKeyDown: handleKeyDown, ...restProps, children: [_jsx("div", { className: s.TypeableLabel, children: _jsx("div", { className: s.LabelPositioner, children: _jsx("div", { className: s.LabelText, children: label }) }) }), _jsx("span", { className: s.Content, children: selected ? children : null }), _jsxs("div", { className: s.IndicatorWrapper, children: [showClearButton && (_jsx(Button, { "aria-label": "Clear selection", className: s.Clear, onPointerDown: handleClearPointerDown, onClick: handleClearClick, color: "secondary", variant: "ghost", size: "3xs", uniform: true, pill: true, children: _jsx(X, {}) })), _jsx(Dropdown, { className: s.DropdownIcon })] })] }), errorMessage && (_jsx(FieldError, { id: errorId, className: s.ErrorMessage, children: errorMessage }))] }));
|
|
68
73
|
});
|
|
69
74
|
FloatingLabelSelect.displayName = "FloatingLabelSelect";
|
|
70
75
|
//# sourceMappingURL=FloatingLabelSelect.js.map
|