@dloizides/ui-feedback 1.17.0 → 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
@@ -595,13 +595,43 @@ var ConfirmDialog = ({
595
595
  }
596
596
  );
597
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
+ }
598
630
  var IS_WEB = reactNative.Platform.OS === "web";
599
631
  var WEB_FIXED_LAYER = { position: "fixed" };
600
632
  var DEFAULT_DURATION_MS = 3e3;
601
633
  var DEFAULT_FADE_MS = 200;
602
634
  var DEFAULT_MAX_LENGTH = 500;
603
- var TOAST_TOP_WEB = 10;
604
- var TOAST_TOP_MOBILE = 40;
605
635
  var TOAST_HORIZONTAL_MARGIN = 10;
606
636
  var TOAST_INITIAL_TRANSLATE_Y = -6;
607
637
  var TOAST_MAX_WIDTH = 600;
@@ -609,6 +639,11 @@ var TOAST_PADDING_HORIZONTAL = 16;
609
639
  var TOAST_PADDING_VERTICAL = 10;
610
640
  var TOAST_BORDER_RADIUS = 8;
611
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;
612
647
  var C0_CONTROL_END = 31;
613
648
  var C1_CONTROL_START = 127;
614
649
  var C1_CONTROL_END = 159;
@@ -618,7 +653,6 @@ var BYTE_ORDER_MARK = 65279;
618
653
  var styles7 = reactNative.StyleSheet.create({
619
654
  container: {
620
655
  position: "absolute",
621
- top: reactNative.Platform.OS === "web" ? TOAST_TOP_WEB : TOAST_TOP_MOBILE,
622
656
  left: TOAST_HORIZONTAL_MARGIN,
623
657
  right: TOAST_HORIZONTAL_MARGIN,
624
658
  alignItems: "center",
@@ -633,9 +667,26 @@ var styles7 = reactNative.StyleSheet.create({
633
667
  minWidth: "40%",
634
668
  maxWidth: TOAST_MAX_WIDTH,
635
669
  boxShadow: "0px 2px 4px rgba(0, 0, 0, 0.2)",
636
- 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"
637
688
  },
638
- text: {}
689
+ text: { flexShrink: 1 }
639
690
  });
640
691
  function sanitizeToastText(input, maxLength) {
641
692
  let stripped = "";
@@ -647,16 +698,11 @@ function sanitizeToastText(input, maxLength) {
647
698
  }
648
699
  return stripped.length > maxLength ? stripped.slice(0, maxLength) : stripped;
649
700
  }
650
- var ToastItem = ({ message, onDone, colors, durationMs, fadeMs, testID }) => {
701
+ var ToastItem = ({ message, onDone, tone, durationMs, fadeMs, testID }) => {
651
702
  const opacityRef = react.useRef(new reactNative.Animated.Value(0));
652
703
  const translateYRef = react.useRef(new reactNative.Animated.Value(TOAST_INITIAL_TRANSLATE_Y));
653
704
  const opacity = opacityRef.current;
654
705
  const translateY = translateYRef.current;
655
- const backgroundColor = react.useMemo(() => {
656
- if (message.type === "success") return colors.success;
657
- if (message.type === "error") return colors.error;
658
- return colors.primary;
659
- }, [colors.error, colors.primary, colors.success, message.type]);
660
706
  const handleDone = react.useCallback(() => {
661
707
  onDone(message.id);
662
708
  }, [message.id, onDone]);
@@ -675,14 +721,17 @@ var ToastItem = ({ message, onDone, colors, durationMs, fadeMs, testID }) => {
675
721
  return () => clearTimeout(hideTimer);
676
722
  }, [handleDone, opacity, translateY, durationMs, fadeMs]);
677
723
  const isError = message.type === "error";
678
- return /* @__PURE__ */ jsxRuntime.jsx(
724
+ return /* @__PURE__ */ jsxRuntime.jsxs(
679
725
  reactNative.Animated.View,
680
726
  {
681
727
  accessibilityLiveRegion: isError ? "assertive" : "polite",
682
728
  role: isError ? "alert" : "status",
683
- style: [styles7.toast, { backgroundColor, transform: [{ translateY }], opacity }],
729
+ style: [styles7.toast, { backgroundColor: tone.fill, borderColor: tone.border, transform: [{ translateY }], opacity }],
684
730
  testID,
685
- 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
+ ]
686
735
  }
687
736
  );
688
737
  };
@@ -696,16 +745,16 @@ var ToastHost = ({
696
745
  durationMs = DEFAULT_DURATION_MS,
697
746
  fadeMs = DEFAULT_FADE_MS,
698
747
  maxLength = DEFAULT_MAX_LENGTH,
699
- toastTestID = FEEDBACK_TEST_IDS.notificationToast
748
+ toastTestID = FEEDBACK_TEST_IDS.notificationToast,
749
+ topInset
700
750
  }) => {
701
751
  const [messages, setMessages] = react.useState([]);
702
752
  const { theme } = useFeedbackUi();
703
- const colors = react.useMemo(
753
+ const tones = react.useMemo(
704
754
  () => ({
705
- primary: theme.palette.primary["500"],
706
- success: (theme.semantic.success ?? theme.semantic.error)["500"],
707
- error: theme.semantic.error["500"],
708
- text: theme.colors.surfaceElevated
755
+ success: resolveToastTone(theme, "success"),
756
+ error: resolveToastTone(theme, "error"),
757
+ info: resolveToastTone(theme, "info")
709
758
  }),
710
759
  [theme]
711
760
  );
@@ -721,14 +770,14 @@ var ToastHost = ({
721
770
  react.useEffect(() => subscribe(push), [subscribe, push]);
722
771
  if (messages.length === 0) return null;
723
772
  const canPortal = IS_WEB && typeof document !== "undefined";
724
- 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(
725
774
  ToastItem,
726
775
  {
727
- colors,
728
776
  durationMs,
729
777
  fadeMs,
730
778
  message: m,
731
779
  testID: toastTestID,
780
+ tone: tones[m.type ?? "info"],
732
781
  onDone: remove
733
782
  },
734
783
  m.id