@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.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +54 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -660,8 +660,8 @@ declare const enum ChipLabelWrap {
|
|
|
660
660
|
/** Outline of an unselected chip. `default` = theme `border`; `strong` = theme `textSecondary`, a darker edge. */
|
|
661
661
|
type ChipOutlineTone = 'default' | 'strong';
|
|
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
|
@@ -660,8 +660,8 @@ declare const enum ChipLabelWrap {
|
|
|
660
660
|
/** Outline of an unselected chip. `default` = theme `border`; `strong` = theme `textSecondary`, a darker edge. */
|
|
661
661
|
type ChipOutlineTone = 'default' | 'strong';
|
|
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,22 +1458,53 @@ 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
|
}
|
|
@@ -1520,6 +1561,7 @@ function OutlineChip(props) {
|
|
|
1520
1561
|
selected,
|
|
1521
1562
|
selectedFill: props.selectedFill,
|
|
1522
1563
|
ink: colors.textStrong,
|
|
1564
|
+
onDarkInk: colors.onPrimary,
|
|
1523
1565
|
rest: { backgroundColor: selected ? colors.tint : colors.muted, textColor: active ? colors.primary : colors.textMuted }
|
|
1524
1566
|
});
|
|
1525
1567
|
const sized = chipSizeLook(props.size);
|
|
@@ -1536,7 +1578,7 @@ function OutlineChip(props) {
|
|
|
1536
1578
|
"aria-pressed": props.ariaPressed,
|
|
1537
1579
|
disabled,
|
|
1538
1580
|
hitSlop: CHIP_HIT_SLOP,
|
|
1539
|
-
style: [sized.hitBox, layout.boxStyle],
|
|
1581
|
+
style: [sized.hitBox, chipBoxFill(props.size, fill.backgroundColor), layout.boxStyle],
|
|
1540
1582
|
tabIndex: props.tabIndex,
|
|
1541
1583
|
testID,
|
|
1542
1584
|
onHoverIn: () => setHovered(true),
|
|
@@ -1562,6 +1604,7 @@ function SolidChip(props) {
|
|
|
1562
1604
|
selected,
|
|
1563
1605
|
selectedFill: props.selectedFill,
|
|
1564
1606
|
ink: colors.textStrong,
|
|
1607
|
+
onDarkInk: colors.onPrimary,
|
|
1565
1608
|
rest: { backgroundColor: selected ? colors.primary : TRANSPARENT_COLOR, textColor: selected ? colors.onPrimary : colors.textStrong }
|
|
1566
1609
|
});
|
|
1567
1610
|
const sized = chipSizeLook(props.size);
|
|
@@ -1579,7 +1622,7 @@ function SolidChip(props) {
|
|
|
1579
1622
|
"aria-pressed": props.ariaPressed,
|
|
1580
1623
|
disabled,
|
|
1581
1624
|
hitSlop: CHIP_HIT_SLOP,
|
|
1582
|
-
style: [sized.hitBox, layout.boxStyle],
|
|
1625
|
+
style: [sized.hitBox, chipBoxFill(props.size, fill.backgroundColor), layout.boxStyle],
|
|
1583
1626
|
testID,
|
|
1584
1627
|
onPress,
|
|
1585
1628
|
...rovingTabStop,
|
|
@@ -1656,7 +1699,7 @@ function useRadioKeyboard(config) {
|
|
|
1656
1699
|
var WHITE_COLOR = "#fff";
|
|
1657
1700
|
var OUTLINE_TINT_ALPHA = 0.1;
|
|
1658
1701
|
var HEX_SHORT_LENGTH2 = 3;
|
|
1659
|
-
var
|
|
1702
|
+
var HEX_RADIX3 = 16;
|
|
1660
1703
|
var RGB_R_START = 0;
|
|
1661
1704
|
var RGB_R_END = 2;
|
|
1662
1705
|
var RGB_G_END = 4;
|
|
@@ -1671,9 +1714,9 @@ function withAlpha2(hex, alpha) {
|
|
|
1671
1714
|
const normalized = hex.replace("#", "");
|
|
1672
1715
|
const isShort = normalized.length === HEX_SHORT_LENGTH2;
|
|
1673
1716
|
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),
|
|
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);
|
|
1677
1720
|
const isValid = !Number.isNaN(r) && !Number.isNaN(g) && !Number.isNaN(b);
|
|
1678
1721
|
return isValid ? `rgba(${r}, ${g}, ${b}, ${alpha})` : hex;
|
|
1679
1722
|
}
|
|
@@ -1740,7 +1783,8 @@ var ChipSelector = ({
|
|
|
1740
1783
|
singleSelectRole = "button",
|
|
1741
1784
|
size = "default",
|
|
1742
1785
|
selectedFill,
|
|
1743
|
-
outlineTone = "default"
|
|
1786
|
+
outlineTone = "default",
|
|
1787
|
+
labelStyle
|
|
1744
1788
|
}) => {
|
|
1745
1789
|
const isRadioGroup = !multiple && singleSelectRole === "radio";
|
|
1746
1790
|
const { theme } = uiFeedback.useUi();
|
|
@@ -1789,6 +1833,7 @@ var ChipSelector = ({
|
|
|
1789
1833
|
containerStyle,
|
|
1790
1834
|
error,
|
|
1791
1835
|
label,
|
|
1836
|
+
labelStyle,
|
|
1792
1837
|
required,
|
|
1793
1838
|
spacing,
|
|
1794
1839
|
testID,
|