@fto-consult/expo-ui 2.18.5 → 2.19.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fto-consult/expo-ui",
3
- "version": "2.18.5",
3
+ "version": "2.19.7",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -103,6 +103,7 @@
103
103
  "react-native-webview": "11.23.1",
104
104
  "sharp-cli": "^2.1.0",
105
105
  "tippy.js": "^6.3.7",
106
+ "use-event-callback": "^0.1.0",
106
107
  "xlsx": "^0.18.5"
107
108
  },
108
109
  "devDependencies": {
@@ -1151,7 +1151,7 @@ export default class CommonDatagridComponent extends AppComponent {
1151
1151
  sortedColumn.header = header;
1152
1152
  sortedColumn.label = restCol.label;
1153
1153
  const isDesc = currentSortedColumn.dir === "desc";
1154
- const prefix = (sortType =='number' || sortType == 'decimal') ? "numeric" : sortType =='boolean'?'bool' : sortType =='date'? 'calendar': sortType =='time'? 'clock' : 'alphabetical';
1154
+ const prefix = (sortType =='number' || sortType == 'decimal') ? "numeric" : sortType =='boolean'?'bool' : sortType.contains('date') ? 'calendar': sortType =='time'? 'clock' : 'alphabetical';
1155
1155
  sortedColumn.icon = 'sort-'+prefix+'-'+(isDesc ? "descending" : "ascending");
1156
1156
  sortedColumn.title = (isDesc ? "Trié par ordre décroissant":"Trié par ordre croissant ")+ " du champ ["+restCol.label+"]";
1157
1157
  }
@@ -0,0 +1,248 @@
1
+ // Copyright 2022 @fto-consult/Boris Fouomene. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ import React from '$react';
6
+ import {
7
+ Animated,
8
+ Easing,
9
+ StyleSheet,
10
+ View,
11
+ } from 'react-native';
12
+ import theme from "$theme";
13
+ import {defaultObj,isObj,defaultStr} from "$utils";
14
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
15
+ import useEventCallback from 'use-event-callback';
16
+ import PropTypes from "prop-types";
17
+ import Surface from '$ecomponents/Surface';
18
+ import Label from "$ecomponents/Label"
19
+ import Button from "$components/Button";
20
+
21
+ const DURATION_SHORT = 4000;
22
+ const DURATION_MEDIUM = 7000;
23
+ const DURATION_LONG = 10000;
24
+
25
+ const Snackbar = ({
26
+ visible,
27
+ action,
28
+ icon,
29
+ duration = DURATION_MEDIUM,
30
+ onDismiss,
31
+ children,
32
+ labelProps,
33
+ elevation = 2,
34
+ containerProps,
35
+ style,
36
+ testID,
37
+ contentProps,
38
+ ...rest
39
+ }) => {
40
+ labelProps = defaultObj(labelProps);
41
+ containerProps = defaultObj(containerProps);
42
+ contentProps = defaultObj(contentProps);
43
+ labelProps = defaultObj(labelProps);
44
+ const { bottom, right, left } = useSafeAreaInsets();
45
+ testID = defaultStr(testID,"RN_SnackbarComponent")
46
+ const { current: opacity } = React.useRef(
47
+ new Animated.Value(0.0)
48
+ );
49
+ const hideTimeout = React.useRef(undefined);
50
+ const flattenStyle = StyleSheet.flatten(style) || {};
51
+ const [hidden, setHidden] = React.useState(!visible);
52
+
53
+ const scale = 1.0;
54
+
55
+ const handleOnVisible = useEventCallback(() => {
56
+ // show
57
+ if (hideTimeout.current) clearTimeout(hideTimeout.current);
58
+ setHidden(false);
59
+ Animated.timing(opacity, {
60
+ toValue: 1,
61
+ duration: 200 * scale,
62
+ easing: Easing.out(Easing.ease),
63
+ useNativeDriver: true,
64
+ }).start(({ finished }) => {
65
+ if (finished) {
66
+ const isInfinity =
67
+ duration === Number.POSITIVE_INFINITY ||
68
+ duration === Number.NEGATIVE_INFINITY;
69
+
70
+ if (!isInfinity) {
71
+ hideTimeout.current = setTimeout(
72
+ onDismiss,
73
+ duration
74
+ );
75
+ }
76
+ }
77
+ });
78
+ });
79
+
80
+ const handleOnHidden = useEventCallback(() => {
81
+ // hide
82
+ if (hideTimeout.current) {
83
+ clearTimeout(hideTimeout.current);
84
+ }
85
+
86
+ Animated.timing(opacity, {
87
+ toValue: 0,
88
+ duration: 100 * scale,
89
+ useNativeDriver: true,
90
+ }).start(({ finished }) => {
91
+ if (finished) {
92
+ setHidden(true);
93
+ }
94
+ });
95
+ });
96
+
97
+ React.useEffect(() => {
98
+ return () => {
99
+ if (hideTimeout.current) clearTimeout(hideTimeout.current);
100
+ };
101
+ }, []);
102
+
103
+ React.useLayoutEffect(() => {
104
+ if (visible) {
105
+ handleOnVisible();
106
+ } else {
107
+ handleOnHidden();
108
+ }
109
+ }, [visible, handleOnVisible, handleOnHidden]);
110
+
111
+ const roundness = theme.roundness, colors = theme.colors;
112
+ action = React.isValidElement(action)? action : isObj(action) ? <Button {...action}/> : null;
113
+ if (hidden) {
114
+ return null;
115
+ }
116
+
117
+ const containerPaddings = {
118
+ paddingBottom: bottom,
119
+ paddingHorizontal: Math.max(left, right),
120
+ };
121
+ return (
122
+ <View
123
+ testID={testID+"_Container"}
124
+ {...containerProps}
125
+ pointerEvents="box-none"
126
+ style={[styles.wrapper, containerPaddings,containerProps.style]}
127
+ >
128
+ <Surface
129
+ pointerEvents="box-none"
130
+ accessibilityLiveRegion="polite"
131
+ elevation = {elevation}
132
+ {...rest}
133
+ testID={testID}
134
+ style={[
135
+ styles.container,
136
+ {
137
+ borderRadius: roundness,
138
+ opacity: opacity,
139
+ transform: [
140
+ {
141
+ scale: visible
142
+ ? opacity.interpolate({
143
+ inputRange: [0, 1],
144
+ outputRange: [0.9, 1],
145
+ })
146
+ : 1,
147
+ },
148
+ ],
149
+ },
150
+ style
151
+ ]}
152
+ >
153
+ {<View testID={testID+"_Content"} {...contentProps} style={[styles.content,contentProps.style]}>
154
+ {typeof children =='string' || typeof children ==='string' ?
155
+ <Label {...labelProps} style={[{color:flattenStyle.color,backgroundColor:flattenStyle.backgroundColor},labelProps.style]}>
156
+ {children}
157
+ </Label> : React.isValidElement(children)? children : null}
158
+ </View>}
159
+ {React.isValidElement(action)? action : null}
160
+ </Surface>
161
+ </View>
162
+ );
163
+ };
164
+
165
+ /**
166
+ * Show the Snackbar for a short duration.
167
+ */
168
+ Snackbar.DURATION_SHORT = DURATION_SHORT;
169
+
170
+ /**
171
+ * Show the Snackbar for a medium duration.
172
+ */
173
+ Snackbar.DURATION_MEDIUM = DURATION_MEDIUM;
174
+
175
+ /**
176
+ * Show the Snackbar for a long duration.
177
+ */
178
+ Snackbar.DURATION_LONG = DURATION_LONG;
179
+
180
+ Snackbar.propTypes = {
181
+ /**
182
+ * Whether the Snackbar is currently visible.
183
+ */
184
+ visible: PropTypes.bool,
185
+ /**
186
+ * Label and press callback for the action button. It should contain the following properties:
187
+ * - `label` - Label of the action button
188
+ * - `onPress` - Callback that is called when action button is pressed.
189
+ */
190
+ action: PropTypes.oneOfType([
191
+ PropTypes.shape({
192
+ label: PropTypes.string,
193
+ }),
194
+ PropTypes.node,
195
+ PropTypes.element,
196
+ ]),
197
+ duration : PropTypes.number,
198
+ /**
199
+ * Callback called when Snackbar is dismissed. The `visible` prop needs to be updated when this is called.
200
+ */
201
+ onDismiss: PropTypes.func,
202
+ /**
203
+ * Text content of the Snackbar.
204
+ */
205
+ children: PropTypes.any,
206
+ containerProps : PropTypes.object,
207
+ contentProps : PropTypes.object,
208
+ };
209
+
210
+ const styles = StyleSheet.create({
211
+ wrapper: {
212
+ position: 'absolute',
213
+ bottom: 0,
214
+ width: '100%',
215
+ },
216
+ container: {
217
+ flexDirection: 'row',
218
+ justifyContent: 'space-between',
219
+ margin: 8,
220
+ borderRadius: 4,
221
+ minHeight: 48,
222
+ },
223
+ content: {
224
+ marginHorizontal: 16,
225
+ marginVertical: 14,
226
+ flex: 1,
227
+ },
228
+ actionsContainer: {
229
+ flexDirection: 'row',
230
+ justifyContent: 'flex-end',
231
+ alignItems: 'center',
232
+ minHeight: 48,
233
+ },
234
+ button: {
235
+ marginRight: 8,
236
+ marginLeft: 4,
237
+ },
238
+ elevation: {
239
+ elevation: 6,
240
+ },
241
+ icon: {
242
+ width: 40,
243
+ height: 40,
244
+ margin: 0,
245
+ },
246
+ });
247
+
248
+ export default theme.withStyles(Snackbar,"SnackbarComponent");