@dloizides/ui-feedback 1.16.2 → 1.18.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.18.0
4
+
5
+ - `ToastHost`: the text and a new type glyph (check / ! / i) use an ink at 4.5:1 or better on the toast fill (`resolveOnBrand`; falls back to the 700 step, then the elevated surface with body text); success and error now differ by shape, not tint alone.
6
+ - `ToastHost`: the web layer sits at top 72 px so a 64 px app header no longer covers it; new `topInset` prop overrides it.
7
+ - `ToastHost`: a theme without a `success` scale uses `primary`, never `error`.
8
+
3
9
  ## 1.16.1
4
10
 
5
11
  - **LiveRunCard step names wrap to two lines instead of truncating** ("Phase A2: resolving offi..."). At wide
package/dist/index.d.mts CHANGED
@@ -267,8 +267,10 @@ interface ToastHostProps {
267
267
  maxLength?: number;
268
268
  /** testID for each toast (defaults to `notification-toast`). */
269
269
  toastTestID?: string;
270
+ /** Top offset of the toast layer (px). Default: 72 on web (below a 64 px header), 40 on native. */
271
+ topInset?: number;
270
272
  }
271
- declare const ToastHost: ({ subscribe, durationMs, fadeMs, maxLength, toastTestID, }: ToastHostProps) => React.ReactElement | null;
273
+ declare const ToastHost: ({ subscribe, durationMs, fadeMs, maxLength, toastTestID, topInset, }: ToastHostProps) => React.ReactElement | null;
272
274
 
273
275
  /**
274
276
  * WarmingOverlay — a calm, branded, full-screen "warming up…" overlay for the
package/dist/index.d.ts CHANGED
@@ -267,8 +267,10 @@ interface ToastHostProps {
267
267
  maxLength?: number;
268
268
  /** testID for each toast (defaults to `notification-toast`). */
269
269
  toastTestID?: string;
270
+ /** Top offset of the toast layer (px). Default: 72 on web (below a 64 px header), 40 on native. */
271
+ topInset?: number;
270
272
  }
271
- declare const ToastHost: ({ subscribe, durationMs, fadeMs, maxLength, toastTestID, }: ToastHostProps) => React.ReactElement | null;
273
+ declare const ToastHost: ({ subscribe, durationMs, fadeMs, maxLength, toastTestID, topInset, }: ToastHostProps) => React.ReactElement | null;
272
274
 
273
275
  /**
274
276
  * WarmingOverlay — a calm, branded, full-screen "warming up…" overlay for the
package/dist/index.js CHANGED
@@ -5,8 +5,8 @@ var jsxRuntime = require('react/jsx-runtime');
5
5
  var reactNative = require('react-native');
6
6
  var a11y = require('@dloizides/a11y');
7
7
  var uiMotion = require('@dloizides/ui-motion');
8
- var reactDom = require('react-dom');
9
8
  var designTokens = require('@dloizides/design-tokens');
9
+ var reactDom = require('react-dom');
10
10
 
11
11
  // src/context/FeedbackUiContext.tsx
12
12
  var DEFAULT_FEEDBACK_VALUE = {
@@ -430,6 +430,12 @@ var AsyncSurface = ({
430
430
  if (loading) return /* @__PURE__ */ jsxRuntime.jsx(PageSkeleton, { showHeader: true, rows: skeletonRows, variant });
431
431
  return children;
432
432
  };
433
+ function confirmFill(theme, destructive) {
434
+ return destructive ? theme.semantic.error["500"] : theme.palette.primary["500"];
435
+ }
436
+ function confirmInk(theme, destructive) {
437
+ return designTokens.resolveOnBrand(confirmFill(theme, destructive));
438
+ }
433
439
  var DIALOG_MAX_WIDTH = 400;
