@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/CHANGELOG.md +4 -0
- package/dist/index.d.mts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +63 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.53.0
|
|
4
|
+
|
|
5
|
+
- `ChipSelector` `outlineTone="surface"`: an unselected outline chip sits on the theme `surface` fill with strong ink (was the page `background` fill with muted ink), so it reads on a white card (MODC-1 D-MC-749 F1). `default` and `strong` unchanged.
|
|
6
|
+
|
|
3
7
|
## [1.51.0] - 2026-11-24
|
|
4
8
|
|
|
5
9
|
### Added
|
package/dist/index.d.mts
CHANGED
|
@@ -657,11 +657,11 @@ declare const enum ChipLabelWrap {
|
|
|
657
657
|
Truncate = "truncate"
|
|
658
658
|
}
|
|
659
659
|
|
|
660
|
-
/**
|
|
661
|
-
type ChipOutlineTone = 'default' | 'strong';
|
|
660
|
+
/** Unselected chip look. `default` = theme `border`; `strong` = theme `textSecondary` edge; `surface` = `border` edge on the surface fill with strong ink. */
|
|
661
|
+
type ChipOutlineTone = 'default' | 'strong' | 'surface';
|
|
662
662
|
|
|
663
|
-
/** Chip size. `default` = 44 px pill; `compact` = 28 px pill in a 44 px hit box; `dense` = `compact` with no row gap (44 px
|
|
664
|
-
type ChipSize = 'default' | 'compact' | 'dense';
|
|
663
|
+
/** Chip size. `default` = 44 px pill; `compact` = 28 px pill in a 44 px hit box; `dense` = `compact` with no row gap; `fit` = 28 px pill that is its own box (wide screens); `tap` = 44 px pill with a 13 px label. */
|
|
664
|
+
type ChipSize = 'default' | 'compact' | 'dense' | 'fit' | 'tap';
|
|
665
665
|
|
|
666
666
|
/**
|
|
667
667
|
* Public + internal types for ChipSelector. Split out of `ChipSelector.tsx` so the component, its
|
|
@@ -688,6 +688,8 @@ interface ChipOption<T> {
|
|
|
688
688
|
interface ChipSelectorProps<T> {
|
|
689
689
|
/** Optional — with no label, no label row is rendered (no phantom gap above the chips). */
|
|
690
690
|
label?: string;
|
|
691
|
+
/** Style for the label text, applied after the field label voice (e.g. a smaller label in a dense card). */
|
|
692
|
+
labelStyle?: StyleProp<TextStyle>;
|
|
691
693
|
options: Array<ChipOption<T>>;
|
|
692
694
|
value: T | T[];
|
|
693
695
|
onChange: (value: T) => void;
|
|
@@ -759,7 +761,7 @@ interface ChipSelectorProps<T> {
|
|
|
759
761
|
* resolvers (`chipIdentity`, colours, radio key logic) in `utils/`.
|
|
760
762
|
*/
|
|
761
763
|
|
|
762
|
-
declare const ChipSelector: <T extends string | number>({ label, options, value, onChange, multiple, disabled, variant, containerStyle, spacing, required, error, testID, chipTestIDPrefix, optionAccessibilityHint, singleSelectRole, size, selectedFill, outlineTone, }: ChipSelectorProps<T>) => React.ReactElement;
|
|
764
|
+
declare const ChipSelector: <T extends string | number>({ label, options, value, onChange, multiple, disabled, variant, containerStyle, spacing, required, error, testID, chipTestIDPrefix, optionAccessibilityHint, singleSelectRole, size, selectedFill, outlineTone, labelStyle, }: ChipSelectorProps<T>) => React.ReactElement;
|
|
763
765
|
|
|
764
766
|
/** `row` = label beside the switch (default); `box` = caption label over a bordered field box holding the state text and the switch. */
|
|
765
767
|
type FormSwitchVariant = 'row' | 'box';
|
package/dist/index.d.ts
CHANGED
|
@@ -657,11 +657,11 @@ declare const enum ChipLabelWrap {
|
|
|
657
657
|
Truncate = "truncate"
|
|
658
658
|
}
|
|
659
659
|
|
|
660
|
-
/**
|
|
661
|
-
type ChipOutlineTone = 'default' | 'strong';
|
|
660
|
+
/** Unselected chip look. `default` = theme `border`; `strong` = theme `textSecondary` edge; `surface` = `border` edge on the surface fill with strong ink. */
|
|
661
|
+
type ChipOutlineTone = 'default' | 'strong' | 'surface';
|
|
662
662
|
|
|
663
|
-
/** Chip size. `default` = 44 px pill; `compact` = 28 px pill in a 44 px hit box; `dense` = `compact` with no row gap (44 px
|
|
664
|
-
type ChipSize = 'default' | 'compact' | 'dense';
|
|
663
|
+
/** Chip size. `default` = 44 px pill; `compact` = 28 px pill in a 44 px hit box; `dense` = `compact` with no row gap; `fit` = 28 px pill that is its own box (wide screens); `tap` = 44 px pill with a 13 px label. */
|
|
664
|
+
type ChipSize = 'default' | 'compact' | 'dense' | 'fit' | 'tap';
|
|
665
665
|
|
|
666
666
|
/**
|
|
667
667
|
* Public + internal types for ChipSelector. Split out of `ChipSelector.tsx` so the component, its
|
|
@@ -688,6 +688,8 @@ interface ChipOption<T> {
|
|
|
688
688
|
interface ChipSelectorProps<T> {
|
|
689
689
|
/** Optional — with no label, no label row is rendered (no phantom gap above the chips). */
|
|
690
690
|
label?: string;
|
|
691
|
+
/** Style for the label text, applied after the field label voice (e.g. a smaller label in a dense card). */
|
|
692
|
+
labelStyle?: StyleProp<TextStyle>;
|
|
691
693
|
options: Array<ChipOption<T>>;
|
|
692
694
|
value: T | T[];
|
|
693
695
|
onChange: (value: T) => void;
|
|
@@ -759,7 +761,7 @@ interface ChipSelectorProps<T> {
|
|
|
759
761
|
* resolvers (`chipIdentity`, colours, radio key logic) in `utils/`.
|
|
760
762
|
*/
|
|
761
763
|
|
|
762
|
-
declare const ChipSelector: <T extends string | number>({ label, options, value, onChange, multiple, disabled, variant, containerStyle, spacing, required, error, testID, chipTestIDPrefix, optionAccessibilityHint, singleSelectRole, size, selectedFill, outlineTone, }: ChipSelectorProps<T>) => React.ReactElement;
|
|
764
|
+
declare const ChipSelector: <T extends string | number>({ label, options, value, onChange, multiple, disabled, variant, containerStyle, spacing, required, error, testID, chipTestIDPrefix, optionAccessibilityHint, singleSelectRole, size, selectedFill, outlineTone, labelStyle, }: ChipSelectorProps<T>) => React.ReactElement;
|
|
763
765
|
|
|
764
766
|
/** `row` = label beside the switch (default); `box` = caption label over a bordered field box holding the state text and the switch. */
|
|
765
767
|
type FormSwitchVariant = 'row' | 'box';
|
package/dist/index.js
CHANGED
|
@@ -1423,6 +1423,11 @@ var COMPACT_PAD_H = 10;
|
|
|
1423
1423
|
var COMPACT_FONT_SIZE = 12;
|
|
1424
1424
|
var COMPACT_LINE_HEIGHT = 18;
|
|
1425
1425
|
var CHIP_BORDER = 1;
|
|
1426
|
+
var WIDE_MIN_TARGET_PX = 24;
|
|
1427
|
+
var TAP_PAD_H = 12;
|
|
1428
|
+
var TAP_FONT_SIZE = 13;
|
|
1429
|
+
var TAP_LINE_HEIGHT = 17;
|
|
1430
|
+
var PILL_RADIUS = 999;
|
|
1426
1431
|
var chipSizeStyles = reactNative.StyleSheet.create({
|
|
1427
1432
|
compactHitBox: {
|
|
1428
1433
|
minHeight: MIN_TARGET_PX,
|
|
@@ -1437,6 +1442,11 @@ var chipSizeStyles = reactNative.StyleSheet.create({
|
|
|
1437
1442
|
minWidth: 0,
|
|
1438
1443
|
borderWidth: CHIP_BORDER
|
|
1439
1444
|
},
|
|
1445
|
+
fitBox: { minHeight: WIDE_MIN_TARGET_PX, minWidth: WIDE_MIN_TARGET_PX, borderRadius: PILL_RADIUS, overflow: "hidden" },
|
|
1446
|
+
tapBox: { minHeight: MIN_TARGET_PX, minWidth: MIN_TARGET_PX, borderRadius: PILL_RADIUS, overflow: "hidden" },
|
|
1447
|
+
pillVisual: { borderRadius: PILL_RADIUS },
|
|
1448
|
+
tapVisual: { paddingHorizontal: TAP_PAD_H, borderRadius: PILL_RADIUS, borderWidth: CHIP_BORDER },
|
|
1449
|
+
tapText: { fontSize: TAP_FONT_SIZE, fontWeight: "600", lineHeight: TAP_LINE_HEIGHT },
|
|
1440
1450
|
compactText: {
|
|
1441
1451
|
fontSize: COMPACT_FONT_SIZE,
|
|
1442
1452
|
fontWeight: "600",
|
|
@@ -1448,25 +1458,63 @@ var chipSizeStyles = reactNative.StyleSheet.create({
|
|
|
1448
1458
|
function isCompactSize(size) {
|
|
1449
1459
|
return size === "compact" || size === "dense";
|
|
1450
1460
|
}
|
|
1461
|
+
function isFitSize(size) {
|
|
1462
|
+
return size === "fit" || size === "tap";
|
|
1463
|
+
}
|
|
1451
1464
|
|
|
1452
1465
|
// src/ChipSelector/utils/chipLook.ts
|
|
1453
|
-
function chipFill({ selected, selectedFill, ink, rest }) {
|
|
1466
|
+
function chipFill({ selected, selectedFill, ink, onDarkInk, rest }) {
|
|
1454
1467
|
if (!selected || selectedFill === void 0)
|
|
1455
1468
|
return { ...rest, checkColor: void 0 };
|
|
1456
|
-
|
|
1469
|
+
const fillInk = onDarkInk !== void 0 && isDarkColor(selectedFill) ? onDarkInk : ink;
|
|
1470
|
+
return { backgroundColor: selectedFill, textColor: fillInk, checkColor: fillInk };
|
|
1471
|
+
}
|
|
1472
|
+
var HEX_RGB = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
|
|
1473
|
+
var FN_RGB = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i;
|
|
1474
|
+
var DARK_LUMINANCE = 0.4;
|
|
1475
|
+
var HEX_RADIX2 = 16;
|
|
1476
|
+
var CHANNEL_MAX = 255;
|
|
1477
|
+
var LUMA = { r: 0.2126, g: 0.7152, b: 0.0722 };
|
|
1478
|
+
function channels(color) {
|
|
1479
|
+
const hex = HEX_RGB.exec(color.trim());
|
|
1480
|
+
if (hex) return hex.slice(1).map((part) => parseInt(part, HEX_RADIX2));
|
|
1481
|
+
const fn = FN_RGB.exec(color.trim());
|
|
1482
|
+
return fn ? fn.slice(1).map(Number) : void 0;
|
|
1483
|
+
}
|
|
1484
|
+
function isDarkColor(color) {
|
|
1485
|
+
const rgb = channels(color);
|
|
1486
|
+
if (rgb === void 0) return false;
|
|
1487
|
+
const [r = 0, g = 0, b = 0] = rgb.map((c) => c / CHANNEL_MAX);
|
|
1488
|
+
return LUMA.r * r + LUMA.g * g + LUMA.b * b < DARK_LUMINANCE;
|
|
1457
1489
|
}
|
|
1458
1490
|
function chipSizeLook(size) {
|
|
1491
|
+
if (size === "fit")
|
|
1492
|
+
return { hitBox: chipSizeStyles.fitBox, visual: [chipSizeStyles.compactVisual, chipSizeStyles.pillVisual], text: chipSizeStyles.compactText };
|
|
1493
|
+
if (size === "tap")
|
|
1494
|
+
return { hitBox: chipSizeStyles.tapBox, visual: chipSizeStyles.tapVisual, text: chipSizeStyles.tapText };
|
|
1459
1495
|
if (!isCompactSize(size))
|
|
1460
1496
|
return { hitBox: void 0, visual: void 0, text: void 0 };
|
|
1461
1497
|
return { hitBox: chipSizeStyles.compactHitBox, visual: chipSizeStyles.compactVisual, text: chipSizeStyles.compactText };
|
|
1462
1498
|
}
|
|
1463
1499
|
var DENSE_ROW_GAP = { rowGap: 0 };
|
|
1500
|
+
var FIT_GAP = { gap: 6 };
|
|
1464
1501
|
function chipRowGap(size) {
|
|
1502
|
+
if (isFitSize(size)) return FIT_GAP;
|
|
1465
1503
|
return size === "dense" ? DENSE_ROW_GAP : void 0;
|
|
1466
1504
|
}
|
|
1505
|
+
function chipBoxFill(size, backgroundColor) {
|
|
1506
|
+
return isFitSize(size) ? { backgroundColor } : void 0;
|
|
1507
|
+
}
|
|
1467
1508
|
function restBorderColor(colors, tone) {
|
|
1468
1509
|
return tone === "strong" ? colors.borderStrong : colors.border;
|
|
1469
1510
|
}
|
|
1511
|
+
function outlineRest(colors, look) {
|
|
1512
|
+
if (look.selected) return { backgroundColor: colors.tint, textColor: colors.primary };
|
|
1513
|
+
const surface = look.tone === "surface";
|
|
1514
|
+
const backgroundColor = surface ? colors.surface : colors.muted;
|
|
1515
|
+
if (look.active) return { backgroundColor, textColor: colors.primary };
|
|
1516
|
+
return { backgroundColor, textColor: surface ? colors.textStrong : colors.textMuted };
|
|
1517
|
+
}
|
|
1470
1518
|
var SOLID_RADIUS = 20;
|
|
1471
1519
|
var OUTLINE_RADIUS = 999;
|
|
1472
1520
|
var OUTLINE_PAD_H = 12;
|
|
@@ -1520,7 +1568,8 @@ function OutlineChip(props) {
|
|
|
1520
1568
|
selected,
|
|
1521
1569
|
selectedFill: props.selectedFill,
|
|
1522
1570
|
ink: colors.textStrong,
|
|
1523
|
-
|
|
1571
|
+
onDarkInk: colors.onPrimary,
|
|
1572
|
+
rest: outlineRest(colors, { tone: props.outlineTone, selected, active })
|
|
1524
1573
|
});
|
|
1525
1574
|
const sized = chipSizeLook(props.size);
|
|
1526
1575
|
const layout = chipLabelLayout(option.labelWrap);
|
|
@@ -1536,7 +1585,7 @@ function OutlineChip(props) {
|
|
|
1536
1585
|
"aria-pressed": props.ariaPressed,
|
|
1537
1586
|
disabled,
|
|
1538
1587
|
hitSlop: CHIP_HIT_SLOP,
|
|
1539
|
-
style: [sized.hitBox, layout.boxStyle],
|
|
1588
|
+
style: [sized.hitBox, chipBoxFill(props.size, fill.backgroundColor), layout.boxStyle],
|
|
1540
1589
|
tabIndex: props.tabIndex,
|
|
1541
1590
|
testID,
|
|
1542
1591
|
onHoverIn: () => setHovered(true),
|
|
@@ -1562,6 +1611,7 @@ function SolidChip(props) {
|
|
|
1562
1611
|
selected,
|
|
1563
1612
|
selectedFill: props.selectedFill,
|
|
1564
1613
|
ink: colors.textStrong,
|
|
1614
|
+
onDarkInk: colors.onPrimary,
|
|
1565
1615
|
rest: { backgroundColor: selected ? colors.primary : TRANSPARENT_COLOR, textColor: selected ? colors.onPrimary : colors.textStrong }
|
|
1566
1616
|
});
|
|
1567
1617
|
const sized = chipSizeLook(props.size);
|
|
@@ -1579,7 +1629,7 @@ function SolidChip(props) {
|
|
|
1579
1629
|
"aria-pressed": props.ariaPressed,
|
|
1580
1630
|
disabled,
|
|
1581
1631
|
hitSlop: CHIP_HIT_SLOP,
|
|
1582
|
-
style: [sized.hitBox, layout.boxStyle],
|
|
1632
|
+
style: [sized.hitBox, chipBoxFill(props.size, fill.backgroundColor), layout.boxStyle],
|
|
1583
1633
|
testID,
|
|
1584
1634
|
onPress,
|
|
1585
1635
|
...rovingTabStop,
|
|
@@ -1656,7 +1706,7 @@ function useRadioKeyboard(config) {
|
|
|
1656
1706
|
var WHITE_COLOR = "#fff";
|
|
1657
1707
|
var OUTLINE_TINT_ALPHA = 0.1;
|
|
1658
1708
|
var HEX_SHORT_LENGTH2 = 3;
|
|
1659
|
-
var
|
|
1709
|
+
var HEX_RADIX3 = 16;
|
|
1660
1710
|
var RGB_R_START = 0;
|
|
1661
1711
|
var RGB_R_END = 2;
|
|
1662
1712
|
var RGB_G_END = 4;
|
|
@@ -1671,9 +1721,9 @@ function withAlpha2(hex, alpha) {
|
|
|
1671
1721
|
const normalized = hex.replace("#", "");
|
|
1672
1722
|
const isShort = normalized.length === HEX_SHORT_LENGTH2;
|
|
1673
1723
|
const full = isShort ? normalized.split("").map((c) => c + c).join("") : normalized;
|
|
1674
|
-
const r = parseInt(full.slice(RGB_R_START, RGB_R_END),
|
|
1675
|
-
const g = parseInt(full.slice(RGB_R_END, RGB_G_END),
|
|
1676
|
-
const b = parseInt(full.slice(RGB_G_END, RGB_B_END),
|
|
1724
|
+
const r = parseInt(full.slice(RGB_R_START, RGB_R_END), HEX_RADIX3);
|
|
1725
|
+
const g = parseInt(full.slice(RGB_R_END, RGB_G_END), HEX_RADIX3);
|
|
1726
|
+
const b = parseInt(full.slice(RGB_G_END, RGB_B_END), HEX_RADIX3);
|
|
1677
1727
|
const isValid = !Number.isNaN(r) && !Number.isNaN(g) && !Number.isNaN(b);
|
|
1678
1728
|
return isValid ? `rgba(${r}, ${g}, ${b}, ${alpha})` : hex;
|
|
1679
1729
|
}
|
|
@@ -1687,6 +1737,7 @@ function buildChipColors(colors, palette) {
|
|
|
1687
1737
|
primary,
|
|
1688
1738
|
onPrimary: onBrandInk(palette),
|
|
1689
1739
|
muted: colors.background,
|
|
1740
|
+
surface: colors.surface ?? colors.background,
|
|
1690
1741
|
tint: withAlpha2(primary, OUTLINE_TINT_ALPHA)
|
|
1691
1742
|
};
|
|
1692
1743
|
}
|
|
@@ -1740,7 +1791,8 @@ var ChipSelector = ({
|
|
|
1740
1791
|
singleSelectRole = "button",
|
|
1741
1792
|
size = "default",
|
|
1742
1793
|
selectedFill,
|
|
1743
|
-
outlineTone = "default"
|
|
1794
|
+
outlineTone = "default",
|
|
1795
|
+
labelStyle
|
|
1744
1796
|
}) => {
|
|
1745
1797
|
const isRadioGroup = !multiple && singleSelectRole === "radio";
|
|
1746
1798
|
const { theme } = uiFeedback.useUi();
|
|
@@ -1789,6 +1841,7 @@ var ChipSelector = ({
|
|
|
1789
1841
|
containerStyle,
|
|
1790
1842
|
error,
|
|
1791
1843
|
label,
|
|
1844
|
+
labelStyle,
|
|
1792
1845
|
required,
|
|
1793
1846
|
spacing,
|
|
1794
1847
|
testID,
|