@dloizides/ui-forms 1.50.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",
@@ -1437,17 +1447,57 @@ var chipSizeStyles = StyleSheet.create({
1437
1447
  }
1438
1448
  });
1439
1449
 
1450
+ // src/ChipSelector/ChipSize.ts
1451
+ function isCompactSize(size) {
1452
+ return size === "compact" || size === "dense";
1453
+ }
1454
+ function isFitSize(size) {
1455
+ return size === "fit" || size === "tap";
1456
+ }
1457
+
1440
1458
  // src/ChipSelector/utils/chipLook.ts
1441
- function chipFill({ selected, selectedFill, ink, rest }) {
1459
+ function chipFill({ selected, selectedFill, ink, onDarkInk, rest }) {
1442
1460
  if (!selected || selectedFill === void 0)
1443
1461
  return { ...rest, checkColor: void 0 };
1444
- 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;
1445
1482
  }
1446
1483
  function chipSizeLook(size) {
1447
- if (size !== "compact")
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 };
1488
+ if (!isCompactSize(size))
1448
1489
  return { hitBox: void 0, visual: void 0, text: void 0 };
1449
1490
  return { hitBox: chipSizeStyles.compactHitBox, visual: chipSizeStyles.compactVisual, text: chipSizeStyles.compactText };
1450
1491
  }
1492
+ var DENSE_ROW_GAP = { rowGap: 0 };
1493
+ var FIT_GAP = { gap: 6 };
1494
+ function chipRowGap(size) {
1495
+ if (isFitSize(size)) return FIT_GAP;
1496
+ return size === "dense" ? DENSE_ROW_GAP : void 0;
1497
+ }
1498
+ function chipBoxFill(size, backgroundColor) {
1499
+ return isFitSize(size) ? { backgroundColor } : void 0;
1500
+ }
1451
1501
  function restBorderColor(colors, tone) {
1452
1502
  return tone === "strong" ? colors.borderStrong : colors.border;
1453
1503
  }
@@ -1504,6 +1554,7 @@ function OutlineChip(props) {
1504
1554
  selected,
1505
1555
  selectedFill: props.selectedFill,
1506
1556
  ink: colors.textStrong,
1557
+ onDarkInk: colors.onPrimary,
1507
1558
  rest: { backgroundColor: selected ? colors.tint : colors.muted, textColor: active ? colors.primary : colors.textMuted }
1508
1559
  });
1509
1560
  const sized = chipSizeLook(props.size);
@@ -1520,7 +1571,7 @@ function OutlineChip(props) {
1520
1571
  "aria-pressed": props.ariaPressed,
1521
1572
  disabled,
1522
1573
  hitSlop: CHIP_HIT_SLOP,
1523
- style: [sized.hitBox, layout.boxStyle],
1574
+ style: [sized.hitBox, chipBoxFill(props.size, fill.backgroundColor), layout.boxStyle],
1524
1575
  tabIndex: props.tabIndex,
1525
1576
  testID,
1526
1577
  onHoverIn: () => setHovered(true),
@@ -1546,6 +1597,7 @@ function SolidChip(props) {
1546
1597
  selected,
1547
1598
  selectedFill: props.selectedFill,
1548
1599
  ink: colors.textStrong,
1600
+ onDarkInk: colors.onPrimary,
1549
1601
  rest: { backgroundColor: selected ? colors.primary : TRANSPARENT_COLOR, textColor: selected ? colors.onPrimary : colors.textStrong }
1550
1602
  });
1551
1603
  const sized = chipSizeLook(props.size);
