@dloizides/ui-forms 1.51.0 → 1.53.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
@@ -1416,6 +1416,11 @@ var COMPACT_PAD_H = 10;
1416
1416
  var COMPACT_FONT_SIZE = 12;
1417
1417
  var COMPACT_LINE_HEIGHT = 18;
1418
1418
  var CHIP_BORDER = 1;
1419
+ var WIDE_MIN_TARGET_PX = 24;
1420
+ var TAP_PAD_H = 12;
1421
+ var TAP_FONT_SIZE = 13;
1422
+ var TAP_LINE_HEIGHT = 17;
1423
+ var PILL_RADIUS = 999;
1419
1424
  var chipSizeStyles = StyleSheet.create({
1420
1425
  compactHitBox: {
1421
1426
  minHeight: MIN_TARGET_PX,
@@ -1430,6 +1435,11 @@ var chipSizeStyles = StyleSheet.create({
1430
1435
  minWidth: 0,
1431
1436
  borderWidth: CHIP_BORDER
1432
1437
  },
1438
+ fitBox: { minHeight: WIDE_MIN_TARGET_PX, minWidth: WIDE_MIN_TARGET_PX, borderRadius: PILL_RADIUS, overflow: "hidden" },
1439
+ tapBox: { minHeight: MIN_TARGET_PX, minWidth: MIN_TARGET_PX, borderRadius: PILL_RADIUS, overflow: "hidden" },
1440
+ pillVisual: { borderRadius: PILL_RADIUS },
1441
+ tapVisual: { paddingHorizontal: TAP_PAD_H, borderRadius: PILL_RADIUS, borderWidth: CHIP_BORDER },
1442
+ tapText: { fontSize: TAP_FONT_SIZE, fontWeight: "600", lineHeight: TAP_LINE_HEIGHT },
1433
1443
  compactText: {
1434
1444
  fontSize: COMPACT_FONT_SIZE,
1435
1445
  fontWeight: "600",
@@ -1441,25 +1451,63 @@ var chipSizeStyles = StyleSheet.create({
1441
1451
  function isCompactSize(size) {
1442
1452
  return size === "compact" || size === "dense";
1443
1453
  }
1454
+ function isFitSize(size) {
1455
+ return size === "fit" || size === "tap";
1456
+ }
1444
1457
 
1445
1458
  // src/ChipSelector/utils/chipLook.ts
1446
- function chipFill({ selected, selectedFill, ink, rest }) {
1459
+ function chipFill({ selected, selectedFill, ink, onDarkInk, rest }) {
1447
1460
  if (!selected || selectedFill === void 0)
1448
1461
  return { ...rest, checkColor: void 0 };
1449
- return { backgroundColor: selectedFill, textColor: ink, checkColor: ink };
1462
+ const fillInk = onDarkInk !== void 0 && isDarkColor(selectedFill) ? onDarkInk : ink;
1463
+ return { backgroundColor: selectedFill, textColor: fillInk, checkColor: fillInk };
1464
+ }
1465
+ var HEX_RGB = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
1466
+ var FN_RGB = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i;
1467
+ var DARK_LUMINANCE = 0.4;
1468
+ var HEX_RADIX2 = 16;
1469
+ var CHANNEL_MAX = 255;
1470
+ var LUMA = { r: 0.2126, g: 0.7152, b: 0.0722 };
1471
+ function channels(color) {
1472
+ const hex = HEX_RGB.exec(color.trim());
1473
+ if (hex) return hex.slice(1).map((part) => parseInt(part, HEX_RADIX2));
1474
+ const fn = FN_RGB.exec(color.trim());
1475
+ return fn ? fn.slice(1).map(Number) : void 0;
1476
+ }
1477
+ function isDarkColor(color) {
1478
+ const rgb = channels(color);
1479
+ if (rgb === void 0) return false;
1480
+ const [r = 0, g = 0, b = 0] = rgb.map((c) => c / CHANNEL_MAX);
1481
+ return LUMA.r * r + LUMA.g * g + LUMA.b * b < DARK_LUMINANCE;
1450
1482
  }
1451
1483
  function chipSizeLook(size) {
1484
+ if (size === "fit")
1485
+ return { hitBox: chipSizeStyles.fitBox, visual: [chipSizeStyles.compactVisual, chipSizeStyles.pillVisual], text: chipSizeStyles.compactText };
1486
+ if (size === "tap")
1487
+ return { hitBox: chipSizeStyles.tapBox, visual: chipSizeStyles.tapVisual, text: chipSizeStyles.tapText };
1452
1488
  if (!isCompactSize(size))
1453
1489
  return { hitBox: void 0, visual: void 0, text: void 0 };
1454
1490
  return { hitBox: chipSizeStyles.compactHitBox, visual: chipSizeStyles.compactVisual, text: chipSizeStyles.compactText };
1455
1491
  }
1456
1492
  var DENSE_ROW_GAP = { rowGap: 0 };
1493
+ var FIT_GAP = { gap: 6 };
1457
1494
  function chipRowGap(size) {
1495
+ if (isFitSize(size)) return FIT_GAP;
1458
1496
  return size === "dense" ? DENSE_ROW_GAP : void 0;
1459
1497
  }
1498
+ function chipBoxFill(size, backgroundColor) {
1499
+ return isFitSize(size) ? { backgroundColor } : void 0;
1500
+ }
1460
1501
  function restBorderColor(colors, tone) {
1461
1502
  return tone === "strong" ? colors.borderStrong : colors.border;
1462
1503
  }
1504
+ function outlineRest(colors, look) {
1505
+ if (look.selected) return { backgroundColor: colors.tint, textColor: colors.primary };
1506
+ const surface = look.tone === "surface";
1507
+ const backgroundColor = surface ? colors.surface : colors.muted;
1508
+ if (look.active) return { backgroundColor, textColor: colors.primary };
1509
+ return { backgroundColor, textColor: surface ? colors.textStrong : colors.textMuted };
1510
+ }
1463
1511
  var SOLID_RADIUS = 20;
1464
1512
  var OUTLINE_RADIUS = 999;
1465
1513
  var OUTLINE_PAD_H = 12;
@@ -1513,7 +1561,8 @@ function OutlineChip(props) {
1513
1561
  selected,
1514
1562
  selectedFill: props.selectedFill,
1515
1563
  ink: colors.textStrong,
1516
- rest: { backgroundColor: selected ? colors.tint : colors.muted, textColor: active ? colors.primary : colors.textMuted }
1564
+ onDarkInk: colors.onPrimary,
1565
+ rest: outlineRest(colors, { tone: props.outlineTone, selected, active })
1517
1566
  });
1518
1567
  const sized = chipSizeLook(props.size);
1519
1568
  const layout = chipLabelLayout(option.labelWrap);
@@ -1529,7 +1578,7 @@ function OutlineChip(props) {
1529
1578
  "aria-pressed": props.ariaPressed,
1530
1579
  disabled,
1531
1580
  hitSlop: CHIP_HIT_SLOP,
1532
- style: [sized.hitBox, layout.boxStyle],
1581
+ style: [sized.hitBox, chipBoxFill(props.size, fill.backgroundColor), layout.boxStyle],
1533
1582
  tabIndex: props.tabIndex,
1534
1583
  testID,
1535
1584
  onHoverIn: () => setHovered(true),
@@ -1555,6 +1604,7 @@ function SolidChip(props) {
1555
1604
  selected,
1556
1605
  selectedFill: props.selectedFill,
1557
1606
  ink: colors.textStrong,
1607
+ onDarkInk: colors.onPrimary,
1558
1608
  rest: { backgroundColor: selected ? colors.primary : TRANSPARENT_COLOR, textColor: selected ? colors.onPrimary : colors.textStrong }
1559
1609
  });
1560
1610
  const sized = chipSizeLook(props.size);
@@ -1572,7 +1622,7 @@ function SolidChip(props) {
1572
1622
  "aria-pressed": props.ariaPressed,
1573
1623
  disabled,
1574
1624
  hitSlop: CHIP_HIT_SLOP,
1575
- style: [sized.hitBox, layout.boxStyle],
1625
+ style: [sized.hitBox, chipBoxFill(props.size, fill.backgroundColor), layout.boxStyle],
1576
1626
  testID,
1577
1627
  onPress,
1578
1628
  ...rovingTabStop,
@@ -1649,7 +1699,7 @@ function useRadioKeyboard(config) {
1649
1699
  var WHITE_COLOR = "#fff";
1650
1700
  var OUTLINE_TINT_ALPHA = 0.1;
1651
1701
  var HEX_SHORT_LENGTH2 = 3;
1652
- var HEX_RADIX2 = 16;
1702
+ var HEX_RADIX3 = 16;
1653
1703
  var RGB_R_START = 0;
1654
1704
  var RGB_R_END = 2;
1655
1705
  var RGB_G_END = 4;
@@ -1664,9 +1714,9 @@ function withAlpha2(hex, alpha) {
1664
1714
  const normalized = hex.replace("#", "");
1665
1715
  const isShort = normalized.length === HEX_SHORT_LENGTH2;
1666
1716
  const full = isShort ? normalized.split("").map((c) => c + c).join("") : normalized;
1667
- const r = parseInt(full.slice(RGB_R_START, RGB_R_END), HEX_RADIX2);
1668
- const g = parseInt(full.slice(RGB_R_END, RGB_G_END), HEX_RADIX2);
1669
- const b = parseInt(full.slice(RGB_G_END, RGB_B_END), HEX_RADIX2);
1717
+ const r = parseInt(full.slice(RGB_R_START, RGB_R_END), HEX_RADIX3);
1718
+ const g = parseInt(full.slice(RGB_R_END, RGB_G_END), HEX_RADIX3);
1719
+ const b = parseInt(full.slice(RGB_G_END, RGB_B_END), HEX_RADIX3);
1670
1720
  const isValid = !Number.isNaN(r) && !Number.isNaN(g) && !Number.isNaN(b);
1671
1721
  return isValid ? `rgba(${r}, ${g}, ${b}, ${alpha})` : hex;
1672
1722
  }
@@ -1680,6 +1730,7 @@ function buildChipColors(colors, palette) {
1680
1730
  primary,
1681
1731
  onPrimary: onBrandInk(palette),
1682
1732
  muted: colors.background,
1733
+ surface: colors.surface ?? colors.background,
1683
1734
  tint: withAlpha2(primary, OUTLINE_TINT_ALPHA)
1684
1735
  };
1685
1736
  }
@@ -1733,7 +1784,8 @@ var ChipSelector = ({
1733
1784
  singleSelectRole = "button",
1734
1785
  size = "default",
1735
1786
  selectedFill,
1736
- outlineTone = "default"
1787
+ outlineTone = "default",
1788
+ labelStyle
1737
1789
  }) => {
1738
1790
  const isRadioGroup = !multiple && singleSelectRole === "radio";
1739
1791
  const { theme } = useUi();
@@ -1782,6 +1834,7 @@ var ChipSelector = ({
1782
1834
  containerStyle,
1783
1835
  error,
1784
1836
  label,
1837
+ labelStyle,
1785
1838
  required,
1786
1839
  spacing,
1787
1840
  testID,