@dloizides/ui-forms 1.18.7 → 1.19.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
@@ -2,10 +2,10 @@ import React2, { useState, useCallback, useMemo, useEffect, useRef, useLayoutEff
2
2
  import { Platform, StyleSheet, TextInput, View, Text, ScrollView, Pressable, Switch, TouchableOpacity } from 'react-native';
3
3
  import { useUi } from '@dloizides/ui-feedback';
4
4
  import { jsx, jsxs } from 'react/jsx-runtime';
5
+ import { Z_INDEX, focusRingOutline, readableScaleInk } from '@dloizides/design-tokens';
5
6
  import { themeFocusRingColor, Button } from '@dloizides/ui-buttons';
6
7
  import { createPortal } from 'react-dom';
7
8
  import { MIN_TOUCH_TARGET_PX } from '@dloizides/a11y';
8
- import { Z_INDEX, focusRingOutline } from '@dloizides/design-tokens';
9
9
 
10
10
  // src/Field/Field.tsx
11
11
  function attachControlId(child, candidateId, describedById) {
@@ -140,6 +140,11 @@ function useFormGridMetrics() {
140
140
  function useIsGapOwned() {
141
141
  return React2.useContext(GapOwnedContext);
142
142
  }
143
+ var ERROR_LIGHT_STEPS = ["500", "600", "700"];
144
+ var ERROR_DARK_STEPS = ["300", "200", "400", "100", "500"];
145
+ function fieldErrorInk(theme) {
146
+ return readableScaleInk({ ...theme.semantic.error }, theme.colors.surface, ERROR_LIGHT_STEPS, ERROR_DARK_STEPS);
147
+ }
143
148
  var ERROR_FONT_SIZE = 12;
144
149
  var HINT_FONT_SIZE = 12;
145
150
  var OPTIONAL_MARK_FONT_WEIGHT = "400";
@@ -195,8 +200,8 @@ var Field = ({
195
200
  const { theme } = useUi();
196
201
  const gapOwned = useIsGapOwned();
197
202
  const spacingStyles = fieldSpacingStyleSet(resolveFieldSpacing(spacing, gapOwned));
198
- const { colors, semantic } = theme;
199
- const errorColor = semantic.error["500"];
203
+ const { colors } = theme;
204
+ const errorColor = fieldErrorInk(theme);
200
205
  const hasError = hasFieldError(error);
201
206
  const hasHint = isPresent(hint);
202
207
  const labelText = label ?? "";
@@ -629,9 +634,9 @@ function withAlpha(color, alpha) {
629
634
  return `rgba(${r}, ${g}, ${b}, ${alpha})`;
630
635
  }
631
636
  function useThemedInput(options = {}) {
632
- const { hasError = false, onFocus, onBlur } = options;
637
+ const { hasError = false, onFocus, onBlur, editable = true } = options;
633
638
  const { theme } = useUi();
634
- const { colors, palette, semantic } = theme;
639
+ const { colors, palette } = theme;
635
640
  const [isFocused, setIsFocused] = useState(false);
636
641
  const [isHovered, setIsHovered] = useState(false);
637
642
  const handleFocus = useCallback(
@@ -651,13 +656,14 @@ function useThemedInput(options = {}) {
651
656
  const handleHoverIn = useCallback(() => setIsHovered(true), []);
652
657
  const handleHoverOut = useCallback(() => setIsHovered(false), []);
653
658
  const primary = palette.primary["500"];
654
- const errorColor = semantic.error["500"];
659
+ const errorColor = fieldErrorInk(theme);
655
660
  const style = useMemo(() => {
656
661
  const restBorder = hasError ? errorColor : colors.border;
657
662
  const focusBorder = hasError ? errorColor : primary;
658
663
  const borderColor = isFocused ? focusBorder : isHovered ? withAlpha(colors.text, HOVER_BORDER_ALPHA) : restBorder;
659
- const backgroundColor = isFocused ? colors.surface : colors.surfaceElevated;
660
- const base = { color: colors.text, borderColor, backgroundColor };
664
+ const editableFill = isFocused ? colors.surface : colors.surfaceElevated;
665
+ const backgroundColor = editable ? editableFill : colors.background;
666
+ const base = { color: editable ? colors.text : colors.textSecondary, borderColor, backgroundColor };
661
667
  if (!IS_WEB5) return base;
662
668
  const ringColor = hasError ? errorColor : themeFocusRingColor(theme);
663
669
  const ring = isFocused ? focusRingOutline(ringColor) : NO_RING;
@@ -677,6 +683,9 @@ function useThemedInput(options = {}) {
677
683
  colors.border,
678
684
  colors.surface,
679
685
  colors.surfaceElevated,
686
+ colors.background,
687
+ colors.textSecondary,
688
+ editable,
680
689
  primary,
681
690
  errorColor,
682
691
  theme
@@ -729,7 +738,7 @@ var ThemedTextInput = React2.forwardRef(function ThemedTextInput2({
729
738
  placeholderTextColor: themedPlaceholder,
730
739
  focusBind,
731
740
  hoverBind
732
- } = useThemedInput({ hasError, onFocus, onBlur });
741
+ } = useThemedInput({ hasError, onFocus, onBlur, editable: rest.editable });
733
742
  const webA11y = webFieldA11y({ describedById, hasError, required: requiredField });
734
743
  const boxStyle = unstyledBox ? null : controlStyles.input;
735
744
  const multilineStyle = rest.multiline === true && !unstyledBox ? boxStyles.multiline : null;
@@ -1582,7 +1591,7 @@ function TypeaheadControl({
1582
1591
  testID
1583
1592
  }) {
1584
1593
  const { theme } = useUi();
1585
- const { colors, palette, semantic } = theme;
1594
+ const { colors, palette } = theme;
1586
1595
  const anchorRef = useRef(null);
1587
1596
  const [isOpen, setIsOpen] = useState(false);
1588
1597
  const exactPick = useMemo(() => options.some((o) => o.label === value), [options, value]);
@@ -1630,7 +1639,7 @@ function TypeaheadControl({
1630
1639
  onFocus: () => setIsOpen(true),
1631
1640
  onBlur: handleBlur,
1632
1641
  onSubmitEditing: handleSubmit,
1633
- style: [controlStyles.input, { borderColor: hasError ? semantic.error["500"] : colors.border, backgroundColor: colors.surface, color: colors.text }],
1642
+ style: [controlStyles.input, { borderColor: hasError ? fieldErrorInk(theme) : colors.border, backgroundColor: colors.surface, color: colors.text }],
1634
1643
  testID: `${testID}-input`
1635
1644
  }
1636
1645
  ),
@@ -1648,7 +1657,7 @@ function TypeaheadControl({
1648
1657
  usePortal: true
1649
1658
  }
1650
1659
  ) : null,
1651
- hasError ? /* @__PURE__ */ jsx(Text, { role: "alert", style: [controlStyles.error, { color: semantic.error["500"] }], testID: `${testID}-error`, children: error }) : null
1660
+ hasError ? /* @__PURE__ */ jsx(Text, { role: "alert", style: [controlStyles.error, { color: fieldErrorInk(theme) }], testID: `${testID}-error`, children: error }) : null
1652
1661
  ] });
1653
1662
  }
1654
1663
  var WEB_DATE_PROPS = typeof document !== "undefined" ? { type: "date" } : {};