@dloizides/ui-forms 1.44.1 → 1.46.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 +117 -2
- package/dist/index.d.ts +117 -2
- package/dist/index.js +422 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +413 -81
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import React37, { forwardRef, createContext, useState, useCallback, useMemo,
|
|
2
|
-
import { Platform, StyleSheet, TextInput, View, Text, useWindowDimensions, ScrollView,
|
|
1
|
+
import React37, { forwardRef, createContext, useRef, useImperativeHandle, useState, useCallback, useMemo, useEffect, useLayoutEffect, useContext } from 'react';
|
|
2
|
+
import { Platform, StyleSheet, TextInput, View, Text, Pressable, useWindowDimensions, ScrollView, Animated, Easing, AccessibilityInfo, Switch, Image, TouchableOpacity, Modal } from 'react-native';
|
|
3
3
|
import { useUi } from '@dloizides/ui-feedback';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import { Z_INDEX, focusRingOutline, readableScaleInk, resolveOnBrand } from '@dloizides/design-tokens';
|
|
6
6
|
import { themeFocusRingColor, Button, useFocusRing, IconButton } from '@dloizides/ui-buttons';
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
8
8
|
import { MIN_TOUCH_TARGET_PX } from '@dloizides/a11y';
|
|
9
|
+
import { parseFieldErrors } from '@dloizides/api-client-base';
|
|
9
10
|
import Svg, { Rect, Circle, Polygon } from 'react-native-svg';
|
|
11
|
+
import { SvgIcon } from '@dloizides/ui-icons';
|
|
10
12
|
|
|
11
13
|
// src/Field/Field.tsx
|
|
12
14
|
function attachControlId(child, candidateId, describedById) {
|
|
@@ -2694,8 +2696,86 @@ function monthStart(iso) {
|
|
|
2694
2696
|
return `${iso.slice(0, MONTH_PREFIX)}-01`;
|
|
2695
2697
|
}
|
|
2696
2698
|
|
|
2697
|
-
// src/DatePicker/utils/
|
|
2699
|
+
// src/DatePicker/utils/formatDate.ts
|
|
2700
|
+
var SAMPLE_UTC = Date.UTC(2027, 5, 12);
|
|
2701
|
+
var TWO_DIGIT_YEAR = 100;
|
|
2702
|
+
var CENTURY = 2e3;
|
|
2703
|
+
var PART_COUNT = 3;
|
|
2704
|
+
var PAD3 = 2;
|
|
2698
2705
|
var MONDAY2 = 1;
|
|
2706
|
+
var ISO_LIKE = /^\d{4}-\d{1,2}-\d{1,2}$/;
|
|
2707
|
+
var MONTH_INDEXES = Array.from({ length: 12 }, (_unused, index) => index);
|
|
2708
|
+
var WEEK_OFFSETS = Array.from({ length: 7 }, (_unused, index) => index);
|
|
2709
|
+
var UTC = "UTC";
|
|
2710
|
+
var PART_OF = { day: "day" /* Day */, month: "month" /* Month */, year: "year" /* Year */ };
|
|
2711
|
+
function utcOf(iso) {
|
|
2712
|
+
const parts = parseIso(iso);
|
|
2713
|
+
return parts === null ? null : new Date(Date.UTC(parts.year, parts.month - 1, parts.day));
|
|
2714
|
+
}
|
|
2715
|
+
function formatWith(iso, locale, options) {
|
|
2716
|
+
const date = utcOf(iso);
|
|
2717
|
+
if (date === null) return iso;
|
|
2718
|
+
return new Intl.DateTimeFormat(locale, { ...options, timeZone: UTC }).format(date).replace(/,/g, "");
|
|
2719
|
+
}
|
|
2720
|
+
function formatDisplay(iso, locale) {
|
|
2721
|
+
return formatWith(iso, locale, { weekday: "short", day: "numeric", month: "short", year: "numeric" });
|
|
2722
|
+
}
|
|
2723
|
+
function formatShort(iso, locale, withYear = true) {
|
|
2724
|
+
return formatWith(iso, locale, withYear ? { day: "numeric", month: "short", year: "numeric" } : { day: "numeric", month: "short" });
|
|
2725
|
+
}
|
|
2726
|
+
function formatMonthYear(iso, locale) {
|
|
2727
|
+
return formatWith(iso, locale, { month: "long", year: "numeric" });
|
|
2728
|
+
}
|
|
2729
|
+
function monthNames(locale) {
|
|
2730
|
+
const format = new Intl.DateTimeFormat(locale, { month: "long", timeZone: UTC });
|
|
2731
|
+
return MONTH_INDEXES.map((month) => format.format(new Date(Date.UTC(2024, month, 1))));
|
|
2732
|
+
}
|
|
2733
|
+
function weekdayNames(locale, firstDay = MONDAY2) {
|
|
2734
|
+
const format = new Intl.DateTimeFormat(locale, { weekday: "short", timeZone: UTC });
|
|
2735
|
+
return WEEK_OFFSETS.map((offset) => format.format(new Date(Date.UTC(2024, 0, firstDay + offset))));
|
|
2736
|
+
}
|
|
2737
|
+
function typedOrder(locale) {
|
|
2738
|
+
const parts = new Intl.DateTimeFormat(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone: UTC }).formatToParts(new Date(SAMPLE_UTC));
|
|
2739
|
+
return parts.map((part) => PART_OF[part.type]).filter((part) => part !== void 0);
|
|
2740
|
+
}
|
|
2741
|
+
function formatTyped(iso, locale) {
|
|
2742
|
+
const parts = parseIso(iso);
|
|
2743
|
+
if (parts === null) return iso;
|
|
2744
|
+
const text = {
|
|
2745
|
+
["day" /* Day */]: String(parts.day).padStart(PAD3, "0"),
|
|
2746
|
+
["month" /* Month */]: String(parts.month).padStart(PAD3, "0"),
|
|
2747
|
+
["year" /* Year */]: String(parts.year)
|
|
2748
|
+
};
|
|
2749
|
+
return typedOrder(locale).map((part) => text[part]).join("/");
|
|
2750
|
+
}
|
|
2751
|
+
function parseTyped(text, locale) {
|
|
2752
|
+
const trimmed = text.trim();
|
|
2753
|
+
if (ISO_LIKE.test(trimmed)) {
|
|
2754
|
+
const [year = 0, month = 0, day = 0] = trimmed.split("-").map(Number);
|
|
2755
|
+
const parts2 = { year, month, day };
|
|
2756
|
+
return isValidParts(parts2) ? toIso(parts2) : null;
|
|
2757
|
+
}
|
|
2758
|
+
const numbers2 = trimmed.split(/\D+/).filter((piece) => piece !== "").map(Number);
|
|
2759
|
+
if (numbers2.length !== PART_COUNT) return null;
|
|
2760
|
+
const order = typedOrder(locale);
|
|
2761
|
+
const read = (part) => numbers2[order.indexOf(part)] ?? 0;
|
|
2762
|
+
const rawYear = read("year" /* Year */);
|
|
2763
|
+
const parts = { year: rawYear < TWO_DIGIT_YEAR ? CENTURY + rawYear : rawYear, month: read("month" /* Month */), day: read("day" /* Day */) };
|
|
2764
|
+
return isValidParts(parts) ? toIso(parts) : null;
|
|
2765
|
+
}
|
|
2766
|
+
|
|
2767
|
+
// src/DatePicker/utils/DateDisplay.ts
|
|
2768
|
+
var DateDisplay = /* @__PURE__ */ ((DateDisplay2) => {
|
|
2769
|
+
DateDisplay2["Long"] = "long";
|
|
2770
|
+
DateDisplay2["Numeric"] = "numeric";
|
|
2771
|
+
return DateDisplay2;
|
|
2772
|
+
})(DateDisplay || {});
|
|
2773
|
+
function displayFormatter(display) {
|
|
2774
|
+
return display === "numeric" /* Numeric */ ? formatTyped : formatDisplay;
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2777
|
+
// src/DatePicker/utils/weekStart.ts
|
|
2778
|
+
var MONDAY3 = 1;
|
|
2699
2779
|
var SUNDAY2 = 7;
|
|
2700
2780
|
var SUNDAY_REGIONS = /* @__PURE__ */ new Set(["US", "CA", "MX", "BR", "JP", "KR", "TW", "HK", "IL", "PH", "IN", "ZA", "SA", "PE", "CO", "VE", "GT", "HN", "PA", "PR", "DO", "SV", "TH", "ID"]);
|
|
2701
2781
|
function weekFirstDay(locale) {
|
|
@@ -2704,20 +2784,20 @@ function weekFirstDay(locale) {
|
|
|
2704
2784
|
const info = resolved;
|
|
2705
2785
|
const first = info.getWeekInfo?.().firstDay ?? info.weekInfo?.firstDay;
|
|
2706
2786
|
if (first !== void 0) return first;
|
|
2707
|
-
return SUNDAY_REGIONS.has(resolved.maximize().region ?? "") ? SUNDAY2 :
|
|
2787
|
+
return SUNDAY_REGIONS.has(resolved.maximize().region ?? "") ? SUNDAY2 : MONDAY3;
|
|
2708
2788
|
} catch {
|
|
2709
|
-
return
|
|
2789
|
+
return MONDAY3;
|
|
2710
2790
|
}
|
|
2711
2791
|
}
|
|
2712
2792
|
var DatePickerContext = createContext({ labels: DEFAULT_DATE_PICKER_LABELS });
|
|
2713
|
-
function DatePickerProvider({ labels, locale, today, children }) {
|
|
2714
|
-
const value = useMemo(() => ({ labels: { ...DEFAULT_DATE_PICKER_LABELS, ...labels }, locale, today }), [labels, locale, today]);
|
|
2793
|
+
function DatePickerProvider({ labels, locale, today, display, children }) {
|
|
2794
|
+
const value = useMemo(() => ({ labels: { ...DEFAULT_DATE_PICKER_LABELS, ...labels }, locale, today, display }), [labels, locale, today, display]);
|
|
2715
2795
|
return /* @__PURE__ */ jsx(DatePickerContext.Provider, { value, children });
|
|
2716
2796
|
}
|
|
2717
2797
|
function useDatePickerConfig() {
|
|
2718
2798
|
const config = useContext(DatePickerContext);
|
|
2719
2799
|
const firstDay = useMemo(() => weekFirstDay(config.locale), [config.locale]);
|
|
2720
|
-
return { labels: config.labels, locale: config.locale, today: config.today ?? todayIso(), firstDay };
|
|
2800
|
+
return { labels: config.labels, locale: config.locale, today: config.today ?? todayIso(), firstDay, display: config.display ?? "long" /* Long */ };
|
|
2721
2801
|
}
|
|
2722
2802
|
|
|
2723
2803
|
// src/DatePicker/utils/motionStyles.ts
|
|
@@ -2762,14 +2842,14 @@ function PickerSurface({ anchorRef, phone, minWidth, label, testID, onDismiss, c
|
|
|
2762
2842
|
// src/DatePicker/utils/calendarKeys.ts
|
|
2763
2843
|
var DAYS_IN_WEEK2 = 7;
|
|
2764
2844
|
var MONTHS_IN_YEAR2 = 12;
|
|
2765
|
-
var
|
|
2845
|
+
var MONDAY4 = 1;
|
|
2766
2846
|
var DAY_STEPS = {
|
|
2767
2847
|
ArrowLeft: -1,
|
|
2768
2848
|
ArrowRight: 1,
|
|
2769
2849
|
ArrowUp: -DAYS_IN_WEEK2,
|
|
2770
2850
|
ArrowDown: DAYS_IN_WEEK2
|
|
2771
2851
|
};
|
|
2772
|
-
function nextFocusDay(iso, key, shiftKey = false, firstDay =
|
|
2852
|
+
function nextFocusDay(iso, key, shiftKey = false, firstDay = MONDAY4) {
|
|
2773
2853
|
const step = DAY_STEPS[key];
|
|
2774
2854
|
if (step !== void 0) return addDays(iso, step);
|
|
2775
2855
|
const monthStep = shiftKey ? MONTHS_IN_YEAR2 : 1;
|
|
@@ -2857,74 +2937,6 @@ function DayCell({ iso, state, testID, label, hint, onPick, onKey }) {
|
|
|
2857
2937
|
) });
|
|
2858
2938
|
}
|
|
2859
2939
|
|
|
2860
|
-
// src/DatePicker/utils/formatDate.ts
|
|
2861
|
-
var SAMPLE_UTC = Date.UTC(2027, 5, 12);
|
|
2862
|
-
var TWO_DIGIT_YEAR = 100;
|
|
2863
|
-
var CENTURY = 2e3;
|
|
2864
|
-
var PART_COUNT = 3;
|
|
2865
|
-
var PAD3 = 2;
|
|
2866
|
-
var MONDAY4 = 1;
|
|
2867
|
-
var ISO_LIKE = /^\d{4}-\d{1,2}-\d{1,2}$/;
|
|
2868
|
-
var MONTH_INDEXES = Array.from({ length: 12 }, (_unused, index) => index);
|
|
2869
|
-
var WEEK_OFFSETS = Array.from({ length: 7 }, (_unused, index) => index);
|
|
2870
|
-
var UTC = "UTC";
|
|
2871
|
-
var PART_OF = { day: "day" /* Day */, month: "month" /* Month */, year: "year" /* Year */ };
|
|
2872
|
-
function utcOf(iso) {
|
|
2873
|
-
const parts = parseIso(iso);
|
|
2874
|
-
return parts === null ? null : new Date(Date.UTC(parts.year, parts.month - 1, parts.day));
|
|
2875
|
-
}
|
|
2876
|
-
function formatWith(iso, locale, options) {
|
|
2877
|
-
const date = utcOf(iso);
|
|
2878
|
-
if (date === null) return iso;
|
|
2879
|
-
return new Intl.DateTimeFormat(locale, { ...options, timeZone: UTC }).format(date).replace(/,/g, "");
|
|
2880
|
-
}
|
|
2881
|
-
function formatDisplay(iso, locale) {
|
|
2882
|
-
return formatWith(iso, locale, { weekday: "short", day: "numeric", month: "short", year: "numeric" });
|
|
2883
|
-
}
|
|
2884
|
-
function formatShort(iso, locale, withYear = true) {
|
|
2885
|
-
return formatWith(iso, locale, withYear ? { day: "numeric", month: "short", year: "numeric" } : { day: "numeric", month: "short" });
|
|
2886
|
-
}
|
|
2887
|
-
function formatMonthYear(iso, locale) {
|
|
2888
|
-
return formatWith(iso, locale, { month: "long", year: "numeric" });
|
|
2889
|
-
}
|
|
2890
|
-
function monthNames(locale) {
|
|
2891
|
-
const format = new Intl.DateTimeFormat(locale, { month: "long", timeZone: UTC });
|
|
2892
|
-
return MONTH_INDEXES.map((month) => format.format(new Date(Date.UTC(2024, month, 1))));
|
|
2893
|
-
}
|
|
2894
|
-
function weekdayNames(locale, firstDay = MONDAY4) {
|
|
2895
|
-
const format = new Intl.DateTimeFormat(locale, { weekday: "short", timeZone: UTC });
|
|
2896
|
-
return WEEK_OFFSETS.map((offset) => format.format(new Date(Date.UTC(2024, 0, firstDay + offset))));
|
|
2897
|
-
}
|
|
2898
|
-
function typedOrder(locale) {
|
|
2899
|
-
const parts = new Intl.DateTimeFormat(locale, { day: "numeric", month: "numeric", year: "numeric", timeZone: UTC }).formatToParts(new Date(SAMPLE_UTC));
|
|
2900
|
-
return parts.map((part) => PART_OF[part.type]).filter((part) => part !== void 0);
|
|
2901
|
-
}
|
|
2902
|
-
function formatTyped(iso, locale) {
|
|
2903
|
-
const parts = parseIso(iso);
|
|
2904
|
-
if (parts === null) return iso;
|
|
2905
|
-
const text = {
|
|
2906
|
-
["day" /* Day */]: String(parts.day).padStart(PAD3, "0"),
|
|
2907
|
-
["month" /* Month */]: String(parts.month).padStart(PAD3, "0"),
|
|
2908
|
-
["year" /* Year */]: String(parts.year)
|
|
2909
|
-
};
|
|
2910
|
-
return typedOrder(locale).map((part) => text[part]).join("/");
|
|
2911
|
-
}
|
|
2912
|
-
function parseTyped(text, locale) {
|
|
2913
|
-
const trimmed = text.trim();
|
|
2914
|
-
if (ISO_LIKE.test(trimmed)) {
|
|
2915
|
-
const [year = 0, month = 0, day = 0] = trimmed.split("-").map(Number);
|
|
2916
|
-
const parts2 = { year, month, day };
|
|
2917
|
-
return isValidParts(parts2) ? toIso(parts2) : null;
|
|
2918
|
-
}
|
|
2919
|
-
const numbers2 = trimmed.split(/\D+/).filter((piece) => piece !== "").map(Number);
|
|
2920
|
-
if (numbers2.length !== PART_COUNT) return null;
|
|
2921
|
-
const order = typedOrder(locale);
|
|
2922
|
-
const read = (part) => numbers2[order.indexOf(part)] ?? 0;
|
|
2923
|
-
const rawYear = read("year" /* Year */);
|
|
2924
|
-
const parts = { year: rawYear < TWO_DIGIT_YEAR ? CENTURY + rawYear : rawYear, month: read("month" /* Month */), day: read("day" /* Day */) };
|
|
2925
|
-
return isValidParts(parts) ? toIso(parts) : null;
|
|
2926
|
-
}
|
|
2927
|
-
|
|
2928
2940
|
// src/DatePicker/utils/monthGrid.ts
|
|
2929
2941
|
var DAYS_IN_WEEK3 = 7;
|
|
2930
2942
|
var MONDAY5 = 1;
|
|
@@ -3190,13 +3202,13 @@ var ICON_SLOT = { position: "absolute", right: 2, top: 0, bottom: 0, display: "f
|
|
|
3190
3202
|
var anchorStyles = StyleSheet.create({ wrap: { position: "relative", width: "100%" } });
|
|
3191
3203
|
function DatePickerInput({ fieldProps, context, onTypedError }) {
|
|
3192
3204
|
const { label, value, onChange, onSubmit, accessibilityHint, testID, required, disabled = false, min, max } = fieldProps;
|
|
3193
|
-
const { labels } = useDatePickerConfig();
|
|
3205
|
+
const { labels, display } = useDatePickerConfig();
|
|
3194
3206
|
const phone = useIsPhone();
|
|
3195
3207
|
const [open, setOpen] = useState(false);
|
|
3196
3208
|
const anchorRef = useRef(null);
|
|
3197
3209
|
const inputRef = useRef(null);
|
|
3198
3210
|
const bounds = { min, max };
|
|
3199
|
-
const typed = useTypedDate({ value, onChange, bounds, format:
|
|
3211
|
+
const typed = useTypedDate({ value, onChange, bounds, format: displayFormatter(display), onError: onTypedError, editOnType: true });
|
|
3200
3212
|
const edit = typedEditBind(typed);
|
|
3201
3213
|
const { style, focusBind, hoverBind } = useThemedInput({ hasError: context.hasError, editable: !disabled });
|
|
3202
3214
|
const focus = focusBind;
|
|
@@ -3735,6 +3747,71 @@ function useFocusFirstInvalid(refs) {
|
|
|
3735
3747
|
first?.focus();
|
|
3736
3748
|
}, []);
|
|
3737
3749
|
}
|
|
3750
|
+
|
|
3751
|
+
// src/useServerFieldErrors/assignServerErrors.ts
|
|
3752
|
+
function lastSegment(path) {
|
|
3753
|
+
return path.slice(path.lastIndexOf(".") + 1).toLowerCase();
|
|
3754
|
+
}
|
|
3755
|
+
function matchField(path, fields) {
|
|
3756
|
+
const exact = fields.find((field2) => field2 === path);
|
|
3757
|
+
if (exact !== void 0) {
|
|
3758
|
+
return exact;
|
|
3759
|
+
}
|
|
3760
|
+
const key = lastSegment(path);
|
|
3761
|
+
return key === "" ? null : fields.find((field2) => field2.toLowerCase() === key) ?? null;
|
|
3762
|
+
}
|
|
3763
|
+
function messageOf(error, formatCode) {
|
|
3764
|
+
const formatted = error.code !== void 0 && formatCode !== void 0 ? formatCode(error.code, error) : null;
|
|
3765
|
+
return typeof formatted === "string" && formatted !== "" ? formatted : error.message;
|
|
3766
|
+
}
|
|
3767
|
+
function assignServerErrors(errors, fields, formatCode) {
|
|
3768
|
+
const byField = {};
|
|
3769
|
+
let formError = null;
|
|
3770
|
+
for (const error of errors) {
|
|
3771
|
+
const field2 = matchField(error.path, fields);
|
|
3772
|
+
const message = messageOf(error, formatCode);
|
|
3773
|
+
if (field2 === null) {
|
|
3774
|
+
formError = formError ?? message;
|
|
3775
|
+
} else if (byField[field2] === void 0) {
|
|
3776
|
+
byField[field2] = message;
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
const matched = fields.filter((field2) => byField[field2] !== void 0);
|
|
3780
|
+
return { byField, formError, matched };
|
|
3781
|
+
}
|
|
3782
|
+
|
|
3783
|
+
// src/useServerFieldErrors/useServerFieldErrors.ts
|
|
3784
|
+
var EMPTY_STATE = { byField: {}, formError: null };
|
|
3785
|
+
var NO_REFS = {};
|
|
3786
|
+
function withoutField(state, field2) {
|
|
3787
|
+
if (state.byField[field2] === void 0) {
|
|
3788
|
+
return state;
|
|
3789
|
+
}
|
|
3790
|
+
const byField = { ...state.byField };
|
|
3791
|
+
delete byField[field2];
|
|
3792
|
+
return { ...state, byField };
|
|
3793
|
+
}
|
|
3794
|
+
function useServerFieldErrors(options) {
|
|
3795
|
+
const { fields, refs, formatCode } = options;
|
|
3796
|
+
const [state, setState] = useState(EMPTY_STATE);
|
|
3797
|
+
const focusFirst = useFocusFirstInvalid(refs ?? NO_REFS);
|
|
3798
|
+
const hasRefs = refs !== void 0;
|
|
3799
|
+
const apply = useCallback(
|
|
3800
|
+
(error) => {
|
|
3801
|
+
const assigned = assignServerErrors(parseFieldErrors(error), fields, formatCode);
|
|
3802
|
+
setState({ byField: assigned.byField, formError: assigned.formError });
|
|
3803
|
+
if (hasRefs && assigned.matched.length > 0) {
|
|
3804
|
+
focusFirst(assigned.matched);
|
|
3805
|
+
}
|
|
3806
|
+
return assigned.matched.length > 0;
|
|
3807
|
+
},
|
|
3808
|
+
[fields, formatCode, focusFirst, hasRefs]
|
|
3809
|
+
);
|
|
3810
|
+
const clear = useCallback((field2) => setState((current) => withoutField(current, field2)), []);
|
|
3811
|
+
const reset = useCallback(() => setState(EMPTY_STATE), []);
|
|
3812
|
+
const errorFor = useCallback((field2) => state.byField[field2], [state.byField]);
|
|
3813
|
+
return { errorFor, apply, clear, formError: state.formError, reset };
|
|
3814
|
+
}
|
|
3738
3815
|
function isScrollable(node) {
|
|
3739
3816
|
return "scrollIntoView" in Object(node);
|
|
3740
3817
|
}
|
|
@@ -5736,6 +5813,261 @@ function DecisionPanel(props) {
|
|
|
5736
5813
|
] });
|
|
5737
5814
|
}
|
|
5738
5815
|
|
|
5739
|
-
|
|
5816
|
+
// src/PasswordField/PasswordRulesDisplay.ts
|
|
5817
|
+
var PasswordRulesDisplay = /* @__PURE__ */ ((PasswordRulesDisplay2) => {
|
|
5818
|
+
PasswordRulesDisplay2["Checklist"] = "checklist";
|
|
5819
|
+
PasswordRulesDisplay2["MeterGrid"] = "meterGrid";
|
|
5820
|
+
PasswordRulesDisplay2["Chips"] = "chips";
|
|
5821
|
+
PasswordRulesDisplay2["Sentence"] = "sentence";
|
|
5822
|
+
return PasswordRulesDisplay2;
|
|
5823
|
+
})(PasswordRulesDisplay || {});
|
|
5824
|
+
|
|
5825
|
+
// src/PasswordField/RuleTone.ts
|
|
5826
|
+
var RuleTone = /* @__PURE__ */ ((RuleTone2) => {
|
|
5827
|
+
RuleTone2["Met"] = "met";
|
|
5828
|
+
RuleTone2["Unmet"] = "unmet";
|
|
5829
|
+
RuleTone2["Refused"] = "refused";
|
|
5830
|
+
return RuleTone2;
|
|
5831
|
+
})(RuleTone || {});
|
|
5832
|
+
function ruleTone(met, flagUnmet) {
|
|
5833
|
+
if (met) return "met" /* Met */;
|
|
5834
|
+
return flagUnmet ? "refused" /* Refused */ : "unmet" /* Unmet */;
|
|
5835
|
+
}
|
|
5836
|
+
var MARK_SIZE = 16;
|
|
5837
|
+
var CHECK_SIZE = 12;
|
|
5838
|
+
var RING_WIDTH = 1.5;
|
|
5839
|
+
var POP_FROM = 0.6;
|
|
5840
|
+
var POP_PEAK = 1.12;
|
|
5841
|
+
var POP_UP_MS = 160;
|
|
5842
|
+
var POP_SETTLE_MS = 100;
|
|
5843
|
+
var styles38 = StyleSheet.create({
|
|
5844
|
+
mark: { width: MARK_SIZE, height: MARK_SIZE, borderRadius: MARK_SIZE / 2, alignItems: "center", justifyContent: "center" },
|
|
5845
|
+
ring: { borderWidth: RING_WIDTH }
|
|
5846
|
+
});
|
|
5847
|
+
function RuleMark({ tone, colors }) {
|
|
5848
|
+
const reduced = useReducedMotion();
|
|
5849
|
+
const scale = useRef(new Animated.Value(1)).current;
|
|
5850
|
+
const wasMet = useRef(tone === "met" /* Met */);
|
|
5851
|
+
const met = tone === "met" /* Met */;
|
|
5852
|
+
useEffect(() => {
|
|
5853
|
+
const turnedMet = met && !wasMet.current;
|
|
5854
|
+
wasMet.current = met;
|
|
5855
|
+
if (!turnedMet || reduced) return;
|
|
5856
|
+
scale.setValue(POP_FROM);
|
|
5857
|
+
Animated.sequence([
|
|
5858
|
+
Animated.timing(scale, { toValue: POP_PEAK, duration: POP_UP_MS, easing: Easing.out(Easing.cubic), useNativeDriver: false }),
|
|
5859
|
+
Animated.timing(scale, { toValue: 1, duration: POP_SETTLE_MS, easing: Easing.out(Easing.cubic), useNativeDriver: false })
|
|
5860
|
+
]).start();
|
|
5861
|
+
}, [met, reduced, scale]);
|
|
5862
|
+
const color = colors.mark[tone];
|
|
5863
|
+
const shape = met ? { backgroundColor: color } : [styles38.ring, { borderColor: color }];
|
|
5864
|
+
return /* @__PURE__ */ jsx(Animated.View, { style: { transform: [{ scale }] }, children: /* @__PURE__ */ jsx(View, { style: [styles38.mark, shape], children: met ? /* @__PURE__ */ jsx(SvgIcon, { color: colors.onMark, name: "check", size: CHECK_SIZE }) : null }) });
|
|
5865
|
+
}
|
|
5866
|
+
var GAP8 = 6;
|
|
5867
|
+
var ROW_GAP8 = 8;
|
|
5868
|
+
var FONT5 = 14;
|
|
5869
|
+
var LINE = 20;
|
|
5870
|
+
var METER_HEIGHT = 4;
|
|
5871
|
+
var RADIUS3 = 999;
|
|
5872
|
+
var CHIP_PAD_V = 4;
|
|
5873
|
+
var CHIP_PAD_H = 10;
|
|
5874
|
+
var CHIP_BORDER = 1;
|
|
5875
|
+
var HALF4 = "50%";
|
|
5876
|
+
var styles39 = StyleSheet.create({
|
|
5877
|
+
column: { gap: GAP8 },
|
|
5878
|
+
row: { flexDirection: "row", alignItems: "center", gap: ROW_GAP8 },
|
|
5879
|
+
text: { fontSize: FONT5, lineHeight: LINE, flexShrink: 1 },
|
|
5880
|
+
meter: { flexDirection: "row", gap: GAP8 },
|
|
5881
|
+
segment: { flex: 1, height: METER_HEIGHT, borderRadius: RADIUS3 },
|
|
5882
|
+
grid: { flexDirection: "row", flexWrap: "wrap", rowGap: GAP8 },
|
|
5883
|
+
cell: { flexBasis: HALF4, maxWidth: HALF4, paddingRight: GAP8 },
|
|
5884
|
+
chips: { flexDirection: "row", flexWrap: "wrap", gap: GAP8 },
|
|
5885
|
+
chip: { borderRadius: RADIUS3, borderWidth: CHIP_BORDER, paddingVertical: CHIP_PAD_V, paddingHorizontal: CHIP_PAD_H },
|
|
5886
|
+
metPhrase: { fontWeight: "700", textDecorationLine: "underline" }
|
|
5887
|
+
});
|
|
5888
|
+
function RuleList({ rules, flagUnmet, colors, testID, listStyle, itemStyle, outlined = false }) {
|
|
5889
|
+
return /* @__PURE__ */ jsx(View, { role: "list", style: listStyle, testID, children: rules.map((rule) => {
|
|
5890
|
+
const tone = ruleTone(rule.met, flagUnmet);
|
|
5891
|
+
const outline = outlined ? { borderColor: colors.mark[tone] } : null;
|
|
5892
|
+
return /* @__PURE__ */ jsxs(View, { role: "listitem", style: [styles39.row, itemStyle, outline], testID: `${testID}-${rule.id}`, ...{ dataSet: { tone } }, children: [
|
|
5893
|
+
/* @__PURE__ */ jsx(RuleMark, { colors, tone }),
|
|
5894
|
+
/* @__PURE__ */ jsx(Text, { style: [styles39.text, { color: colors.text[tone] }], children: rule.label })
|
|
5895
|
+
] }, rule.id);
|
|
5896
|
+
}) });
|
|
5897
|
+
}
|
|
5898
|
+
function RulesChecklist(props) {
|
|
5899
|
+
return /* @__PURE__ */ jsx(RuleList, { ...props, listStyle: styles39.column });
|
|
5900
|
+
}
|
|
5901
|
+
function RulesChips(props) {
|
|
5902
|
+
return /* @__PURE__ */ jsx(RuleList, { ...props, outlined: true, itemStyle: styles39.chip, listStyle: styles39.chips });
|
|
5903
|
+
}
|
|
5904
|
+
function RulesMeterGrid(props) {
|
|
5905
|
+
const { rules, flagUnmet, colors, testID } = props;
|
|
5906
|
+
const metCount = rules.filter((rule) => rule.met).length;
|
|
5907
|
+
const unfilled = flagUnmet ? colors.mark.refused : colors.track;
|
|
5908
|
+
return /* @__PURE__ */ jsxs(View, { style: styles39.column, children: [
|
|
5909
|
+
/* @__PURE__ */ jsx(View, { style: styles39.meter, testID: `${testID}-meter`, children: rules.map((rule, index) => /* @__PURE__ */ jsx(View, { style: [styles39.segment, { backgroundColor: index < metCount ? colors.mark.met : unfilled }] }, rule.id)) }),
|
|
5910
|
+
/* @__PURE__ */ jsx(RuleList, { ...props, itemStyle: styles39.cell, listStyle: styles39.grid })
|
|
5911
|
+
] });
|
|
5912
|
+
}
|
|
5913
|
+
function RulesSentence({ rules, flagUnmet, colors, testID }) {
|
|
5914
|
+
return /* @__PURE__ */ jsx(Text, { style: [styles39.text, { color: colors.text.unmet }], testID, children: rules.map((rule, index) => {
|
|
5915
|
+
const tone = ruleTone(rule.met, flagUnmet);
|
|
5916
|
+
return /* @__PURE__ */ jsxs(Text, { style: [{ color: colors.text[tone] }, rule.met ? styles39.metPhrase : null], testID: `${testID}-${rule.id}`, ...{ dataSet: { tone } }, children: [
|
|
5917
|
+
index > 0 ? ", " : "",
|
|
5918
|
+
rule.label
|
|
5919
|
+
] }, rule.id);
|
|
5920
|
+
}) });
|
|
5921
|
+
}
|
|
5922
|
+
function PasswordRules({ display, ...variant }) {
|
|
5923
|
+
switch (display) {
|
|
5924
|
+
case "checklist" /* Checklist */:
|
|
5925
|
+
return /* @__PURE__ */ jsx(RulesChecklist, { ...variant });
|
|
5926
|
+
case "chips" /* Chips */:
|
|
5927
|
+
return /* @__PURE__ */ jsx(RulesChips, { ...variant });
|
|
5928
|
+
case "sentence" /* Sentence */:
|
|
5929
|
+
return /* @__PURE__ */ jsx(RulesSentence, { ...variant });
|
|
5930
|
+
default:
|
|
5931
|
+
return /* @__PURE__ */ jsx(RulesMeterGrid, { ...variant });
|
|
5932
|
+
}
|
|
5933
|
+
}
|
|
5934
|
+
var ICON_SIZE = 20;
|
|
5935
|
+
var styles40 = StyleSheet.create({
|
|
5936
|
+
button: { width: MIN_TOUCH_TARGET_PX, height: MIN_TOUCH_TARGET_PX, alignItems: "center", justifyContent: "center" }
|
|
5937
|
+
});
|
|
5938
|
+
function RevealToggle({ revealed, onToggle, onPressIn, showLabel, hideLabel, color, testID }) {
|
|
5939
|
+
const label = revealed ? hideLabel : showLabel;
|
|
5940
|
+
return /* @__PURE__ */ jsx(
|
|
5941
|
+
Pressable,
|
|
5942
|
+
{
|
|
5943
|
+
accessibilityHint: label,
|
|
5944
|
+
accessibilityLabel: label,
|
|
5945
|
+
accessibilityRole: "button",
|
|
5946
|
+
"aria-pressed": revealed,
|
|
5947
|
+
style: styles40.button,
|
|
5948
|
+
testID,
|
|
5949
|
+
onPress: onToggle,
|
|
5950
|
+
onPressIn,
|
|
5951
|
+
children: /* @__PURE__ */ jsx(SvgIcon, { color, name: revealed ? "eyeOff" : "eye", size: ICON_SIZE })
|
|
5952
|
+
}
|
|
5953
|
+
);
|
|
5954
|
+
}
|
|
5955
|
+
|
|
5956
|
+
// src/PasswordField/ruleAnnouncement.ts
|
|
5957
|
+
function changedRules(previous, next) {
|
|
5958
|
+
const before = new Map(previous.map((rule) => [rule.id, rule.met]));
|
|
5959
|
+
return next.filter((rule) => before.has(rule.id) && before.get(rule.id) !== rule.met);
|
|
5960
|
+
}
|
|
5961
|
+
function ruleAnnouncement(changed, labels) {
|
|
5962
|
+
return changed.map((rule) => `${rule.label}: ${rule.met ? labels.met : labels.unmet}`).join(". ");
|
|
5963
|
+
}
|
|
5964
|
+
|
|
5965
|
+
// src/PasswordField/usePasswordRuleAnnouncement.ts
|
|
5966
|
+
function usePasswordRuleAnnouncement(rules, labels) {
|
|
5967
|
+
const previous = useRef(rules);
|
|
5968
|
+
const [message, setMessage] = useState("");
|
|
5969
|
+
useEffect(() => {
|
|
5970
|
+
const changed = changedRules(previous.current, rules);
|
|
5971
|
+
previous.current = rules;
|
|
5972
|
+
if (changed.length > 0) setMessage(ruleAnnouncement(changed, labels));
|
|
5973
|
+
}, [rules, labels]);
|
|
5974
|
+
return message;
|
|
5975
|
+
}
|
|
5976
|
+
function ruleColorsFrom(palette) {
|
|
5977
|
+
return {
|
|
5978
|
+
mark: { ["met" /* Met */]: palette.success, ["unmet" /* Unmet */]: palette.textSecondary, ["refused" /* Refused */]: palette.error },
|
|
5979
|
+
text: { ["met" /* Met */]: palette.text, ["unmet" /* Unmet */]: palette.textSecondary, ["refused" /* Refused */]: palette.error },
|
|
5980
|
+
track: palette.border,
|
|
5981
|
+
onMark: palette.background
|
|
5982
|
+
};
|
|
5983
|
+
}
|
|
5984
|
+
function useRuleColors(override) {
|
|
5985
|
+
const { theme } = useUi();
|
|
5986
|
+
return useMemo(() => {
|
|
5987
|
+
if (override !== void 0) return ruleColorsFrom(override);
|
|
5988
|
+
return ruleColorsFrom({
|
|
5989
|
+
success: theme.semantic.success?.["500"] ?? theme.colors.text,
|
|
5990
|
+
error: theme.semantic.error["500"],
|
|
5991
|
+
text: theme.colors.text,
|
|
5992
|
+
textSecondary: theme.colors.textSecondary,
|
|
5993
|
+
border: theme.colors.border,
|
|
5994
|
+
background: theme.colors.background
|
|
5995
|
+
});
|
|
5996
|
+
}, [theme, override]);
|
|
5997
|
+
}
|
|
5998
|
+
var RULES_GAP = 8;
|
|
5999
|
+
var TOGGLE_INSET = 48;
|
|
6000
|
+
var NO_RULES = [];
|
|
6001
|
+
var styles41 = StyleSheet.create({
|
|
6002
|
+
inputRow: { position: "relative", justifyContent: "center" },
|
|
6003
|
+
input: { paddingRight: TOGGLE_INSET },
|
|
6004
|
+
toggle: { position: "absolute", right: 0, top: 0, bottom: 0, justifyContent: "center" },
|
|
6005
|
+
rules: { marginTop: RULES_GAP },
|
|
6006
|
+
live: { position: "absolute", width: 1, height: 1, overflow: "hidden", opacity: 0 }
|
|
6007
|
+
});
|
|
6008
|
+
function joinIds(...ids) {
|
|
6009
|
+
const joined = ids.filter((id) => id !== void 0 && id !== "").join(" ");
|
|
6010
|
+
return joined === "" ? void 0 : joined;
|
|
6011
|
+
}
|
|
6012
|
+
function useCaretKeepingToggle(inputRef, initialLength) {
|
|
6013
|
+
const [revealed, setRevealed] = useState(false);
|
|
6014
|
+
const selection2 = useRef({ start: initialLength, end: initialLength });
|
|
6015
|
+
const hadFocus = useRef(false);
|
|
6016
|
+
const onSelectionChange = useCallback((event) => {
|
|
6017
|
+
selection2.current = event.nativeEvent.selection;
|
|
6018
|
+
}, []);
|
|
6019
|
+
const onPressIn = useCallback(() => {
|
|
6020
|
+
hadFocus.current = inputRef.current?.isFocused?.() ?? false;
|
|
6021
|
+
}, [inputRef]);
|
|
6022
|
+
const onToggle = useCallback(() => {
|
|
6023
|
+
setRevealed((current) => !current);
|
|
6024
|
+
if (!hadFocus.current) return;
|
|
6025
|
+
const node = inputRef.current;
|
|
6026
|
+
const { start, end } = selection2.current;
|
|
6027
|
+
requestAnimationFrame(() => {
|
|
6028
|
+
node?.focus();
|
|
6029
|
+
node?.setSelectionRange?.(start, end);
|
|
6030
|
+
});
|
|
6031
|
+
}, [inputRef]);
|
|
6032
|
+
return { revealed, onPressIn, onToggle, onSelectionChange };
|
|
6033
|
+
}
|
|
6034
|
+
var PasswordField = React37.forwardRef(function PasswordField2({ label, value, onChangeText, labels, testID, rules = NO_RULES, rulesDisplay = "meterGrid" /* MeterGrid */, flagUnmet = false, error, colors: colorOverride, inputProps }, ref) {
|
|
6035
|
+
const inputRef = useRef(null);
|
|
6036
|
+
useImperativeHandle(ref, () => inputRef.current);
|
|
6037
|
+
const toggle2 = useCaretKeepingToggle(inputRef, value.length);
|
|
6038
|
+
const colors = useRuleColors(colorOverride);
|
|
6039
|
+
const announcement = usePasswordRuleAnnouncement(rules, labels);
|
|
6040
|
+
const rulesId = `${testID}-rules`;
|
|
6041
|
+
const hasRules = rules.length > 0;
|
|
6042
|
+
return /* @__PURE__ */ jsx(Field, { error, label, testID: `${testID}-field`, children: (context) => /* @__PURE__ */ jsxs(View, { children: [
|
|
6043
|
+
/* @__PURE__ */ jsxs(View, { style: styles41.inputRow, children: [
|
|
6044
|
+
/* @__PURE__ */ jsx(
|
|
6045
|
+
ThemedTextInput,
|
|
6046
|
+
{
|
|
6047
|
+
autoCapitalize: "none",
|
|
6048
|
+
autoCorrect: false,
|
|
6049
|
+
...inputProps,
|
|
6050
|
+
ref: inputRef,
|
|
6051
|
+
describedById: joinIds(context.describedById, hasRules ? rulesId : void 0),
|
|
6052
|
+
hasError: context.hasError || flagUnmet && rules.some((rule) => !rule.met),
|
|
6053
|
+
id: context.controlId,
|
|
6054
|
+
secureTextEntry: !toggle2.revealed,
|
|
6055
|
+
style: [styles41.input, inputProps?.style],
|
|
6056
|
+
testID,
|
|
6057
|
+
value,
|
|
6058
|
+
onChangeText,
|
|
6059
|
+
onSelectionChange: toggle2.onSelectionChange
|
|
6060
|
+
}
|
|
6061
|
+
),
|
|
6062
|
+
/* @__PURE__ */ jsx(View, { style: styles41.toggle, children: /* @__PURE__ */ jsx(RevealToggle, { color: colors.text.unmet, hideLabel: labels.hide, revealed: toggle2.revealed, showLabel: labels.show, testID: `${testID}-reveal`, onPressIn: toggle2.onPressIn, onToggle: toggle2.onToggle }) })
|
|
6063
|
+
] }),
|
|
6064
|
+
hasRules ? /* @__PURE__ */ jsxs(View, { nativeID: rulesId, style: styles41.rules, children: [
|
|
6065
|
+
/* @__PURE__ */ jsx(PasswordRules, { colors, display: rulesDisplay, flagUnmet, rules, testID: rulesId }),
|
|
6066
|
+
/* @__PURE__ */ jsx(Text, { "aria-live": "polite", accessibilityLiveRegion: "polite", style: styles41.live, testID: `${testID}-announce`, children: announcement })
|
|
6067
|
+
] }) : null
|
|
6068
|
+
] }) });
|
|
6069
|
+
});
|
|
6070
|
+
|
|
6071
|
+
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, PHONE_MAX_WIDTH, PasswordField, PasswordRules, PasswordRulesDisplay, RESPONSIVE_FORM_DEFAULT_BREAKPOINT, RadioList, ResponsiveFormLayout, RevealToggle, RuleTone, SEGMENT_BESIDE_FIELD, SEGMENT_BESIDE_TEXT_INPUT, SearchSelect, SelectControl, SelectField, 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, suggestOptions, toCountryValue, toggleGroupSelection, useAutoGrowRows, useBlurVerdict, useDeferredFocus, useFocusFirstInvalid, useKeepInView, useOutsidePress, useRecentValues, useReducedMotion, useSearchSelectState, useServerFieldErrors, useThemedInput, validateBic, validateDecision, validateIban };
|
|
5740
6072
|
//# sourceMappingURL=index.mjs.map
|
|
5741
6073
|
//# sourceMappingURL=index.mjs.map
|