@dloizides/ui-forms 1.54.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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import React40, { createContext, forwardRef, useRef, useImperativeHandle, useState, useCallback, useMemo, useEffect, useLayoutEffect, useContext } from 'react';
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 (!React40.isValidElement(child) || child.type === React40.Fragment) {
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: React40.cloneElement(element, injected), controlId };
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 = React40.createContext(null);
145
- var GapOwnedContext = React40.createContext(false);
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 React40.useContext(FormGridContext);
149
+ return React41.useContext(FormGridContext);
150
150
  }
151
151
  function useIsGapOwned() {
152
- return React40.useContext(GapOwnedContext);
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] = React40.useState(() => {
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 = React40.useMemo(
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 = React40.useMemo(() => ({ minWidth, basis }), [minWidth, basis]);
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] = React40.useState(() => {
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 = React40.useRef(null);
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 = React40.forwardRef(function ThemedTextInput2({
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] = React40.useState(false);
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 = React40.useRef([]);
1674
- const chipRef = React40.useCallback((index) => (node) => {
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 = React40.useMemo(() => buildChipColors(colors, palette), [colors, palette]);
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 = React40.useCallback(() => {
1918
+ const toggle2 = React41.useCallback(() => {
1919
1919
  if (!disabled) onValueChange(!value);
1920
1920
  }, [disabled, onValueChange, value]);
1921
- const boxColors = React40.useMemo(
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 = React40.useCallback(() => {
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 = React40.useMemo(() => {
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 };
@@ -2027,9 +2027,19 @@ var FormSwitch = ({
2027
2027
  disabled = false,
2028
2028
  ...props
2029
2029
  }) => variant === "box" ? /* @__PURE__ */ jsx(FormSwitchBox, { ...props, disabled, stateLabel, testID }) : /* @__PURE__ */ jsx(FormSwitchRow, { ...props, disabled, testID });
2030
-
2031
- // src/FormCheckbox/checkboxColors.ts
2032
2030
  var checkboxBoxColors = (colors, brand, checked) => checked ? { backgroundColor: brand, borderColor: brand } : { backgroundColor: "transparent", borderColor: colors.textSecondary };
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
+ }
2033
2043
  var ACTIVATION_KEYS = ["Enter", " ", "Spacebar"];
2034
2044
  var HINT_FONT_SIZE2 = 12;
2035
2045
  var BOX_SIZE = 20;
@@ -2056,6 +2066,11 @@ var styles17 = StyleSheet.create({
2056
2066
  centered: {
2057
2067
  alignItems: "center"
2058
2068
  },
2069
+ boxOnly: {
2070
+ minWidth: MIN_TOUCH_TARGET_PX,
2071
+ justifyContent: "center",
2072
+ marginBottom: 0
2073
+ },
2059
2074
  box: {
2060
2075
  width: BOX_SIZE,
2061
2076
  height: BOX_SIZE,
@@ -2105,22 +2120,25 @@ var FormCheckbox = ({
2105
2120
  containerStyle,
2106
2121
  testID = "form-checkbox",
2107
2122
  accessibilityLabel,
2108
- accessibilityHint
2123
+ accessibilityHint,
2124
+ labelHidden = false
2109
2125
  }) => {
2126
+ const lookBox = useCheckboxLookBox();
2110
2127
  const { theme } = useUi();
2111
2128
  const { colors, palette } = theme;
2112
2129
  const brand = palette.primary["500"];
2113
2130
  const hintText = typeof hint === "string" && hint !== "" ? hint : description;
2114
2131
  const hasHint = typeof hintText === "string" && hintText !== "";
2115
2132
  const { hintId } = useFieldIds();
2116
- const [focused, setFocused] = React40.useState(false);
2117
- const themeStyles = React40.useMemo(() => {
2133
+ const [focused, setFocused] = React41.useState(false);
2134
+ const themeStyles = React41.useMemo(() => {
2118
2135
  const boxOn = checkboxBoxColors(colors, brand, true);
2119
2136
  const boxOff = checkboxBoxColors(colors, brand, false);
2120
2137
  const ring = { borderColor: brand };
2138
+ const tick = { borderColor: checkboxTickColor(brand) };
2121
2139
  const labelStyle = { color: colors.text };
2122
2140
  const hintStyle = { color: colors.textSecondary };
2123
- return { boxOn, boxOff, ring, label: labelStyle, hint: hintStyle };
2141
+ return { boxOn, boxOff, ring, tick, label: labelStyle, hint: hintStyle };
2124
2142
  }, [brand, colors]);
2125
2143
  const toggle2 = () => {
2126
2144
  const next = !value;
@@ -2152,6 +2170,7 @@ var FormCheckbox = ({
2152
2170
  style: [
2153
2171
  styles17.container,
2154
2172
  hasHint ? null : styles17.centered,
2173
+ labelHidden ? styles17.boxOnly : null,
2155
2174
  containerStyle,
2156
2175
  disabled ? { opacity: DISABLED_OPACITY } : null,
2157
2176
  Platform.OS === "web" ? WEB_NO_DEFAULT_OUTLINE : null
@@ -2159,11 +2178,11 @@ var FormCheckbox = ({
2159
2178
  testID,
2160
2179
  ...keyboardProps,
2161
2180
  children: [
2162
- /* @__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: [
2163
2182
  focused ? /* @__PURE__ */ jsx(View, { pointerEvents: "none", style: [styles17.focusRing, themeStyles.ring], testID: `${testID}-focus-ring` }) : null,
2164
- value ? /* @__PURE__ */ jsx(View, { accessibilityElementsHidden: true, pointerEvents: "none", style: [styles17.tick, { borderColor: colors.surface }], testID: `${testID}-tick` }) : null
2183
+ value ? /* @__PURE__ */ jsx(View, { accessibilityElementsHidden: true, pointerEvents: "none", style: [styles17.tick, themeStyles.tick], testID: `${testID}-tick` }) : null
2165
2184
  ] }),
2166
- /* @__PURE__ */ jsxs(View, { style: styles17.textColumn, children: [
2185
+ labelHidden ? null : /* @__PURE__ */ jsxs(View, { style: styles17.textColumn, children: [
2167
2186
  /* @__PURE__ */ jsx(Text, { style: [styles17.label, themeStyles.label], children: label }),
2168
2187
  hasHint ? /* @__PURE__ */ jsx(Text, { nativeID: hintId, style: [styles17.hint, themeStyles.hint], children: hintText }) : null
2169
2188
  ] })
@@ -6044,7 +6063,7 @@ var styles38 = StyleSheet.create({
6044
6063
  function RadioList(props) {
6045
6064
  const { options, value, onChange, optionTestIDPrefix, label, error, required = false, disabled = false, testID } = props;
6046
6065
  const { theme } = useUi();
6047
- const colors = React40.useMemo(() => buildChipColors(theme.colors, theme.palette), [theme.colors, theme.palette]);
6066
+ const colors = React41.useMemo(() => buildChipColors(theme.colors, theme.palette), [theme.colors, theme.palette]);
6048
6067
  const selectedIndex = options.findIndex((option) => option.value === value);
6049
6068
  const radio = useRadioKeyboard({ enabled: true, disabled, values: options.map((option) => option.value), selectedIndex, onChange });
6050
6069
  return /* @__PURE__ */ jsx(Field, { error, label, required, testID, children: ({ describedById, hasError }) => /* @__PURE__ */ jsx(
@@ -6199,12 +6218,12 @@ var SubmitError = ({ message, testID }) => {
6199
6218
  };
6200
6219
  var toggle = (list, id) => list.includes(id) ? list.filter((item) => item !== id) : [...list, id];
6201
6220
  function useDecisionPanel(outcomes, onSubmit) {
6202
- const [outcome, setOutcome] = React40.useState("");
6203
- const [note, setNote] = React40.useState("");
6204
- const [reasons, setReasons] = React40.useState([]);
6205
- const [checked, setChecked] = React40.useState([]);
6206
- const [error, setError] = React40.useState(null);
6207
- const [pending, setPending] = React40.useState(null);
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);
6208
6227
  const submit = async (override) => {
6209
6228
  const target = override ?? outcome;
6210
6229
  const problem = validateDecision(outcomes, target, note);
@@ -6477,7 +6496,7 @@ function useCaretKeepingToggle(inputRef, initialLength) {
6477
6496
  }, [inputRef]);
6478
6497
  return { revealed, onPressIn, onToggle, onSelectionChange };
6479
6498
  }
6480
- var PasswordField = React40.forwardRef(function PasswordField2({ label, value, onChangeText, labels, testID, rules = NO_RULES, rulesDisplay = "meterGrid" /* MeterGrid */, flagUnmet = false, error, colors: colorOverride, inputProps }, ref) {
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) {
6481
6500
  const inputRef = useRef(null);
6482
6501
  useImperativeHandle(ref, () => inputRef.current);
6483
6502
  const toggle2 = useCaretKeepingToggle(inputRef, value.length);
@@ -6514,6 +6533,6 @@ var PasswordField = React40.forwardRef(function PasswordField2({ label, value, o
6514
6533
  ] }) });
6515
6534
  });
6516
6535
 
6517
- 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 };
6518
6537
  //# sourceMappingURL=index.mjs.map
6519
6538
  //# sourceMappingURL=index.mjs.map