@dloizides/ui-forms 1.55.0 → 1.56.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/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +238 -225
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React41, { createContext, forwardRef, useRef, useImperativeHandle, useState, useCallback, useMemo, useEffect, useLayoutEffect, useContext } from 'react';
|
|
2
2
|
import { Platform, StyleSheet, TextInput, View, Text, Pressable, useWindowDimensions, ScrollView, Animated, Easing, AccessibilityInfo, Image, TouchableOpacity, Switch, Modal } from 'react-native';
|
|
3
3
|
import { useUi } from '@dloizides/ui-feedback';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -12,7 +12,7 @@ import { parseFieldErrors } from '@dloizides/api-client-base';
|
|
|
12
12
|
|
|
13
13
|
// src/Field/Field.tsx
|
|
14
14
|
function attachControlId(child, candidateId, describedById) {
|
|
15
|
-
if (!
|
|
15
|
+
if (!React41.isValidElement(child) || child.type === React41.Fragment) {
|
|
16
16
|
return { node: child };
|
|
17
17
|
}
|
|
18
18
|
const props = child.props;
|
|
@@ -23,7 +23,7 @@ function attachControlId(child, candidateId, describedById) {
|
|
|
23
23
|
if (describedById !== void 0 && props.describedById === void 0) {
|
|
24
24
|
injected.describedById = describedById;
|
|
25
25
|
}
|
|
26
|
-
return { node:
|
|
26
|
+
return { node: React41.cloneElement(element, injected), controlId };
|
|
27
27
|
}
|
|
28
28
|
var IS_WEB = Platform.OS === "web";
|
|
29
29
|
function isAttributeHost(node) {
|
|
@@ -141,15 +141,15 @@ var labelVariantStyles = StyleSheet.create({
|
|
|
141
141
|
function resolveLabelVariantStyle(variant) {
|
|
142
142
|
return labelVariantStyles[variant ?? "field"] ?? labelVariantStyles.field;
|
|
143
143
|
}
|
|
144
|
-
var FormGridContext =
|
|
145
|
-
var GapOwnedContext =
|
|
144
|
+
var FormGridContext = React41.createContext(null);
|
|
145
|
+
var GapOwnedContext = React41.createContext(false);
|
|
146
146
|
var FormGridProvider = FormGridContext.Provider;
|
|
147
147
|
var GapOwnedProvider = GapOwnedContext.Provider;
|
|
148
148
|
function useFormGridMetrics() {
|
|
149
|
-
return
|
|
149
|
+
return React41.useContext(FormGridContext);
|
|
150
150
|
}
|
|
151
151
|
function useIsGapOwned() {
|
|
152
|
-
return
|
|
152
|
+
return React41.useContext(GapOwnedContext);
|
|
153
153
|
}
|
|
154
154
|
var ERROR_LIGHT_STEPS = ["500", "600", "700"];
|
|
155
155
|
var ERROR_DARK_STEPS = ["300", "200", "400", "100", "500"];
|
|
@@ -172,7 +172,7 @@ var styles = StyleSheet.create({
|
|
|
172
172
|
});
|
|
173
173
|
var fieldSeq = 0;
|
|
174
174
|
function useFieldIds() {
|
|
175
|
-
const [ids] =
|
|
175
|
+
const [ids] = React41.useState(() => {
|
|
176
176
|
fieldSeq += 1;
|
|
177
177
|
const seq = String(fieldSeq);
|
|
178
178
|
return {
|
|
@@ -219,7 +219,7 @@ var Field = ({
|
|
|
219
219
|
const hasLabel = labelText !== "";
|
|
220
220
|
const marker = resolveFieldMarker(required, optional);
|
|
221
221
|
const { hintId, errorId, controlId, labelId } = useFieldIds();
|
|
222
|
-
const themeStyles =
|
|
222
|
+
const themeStyles = React41.useMemo(
|
|
223
223
|
() => ({
|
|
224
224
|
label: { color: colors.textSecondary },
|
|
225
225
|
requiredMark: { color: errorColor },
|
|
@@ -271,7 +271,7 @@ var FormGrid = ({
|
|
|
271
271
|
style,
|
|
272
272
|
testID
|
|
273
273
|
}) => {
|
|
274
|
-
const metrics =
|
|
274
|
+
const metrics = React41.useMemo(() => ({ minWidth, basis }), [minWidth, basis]);
|
|
275
275
|
return /* @__PURE__ */ jsx(FormGridProvider, { value: metrics, children: /* @__PURE__ */ jsx(GapOwnedProvider, { value: true, children: /* @__PURE__ */ jsx(View, { style: [styles2.grid, { gap }, style], testID, children }) }) });
|
|
276
276
|
};
|
|
277
277
|
var LABEL_LINE_PLACEHOLDER = "\xA0";
|
|
@@ -538,7 +538,7 @@ var styles9 = StyleSheet.create({
|
|
|
538
538
|
});
|
|
539
539
|
var sectionSeq = 0;
|
|
540
540
|
function useSectionLegendId() {
|
|
541
|
-
const [id] =
|
|
541
|
+
const [id] = React41.useState(() => {
|
|
542
542
|
sectionSeq += 1;
|
|
543
543
|
return `form-section-legend-${String(sectionSeq)}`;
|
|
544
544
|
});
|
|
@@ -932,7 +932,7 @@ function AnchoredMenu({
|
|
|
932
932
|
listbox,
|
|
933
933
|
placement
|
|
934
934
|
}) {
|
|
935
|
-
const menuRef =
|
|
935
|
+
const menuRef = React41.useRef(null);
|
|
936
936
|
useDismiss(anchorRef, menuRef, onDismiss);
|
|
937
937
|
useKeepHighlightInView(testID, listbox?.highlightedValue);
|
|
938
938
|
const rect2 = useAnchorRect(placement?.positionRef ?? anchorRef, usePortal);
|
|
@@ -1092,7 +1092,7 @@ var boxStyles = StyleSheet.create({
|
|
|
1092
1092
|
textAlignVertical: "top"
|
|
1093
1093
|
}
|
|
1094
1094
|
});
|
|
1095
|
-
var ThemedTextInput =
|
|
1095
|
+
var ThemedTextInput = React41.forwardRef(function ThemedTextInput2({
|
|
1096
1096
|
hasError = false,
|
|
1097
1097
|
describedById,
|
|
1098
1098
|
requiredField = false,
|
|
@@ -1554,7 +1554,7 @@ function ChipContent(props) {
|
|
|
1554
1554
|
}
|
|
1555
1555
|
function OutlineChip(props) {
|
|
1556
1556
|
const { option, selected, disabled, colors, testID, accessibilityHint, onPress } = props;
|
|
1557
|
-
const [hovered, setHovered] =
|
|
1557
|
+
const [hovered, setHovered] = React41.useState(false);
|
|
1558
1558
|
const active = selected || hovered;
|
|
1559
1559
|
const borderColor = active ? colors.primary : restBorderColor(colors, props.outlineTone);
|
|
1560
1560
|
const fill = chipFill({
|
|
@@ -1670,8 +1670,8 @@ function radioTabIndex(index, selectedIndex, disabled) {
|
|
|
1670
1670
|
var NO_GROUP_PROPS = {};
|
|
1671
1671
|
function useRadioKeyboard(config) {
|
|
1672
1672
|
const { enabled, disabled, values, selectedIndex, onChange } = config;
|
|
1673
|
-
const nodes =
|
|
1674
|
-
const chipRef =
|
|
1673
|
+
const nodes = React41.useRef([]);
|
|
1674
|
+
const chipRef = React41.useCallback((index) => (node) => {
|
|
1675
1675
|
nodes.current[index] = node;
|
|
1676
1676
|
}, []);
|
|
1677
1677
|
const onKeyDown = (event) => {
|
|
@@ -1790,7 +1790,7 @@ var ChipSelector = ({
|
|
|
1790
1790
|
const isRadioGroup = !multiple && singleSelectRole === "radio";
|
|
1791
1791
|
const { theme } = useUi();
|
|
1792
1792
|
const { colors, palette } = theme;
|
|
1793
|
-
const chipColors =
|
|
1793
|
+
const chipColors = React41.useMemo(() => buildChipColors(colors, palette), [colors, palette]);
|
|
1794
1794
|
function isSelected(optionValue) {
|
|
1795
1795
|
if (multiple && Array.isArray(value))
|
|
1796
1796
|
return value.includes(optionValue);
|
|
@@ -1915,10 +1915,10 @@ var FormSwitchBox = ({
|
|
|
1915
1915
|
}) => {
|
|
1916
1916
|
const { colors } = useUi().theme;
|
|
1917
1917
|
const { disabled, onValueChange, value } = slot;
|
|
1918
|
-
const toggle2 =
|
|
1918
|
+
const toggle2 = React41.useCallback(() => {
|
|
1919
1919
|
if (!disabled) onValueChange(!value);
|
|
1920
1920
|
}, [disabled, onValueChange, value]);
|
|
1921
|
-
const boxColors =
|
|
1921
|
+
const boxColors = React41.useMemo(
|
|
1922
1922
|
() => ({ borderColor: colors.border, backgroundColor: colors.surface }),
|
|
1923
1923
|
[colors.border, colors.surface]
|
|
1924
1924
|
);
|
|
@@ -1972,12 +1972,12 @@ var FormSwitchRow = ({
|
|
|
1972
1972
|
activeTrackColor
|
|
1973
1973
|
}) => {
|
|
1974
1974
|
const { theme } = useUi();
|
|
1975
|
-
const toggle2 =
|
|
1975
|
+
const toggle2 = React41.useCallback(() => {
|
|
1976
1976
|
if (!disabled) onValueChange(!value);
|
|
1977
1977
|
}, [disabled, onValueChange, value]);
|
|
1978
1978
|
const { colors } = theme;
|
|
1979
1979
|
const hasDescription = typeof description === "string" && description !== "";
|
|
1980
|
-
const themeStyles =
|
|
1980
|
+
const themeStyles = React41.useMemo(() => {
|
|
1981
1981
|
const labelStyle = { color: colors.text };
|
|
1982
1982
|
const descriptionStyle = { color: colors.textSecondary };
|
|
1983
1983
|
return { label: labelStyle, description: descriptionStyle };
|
|
@@ -2029,6 +2029,17 @@ var FormSwitch = ({
|
|
|
2029
2029
|
}) => variant === "box" ? /* @__PURE__ */ jsx(FormSwitchBox, { ...props, disabled, stateLabel, testID }) : /* @__PURE__ */ jsx(FormSwitchRow, { ...props, disabled, testID });
|
|
2030
2030
|
var checkboxBoxColors = (colors, brand, checked) => checked ? { backgroundColor: brand, borderColor: brand } : { backgroundColor: "transparent", borderColor: colors.textSecondary };
|
|
2031
2031
|
var checkboxTickColor = (brand) => resolveOnBrand(brand);
|
|
2032
|
+
var COMPACT_BOX = { width: 16, height: 16, borderRadius: 4, borderWidth: 1.5 };
|
|
2033
|
+
var CheckboxLookContext = createContext("default");
|
|
2034
|
+
function CheckboxLookProvider({ look, children }) {
|
|
2035
|
+
return /* @__PURE__ */ jsx(CheckboxLookContext.Provider, { value: look, children });
|
|
2036
|
+
}
|
|
2037
|
+
function checkboxLookBox(look) {
|
|
2038
|
+
return look === "compact" ? COMPACT_BOX : void 0;
|
|
2039
|
+
}
|
|
2040
|
+
function useCheckboxLookBox() {
|
|
2041
|
+
return checkboxLookBox(useContext(CheckboxLookContext));
|
|
2042
|
+
}
|
|
2032
2043
|
var ACTIVATION_KEYS = ["Enter", " ", "Spacebar"];
|
|
2033
2044
|
var HINT_FONT_SIZE2 = 12;
|
|
2034
2045
|
var BOX_SIZE = 20;
|
|
@@ -2112,14 +2123,15 @@ var FormCheckbox = ({
|
|
|
2112
2123
|
accessibilityHint,
|
|
2113
2124
|
labelHidden = false
|
|
2114
2125
|
}) => {
|
|
2126
|
+
const lookBox = useCheckboxLookBox();
|
|
2115
2127
|
const { theme } = useUi();
|
|
2116
2128
|
const { colors, palette } = theme;
|
|
2117
2129
|
const brand = palette.primary["500"];
|
|
2118
2130
|
const hintText = typeof hint === "string" && hint !== "" ? hint : description;
|
|
2119
2131
|
const hasHint = typeof hintText === "string" && hintText !== "";
|
|
2120
2132
|
const { hintId } = useFieldIds();
|
|
2121
|
-
const [focused, setFocused] =
|
|
2122
|
-
const themeStyles =
|
|
2133
|
+
const [focused, setFocused] = React41.useState(false);
|
|
2134
|
+
const themeStyles = React41.useMemo(() => {
|
|
2123
2135
|
const boxOn = checkboxBoxColors(colors, brand, true);
|
|
2124
2136
|
const boxOff = checkboxBoxColors(colors, brand, false);
|
|
2125
2137
|
const ring = { borderColor: brand };
|
|
@@ -2166,7 +2178,7 @@ var FormCheckbox = ({
|
|
|
2166
2178
|
testID,
|
|
2167
2179
|
...keyboardProps,
|
|
2168
2180
|
children: [
|
|
2169
|
-
/* @__PURE__ */ jsxs(View, { style: [styles17.box, value ? themeStyles.boxOn : themeStyles.boxOff], testID: `${testID}-box`, children: [
|
|
2181
|
+
/* @__PURE__ */ jsxs(View, { style: [styles17.box, lookBox, value ? themeStyles.boxOn : themeStyles.boxOff], testID: `${testID}-box`, children: [
|
|
2170
2182
|
focused ? /* @__PURE__ */ jsx(View, { pointerEvents: "none", style: [styles17.focusRing, themeStyles.ring], testID: `${testID}-focus-ring` }) : null,
|
|
2171
2183
|
value ? /* @__PURE__ */ jsx(View, { accessibilityElementsHidden: true, pointerEvents: "none", style: [styles17.tick, themeStyles.tick], testID: `${testID}-tick` }) : null
|
|
2172
2184
|
] }),
|
|
@@ -6051,7 +6063,7 @@ var styles38 = StyleSheet.create({
|
|
|
6051
6063
|
function RadioList(props) {
|
|
6052
6064
|
const { options, value, onChange, optionTestIDPrefix, label, error, required = false, disabled = false, testID } = props;
|
|
6053
6065
|
const { theme } = useUi();
|
|
6054
|
-
const colors =
|
|
6066
|
+
const colors = React41.useMemo(() => buildChipColors(theme.colors, theme.palette), [theme.colors, theme.palette]);
|
|
6055
6067
|
const selectedIndex = options.findIndex((option) => option.value === value);
|
|
6056
6068
|
const radio = useRadioKeyboard({ enabled: true, disabled, values: options.map((option) => option.value), selectedIndex, onChange });
|
|
6057
6069
|
return /* @__PURE__ */ jsx(Field, { error, label, required, testID, children: ({ describedById, hasError }) => /* @__PURE__ */ jsx(
|
|
@@ -6206,12 +6218,12 @@ var SubmitError = ({ message, testID }) => {
|
|
|
6206
6218
|
};
|
|
6207
6219
|
var toggle = (list, id) => list.includes(id) ? list.filter((item) => item !== id) : [...list, id];
|
|
6208
6220
|
function useDecisionPanel(outcomes, onSubmit) {
|
|
6209
|
-
const [outcome, setOutcome] =
|
|
6210
|
-
const [note, setNote] =
|
|
6211
|
-
const [reasons, setReasons] =
|
|
6212
|
-
const [checked, setChecked] =
|
|
6213
|
-
const [error, setError] =
|
|
6214
|
-
const [pending, setPending] =
|
|
6221
|
+
const [outcome, setOutcome] = React41.useState("");
|
|
6222
|
+
const [note, setNote] = React41.useState("");
|
|
6223
|
+
const [reasons, setReasons] = React41.useState([]);
|
|
6224
|
+
const [checked, setChecked] = React41.useState([]);
|
|
6225
|
+
const [error, setError] = React41.useState(null);
|
|
6226
|
+
const [pending, setPending] = React41.useState(null);
|
|
6215
6227
|
const submit = async (override) => {
|
|
6216
6228
|
const target = override ?? outcome;
|
|
6217
6229
|
const problem = validateDecision(outcomes, target, note);
|
|
@@ -6484,7 +6496,7 @@ function useCaretKeepingToggle(inputRef, initialLength) {
|
|
|
6484
6496
|
}, [inputRef]);
|
|
6485
6497
|
return { revealed, onPressIn, onToggle, onSelectionChange };
|
|
6486
6498
|
}
|
|
6487
|
-
var PasswordField =
|
|
6499
|
+
var PasswordField = React41.forwardRef(function PasswordField2({ label, value, onChangeText, labels, testID, rules = NO_RULES, rulesDisplay = "meterGrid" /* MeterGrid */, flagUnmet = false, error, colors: colorOverride, inputProps }, ref) {
|
|
6488
6500
|
const inputRef = useRef(null);
|
|
6489
6501
|
useImperativeHandle(ref, () => inputRef.current);
|
|
6490
6502
|
const toggle2 = useCaretKeepingToggle(inputRef, value.length);
|
|
@@ -6521,6 +6533,6 @@ var PasswordField = React40.forwardRef(function PasswordField2({ label, value, o
|
|
|
6521
6533
|
] }) });
|
|
6522
6534
|
});
|
|
6523
6535
|
|
|
6524
|
-
export { ActionBar, AddOnRequest, AlignToControl, AnchoredMenu, BicInput, BicRejection, COUNTRIES, ChipLabelWrap, ChipSelector, CountryField, CountryFlag, DEFAULT_DATE_PICKER_LABELS, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateDisplay, DateField, DateInput, DatePickerProvider, DateRangeControl, DateTimeField, DecisionPanel, DropdownPlacement, FLAG_HEIGHT, FLAG_WIDTH, Field, FileInput, FixBar, FlagShapeKind, FormActions, FormCell, FormCheckbox, FormField, FormGrid, FormSection, FormStack, FormStatusLine, FormSwitch, GatedChecklist, IBAN_MAX_LENGTH, IBAN_REGISTERED_COUNTRY_COUNT, INLINE_FIELD_ROW_MIN_WIDTH, IbanInput, IbanRejection, InlineFieldRow, LINE_ITEMS_WIDE_MIN_WIDTH, LineItems, MultiSelectField, PHONE_MAX_WIDTH, PasswordField, PasswordRules, PasswordRulesDisplay, RESPONSIVE_FORM_DEFAULT_BREAKPOINT, RadioList, ResponsiveFormLayout, RevealToggle, RuleTone, SEGMENT_BESIDE_FIELD, SEGMENT_BESIDE_TEXT_INPUT, SearchSelect, SelectControl, SelectField, SelectLookProvider, SelectSurface, StepperNav, StepperTabs, ThemedTextInput, TypeaheadControl, UploadWithLinkField, actionBarPosition, assignServerErrors, buildSearchSelectSections, canRemoveLine, changedRules, controlStyles, countryFieldOptions, countryFlag, countryOptions, defaultDecisionVariant, draftBic, draftIban, dropdownFrame, findOption, fitDropdownWidth, flagShapes, groupAriaChecked, groupInFours, highlightAfterQuery, ibanCounter, ibanLengthFor, inlineFieldRowLayout, isAddOnOpen, isChecklistComplete, isFallbackFlag, isFixBarVisible, isLineItemsWide, isOutside, isUnmatched, isWideFormLayout, leadFirst, lineItemColumnFlex, lineNumberOf, moveHighlight, nextHighlight, placeDropdown, radioRowIdentity, rejectionMessage, resolveGroupSelection, resolveSelectMotion, resolveStepNeighbours, rowsForText, ruleAnnouncement, ruleColorsFrom, ruleTone, selectLookMetrics, suggestOptions, toCountryValue, toggleGroupSelection, useAutoGrowRows, useBlurVerdict, useDeferredFocus, useFocusFirstInvalid, useKeepInView, useOutsidePress, useRecentValues, useReducedMotion, useSearchSelectState, useServerFieldErrors, useThemedInput, validateBic, validateDecision, validateIban };
|
|
6536
|
+
export { ActionBar, AddOnRequest, AlignToControl, AnchoredMenu, BicInput, BicRejection, COUNTRIES, CheckboxLookProvider, ChipLabelWrap, ChipSelector, CountryField, CountryFlag, DEFAULT_DATE_PICKER_LABELS, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateDisplay, DateField, DateInput, DatePickerProvider, DateRangeControl, DateTimeField, DecisionPanel, DropdownPlacement, FLAG_HEIGHT, FLAG_WIDTH, Field, FileInput, FixBar, FlagShapeKind, FormActions, FormCell, FormCheckbox, FormField, FormGrid, FormSection, FormStack, FormStatusLine, FormSwitch, GatedChecklist, IBAN_MAX_LENGTH, IBAN_REGISTERED_COUNTRY_COUNT, INLINE_FIELD_ROW_MIN_WIDTH, IbanInput, IbanRejection, InlineFieldRow, LINE_ITEMS_WIDE_MIN_WIDTH, LineItems, MultiSelectField, PHONE_MAX_WIDTH, PasswordField, PasswordRules, PasswordRulesDisplay, RESPONSIVE_FORM_DEFAULT_BREAKPOINT, RadioList, ResponsiveFormLayout, RevealToggle, RuleTone, SEGMENT_BESIDE_FIELD, SEGMENT_BESIDE_TEXT_INPUT, SearchSelect, SelectControl, SelectField, SelectLookProvider, SelectSurface, StepperNav, StepperTabs, ThemedTextInput, TypeaheadControl, UploadWithLinkField, actionBarPosition, assignServerErrors, buildSearchSelectSections, canRemoveLine, changedRules, controlStyles, countryFieldOptions, countryFlag, countryOptions, defaultDecisionVariant, draftBic, draftIban, dropdownFrame, findOption, fitDropdownWidth, flagShapes, groupAriaChecked, groupInFours, highlightAfterQuery, ibanCounter, ibanLengthFor, inlineFieldRowLayout, isAddOnOpen, isChecklistComplete, isFallbackFlag, isFixBarVisible, isLineItemsWide, isOutside, isUnmatched, isWideFormLayout, leadFirst, lineItemColumnFlex, lineNumberOf, moveHighlight, nextHighlight, placeDropdown, radioRowIdentity, rejectionMessage, resolveGroupSelection, resolveSelectMotion, resolveStepNeighbours, rowsForText, ruleAnnouncement, ruleColorsFrom, ruleTone, selectLookMetrics, suggestOptions, toCountryValue, toggleGroupSelection, useAutoGrowRows, useBlurVerdict, useDeferredFocus, useFocusFirstInvalid, useKeepInView, useOutsidePress, useRecentValues, useReducedMotion, useSearchSelectState, useServerFieldErrors, useThemedInput, validateBic, validateDecision, validateIban };
|
|
6525
6537
|
//# sourceMappingURL=index.mjs.map
|
|
6526
6538
|
//# sourceMappingURL=index.mjs.map
|