@dloizides/ui-forms 1.20.0 → 1.21.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
@@ -1431,12 +1431,18 @@ var FormSwitch = ({
1431
1431
  )
1432
1432
  );
1433
1433
  };
1434
+
1435
+ // src/FormCheckbox/checkboxColors.ts
1436
+ var checkboxBoxColors = (colors, brand, checked) => checked ? { backgroundColor: brand, borderColor: brand } : { backgroundColor: "transparent", borderColor: colors.textSecondary };
1434
1437
  var ACTIVATION_KEYS = ["Enter", " ", "Spacebar"];
1435
1438
  var HINT_FONT_SIZE2 = 12;
1436
1439
  var BOX_SIZE = 20;
1437
1440
  var BOX_RADIUS = 5;
1438
1441
  var CHECK_FONT_SIZE = 14;
1439
1442
  var DISABLED_OPACITY = 0.5;
1443
+ var FOCUS_RING_WIDTH = 2;
1444
+ var WEB_NO_DEFAULT_OUTLINE = { outlineStyle: "none" };
1445
+ var FOCUS_RING_INSET = -6;
1440
1446
  var styles9 = StyleSheet.create({
1441
1447
  container: {
1442
1448
  flexDirection: "row",
@@ -1461,6 +1467,15 @@ var styles9 = StyleSheet.create({
1461
1467
  // Nudge the box to sit on the label's first text line.
1462
1468
  marginTop: 1
1463
1469
  },
1470
+ focusRing: {
1471
+ position: "absolute",
1472
+ top: FOCUS_RING_INSET,
1473
+ left: FOCUS_RING_INSET,
1474
+ right: FOCUS_RING_INSET,
1475
+ bottom: FOCUS_RING_INSET,
1476
+ borderWidth: FOCUS_RING_WIDTH,
1477
+ borderRadius: BOX_RADIUS - FOCUS_RING_INSET
1478
+ },
1464
1479
  check: {
1465
1480
  fontSize: CHECK_FONT_SIZE,
1466
1481
  fontWeight: "700",
@@ -1496,13 +1511,15 @@ var FormCheckbox = ({
1496
1511
  const hintText = typeof hint === "string" && hint !== "" ? hint : description;
1497
1512
  const hasHint = typeof hintText === "string" && hintText !== "";
1498
1513
  const { hintId } = useFieldIds();
1514
+ const [focused, setFocused] = React2.useState(false);
1499
1515
  const themeStyles = React2.useMemo(() => {
1500
- const boxOn = { backgroundColor: brand, borderColor: brand };
1501
- const boxOff = { backgroundColor: "transparent", borderColor: colors.border };
1516
+ const boxOn = checkboxBoxColors(colors, brand, true);
1517
+ const boxOff = checkboxBoxColors(colors, brand, false);
1518
+ const ring = { borderColor: brand };
1502
1519
  const labelStyle = { color: colors.text };
1503
1520
  const hintStyle = { color: colors.textSecondary };
1504
- return { boxOn, boxOff, label: labelStyle, hint: hintStyle };
1505
- }, [brand, colors.border, colors.text, colors.textSecondary]);
1521
+ return { boxOn, boxOff, ring, label: labelStyle, hint: hintStyle };
1522
+ }, [brand, colors]);
1506
1523
  const toggle = () => {
1507
1524
  const next = !value;
1508
1525
  if (onValueChange) onValueChange(next);
@@ -1526,18 +1543,24 @@ var FormCheckbox = ({
1526
1543
  "aria-checked": value,
1527
1544
  "aria-describedby": hasHint ? hintId : void 0,
1528
1545
  disabled,
1546
+ onBlur: () => setFocused(false),
1547
+ onFocus: () => setFocused(true),
1529
1548
  onPress: toggle,
1530
1549
  role: "checkbox",
1531
1550
  style: [
1532
1551
  styles9.container,
1533
1552
  hasHint ? null : styles9.centered,
1534
1553
  containerStyle,
1535
- disabled ? { opacity: DISABLED_OPACITY } : null
1554
+ disabled ? { opacity: DISABLED_OPACITY } : null,
1555
+ Platform.OS === "web" ? WEB_NO_DEFAULT_OUTLINE : null
1536
1556
  ],
1537
1557
  testID,
1538
1558
  ...keyboardProps,
1539
1559
  children: [
1540
- /* @__PURE__ */ jsx(View, { style: [styles9.box, value ? themeStyles.boxOn : themeStyles.boxOff], children: value ? /* @__PURE__ */ jsx(Text, { style: [styles9.check, { color: colors.surface }], accessibilityElementsHidden: true, children: "\u2713" }) : null }),
1560
+ /* @__PURE__ */ jsxs(View, { style: [styles9.box, value ? themeStyles.boxOn : themeStyles.boxOff], testID: `${testID}-box`, children: [
1561
+ focused ? /* @__PURE__ */ jsx(View, { pointerEvents: "none", style: [styles9.focusRing, themeStyles.ring], testID: `${testID}-focus-ring` }) : null,
1562
+ value ? /* @__PURE__ */ jsx(Text, { style: [styles9.check, { color: colors.surface }], accessibilityElementsHidden: true, children: "\u2713" }) : null
1563
+ ] }),
1541
1564
  /* @__PURE__ */ jsxs(View, { style: styles9.textColumn, children: [
1542
1565
  /* @__PURE__ */ jsx(Text, { style: [styles9.label, themeStyles.label], children: label }),
1543
1566
  hasHint ? /* @__PURE__ */ jsx(Text, { nativeID: hintId, style: [styles9.hint, themeStyles.hint], children: hintText }) : null