@fto-consult/expo-ui 8.48.3 → 8.49.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fto-consult/expo-ui",
3
- "version": "8.48.3",
3
+ "version": "8.49.0",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "react-native-paper-doc": "https://github.com/callstack/react-native-paper/tree/main/docs/docs/guides",
6
6
  "scripts": {
@@ -0,0 +1,160 @@
1
+ import { forwardRef } from "react";
2
+ import View from "$ecomponents/View";
3
+ import { Badge as RNBadge } from "react-native-paper";
4
+ import { StyleSheet, Pressable } from "react-native";
5
+ import Menu from "$ecomponents/Menu";
6
+ import List from "$ecomponents/List";
7
+ import theme from "$theme";
8
+ import Icon from "$ecomponents/Icon";
9
+ import { defaultStr,isPlainObj } from "$utils";
10
+ import { HStack } from "$ecomponents/Stack";
11
+ import Label from "$ecomponents/Label";
12
+ import Divider from "$ecomponents/Divider";
13
+ import Button from "$ecomponents/Button";
14
+ import Dimensions from "$cdimensions";
15
+ import React from "$react";
16
+ import PropTypes from "prop-types";
17
+
18
+ const Notifications = forwardRef(({testID,items:cItems,menuProps,title,containerProps,contentContainerProps,clearAllButton,clearAll,...rest}, ref) => {
19
+ const items = React.useMemo(()=>{
20
+ return Array.isArray(cItems) ? cItems : [];
21
+ },[cItems]);
22
+ testID = defaultStr(testID, "RN_Main_Notifications");
23
+ const { height } = Dimensions.get("window");
24
+ menuProps = Object.assign({},menuProps);
25
+ containerProps = Object.assign({},containerProps);
26
+ contentContainerProps = Object.assign({},contentContainerProps);
27
+ return (
28
+ <Menu
29
+ testID = {`${testID}_NotificationsMenu`}
30
+ ref = {ref}
31
+ anchor={(p) => {
32
+ const { onPress } = p;
33
+ return (
34
+ <Pressable {...p} style={[p.style, styles.anchor]}>
35
+ <RNBadge
36
+ onPress={onPress}
37
+ style={[
38
+ styles.badge,
39
+ {
40
+ color: theme.colors.onSecondary,
41
+ backgroundColor: theme.colors.secondary,
42
+ },
43
+ ]}
44
+ >
45
+ {items.length}
46
+ </RNBadge>
47
+ <Icon
48
+ containerColor={theme.colors.onPrimary}
49
+ mode={"contained"}
50
+ onPress={onPress}
51
+ size={22}
52
+ style={[theme.styles.noMargin]}
53
+ color={theme.colors.primary}
54
+ name={
55
+ items.length ? "material-notifications" : "material-notifications-none"
56
+ }
57
+ />
58
+ </Pressable>
59
+ );
60
+ }}
61
+ {...menuProps}
62
+ style={[styles.menu,menuProps.style]}
63
+ children={
64
+ <View {...containerProps} style={[styles.container,containerProps.style]} testID={`${testID}_Container`}>
65
+ {items.length ? (
66
+ <View
67
+ style={theme.styles.w100}
68
+ testID={testID + "_TiteleContainer"}
69
+ >
70
+ <HStack
71
+ testID={`${testID}_LabelContainer`}
72
+ style={[theme.styles.justifyContentSpaceBetween]}
73
+ >
74
+ {title !== false ? (
75
+ React.isValidElement(title)? title : <Label fontSize={17} textBold primary>
76
+ Notifications{meter.name||""}
77
+ </Label>
78
+ ) : null}
79
+ {clearAllButton !== false && (React.isValidElement(clearAllButton)? clearAllButton :
80
+ <Button
81
+ borderRadius={10}
82
+ style={[theme.styles.cursorPointer]}
83
+ title={`Effacer les ${items.length.formatNumber()} notifications?`}
84
+ error
85
+ upperCase={false}
86
+ mode="contained"
87
+ onPress={(event)=>{
88
+ if(typeof clearAll =="function"){
89
+ return clearAll({items,event});
90
+ }
91
+ }}
92
+ icon="delete"
93
+ >
94
+ Effacer tout
95
+ </Button>
96
+ ) || null}
97
+ <Label success textBold>
98
+ {items.length?.formatNumber()}
99
+ </Label>
100
+ </HStack>
101
+ <Divider style={[theme.styles.w100, theme.styles.mt1]} />
102
+ </View>
103
+ ) : null}
104
+ <View
105
+ testID={`${testID}_ListContainer`}
106
+ {...contentContainerProps}
107
+ style={[{ maxHeight: Math.max(height - 150, 230) },contentContainerProps.style]}
108
+ >
109
+ <List
110
+ items={items}
111
+ testID = {testID}
112
+ {...rest}
113
+ />
114
+ </View>
115
+ </View>
116
+ }
117
+ />
118
+ );
119
+ });
120
+
121
+ Notifications.displayName = "NotificationsComponents";
122
+
123
+ Notifications.propTypes = {
124
+ ...Object.assign({},List.propTypes), ///les props identiques au composant List
125
+ items : PropTypes.array.isRequired,//les items à afficher dans le menu
126
+ menuProps : Object.assign({},Menu.propTypes), //les props du composant menu
127
+ containerProps : PropTypes.object,
128
+ contentContainerProps : PropTypes.object, //les props du contentContainer, composant wrapper au composant List
129
+ title : PropTypes.oneOfType([
130
+ PropTypes.bool, //si false, alors le titre qui s'affiche lorsque le menu est ouvert ne sera pas rendu
131
+ PropTypes.ReactNode, //si un composant react alors il sera utilisé pour substituer le composant title par défaut
132
+ ]),
133
+ clearAllButton : PropTypes.oneOfType([
134
+ PropTypes.bool, //si false, alors le bouton clearAll ne sera pas affiché
135
+ PropTypes.ReactNode, //si un composant react alors il sera utilisé pour substituer le composant bouton par défaut
136
+ ])
137
+ }
138
+
139
+ const styles = StyleSheet.create({
140
+ container: {
141
+ minWidth: 300,
142
+ padding: 15,
143
+ },
144
+ anchor: {
145
+ position: "relative",
146
+ marginRight: 10,
147
+ marginTop: 10,
148
+ },
149
+ badge: {
150
+ position: "absolute",
151
+ top: -8,
152
+ right: -10,
153
+ zIndex: 1000,
154
+ },
155
+ menu: {
156
+ maxWidth: 300,
157
+ },
158
+ });
159
+
160
+ export default Notifications;