@dloizides/ui-forms 1.47.0 → 1.48.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
@@ -6,9 +6,9 @@ import { Z_INDEX, focusRingOutline, readableScaleInk, resolveOnBrand } from '@dl
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 { SvgIcon } from '@dloizides/ui-icons';
9
10
  import { parseFieldErrors } from '@dloizides/api-client-base';
10
11
  import Svg, { Rect, Circle, Polygon } from 'react-native-svg';
11
- import { SvgIcon } from '@dloizides/ui-icons';
12
12
 
13
13
  // src/Field/Field.tsx
14
14
  function attachControlId(child, candidateId, describedById) {
@@ -1410,19 +1410,57 @@ function chipLabelLayout(labelWrap) {
1410
1410
  return { boxStyle: CAPPED_BOX, textStyle: SHRINKING_TEXT, numberOfLines: SINGLE_LINE };
1411
1411
  return { boxStyle: void 0, textStyle: void 0, numberOfLines: void 0 };
1412
1412
  }
1413
+ var MIN_TARGET_PX = 44;
1414
+ var COMPACT_PAD_V = 4;
1415
+ var COMPACT_PAD_H = 10;
1416
+ var COMPACT_FONT_SIZE = 12;
1417
+ var COMPACT_LINE_HEIGHT = 18;
1418
+ var CHIP_BORDER = 1;
1419
+ var chipSizeStyles = StyleSheet.create({
1420
+ compactHitBox: {
1421
+ minHeight: MIN_TARGET_PX,
1422
+ minWidth: MIN_TARGET_PX,
1423
+ justifyContent: "center",
1424
+ alignItems: "center"
1425
+ },
1426
+ compactVisual: {
1427
+ paddingVertical: COMPACT_PAD_V,
1428
+ paddingHorizontal: COMPACT_PAD_H,
1429
+ minHeight: 0,
1430
+ minWidth: 0,
1431
+ borderWidth: CHIP_BORDER
1432
+ },
1433
+ compactText: {
1434
+ fontSize: COMPACT_FONT_SIZE,
1435
+ fontWeight: "600",
1436
+ lineHeight: COMPACT_LINE_HEIGHT
1437
+ }
1438
+ });
1439
+
1440
+ // src/ChipSelector/utils/chipLook.ts
1441
+ function chipFill({ selected, selectedFill, ink, rest }) {
1442
+ if (!selected || selectedFill === void 0)
1443
+ return { ...rest, checkColor: void 0 };
1444
+ return { backgroundColor: selectedFill, textColor: ink, checkColor: ink };
1445
+ }
1446
+ function chipSizeLook(size) {
1447
+ if (size !== "compact")
1448
+ return { hitBox: void 0, visual: void 0, text: void 0 };
1449
+ return { hitBox: chipSizeStyles.compactHitBox, visual: chipSizeStyles.compactVisual, text: chipSizeStyles.compactText };
1450
+ }
1413
1451
  var SOLID_RADIUS = 20;
1414
1452
  var OUTLINE_RADIUS = 999;
1415
1453
  var OUTLINE_PAD_H = 12;
1416
1454
  var OUTLINE_PAD_V = 5;
1417
1455
  var OUTLINE_FONT_SIZE = 13;
1418
1456
  var CHIP_ICON_GAP = 6;
1419
- var MIN_TARGET_PX = 44;
1457
+ var MIN_TARGET_PX2 = 44;
1420
1458
  var chipStyles = StyleSheet.create({
1421
1459
  chip: {
1422
1460
  paddingHorizontal: 12,
1423
1461
  paddingVertical: 6,
1424
- minHeight: MIN_TARGET_PX,
1425
- minWidth: MIN_TARGET_PX,
1462
+ minHeight: MIN_TARGET_PX2,
1463
+ minWidth: MIN_TARGET_PX2,
1426
1464
  justifyContent: "center",
1427
1465
  borderRadius: SOLID_RADIUS,
1428
1466
  backgroundColor: TRANSPARENT_COLOR,
@@ -1431,8 +1469,8 @@ var chipStyles = StyleSheet.create({
1431
1469
  chipOutline: {
1432
1470
  paddingHorizontal: OUTLINE_PAD_H,
1433
1471
  paddingVertical: OUTLINE_PAD_V,
1434
- minHeight: MIN_TARGET_PX,
1435
- minWidth: MIN_TARGET_PX,
1472
+ minHeight: MIN_TARGET_PX2,
1473
+ minWidth: MIN_TARGET_PX2,
1436
1474
  justifyContent: "center",
1437
1475
  borderRadius: OUTLINE_RADIUS,
1438
1476
  borderWidth: 1
@@ -1441,12 +1479,16 @@ var chipStyles = StyleSheet.create({
1441
1479
  chipText: {},
1442
1480
  chipTextOutline: { fontSize: OUTLINE_FONT_SIZE }
1443
1481
  });
1444
- function ChipContent({ icon, label, textStyle, numberOfLines }) {
1482
+ var CHECK_SIZE = 12;
1483
+ function ChipContent(props) {
1484
+ const { icon, label, textStyle, numberOfLines, checkColor } = props;
1445
1485
  const text = /* @__PURE__ */ jsx(Text, { numberOfLines, style: textStyle, children: label });
1446
- if (icon === void 0 || icon === null)
1486
+ const hasIcon = icon !== void 0 && icon !== null;
1487
+ if (!hasIcon && checkColor === void 0)
1447
1488
  return text;
1448
1489
  return /* @__PURE__ */ jsxs(View, { style: chipStyles.chipContent, children: [
1449
- /* @__PURE__ */ jsx(View, { "aria-hidden": true, children: icon }),
1490
+ checkColor === void 0 ? null : /* @__PURE__ */ jsx(View, { "aria-hidden": true, testID: props.checkTestID, children: /* @__PURE__ */ jsx(SvgIcon, { color: checkColor, name: "check", size: CHECK_SIZE }) }),
1491
+ hasIcon ? /* @__PURE__ */ jsx(View, { "aria-hidden": true, children: icon }) : null,
1450
1492
  text
1451
1493
  ] });
1452
1494
  }
@@ -1455,8 +1497,13 @@ function OutlineChip(props) {
1455
1497
  const [hovered, setHovered] = React38.useState(false);
1456
1498
  const active = selected || hovered;
1457
1499
  const borderColor = active ? colors.primary : colors.border;
1458
- const backgroundColor = selected ? colors.tint : colors.muted;
1459
- const textColor = active ? colors.primary : colors.textMuted;
1500
+ const fill = chipFill({
1501
+ selected,
1502
+ selectedFill: props.selectedFill,
1503
+ ink: colors.textStrong,
1504
+ rest: { backgroundColor: selected ? colors.tint : colors.muted, textColor: active ? colors.primary : colors.textMuted }
1505
+ });
1506
+ const sized = chipSizeLook(props.size);
1460
1507
  const layout = chipLabelLayout(option.labelWrap);
1461
1508
  return /* @__PURE__ */ jsx(
1462
1509
  Pressable,
@@ -1470,19 +1517,21 @@ function OutlineChip(props) {
1470
1517
  "aria-pressed": props.ariaPressed,
1471
1518
  disabled,
1472
1519
  hitSlop: CHIP_HIT_SLOP,
1473
- style: layout.boxStyle,
1520
+ style: [sized.hitBox, layout.boxStyle],
1474
1521
  tabIndex: props.tabIndex,
1475
1522
  testID,
1476
1523
  onHoverIn: () => setHovered(true),
1477
1524
  onHoverOut: () => setHovered(false),
1478
1525
  onPress,
1479
- children: /* @__PURE__ */ jsx(View, { style: [chipStyles.chipOutline, { borderColor, backgroundColor }, layout.boxStyle], children: /* @__PURE__ */ jsx(
1526
+ children: /* @__PURE__ */ jsx(View, { style: [chipStyles.chipOutline, sized.visual, { borderColor, backgroundColor: fill.backgroundColor }, layout.boxStyle], children: /* @__PURE__ */ jsx(
1480
1527
  ChipContent,
1481
1528
  {
1529
+ checkColor: fill.checkColor,
1530
+ checkTestID: `${testID}-check`,
1482
1531
  icon: option.icon,
1483
1532
  label: option.label,
1484
1533
  numberOfLines: layout.numberOfLines,
1485
- textStyle: [chipStyles.chipText, chipStyles.chipTextOutline, { color: textColor }, layout.textStyle]
1534
+ textStyle: [chipStyles.chipText, chipStyles.chipTextOutline, sized.text, { color: fill.textColor }, layout.textStyle]
1486
1535
  }
1487
1536
  ) })
1488
1537
  }
@@ -1490,8 +1539,13 @@ function OutlineChip(props) {
1490
1539
  }
1491
1540
  function SolidChip(props) {
1492
1541
  const { option, selected, disabled, colors, testID, accessibilityHint, onPress } = props;
1493
- const backgroundColor = selected ? colors.primary : TRANSPARENT_COLOR;
1494
- const textColor = selected ? colors.onPrimary : colors.textStrong;
1542
+ const fill = chipFill({
1543
+ selected,
1544
+ selectedFill: props.selectedFill,
1545
+ ink: colors.textStrong,
1546
+ rest: { backgroundColor: selected ? colors.primary : TRANSPARENT_COLOR, textColor: selected ? colors.onPrimary : colors.textStrong }
1547
+ });
1548
+ const sized = chipSizeLook(props.size);
1495
1549
  const layout = chipLabelLayout(option.labelWrap);
1496
1550
  const rovingTabStop = { tabIndex: props.tabIndex };
1497
1551
  return /* @__PURE__ */ jsx(
@@ -1506,17 +1560,19 @@ function SolidChip(props) {
1506
1560
  "aria-pressed": props.ariaPressed,
1507
1561
  disabled,
1508
1562
  hitSlop: CHIP_HIT_SLOP,
1509
- style: layout.boxStyle,
1563
+ style: [sized.hitBox, layout.boxStyle],
1510
1564
  testID,
1511
1565
  onPress,
1512
1566
  ...rovingTabStop,
1513
- children: /* @__PURE__ */ jsx(View, { style: [chipStyles.chip, { borderColor: colors.border, backgroundColor }, layout.boxStyle], children: /* @__PURE__ */ jsx(
1567
+ children: /* @__PURE__ */ jsx(View, { style: [chipStyles.chip, sized.visual, { borderColor: colors.border, backgroundColor: fill.backgroundColor }, layout.boxStyle], children: /* @__PURE__ */ jsx(
1514
1568
  ChipContent,
1515
1569
  {
1570
+ checkColor: fill.checkColor,
1571
+ checkTestID: `${testID}-check`,
1516
1572
  icon: option.icon,
1517
1573
  label: option.label,
1518
1574
  numberOfLines: layout.numberOfLines,
1519
- textStyle: [chipStyles.chipText, { color: textColor }, layout.textStyle]
1575
+ textStyle: [chipStyles.chipText, sized.text, { color: fill.textColor }, layout.textStyle]
1520
1576
  }
1521
1577
  ) })
1522
1578
  }
@@ -1661,7 +1717,9 @@ var ChipSelector = ({
1661
1717
  testID,
1662
1718
  chipTestIDPrefix = DEFAULT_CHIP_TESTID_PREFIX,
1663
1719
  optionAccessibilityHint,
1664
- singleSelectRole = "button"
1720
+ singleSelectRole = "button",
1721
+ size = "default",
1722
+ selectedFill
1665
1723
  }) => {
1666
1724
  const isRadioGroup = !multiple && singleSelectRole === "radio";
1667
1725
  const { theme } = useUi();
@@ -1686,6 +1744,8 @@ var ChipSelector = ({
1686
1744
  disabled,
1687
1745
  option,
1688
1746
  selected,
1747
+ size,
1748
+ selectedFill,
1689
1749
  ...chipIdentity(option, selected, {
1690
1750
  prefix: chipTestIDPrefix,
1691
1751
  hint: optionAccessibilityHint,
@@ -5676,7 +5736,7 @@ var GatedChecklist = ({ title, items, checked, onToggle, testID, disabled = fals
5676
5736
  children?.(complete)
5677
5737
  ] });
5678
5738
  };
5679
- var MIN_TARGET_PX2 = 44;
5739
+ var MIN_TARGET_PX3 = 44;
5680
5740
  var DOT_SIZE = 18;
5681
5741
  var DOT_INNER = 8;
5682
5742
  var ROW_GAP6 = 10;
@@ -5693,7 +5753,7 @@ var styles35 = StyleSheet.create({
5693
5753
  borderWidth: 1,
5694
5754
  columnGap: ROW_GAP6,
5695
5755
  flexDirection: "row",
5696
- minHeight: MIN_TARGET_PX2,
5756
+ minHeight: MIN_TARGET_PX3,
5697
5757
  paddingHorizontal: PAD_H2,
5698
5758
  paddingVertical: PAD_V2
5699
5759
  },
@@ -5984,7 +6044,7 @@ function ruleTone(met, flagUnmet) {
5984
6044
  return flagUnmet ? "refused" /* Refused */ : "unmet" /* Unmet */;
5985
6045
  }
5986
6046
  var MARK_SIZE = 16;
5987
- var CHECK_SIZE = 12;
6047
+ var CHECK_SIZE2 = 12;
5988
6048
  var RING_WIDTH = 1.5;
5989
6049
  var POP_FROM = 0.6;
5990
6050
  var POP_PEAK = 1.12;
@@ -6011,7 +6071,7 @@ function RuleMark({ tone, colors }) {
6011
6071
  }, [met, reduced, scale]);
6012
6072
  const color = colors.mark[tone];
6013
6073
  const shape = met ? { backgroundColor: color } : [styles40.ring, { borderColor: color }];
6014
- return /* @__PURE__ */ jsx(Animated.View, { style: { transform: [{ scale }] }, children: /* @__PURE__ */ jsx(View, { style: [styles40.mark, shape], children: met ? /* @__PURE__ */ jsx(SvgIcon, { color: colors.onMark, name: "check", size: CHECK_SIZE }) : null }) });
6074
+ return /* @__PURE__ */ jsx(Animated.View, { style: { transform: [{ scale }] }, children: /* @__PURE__ */ jsx(View, { style: [styles40.mark, shape], children: met ? /* @__PURE__ */ jsx(SvgIcon, { color: colors.onMark, name: "check", size: CHECK_SIZE2 }) : null }) });
6015
6075
  }
6016
6076
  var GAP8 = 6;
6017
6077
  var ROW_GAP8 = 8;
@@ -6021,7 +6081,7 @@ var METER_HEIGHT = 4;
6021
6081
  var RADIUS3 = 999;
6022
6082
  var CHIP_PAD_V2 = 4;
6023
6083
  var CHIP_PAD_H2 = 10;
6024
- var CHIP_BORDER = 1;
6084
+ var CHIP_BORDER2 = 1;
6025
6085
  var HALF4 = "50%";
6026
6086
  var styles41 = StyleSheet.create({
6027
6087
  column: { gap: GAP8 },
@@ -6032,7 +6092,7 @@ var styles41 = StyleSheet.create({
6032
6092
  grid: { flexDirection: "row", flexWrap: "wrap", rowGap: GAP8 },
6033
6093
  cell: { flexBasis: HALF4, maxWidth: HALF4, paddingRight: GAP8 },
6034
6094
  chips: { flexDirection: "row", flexWrap: "wrap", gap: GAP8 },
6035
- chip: { borderRadius: RADIUS3, borderWidth: CHIP_BORDER, paddingVertical: CHIP_PAD_V2, paddingHorizontal: CHIP_PAD_H2 },
6095
+ chip: { borderRadius: RADIUS3, borderWidth: CHIP_BORDER2, paddingVertical: CHIP_PAD_V2, paddingHorizontal: CHIP_PAD_H2 },
6036
6096
  metPhrase: { fontWeight: "700", textDecorationLine: "underline" }
6037
6097
  });
6038
6098
  function RuleList({ rules, flagUnmet, colors, testID, listStyle, itemStyle, outlined = false }) {