434
440
  var styles6 = reactNative.StyleSheet.create({
435
441
  overlay: {
@@ -505,10 +511,8 @@ var ConfirmDialog = ({
505
511
  message: { color: theme.colors.textSecondary },
506
512
  cancelButton: { borderColor: theme.colors.border },
507
513
  cancelButtonText: { color: theme.colors.text },
508
- confirmButton: {
509
- backgroundColor: destructive ? theme.semantic.error["500"] : theme.palette.primary["500"]
510
- },
511
- confirmButtonText: { color: theme.colors.surfaceElevated }
514
+ confirmButton: { backgroundColor: confirmFill(theme, destructive) },
515
+ confirmButtonText: { color: confirmInk(theme, destructive) }
512
516
  }),
513
517
  [theme, destructive]
514
518
  );
@@ -571,7 +575,7 @@ var ConfirmDialog = ({
571
575
  children: loading ? /* @__PURE__ */ jsxRuntime.jsx(
572
576
  reactNative.ActivityIndicator,
573
577
  {
574
- color: theme.colors.surfaceElevated,
578
+ color: confirmInk(theme, destructive),
575
579
  size: "small",
576
580
  testID: "confirm-loading"
577
581
  }
@@ -591,13 +595,43 @@ var ConfirmDialog = ({
591
595
  }
592
596
  );
593
597
  };
598
+ var APP_HEADER_HEIGHT = 64;
599
+ var HEADER_GAP = 8;
600
+ var TOAST_TOP_MOBILE = 40;
601
+ var TOAST_TOP_WEB = APP_HEADER_HEIGHT + HEADER_GAP;
602
+ var GLYPHS = {
603
+ success: "\u2713",
604
+ error: "!",
605
+ info: "i"
606
+ };
607
+ function scaleFor(theme, type) {
608
+ if (type === "error") return theme.semantic.error;
609
+ if (type === "success") return theme.semantic.success ?? theme.palette.primary;
610
+ return theme.palette.primary;
611
+ }
612
+ function readableInk(fill) {
613
+ if (fill === void 0 || !designTokens.isHexColor(fill) || !designTokens.canCarryAccessibleInk(fill)) return null;
614
+ return designTokens.resolveOnBrand(fill);
615
+ }
616
+ function resolveToastTone(theme, type = "info") {
617
+ const scale2 = scaleFor(theme, type);
618
+ const glyph = GLYPHS[type];
619
+ const deep = scale2[designTokens.UI_DEEP_STEP];
620
+ for (const fill of [scale2[designTokens.UI_MAIN_STEP], deep]) {
621
+ const ink = readableInk(fill);
622
+ if (ink !== null && fill !== void 0) return { fill, ink, border: fill, glyph };
623
+ }
624
+ return { fill: theme.colors.surfaceElevated, ink: theme.colors.text, border: scale2[designTokens.UI_MAIN_STEP], glyph };
625
+ }
626
+ function toastTop(isWeb, topInset) {
627
+ if (topInset !== void 0) return topInset;
628
+ return isWeb ? TOAST_TOP_WEB : TOAST_TOP_MOBILE;
629
+ }
594
630
  var IS_WEB = reactNative.Platform.OS === "web";
595
631
  var WEB_FIXED_LAYER = { position: "fixed" };
596
632
  var DEFAULT_DURATION_MS = 3e3;
597
633
  var DEFAULT_FADE_MS = 200;
598
634
  var DEFAULT_MAX_LENGTH = 500;
599
- var TOAST_TOP_WEB = 10;
600
- var TOAST_TOP_MOBILE = 40;
601
635
  var TOAST_HORIZONTAL_MARGIN = 10;
602
636
  var TOAST_INITIAL_TRANSLATE_Y = -6;
603
637
  var TOAST_MAX_WIDTH = 600;
@@ -605,6 +639,11 @@ var TOAST_PADDING_HORIZONTAL = 16;
605
639
  var TOAST_PADDING_VERTICAL = 10;
606
640
  var TOAST_BORDER_RADIUS = 8;
607
641
  var TOAST_MARGIN_VERTICAL = 6;
642
+ var TOAST_GLYPH_SIZE = 20;
643
+ var TOAST_GLYPH_FONT_SIZE = 12;
644
+ var TOAST_GLYPH_LINE_HEIGHT = 18;
645
+ var TOAST_GLYPH_GAP = 10;
646
+ var TOAST_GLYPH_BORDER = 1.5;
608
647
  var C0_CONTROL_END = 31;
609
648
  var C1_CONTROL_START = 127;
610
649
  var C1_CONTROL_END = 159;
@@ -614,7 +653,6 @@ var BYTE_ORDER_MARK = 65279;
614
653
  var styles7 = reactNative.StyleSheet.create({
615
654
  container: {
616
655
  position: "absolute",
617
- top: reactNative.Platform.OS === "web" ? TOAST_TOP_WEB : TOAST_TOP_MOBILE,
618
656
  left: TOAST_HORIZONTAL_MARGIN,
619
657
  right: TOAST_HORIZONTAL_MARGIN,
620
658
  alignItems: "center",
@@ -629,9 +667,26 @@ var styles7 = reactNative.StyleSheet.create({
629
667
  minWidth: "40%",
630
668
  maxWidth: TOAST_MAX_WIDTH,
631
669
  boxShadow: "0px 2px 4px rgba(0, 0, 0, 0.2)",
632
- elevation: 4
670
+ elevation: 4,
671
+ flexDirection: "row",
672
+ alignItems: "center",
673
+ gap: TOAST_GLYPH_GAP,
674
+ borderWidth: 1
675
+ },
676
+ glyph: {
677
+ width: TOAST_GLYPH_SIZE,
678
+ height: TOAST_GLYPH_SIZE,
679
+ borderRadius: TOAST_GLYPH_SIZE / 2,
680
+ borderWidth: TOAST_GLYPH_BORDER,
681
+ alignItems: "center",
682
+ justifyContent: "center"
683
+ },
684
+ glyphText: {
685
+ fontSize: TOAST_GLYPH_FONT_SIZE,
686
+ lineHeight: TOAST_GLYPH_LINE_HEIGHT,
687
+ fontWeight: "700"
633
688
  },
634
- text: {}
689
+ text: { flexShrink: 1 }
635
690
  });
636
691
  function sanitizeToastText(input, maxLength) {
637
692
  let stripped = "";
@@ -643,16 +698,11 @@ function sanitizeToastText(input, maxLength) {
643
698
  }
644
699
  return stripped.length > maxLength ? stripped.slice(0, maxLength) : stripped;
645
700
  }
646
- var ToastItem = ({ message, onDone, colors, durationMs, fadeMs, testID }) => {
701
+ var ToastItem = ({ message, onDone, tone, durationMs, fadeMs, testID }) => {
647
702
  const opacityRef = react.useRef(new reactNative.Animated.Value(0));
648
703
  const translateYRef = react.useRef(new reactNative.Animated.Value(TOAST_INITIAL_TRANSLATE_Y));
649
704
  const opacity = opacityRef.current;
650
705
  const translateY = translateYRef.current;
651
- const backgroundColor = react.useMemo(() => {
652
- if (message.type === "success") return colors.success;
653
- if (message.type === "error") return colors.error;
654
- return colors.primary;
655
- }, [colors.error, colors.primary, colors.success, message.type]);
656
706
  const handleDone = react.useCallback(() => {
657
707
  onDone(message.id);
658
708
  }, [message.id, onDone]);
@@ -671,14 +721,17 @@ var ToastItem = ({ message, onDone, colors, durationMs, fadeMs, testID }) => {
671
721
  return () => clearTimeout(hideTimer);
672
722
  }, [handleDone, opacity, translateY, durationMs, fadeMs]);
673
723
  const isError = message.type === "error";
674
- return /* @__PURE__ */ jsxRuntime.jsx(
724
+ return /* @__PURE__ */ jsxRuntime.jsxs(
675
725
  reactNative.Animated.View,
676
726
  {
677
727
  accessibilityLiveRegion: isError ? "assertive" : "polite",
678
728
  role: isError ? "alert" : "status",
679
- style: [styles7.toast, { backgroundColor, transform: [{ translateY }], opacity }],
729
+ style: [styles7.toast, { backgroundColor: tone.fill, borderColor: tone.border, transform: [{ translateY }], opacity }],
680
730
  testID,
681
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles7.text, { color: colors.text }], children: message.text })
731
+ children: [
732
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { "aria-hidden": true, importantForAccessibility: "no-hide-descendants", style: [styles7.glyph, { borderColor: tone.ink }], children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles7.glyphText, { color: tone.ink }], children: tone.glyph }) }),
733
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles7.text, { color: tone.ink }], children: message.text })
734
+ ]
682
735
  }