@@ -1563,7 +1615,7 @@ function SolidChip(props) {
1563
1615
  "aria-pressed": props.ariaPressed,
1564
1616
  disabled,
1565
1617
  hitSlop: CHIP_HIT_SLOP,
1566
- style: [sized.hitBox, layout.boxStyle],
1618
+ style: [sized.hitBox, chipBoxFill(props.size, fill.backgroundColor), layout.boxStyle],
1567
1619
  testID,
1568
1620
  onPress,
1569
1621
  ...rovingTabStop,
@@ -1640,7 +1692,7 @@ function useRadioKeyboard(config) {
1640
1692
  var WHITE_COLOR = "#fff";
1641
1693
  var OUTLINE_TINT_ALPHA = 0.1;
1642
1694
  var HEX_SHORT_LENGTH2 = 3;
1643
- var HEX_RADIX2 = 16;
1695
+ var HEX_RADIX3 = 16;
1644
1696
  var RGB_R_START = 0;
1645
1697
  var RGB_R_END = 2;
1646
1698
  var RGB_G_END = 4;
@@ -1655,9 +1707,9 @@ function withAlpha2(hex, alpha) {
1655
1707
  const normalized = hex.replace("#", "");
1656
1708
  const isShort = normalized.length === HEX_SHORT_LENGTH2;
1657
1709
  const full = isShort ? normalized.split("").map((c) => c + c).join("") : normalized;
1658
- const r = parseInt(full.slice(RGB_R_START, RGB_R_END), HEX_RADIX2);
1659
- const g = parseInt(full.slice(RGB_R_END, RGB_G_END), HEX_RADIX2);
1660
- 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);
1661
1713
  const isValid = !Number.isNaN(r) && !Number.isNaN(g) && !Number.isNaN(b);
1662
1714
  return isValid ? `rgba(${r}, ${g}, ${b}, ${alpha})` : hex;
1663
1715
  }
@@ -1724,7 +1776,8 @@ var ChipSelector = ({
1724
1776
  singleSelectRole = "button",
1725
1777
  size = "default",
1726
1778
  selectedFill,
1727
- outlineTone = "default"
1779
+ outlineTone = "default",
1780
+ labelStyle
1728
1781
  }) => {
1729
1782
  const isRadioGroup = !multiple && singleSelectRole === "radio";
1730
1783
  const { theme } = useUi();
@@ -1773,6 +1826,7 @@ var ChipSelector = ({
1773
1826
  containerStyle,
1774
1827
  error,
1775
1828
  label,
1829
+ labelStyle,
1776
1830
  required,
1777
1831
  spacing,
1778
1832
  testID,
@@ -1780,7 +1834,7 @@ var ChipSelector = ({
1780
1834
  View,
1781
1835
  {
1782
1836
  accessibilityRole: isRadioGroup ? "radiogroup" : void 0,
1783
- style: styles13.chipContainer,
1837
+ style: [styles13.chipContainer, chipRowGap(size)],
1784
1838
  ...webFieldA11y({ describedById, hasError }),
1785
1839
  ...radio.groupProps,
1786
1840
  children: options.map(renderChip)
@@ -2115,11 +2169,18 @@ var NATIVE_SELECT_BOX = {
2115
2169
  fontFamily: "inherit",
2116
2170
  width: "100%"
2117
2171
  };
2118
- function nativeSelectStyle(borderColor, backgroundColor, color) {
2172
+ var FIT_SELECT_BOX = { width: "auto", maxWidth: "none" };
2173
+ var fitStyles = StyleSheet.create({
2174
+ anchor: { alignSelf: "flex-start", flexShrink: 0 }
2175
+ });
2176
+ function nativeSelectBox(fit) {
2177
+ return fit ? { ...NATIVE_SELECT_BOX, ...FIT_SELECT_BOX } : NATIVE_SELECT_BOX;
2178
+ }
2179
+ function nativeSelectStyle(fit, borderColor, backgroundColor, color) {
2119
2180
  const trigger = StyleSheet.flatten(controlStyles.selectTrigger);
2120
2181
  const text = StyleSheet.flatten(controlStyles.selectTriggerText);
2121
2182
  return {
2122
- ...NATIVE_SELECT_BOX,
2183
+ ...nativeSelectBox(fit),
2123
2184
  minHeight: trigger.minHeight,
2124
2185
  borderWidth: trigger.borderWidth,
2125
2186
  borderRadius: trigger.borderRadius,
@@ -2140,20 +2201,22 @@ function NativeSelect({
2140
2201
  accessibilityHint,
2141
2202
  labelledById,
2142
2203
  style,
2143
- testID
2204
+ testID,
2205
+ native
2144
2206
  }) {
2145
2207
  const { theme } = useUi();
2146
2208
  const { colors } = theme;
2147
2209
  const hasMatch = options.some((o) => o.value === value);
2148
2210
  const textColor = hasMatch ? colors.text : colors.textSecondary;
2211
+ const fit = native === "fit";
2149
2212
  const handleChange = (event) => onChange(event.target.value);
2150
- return /* @__PURE__ */ jsx(View, { style: [controlStyles.anchor, style], children: /* @__PURE__ */ jsxs(
2213
+ return /* @__PURE__ */ jsx(View, { style: [controlStyles.anchor, fit ? fitStyles.anchor : void 0, style], children: /* @__PURE__ */ jsxs(
2151
2214
  "select",
2152
2215
  {
2153
2216
  "aria-label": accessibilityLabel,
2154
2217
  "aria-labelledby": labelledById,
2155
2218
  "data-testid": testID,
2156
- style: nativeSelectStyle(colors.border, colors.surfaceElevated, textColor),
2219
+ style: nativeSelectStyle(fit, colors.border, colors.surfaceElevated, textColor),
2157
2220
  title: accessibilityHint,
2158
2221
  value,
2159
2222
  onChange: handleChange,
@@ -2207,7 +2270,7 @@ function listboxTriggerAria(testID, hasList, highlighted) {
2207
2270
  };
2208
2271
  }
2209
2272
  function SelectControl(props) {
2210
- return props.native === true && IS_WEB7 ? /* @__PURE__ */ jsx(NativeSelect, { ...props }) : /* @__PURE__ */ jsx(MenuSelectControl, { ...props });
2273
+ return (props.native === true || props.native === "fit") && IS_WEB7 ? /* @__PURE__ */ jsx(NativeSelect, { ...props }) : /* @__PURE__ */ jsx(MenuSelectControl, { ...props });
2211
2274
  }
2212
2275
  function MenuSelectControl({
2213
2276
  options,