@dloizides/ui-forms 1.51.0 → 1.52.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,22 +1451,53 @@ 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
  }
@@ -1513,6 +1554,7 @@ function OutlineChip(props) {
1513
1554
  selected,
1514
1555
  selectedFill: props.selectedFill,
1515
1556
  ink: colors.textStrong,
1557
+ onDarkInk: colors.onPrimary,
1516
1558
  rest: { backgroundColor: selected ? colors.tint : colors.muted, textColor: active ? colors.primary : colors.textMuted }
1517
1559
  });
1518
1560
  const sized = chipSizeLook(props.size);
@@ -1529,7 +1571,7 @@ function OutlineChip(props) {
1529
1571
  "aria-pressed": props.ariaPressed,
1530
1572
  disabled,
1531
1573
  hitSlop: CHIP_HIT_SLOP,
1532
- style: [sized.hitBox, layout.boxStyle],
1574
+ style: [sized.hitBox, chipBoxFill(props.size, fill.backgroundColor), layout.boxStyle],
1533
1575
  tabIndex: props.tabIndex,
1534
1576
  testID,
1535
1577
  onHoverIn: () => setHovered(true),
@@ -1555,6 +1597,7 @@ function SolidChip(props) {
1555
1597
  selected,
1556
1598
  selectedFill: props.selectedFill,
1557
1599
  ink: colors.textStrong,
1600
+ onDarkInk: colors.onPrimary,
1558
1601
  rest: { backgroundColor: selected ? colors.primary : TRANSPARENT_COLOR, textColor: selected ? colors.onPrimary : colors.textStrong }
1559
1602
  });
1560
1603
  const sized = chipSizeLook(props.size);
@@ -1572,7 +1615,7 @@ function SolidChip(props) {
1572
1615
  "aria-pressed": props.ariaPressed,
1573
1616
  disabled,
1574
1617
  hitSlop: CHIP_HIT_SLOP,
1575
- style: [sized.hitBox, layout.boxStyle],
1618
+ style: [sized.hitBox, chipBoxFill(props.size, fill.backgroundColor), layout.boxStyle],
1576
1619
  testID,
1577
1620
  onPress,
1578
1621
  ...rovingTabStop,
@@ -1649,7 +1692,7 @@ function useRadioKeyboard(config) {
1649
1692
  var WHITE_COLOR = "#fff";
1650
1693
  var OUTLINE_TINT_ALPHA = 0.1;
1651
1694
  var HEX_SHORT_LENGTH2 = 3;
1652
- var HEX_RADIX2 = 16;
1695
+ var HEX_RADIX3 = 16;
1653
1696
  var RGB_R_START = 0;
1654
1697
  var RGB_R_END = 2;
1655
1698
  var RGB_G_END = 4;
@@ -1664,9 +1707,9 @@ function withAlpha2(hex, alpha) {
1664
1707
  const normalized = hex.replace("#", "");
1665
1708
  const isShort = normalized.length === HEX_SHORT_LENGTH2;
1666
1709
  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);
1710
+ const r = parseInt(full.slice(RGB_R_START, RGB_R_END), HEX_RADIX3);
1711
+ const g = parseInt(full.slice(RGB_R_END, RGB_G_END), HEX_RADIX3);
1712
+ const b = parseInt(full.slice(RGB_G_END, RGB_B_END), HEX_RADIX3);
1670
1713
  const isValid = !Number.isNaN(r) && !Number.isNaN(g) && !Number.isNaN(b);
1671
1714
  return isValid ? `rgba(${r}, ${g}, ${b}, ${alpha})` : hex;
1672
1715
  }
@@ -1733,7 +1776,8 @@ var ChipSelector = ({
1733
1776
  singleSelectRole = "button",
1734
1777
  size = "default",
1735
1778
  selectedFill,
1736
- outlineTone = "default"
1779
+ outlineTone = "default",
1780
+ labelStyle
1737
1781
  }) => {
1738
1782
  const isRadioGroup = !multiple && singleSelectRole === "radio";
1739
1783
  const { theme } = useUi();
@@ -1782,6 +1826,7 @@ var ChipSelector = ({
1782
1826
  containerStyle,
1783
1827
  error,
1784
1828
  label,
1829
+ labelStyle,
1785
1830
  required,
1786
1831
  spacing,
1787
1832
  testID,