@dloizides/ui-feedback 1.25.1 → 1.26.1

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,9 @@ import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import { Platform, StyleSheet, 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
+ import { Z_INDEX, isFocusVisible, resolveFocusRingColor, resolveOnBrand, UI_DEEP_STEP, UI_MAIN_STEP, focusRingOutline, isHexColor, canCarryAccessibleInk } from '@dloizides/design-tokens';
7
7
  import { createPortal } from 'react-dom';
8
+ import { LocalModelPhase } from '@dloizides/text-generation';
8
9
 
9
10
  // src/context/FeedbackUiContext.tsx
10
11
  var DEFAULT_FEEDBACK_VALUE = {
@@ -623,6 +624,32 @@ function confirmFill(theme, destructive) {
623
624
  function confirmInk(theme, destructive) {
624
625
  return resolveOnBrand(confirmFill(theme, destructive));
625
626
  }
627
+ var LIGHT_BRAND_STEP = "300";
628
+ var NO_RING = { outlineWidth: 0 };
629
+ var NATIVE_RING = {};
630
+ function buildDialogRingStyle(visible, color, isWeb) {
631
+ if (!isWeb) return NATIVE_RING;
632
+ return visible ? focusRingOutline(color) : NO_RING;
633
+ }
634
+ function dialogRingColor(theme) {
635
+ const colors = theme.colors;
636
+ return resolveFocusRingColor({
637
+ focusRing: colors.focusRing,
638
+ primary: theme.palette.primary["500"],
639
+ primaryLight: theme.palette.primary[LIGHT_BRAND_STEP],
640
+ text: colors.text,
641
+ background: colors.background
642
+ });
643
+ }
644
+ function useDialogFocusRing(color) {
645
+ const [visible, setVisible] = useState(false);
646
+ const onFocus = useCallback((event) => {
647
+ setVisible(isFocusVisible(event?.target));
648
+ }, []);
649
+ const onBlur = useCallback(() => setVisible(false), []);
650
+ const ringStyle = useMemo(() => buildDialogRingStyle(visible, color, Platform.OS === "web"), [visible, color]);
651
+ return { ringStyle, onFocus, onBlur };
652
+ }
626
653
  var DIALOG_MAX_WIDTH = 400;
627
654
  var styles8 = StyleSheet.create({
628
655
  overlay: {
@@ -691,6 +718,8 @@ var ConfirmDialog = ({
691
718
  const { theme, t } = useFeedbackUi();
692
719
  const titleId = useId();
693
720
  const innerDialogRole = Platform.OS === "web" ? void 0 : "dialog";
721
+ const cancelRing = useDialogFocusRing(dialogRingColor(theme));
722
+ const confirmRing = useDialogFocusRing(dialogRingColor(theme));
694
723
  const colorStyles = useMemo(
695
724
  () => ({
696
725
  dialog: { backgroundColor: theme.colors.surfaceElevated },
@@ -736,9 +765,12 @@ var ConfirmDialog = ({
736
765
  style: [
737
766
  styles8.button,
738
767
  styles8.cancelButton,
739
- colorStyles.cancelButton
768
+ colorStyles.cancelButton,
769
+ cancelRing.ringStyle
740
770
  ],
741
771
  testID: FEEDBACK_TEST_IDS.cancelConfirmButton,
772
+ onBlur: cancelRing.onBlur,
773
+ onFocus: cancelRing.onFocus,
742
774
  onPress: onCancel,
743
775
  children: /* @__PURE__ */ jsx(Text, { style: [styles8.buttonText, colorStyles.cancelButtonText], children: resolvedCancelLabel })
744
776
  }
@@ -755,9 +787,12 @@ var ConfirmDialog = ({
755
787
  styles8.button,
756
788
  styles8.confirmButton,
757
789
  colorStyles.confirmButton,
758
- isConfirmDisabled && styles8.disabledButton
790
+ isConfirmDisabled && styles8.disabledButton,
791
+ confirmRing.ringStyle
759
792
  ],
760
793
  testID: FEEDBACK_TEST_IDS.confirmButton,
794
+ onBlur: confirmRing.onBlur,
795
+ onFocus: confirmRing.onFocus,
761
796
  onPress: onConfirm,
762
797
  children: loading ? /* @__PURE__ */ jsx(
763
798
  ActivityIndicator,
@@ -1763,7 +1798,50 @@ function LiveRunCard(props) {
1763
1798
  showTimings && selected !== void 0 && selected.steps.length > 0 ? /* @__PURE__ */ jsx(RunStepBars, { steps: selected.steps, maxBars, labels, compact, testID: `${testID}-steps` }, selected.id) : null
1764
1799
  ] });
1765
1800
  }
1801
+ function useLocalModel(model) {
1802
+ const state = useSyncExternalStore(model.subscribe, model.state);
1803
+ useEffect(() => {
1804
+ model.check().catch(() => void 0);
1805
+ }, [model]);
1806
+ return state;
1807
+ }
1808
+ var PERCENT2 = 100;
1809
+ var LocalModelGate = ({
1810
+ model,
1811
+ labels,
1812
+ testIds,
1813
+ slots,
1814
+ children
1815
+ }) => {
1816
+ const { phase, block, progress } = useLocalModel(model);
1817
+ const consent = useCallback(() => {
1818
+ model.consent().catch(() => void 0);
1819
+ }, [model]);
1820
+ const { Card, Text: Text16, Button } = slots;
1821
+ switch (phase) {
1822
+ case LocalModelPhase.Checking:
1823
+ return null;
1824
+ case LocalModelPhase.Blocked:
1825
+ return /* @__PURE__ */ jsx(Card, { testID: testIds.blocked, children: /* @__PURE__ */ jsx(Text16, { children: labels.blocked(block) }) });
1826
+ case LocalModelPhase.Offer:
1827
+ return /* @__PURE__ */ jsxs(Card, { testID: testIds.offer, children: [
1828
+ /* @__PURE__ */ jsx(Text16, { heading: true, children: labels.title }),
1829
+ /* @__PURE__ */ jsx(Text16, { children: labels.offerBody }),
1830
+ /* @__PURE__ */ jsx(Button, { hint: labels.consentHint, label: labels.consent, testID: testIds.consent, onPress: consent })
1831
+ ] });
1832
+ case LocalModelPhase.Loading:
1833
+ return /* @__PURE__ */ jsx(Card, { testID: testIds.loading, children: /* @__PURE__ */ jsx(Text16, { children: labels.loading(String(Math.round(progress * PERCENT2))) }) });
1834
+ case LocalModelPhase.Failed:
1835
+ return /* @__PURE__ */ jsxs(Card, { testID: testIds.failed, children: [
1836
+ /* @__PURE__ */ jsx(Text16, { children: labels.failed }),
1837
+ /* @__PURE__ */ jsx(Button, { hint: labels.consentHint, label: labels.retry, testID: testIds.consent, onPress: consent })
1838
+ ] });
1839
+ case LocalModelPhase.Ready:
1840
+ default:
1841
+ return children;
1842
+ }
1843
+ };
1766
1844
 
1767
- export { AppErrorBoundary, AsyncSurface, COPY_FEEDBACK_MS, ConfirmDialog, CopyStatus, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, EmptyListState, ErrorNotice, ErrorReferenceRow, ErrorState, FEEDBACK_TEST_IDS, FeedbackUiProvider, LIVE_RUN_CARD_COMPACT_MAX_PX, LiveRunCard, LoadingFallback, MODAL_OVERLAY_COLOR, PageSkeleton, ProgressBar, ToastHost, FeedbackUiProvider as UiProvider, UiThemeOverride, WARMING_QUIET_PERIOD_MS, WarmingOverlay, barFraction, clampPercent, copyText, createToastBus, defaultGroupId, getWarmingSnapshot, mergeRunSteps, notifyWarming, progressPercent, readTraceId, runToneColor, settleWarming, splitShorterSteps, subscribeWarming, summariseDoneGroups, useCopyToClipboard, useFeedbackUi, useFeedbackUi as useUi };
1845
+ export { AppErrorBoundary, AsyncSurface, COPY_FEEDBACK_MS, ConfirmDialog, CopyStatus, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, EmptyListState, ErrorNotice, ErrorReferenceRow, ErrorState, FEEDBACK_TEST_IDS, FeedbackUiProvider, LIVE_RUN_CARD_COMPACT_MAX_PX, LiveRunCard, LoadingFallback, LocalModelGate, MODAL_OVERLAY_COLOR, PageSkeleton, ProgressBar, ToastHost, FeedbackUiProvider as UiProvider, UiThemeOverride, WARMING_QUIET_PERIOD_MS, WarmingOverlay, barFraction, clampPercent, copyText, createToastBus, defaultGroupId, getWarmingSnapshot, mergeRunSteps, notifyWarming, progressPercent, readTraceId, runToneColor, settleWarming, splitShorterSteps, subscribeWarming, summariseDoneGroups, useCopyToClipboard, useFeedbackUi, useLocalModel, useFeedbackUi as useUi };
1768
1846
  //# sourceMappingURL=index.mjs.map
1769
1847
  //# sourceMappingURL=index.mjs.map