@dloizides/ui-forms 1.39.1 → 1.41.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 +7 -0
- package/dist/index.d.mts +122 -1
- package/dist/index.d.ts +122 -1
- package/dist/index.js +497 -151
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +369 -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 React26, { forwardRef, useState, useCallback, useMemo, useRef, useEffect, useLayoutEffect } from 'react';
|
|
2
2
|
import { Platform, StyleSheet, TextInput, View, Text, useWindowDimensions, ScrollView, Pressable, Switch, Image, AccessibilityInfo, Animated, TouchableOpacity, Modal } from 'react-native';
|
|
3
3
|
import { useUi } from '@dloizides/ui-feedback';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -10,7 +10,7 @@ import Svg, { Rect, Circle, Polygon } from 'react-native-svg';
|
|
|
10
10
|
|
|
11
11
|
// src/Field/Field.tsx
|
|
12
12
|
function attachControlId(child, candidateId, describedById) {
|
|
13
|
-
if (!
|
|
13
|
+
if (!React26.isValidElement(child) || child.type === React26.Fragment) {
|
|
14
14
|
return { node: child };
|
|
15
15
|
}
|
|
16
16
|
const props = child.props;
|
|
@@ -21,7 +21,7 @@ function attachControlId(child, candidateId, describedById) {
|
|
|
21
21
|
if (describedById !== void 0 && props.describedById === void 0) {
|
|
22
22
|
injected.describedById = describedById;
|
|
23
23
|
}
|
|
24
|
-
return { node:
|
|
24
|
+
return { node: React26.cloneElement(element, injected), controlId };
|
|
25
25
|
}
|
|
26
26
|
var IS_WEB = Platform.OS === "web";
|
|
27
27
|
function isAttributeHost(node) {
|
|
@@ -131,15 +131,15 @@ var labelVariantStyles = StyleSheet.create({
|
|
|
131
131
|
function resolveLabelVariantStyle(variant) {
|
|
132
132
|
return variant === "control" ? labelVariantStyles.control : labelVariantStyles.field;
|
|
133
133
|
}
|
|
134
|
-
var FormGridContext =
|
|
135
|
-
var GapOwnedContext =
|
|
134
|
+
var FormGridContext = React26.createContext(null);
|
|
135
|
+
var GapOwnedContext = React26.createContext(false);
|
|
136
136
|
var FormGridProvider = FormGridContext.Provider;
|
|
137
137
|
var GapOwnedProvider = GapOwnedContext.Provider;
|
|
138
138
|
function useFormGridMetrics() {
|
|
139
|
-
return
|
|
139
|
+
return React26.useContext(FormGridContext);
|
|
140
140
|
}
|
|
141
141
|
function useIsGapOwned() {
|
|
142
|
-
return
|
|
142
|
+
return React26.useContext(GapOwnedContext);
|
|
143
143
|
}
|
|
144
144
|
var ERROR_LIGHT_STEPS = ["500", "600", "700"];
|
|
145
145
|
var ERROR_DARK_STEPS = ["300", "200", "400", "100", "500"];
|
|
@@ -162,7 +162,7 @@ var styles = StyleSheet.create({
|
|
|
162
162
|
});
|
|
163
163
|
var fieldSeq = 0;
|
|
164
164
|
function useFieldIds() {
|
|
165
|
-
const [ids] =
|
|
165
|
+
const [ids] = React26.useState(() => {
|
|
166
166
|
fieldSeq += 1;
|
|
167
167
|
const seq = String(fieldSeq);
|
|
168
168
|
return {
|
|
@@ -209,7 +209,7 @@ var Field = ({
|
|
|
209
209
|
const hasLabel = labelText !== "";
|
|
210
210
|
const marker = resolveFieldMarker(required, optional);
|
|
211
211
|
const { hintId, errorId, controlId, labelId } = useFieldIds();
|
|
212
|
-
const themeStyles =
|
|
212
|
+
const themeStyles = React26.useMemo(
|
|
213
213
|
() => ({
|
|
214
214
|
label: { color: colors.textSecondary },
|
|
215
215
|
requiredMark: { color: errorColor },
|
|
@@ -261,7 +261,7 @@ var FormGrid = ({
|
|
|
261
261
|
style,
|
|
262
262
|
testID
|
|
263
263
|
}) => {
|
|
264
|
-
const metrics =
|
|
264
|
+
const metrics = React26.useMemo(() => ({ minWidth, basis }), [minWidth, basis]);
|
|
265
265
|
return /* @__PURE__ */ jsx(FormGridProvider, { value: metrics, children: /* @__PURE__ */ jsx(GapOwnedProvider, { value: true, children: /* @__PURE__ */ jsx(View, { style: [styles2.grid, { gap }, style], testID, children }) }) });
|
|
266
266
|
};
|
|
267
267
|
var LABEL_LINE_PLACEHOLDER = "\xA0";
|
|
@@ -528,7 +528,7 @@ var styles9 = StyleSheet.create({
|
|
|
528
528
|
});
|
|
529
529
|
var sectionSeq = 0;
|
|
530
530
|
function useSectionLegendId() {
|
|
531
|
-
const [id] =
|
|
531
|
+
const [id] = React26.useState(() => {
|
|
532
532
|
sectionSeq += 1;
|
|
533
533
|
return `form-section-legend-${String(sectionSeq)}`;
|
|
534
534
|
});
|
|
@@ -922,7 +922,7 @@ function AnchoredMenu({
|
|
|
922
922
|
listbox,
|
|
923
923
|
placement
|
|
924
924
|
}) {
|
|
925
|
-
const menuRef =
|
|
925
|
+
const menuRef = React26.useRef(null);
|
|
926
926
|
useDismiss(anchorRef, menuRef, onDismiss);
|
|
927
927
|
useKeepHighlightInView(testID, listbox?.highlightedValue);
|
|
928
928
|
const rect2 = useAnchorRect(placement?.positionRef ?? anchorRef, usePortal);
|
|
@@ -1082,7 +1082,7 @@ var boxStyles = StyleSheet.create({
|
|
|
1082
1082
|
textAlignVertical: "top"
|
|
1083
1083
|
}
|
|
1084
1084
|
});
|
|
1085
|
-
var ThemedTextInput =
|
|
1085
|
+
var ThemedTextInput = React26.forwardRef(function ThemedTextInput2({
|
|
1086
1086
|
hasError = false,
|
|
1087
1087
|
describedById,
|
|
1088
1088
|
requiredField = false,
|
|
@@ -1392,7 +1392,7 @@ function ChipContent({ icon, label, textStyle, numberOfLines }) {
|
|
|
1392
1392
|
}
|
|
1393
1393
|
function OutlineChip(props) {
|
|
1394
1394
|
const { option, selected, disabled, colors, testID, accessibilityHint, onPress } = props;
|
|
1395
|
-
const [hovered, setHovered] =
|
|
1395
|
+
const [hovered, setHovered] = React26.useState(false);
|
|
1396
1396
|
const active = selected || hovered;
|
|
1397
1397
|
const borderColor = active ? colors.primary : colors.border;
|
|
1398
1398
|
const backgroundColor = selected ? colors.tint : colors.muted;
|
|
@@ -1492,8 +1492,8 @@ function radioTabIndex(index, selectedIndex, disabled) {
|
|
|
1492
1492
|
var NO_GROUP_PROPS = {};
|
|
1493
1493
|
function useRadioKeyboard(config) {
|
|
1494
1494
|
const { enabled, disabled, values, selectedIndex, onChange } = config;
|
|
1495
|
-
const nodes =
|
|
1496
|
-
const chipRef =
|
|
1495
|
+
const nodes = React26.useRef([]);
|
|
1496
|
+
const chipRef = React26.useCallback((index) => (node) => {
|
|
1497
1497
|
nodes.current[index] = node;
|
|
1498
1498
|
}, []);
|
|
1499
1499
|
const onKeyDown = (event) => {
|
|
@@ -1606,7 +1606,7 @@ var ChipSelector = ({
|
|
|
1606
1606
|
const isRadioGroup = !multiple && singleSelectRole === "radio";
|
|
1607
1607
|
const { theme } = useUi();
|
|
1608
1608
|
const { colors, palette } = theme;
|
|
1609
|
-
const chipColors =
|
|
1609
|
+
const chipColors = React26.useMemo(() => buildChipColors(colors, palette), [colors, palette]);
|
|
1610
1610
|
function isSelected(optionValue) {
|
|
1611
1611
|
if (multiple && Array.isArray(value))
|
|
1612
1612
|
return value.includes(optionValue);
|
|
@@ -1702,12 +1702,12 @@ var FormSwitch = ({
|
|
|
1702
1702
|
accessibilityHint
|
|
1703
1703
|
}) => {
|
|
1704
1704
|
const { theme } = useUi();
|
|
1705
|
-
const
|
|
1705
|
+
const toggle2 = React26.useCallback(() => {
|
|
1706
1706
|
if (!disabled) onValueChange(!value);
|
|
1707
1707
|
}, [disabled, onValueChange, value]);
|
|
1708
1708
|
const { colors } = theme;
|
|
1709
1709
|
const hasDescription = typeof description === "string" && description !== "";
|
|
1710
|
-
const themeStyles =
|
|
1710
|
+
const themeStyles = React26.useMemo(() => {
|
|
1711
1711
|
const labelStyle = { color: colors.text };
|
|
1712
1712
|
const descriptionStyle = { color: colors.textSecondary };
|
|
1713
1713
|
return { label: labelStyle, description: descriptionStyle };
|
|
@@ -1724,10 +1724,10 @@ var FormSwitch = ({
|
|
|
1724
1724
|
{
|
|
1725
1725
|
accessible: false,
|
|
1726
1726
|
disabled,
|
|
1727
|
-
onPress:
|
|
1727
|
+
onPress: toggle2,
|
|
1728
1728
|
style: [styles13.container, containerStyle],
|
|
1729
1729
|
tabIndex: -1,
|
|
1730
|
-
testID
|
|
1730
|
+
testID,
|
|
1731
1731
|
children: [
|
|
1732
1732
|
/* @__PURE__ */ jsxs(View, { style: styles13.textColumn, children: [
|
|
1733
1733
|
/* @__PURE__ */ jsx(Text, { style: [styles13.label, themeStyles.label], children: label }),
|
|
@@ -1740,7 +1740,7 @@ var FormSwitch = ({
|
|
|
1740
1740
|
accessibilityLabel: label,
|
|
1741
1741
|
accessibilityState: { checked: value, disabled },
|
|
1742
1742
|
disabled,
|
|
1743
|
-
testID
|
|
1743
|
+
testID: `${testID}-switch`,
|
|
1744
1744
|
value,
|
|
1745
1745
|
onValueChange
|
|
1746
1746
|
}
|
|
@@ -1830,8 +1830,8 @@ var FormCheckbox = ({
|
|
|
1830
1830
|
const hintText = typeof hint === "string" && hint !== "" ? hint : description;
|
|
1831
1831
|
const hasHint = typeof hintText === "string" && hintText !== "";
|
|
1832
1832
|
const { hintId } = useFieldIds();
|
|
1833
|
-
const [focused, setFocused] =
|
|
1834
|
-
const themeStyles =
|
|
1833
|
+
const [focused, setFocused] = React26.useState(false);
|
|
1834
|
+
const themeStyles = React26.useMemo(() => {
|
|
1835
1835
|
const boxOn = checkboxBoxColors(colors, brand, true);
|
|
1836
1836
|
const boxOff = checkboxBoxColors(colors, brand, false);
|
|
1837
1837
|
const ring = { borderColor: brand };
|
|
@@ -1839,7 +1839,7 @@ var FormCheckbox = ({
|
|
|
1839
1839
|
const hintStyle = { color: colors.textSecondary };
|
|
1840
1840
|
return { boxOn, boxOff, ring, label: labelStyle, hint: hintStyle };
|
|
1841
1841
|
}, [brand, colors]);
|
|
1842
|
-
const
|
|
1842
|
+
const toggle2 = () => {
|
|
1843
1843
|
const next = !value;
|
|
1844
1844
|
if (onValueChange) onValueChange(next);
|
|
1845
1845
|
if (onChange) onChange(next);
|
|
@@ -1849,7 +1849,7 @@ var FormCheckbox = ({
|
|
|
1849
1849
|
const key = event.key ?? "";
|
|
1850
1850
|
if (!ACTIVATION_KEYS.includes(key)) return;
|
|
1851
1851
|
if (typeof event.preventDefault === "function") event.preventDefault();
|
|
1852
|
-
|
|
1852
|
+
toggle2();
|
|
1853
1853
|
};
|
|
1854
1854
|
const keyboardProps = Platform.OS === "web" ? { onKeyDown: handleKeyDown } : {};
|
|
1855
1855
|
return /* @__PURE__ */ jsxs(
|
|
@@ -1864,7 +1864,7 @@ var FormCheckbox = ({
|
|
|
1864
1864
|
disabled,
|
|
1865
1865
|
onBlur: () => setFocused(false),
|
|
1866
1866
|
onFocus: () => setFocused(true),
|
|
1867
|
-
onPress:
|
|
1867
|
+
onPress: toggle2,
|
|
1868
1868
|
role: "checkbox",
|
|
1869
1869
|
style: [
|
|
1870
1870
|
styles14.container,
|
|
@@ -1900,7 +1900,7 @@ function nextHighlight(current, count, delta) {
|
|
|
1900
1900
|
// src/SelectControl/useSelectListbox.ts
|
|
1901
1901
|
var FORWARD = 1;
|
|
1902
1902
|
var BACKWARD = -1;
|
|
1903
|
-
function useSelectListbox({ options, isOpen, open, toggle, select }) {
|
|
1903
|
+
function useSelectListbox({ options, isOpen, open, toggle: toggle2, select }) {
|
|
1904
1904
|
const [row, setRow] = useState(NO_HIGHLIGHT);
|
|
1905
1905
|
const highlighted = isOpen ? options[row] : void 0;
|
|
1906
1906
|
useEffect(() => {
|
|
@@ -1916,7 +1916,7 @@ function useSelectListbox({ options, isOpen, open, toggle, select }) {
|
|
|
1916
1916
|
open();
|
|
1917
1917
|
setRow((current) => nextHighlight(current, options.length, key === "ArrowDown" ? FORWARD : BACKWARD));
|
|
1918
1918
|
} else if (highlighted !== void 0) select(highlighted.value);
|
|
1919
|
-
else
|
|
1919
|
+
else toggle2();
|
|
1920
1920
|
};
|
|
1921
1921
|
return { highlighted, onKeyDown };
|
|
1922
1922
|
}
|
|
@@ -1956,7 +1956,7 @@ function SelectControl({
|
|
|
1956
1956
|
const open = useCallback(() => {
|
|
1957
1957
|
setIsOpen(true);
|
|
1958
1958
|
}, []);
|
|
1959
|
-
const
|
|
1959
|
+
const toggle2 = useCallback(() => {
|
|
1960
1960
|
setIsOpen((prev) => !prev);
|
|
1961
1961
|
}, []);
|
|
1962
1962
|
const select = useCallback(
|
|
@@ -1966,7 +1966,7 @@ function SelectControl({
|
|
|
1966
1966
|
},
|
|
1967
1967
|
[onChange]
|
|
1968
1968
|
);
|
|
1969
|
-
const listbox = useSelectListbox({ options, isOpen, open, toggle, select });
|
|
1969
|
+
const listbox = useSelectListbox({ options, isOpen, open, toggle: toggle2, select });
|
|
1970
1970
|
const isListbox = menuAnchor !== void 0;
|
|
1971
1971
|
const captureKeys = isListbox ? { onKeyDownCapture: listbox.onKeyDown } : {};
|
|
1972
1972
|
const triggerAria = isListbox ? listboxTriggerAria(testID, isOpen && options.length > 0, listbox.highlighted) : {};
|
|
@@ -1983,7 +1983,7 @@ function SelectControl({
|
|
|
1983
1983
|
"aria-haspopup": isListbox ? "listbox" : "menu",
|
|
1984
1984
|
"aria-labelledby": labelledById,
|
|
1985
1985
|
onBlur: isListbox ? close : void 0,
|
|
1986
|
-
onPress:
|
|
1986
|
+
onPress: toggle2,
|
|
1987
1987
|
style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }],
|
|
1988
1988
|
testID: `${testID}-trigger`,
|
|
1989
1989
|
children: [
|
|
@@ -4246,7 +4246,343 @@ function BicInput({ value, onChange, onVerdict, accessibilityLabel, accessibilit
|
|
|
4246
4246
|
/* @__PURE__ */ jsx(RejectionLine, { message, testID })
|
|
4247
4247
|
] });
|
|
4248
4248
|
}
|
|
4249
|
+
var BAR_GAP = 8;
|
|
4250
|
+
var PAD_V = 10;
|
|
4251
|
+
var PAD_H = 16;
|
|
4252
|
+
var TEXT_SIZE2 = 13;
|
|
4253
|
+
var TEXT_LINE2 = 18;
|
|
4254
|
+
var styles29 = StyleSheet.create({
|
|
4255
|
+
bar: { borderTopWidth: 1, paddingHorizontal: PAD_H, paddingVertical: PAD_V, rowGap: BAR_GAP },
|
|
4256
|
+
actions: { flexDirection: "row", flexWrap: "wrap", gap: BAR_GAP },
|
|
4257
|
+
message: { fontSize: TEXT_SIZE2, fontWeight: "700", lineHeight: TEXT_LINE2 }
|
|
4258
|
+
});
|
|
4259
|
+
var PINNED = { position: "sticky", bottom: 0, zIndex: 1 };
|
|
4260
|
+
var actionBarPosition = (sticky, os) => sticky && os === "web" ? "sticky" : "relative";
|
|
4261
|
+
var ActionBar = ({ children, message, sticky = false, testID, style }) => {
|
|
4262
|
+
const { theme } = useUi();
|
|
4263
|
+
const { colors } = theme;
|
|
4264
|
+
const pinned = actionBarPosition(sticky, Platform.OS) === "sticky" ? PINNED : null;
|
|
4265
|
+
const hasMessage = message !== void 0 && message !== "";
|
|
4266
|
+
return /* @__PURE__ */ jsxs(View, { style: [styles29.bar, { backgroundColor: colors.surface, borderTopColor: colors.border }, pinned, style], testID, children: [
|
|
4267
|
+
hasMessage ? /* @__PURE__ */ jsx(Text, { role: "status", style: [styles29.message, { color: colors.text }], testID: `${testID}-message`, children: message }) : null,
|
|
4268
|
+
/* @__PURE__ */ jsx(View, { style: styles29.actions, children })
|
|
4269
|
+
] });
|
|
4270
|
+
};
|
|
4271
|
+
|
|
4272
|
+
// src/GatedChecklist/isChecklistComplete.ts
|
|
4273
|
+
var isChecklistComplete = (items, checked) => items.every((item) => checked.includes(item.id));
|
|
4274
|
+
var TITLE_SIZE = 13;
|
|
4275
|
+
var TITLE_GAP = 6;
|
|
4276
|
+
var styles30 = StyleSheet.create({
|
|
4277
|
+
title: { fontSize: TITLE_SIZE, fontWeight: "700", marginBottom: TITLE_GAP }
|
|
4278
|
+
});
|
|
4279
|
+
var GatedChecklist = ({ title, items, checked, onToggle, testID, disabled = false, children }) => {
|
|
4280
|
+
const { theme } = useUi();
|
|
4281
|
+
const complete = isChecklistComplete(items, checked);
|
|
4282
|
+
return /* @__PURE__ */ jsxs(View, { testID, children: [
|
|
4283
|
+
/* @__PURE__ */ jsx(Text, { accessibilityRole: "header", style: [styles30.title, { color: theme.colors.text }], children: title }),
|
|
4284
|
+
items.map((item) => /* @__PURE__ */ jsx(
|
|
4285
|
+
FormCheckbox,
|
|
4286
|
+
{
|
|
4287
|
+
description: item.description,
|
|
4288
|
+
disabled,
|
|
4289
|
+
label: item.label,
|
|
4290
|
+
testID: `${testID}-item-${item.id}`,
|
|
4291
|
+
value: checked.includes(item.id),
|
|
4292
|
+
onValueChange: () => onToggle(item.id)
|
|
4293
|
+
},
|
|
4294
|
+
item.id
|
|
4295
|
+
)),
|
|
4296
|
+
children?.(complete)
|
|
4297
|
+
] });
|
|
4298
|
+
};
|
|
4299
|
+
var MIN_TARGET_PX2 = 44;
|
|
4300
|
+
var DOT_SIZE = 18;
|
|
4301
|
+
var DOT_INNER = 8;
|
|
4302
|
+
var ROW_GAP6 = 10;
|
|
4303
|
+
var PAD_H2 = 12;
|
|
4304
|
+
var PAD_V2 = 8;
|
|
4305
|
+
var RADIUS = 8;
|
|
4306
|
+
var LABEL_SIZE = 14;
|
|
4307
|
+
var DESCRIPTION_SIZE = 12;
|
|
4308
|
+
var DESCRIPTION_LINE = 16;
|
|
4309
|
+
var styles31 = StyleSheet.create({
|
|
4310
|
+
row: {
|
|
4311
|
+
alignItems: "center",
|
|
4312
|
+
borderRadius: RADIUS,
|
|
4313
|
+
borderWidth: 1,
|
|
4314
|
+
columnGap: ROW_GAP6,
|
|
4315
|
+
flexDirection: "row",
|
|
4316
|
+
minHeight: MIN_TARGET_PX2,
|
|
4317
|
+
paddingHorizontal: PAD_H2,
|
|
4318
|
+
paddingVertical: PAD_V2
|
|
4319
|
+
},
|
|
4320
|
+
dot: { alignItems: "center", borderRadius: DOT_SIZE / 2, borderWidth: 2, height: DOT_SIZE, justifyContent: "center", width: DOT_SIZE },
|
|
4321
|
+
dotInner: { borderRadius: DOT_INNER / 2, height: DOT_INNER, width: DOT_INNER },
|
|
4322
|
+
text: { flex: 1, flexShrink: 1 },
|
|
4323
|
+
label: { fontSize: LABEL_SIZE, fontWeight: "600" },
|
|
4324
|
+
description: { fontSize: DESCRIPTION_SIZE, lineHeight: DESCRIPTION_LINE }
|
|
4325
|
+
});
|
|
4326
|
+
function RadioRow({ option, identity, colors, tabIndex, hostRef, onPress }) {
|
|
4327
|
+
const { checked, disabled } = identity.accessibilityState;
|
|
4328
|
+
const accent = checked ? colors.primary : colors.border;
|
|
4329
|
+
const hasDescription = option.description !== void 0 && option.description !== "";
|
|
4330
|
+
return /* @__PURE__ */ jsxs(
|
|
4331
|
+
Pressable,
|
|
4332
|
+
{
|
|
4333
|
+
ref: hostRef,
|
|
4334
|
+
accessibilityHint: option.hint,
|
|
4335
|
+
accessibilityLabel: identity.accessibilityLabel,
|
|
4336
|
+
accessibilityRole: "radio",
|
|
4337
|
+
accessibilityState: identity.accessibilityState,
|
|
4338
|
+
"aria-checked": checked,
|
|
4339
|
+
disabled,
|
|
4340
|
+
style: [styles31.row, { borderColor: accent, backgroundColor: checked ? colors.tint : colors.muted }],
|
|
4341
|
+
tabIndex,
|
|
4342
|
+
testID: identity.testID,
|
|
4343
|
+
onPress,
|
|
4344
|
+
children: [
|
|
4345
|
+
/* @__PURE__ */ jsx(View, { style: [styles31.dot, { borderColor: accent }], children: checked ? /* @__PURE__ */ jsx(View, { style: [styles31.dotInner, { backgroundColor: colors.primary }] }) : null }),
|
|
4346
|
+
/* @__PURE__ */ jsxs(View, { style: styles31.text, children: [
|
|
4347
|
+
/* @__PURE__ */ jsx(Text, { style: [styles31.label, { color: checked ? colors.primary : colors.textStrong }], children: option.label }),
|
|
4348
|
+
hasDescription ? /* @__PURE__ */ jsx(Text, { style: [styles31.description, { color: colors.textMuted }], testID: `${identity.testID}-description`, children: option.description }) : null
|
|
4349
|
+
] })
|
|
4350
|
+
]
|
|
4351
|
+
}
|
|
4352
|
+
);
|
|
4353
|
+
}
|
|
4354
|
+
|
|
4355
|
+
// src/RadioList/utils/radioRowIdentity.ts
|
|
4356
|
+
var radioRowIdentity = (option, selected, disabled, prefix) => {
|
|
4357
|
+
const hasDescription = option.description !== void 0 && option.description !== "";
|
|
4358
|
+
return {
|
|
4359
|
+
testID: `${prefix}-${String(option.value)}`,
|
|
4360
|
+
accessibilityLabel: hasDescription ? `${option.label}, ${String(option.description)}` : option.label,
|
|
4361
|
+
accessibilityState: { checked: selected, selected, disabled }
|
|
4362
|
+
};
|
|
4363
|
+
};
|
|
4364
|
+
var ROW_GAP7 = 8;
|
|
4365
|
+
var styles32 = StyleSheet.create({
|
|
4366
|
+
list: { rowGap: ROW_GAP7 }
|
|
4367
|
+
});
|
|
4368
|
+
function RadioList(props) {
|
|
4369
|
+
const { options, value, onChange, optionTestIDPrefix, label, error, required = false, disabled = false, testID } = props;
|
|
4370
|
+
const { theme } = useUi();
|
|
4371
|
+
const colors = React26.useMemo(() => buildChipColors(theme.colors, theme.palette), [theme.colors, theme.palette]);
|
|
4372
|
+
const selectedIndex = options.findIndex((option) => option.value === value);
|
|
4373
|
+
const radio = useRadioKeyboard({ enabled: true, disabled, values: options.map((option) => option.value), selectedIndex, onChange });
|
|
4374
|
+
return /* @__PURE__ */ jsx(Field, { error, label, required, testID, children: ({ describedById, hasError }) => /* @__PURE__ */ jsx(
|
|
4375
|
+
View,
|
|
4376
|
+
{
|
|
4377
|
+
accessibilityRole: "radiogroup",
|
|
4378
|
+
style: styles32.list,
|
|
4379
|
+
...webFieldA11y({ describedById, hasError }),
|
|
4380
|
+
...radio.groupProps,
|
|
4381
|
+
children: options.map((option, index) => /* @__PURE__ */ jsx(
|
|
4382
|
+
RadioRow,
|
|
4383
|
+
{
|
|
4384
|
+
colors,
|
|
4385
|
+
hostRef: radio.chipRef(index),
|
|
4386
|
+
identity: radioRowIdentity(option, index === selectedIndex, disabled, optionTestIDPrefix),
|
|
4387
|
+
option,
|
|
4388
|
+
tabIndex: radio.tabIndexFor(index),
|
|
4389
|
+
onPress: () => onChange(option.value)
|
|
4390
|
+
},
|
|
4391
|
+
String(option.value)
|
|
4392
|
+
))
|
|
4393
|
+
}
|
|
4394
|
+
) });
|
|
4395
|
+
}
|
|
4396
|
+
|
|
4397
|
+
// src/DecisionPanel/utils/decisionRules.ts
|
|
4398
|
+
var validateDecision = (outcomes, outcome, note) => {
|
|
4399
|
+
const chosen = outcomes.find((item) => item.value === outcome);
|
|
4400
|
+
if (chosen === void 0) return "choose";
|
|
4401
|
+
const noteMissing = chosen.noteRequired === true && note.trim() === "";
|
|
4402
|
+
return noteMissing ? "note" : null;
|
|
4403
|
+
};
|
|
4404
|
+
var defaultDecisionVariant = (width) => isWideFormLayout(width) ? "sticky-bar" : "choose-then-submit";
|
|
4405
|
+
var leadFirst = (outcomes, lead) => [
|
|
4406
|
+
...outcomes.filter((item) => item.value === lead),
|
|
4407
|
+
...outcomes.filter((item) => item.value !== lead)
|
|
4408
|
+
];
|
|
4409
|
+
var toneVariant = (tone) => {
|
|
4410
|
+
if (tone === "primary") return "primary";
|
|
4411
|
+
return tone === "danger" ? "danger" : "secondary";
|
|
4412
|
+
};
|
|
4413
|
+
var NOTE_LINES = 3;
|
|
4414
|
+
function DecisionNote({ state, labels, testID, disabled }) {
|
|
4415
|
+
const error = state.error === "note" ? labels.noteRequiredError : void 0;
|
|
4416
|
+
return /* @__PURE__ */ jsx(
|
|
4417
|
+
FormField,
|
|
4418
|
+
{
|
|
4419
|
+
multiline: true,
|
|
4420
|
+
editable: !disabled,
|
|
4421
|
+
error,
|
|
4422
|
+
label: labels.note,
|
|
4423
|
+
numberOfLines: NOTE_LINES,
|
|
4424
|
+
placeholder: labels.notePlaceholder,
|
|
4425
|
+
testID: `${testID}-note`,
|
|
4426
|
+
value: state.note,
|
|
4427
|
+
onChangeText: state.setNote
|
|
4428
|
+
}
|
|
4429
|
+
);
|
|
4430
|
+
}
|
|
4431
|
+
var BUTTON_BASIS = "40%";
|
|
4432
|
+
var styles33 = StyleSheet.create({
|
|
4433
|
+
cell: { flexBasis: BUTTON_BASIS, flexGrow: 1 }
|
|
4434
|
+
});
|
|
4435
|
+
function OutcomeButtons({ outcomes, pending, disabled, testID, onPress }) {
|
|
4436
|
+
return /* @__PURE__ */ jsx(Fragment, { children: outcomes.map((item) => /* @__PURE__ */ jsx(View, { style: styles33.cell, children: /* @__PURE__ */ jsx(
|
|
4437
|
+
Button,
|
|
4438
|
+
{
|
|
4439
|
+
fullWidth: true,
|
|
4440
|
+
accessibilityHint: item.hint,
|
|
4441
|
+
accessibilityLabel: item.label,
|
|
4442
|
+
disabled: disabled || pending !== null && pending !== item.value,
|
|
4443
|
+
label: item.label,
|
|
4444
|
+
loading: pending === item.value,
|
|
4445
|
+
testID: `${testID}-action-${item.value}`,
|
|
4446
|
+
variant: toneVariant(item.tone),
|
|
4447
|
+
onPress: () => onPress(item.value)
|
|
4448
|
+
}
|
|
4449
|
+
) }, item.value)) });
|
|
4450
|
+
}
|
|
4451
|
+
var retone = (item, lead) => {
|
|
4452
|
+
if (item.value === lead) return { ...item, tone: "primary" };
|
|
4453
|
+
return item.tone === "primary" ? { ...item, tone: "neutral" } : item;
|
|
4454
|
+
};
|
|
4455
|
+
function ChecksDriveDecision(props) {
|
|
4456
|
+
const { state, outcomes, labels, testID, disabled, reasons = [], leadOutcome } = props;
|
|
4457
|
+
const ordered = leadFirst(outcomes, leadOutcome).map((item) => retone(item, leadOutcome));
|
|
4458
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4459
|
+
reasons.length > 0 ? /* @__PURE__ */ jsx(
|
|
4460
|
+
ChipSelector,
|
|
4461
|
+
{
|
|
4462
|
+
multiple: true,
|
|
4463
|
+
chipTestIDPrefix: `${testID}-reason`,
|
|
4464
|
+
disabled,
|
|
4465
|
+
label: labels.reasons,
|
|
4466
|
+
options: reasons,
|
|
4467
|
+
testID: `${testID}-reasons`,
|
|
4468
|
+
value: state.reasons,
|
|
4469
|
+
variant: "outline",
|
|
4470
|
+
onChange: state.toggleReason
|
|
4471
|
+
}
|
|
4472
|
+
) : null,
|
|
4473
|
+
/* @__PURE__ */ jsx(DecisionNote, { ...props }),
|
|
4474
|
+
/* @__PURE__ */ jsx(ActionBar, { message: labels.message, testID: `${testID}-bar`, children: /* @__PURE__ */ jsx(OutcomeButtons, { disabled, outcomes: ordered, pending: state.pending, testID, onPress: state.submit }) })
|
|
4475
|
+
] });
|
|
4476
|
+
}
|
|
4477
|
+
function ChooseThenSubmitDecision(props) {
|
|
4478
|
+
const { state, outcomes, labels, testID, disabled } = props;
|
|
4479
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4480
|
+
/* @__PURE__ */ jsx(
|
|
4481
|
+
RadioList,
|
|
4482
|
+
{
|
|
4483
|
+
disabled,
|
|
4484
|
+
error: state.error === "choose" ? labels.chooseError : void 0,
|
|
4485
|
+
optionTestIDPrefix: `${testID}-outcome`,
|
|
4486
|
+
options: outcomes,
|
|
4487
|
+
testID: `${testID}-outcomes`,
|
|
4488
|
+
value: state.outcome === "" ? void 0 : state.outcome,
|
|
4489
|
+
onChange: state.choose
|
|
4490
|
+
}
|
|
4491
|
+
),
|
|
4492
|
+
/* @__PURE__ */ jsx(DecisionNote, { ...props }),
|
|
4493
|
+
/* @__PURE__ */ jsx(
|
|
4494
|
+
Button,
|
|
4495
|
+
{
|
|
4496
|
+
fullWidth: true,
|
|
4497
|
+
accessibilityHint: labels.submitHint,
|
|
4498
|
+
accessibilityLabel: labels.submit,
|
|
4499
|
+
disabled,
|
|
4500
|
+
label: labels.submit,
|
|
4501
|
+
loading: state.pending !== null,
|
|
4502
|
+
testID: `${testID}-submit`,
|
|
4503
|
+
onPress: () => state.submit()
|
|
4504
|
+
}
|
|
4505
|
+
)
|
|
4506
|
+
] });
|
|
4507
|
+
}
|
|
4508
|
+
function StickyBarDecision(props) {
|
|
4509
|
+
const { state, outcomes, labels, testID, disabled } = props;
|
|
4510
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4511
|
+
/* @__PURE__ */ jsx(DecisionNote, { ...props }),
|
|
4512
|
+
/* @__PURE__ */ jsx(ActionBar, { sticky: true, message: labels.message, testID: `${testID}-bar`, children: /* @__PURE__ */ jsx(OutcomeButtons, { disabled, outcomes, pending: state.pending, testID, onPress: state.submit }) })
|
|
4513
|
+
] });
|
|
4514
|
+
}
|
|
4515
|
+
var TEXT_SIZE3 = 13;
|
|
4516
|
+
var TEXT_LINE3 = 18;
|
|
4517
|
+
var styles34 = StyleSheet.create({
|
|
4518
|
+
text: { fontSize: TEXT_SIZE3, fontWeight: "700", lineHeight: TEXT_LINE3 }
|
|
4519
|
+
});
|
|
4520
|
+
var SubmitError = ({ message, testID }) => {
|
|
4521
|
+
const { theme } = useUi();
|
|
4522
|
+
return /* @__PURE__ */ jsx(Text, { role: "alert", style: [styles34.text, { color: fieldErrorInk(theme) }], testID, children: message });
|
|
4523
|
+
};
|
|
4524
|
+
var toggle = (list, id) => list.includes(id) ? list.filter((item) => item !== id) : [...list, id];
|
|
4525
|
+
function useDecisionPanel(outcomes, onSubmit) {
|
|
4526
|
+
const [outcome, setOutcome] = React26.useState("");
|
|
4527
|
+
const [note, setNote] = React26.useState("");
|
|
4528
|
+
const [reasons, setReasons] = React26.useState([]);
|
|
4529
|
+
const [checked, setChecked] = React26.useState([]);
|
|
4530
|
+
const [error, setError] = React26.useState(null);
|
|
4531
|
+
const [pending, setPending] = React26.useState(null);
|
|
4532
|
+
const submit = async (override) => {
|
|
4533
|
+
const target = override ?? outcome;
|
|
4534
|
+
const problem = validateDecision(outcomes, target, note);
|
|
4535
|
+
setError(problem);
|
|
4536
|
+
if (problem !== null || target === "") return;
|
|
4537
|
+
setPending(target);
|
|
4538
|
+
try {
|
|
4539
|
+
await onSubmit({ outcome: target, note, reasons });
|
|
4540
|
+
} catch {
|
|
4541
|
+
setError("submit");
|
|
4542
|
+
} finally {
|
|
4543
|
+
setPending(null);
|
|
4544
|
+
}
|
|
4545
|
+
};
|
|
4546
|
+
return {
|
|
4547
|
+
outcome,
|
|
4548
|
+
note,
|
|
4549
|
+
reasons,
|
|
4550
|
+
checked,
|
|
4551
|
+
error,
|
|
4552
|
+
pending,
|
|
4553
|
+
choose: (next) => {
|
|
4554
|
+
setOutcome(next);
|
|
4555
|
+
setError(null);
|
|
4556
|
+
},
|
|
4557
|
+
setNote,
|
|
4558
|
+
toggleReason: (reason) => setReasons((list) => toggle(list, reason)),
|
|
4559
|
+
toggleCheck: (id) => setChecked((list) => toggle(list, id)),
|
|
4560
|
+
submit
|
|
4561
|
+
};
|
|
4562
|
+
}
|
|
4563
|
+
var TITLE_SIZE2 = 15;
|
|
4564
|
+
var PANEL_GAP = 12;
|
|
4565
|
+
var styles35 = StyleSheet.create({
|
|
4566
|
+
panel: { rowGap: PANEL_GAP },
|
|
4567
|
+
title: { fontSize: TITLE_SIZE2, fontWeight: "700" }
|
|
4568
|
+
});
|
|
4569
|
+
function renderVariant(variant, props) {
|
|
4570
|
+
if (variant === "sticky-bar") return /* @__PURE__ */ jsx(StickyBarDecision, { ...props });
|
|
4571
|
+
if (variant === "checks-drive") return /* @__PURE__ */ jsx(ChecksDriveDecision, { ...props });
|
|
4572
|
+
return /* @__PURE__ */ jsx(ChooseThenSubmitDecision, { ...props });
|
|
4573
|
+
}
|
|
4574
|
+
function DecisionPanel(props) {
|
|
4575
|
+
const { variant, outcomes, onSubmit, labels, testID, reasons, leadOutcome, checklist, disabled = false, style } = props;
|
|
4576
|
+
const { theme } = useUi();
|
|
4577
|
+
const state = useDecisionPanel(outcomes, onSubmit);
|
|
4578
|
+
const body = (locked) => renderVariant(variant, { state, outcomes, labels, testID, disabled: disabled || locked, reasons, leadOutcome });
|
|
4579
|
+
return /* @__PURE__ */ jsxs(View, { style: [styles35.panel, style], testID, children: [
|
|
4580
|
+
/* @__PURE__ */ jsx(Text, { accessibilityRole: "header", style: [styles35.title, { color: theme.colors.text }], children: labels.title }),
|
|
4581
|
+
checklist !== void 0 ? /* @__PURE__ */ jsx(GatedChecklist, { checked: state.checked, items: checklist.items, testID: `${testID}-checklist`, title: checklist.title, onToggle: state.toggleCheck, children: (complete) => body(!complete) }) : body(false),
|
|
4582
|
+
state.error === "submit" ? /* @__PURE__ */ jsx(SubmitError, { message: labels.submitError, testID: `${testID}-error` }) : null
|
|
4583
|
+
] });
|
|
4584
|
+
}
|
|
4249
4585
|
|
|
4250
|
-
export { AddOnRequest, AlignToControl, AnchoredMenu, BicInput, BicRejection, COUNTRIES, ChipLabelWrap, ChipSelector, CountryField, CountryFlag, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateField, DateInput, DateRangeControl, DateTimeField, DropdownPlacement, FLAG_HEIGHT, FLAG_WIDTH, Field, FixBar, FlagShapeKind, FormActions, FormCell, FormCheckbox, FormField, FormGrid, FormSection, FormStack, FormStatusLine, FormSwitch, IBAN_MAX_LENGTH, IBAN_REGISTERED_COUNTRY_COUNT, INLINE_FIELD_ROW_MIN_WIDTH, IbanInput, IbanRejection, InlineFieldRow, LINE_ITEMS_WIDE_MIN_WIDTH, LineItems, PHONE_MAX_WIDTH, RESPONSIVE_FORM_DEFAULT_BREAKPOINT, ResponsiveFormLayout, SearchSelect, SelectControl, SelectField, SelectSurface, StepperNav, StepperTabs, ThemedTextInput, TypeaheadControl, UploadWithLinkField, buildSearchSelectSections, canRemoveLine, controlStyles, countryFieldOptions, countryFlag, countryOptions, draftBic, draftIban, dropdownFrame, findOption, fitDropdownWidth, flagShapes, groupAriaChecked, groupInFours, highlightAfterQuery, ibanCounter, ibanLengthFor, inlineFieldRowLayout, isAddOnOpen, isFallbackFlag, isFixBarVisible, isLineItemsWide, isOutside, isUnmatched, isWideFormLayout, lineItemColumnFlex, lineNumberOf, moveHighlight, nextHighlight, placeDropdown, rejectionMessage, resolveGroupSelection, resolveSelectMotion, resolveStepNeighbours, suggestOptions, toCountryValue, toggleGroupSelection, useBlurVerdict, useDeferredFocus, useFocusFirstInvalid, useKeepInView, useOutsidePress, useRecentValues, useReducedMotion, useSearchSelectState, useThemedInput, validateBic, validateIban };
|
|
4586
|
+
export { ActionBar, AddOnRequest, AlignToControl, AnchoredMenu, BicInput, BicRejection, COUNTRIES, ChipLabelWrap, ChipSelector, CountryField, CountryFlag, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateField, DateInput, DateRangeControl, DateTimeField, DecisionPanel, DropdownPlacement, FLAG_HEIGHT, FLAG_WIDTH, Field, 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, PHONE_MAX_WIDTH, RESPONSIVE_FORM_DEFAULT_BREAKPOINT, RadioList, ResponsiveFormLayout, SearchSelect, SelectControl, SelectField, SelectSurface, StepperNav, StepperTabs, ThemedTextInput, TypeaheadControl, UploadWithLinkField, actionBarPosition, buildSearchSelectSections, canRemoveLine, 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, suggestOptions, toCountryValue, toggleGroupSelection, useBlurVerdict, useDeferredFocus, useFocusFirstInvalid, useKeepInView, useOutsidePress, useRecentValues, useReducedMotion, useSearchSelectState, useThemedInput, validateBic, validateDecision, validateIban };
|
|
4251
4587
|
//# sourceMappingURL=index.mjs.map
|
|
4252
4588
|
//# sourceMappingURL=index.mjs.map
|