@btndprojects/loam-ui-native 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dist/accordion/index.js +3 -0
- package/dist/adaptive/index.js +2 -0
- package/dist/alert/index.js +3 -0
- package/dist/analyzer/index.js +6 -0
- package/dist/announcement/index.js +6 -0
- package/dist/audio-player/index.js +3 -0
- package/dist/avatar/index.js +3 -0
- package/dist/avatar-group/index.js +3 -0
- package/dist/badge/index.js +5 -0
- package/dist/banner/index.js +2 -0
- package/dist/board/index.js +7 -0
- package/dist/button/index.js +5 -0
- package/dist/camera-permission/index.js +13 -0
- package/dist/capture-result/index.js +18 -0
- package/dist/card/index.js +4 -0
- package/dist/card-form/index.js +10 -0
- package/dist/carousel/index.js +2 -0
- package/dist/chart/index.js +6 -0
- package/dist/charts/index.js +7 -0
- package/dist/checkbox/index.js +7 -0
- package/dist/checklist/index.js +10 -0
- package/dist/checkout/index.js +13 -0
- package/dist/chip/index.js +7 -0
- package/dist/chunk-223Q2T2Q.js +229 -0
- package/dist/chunk-2A5NIQAK.js +254 -0
- package/dist/chunk-2GK6PHGE.js +363 -0
- package/dist/chunk-2WUTXHMU.js +1 -0
- package/dist/chunk-2ZZ7TDJ4.js +324 -0
- package/dist/chunk-35OFI3JG.js +499 -0
- package/dist/chunk-3ARE4TES.js +195 -0
- package/dist/chunk-3ECPOSKO.js +1 -0
- package/dist/chunk-3ENTMPQY.js +229 -0
- package/dist/chunk-3HJH6FF4.js +98 -0
- package/dist/chunk-3NMD74ZU.js +4 -0
- package/dist/chunk-3WPW4KUN.js +182 -0
- package/dist/chunk-47FWHGUN.js +394 -0
- package/dist/chunk-4BXMXBJO.js +141 -0
- package/dist/chunk-4DS5ZWVC.js +83 -0
- package/dist/chunk-4GBOGOTV.js +295 -0
- package/dist/chunk-4SZYY6AN.js +99 -0
- package/dist/chunk-4YIP3CWS.js +237 -0
- package/dist/chunk-4YQOR7JM.js +204 -0
- package/dist/chunk-4ZAHCY44.js +177 -0
- package/dist/chunk-52X2VYTD.js +228 -0
- package/dist/chunk-5P26LBDL.js +1 -0
- package/dist/chunk-5XLRYDAX.js +1 -0
- package/dist/chunk-5YNTNN5A.js +177 -0
- package/dist/chunk-66SG2H23.js +129 -0
- package/dist/chunk-6HT2LP62.js +504 -0
- package/dist/chunk-6N33LFQA.js +35 -0
- package/dist/chunk-6X6PQ443.js +432 -0
- package/dist/chunk-7CFF4HXS.js +126 -0
- package/dist/chunk-7O2FMUPT.js +755 -0
- package/dist/chunk-AI4DWZCD.js +162 -0
- package/dist/chunk-AWJOCGFZ.js +213 -0
- package/dist/chunk-AZRX6SAC.js +285 -0
- package/dist/chunk-B54QE2FN.js +1 -0
- package/dist/chunk-BC475SJH.js +1 -0
- package/dist/chunk-BEDBFJND.js +202 -0
- package/dist/chunk-BTTFCMKG.js +166 -0
- package/dist/chunk-BV3B2HYZ.js +1635 -0
- package/dist/chunk-C2NTXVWM.js +98 -0
- package/dist/chunk-CDRZHT42.js +424 -0
- package/dist/chunk-CJ5EOYZE.js +62 -0
- package/dist/chunk-CUMUNPXY.js +128 -0
- package/dist/chunk-CUS3ZSCU.js +1 -0
- package/dist/chunk-CYRBHQQZ.js +411 -0
- package/dist/chunk-DHWADYZX.js +144 -0
- package/dist/chunk-DKCSPATL.js +1 -0
- package/dist/chunk-DM5QUKKO.js +326 -0
- package/dist/chunk-DSJBXLUG.js +845 -0
- package/dist/chunk-DYBH2I6W.js +1 -0
- package/dist/chunk-DZ255O2F.js +1 -0
- package/dist/chunk-E35BPSGW.js +1 -0
- package/dist/chunk-EJBDRVIH.js +166 -0
- package/dist/chunk-F43NP42L.js +1 -0
- package/dist/chunk-F5XNPWS7.js +1024 -0
- package/dist/chunk-FIF2M24N.js +1521 -0
- package/dist/chunk-FOKG57CR.js +993 -0
- package/dist/chunk-G3HOYSF7.js +1 -0
- package/dist/chunk-GDKZTW34.js +395 -0
- package/dist/chunk-GL7B2DOW.js +134 -0
- package/dist/chunk-GNNJ4GCC.js +471 -0
- package/dist/chunk-GNZ56EUI.js +1 -0
- package/dist/chunk-H6NIOQHK.js +346 -0
- package/dist/chunk-H6PC7RDA.js +1 -0
- package/dist/chunk-HPPW424V.js +334 -0
- package/dist/chunk-HQOQIBJI.js +1 -0
- package/dist/chunk-HU2EQNRZ.js +44 -0
- package/dist/chunk-IIQTAY3J.js +715 -0
- package/dist/chunk-ITTYJZWX.js +271 -0
- package/dist/chunk-IVNRBPGC.js +1018 -0
- package/dist/chunk-J4KLDGI4.js +1 -0
- package/dist/chunk-J7Q7VCVC.js +254 -0
- package/dist/chunk-JDEOITQ2.js +1 -0
- package/dist/chunk-JNH2TYIN.js +96 -0
- package/dist/chunk-JRLTGLN4.js +1 -0
- package/dist/chunk-JTRJJLKL.js +1 -0
- package/dist/chunk-JUAMLEHX.js +379 -0
- package/dist/chunk-JXJB2X6M.js +131 -0
- package/dist/chunk-KMI5ML5I.js +262 -0
- package/dist/chunk-KTAC4MGE.js +4 -0
- package/dist/chunk-LAECSR4H.js +178 -0
- package/dist/chunk-LK4BCSGX.js +1 -0
- package/dist/chunk-LOE5YNN3.js +470 -0
- package/dist/chunk-LRJNDEIA.js +302 -0
- package/dist/chunk-LSS54GLJ.js +116 -0
- package/dist/chunk-LZLHELAG.js +137 -0
- package/dist/chunk-M2LUXGKZ.js +1 -0
- package/dist/chunk-MOUJOP55.js +425 -0
- package/dist/chunk-N32RGOA5.js +159 -0
- package/dist/chunk-N5ZNE2YE.js +1 -0
- package/dist/chunk-NBNCBML6.js +1 -0
- package/dist/chunk-NKB7BZYK.js +167 -0
- package/dist/chunk-NQYBUO3K.js +1795 -0
- package/dist/chunk-NY2U3PBI.js +59 -0
- package/dist/chunk-O4AEHWII.js +464 -0
- package/dist/chunk-O7AE6DAF.js +146 -0
- package/dist/chunk-OETCUXQP.js +134 -0
- package/dist/chunk-OOPPQH27.js +179 -0
- package/dist/chunk-OPXFZ4Y5.js +204 -0
- package/dist/chunk-P23EQNRQ.js +338 -0
- package/dist/chunk-PJXUJYS6.js +248 -0
- package/dist/chunk-PNWUWOBF.js +1 -0
- package/dist/chunk-PUPM2YGF.js +376 -0
- package/dist/chunk-PZXZJBMP.js +620 -0
- package/dist/chunk-Q72LJOVE.js +169 -0
- package/dist/chunk-QCDXZBC5.js +247 -0
- package/dist/chunk-QDYDBCFP.js +197 -0
- package/dist/chunk-QJJ6MADV.js +274 -0
- package/dist/chunk-QKXCPTFS.js +349 -0
- package/dist/chunk-QWCMU5B2.js +860 -0
- package/dist/chunk-RGQWWKLA.js +634 -0
- package/dist/chunk-RIBDXGUG.js +108 -0
- package/dist/chunk-RJQOOHT2.js +214 -0
- package/dist/chunk-RNGLIHFA.js +191 -0
- package/dist/chunk-RQ3HASCC.js +6 -0
- package/dist/chunk-RSOJT5YW.js +124 -0
- package/dist/chunk-RTIKSY6A.js +1 -0
- package/dist/chunk-RUZHTGKB.js +237 -0
- package/dist/chunk-RW6ZL2FQ.js +284 -0
- package/dist/chunk-S7F6XLTK.js +540 -0
- package/dist/chunk-SBMNWWBV.js +155 -0
- package/dist/chunk-SDTQPRRB.js +1 -0
- package/dist/chunk-SYNOJOQO.js +377 -0
- package/dist/chunk-T753XT36.js +1 -0
- package/dist/chunk-TKQYWZ5V.js +196 -0
- package/dist/chunk-TKVFVF5D.js +95 -0
- package/dist/chunk-TOXAGRDQ.js +144 -0
- package/dist/chunk-TUTI5HOZ.js +112 -0
- package/dist/chunk-U7TFM2JA.js +140 -0
- package/dist/chunk-UC2WGUP3.js +627 -0
- package/dist/chunk-UWFLYMAR.js +1126 -0
- package/dist/chunk-UWSZB7BJ.js +1 -0
- package/dist/chunk-UYG5L34B.js +87 -0
- package/dist/chunk-VBOXAEPI.js +336 -0
- package/dist/chunk-VCDBXW5H.js +188 -0
- package/dist/chunk-VCXPHHDS.js +1 -0
- package/dist/chunk-VEAYTRPX.js +414 -0
- package/dist/chunk-VFCUIDRT.js +1 -0
- package/dist/chunk-VQHPQEUH.js +273 -0
- package/dist/chunk-VXDZFJGP.js +874 -0
- package/dist/chunk-WS56BL3D.js +1 -0
- package/dist/chunk-WSW6ZFAQ.js +98 -0
- package/dist/chunk-WVKKJA6U.js +870 -0
- package/dist/chunk-XNUVB5OL.js +375 -0
- package/dist/chunk-XOSCY2CW.js +242 -0
- package/dist/chunk-XXXEFXY5.js +99 -0
- package/dist/chunk-Y5CSSPV4.js +1 -0
- package/dist/chunk-Y6DU4J47.js +1 -0
- package/dist/chunk-YC6WORFL.js +535 -0
- package/dist/chunk-YDGVJETP.js +60 -0
- package/dist/chunk-YF4NSSMT.js +366 -0
- package/dist/chunk-YG3ZJHGU.js +223 -0
- package/dist/chunk-YIJ55TBC.js +1 -0
- package/dist/chunk-YKZ4RZZF.js +1 -0
- package/dist/chunk-YLLCXTMC.js +37 -0
- package/dist/chunk-YTA74UZR.js +1 -0
- package/dist/chunk-Z7H7VSFZ.js +323 -0
- package/dist/chunk-ZK2H4O5P.js +1 -0
- package/dist/chunk-ZVFE5QGU.js +524 -0
- package/dist/coachmark/index.js +4 -0
- package/dist/code-block/index.js +4 -0
- package/dist/color-field/index.js +7 -0
- package/dist/commerce/index.js +20 -0
- package/dist/connectivity/index.js +2 -0
- package/dist/context-menu/index.js +5 -0
- package/dist/copy-button/index.js +3 -0
- package/dist/data-grid/index.js +24 -0
- package/dist/date-range-picker/index.js +13 -0
- package/dist/description-list/index.js +2 -0
- package/dist/dialog/index.js +3 -0
- package/dist/empty-state/index.js +3 -0
- package/dist/error-summary/index.js +3 -0
- package/dist/fab/index.js +2 -0
- package/dist/file-upload/index.js +9 -0
- package/dist/filter-bar/index.js +8 -0
- package/dist/flow-run/index.js +14 -0
- package/dist/form/index.js +3 -0
- package/dist/gallery/index.js +2 -0
- package/dist/header/index.js +5 -0
- package/dist/hold-to-confirm/index.js +4 -0
- package/dist/index.d.ts +22883 -0
- package/dist/index.js +158 -0
- package/dist/infinite-list/index.js +2 -0
- package/dist/inline-edit/index.js +5 -0
- package/dist/input/index.js +5 -0
- package/dist/interactions/index.js +2 -0
- package/dist/invoice/index.js +10 -0
- package/dist/kbd/index.js +1 -0
- package/dist/keyboard/index.js +3 -0
- package/dist/list-row/index.js +7 -0
- package/dist/log-viewer/index.js +2 -0
- package/dist/map-view/index.js +3 -0
- package/dist/markdown/index.js +6 -0
- package/dist/metric/index.js +4 -0
- package/dist/money/index.js +3 -0
- package/dist/nav-drawer/index.js +2 -0
- package/dist/navigation/index.js +2 -0
- package/dist/notification-center/index.js +16 -0
- package/dist/number-roll/index.js +3 -0
- package/dist/one-handed/index.js +5 -0
- package/dist/os-surfaces/index.js +3 -0
- package/dist/otp/index.js +7 -0
- package/dist/page-header/index.js +1 -0
- package/dist/payment-method/index.js +12 -0
- package/dist/payment-status/index.js +16 -0
- package/dist/permission/index.js +2 -0
- package/dist/picker/index.js +7 -0
- package/dist/progress/index.js +5 -0
- package/dist/pull-to-refresh/index.js +4 -0
- package/dist/radio-group/index.js +6 -0
- package/dist/rating/index.js +2 -0
- package/dist/receivables/index.js +20 -0
- package/dist/refund/index.js +16 -0
- package/dist/save-status/index.js +3 -0
- package/dist/scroll-area/index.js +1 -0
- package/dist/search-bar/index.js +5 -0
- package/dist/segmented-control/index.js +5 -0
- package/dist/sheet/index.js +4 -0
- package/dist/skeleton/index.js +2 -0
- package/dist/slider/index.js +5 -0
- package/dist/spinner/index.js +2 -0
- package/dist/split-button/index.js +7 -0
- package/dist/spotlight/index.js +2 -0
- package/dist/stage-timeline/index.js +4 -0
- package/dist/status-dot/index.js +2 -0
- package/dist/stepper/index.js +6 -0
- package/dist/streaming-text/index.js +3 -0
- package/dist/survey/index.js +19 -0
- package/dist/switch/index.js +5 -0
- package/dist/system-state/index.js +4 -0
- package/dist/tab-bar/index.js +2 -0
- package/dist/tabs/index.js +2 -0
- package/dist/textarea/index.js +6 -0
- package/dist/thinking/index.js +2 -0
- package/dist/timeline/index.js +4 -0
- package/dist/toast/index.js +2 -0
- package/dist/toolbar/index.js +2 -0
- package/dist/tour/index.js +11 -0
- package/dist/truncation-notice/index.js +2 -0
- package/dist/update-notice/index.js +11 -0
- package/dist/video-player/index.js +2 -0
- package/dist/viewfinder/index.js +5 -0
- package/dist/widget/index.js +4 -0
- package/dist/wizard/index.js +6 -0
- package/package.json +76 -3
- package/README.md +0 -3
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Animated, Easing, View, Text } from 'react-native';
|
|
3
|
+
import { createStyleSheet, useLoamTheme, useStyles } from '@btndprojects/loam-theme-native';
|
|
4
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/thinking/thinking.tsx
|
|
7
|
+
var DOT_BOX = { sm: 6, md: 8, lg: 10 };
|
|
8
|
+
function useThinkingPulse(active) {
|
|
9
|
+
const theme = useLoamTheme();
|
|
10
|
+
const p = React.useRef(new Animated.Value(0)).current;
|
|
11
|
+
const { duration, easing } = theme.motion.loop;
|
|
12
|
+
React.useEffect(() => {
|
|
13
|
+
if (!active) {
|
|
14
|
+
p.setValue(0);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const bezier = Easing.bezier(...easing);
|
|
18
|
+
const loop = Animated.loop(
|
|
19
|
+
Animated.sequence([
|
|
20
|
+
Animated.timing(p, { toValue: 1, duration, easing: bezier, useNativeDriver: true }),
|
|
21
|
+
Animated.timing(p, { toValue: 0, duration, easing: bezier, useNativeDriver: true })
|
|
22
|
+
])
|
|
23
|
+
);
|
|
24
|
+
loop.start();
|
|
25
|
+
return () => loop.stop();
|
|
26
|
+
}, [active, p, duration, easing]);
|
|
27
|
+
return active ? {
|
|
28
|
+
opacity: p.interpolate({ inputRange: [0, 1], outputRange: [1, 0.55] }),
|
|
29
|
+
transform: [{ scale: p.interpolate({ inputRange: [0, 1], outputRange: [1, 0.9] }) }]
|
|
30
|
+
} : null;
|
|
31
|
+
}
|
|
32
|
+
function Thinking({
|
|
33
|
+
label = "Thinking\u2026",
|
|
34
|
+
size = "md",
|
|
35
|
+
tone = "working",
|
|
36
|
+
motion = "full",
|
|
37
|
+
announce = true,
|
|
38
|
+
accessibleLabel = "Thinking",
|
|
39
|
+
style,
|
|
40
|
+
testID
|
|
41
|
+
}) {
|
|
42
|
+
const { styles } = useStyles(sheet, { tone, size });
|
|
43
|
+
const theme = useLoamTheme();
|
|
44
|
+
const pulseStyle = useThinkingPulse(motion === "full" && !theme.reduceMotion);
|
|
45
|
+
const hasLabel = label !== "";
|
|
46
|
+
const box = DOT_BOX[size];
|
|
47
|
+
const dotColor = tone === "accent" ? theme.color.accent : tone === "neutral" ? theme.color.text2 : theme.status.working;
|
|
48
|
+
const name = hasLabel ? label : accessibleLabel;
|
|
49
|
+
const liveProps = announce ? { accessibilityLiveRegion: "polite", role: "status", accessibilityLabel: name } : {};
|
|
50
|
+
return /* @__PURE__ */ jsxs(View, { ...liveProps, testID, style: [styles.root, style], children: [
|
|
51
|
+
/* @__PURE__ */ jsx(
|
|
52
|
+
Animated.View,
|
|
53
|
+
{
|
|
54
|
+
style: [
|
|
55
|
+
{ width: box, height: box, borderRadius: theme.radius.full, backgroundColor: dotColor },
|
|
56
|
+
pulseStyle
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
),
|
|
60
|
+
hasLabel ? /* @__PURE__ */ jsx(Text, { style: styles.label, children: label }) : null
|
|
61
|
+
] });
|
|
62
|
+
}
|
|
63
|
+
var sheet = createStyleSheet((theme) => ({
|
|
64
|
+
root: {
|
|
65
|
+
flexDirection: "row",
|
|
66
|
+
alignItems: "center",
|
|
67
|
+
alignSelf: "flex-start",
|
|
68
|
+
gap: theme.space.s2
|
|
69
|
+
},
|
|
70
|
+
label: {
|
|
71
|
+
fontFamily: theme.font.sans,
|
|
72
|
+
variants: {
|
|
73
|
+
tone: {
|
|
74
|
+
working: { color: theme.color.text },
|
|
75
|
+
accent: { color: theme.color.text },
|
|
76
|
+
neutral: { color: theme.color.text2 }
|
|
77
|
+
},
|
|
78
|
+
size: {
|
|
79
|
+
sm: {
|
|
80
|
+
fontSize: theme.type.caption1.fontSize,
|
|
81
|
+
lineHeight: theme.type.caption1.lineHeight,
|
|
82
|
+
letterSpacing: theme.type.caption1.letterSpacing
|
|
83
|
+
},
|
|
84
|
+
md: {
|
|
85
|
+
fontSize: theme.type.footnote.fontSize,
|
|
86
|
+
lineHeight: theme.type.footnote.lineHeight,
|
|
87
|
+
letterSpacing: theme.type.footnote.letterSpacing
|
|
88
|
+
},
|
|
89
|
+
lg: {
|
|
90
|
+
fontSize: theme.type.subheadline.fontSize,
|
|
91
|
+
lineHeight: theme.type.subheadline.lineHeight,
|
|
92
|
+
letterSpacing: theme.type.subheadline.letterSpacing
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}));
|
|
98
|
+
|
|
99
|
+
export { Thinking, useThinkingPulse };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
import { Coachmark, CoachmarkDots } from './chunk-P23EQNRQ.js';
|
|
2
|
+
import { useTourHost, Highlight, Beacon, useTourInsets } from './chunk-JUAMLEHX.js';
|
|
3
|
+
import { Progress } from './chunk-2ZZ7TDJ4.js';
|
|
4
|
+
import { Button } from './chunk-3ARE4TES.js';
|
|
5
|
+
import { Icon } from './chunk-TKVFVF5D.js';
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import { BackHandler, Pressable, View, Text } from 'react-native';
|
|
8
|
+
import { createStyleSheet, useLoamTheme, useStyles } from '@btndprojects/loam-theme-native';
|
|
9
|
+
import { materializeTour, resolveText, stepsForSurface, kindFor, canAttachGate, isStepGated, highlightFor, shouldSkipMissingStep, hintRuns } from '@btndprojects/loam-engage';
|
|
10
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
11
|
+
|
|
12
|
+
var DEFAULT_LABELS = {
|
|
13
|
+
back: "Back",
|
|
14
|
+
next: "Next",
|
|
15
|
+
finish: "Finish",
|
|
16
|
+
skipStep: "Skip this step",
|
|
17
|
+
waiting: "Do it to continue",
|
|
18
|
+
leave: "Leave the tour",
|
|
19
|
+
minimise: "Minimise \xB7 resume later",
|
|
20
|
+
resume: "Resume tour",
|
|
21
|
+
beacon: "Something new here",
|
|
22
|
+
opening: "Opening",
|
|
23
|
+
step: "Step"
|
|
24
|
+
};
|
|
25
|
+
var TourContext = React.createContext(null);
|
|
26
|
+
function TourProvider({
|
|
27
|
+
children,
|
|
28
|
+
defaultActiveId = null
|
|
29
|
+
}) {
|
|
30
|
+
const [activeId, setActiveId] = React.useState(defaultActiveId);
|
|
31
|
+
const listeners = React.useRef(/* @__PURE__ */ new Set());
|
|
32
|
+
const value = React.useMemo(
|
|
33
|
+
() => ({
|
|
34
|
+
activeId,
|
|
35
|
+
start: setActiveId,
|
|
36
|
+
stop: () => setActiveId(null),
|
|
37
|
+
// Copied before iterating: a listener that unsubscribes itself on the
|
|
38
|
+
// event it was waiting for would otherwise mutate the set mid-loop.
|
|
39
|
+
track: (event, props) => [...listeners.current].forEach((fn) => fn(event, props)),
|
|
40
|
+
subscribe: (listener) => {
|
|
41
|
+
listeners.current.add(listener);
|
|
42
|
+
return () => listeners.current.delete(listener);
|
|
43
|
+
}
|
|
44
|
+
}),
|
|
45
|
+
[activeId]
|
|
46
|
+
);
|
|
47
|
+
return /* @__PURE__ */ jsx(TourContext.Provider, { value, children });
|
|
48
|
+
}
|
|
49
|
+
function useTour() {
|
|
50
|
+
const ctx = React.useContext(TourContext);
|
|
51
|
+
if (!ctx) throw new Error("useTour must be used inside a <TourProvider>.");
|
|
52
|
+
return ctx;
|
|
53
|
+
}
|
|
54
|
+
function Tour({
|
|
55
|
+
steps,
|
|
56
|
+
id,
|
|
57
|
+
name,
|
|
58
|
+
open: openProp,
|
|
59
|
+
defaultOpen = false,
|
|
60
|
+
onOpenChange,
|
|
61
|
+
stepIndex: stepProp,
|
|
62
|
+
defaultStepIndex = 0,
|
|
63
|
+
onStepIndexChange,
|
|
64
|
+
variants,
|
|
65
|
+
variantId,
|
|
66
|
+
metadata,
|
|
67
|
+
locale,
|
|
68
|
+
defaultLocale,
|
|
69
|
+
surface = "auto",
|
|
70
|
+
cardVariant,
|
|
71
|
+
route,
|
|
72
|
+
onNavigate,
|
|
73
|
+
onAction,
|
|
74
|
+
onComplete,
|
|
75
|
+
onDismiss,
|
|
76
|
+
onEvent,
|
|
77
|
+
minimisable = true,
|
|
78
|
+
labels: labelOverrides,
|
|
79
|
+
motion = "full"
|
|
80
|
+
}) {
|
|
81
|
+
const ctx = React.useContext(TourContext);
|
|
82
|
+
const host = useTourHost();
|
|
83
|
+
const labels = React.useMemo(() => ({ ...DEFAULT_LABELS, ...labelOverrides }), [labelOverrides]);
|
|
84
|
+
const touch = surface !== "pointer";
|
|
85
|
+
const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);
|
|
86
|
+
const open = openProp ?? (id && ctx ? ctx.activeId === id : uncontrolledOpen);
|
|
87
|
+
const [uncontrolledStep, setUncontrolledStep] = React.useState(defaultStepIndex);
|
|
88
|
+
const rawIndex = stepProp ?? uncontrolledStep;
|
|
89
|
+
const [minimised, setMinimised] = React.useState(false);
|
|
90
|
+
const [beaconOpen, setBeaconOpen] = React.useState(false);
|
|
91
|
+
const flow = React.useMemo(
|
|
92
|
+
() => materializeTour(steps, variants, metadata, variantId).steps,
|
|
93
|
+
[steps, variants, metadata, variantId]
|
|
94
|
+
);
|
|
95
|
+
const t = React.useCallback(
|
|
96
|
+
(value) => resolveText(value, locale, defaultLocale),
|
|
97
|
+
[locale, defaultLocale]
|
|
98
|
+
);
|
|
99
|
+
const visible = React.useMemo(
|
|
100
|
+
() => stepsForSurface(flow, touch ? "touch" : "pointer"),
|
|
101
|
+
[flow, touch]
|
|
102
|
+
);
|
|
103
|
+
const total = visible.length;
|
|
104
|
+
const index = Math.min(Math.max(rawIndex, 0), Math.max(0, total - 1));
|
|
105
|
+
const step = visible[index];
|
|
106
|
+
const stepRef = React.useRef(step);
|
|
107
|
+
stepRef.current = step;
|
|
108
|
+
const emit = React.useCallback(
|
|
109
|
+
(eventName, props) => {
|
|
110
|
+
onEvent?.({ name: eventName, step: index, of: total, stepId: step?.id, props });
|
|
111
|
+
},
|
|
112
|
+
[onEvent, index, total, step]
|
|
113
|
+
);
|
|
114
|
+
const emitRef = React.useRef(emit);
|
|
115
|
+
emitRef.current = emit;
|
|
116
|
+
const setIndex = React.useCallback(
|
|
117
|
+
(next) => {
|
|
118
|
+
if (stepProp === void 0) setUncontrolledStep(next);
|
|
119
|
+
onStepIndexChange?.(next);
|
|
120
|
+
},
|
|
121
|
+
[stepProp, onStepIndexChange]
|
|
122
|
+
);
|
|
123
|
+
const close = React.useCallback(
|
|
124
|
+
(how) => {
|
|
125
|
+
if (openProp === void 0) setUncontrolledOpen(false);
|
|
126
|
+
if (id && ctx && ctx.activeId === id) ctx.stop();
|
|
127
|
+
onOpenChange?.(false);
|
|
128
|
+
if (how === "complete") {
|
|
129
|
+
emitRef.current("tour_completed");
|
|
130
|
+
onComplete?.();
|
|
131
|
+
} else {
|
|
132
|
+
emitRef.current("tour_skipped", { reason: how });
|
|
133
|
+
onDismiss?.(how);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
[openProp, id, ctx, onOpenChange, onComplete, onDismiss]
|
|
137
|
+
);
|
|
138
|
+
const advance = React.useCallback(
|
|
139
|
+
(via) => {
|
|
140
|
+
emitRef.current("tour_advanced", { via });
|
|
141
|
+
if (index >= total - 1) close("complete");
|
|
142
|
+
else setIndex(index + 1);
|
|
143
|
+
},
|
|
144
|
+
[index, total, close, setIndex]
|
|
145
|
+
);
|
|
146
|
+
const advanceRef = React.useRef(advance);
|
|
147
|
+
advanceRef.current = advance;
|
|
148
|
+
const skipStep = React.useCallback(
|
|
149
|
+
(reason, props) => {
|
|
150
|
+
emitRef.current("tour_step_skipped", { reason, ...props });
|
|
151
|
+
if (index >= total - 1) close("complete");
|
|
152
|
+
else setIndex(index + 1);
|
|
153
|
+
},
|
|
154
|
+
[index, total, close, setIndex]
|
|
155
|
+
);
|
|
156
|
+
const skipRef = React.useRef(skipStep);
|
|
157
|
+
skipRef.current = skipStep;
|
|
158
|
+
const anchorName = open && !minimised && step?.anchor && step.kind !== "modal" ? step.anchor : null;
|
|
159
|
+
const [anchorReady, setAnchorReady] = React.useState(false);
|
|
160
|
+
React.useEffect(() => {
|
|
161
|
+
setAnchorReady(false);
|
|
162
|
+
if (!anchorName || !host) return;
|
|
163
|
+
let alive = true;
|
|
164
|
+
let timer;
|
|
165
|
+
const started = Date.now();
|
|
166
|
+
const look = () => {
|
|
167
|
+
if (!alive) return;
|
|
168
|
+
if (host.get(anchorName)?.current) {
|
|
169
|
+
setAnchorReady(true);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (Date.now() - started >= 2600) {
|
|
173
|
+
const missing = stepRef.current;
|
|
174
|
+
if (missing && !shouldSkipMissingStep(missing, kindFor(missing.kind, Boolean(missing.anchor)))) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
skipRef.current("anchor-missing", { anchor: anchorName });
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
timer = setTimeout(look, 100);
|
|
181
|
+
};
|
|
182
|
+
look();
|
|
183
|
+
const off = host.subscribe(look);
|
|
184
|
+
return () => {
|
|
185
|
+
alive = false;
|
|
186
|
+
off();
|
|
187
|
+
if (timer) clearTimeout(timer);
|
|
188
|
+
};
|
|
189
|
+
}, [anchorName, host]);
|
|
190
|
+
const needsRoute = Boolean(open && !minimised && step?.route && route !== void 0 && route !== step.route);
|
|
191
|
+
const navigatedFor = React.useRef(null);
|
|
192
|
+
React.useEffect(() => {
|
|
193
|
+
if (!needsRoute || !onNavigate || !step?.route) return;
|
|
194
|
+
const key = `${index}:${step.route}`;
|
|
195
|
+
if (navigatedFor.current === key) return;
|
|
196
|
+
navigatedFor.current = key;
|
|
197
|
+
emitRef.current("tour_navigated", { to: step.route });
|
|
198
|
+
onNavigate(step.route);
|
|
199
|
+
}, [needsRoute, onNavigate, step, index]);
|
|
200
|
+
React.useEffect(() => {
|
|
201
|
+
if (!needsRoute) navigatedFor.current = null;
|
|
202
|
+
}, [needsRoute, index]);
|
|
203
|
+
const wasOpen = React.useRef(false);
|
|
204
|
+
React.useEffect(() => {
|
|
205
|
+
if (open && !wasOpen.current) emitRef.current("tour_started");
|
|
206
|
+
wasOpen.current = open;
|
|
207
|
+
}, [open]);
|
|
208
|
+
const lastViewed = React.useRef(null);
|
|
209
|
+
React.useEffect(() => {
|
|
210
|
+
if (!open || minimised || !step) return;
|
|
211
|
+
if (anchorName && !anchorReady) return;
|
|
212
|
+
if (lastViewed.current === String(index)) return;
|
|
213
|
+
lastViewed.current = String(index);
|
|
214
|
+
emitRef.current("tour_step_viewed", {
|
|
215
|
+
anchor: step.anchor ?? null,
|
|
216
|
+
kind: kindFor(step.kind, Boolean(step.anchor))
|
|
217
|
+
});
|
|
218
|
+
}, [open, minimised, step, index, anchorName, anchorReady]);
|
|
219
|
+
React.useEffect(() => {
|
|
220
|
+
if (!open) lastViewed.current = null;
|
|
221
|
+
}, [open]);
|
|
222
|
+
React.useEffect(() => {
|
|
223
|
+
setBeaconOpen(false);
|
|
224
|
+
}, [index]);
|
|
225
|
+
const advanceOn = step?.advanceOn;
|
|
226
|
+
const gateAttachable = canAttachGate(advanceOn, Boolean(anchorName && anchorReady), false);
|
|
227
|
+
const gated = isStepGated(step?.requireAction, advanceOn, gateAttachable);
|
|
228
|
+
const degradedRef = React.useRef(null);
|
|
229
|
+
React.useEffect(() => {
|
|
230
|
+
if (!open || minimised || !advanceOn || advanceOn.type === "next" || gateAttachable) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const key = `${index}:${advanceOn.type}`;
|
|
234
|
+
if (degradedRef.current === key) return;
|
|
235
|
+
degradedRef.current = key;
|
|
236
|
+
emitRef.current("tour_step_skipped", {
|
|
237
|
+
reason: "gate-unattachable",
|
|
238
|
+
gate: advanceOn.type,
|
|
239
|
+
fellBackTo: "next"
|
|
240
|
+
});
|
|
241
|
+
}, [open, minimised, advanceOn, gateAttachable, index]);
|
|
242
|
+
React.useEffect(() => {
|
|
243
|
+
if (!open || minimised || advanceOn?.type !== "click" || !host || !anchorName) return;
|
|
244
|
+
return host.subscribePress((pressed) => {
|
|
245
|
+
if (pressed === anchorName) setTimeout(() => advanceRef.current("click"), 260);
|
|
246
|
+
});
|
|
247
|
+
}, [open, minimised, advanceOn, host, anchorName]);
|
|
248
|
+
React.useEffect(() => {
|
|
249
|
+
if (!open || minimised || advanceOn?.type !== "event" || !ctx) return;
|
|
250
|
+
return ctx.subscribe((event) => {
|
|
251
|
+
if (event === advanceOn.event) advanceRef.current("event");
|
|
252
|
+
});
|
|
253
|
+
}, [open, minimised, advanceOn, ctx]);
|
|
254
|
+
const prevRoute = React.useRef(route);
|
|
255
|
+
React.useEffect(() => {
|
|
256
|
+
const before = prevRoute.current;
|
|
257
|
+
prevRoute.current = route;
|
|
258
|
+
if (!open || minimised || advanceOn?.type !== "route") return;
|
|
259
|
+
const want = advanceOn.route ?? step?.route;
|
|
260
|
+
if (want && route === want && before !== route) advanceRef.current("route");
|
|
261
|
+
}, [route, open, minimised, advanceOn, step]);
|
|
262
|
+
React.useEffect(() => {
|
|
263
|
+
if (!open || minimised) return;
|
|
264
|
+
const sub = BackHandler.addEventListener("hardwareBackPress", () => {
|
|
265
|
+
close("back");
|
|
266
|
+
return true;
|
|
267
|
+
});
|
|
268
|
+
return () => sub.remove();
|
|
269
|
+
}, [open, minimised, close]);
|
|
270
|
+
if (!open || !step || total === 0) return null;
|
|
271
|
+
if (minimised) {
|
|
272
|
+
return /* @__PURE__ */ jsx(
|
|
273
|
+
TourLauncher,
|
|
274
|
+
{
|
|
275
|
+
label: labels.resume,
|
|
276
|
+
counter: `${index + 1}/${total}`,
|
|
277
|
+
motion,
|
|
278
|
+
onPress: () => {
|
|
279
|
+
setMinimised(false);
|
|
280
|
+
emitRef.current("tour_resumed");
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
const kind = kindFor(step.kind, Boolean(step.anchor));
|
|
286
|
+
const highlight = highlightFor(kind, step.highlight);
|
|
287
|
+
const resolved = anchorName && anchorReady ? anchorName : null;
|
|
288
|
+
const waiting = needsRoute || Boolean(step.anchor) && kind !== "modal" && !resolved;
|
|
289
|
+
const variant = cardVariant ?? (kind === "modal" || !resolved ? "centered" : touch ? "docked" : "anchored");
|
|
290
|
+
if (kind === "beacon" && resolved && !beaconOpen) {
|
|
291
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
292
|
+
/* @__PURE__ */ jsx(Highlight, { kind: highlight, target: resolved, padding: step.padding, motion }),
|
|
293
|
+
/* @__PURE__ */ jsx(
|
|
294
|
+
Beacon,
|
|
295
|
+
{
|
|
296
|
+
target: resolved,
|
|
297
|
+
accessibilityLabel: t(step.hint) ?? labels.beacon,
|
|
298
|
+
motion,
|
|
299
|
+
onPress: () => setBeaconOpen(true)
|
|
300
|
+
}
|
|
301
|
+
)
|
|
302
|
+
] });
|
|
303
|
+
}
|
|
304
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
305
|
+
resolved ? /* @__PURE__ */ jsx(Highlight, { kind: highlight, target: resolved, padding: step.padding, motion }) : null,
|
|
306
|
+
/* @__PURE__ */ jsx(
|
|
307
|
+
TourStepCard,
|
|
308
|
+
{
|
|
309
|
+
step,
|
|
310
|
+
index,
|
|
311
|
+
total,
|
|
312
|
+
titles: visible.map((s) => t(s.title) ?? ""),
|
|
313
|
+
name,
|
|
314
|
+
target: variant === "anchored" ? resolved : void 0,
|
|
315
|
+
variant,
|
|
316
|
+
gated,
|
|
317
|
+
locale,
|
|
318
|
+
defaultLocale,
|
|
319
|
+
waiting: waiting ? `${labels.opening} ${step.route ?? ""}`.trim() : void 0,
|
|
320
|
+
labels,
|
|
321
|
+
motion,
|
|
322
|
+
onNext: () => advance("next"),
|
|
323
|
+
onBack: index > 0 ? () => setIndex(index - 1) : void 0,
|
|
324
|
+
onSkipStep: () => skipStep("user-skipped"),
|
|
325
|
+
onSelectStep: setIndex,
|
|
326
|
+
onClose: () => close("user"),
|
|
327
|
+
onMinimise: minimisable ? () => {
|
|
328
|
+
setMinimised(true);
|
|
329
|
+
emitRef.current("tour_minimised");
|
|
330
|
+
} : void 0,
|
|
331
|
+
onAction: onAction ? (action) => onAction(action, step) : void 0
|
|
332
|
+
},
|
|
333
|
+
index
|
|
334
|
+
)
|
|
335
|
+
] });
|
|
336
|
+
}
|
|
337
|
+
function TourHint({ text }) {
|
|
338
|
+
const { styles } = useStyles(sheet);
|
|
339
|
+
return /* @__PURE__ */ jsx(Fragment, { children: hintRuns(text).map(
|
|
340
|
+
(run, i) => run.key ? /* @__PURE__ */ jsx(Text, { style: styles.hintKey, children: run.text }, i) : /* @__PURE__ */ jsx(Text, { children: run.text }, i)
|
|
341
|
+
) });
|
|
342
|
+
}
|
|
343
|
+
function TourStepCard({
|
|
344
|
+
step,
|
|
345
|
+
index,
|
|
346
|
+
total,
|
|
347
|
+
titles,
|
|
348
|
+
name,
|
|
349
|
+
target,
|
|
350
|
+
variant = "docked",
|
|
351
|
+
gated = false,
|
|
352
|
+
waiting,
|
|
353
|
+
labels: labelOverrides,
|
|
354
|
+
onNext,
|
|
355
|
+
onBack,
|
|
356
|
+
onSkipStep,
|
|
357
|
+
onSelectStep,
|
|
358
|
+
onClose,
|
|
359
|
+
onMinimise,
|
|
360
|
+
onAction,
|
|
361
|
+
locale,
|
|
362
|
+
defaultLocale,
|
|
363
|
+
motion = "full"
|
|
364
|
+
}) {
|
|
365
|
+
const theme = useLoamTheme();
|
|
366
|
+
const { styles } = useStyles(sheet);
|
|
367
|
+
const labels = { ...DEFAULT_LABELS, ...labelOverrides };
|
|
368
|
+
const t = (value) => resolveText(value, locale, defaultLocale);
|
|
369
|
+
const isLast = index === total - 1;
|
|
370
|
+
const kind = kindFor(step.kind, Boolean(step.anchor));
|
|
371
|
+
const cta = step.cta;
|
|
372
|
+
return /* @__PURE__ */ jsxs(
|
|
373
|
+
Coachmark,
|
|
374
|
+
{
|
|
375
|
+
target,
|
|
376
|
+
variant,
|
|
377
|
+
placement: step.placement ?? "bottom",
|
|
378
|
+
width: kind === "modal" ? theme.panel.xl : theme.panel.lg,
|
|
379
|
+
kicker: name,
|
|
380
|
+
title: t(step.title) ?? "",
|
|
381
|
+
body: typeof step.body === "string" ? step.body : void 0,
|
|
382
|
+
media: step.media,
|
|
383
|
+
hint: waiting ?? (gated ? /* @__PURE__ */ jsx(TourHint, { text: t(step.hint) ?? labels.waiting }) : void 0),
|
|
384
|
+
motion,
|
|
385
|
+
onClose,
|
|
386
|
+
closeLabel: labels.leave,
|
|
387
|
+
headerActions: onMinimise ? /* @__PURE__ */ jsx(
|
|
388
|
+
Pressable,
|
|
389
|
+
{
|
|
390
|
+
accessibilityRole: "button",
|
|
391
|
+
accessibilityLabel: labels.minimise,
|
|
392
|
+
onPress: onMinimise,
|
|
393
|
+
hitSlop: theme.space[10],
|
|
394
|
+
style: styles.iconButton,
|
|
395
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "chevron-down", size: theme.icon.sm, color: theme.color.text3 })
|
|
396
|
+
}
|
|
397
|
+
) : null,
|
|
398
|
+
actions: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
399
|
+
onBack ? /* @__PURE__ */ jsx(Button, { size: "sm", variant: "outline", onPress: onBack, children: labels.back }) : null,
|
|
400
|
+
gated ? step.skippable === false ? null : /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", onPress: onSkipStep, children: labels.skipStep }) : /* @__PURE__ */ jsx(Button, { size: "lg", variant: "primary", onPress: onNext, children: isLast ? labels.finish : labels.next })
|
|
401
|
+
] }),
|
|
402
|
+
children: [
|
|
403
|
+
typeof step.body !== "string" && step.body ? /* @__PURE__ */ jsx(Fragment, { children: step.body }) : null,
|
|
404
|
+
cta ? /* @__PURE__ */ jsx(Button, { size: "sm", variant: "ghost", trailingIcon: "arrow-right", onPress: () => onAction?.(cta.action), children: cta.label }) : null,
|
|
405
|
+
/* @__PURE__ */ jsx(
|
|
406
|
+
TourProgress,
|
|
407
|
+
{
|
|
408
|
+
index,
|
|
409
|
+
total,
|
|
410
|
+
titles,
|
|
411
|
+
stepLabel: labels.step,
|
|
412
|
+
onSelect: onSelectStep
|
|
413
|
+
}
|
|
414
|
+
)
|
|
415
|
+
]
|
|
416
|
+
}
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
function TourProgress({
|
|
420
|
+
index,
|
|
421
|
+
total,
|
|
422
|
+
titles,
|
|
423
|
+
onSelect,
|
|
424
|
+
stepLabel = "Step"
|
|
425
|
+
}) {
|
|
426
|
+
const { styles } = useStyles(sheet);
|
|
427
|
+
return /* @__PURE__ */ jsxs(View, { style: styles.progress, children: [
|
|
428
|
+
/* @__PURE__ */ jsx(
|
|
429
|
+
Progress,
|
|
430
|
+
{
|
|
431
|
+
size: "sm",
|
|
432
|
+
value: index + 1,
|
|
433
|
+
max: Math.max(1, total),
|
|
434
|
+
accessibilityLabel: `${stepLabel} ${index + 1} of ${total}`
|
|
435
|
+
}
|
|
436
|
+
),
|
|
437
|
+
/* @__PURE__ */ jsxs(View, { style: styles.progressRail, children: [
|
|
438
|
+
/* @__PURE__ */ jsx(
|
|
439
|
+
CoachmarkDots,
|
|
440
|
+
{
|
|
441
|
+
total,
|
|
442
|
+
index,
|
|
443
|
+
onSelect,
|
|
444
|
+
stepLabel,
|
|
445
|
+
titles
|
|
446
|
+
}
|
|
447
|
+
),
|
|
448
|
+
/* @__PURE__ */ jsxs(Text, { style: styles.counter, children: [
|
|
449
|
+
index + 1,
|
|
450
|
+
" / ",
|
|
451
|
+
total
|
|
452
|
+
] })
|
|
453
|
+
] })
|
|
454
|
+
] });
|
|
455
|
+
}
|
|
456
|
+
function TourLauncher({
|
|
457
|
+
label = "Resume tour",
|
|
458
|
+
counter,
|
|
459
|
+
onPress,
|
|
460
|
+
pinned = true
|
|
461
|
+
}) {
|
|
462
|
+
const theme = useLoamTheme();
|
|
463
|
+
const { styles } = useStyles(sheet);
|
|
464
|
+
const insets = useTourInsets();
|
|
465
|
+
return /* @__PURE__ */ jsxs(
|
|
466
|
+
Pressable,
|
|
467
|
+
{
|
|
468
|
+
accessibilityRole: "button",
|
|
469
|
+
accessibilityLabel: counter ? `${label} \u2014 ${counter}` : label,
|
|
470
|
+
onPress,
|
|
471
|
+
style: ({ pressed }) => [
|
|
472
|
+
styles.launcher,
|
|
473
|
+
pinned ? styles.launcherPinned : null,
|
|
474
|
+
pinned ? { right: theme.space[16] + insets.right, bottom: theme.space[16] + insets.bottom } : null,
|
|
475
|
+
pressed ? { backgroundColor: theme.state.pressed } : null
|
|
476
|
+
],
|
|
477
|
+
children: [
|
|
478
|
+
/* @__PURE__ */ jsx(Icon, { name: "star", size: theme.icon.sm, color: theme.color.accentStrong }),
|
|
479
|
+
/* @__PURE__ */ jsx(Text, { style: styles.launcherLabel, children: label }),
|
|
480
|
+
counter ? /* @__PURE__ */ jsx(Text, { style: styles.counter, children: counter }) : null
|
|
481
|
+
]
|
|
482
|
+
}
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
var sheet = createStyleSheet((theme) => ({
|
|
486
|
+
/** A control named inside a gated hint, shaped like the app's own label. */
|
|
487
|
+
hintKey: {
|
|
488
|
+
fontFamily: theme.font.sans,
|
|
489
|
+
color: theme.color.text,
|
|
490
|
+
textTransform: "none"
|
|
491
|
+
},
|
|
492
|
+
iconButton: {
|
|
493
|
+
width: theme.ctl.sm,
|
|
494
|
+
height: theme.ctl.sm,
|
|
495
|
+
alignItems: "center",
|
|
496
|
+
justifyContent: "center",
|
|
497
|
+
borderRadius: theme.radius.full
|
|
498
|
+
},
|
|
499
|
+
progress: { gap: theme.space[8], marginTop: theme.space[2] },
|
|
500
|
+
progressRail: { flexDirection: "row", alignItems: "center", gap: theme.space[6] },
|
|
501
|
+
counter: {
|
|
502
|
+
marginLeft: "auto",
|
|
503
|
+
fontFamily: theme.font.mono,
|
|
504
|
+
fontSize: theme.type.caption2.fontSize,
|
|
505
|
+
color: theme.color.text3,
|
|
506
|
+
fontVariant: ["tabular-nums"]
|
|
507
|
+
},
|
|
508
|
+
launcher: {
|
|
509
|
+
flexDirection: "row",
|
|
510
|
+
alignItems: "center",
|
|
511
|
+
gap: theme.space[9],
|
|
512
|
+
height: theme.ctl.lg,
|
|
513
|
+
paddingHorizontal: theme.space[15],
|
|
514
|
+
borderRadius: theme.radius.full,
|
|
515
|
+
borderWidth: theme.borderWidth.thin,
|
|
516
|
+
// The pill's edge is the only thing separating it from the screen behind,
|
|
517
|
+
// so it is a graphical edge at 3:1 — the measured accent, not the raw one.
|
|
518
|
+
borderColor: theme.focus.ringColor,
|
|
519
|
+
backgroundColor: theme.color.surface,
|
|
520
|
+
...theme.shadow.lg
|
|
521
|
+
},
|
|
522
|
+
launcherPinned: {
|
|
523
|
+
position: "absolute",
|
|
524
|
+
right: theme.space[16],
|
|
525
|
+
bottom: theme.space[16]
|
|
526
|
+
},
|
|
527
|
+
launcherLabel: {
|
|
528
|
+
fontFamily: theme.font.sans,
|
|
529
|
+
fontWeight: theme.fontWeight.bold,
|
|
530
|
+
fontSize: theme.type.subheadline.fontSize,
|
|
531
|
+
color: theme.color.accentStrong
|
|
532
|
+
}
|
|
533
|
+
}));
|
|
534
|
+
|
|
535
|
+
export { Tour, TourLauncher, TourProgress, TourProvider, TourStepCard, useTour };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ErrorSummary } from './chunk-C2NTXVWM.js';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import { createStyleSheet, useStyles } from '@btndprojects/loam-theme-native';
|
|
5
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
var FormContext = React.createContext(null);
|
|
8
|
+
function useFormContext() {
|
|
9
|
+
const ctx = React.useContext(FormContext);
|
|
10
|
+
if (!ctx) throw new Error("useFormContext must be used inside a <Form>");
|
|
11
|
+
return ctx;
|
|
12
|
+
}
|
|
13
|
+
function Form({
|
|
14
|
+
onSubmit,
|
|
15
|
+
onValidate,
|
|
16
|
+
onFocusField,
|
|
17
|
+
submitting = false,
|
|
18
|
+
motion = "full",
|
|
19
|
+
children
|
|
20
|
+
}) {
|
|
21
|
+
const { styles } = useStyles(sheet);
|
|
22
|
+
const [errors, setErrors] = React.useState([]);
|
|
23
|
+
const submit = React.useCallback(async () => {
|
|
24
|
+
if (submitting) return;
|
|
25
|
+
if (onValidate) {
|
|
26
|
+
const found = await onValidate();
|
|
27
|
+
if (found.length > 0) {
|
|
28
|
+
setErrors(found);
|
|
29
|
+
const first = found[0];
|
|
30
|
+
if (first) onFocusField?.(first.fieldId);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
setErrors([]);
|
|
35
|
+
await onSubmit();
|
|
36
|
+
}, [submitting, onValidate, onFocusField, onSubmit]);
|
|
37
|
+
const ctx = React.useMemo(() => ({ submit, submitting }), [submit, submitting]);
|
|
38
|
+
return /* @__PURE__ */ jsx(FormContext.Provider, { value: ctx, children: /* @__PURE__ */ jsxs(View, { style: styles.form, children: [
|
|
39
|
+
/* @__PURE__ */ jsx(ErrorSummary, { errors, motion, onFocusField }),
|
|
40
|
+
children
|
|
41
|
+
] }) });
|
|
42
|
+
}
|
|
43
|
+
function FormActions({ children }) {
|
|
44
|
+
const { styles } = useStyles(sheet);
|
|
45
|
+
return /* @__PURE__ */ jsx(View, { style: styles.actions, children });
|
|
46
|
+
}
|
|
47
|
+
var sheet = createStyleSheet((theme) => ({
|
|
48
|
+
form: {
|
|
49
|
+
gap: theme.space.s5
|
|
50
|
+
},
|
|
51
|
+
actions: {
|
|
52
|
+
flexDirection: "row",
|
|
53
|
+
flexWrap: "wrap",
|
|
54
|
+
alignItems: "center",
|
|
55
|
+
gap: theme.space.s3,
|
|
56
|
+
paddingTop: theme.space.s1
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
export { Form, FormActions, useFormContext };
|