@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/dist/index.mjs CHANGED
@@ -3,8 +3,8 @@ 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, UI_DEEP_STEP, UI_MAIN_STEP, isHexColor, canCarryAccessibleInk } from '@dloizides/design-tokens';
6
7
  import { createPortal } from 'react-dom';
7
- import { Z_INDEX } from '@dloizides/design-tokens';
8
8
 
9
9
  // src/context/FeedbackUiContext.tsx
10
10
  var DEFAULT_FEEDBACK_VALUE = {
@@ -428,6 +428,12 @@ var AsyncSurface = ({
428
428
  if (loading) return /* @__PURE__ */ jsx(PageSkeleton, { showHeader: true, rows: skeletonRows, variant });
429
429
  return children;
430
430
  };
431
+ function confirmFill(theme, destructive) {
432
+ return destructive ? theme.semantic.error["500"] : theme.palette.primary["500"];
433
+ }
434
+ function confirmInk(theme, destructive) {
435
+ return resolveOnBrand(confirmFill(theme, destructive));
436
+ }
431
437
  var DIALOG_MAX_WIDTH = 400;
432
438
  var styles6 = StyleSheet.create({
433
439
  overlay: {
@@ -503,10 +509,8 @@ var ConfirmDialog = ({
503
509
  message: { color: theme.colors.textSecondary },
504
510
  cancelButton: { borderColor: theme.colors.border },
505
511
  cancelButtonText: { color: theme.colors.text },
506
- confirmButton: {
507
- backgroundColor: destructive ? theme.semantic.error["500"] : theme.palette.primary["500"]
508
- },
509
- confirmButtonText: { color: theme.colors.surfaceElevated }
512
+ confirmButton: { backgroundColor: confirmFill(theme, destructive) },
513
+ confirmButtonText: { color: confirmInk(theme, destructive) }
510
514
  }),
511
515
  [theme, destructive]
512
516
  );
@@ -569,7 +573,7 @@ var ConfirmDialog = ({
569
573
  children: loading ? /* @__PURE__ */ jsx(
570
574
  ActivityIndicator,
571
575
  {
572
- color: theme.colors.surfaceElevated,
576
+ color: confirmInk(theme, destructive),
573
577
  size: "small",
574
578
  testID: "confirm-loading"
575
579
  }
@@ -589,13 +593,43 @@ var ConfirmDialog = ({
589
593
  }
590
594
  );
591
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
+ }
592
628
  var IS_WEB = Platform.OS === "web";
593
629
  var WEB_FIXED_LAYER = { position: "fixed" };
594
630
  var DEFAULT_DURATION_MS = 3e3;
595
631
  var DEFAULT_FADE_MS = 200;
596
632
  var DEFAULT_MAX_LENGTH = 500;
597
- var TOAST_TOP_WEB = 10;
598
- var TOAST_TOP_MOBILE = 40;
599
633
  var TOAST_HORIZONTAL_MARGIN = 10;
600
634
  var TOAST_INITIAL_TRANSLATE_Y = -6;
601
635
  var TOAST_MAX_WIDTH = 600;
@@ -603,6 +637,11 @@ var TOAST_PADDING_HORIZONTAL = 16;
603
637
  var TOAST_PADDING_VERTICAL = 10;
604
638
  var TOAST_BORDER_RADIUS = 8;
605
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;
606
645
  var C0_CONTROL_END = 31;
607
646
  var C1_CONTROL_START = 127;
608
647
  var C1_CONTROL_END = 159;
@@ -612,7 +651,6 @@ var BYTE_ORDER_MARK = 65279;
612
651
  var styles7 = StyleSheet.create({
613
652
  container: {
614
653
  position: "absolute",
615
- top: Platform.OS === "web" ? TOAST_TOP_WEB : TOAST_TOP_MOBILE,
616
654
  left: TOAST_HORIZONTAL_MARGIN,
617
655
  right: TOAST_HORIZONTAL_MARGIN,
618
656
  alignItems: "center",
@@ -627,9 +665,26 @@ var styles7 = StyleSheet.create({
627
665
  minWidth: "40%",
628
666
  maxWidth: TOAST_MAX_WIDTH,
629
667
  boxShadow: "0px 2px 4px rgba(0, 0, 0, 0.2)",
630
- 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"
631
681
  },
632
- text: {}
682
+ glyphText: {
683
+ fontSize: TOAST_GLYPH_FONT_SIZE,
684
+ lineHeight: TOAST_GLYPH_LINE_HEIGHT,
685
+ fontWeight: "700"
686
+ },
687
+ text: { flexShrink: 1 }
633
688
  });
634
689
  function sanitizeToastText(input, maxLength) {
635
690
  let stripped = "";
@@ -641,16 +696,11 @@ function sanitizeToastText(input, maxLength) {
641
696
  }
642
697
  return stripped.length > maxLength ? stripped.slice(0, maxLength) : stripped;
643
698
  }
644
- var ToastItem = ({ message, onDone, colors, durationMs, fadeMs, testID }) => {
699
+ var ToastItem = ({ message, onDone, tone, durationMs, fadeMs, testID }) => {
645
700
  const opacityRef = useRef(new Animated.Value(0));
646
701
  const translateYRef = useRef(new Animated.Value(TOAST_INITIAL_TRANSLATE_Y));
647
702
  const opacity = opacityRef.current;
648
703
  const translateY = translateYRef.current;
649
- const backgroundColor = useMemo(() => {
650
- if (message.type === "success") return colors.success;
651
- if (message.type === "error") return colors.error;
652
- return colors.primary;
653
- }, [colors.error, colors.primary, colors.success, message.type]);
654
704
  const handleDone = useCallback(() => {
655
705
  onDone(message.id);
656
706
  }, [message.id, onDone]);
@@ -669,14 +719,17 @@ var ToastItem = ({ message, onDone, colors, durationMs, fadeMs, testID }) => {
669
719
  return () => clearTimeout(hideTimer);
670
720
  }, [handleDone, opacity, translateY, durationMs, fadeMs]);
671
721
  const isError = message.type === "error";
672
- return /* @__PURE__ */ jsx(
722
+ return /* @__PURE__ */ jsxs(
673
723
  Animated.View,
674
724
  {
675
725
  accessibilityLiveRegion: isError ? "assertive" : "polite",
676
726
  role: isError ? "alert" : "status",
677
- style: [styles7.toast, { backgroundColor, transform: [{ translateY }], opacity }],
727
+ style: [styles7.toast, { backgroundColor: tone.fill, borderColor: tone.border, transform: [{ translateY }], opacity }],
678
728
  testID,
679
- 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
+ ]
680
733
  }
681
734
  );
682
735
  };
@@ -690,16 +743,16 @@ var ToastHost = ({
690
743
  durationMs = DEFAULT_DURATION_MS,
691
744
  fadeMs = DEFAULT_FADE_MS,
692
745
  maxLength = DEFAULT_MAX_LENGTH,
693
- toastTestID = FEEDBACK_TEST_IDS.notificationToast
746
+ toastTestID = FEEDBACK_TEST_IDS.notificationToast,
747
+ topInset
694
748
  }) => {
695
749
  const [messages, setMessages] = useState([]);
696
750
  const { theme } = useFeedbackUi();
697
- const colors = useMemo(
751
+ const tones = useMemo(
698
752
  () => ({
699
- primary: theme.palette.primary["500"],
700
- success: (theme.semantic.success ?? theme.semantic.error)["500"],
701
- error: theme.semantic.error["500"],
702
- text: theme.colors.surfaceElevated
753
+ success: resolveToastTone(theme, "success"),
754
+ error: resolveToastTone(theme, "error"),
755
+ info: resolveToastTone(theme, "info")
703
756
  }),
704
757
  [theme]
705
758
  );
@@ -715,14 +768,14 @@ var ToastHost = ({
715
768
  useEffect(() => subscribe(push), [subscribe, push]);
716
769
  if (messages.length === 0) return null;
717
770
  const canPortal = IS_WEB && typeof document !== "undefined";
718
- 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(
719
772
  ToastItem,
720
773
  {
721
- colors,
722
774
  durationMs,
723
775
  fadeMs,
724
776
  message: m,
725
777
  testID: toastTestID,
778
+ tone: tones[m.type ?? "info"],
726
779
  onDone: remove
727
780
  },
728
781
  m.id