@thanhphi/unistyles-ui 0.0.0-stage → 0.2.7
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 +384 -2
- package/dist/choices.d.ts +52 -0
- package/dist/choices.js +143 -0
- package/dist/colors/index.d.ts +79 -0
- package/dist/colors/index.js +2 -0
- package/dist/date.d.ts +40 -0
- package/dist/date.js +153 -0
- package/dist/fields.d.ts +140 -0
- package/dist/fields.js +233 -0
- package/dist/form/index.d.ts +14 -0
- package/dist/form/index.js +68 -0
- package/dist/icons.d.ts +10 -0
- package/dist/icons.js +52 -0
- package/dist/image.d.ts +20 -0
- package/dist/image.js +34 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +33 -0
- package/dist/list-picker.d.ts +45 -0
- package/dist/list-picker.js +76 -0
- package/dist/module/choices.js +135 -0
- package/dist/module/colors/index.js +1 -0
- package/dist/module/colors/package.json +1 -0
- package/dist/module/date.js +145 -0
- package/dist/module/fields.js +225 -0
- package/dist/module/form/index.js +62 -0
- package/dist/module/form/package.json +1 -0
- package/dist/module/icons.js +16 -0
- package/dist/module/image.js +31 -0
- package/dist/module/index.js +13 -0
- package/dist/module/list-picker.js +70 -0
- package/dist/module/overlays.js +138 -0
- package/dist/module/package.json +1 -0
- package/dist/module/primitives.js +432 -0
- package/dist/module/process-graph.js +125 -0
- package/dist/module/rich-html/html-styles.js +55 -0
- package/dist/module/rich-html/image-renderers.js +141 -0
- package/dist/module/rich-html/index.js +54 -0
- package/dist/module/rich-html/normalize-inline-colors.js +93 -0
- package/dist/module/rich-html/package.json +1 -0
- package/dist/module/rich-html/rich-html.js +118 -0
- package/dist/module/search.js +88 -0
- package/dist/module/theme.js +62 -0
- package/dist/module/toast.js +30 -0
- package/dist/module/ui-modal.js +145 -0
- package/dist/overlays.d.ts +72 -0
- package/dist/overlays.js +146 -0
- package/dist/primitives.d.ts +157 -0
- package/dist/primitives.js +480 -0
- package/dist/process-graph.d.ts +33 -0
- package/dist/process-graph.js +161 -0
- package/dist/rich-html/html-styles.d.ts +23 -0
- package/dist/rich-html/html-styles.js +63 -0
- package/dist/rich-html/image-renderers.d.ts +12 -0
- package/dist/rich-html/image-renderers.js +144 -0
- package/dist/rich-html/index.d.ts +18 -0
- package/dist/rich-html/index.js +92 -0
- package/dist/rich-html/normalize-inline-colors.d.ts +8 -0
- package/dist/rich-html/normalize-inline-colors.js +99 -0
- package/dist/rich-html/rich-html.d.ts +7 -0
- package/dist/rich-html/rich-html.js +123 -0
- package/dist/search.d.ts +27 -0
- package/dist/search.js +91 -0
- package/dist/theme.d.ts +67 -0
- package/dist/theme.js +68 -0
- package/dist/toast.d.ts +3 -0
- package/dist/toast.js +69 -0
- package/dist/ui-modal.d.ts +17 -0
- package/dist/ui-modal.js +151 -0
- package/package.json +35 -4
package/dist/ui-modal.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.UIModal = UIModal;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const react_native_1 = require("react-native");
|
|
10
|
+
const theme_1 = require("./theme");
|
|
11
|
+
function UIModal({ visible, onClose, onOpened, onClosed, position = "center", animationType = "slide", statusBarTranslucent, keyboardAvoiding = false, backdropColor, contentStyle, containerStyle, children, }) {
|
|
12
|
+
const { colors } = (0, theme_1.useUITheme)();
|
|
13
|
+
const Root = keyboardAvoiding && react_native_1.Platform.OS === "ios" ? react_native_1.KeyboardAvoidingView : react_native_1.View;
|
|
14
|
+
const backgroundColor = backdropColor ?? colors.backdrop;
|
|
15
|
+
const renderContent = (motion) => {
|
|
16
|
+
const Panel = motion ? react_native_1.Animated.View : react_native_1.View;
|
|
17
|
+
return ((0, jsx_runtime_1.jsxs)(Root, { behavior: Root === react_native_1.KeyboardAvoidingView ? "padding" : undefined, style: [
|
|
18
|
+
styles.root,
|
|
19
|
+
position === "bottom" && styles.bottom,
|
|
20
|
+
containerStyle,
|
|
21
|
+
!motion && { backgroundColor },
|
|
22
|
+
], pointerEvents: visible ? "auto" : "none", children: [motion && ((0, jsx_runtime_1.jsx)(react_native_1.Animated.View, { pointerEvents: "none", style: [
|
|
23
|
+
react_native_1.StyleSheet.absoluteFill,
|
|
24
|
+
{ backgroundColor, opacity: motion.progress },
|
|
25
|
+
] })), onClose && ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { style: react_native_1.StyleSheet.absoluteFill, onPress: onClose, accessible: false })), (0, jsx_runtime_1.jsx)(Panel, { accessibilityViewIsModal: true, onLayout: motion?.onLayout, style: [
|
|
26
|
+
styles.panel,
|
|
27
|
+
position === "fullScreen" && styles.fullScreen,
|
|
28
|
+
contentStyle,
|
|
29
|
+
motion && {
|
|
30
|
+
opacity: motion.progress,
|
|
31
|
+
transform: [
|
|
32
|
+
{
|
|
33
|
+
translateY: motion.progress.interpolate({
|
|
34
|
+
inputRange: [0, 1],
|
|
35
|
+
outputRange: [motion.offset, 0],
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
], children: children })] }));
|
|
41
|
+
};
|
|
42
|
+
if (onOpened || onClosed)
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(ModalTransition, { visible: visible, onClose: onClose, onOpened: onOpened, onClosed: onClosed, animationType: animationType, statusBarTranslucent: statusBarTranslucent, children: renderContent }));
|
|
44
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Modal, { visible: visible, transparent: true, animationType: animationType, onRequestClose: onClose ?? ignoreModalClose, statusBarTranslucent: statusBarTranslucent, children: renderContent() }));
|
|
45
|
+
}
|
|
46
|
+
// Modal.onDismiss is iOS-only. Animate the panel and backdrop when callbacks
|
|
47
|
+
// are requested so Android can finish the exit before removing the modal.
|
|
48
|
+
function ModalTransition({ visible, onClose, statusBarTranslucent, onOpened, onClosed, animationType, children, }) {
|
|
49
|
+
const [presented, setPresented] = react_1.default.useState(visible);
|
|
50
|
+
const [shown, setShown] = react_1.default.useState(false);
|
|
51
|
+
const [panelHeight, setPanelHeight] = react_1.default.useState(0);
|
|
52
|
+
const [reduceMotion, setReduceMotion] = react_1.default.useState(false);
|
|
53
|
+
const [progress] = react_1.default.useState(() => new react_native_1.Animated.Value(0));
|
|
54
|
+
const request = react_1.default.useRef({ visible, onOpened, onClosed });
|
|
55
|
+
const dismissing = react_1.default.useRef(false);
|
|
56
|
+
const didOpen = react_1.default.useRef(false);
|
|
57
|
+
const entranceReady = shown && (animationType !== "slide" || panelHeight > 0);
|
|
58
|
+
const animate = animationType !== "none" && !reduceMotion;
|
|
59
|
+
react_1.default.useEffect(() => {
|
|
60
|
+
if (!presented)
|
|
61
|
+
return;
|
|
62
|
+
let active = true;
|
|
63
|
+
react_native_1.AccessibilityInfo.isReduceMotionEnabled().then((value) => {
|
|
64
|
+
if (active)
|
|
65
|
+
setReduceMotion(value);
|
|
66
|
+
});
|
|
67
|
+
const subscription = react_native_1.AccessibilityInfo.addEventListener("reduceMotionChanged", setReduceMotion);
|
|
68
|
+
return () => {
|
|
69
|
+
active = false;
|
|
70
|
+
subscription.remove();
|
|
71
|
+
};
|
|
72
|
+
}, [presented]);
|
|
73
|
+
react_1.default.useLayoutEffect(() => {
|
|
74
|
+
request.current = { visible, onOpened, onClosed };
|
|
75
|
+
}, [visible, onOpened, onClosed]);
|
|
76
|
+
const didDismiss = react_1.default.useCallback(() => {
|
|
77
|
+
if (!dismissing.current)
|
|
78
|
+
return;
|
|
79
|
+
dismissing.current = false;
|
|
80
|
+
setShown(false);
|
|
81
|
+
setPanelHeight(0);
|
|
82
|
+
if (request.current.visible)
|
|
83
|
+
setPresented(true);
|
|
84
|
+
else
|
|
85
|
+
request.current.onClosed?.();
|
|
86
|
+
}, []);
|
|
87
|
+
react_1.default.useEffect(() => {
|
|
88
|
+
if (react_native_1.Platform.OS !== "ios" && !presented)
|
|
89
|
+
didDismiss();
|
|
90
|
+
}, [didDismiss, presented]);
|
|
91
|
+
react_1.default.useEffect(() => {
|
|
92
|
+
if (dismissing.current)
|
|
93
|
+
return;
|
|
94
|
+
if (!presented) {
|
|
95
|
+
if (visible)
|
|
96
|
+
setPresented(true);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (visible && !entranceReady && animate)
|
|
100
|
+
return;
|
|
101
|
+
if (visible && !shown)
|
|
102
|
+
return;
|
|
103
|
+
if (!visible)
|
|
104
|
+
didOpen.current = false;
|
|
105
|
+
const complete = () => {
|
|
106
|
+
if (visible !== request.current.visible)
|
|
107
|
+
return;
|
|
108
|
+
if (visible) {
|
|
109
|
+
if (didOpen.current)
|
|
110
|
+
return;
|
|
111
|
+
didOpen.current = true;
|
|
112
|
+
request.current.onOpened?.();
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
dismissing.current = true;
|
|
116
|
+
setPresented(false);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const target = visible ? 1 : 0;
|
|
120
|
+
if (!animate || !shown) {
|
|
121
|
+
progress.setValue(target);
|
|
122
|
+
complete();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const animation = react_native_1.Animated.timing(progress, {
|
|
126
|
+
toValue: target,
|
|
127
|
+
duration: visible ? 220 : 200,
|
|
128
|
+
easing: react_native_1.Easing.out(react_native_1.Easing.cubic),
|
|
129
|
+
useNativeDriver: true,
|
|
130
|
+
});
|
|
131
|
+
animation.start(({ finished }) => {
|
|
132
|
+
if (finished)
|
|
133
|
+
complete();
|
|
134
|
+
});
|
|
135
|
+
return () => animation.stop();
|
|
136
|
+
}, [animate, entranceReady, presented, progress, shown, visible]);
|
|
137
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.Modal, { visible: presented, transparent: true, animationType: "none", onRequestClose: visible ? onClose ?? ignoreModalClose : ignoreModalClose, onShow: () => setShown(true), onDismiss: didDismiss, statusBarTranslucent: statusBarTranslucent, children: children(animate
|
|
138
|
+
? {
|
|
139
|
+
progress,
|
|
140
|
+
offset: animationType === "slide" ? panelHeight : 0,
|
|
141
|
+
onLayout: (event) => setPanelHeight(event.nativeEvent.layout.height),
|
|
142
|
+
}
|
|
143
|
+
: undefined) }));
|
|
144
|
+
}
|
|
145
|
+
const ignoreModalClose = () => { };
|
|
146
|
+
const styles = react_native_1.StyleSheet.create({
|
|
147
|
+
root: { flex: 1, justifyContent: "center" },
|
|
148
|
+
bottom: { justifyContent: "flex-end" },
|
|
149
|
+
panel: { flexShrink: 1 },
|
|
150
|
+
fullScreen: { flex: 1 },
|
|
151
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thanhphi/unistyles-ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.7",
|
|
4
|
+
"description": "React Native UI components with app-owned themes and Unistyles integration",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/module/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"react-native": "dist/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {"types": "./dist/index.d.ts", "react-native": "./dist/index.js", "import": "./dist/module/index.js", "require": "./dist/index.js"},
|
|
12
|
+
"./form": {"types": "./dist/form/index.d.ts", "react-native": "./dist/form/index.js", "import": "./dist/module/form/index.js", "require": "./dist/form/index.js"},
|
|
13
|
+
"./rich-html": {"types": "./dist/rich-html/index.d.ts", "react-native": "./dist/rich-html/index.js", "import": "./dist/module/rich-html/index.js", "require": "./dist/rich-html/index.js"},
|
|
14
|
+
"./toast": {"types": "./dist/toast.d.ts", "react-native": "./dist/toast.js", "import": "./dist/module/toast.js", "require": "./dist/toast.js"},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"expo-image": ">=55.0.0 <56",
|
|
21
|
+
"react": ">=19.0.0 <20",
|
|
22
|
+
"react-native": ">=0.83.0 <0.84",
|
|
23
|
+
"react-native-calendars": ">=1.1314.0 <2",
|
|
24
|
+
"react-native-keyboard-controller": ">=1.21.7 <2",
|
|
25
|
+
"react-native-render-html": "6.3.4",
|
|
26
|
+
"react-native-safe-area-context": ">=5.6.0 <6",
|
|
27
|
+
"react-native-svg": ">=15.15.0 <16",
|
|
28
|
+
"react-native-toast-message": ">=2.3.3 <3"
|
|
29
|
+
},
|
|
30
|
+
"peerDependenciesMeta": {
|
|
31
|
+
"react-native-keyboard-controller": {"optional": true},
|
|
32
|
+
"react-native-render-html": {"optional": true},
|
|
33
|
+
"react-native-toast-message": {"optional": true}
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {"access": "public", "registry": "https://registry.npmjs.org/"},
|
|
36
|
+
"engines": {"node": ">=20"}
|
|
37
|
+
}
|