@viveksinghind/narrative-form-native 1.0.2
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/README.md +61 -0
- package/dist/components/DoneScreen.d.ts +10 -0
- package/dist/components/DoneScreen.d.ts.map +1 -0
- package/dist/components/DoneScreen.js +33 -0
- package/dist/components/DoneScreen.js.map +1 -0
- package/dist/components/ErrorMessage.d.ts +8 -0
- package/dist/components/ErrorMessage.d.ts.map +1 -0
- package/dist/components/ErrorMessage.js +40 -0
- package/dist/components/ErrorMessage.js.map +1 -0
- package/dist/components/Line.d.ts +21 -0
- package/dist/components/Line.d.ts.map +1 -0
- package/dist/components/Line.js +130 -0
- package/dist/components/Line.js.map +1 -0
- package/dist/components/NarrativeForm.d.ts +25 -0
- package/dist/components/NarrativeForm.d.ts.map +1 -0
- package/dist/components/NarrativeForm.js +113 -0
- package/dist/components/NarrativeForm.js.map +1 -0
- package/dist/components/ThemeProvider.d.ts +13 -0
- package/dist/components/ThemeProvider.d.ts.map +1 -0
- package/dist/components/ThemeProvider.js +19 -0
- package/dist/components/ThemeProvider.js.map +1 -0
- package/dist/components/ToastProvider.d.ts +9 -0
- package/dist/components/ToastProvider.d.ts.map +1 -0
- package/dist/components/ToastProvider.js +41 -0
- package/dist/components/ToastProvider.js.map +1 -0
- package/dist/components/WelcomeScreen.d.ts +9 -0
- package/dist/components/WelcomeScreen.d.ts.map +1 -0
- package/dist/components/WelcomeScreen.js +63 -0
- package/dist/components/WelcomeScreen.js.map +1 -0
- package/dist/hooks/useDynamicForm.d.ts +18 -0
- package/dist/hooks/useDynamicForm.d.ts.map +1 -0
- package/dist/hooks/useDynamicForm.js +50 -0
- package/dist/hooks/useDynamicForm.js.map +1 -0
- package/dist/hooks/useFormState.d.ts +43 -0
- package/dist/hooks/useFormState.d.ts.map +1 -0
- package/dist/hooks/useFormState.js +57 -0
- package/dist/hooks/useFormState.js.map +1 -0
- package/dist/hooks/useTypewriter.d.ts +46 -0
- package/dist/hooks/useTypewriter.d.ts.map +1 -0
- package/dist/hooks/useTypewriter.js +94 -0
- package/dist/hooks/useTypewriter.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +621 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vivek Singh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @viveksinghind/narrative-form-native
|
|
2
|
+
|
|
3
|
+
React Native components for Narrative Form, a dynamic typewriter-style sign-up flow.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @viveksinghind/narrative-form-native @viveksinghind/narrative-form-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import { SafeAreaView, StyleSheet } from 'react-native';
|
|
16
|
+
import { NarrativeForm } from '@viveksinghind/narrative-form-native';
|
|
17
|
+
|
|
18
|
+
const myFormConfig = {
|
|
19
|
+
form: { id: "test", name: "Test Form", version: 1 },
|
|
20
|
+
welcome: {
|
|
21
|
+
heading: "Welcome to the future",
|
|
22
|
+
subtext: "Let's get started",
|
|
23
|
+
ctaLabel: "Begin"
|
|
24
|
+
},
|
|
25
|
+
fields: [
|
|
26
|
+
{
|
|
27
|
+
key: "name",
|
|
28
|
+
type: "text",
|
|
29
|
+
prefix: "Hi, my name is",
|
|
30
|
+
validation: { required: true }
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
done: {
|
|
34
|
+
message: "All done! Thank you.",
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default function App() {
|
|
39
|
+
return (
|
|
40
|
+
<SafeAreaView style={styles.container}>
|
|
41
|
+
<NarrativeForm
|
|
42
|
+
config={myFormConfig}
|
|
43
|
+
onComplete={(values) => console.log('Form Complete!', values)}
|
|
44
|
+
/>
|
|
45
|
+
</SafeAreaView>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const styles = StyleSheet.create({
|
|
50
|
+
container: {
|
|
51
|
+
flex: 1,
|
|
52
|
+
backgroundColor: '#fff',
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Features
|
|
58
|
+
- Fully native animations using `Animated` API
|
|
59
|
+
- Works seamlessly on iOS and Android
|
|
60
|
+
- Accessible form elements
|
|
61
|
+
- Themeable via config
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { NarrativeDone, NarrativeFieldValues, NarrativeMeta, NarrativeTypewriter } from "@viveksinghind/narrative-form-core";
|
|
3
|
+
export interface DoneScreenProps {
|
|
4
|
+
done: NarrativeDone;
|
|
5
|
+
values: NarrativeFieldValues;
|
|
6
|
+
meta: NarrativeMeta;
|
|
7
|
+
typewriter: NarrativeTypewriter;
|
|
8
|
+
}
|
|
9
|
+
export declare const DoneScreen: React.FC<DoneScreenProps>;
|
|
10
|
+
//# sourceMappingURL=DoneScreen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DoneScreen.d.ts","sourceRoot":"","sources":["../../src/components/DoneScreen.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAGlI,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,UAAU,EAAE,mBAAmB,CAAC;CACjC;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAqBhD,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { Animated, Text, StyleSheet } from "react-native";
|
|
4
|
+
import { useTheme } from "./ThemeProvider";
|
|
5
|
+
export const DoneScreen = ({ done, values, meta }) => {
|
|
6
|
+
const { theme, isDark } = useTheme();
|
|
7
|
+
const opacity = useRef(new Animated.Value(0)).current;
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
Animated.timing(opacity, {
|
|
10
|
+
toValue: 1,
|
|
11
|
+
duration: 500,
|
|
12
|
+
useNativeDriver: true,
|
|
13
|
+
}).start();
|
|
14
|
+
}, [opacity]);
|
|
15
|
+
const textColor = (theme === null || theme === void 0 ? void 0 : theme.textColor) || (isDark ? "#fff" : "#000");
|
|
16
|
+
const messageStr = typeof done.message === "function" ? done.message(values) : done.message;
|
|
17
|
+
return (_jsx(Animated.View, { style: [styles.container, { opacity }], children: _jsx(Text, { style: [styles.title, { color: textColor }], children: messageStr }) }));
|
|
18
|
+
};
|
|
19
|
+
const styles = StyleSheet.create({
|
|
20
|
+
container: {
|
|
21
|
+
padding: 20,
|
|
22
|
+
marginTop: 20,
|
|
23
|
+
},
|
|
24
|
+
title: {
|
|
25
|
+
fontSize: 24,
|
|
26
|
+
fontWeight: "bold",
|
|
27
|
+
marginBottom: 8,
|
|
28
|
+
},
|
|
29
|
+
subtitle: {
|
|
30
|
+
fontSize: 16,
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=DoneScreen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DoneScreen.js","sourceRoot":"","sources":["../../src/components/DoneScreen.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAQ,IAAI,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAS3C,MAAM,CAAC,MAAM,UAAU,GAA8B,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE;IAC9E,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC;IACrC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CA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{
|
|
4
|
+
message: string | null;
|
|
5
|
+
config?: NarrativeErrorDisplay;
|
|
6
|
+
}
|
|
7
|
+
export declare const ErrorMessage: React.FC<ErrorMessageProps>;
|
|
8
|
+
//# sourceMappingURL=ErrorMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorMessage.d.ts","sourceRoot":"","sources":["../../src/components/ErrorMessage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAEjD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAGhF,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,CAAC,EAAE,qBAAqB,CAAC;CAChC;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAkCpD,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { Animated, Text, StyleSheet } from "react-native";
|
|
4
|
+
import { useTheme } from "./ThemeProvider";
|
|
5
|
+
export const ErrorMessage = ({ message, config }) => {
|
|
6
|
+
const { theme } = useTheme();
|
|
7
|
+
const opacity = useRef(new Animated.Value(0)).current;
|
|
8
|
+
const translateY = useRef(new Animated.Value(-10)).current;
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (message) {
|
|
11
|
+
Animated.parallel([
|
|
12
|
+
Animated.timing(opacity, {
|
|
13
|
+
toValue: 1,
|
|
14
|
+
duration: 200,
|
|
15
|
+
useNativeDriver: true,
|
|
16
|
+
}),
|
|
17
|
+
Animated.timing(translateY, {
|
|
18
|
+
toValue: 0,
|
|
19
|
+
duration: 200,
|
|
20
|
+
useNativeDriver: true,
|
|
21
|
+
})
|
|
22
|
+
]).start();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
opacity.setValue(0);
|
|
26
|
+
translateY.setValue(-10);
|
|
27
|
+
}
|
|
28
|
+
}, [message, opacity, translateY]);
|
|
29
|
+
if (!message)
|
|
30
|
+
return null;
|
|
31
|
+
return (_jsx(Animated.View, { style: { opacity, transform: [{ translateY }] }, children: _jsx(Text, { style: [styles.errorText, { color: (theme === null || theme === void 0 ? void 0 : theme.errorColor) || "#d32f2f" }], children: message }) }));
|
|
32
|
+
};
|
|
33
|
+
const styles = StyleSheet.create({
|
|
34
|
+
errorText: {
|
|
35
|
+
fontSize: 14,
|
|
36
|
+
marginTop: 4,
|
|
37
|
+
marginBottom: 8,
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=ErrorMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorMessage.js","sourceRoot":"","sources":["../../src/components/ErrorMessage.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAO3C,MAAM,CAAC,MAAM,YAAY,GAAgC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;IAC/E,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAC;IAC7B,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IACtD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAE3D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,EAAE,CAAC;YACZ,QAAQ,CAAC,QAAQ,CAAC;gBAChB,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE;oBACvB,OAAO,EAAE,CAAC;oBACV,QAAQ,EAAE,GAAG;oBACb,eAAe,EAAE,IAAI;iBACtB,CAAC;gBACF,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE;oBAC1B,OAAO,EAAE,CAAC;oBACV,QAAQ,EAAE,GAAG;oBACb,eAAe,EAAE,IAAI;iBACtB,CAAC;aACH,CAAC,CAAC,KAAK,EAAE,CAAC;QACb,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YACpB,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;IAEnC,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAE1B,OAAO,CACL,KAAC,QAAQ,CAAC,IAAI,IAAC,KAAK,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,YAC5D,KAAC,IAAI,IAAC,KAAK,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,UAAU,KAAI,SAAS,EAAE,CAAC,YACvE,OAAO,GACH,GACO,CACjB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,SAAS,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,CAAC;QACZ,YAAY,EAAE,CAAC;KAChB;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { NarrativeField, FieldStatus, NarrativeTypewriter, NarrativeFieldValues } from "@viveksinghind/narrative-form-core";
|
|
3
|
+
export interface LineProps {
|
|
4
|
+
field: NarrativeField;
|
|
5
|
+
status: FieldStatus;
|
|
6
|
+
value: any;
|
|
7
|
+
allValues: NarrativeFieldValues;
|
|
8
|
+
typewriter: NarrativeTypewriter;
|
|
9
|
+
editable: boolean;
|
|
10
|
+
locked: boolean;
|
|
11
|
+
editLabel: string;
|
|
12
|
+
onTypingComplete: (key: string) => void;
|
|
13
|
+
onConfirm: (key: string, value: string) => void;
|
|
14
|
+
onEdit: (key: string) => void;
|
|
15
|
+
onError: (key: string, error: string) => void;
|
|
16
|
+
onChange: (key: string, value: string) => void;
|
|
17
|
+
onFocus: (key: string) => void;
|
|
18
|
+
onBlur: (key: string, value: string) => void;
|
|
19
|
+
}
|
|
20
|
+
export declare const Line: React.FC<LineProps>;
|
|
21
|
+
//# sourceMappingURL=Line.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Line.d.ts","sourceRoot":"","sources":["../../src/components/Line.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAExE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAKjI,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,GAAG,CAAC;IACX,SAAS,EAAE,oBAAoB,CAAC;IAChC,UAAU,EAAE,mBAAmB,CAAC;IAChC,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C;AAED,eAAO,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CAsJpC,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { Animated, View, Text, TextInput, TouchableOpacity, StyleSheet, Keyboard } from "react-native";
|
|
4
|
+
import { validateField, validateFieldAsync, hasAsyncValidation } from "@viveksinghind/narrative-form-core";
|
|
5
|
+
import { ErrorMessage } from "./ErrorMessage";
|
|
6
|
+
import { useTheme } from "./ThemeProvider";
|
|
7
|
+
export const Line = ({ field, status, value, allValues, typewriter, editable, locked, editLabel, onTypingComplete, onConfirm, onEdit, onError, onChange, onFocus, onBlur, }) => {
|
|
8
|
+
const { theme, isDark } = useTheme();
|
|
9
|
+
const [typedPrompt, setTypedPrompt] = useState("");
|
|
10
|
+
const [localValue, setLocalValue] = useState(value ? String(value) : "");
|
|
11
|
+
const [errorMsg, setErrorMsg] = useState(null);
|
|
12
|
+
const [isValidating, setIsValidating] = useState(false);
|
|
13
|
+
const inputRef = useRef(null);
|
|
14
|
+
const opacity = useRef(new Animated.Value(0)).current;
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
Animated.timing(opacity, {
|
|
17
|
+
toValue: 1,
|
|
18
|
+
duration: 300,
|
|
19
|
+
useNativeDriver: true,
|
|
20
|
+
}).start();
|
|
21
|
+
}, [opacity]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (value !== undefined && String(value) !== localValue) {
|
|
24
|
+
setLocalValue(String(value));
|
|
25
|
+
}
|
|
26
|
+
}, [value]);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
var _a;
|
|
29
|
+
if (status !== "typing")
|
|
30
|
+
return;
|
|
31
|
+
if (!typewriter.enabled) {
|
|
32
|
+
setTypedPrompt(field.prefix);
|
|
33
|
+
onTypingComplete(field.key);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
let i = 0;
|
|
37
|
+
const interval = setInterval(() => {
|
|
38
|
+
setTypedPrompt(field.prefix.slice(0, i + 1));
|
|
39
|
+
i++;
|
|
40
|
+
if (i >= field.prefix.length) {
|
|
41
|
+
clearInterval(interval);
|
|
42
|
+
onTypingComplete(field.key);
|
|
43
|
+
}
|
|
44
|
+
}, (_a = typewriter.speed) !== null && _a !== void 0 ? _a : 30);
|
|
45
|
+
return () => clearInterval(interval);
|
|
46
|
+
}, [status, field.prefix, field.key, typewriter, onTypingComplete]);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (status === "active" || status === "editing") {
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
var _a;
|
|
51
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
52
|
+
}, 50);
|
|
53
|
+
}
|
|
54
|
+
}, [status]);
|
|
55
|
+
const handleConfirm = useCallback(async () => {
|
|
56
|
+
const syncResult = validateField(localValue, field.validation, allValues);
|
|
57
|
+
if (!syncResult.valid) {
|
|
58
|
+
const err = syncResult.errors[0] || "Invalid input";
|
|
59
|
+
setErrorMsg(err);
|
|
60
|
+
onError(field.key, err);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (hasAsyncValidation(field.validation)) {
|
|
64
|
+
setIsValidating(true);
|
|
65
|
+
const asyncResult = await validateFieldAsync(localValue, field.validation, allValues).promise;
|
|
66
|
+
setIsValidating(false);
|
|
67
|
+
if (!asyncResult.valid) {
|
|
68
|
+
const err = asyncResult.errors[0] || "Invalid input";
|
|
69
|
+
setErrorMsg(err);
|
|
70
|
+
onError(field.key, err);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
setErrorMsg(null);
|
|
75
|
+
Keyboard.dismiss();
|
|
76
|
+
onConfirm(field.key, localValue);
|
|
77
|
+
}, [field, localValue, allValues, onError, onConfirm]);
|
|
78
|
+
const textColor = (theme === null || theme === void 0 ? void 0 : theme.textColor) || (isDark ? "#fff" : "#000");
|
|
79
|
+
const primaryColor = (theme === null || theme === void 0 ? void 0 : theme.buttonBackground) || "#007bff";
|
|
80
|
+
const isConfirmed = status === "confirmed";
|
|
81
|
+
const isActive = status === "active" || status === "editing";
|
|
82
|
+
return (_jsxs(Animated.View, { style: [styles.container, { opacity }], children: [_jsxs(View, { style: styles.promptRow, children: [_jsx(Text, { style: [styles.prompt, { color: textColor }], children: status === "typing" ? typedPrompt : field.prefix }), isConfirmed && (_jsx(Text, { style: [styles.value, { color: primaryColor }], children: localValue })), isConfirmed && editable && !locked && (_jsx(TouchableOpacity, { onPress: () => onEdit(field.key), style: styles.editBtn, children: _jsx(Text, { style: [styles.editBtnText, { color: primaryColor }], children: editLabel }) }))] }), isActive && (_jsx(View, { style: styles.inputRow, children: _jsx(TextInput, { ref: inputRef, style: [
|
|
83
|
+
styles.input,
|
|
84
|
+
{ color: textColor, borderBottomColor: isValidating ? "#ccc" : primaryColor }
|
|
85
|
+
], value: localValue, onChangeText: (text) => {
|
|
86
|
+
setLocalValue(text);
|
|
87
|
+
onChange(field.key, text);
|
|
88
|
+
if (errorMsg)
|
|
89
|
+
setErrorMsg(null);
|
|
90
|
+
}, onFocus: () => onFocus(field.key), onBlur: () => onBlur(field.key, localValue), onSubmitEditing: handleConfirm, keyboardType: field.type === "email" ? "email-address" : "default", secureTextEntry: field.type === "password", returnKeyType: "next", editable: !isValidating }) })), _jsx(ErrorMessage, { message: errorMsg })] }));
|
|
91
|
+
};
|
|
92
|
+
const styles = StyleSheet.create({
|
|
93
|
+
container: {
|
|
94
|
+
marginVertical: 12,
|
|
95
|
+
},
|
|
96
|
+
promptRow: {
|
|
97
|
+
flexDirection: "row",
|
|
98
|
+
alignItems: "center",
|
|
99
|
+
flexWrap: "wrap",
|
|
100
|
+
},
|
|
101
|
+
prompt: {
|
|
102
|
+
fontSize: 18,
|
|
103
|
+
marginRight: 8,
|
|
104
|
+
},
|
|
105
|
+
value: {
|
|
106
|
+
fontSize: 18,
|
|
107
|
+
fontWeight: "600",
|
|
108
|
+
marginRight: 8,
|
|
109
|
+
},
|
|
110
|
+
editBtn: {
|
|
111
|
+
marginLeft: 8,
|
|
112
|
+
paddingHorizontal: 8,
|
|
113
|
+
paddingVertical: 4,
|
|
114
|
+
borderRadius: 4,
|
|
115
|
+
backgroundColor: "rgba(0,0,0,0.05)",
|
|
116
|
+
},
|
|
117
|
+
editBtnText: {
|
|
118
|
+
fontSize: 12,
|
|
119
|
+
fontWeight: "bold",
|
|
120
|
+
},
|
|
121
|
+
inputRow: {
|
|
122
|
+
marginTop: 8,
|
|
123
|
+
},
|
|
124
|
+
input: {
|
|
125
|
+
fontSize: 18,
|
|
126
|
+
paddingVertical: 8,
|
|
127
|
+
borderBottomWidth: 2,
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
//# sourceMappingURL=Line.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Line.js","sourceRoot":"","sources":["../../src/components/Line.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,gBAAgB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEvG,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAC3G,OAAO,EAAE,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AAQ,EAAE,EAAE;QACZ,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE,CAAC;KACf;IACD,OAAO,EAAE;QACP,UAAU,EAAE,CAAC;QACb,iBAAiB,EAAE,CAAC;QACpB,eAAe,EAAE,CAAC;QAClB,YAAY,EAAE,CAAC;QACf,eAAe,EAAE,kBAAkB;KACpC;IACD,WAAW,EAAE;QACX,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,MAAM;KACnB;IACD,QAAQ,EAAE;QACR,SAAS,EAAE,CAAC;KACb;IACD,KAAK,EAAE;QACL,QAAQ,EAAE,EAAE;QACZ,eAAe,EAAE,CAAC;QAClB,iBAAiB,EAAE,CAAC;KACrB;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { NarrativeField, NarrativeTheme, NarrativeTypewriter, NarrativeWelcome, NarrativeDone, NarrativeCallbacks, NarrativeFieldValues, NarrativeRefHandle, NarrativeI18n, NarrativeFormConfig, NarrativeCrossFieldValidator } from "@viveksinghind/narrative-form-core";
|
|
3
|
+
export interface NarrativeFormProps {
|
|
4
|
+
fields?: NarrativeField[];
|
|
5
|
+
fieldsUrl?: string;
|
|
6
|
+
fieldsUrlHeaders?: Record<string, string>;
|
|
7
|
+
formConfig?: NarrativeFormConfig;
|
|
8
|
+
theme?: NarrativeTheme;
|
|
9
|
+
typewriter?: NarrativeTypewriter;
|
|
10
|
+
welcome?: NarrativeWelcome;
|
|
11
|
+
done?: NarrativeDone;
|
|
12
|
+
editable?: boolean;
|
|
13
|
+
editLabel?: string;
|
|
14
|
+
callbacks?: NarrativeCallbacks;
|
|
15
|
+
formRef?: React.Ref<NarrativeRefHandle>;
|
|
16
|
+
defaultValues?: NarrativeFieldValues;
|
|
17
|
+
values?: NarrativeFieldValues;
|
|
18
|
+
strings?: Partial<NarrativeI18n>;
|
|
19
|
+
locale?: string;
|
|
20
|
+
direction?: "ltr" | "rtl";
|
|
21
|
+
crossFieldValidators?: NarrativeCrossFieldValidator[];
|
|
22
|
+
reducedMotion?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare const NarrativeForm: React.FC<NarrativeFormProps>;
|
|
25
|
+
//# sourceMappingURL=NarrativeForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NarrativeForm.d.ts","sourceRoot":"","sources":["../../src/components/NarrativeForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAEjF,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EAEpB,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,4BAA4B,EAC7B,MAAM,oCAAoC,CAAC;AAU5C,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,cAAc,EAAE,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,OAAO,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACxC,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAC1B,oBAAoB,CAAC,EAAE,4BAA4B,EAAE,CAAC;IACtD,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AA+ID,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAQtD,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState, useMemo } from "react";
|
|
3
|
+
import { View, StyleSheet, ScrollView } from "react-native";
|
|
4
|
+
import { mergeStrings } from "@viveksinghind/narrative-form-core";
|
|
5
|
+
import { useFormState } from "../hooks/useFormState";
|
|
6
|
+
import { useDynamicForm } from "../hooks/useDynamicForm";
|
|
7
|
+
import { Line } from "./Line";
|
|
8
|
+
import { ToastProvider } from "./ToastProvider";
|
|
9
|
+
import { ThemeProvider, useTheme } from "./ThemeProvider";
|
|
10
|
+
import { WelcomeScreen } from "./WelcomeScreen";
|
|
11
|
+
import { DoneScreen } from "./DoneScreen";
|
|
12
|
+
const NarrativeFormInner = (props) => {
|
|
13
|
+
var _a, _b, _c;
|
|
14
|
+
const { isDark } = useTheme();
|
|
15
|
+
const i18n = useMemo(() => mergeStrings(props.strings), [props.strings]);
|
|
16
|
+
const { config: dynamicConfig, loading, error, retry } = useDynamicForm({ fieldsUrl: props.fieldsUrl, fieldsUrlHeaders: props.fieldsUrlHeaders });
|
|
17
|
+
const resolvedConfig = useMemo(() => {
|
|
18
|
+
if (props.fields)
|
|
19
|
+
return { fields: props.fields };
|
|
20
|
+
if (props.formConfig)
|
|
21
|
+
return props.formConfig;
|
|
22
|
+
if (dynamicConfig)
|
|
23
|
+
return dynamicConfig;
|
|
24
|
+
return null;
|
|
25
|
+
}, [props.fields, props.formConfig, dynamicConfig]);
|
|
26
|
+
const fields = (_a = resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.fields) !== null && _a !== void 0 ? _a : [];
|
|
27
|
+
const welcome = (_b = props.welcome) !== null && _b !== void 0 ? _b : (resolvedConfig && "welcome" in resolvedConfig ? resolvedConfig.welcome : undefined);
|
|
28
|
+
const done = (_c = props.done) !== null && _c !== void 0 ? _c : (resolvedConfig && "done" in resolvedConfig ? resolvedConfig.done : undefined);
|
|
29
|
+
const effectiveTypewriter = useMemo(() => {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
return ({
|
|
32
|
+
...props.typewriter,
|
|
33
|
+
enabled: props.reducedMotion ? false : ((_b = (_a = props.typewriter) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : true),
|
|
34
|
+
});
|
|
35
|
+
}, [props.typewriter, props.reducedMotion]);
|
|
36
|
+
const { snapshot, startTyping, activateField, confirmField, editField, reconfirmField, next, focusField, reset, getValues, getMeta, } = useFormState(fields);
|
|
37
|
+
const showWelcome = (welcome === null || welcome === void 0 ? void 0 : welcome.show) !== false && welcome !== undefined;
|
|
38
|
+
const [welcomeDismissed, setWelcomeDismissed] = useState(!showWelcome);
|
|
39
|
+
const hasStartedRef = useRef(false);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!welcomeDismissed || hasStartedRef.current || fields.length === 0)
|
|
42
|
+
return;
|
|
43
|
+
hasStartedRef.current = true;
|
|
44
|
+
const firstField = fields.find((f) => snapshot.statuses[f.key] !== "confirmed");
|
|
45
|
+
if (firstField) {
|
|
46
|
+
startTyping(firstField.key);
|
|
47
|
+
}
|
|
48
|
+
}, [welcomeDismissed, fields, startTyping, snapshot.statuses]);
|
|
49
|
+
const handleConfirm = useCallback((key, value) => {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
const status = snapshot.statuses[key];
|
|
52
|
+
if (status === "editing") {
|
|
53
|
+
reconfirmField(key, value);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
confirmField(key, value);
|
|
57
|
+
}
|
|
58
|
+
(_b = (_a = props.callbacks) === null || _a === void 0 ? void 0 : _a.onFieldComplete) === null || _b === void 0 ? void 0 : _b.call(_a, key, value, 0);
|
|
59
|
+
const currentIndex = fields.findIndex((f) => f.key === key);
|
|
60
|
+
for (let i = currentIndex + 1; i < fields.length; i++) {
|
|
61
|
+
const nextField = fields[i];
|
|
62
|
+
if (!nextField || snapshot.statuses[nextField.key] === "confirmed")
|
|
63
|
+
continue;
|
|
64
|
+
startTyping(nextField.key);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}, [snapshot, fields, confirmField, reconfirmField, startTyping, props.callbacks]);
|
|
68
|
+
const visibleFields = useMemo(() => {
|
|
69
|
+
return fields.filter((field) => {
|
|
70
|
+
const status = snapshot.statuses[field.key];
|
|
71
|
+
return status === "typing" || status === "active" || status === "confirmed" || status === "editing";
|
|
72
|
+
});
|
|
73
|
+
}, [fields, snapshot.statuses]);
|
|
74
|
+
const scrollViewRef = useRef(null);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (visibleFields.length > 0) {
|
|
77
|
+
setTimeout(() => {
|
|
78
|
+
var _a;
|
|
79
|
+
(_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollToEnd({ animated: true });
|
|
80
|
+
}, 100);
|
|
81
|
+
}
|
|
82
|
+
}, [visibleFields.length]);
|
|
83
|
+
return (_jsxs(ScrollView, { ref: scrollViewRef, style: [styles.container, isDark ? styles.darkContainer : styles.lightContainer], contentContainerStyle: styles.content, keyboardShouldPersistTaps: "handled", children: [!welcomeDismissed && welcome && (_jsx(WelcomeScreen, { welcome: welcome, typewriter: effectiveTypewriter, onStart: () => setWelcomeDismissed(true) })), welcomeDismissed && (_jsx(View, { style: styles.formBody, children: visibleFields.map((field) => {
|
|
84
|
+
var _a, _b, _c, _d, _e;
|
|
85
|
+
return (_jsx(Line, { field: field, status: (_a = snapshot.statuses[field.key]) !== null && _a !== void 0 ? _a : "idle", value: (_c = (_b = props.values) === null || _b === void 0 ? void 0 : _b[field.key]) !== null && _c !== void 0 ? _c : snapshot.values[field.key], allValues: snapshot.values, typewriter: effectiveTypewriter, editable: (_d = props.editable) !== null && _d !== void 0 ? _d : true, locked: false, editLabel: (_e = props.editLabel) !== null && _e !== void 0 ? _e : i18n.editLabel, onTypingComplete: (k) => activateField(k), onConfirm: handleConfirm, onEdit: (k) => {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
editField(k);
|
|
88
|
+
(_b = (_a = props.callbacks) === null || _a === void 0 ? void 0 : _a.onEdit) === null || _b === void 0 ? void 0 : _b.call(_a, k);
|
|
89
|
+
}, onError: (k, err) => { var _a, _b; return (_b = (_a = props.callbacks) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, k, err); }, onChange: (k, v) => { var _a, _b; return (_b = (_a = props.callbacks) === null || _a === void 0 ? void 0 : _a.onChange) === null || _b === void 0 ? void 0 : _b.call(_a, k, v); }, onFocus: (k) => { var _a, _b; return (_b = (_a = props.callbacks) === null || _a === void 0 ? void 0 : _a.onFieldFocus) === null || _b === void 0 ? void 0 : _b.call(_a, k); }, onBlur: (k, v) => { var _a, _b; return (_b = (_a = props.callbacks) === null || _a === void 0 ? void 0 : _a.onFieldBlur) === null || _b === void 0 ? void 0 : _b.call(_a, k, v); } }, field.key));
|
|
90
|
+
}) })), snapshot.isComplete && done && (_jsx(DoneScreen, { done: done, values: snapshot.values, meta: getMeta(), typewriter: effectiveTypewriter }))] }));
|
|
91
|
+
};
|
|
92
|
+
export const NarrativeForm = (props) => {
|
|
93
|
+
return (_jsx(ThemeProvider, { theme: props.theme, children: _jsx(ToastProvider, { children: _jsx(NarrativeFormInner, { ...props }) }) }));
|
|
94
|
+
};
|
|
95
|
+
const styles = StyleSheet.create({
|
|
96
|
+
container: {
|
|
97
|
+
flex: 1,
|
|
98
|
+
},
|
|
99
|
+
lightContainer: {
|
|
100
|
+
backgroundColor: "#ffffff",
|
|
101
|
+
},
|
|
102
|
+
darkContainer: {
|
|
103
|
+
backgroundColor: "#121212",
|
|
104
|
+
},
|
|
105
|
+
content: {
|
|
106
|
+
padding: 20,
|
|
107
|
+
flexGrow: 1,
|
|
108
|
+
},
|
|
109
|
+
formBody: {
|
|
110
|
+
flex: 1,
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
//# sourceMappingURL=NarrativeForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NarrativeForm.js","sourceRoot":"","sources":["../../src/components/NarrativeForm.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACjF,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAe5D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAwB1C,MAAM,kBAAkB,GAAiC,CAAC,KAAK,EAAE,EAAE;;IACjE,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAEzE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GACpD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,IACU,CACd,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAiC,CAAC,KAAK,EAAE,EAAE;IACnE,OAAO,CACL,KAAC,aAAa,IAAC,KAAK,EAAE,KAAK,CAAC,KAAK,YAC/B,KAAC,aAAa,cACZ,KAAC,kBAAkB,OAAK,KAAK,GAAI,GACnB,GACF,CACjB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,SAAS,EAAE;QACT,IAAI,EAAE,CAAC;KACR;IACD,cAAc,EAAE;QACd,eAAe,EAAE,SAAS;KAC3B;IACD,aAAa,EAAE;QACb,eAAe,EAAE,SAAS;KAC3B;IACD,OAAO,EAAE;QACP,OAAO,EAAE,EAAE;QACX,QAAQ,EAAE,CAAC;KACZ;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,CAAC;KACR;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { NarrativeTheme } from "@viveksinghind/narrative-form-core";
|
|
3
|
+
export interface ThemeContextValue {
|
|
4
|
+
theme: NarrativeTheme | undefined;
|
|
5
|
+
isDark: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const useTheme: () => ThemeContextValue;
|
|
8
|
+
export interface ThemeProviderProps {
|
|
9
|
+
theme?: NarrativeTheme;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export declare const ThemeProvider: React.FC<ThemeProviderProps>;
|
|
13
|
+
//# sourceMappingURL=ThemeProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../src/components/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,cAAc,GAAG,SAAS,CAAC;IAClC,MAAM,EAAE,OAAO,CAAC;CACjB;AAOD,eAAO,MAAM,QAAQ,yBAAiC,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAWtD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useMemo } from "react";
|
|
3
|
+
const ThemeContext = createContext({
|
|
4
|
+
theme: undefined,
|
|
5
|
+
isDark: false,
|
|
6
|
+
});
|
|
7
|
+
export const useTheme = () => useContext(ThemeContext);
|
|
8
|
+
export const ThemeProvider = ({ theme, children }) => {
|
|
9
|
+
const value = useMemo(() => {
|
|
10
|
+
// In React Native we can check Appearance.getColorScheme() if we want auto dark mode,
|
|
11
|
+
// but for now we just rely on the theme prop.
|
|
12
|
+
return {
|
|
13
|
+
theme,
|
|
14
|
+
isDark: !!(theme === null || theme === void 0 ? void 0 : theme.mode) && theme.mode === "dark",
|
|
15
|
+
};
|
|
16
|
+
}, [theme]);
|
|
17
|
+
return _jsx(ThemeContext.Provider, { value: value, children: children });
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=ThemeProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeProvider.js","sourceRoot":"","sources":["../../src/components/ThemeProvider.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAQlE,MAAM,YAAY,GAAG,aAAa,CAAoB;IACpD,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,KAAK;CACd,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AAOvD,MAAM,CAAC,MAAM,aAAa,GAAiC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;IACjF,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,sFAAsF;QACtF,8CAA8C;QAC9C,OAAO;YACL,KAAK;YACL,MAAM,EAAE,CAAC,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,CAAA,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;SAC/C,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,KAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAyB,CAAC;AACjF,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface ToastContextValue {
|
|
3
|
+
showToast: (message: string, type?: "error" | "success" | "info") => void;
|
|
4
|
+
}
|
|
5
|
+
export declare const useToast: () => ToastContextValue;
|
|
6
|
+
export declare const ToastProvider: React.FC<{
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
}>;
|
|
9
|
+
//# sourceMappingURL=ToastProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToastProvider.d.ts","sourceRoot":"","sources":["../../src/components/ToastProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAGhF,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,KAAK,IAAI,CAAC;CAC3E;AAMD,eAAO,MAAM,QAAQ,yBAAiC,CAAC;AAEvD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CAoBjE,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useState, useCallback } from "react";
|
|
3
|
+
import { View, Text, StyleSheet } from "react-native";
|
|
4
|
+
const ToastContext = createContext({
|
|
5
|
+
showToast: () => { },
|
|
6
|
+
});
|
|
7
|
+
export const useToast = () => useContext(ToastContext);
|
|
8
|
+
export const ToastProvider = ({ children }) => {
|
|
9
|
+
const [toast, setToast] = useState(null);
|
|
10
|
+
const showToast = useCallback((message, type = "info") => {
|
|
11
|
+
setToast({ message, type });
|
|
12
|
+
setTimeout(() => setToast(null), 3000);
|
|
13
|
+
}, []);
|
|
14
|
+
return (_jsx(ToastContext.Provider, { value: { showToast }, children: _jsxs(View, { style: styles.container, children: [children, toast && (_jsx(View, { style: [styles.toast, toast.type === "error" ? styles.toastError : styles.toastSuccess], children: _jsx(Text, { style: styles.toastText, children: toast.message }) }))] }) }));
|
|
15
|
+
};
|
|
16
|
+
const styles = StyleSheet.create({
|
|
17
|
+
container: {
|
|
18
|
+
flex: 1,
|
|
19
|
+
},
|
|
20
|
+
toast: {
|
|
21
|
+
position: "absolute",
|
|
22
|
+
bottom: 40,
|
|
23
|
+
left: 20,
|
|
24
|
+
right: 20,
|
|
25
|
+
padding: 16,
|
|
26
|
+
borderRadius: 8,
|
|
27
|
+
backgroundColor: "#333",
|
|
28
|
+
alignItems: "center",
|
|
29
|
+
},
|
|
30
|
+
toastError: {
|
|
31
|
+
backgroundColor: "#d32f2f",
|
|
32
|
+
},
|
|
33
|
+
toastSuccess: {
|
|
34
|
+
backgroundColor: "#2e7d32",
|
|
35
|
+
},
|
|
36
|
+
toastText: {
|
|
37
|
+
color: "#fff",
|
|
38
|
+
fontSize: 14,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=ToastProvider.js.map
|
|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