@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/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import { StyleSheet, Platform, TouchableOpacity, Text, View, ActivityIndicator, Modal, useWindowDimensions, Animated, Pressable } from 'react-native';
4
4
  import { MIN_TOUCH_TARGET_PX } from '@dloizides/a11y';
5
5
  import { Skeleton } from '@dloizides/ui-motion';
6
- import { Z_INDEX, resolveOnBrand } from '@dloizides/design-tokens';
6
+ import { Z_INDEX, resolveOnBrand, UI_DEEP_STEP, UI_MAIN_STEP, isHexColor, canCarryAccessibleInk } from '@dloizides/design-tokens';
7
7
  import { createPortal } from 'react-dom';
8
8
 
9
9
  // src/context/FeedbackUiContext.tsx
@@ -593,13 +593,43 @@ var ConfirmDialog = ({
593
593
  }
594
594
  );
595
595
  };
596
+ var APP_HEADER_HEIGHT = 64;
597
+ var HEADER_GAP = 8;
598
+ var TOAST_TOP_MOBILE = 40;
599
+ var TOAST_TOP_WEB = APP_HEADER_HEIGHT + HEADER_GAP;
600
+ var GLYPHS = {
601
+ success: "\u2713",
602
+ error: "!",
603
+ info: "i"
604
+ };
605
+ function scaleFor(theme, type) {
606
+ if (type === "error") return theme.semantic.error;
607
+ if (type === "success") return theme.semantic.success ?? theme.palette.primary;
608
+ return theme.palette.primary;
609
+ }
610
+ function readableInk(fill) {
611
+ if (fill === void 0 || !isHexColor(fill) || !canCarryAccessibleInk(fill)) return null;
612
+ return resolveOnBrand(fill);
613
+ }
614
+ function resolveToastTone(theme, type = "info") {
615
+ const scale2 = scaleFor(theme, type);
616
+ const glyph = GLYPHS[type];
617
+ const deep = scale2[UI_DEEP_STEP];
618
+ for (const fill of [scale2[UI_MAIN_STEP], deep]) {
619
+ const ink = readableInk(fill);
620
+ if (ink !== null && fill !== void 0) return { fill, ink, border: fill, glyph };
621
+ }
622
+ return { fill: theme.colors.surfaceElevated, ink: theme.colors.text, border: scale2[UI_MAIN_STEP], glyph };
623
+ }
624
+ function toastTop(isWeb, topInset) {
625
+ if (topInset !== void 0) return topInset;
626
+ return isWeb ? TOAST_TOP_WEB : TOAST_TOP_MOBILE;
627
+ }
596
628
  var IS_WEB = Platform.OS === "web";
597
629
  var WEB_FIXED_LAYER = { position: "fixed" };
598
630
  var DEFAULT_DURATION_MS = 3e3;
599
631
  var DEFAULT_FADE_MS = 200;
600
632
  var DEFAULT_MAX_LENGTH = 500;
601
- var TOAST_TOP_WEB = 10;
602
- var TOAST_TOP_MOBILE = 40;
603
633
  var TOAST_HORIZONTAL_MARGIN = 10;
604
634
  var TOAST_INITIAL_TRANSLATE_Y = -6;
605
635
  var TOAST_MAX_WIDTH = 600;
@@ -607,6 +637,11 @@ var TOAST_PADDING_HORIZONTAL = 16;
607
637
  var TOAST_PADDING_VERTICAL = 10;
608
638
  var TOAST_BORDER_RADIUS = 8;
609
639
  var TOAST_MARGIN_VERTICAL = 6;
640
+ var TOAST_GLYPH_SIZE = 20;
641
+ var TOAST_GLYPH_FONT_SIZE = 12;
642
+ var TOAST_GLYPH_LINE_HEIGHT = 18;
643
+ var TOAST_GLYPH_GAP = 10;
644
+ var TOAST_GLYPH_BORDER = 1.5;
610
645
  var C0_CONTROL_END = 31;
611
646
  var C1_CONTROL_START = 127;
612
647
  var C1_CONTROL_END = 159;