683
736
  );
684
737
  };
@@ -692,16 +745,16 @@ var ToastHost = ({
692
745
  durationMs = DEFAULT_DURATION_MS,
693
746
  fadeMs = DEFAULT_FADE_MS,
694
747
  maxLength = DEFAULT_MAX_LENGTH,
695
- toastTestID = FEEDBACK_TEST_IDS.notificationToast
748
+ toastTestID = FEEDBACK_TEST_IDS.notificationToast,
749
+ topInset
696
750
  }) => {
697
751
  const [messages, setMessages] = react.useState([]);
698
752
  const { theme } = useFeedbackUi();
699
- const colors = react.useMemo(
753
+ const tones = react.useMemo(
700
754
  () => ({
701
- primary: theme.palette.primary["500"],
702
- success: (theme.semantic.success ?? theme.semantic.error)["500"],
703
- error: theme.semantic.error["500"],
704
- text: theme.colors.surfaceElevated
755
+ success: resolveToastTone(theme, "success"),
756
+ error: resolveToastTone(theme, "error"),
757
+ info: resolveToastTone(theme, "info")
705
758
  }),
706
759
  [theme]
707
760
  );
@@ -717,14 +770,14 @@ var ToastHost = ({
717
770
  react.useEffect(() => subscribe(push), [subscribe, push]);
718
771
  if (messages.length === 0) return null;
719
772
  const canPortal = IS_WEB && typeof document !== "undefined";
720
- const layer = /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles7.container, canPortal ? WEB_FIXED_LAYER : null], children: messages.map((m) => /* @__PURE__ */ jsxRuntime.jsx(
773
+ const layer = /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [styles7.container, { top: toastTop(IS_WEB, topInset) }, canPortal ? WEB_FIXED_LAYER : null], children: messages.map((m) => /* @__PURE__ */ jsxRuntime.jsx(
721
774
  ToastItem,
722
775
  {
723
- colors,
724
776
  durationMs,
725
777
  fadeMs,
726
778
  message: m,
727
779
  testID: toastTestID,
780
+ tone: tones[m.type ?? "info"],
728
781
  onDone: remove
729
782
  },
730
783
  m.id