@dloizides/ui-forms 1.26.0 → 1.28.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/CHANGELOG.md +14 -0
- package/dist/index.d.mts +43 -4
- package/dist/index.d.ts +43 -4
- package/dist/index.js +155 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +153 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -609,18 +609,23 @@ function readAnchorRect(ref) {
|
|
|
609
609
|
const r = node.getBoundingClientRect();
|
|
610
610
|
return { top: r.top, left: r.left, width: r.width, bottom: r.bottom };
|
|
611
611
|
}
|
|
612
|
-
function buildPortalPopoverStyle(rect, viewportBottom) {
|
|
612
|
+
function buildPortalPopoverStyle(rect, viewportBottom, viewportWidth) {
|
|
613
613
|
return {
|
|
614
614
|
...viewportBottom !== void 0 ? { maxHeight: menuMaxHeight(rect.bottom, viewportBottom) } : null,
|
|
615
615
|
// RN's ViewStyle union omits 'fixed', but react-native-web honours it at runtime.
|
|
616
616
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- web-only position value
|
|
617
617
|
position: "fixed",
|
|
618
618
|
top: rect.bottom + MENU_TOP_GAP2,
|
|
619
|
-
|
|
620
|
-
width: rect.width,
|
|
619
|
+
...horizontalPlacement(rect, viewportWidth),
|
|
621
620
|
zIndex: MENU_PORTAL_Z_INDEX
|
|
622
621
|
};
|
|
623
622
|
}
|
|
623
|
+
function horizontalPlacement(rect, viewportWidth) {
|
|
624
|
+
if (viewportWidth === void 0) return { left: rect.left, width: rect.width };
|
|
625
|
+
const width = Math.min(Math.max(rect.width, MENU_MIN_WIDTH), viewportWidth - 2 * VIEWPORT_MARGIN);
|
|
626
|
+
const left = Math.max(VIEWPORT_MARGIN, Math.min(rect.left, viewportWidth - VIEWPORT_MARGIN - width));
|
|
627
|
+
return { left, width };
|
|
628
|
+
}
|
|
624
629
|
function useAnchorRect(ref, enabled) {
|
|
625
630
|
const [rect, setRect] = useState(null);
|
|
626
631
|
useLayoutEffect(() => {
|
|
@@ -755,15 +760,16 @@ function AnchoredMenu({
|
|
|
755
760
|
testID,
|
|
756
761
|
anchorRef,
|
|
757
762
|
usePortal = true,
|
|
758
|
-
listbox
|
|
763
|
+
listbox,
|
|
764
|
+
placement
|
|
759
765
|
}) {
|
|
760
766
|
const menuRef = React2.useRef(null);
|
|
761
767
|
useDismiss(anchorRef, menuRef, onDismiss);
|
|
762
768
|
useKeepHighlightInView(testID, listbox?.highlightedValue);
|
|
763
|
-
const rect = useAnchorRect(anchorRef, usePortal);
|
|
769
|
+
const rect = useAnchorRect(placement?.positionRef ?? anchorRef, usePortal);
|
|
764
770
|
const viewportBottom = useVisualViewportBottom(usePortal);
|
|
765
|
-
const portalStyle = rect !== null ? buildPortalPopoverStyle(rect, viewportBottom ?? void 0) : null;
|
|
766
771
|
const { width: windowWidth } = useWindowDimensions();
|
|
772
|
+
const portalStyle = rect !== null ? buildPortalPopoverStyle(rect, viewportBottom ?? void 0, placement !== void 0 ? windowWidth : void 0) : null;
|
|
767
773
|
const menuWidth = rect?.width ?? windowWidth;
|
|
768
774
|
const isListbox = listbox !== void 0;
|
|
769
775
|
const statusText = listbox?.statusText;
|
|
@@ -1691,8 +1697,48 @@ var FormCheckbox = ({
|
|
|
1691
1697
|
}
|
|
1692
1698
|
);
|
|
1693
1699
|
};
|
|
1700
|
+
|
|
1701
|
+
// src/controls/nextHighlight.ts
|
|
1702
|
+
var NO_HIGHLIGHT = -1;
|
|
1703
|
+
function nextHighlight(current, count, delta) {
|
|
1704
|
+
if (count === 0) return NO_HIGHLIGHT;
|
|
1705
|
+
if (current === NO_HIGHLIGHT) return delta > 0 ? 0 : count - 1;
|
|
1706
|
+
return (current + delta + count) % count;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
// src/SelectControl/useSelectListbox.ts
|
|
1710
|
+
var FORWARD = 1;
|
|
1711
|
+
var BACKWARD = -1;
|
|
1712
|
+
function useSelectListbox({ options, isOpen, open, toggle, select }) {
|
|
1713
|
+
const [row, setRow] = useState(NO_HIGHLIGHT);
|
|
1714
|
+
const highlighted = isOpen ? options[row] : void 0;
|
|
1715
|
+
useEffect(() => {
|
|
1716
|
+
if (!isOpen) setRow(NO_HIGHLIGHT);
|
|
1717
|
+
}, [isOpen]);
|
|
1718
|
+
const onKeyDown = (event) => {
|
|
1719
|
+
const { key } = event;
|
|
1720
|
+
const isArrow = key === "ArrowDown" || key === "ArrowUp";
|
|
1721
|
+
if (!isArrow && key !== "Enter" && key !== " ") return;
|
|
1722
|
+
event.preventDefault();
|
|
1723
|
+
event.stopPropagation();
|
|
1724
|
+
if (isArrow) {
|
|
1725
|
+
open();
|
|
1726
|
+
setRow((current) => nextHighlight(current, options.length, key === "ArrowDown" ? FORWARD : BACKWARD));
|
|
1727
|
+
} else if (highlighted !== void 0) select(highlighted.value);
|
|
1728
|
+
else toggle();
|
|
1729
|
+
};
|
|
1730
|
+
return { highlighted, onKeyDown };
|
|
1731
|
+
}
|
|
1694
1732
|
var CHEVRON_DOWN = "\u25BE";
|
|
1695
1733
|
var CHEVRON_UP = "\u25B4";
|
|
1734
|
+
function listboxTriggerAria(testID, hasList, highlighted) {
|
|
1735
|
+
return {
|
|
1736
|
+
role: "combobox",
|
|
1737
|
+
"aria-haspopup": "listbox",
|
|
1738
|
+
"aria-controls": hasList ? listboxDomId(testID) : void 0,
|
|
1739
|
+
"aria-activedescendant": highlighted !== void 0 ? optionDomId(testID, highlighted.value) : void 0
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1696
1742
|
function SelectControl({
|
|
1697
1743
|
options,
|
|
1698
1744
|
value,
|
|
@@ -1702,6 +1748,7 @@ function SelectControl({
|
|
|
1702
1748
|
accessibilityHint,
|
|
1703
1749
|
labelledById,
|
|
1704
1750
|
optionHint = "",
|
|
1751
|
+
menuAnchor,
|
|
1705
1752
|
style,
|
|
1706
1753
|
testID
|
|
1707
1754
|
}) {
|
|
@@ -1716,6 +1763,9 @@ function SelectControl({
|
|
|
1716
1763
|
const close = useCallback(() => {
|
|
1717
1764
|
setIsOpen(false);
|
|
1718
1765
|
}, []);
|
|
1766
|
+
const open = useCallback(() => {
|
|
1767
|
+
setIsOpen(true);
|
|
1768
|
+
}, []);
|
|
1719
1769
|
const toggle = useCallback(() => {
|
|
1720
1770
|
setIsOpen((prev) => !prev);
|
|
1721
1771
|
}, []);
|
|
@@ -1726,16 +1776,22 @@ function SelectControl({
|
|
|
1726
1776
|
},
|
|
1727
1777
|
[onChange]
|
|
1728
1778
|
);
|
|
1729
|
-
|
|
1779
|
+
const listbox = useSelectListbox({ options, isOpen, open, toggle, select });
|
|
1780
|
+
const isListbox = menuAnchor !== void 0;
|
|
1781
|
+
const captureKeys = isListbox ? { onKeyDownCapture: listbox.onKeyDown } : {};
|
|
1782
|
+
const triggerAria = isListbox ? listboxTriggerAria(testID, isOpen && options.length > 0, listbox.highlighted) : {};
|
|
1783
|
+
return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: [controlStyles.anchor, style], ...captureKeys, children: [
|
|
1730
1784
|
/* @__PURE__ */ jsxs(
|
|
1731
1785
|
Pressable,
|
|
1732
1786
|
{
|
|
1733
|
-
|
|
1787
|
+
...triggerAria,
|
|
1788
|
+
accessibilityRole: isListbox ? void 0 : "button",
|
|
1734
1789
|
accessibilityLabel,
|
|
1735
1790
|
accessibilityHint,
|
|
1736
1791
|
accessibilityState: { expanded: isOpen },
|
|
1737
1792
|
"aria-expanded": isOpen,
|
|
1738
1793
|
"aria-labelledby": labelledById,
|
|
1794
|
+
onBlur: isListbox ? close : void 0,
|
|
1739
1795
|
onPress: toggle,
|
|
1740
1796
|
style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }],
|
|
1741
1797
|
testID: `${testID}-trigger`,
|
|
@@ -1752,10 +1808,13 @@ function SelectControl({
|
|
|
1752
1808
|
selectedValue: value,
|
|
1753
1809
|
onSelect: select,
|
|
1754
1810
|
onDismiss: close,
|
|
1755
|
-
colors: { text: colors.text, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
|
|
1811
|
+
colors: { text: colors.text, ...isListbox ? { textSecondary: colors.textSecondary } : null, border: colors.border, surface: colors.surface, brand: palette.primary["500"] },
|
|
1756
1812
|
optionHint,
|
|
1757
1813
|
testID,
|
|
1758
|
-
anchorRef
|
|
1814
|
+
anchorRef,
|
|
1815
|
+
accessibilityLabel: menuAnchor?.listboxLabel,
|
|
1816
|
+
listbox: isListbox ? { highlightedValue: listbox.highlighted?.value } : void 0,
|
|
1817
|
+
placement: isListbox ? { positionRef: menuAnchor.anchorRef } : void 0
|
|
1759
1818
|
}
|
|
1760
1819
|
) : null
|
|
1761
1820
|
] });
|
|
@@ -1863,15 +1922,9 @@ function useTypeaheadSearch(load, query, enabled, debounceMs) {
|
|
|
1863
1922
|
}
|
|
1864
1923
|
|
|
1865
1924
|
// src/TypeaheadControl/hooks/useTypeaheadState.ts
|
|
1866
|
-
var
|
|
1867
|
-
var
|
|
1868
|
-
var BACKWARD = -1;
|
|
1925
|
+
var FORWARD2 = 1;
|
|
1926
|
+
var BACKWARD2 = -1;
|
|
1869
1927
|
var NO_ROWS = [];
|
|
1870
|
-
function nextHighlight(current, count, delta) {
|
|
1871
|
-
if (count === 0) return NO_HIGHLIGHT;
|
|
1872
|
-
if (current === NO_HIGHLIGHT) return delta > 0 ? 0 : count - 1;
|
|
1873
|
-
return (current + delta + count) % count;
|
|
1874
|
-
}
|
|
1875
1928
|
function searchStatusText(found, search) {
|
|
1876
1929
|
if (found.hasFailed) return search.errorText;
|
|
1877
1930
|
if (found.results.length > 0) return void 0;
|
|
@@ -1953,7 +2006,7 @@ function useTypeaheadKeys(input) {
|
|
|
1953
2006
|
if (key === "ArrowDown" || key === "ArrowUp") {
|
|
1954
2007
|
event.preventDefault();
|
|
1955
2008
|
setIsOpen(true);
|
|
1956
|
-
setHighlightIndex((current) => nextHighlight(current, rowCount, key === "ArrowDown" ?
|
|
2009
|
+
setHighlightIndex((current) => nextHighlight(current, rowCount, key === "ArrowDown" ? FORWARD2 : BACKWARD2));
|
|
1957
2010
|
} else if (key === "Escape" && isOpen) {
|
|
1958
2011
|
event.preventDefault();
|
|
1959
2012
|
close();
|
|
@@ -2110,6 +2163,86 @@ function DateRangeControl({
|
|
|
2110
2163
|
)
|
|
2111
2164
|
] });
|
|
2112
2165
|
}
|
|
2166
|
+
var NATIVE_INPUT_BOX = {
|
|
2167
|
+
borderStyle: "solid",
|
|
2168
|
+
boxSizing: "border-box",
|
|
2169
|
+
fontFamily: "inherit",
|
|
2170
|
+
width: "100%"
|
|
2171
|
+
};
|
|
2172
|
+
function buildNativeInputStyle(themed) {
|
|
2173
|
+
const { paddingHorizontal, paddingVertical, ...box } = StyleSheet.flatten(controlStyles.input);
|
|
2174
|
+
return {
|
|
2175
|
+
...box,
|
|
2176
|
+
...themed,
|
|
2177
|
+
...NATIVE_INPUT_BOX,
|
|
2178
|
+
paddingBlock: paddingVertical,
|
|
2179
|
+
paddingInline: paddingHorizontal
|
|
2180
|
+
};
|
|
2181
|
+
}
|
|
2182
|
+
function WebDateInput({ fieldProps, context, webInputType }) {
|
|
2183
|
+
const { label, value, onChange, onSubmit, accessibilityHint, testID, required, disabled = false, min, max } = fieldProps;
|
|
2184
|
+
const { style, focusBind, hoverBind } = useThemedInput({ hasError: context.hasError, editable: !disabled });
|
|
2185
|
+
const webA11y = webFieldA11y({
|
|
2186
|
+
describedById: context.describedById,
|
|
2187
|
+
hasError: context.hasError,
|
|
2188
|
+
required
|
|
2189
|
+
});
|
|
2190
|
+
const handleChange = (event) => onChange(event.target.value);
|
|
2191
|
+
const handleKeyDown = (event) => {
|
|
2192
|
+
if (event.key !== "Enter" || onSubmit === void 0) return;
|
|
2193
|
+
event.preventDefault();
|
|
2194
|
+
onSubmit();
|
|
2195
|
+
};
|
|
2196
|
+
return /* @__PURE__ */ jsx(
|
|
2197
|
+
"input",
|
|
2198
|
+
{
|
|
2199
|
+
...webA11y,
|
|
2200
|
+
...hoverBind,
|
|
2201
|
+
...focusBind,
|
|
2202
|
+
"aria-label": label,
|
|
2203
|
+
"data-testid": testID,
|
|
2204
|
+
disabled,
|
|
2205
|
+
id: context.controlId,
|
|
2206
|
+
max,
|
|
2207
|
+
min,
|
|
2208
|
+
style: buildNativeInputStyle(style),
|
|
2209
|
+
title: accessibilityHint,
|
|
2210
|
+
type: webInputType,
|
|
2211
|
+
value,
|
|
2212
|
+
onChange: handleChange,
|
|
2213
|
+
onKeyDown: handleKeyDown
|
|
2214
|
+
}
|
|
2215
|
+
);
|
|
2216
|
+
}
|
|
2217
|
+
var IS_WEB7 = Platform.OS === "web";
|
|
2218
|
+
function renderNativeInput(fieldProps, context) {
|
|
2219
|
+
return /* @__PURE__ */ jsx(
|
|
2220
|
+
ThemedTextInput,
|
|
2221
|
+
{
|
|
2222
|
+
accessibilityHint: fieldProps.accessibilityHint,
|
|
2223
|
+
accessibilityLabel: fieldProps.label,
|
|
2224
|
+
describedById: context.describedById,
|
|
2225
|
+
editable: fieldProps.disabled !== true,
|
|
2226
|
+
hasError: context.hasError,
|
|
2227
|
+
id: context.controlId,
|
|
2228
|
+
requiredField: fieldProps.required,
|
|
2229
|
+
testID: fieldProps.testID,
|
|
2230
|
+
value: fieldProps.value,
|
|
2231
|
+
onChangeText: fieldProps.onChange,
|
|
2232
|
+
onSubmitEditing: fieldProps.onSubmit
|
|
2233
|
+
}
|
|
2234
|
+
);
|
|
2235
|
+
}
|
|
2236
|
+
function TemporalField({ fieldProps, webInputType }) {
|
|
2237
|
+
const { label, required, hint, error } = fieldProps;
|
|
2238
|
+
return /* @__PURE__ */ jsx(Field, { error, hint, label, required, children: (context) => IS_WEB7 ? /* @__PURE__ */ jsx(WebDateInput, { context, fieldProps, webInputType }) : renderNativeInput(fieldProps, context) });
|
|
2239
|
+
}
|
|
2240
|
+
function DateField(props) {
|
|
2241
|
+
return /* @__PURE__ */ jsx(TemporalField, { fieldProps: props, webInputType: "date" });
|
|
2242
|
+
}
|
|
2243
|
+
function DateTimeField(props) {
|
|
2244
|
+
return /* @__PURE__ */ jsx(TemporalField, { fieldProps: props, webInputType: "datetime-local" });
|
|
2245
|
+
}
|
|
2113
2246
|
|
|
2114
2247
|
// src/groupSelection/groupSelection.ts
|
|
2115
2248
|
var NONE = 0;
|
|
@@ -2350,6 +2483,6 @@ var UploadWithLinkField = ({
|
|
|
2350
2483
|
] });
|
|
2351
2484
|
};
|
|
2352
2485
|
|
|
2353
|
-
export { AlignToControl, AnchoredMenu, ChipSelector, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateRangeControl, Field, FormActions, FormCell, FormCheckbox, FormField, FormGrid, FormSection, FormStatusLine, FormSwitch, INLINE_FIELD_ROW_MIN_WIDTH, InlineFieldRow, SelectControl, SelectField, StepperNav, StepperTabs, ThemedTextInput, TypeaheadControl, UploadWithLinkField, controlStyles, groupAriaChecked, inlineFieldRowLayout, isUnmatched, resolveGroupSelection, resolveStepNeighbours, suggestOptions, toggleGroupSelection, useFocusFirstInvalid, useKeepInView, useRecentValues, useThemedInput };
|
|
2486
|
+
export { AlignToControl, AnchoredMenu, ChipSelector, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateField, DateRangeControl, DateTimeField, Field, FormActions, FormCell, FormCheckbox, FormField, FormGrid, FormSection, FormStatusLine, FormSwitch, INLINE_FIELD_ROW_MIN_WIDTH, InlineFieldRow, SelectControl, SelectField, StepperNav, StepperTabs, ThemedTextInput, TypeaheadControl, UploadWithLinkField, controlStyles, groupAriaChecked, inlineFieldRowLayout, isUnmatched, nextHighlight, resolveGroupSelection, resolveStepNeighbours, suggestOptions, toggleGroupSelection, useFocusFirstInvalid, useKeepInView, useRecentValues, useThemedInput };
|
|
2354
2487
|
//# sourceMappingURL=index.mjs.map
|
|
2355
2488
|
//# sourceMappingURL=index.mjs.map
|