@dloizides/ui-forms 1.21.0 → 1.22.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 +67 -1
- package/dist/index.d.ts +67 -1
- package/dist/index.js +190 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +189 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React2, { useState, useCallback, useMemo, useEffect, useRef, useLayoutEffect } from 'react';
|
|
2
|
-
import { Platform, StyleSheet, TextInput, View, Text, useWindowDimensions, ScrollView, Pressable, Switch, TouchableOpacity } from 'react-native';
|
|
2
|
+
import { Platform, StyleSheet, TextInput, View, Text, useWindowDimensions, ScrollView, Pressable, Switch, Image, TouchableOpacity } 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 } from '@dloizides/design-tokens';
|
|
6
|
-
import { themeFocusRingColor, Button } from '@dloizides/ui-buttons';
|
|
6
|
+
import { themeFocusRingColor, Button, useFocusRing } from '@dloizides/ui-buttons';
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
8
8
|
import { MIN_TOUCH_TARGET_PX } from '@dloizides/a11y';
|
|
9
9
|
|
|
@@ -1854,7 +1854,193 @@ function toggleGroupSelection(selected, groupKeys, order) {
|
|
|
1854
1854
|
});
|
|
1855
1855
|
return order === void 0 ? merged : order.filter((key) => merged.includes(key));
|
|
1856
1856
|
}
|
|
1857
|
+
var ROW_GAP = 4;
|
|
1858
|
+
var TAB_PADDING = 4;
|
|
1859
|
+
var INDICATOR_WIDTH = 2;
|
|
1860
|
+
var TAB_FONT_SIZE = 12;
|
|
1861
|
+
var styles10 = StyleSheet.create({
|
|
1862
|
+
row: { flexDirection: "row", flexWrap: "nowrap", gap: ROW_GAP },
|
|
1863
|
+
tab: {
|
|
1864
|
+
borderBottomWidth: INDICATOR_WIDTH,
|
|
1865
|
+
flexBasis: 0,
|
|
1866
|
+
flexGrow: 1,
|
|
1867
|
+
flexShrink: 1,
|
|
1868
|
+
justifyContent: "center",
|
|
1869
|
+
minHeight: MIN_TOUCH_TARGET_PX,
|
|
1870
|
+
minWidth: 0,
|
|
1871
|
+
paddingHorizontal: TAB_PADDING
|
|
1872
|
+
},
|
|
1873
|
+
text: { fontSize: TAB_FONT_SIZE, textAlign: "center" },
|
|
1874
|
+
textSelected: { fontWeight: "700" }
|
|
1875
|
+
});
|
|
1876
|
+
var StepperTab = ({
|
|
1877
|
+
step,
|
|
1878
|
+
selected,
|
|
1879
|
+
hint,
|
|
1880
|
+
onStep,
|
|
1881
|
+
testID
|
|
1882
|
+
}) => {
|
|
1883
|
+
const { theme } = useUi();
|
|
1884
|
+
const ring = useFocusRing();
|
|
1885
|
+
const indicator = selected ? theme.palette.primary["500"] : theme.colors.border;
|
|
1886
|
+
const webKeyProps = {
|
|
1887
|
+
onKeyDown: (event) => {
|
|
1888
|
+
if (event.key !== " ") return;
|
|
1889
|
+
event.preventDefault?.();
|
|
1890
|
+
onStep(step.key);
|
|
1891
|
+
}
|
|
1892
|
+
};
|
|
1893
|
+
return /* @__PURE__ */ jsx(
|
|
1894
|
+
Pressable,
|
|
1895
|
+
{
|
|
1896
|
+
accessibilityHint: hint,
|
|
1897
|
+
accessibilityLabel: step.label,
|
|
1898
|
+
accessibilityRole: "tab",
|
|
1899
|
+
accessibilityState: { selected },
|
|
1900
|
+
"aria-selected": selected,
|
|
1901
|
+
style: [styles10.tab, { borderBottomColor: indicator }, ring.ringStyle],
|
|
1902
|
+
testID,
|
|
1903
|
+
onBlur: ring.onBlur,
|
|
1904
|
+
onFocus: ring.onFocus,
|
|
1905
|
+
onPress: () => onStep(step.key),
|
|
1906
|
+
...webKeyProps,
|
|
1907
|
+
children: /* @__PURE__ */ jsx(Text, { style: [styles10.text, { color: theme.colors.text }, selected ? styles10.textSelected : void 0], children: step.label })
|
|
1908
|
+
}
|
|
1909
|
+
);
|
|
1910
|
+
};
|
|
1911
|
+
var StepperTabs = ({
|
|
1912
|
+
steps,
|
|
1913
|
+
current,
|
|
1914
|
+
onStep,
|
|
1915
|
+
stepHint,
|
|
1916
|
+
testID
|
|
1917
|
+
}) => /* @__PURE__ */ jsx(View, { accessibilityRole: "tablist", style: styles10.row, testID, children: steps.map((step) => /* @__PURE__ */ jsx(
|
|
1918
|
+
StepperTab,
|
|
1919
|
+
{
|
|
1920
|
+
hint: stepHint,
|
|
1921
|
+
selected: step.key === current,
|
|
1922
|
+
step,
|
|
1923
|
+
testID: `${testID}-${step.key}`,
|
|
1924
|
+
onStep
|
|
1925
|
+
},
|
|
1926
|
+
step.key
|
|
1927
|
+
)) });
|
|
1928
|
+
|
|
1929
|
+
// src/Stepper/stepperModel.ts
|
|
1930
|
+
function resolveStepNeighbours(steps, current) {
|
|
1931
|
+
const index = steps.findIndex((step) => step.key === current);
|
|
1932
|
+
if (index < 0) return { previous: null, next: null };
|
|
1933
|
+
return { previous: steps[index - 1] ?? null, next: steps[index + 1] ?? null };
|
|
1934
|
+
}
|
|
1935
|
+
var ROW_GAP2 = 8;
|
|
1936
|
+
var styles11 = StyleSheet.create({
|
|
1937
|
+
cell: { flex: 1, minWidth: 0 },
|
|
1938
|
+
row: { flexDirection: "row", gap: ROW_GAP2 }
|
|
1939
|
+
});
|
|
1940
|
+
var StepperNav = ({
|
|
1941
|
+
steps,
|
|
1942
|
+
current,
|
|
1943
|
+
onStep,
|
|
1944
|
+
labels,
|
|
1945
|
+
testID
|
|
1946
|
+
}) => {
|
|
1947
|
+
const { previous, next } = resolveStepNeighbours(steps, current);
|
|
1948
|
+
return /* @__PURE__ */ jsxs(View, { style: styles11.row, testID, children: [
|
|
1949
|
+
/* @__PURE__ */ jsx(View, { style: styles11.cell, children: /* @__PURE__ */ jsx(
|
|
1950
|
+
Button,
|
|
1951
|
+
{
|
|
1952
|
+
fullWidth: true,
|
|
1953
|
+
accessibilityHint: labels.backHint,
|
|
1954
|
+
accessibilityLabel: labels.back,
|
|
1955
|
+
autoLoading: false,
|
|
1956
|
+
disabled: previous === null,
|
|
1957
|
+
label: labels.back,
|
|
1958
|
+
testID: `${testID}-back`,
|
|
1959
|
+
variant: "outline",
|
|
1960
|
+
onPress: () => {
|
|
1961
|
+
if (previous !== null) onStep(previous.key);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
) }),
|
|
1965
|
+
next === null ? null : /* @__PURE__ */ jsx(View, { style: styles11.cell, children: /* @__PURE__ */ jsx(
|
|
1966
|
+
Button,
|
|
1967
|
+
{
|
|
1968
|
+
fullWidth: true,
|
|
1969
|
+
accessibilityHint: labels.nextHint,
|
|
1970
|
+
accessibilityLabel: labels.next(next),
|
|
1971
|
+
autoLoading: false,
|
|
1972
|
+
label: labels.next(next),
|
|
1973
|
+
testID: `${testID}-next`,
|
|
1974
|
+
onPress: () => onStep(next.key)
|
|
1975
|
+
}
|
|
1976
|
+
) })
|
|
1977
|
+
] });
|
|
1978
|
+
};
|
|
1979
|
+
var DEFAULT_PREVIEW_PX = 48;
|
|
1980
|
+
var PREVIEW_RADIUS = 8;
|
|
1981
|
+
var GAP = 8;
|
|
1982
|
+
var TITLE_FONT_SIZE = 14;
|
|
1983
|
+
var HELP_FONT_SIZE = 13;
|
|
1984
|
+
var styles12 = StyleSheet.create({
|
|
1985
|
+
help: { flex: 1, fontSize: HELP_FONT_SIZE },
|
|
1986
|
+
root: { gap: GAP },
|
|
1987
|
+
tile: { alignItems: "center", flexDirection: "row", gap: GAP },
|
|
1988
|
+
title: { fontSize: TITLE_FONT_SIZE, fontWeight: "700" },
|
|
1989
|
+
toggle: { alignSelf: "flex-start", justifyContent: "center", minHeight: MIN_TOUCH_TARGET_PX },
|
|
1990
|
+
toggleText: { fontSize: TITLE_FONT_SIZE, fontWeight: "700", textDecorationLine: "underline" }
|
|
1991
|
+
});
|
|
1992
|
+
var UploadWithLinkField = ({
|
|
1993
|
+
value,
|
|
1994
|
+
onChange,
|
|
1995
|
+
labels,
|
|
1996
|
+
uploadControl,
|
|
1997
|
+
testID,
|
|
1998
|
+
disabled = false,
|
|
1999
|
+
previewSize = DEFAULT_PREVIEW_PX
|
|
2000
|
+
}) => {
|
|
2001
|
+
const { theme } = useUi();
|
|
2002
|
+
const ring = useFocusRing();
|
|
2003
|
+
const url = value ?? "";
|
|
2004
|
+
const [pasting, setPasting] = useState(url !== "");
|
|
2005
|
+
const previewBox = { borderRadius: PREVIEW_RADIUS, height: previewSize, width: previewSize };
|
|
2006
|
+
return /* @__PURE__ */ jsxs(View, { style: styles12.root, children: [
|
|
2007
|
+
/* @__PURE__ */ jsx(Text, { style: [styles12.title, { color: theme.colors.text }], children: labels.title }),
|
|
2008
|
+
/* @__PURE__ */ jsxs(View, { style: styles12.tile, children: [
|
|
2009
|
+
url === "" ? /* @__PURE__ */ jsx(View, { style: [previewBox, { backgroundColor: theme.colors.border }] }) : /* @__PURE__ */ jsx(Image, { accessible: false, source: { uri: url }, style: previewBox, testID: `${testID}-preview` }),
|
|
2010
|
+
labels.help === void 0 ? null : /* @__PURE__ */ jsx(Text, { style: [styles12.help, { color: theme.colors.text }], children: labels.help })
|
|
2011
|
+
] }),
|
|
2012
|
+
uploadControl,
|
|
2013
|
+
/* @__PURE__ */ jsx(
|
|
2014
|
+
Pressable,
|
|
2015
|
+
{
|
|
2016
|
+
accessibilityHint: labels.pasteToggleHint,
|
|
2017
|
+
accessibilityLabel: labels.pasteToggle,
|
|
2018
|
+
accessibilityRole: "button",
|
|
2019
|
+
accessibilityState: { expanded: pasting },
|
|
2020
|
+
"aria-expanded": pasting,
|
|
2021
|
+
style: [styles12.toggle, ring.ringStyle],
|
|
2022
|
+
testID: `${testID}-paste`,
|
|
2023
|
+
onBlur: ring.onBlur,
|
|
2024
|
+
onFocus: ring.onFocus,
|
|
2025
|
+
onPress: () => setPasting(!pasting),
|
|
2026
|
+
children: /* @__PURE__ */ jsx(Text, { style: [styles12.toggleText, { color: theme.colors.text }], children: labels.pasteToggle })
|
|
2027
|
+
}
|
|
2028
|
+
),
|
|
2029
|
+
pasting ? /* @__PURE__ */ jsx(
|
|
2030
|
+
FormField,
|
|
2031
|
+
{
|
|
2032
|
+
accessibilityHint: labels.linkHint,
|
|
2033
|
+
editable: !disabled,
|
|
2034
|
+
label: labels.link,
|
|
2035
|
+
placeholder: labels.linkPlaceholder,
|
|
2036
|
+
testID,
|
|
2037
|
+
value: url,
|
|
2038
|
+
onChangeText: onChange
|
|
2039
|
+
}
|
|
2040
|
+
) : null
|
|
2041
|
+
] });
|
|
2042
|
+
};
|
|
1857
2043
|
|
|
1858
|
-
export { AlignToControl, AnchoredMenu, ChipSelector, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateRangeControl, Field, FormActions, FormCell, FormCheckbox, FormField, FormGrid, FormSection, FormSwitch, INLINE_FIELD_ROW_MIN_WIDTH, InlineFieldRow, SelectControl, ThemedTextInput, TypeaheadControl, controlStyles, groupAriaChecked, inlineFieldRowLayout, isUnmatched, resolveGroupSelection, suggestOptions, toggleGroupSelection, useRecentValues, useThemedInput };
|
|
2044
|
+
export { AlignToControl, AnchoredMenu, ChipSelector, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateRangeControl, Field, FormActions, FormCell, FormCheckbox, FormField, FormGrid, FormSection, FormSwitch, INLINE_FIELD_ROW_MIN_WIDTH, InlineFieldRow, SelectControl, StepperNav, StepperTabs, ThemedTextInput, TypeaheadControl, UploadWithLinkField, controlStyles, groupAriaChecked, inlineFieldRowLayout, isUnmatched, resolveGroupSelection, resolveStepNeighbours, suggestOptions, toggleGroupSelection, useRecentValues, useThemedInput };
|
|
1859
2045
|
//# sourceMappingURL=index.mjs.map
|
|
1860
2046
|
//# sourceMappingURL=index.mjs.map
|