@@ -616,7 +651,6 @@ var BYTE_ORDER_MARK = 65279;
616
651
  var styles7 = StyleSheet.create({
617
652
  container: {
618
653
  position: "absolute",
619
- top: Platform.OS === "web" ? TOAST_TOP_WEB : TOAST_TOP_MOBILE,
620
654
  left: TOAST_HORIZONTAL_MARGIN,
621
655
  right: TOAST_HORIZONTAL_MARGIN,
622
656
  alignItems: "center",
@@ -631,9 +665,26 @@ var styles7 = StyleSheet.create({
631
665
  minWidth: "40%",
632
666
  maxWidth: TOAST_MAX_WIDTH,
633
667
  boxShadow: "0px 2px 4px rgba(0, 0, 0, 0.2)",
634
- elevation: 4
668
+ elevation: 4,
669
+ flexDirection: "row",
670
+ alignItems: "center",
671
+ gap: TOAST_GLYPH_GAP,
672
+ borderWidth: 1
673
+ },
674
+ glyph: {
675
+ width: TOAST_GLYPH_SIZE,
676
+ height: TOAST_GLYPH_SIZE,
677
+ borderRadius: TOAST_GLYPH_SIZE / 2,
678
+ borderWidth: TOAST_GLYPH_BORDER,
679
+ alignItems: "center",
680
+ justifyContent: "center"
681
+ },
682
+ glyphText: {
683
+ fontSize: TOAST_GLYPH_FONT_SIZE,
684
+ lineHeight: TOAST_GLYPH_LINE_HEIGHT,
685
+ fontWeight: "700"
635
686
  },
636
- text: {}
687
+ text: { flexShrink: 1 }
637
688
  });
638
689
  function sanitizeToastText(input, maxLength) {
639
690
  let stripped = "";
@@ -645,16 +696,11 @@ function sanitizeToastText(input, maxLength) {
645
696
  }
646
697
  return stripped.length > maxLength ? stripped.slice(0, maxLength) : stripped;
647
698
  }
648
- var ToastItem = ({ message, onDone, colors, durationMs, fadeMs, testID }) => {
699
+ var ToastItem = ({ message, onDone, tone, durationMs, fadeMs, testID }) => {
649
700
  const opacityRef = useRef(new Animated.Value(0));
650
701
  const translateYRef = useRef(new Animated.Value(TOAST_INITIAL_TRANSLATE_Y));
651
702
  const opacity = opacityRef.current;
652
703
  const translateY = translateYRef.current;
653
- const backgroundColor = useMemo(() => {
654
- if (message.type === "success") return colors.success;
655
- if (message.type === "error") return colors.error;
656
- return colors.primary;
657
- }, [colors.error, colors.primary, colors.success, message.type]);
658
704
  const handleDone = useCallback(() => {
659
705
  onDone(message.id);
660
706
  }, [message.id, onDone]);
@@ -673,14 +719,17 @@ var ToastItem = ({ message, onDone, colors, durationMs, fadeMs, testID }) => {
673
719
  return () => clearTimeout(hideTimer);
674
720
  }, [handleDone, opacity, translateY, durationMs, fadeMs]);
675
721
  const isError = message.type === "error";
676
- return /* @__PURE__ */ jsx(
722
+ return /* @__PURE__ */ jsxs(
677
723
  Animated.View,
678
724
  {
679
725
  accessibilityLiveRegion: isError ? "assertive" : "polite",
680
726
  role: isError ? "alert" : "status",
681
- style: [styles7.toast, { backgroundColor, transform: [{ translateY }], opacity }],
727
+ style: [styles7.toast, { backgroundColor: tone.fill, borderColor: tone.border, transform: [{ translateY }], opacity }],
682
728
  testID,
683
- children: /* @__PURE__ */ jsx(Text, { style: [styles7.text, { color: colors.text }], children: message.text })
729
+ children: [
730
+ /* @__PURE__ */ jsx(View, { "aria-hidden": true, importantForAccessibility: "no-hide-descendants", style: [styles7.glyph, { borderColor: tone.ink }], children: /* @__PURE__ */ jsx(Text, { style: [styles7.glyphText, { color: tone.ink }], children: tone.glyph }) }),
731
+ /* @__PURE__ */ jsx(Text, { style: [styles7.text, { color: tone.ink }], children: message.text })
732
+ ]
684
733
  }
685
734
  );
686
735
  };
@@ -694,16 +743,16 @@ var ToastHost = ({
694
743
  durationMs = DEFAULT_DURATION_MS,
695
744
  fadeMs = DEFAULT_FADE_MS,
696
745
  maxLength = DEFAULT_MAX_LENGTH,
697
- toastTestID = FEEDBACK_TEST_IDS.notificationToast
746
+ toastTestID = FEEDBACK_TEST_IDS.notificationToast,
747
+ topInset
698
748
  }) => {
699
749
  const [messages, setMessages] = useState([]);
700
750
  const { theme } = useFeedbackUi();
701
- const colors = useMemo(
751
+ const tones = useMemo(
702
752
  () => ({
703
- primary: theme.palette.primary["500"],
704
- success: (theme.semantic.success ?? theme.semantic.error)["500"],
705
- error: theme.semantic.error["500"],
706
- text: theme.colors.surfaceElevated
753
+ success: resolveToastTone(theme, "success"),
754
+ error: resolveToastTone(theme, "error"),
755
+ info: resolveToastTone(theme, "info")
707
756
  }),
708
757
  [theme]
709
758
  );
@@ -719,14 +768,14 @@ var ToastHost = ({
719
768
  useEffect(() => subscribe(push), [subscribe, push]);
720
769
  if (messages.length === 0) return null;
721
770
  const canPortal = IS_WEB && typeof document !== "undefined";
722
- const layer = /* @__PURE__ */ jsx(View, { style: [styles7.container, canPortal ? WEB_FIXED_LAYER : null], children: messages.map((m) => /* @__PURE__ */ jsx(
771
+ const layer = /* @__PURE__ */ jsx(View, { style: [styles7.container, { top: toastTop(IS_WEB, topInset) }, canPortal ? WEB_FIXED_LAYER : null], children: messages.map((m) => /* @__PURE__ */ jsx(
723
772
  ToastItem,
724
773
  {
725
- colors,
726
774
  durationMs,
727
775
  fadeMs,
728
776
  message: m,
729
777
  testID: toastTestID,
778
+ tone: tones[m.type ?? "info"],
730
779
  onDone: remove
731
780
  },
732
781
  m.id