@fto-consult/expo-ui 1.4.9 → 1.4.11

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": "1.4.9",
3
+ "version": "1.4.11",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -61,7 +61,7 @@
61
61
  "@expo/html-elements": "^0.2.0",
62
62
  "@expo/metro-config": "^0.4.0",
63
63
  "@expo/webpack-config": "^0.17.2",
64
- "@fto-consult/common": "^1.7.7",
64
+ "@fto-consult/common": "^1.7.10",
65
65
  "@gorhom/portal": "^1.0.14",
66
66
  "@react-native-async-storage/async-storage": "~1.17.3",
67
67
  "@react-native-community/datetimepicker": "6.2.0",
package/src/auth/Login.js CHANGED
@@ -18,6 +18,7 @@ import {Provider as DialogProvider} from "$ecomponents/Dialog";
18
18
  import ScreenWithoutAuthContainer from "$escreen/ScreenWithoutAuthContainer";
19
19
  import {getTitle} from "$escreens/Auth/utils";
20
20
  import {isWeb} from "$cplatform";
21
+ import ProviderSelector from "./ProviderSelector";
21
22
 
22
23
  import getLoginProps from "$getLoginProps";
23
24
  const getProps = typeof getLoginProps =='function'? getLoginProps : x=>null;
@@ -97,6 +98,7 @@ export default function LoginComponent(props){
97
98
  focusField,
98
99
  formName,
99
100
  nextButtonRef,
101
+ ProviderSelector,
100
102
  previousButtonRef,
101
103
  }));
102
104
  React.useEffect(()=>{
@@ -0,0 +1,75 @@
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
+ import Button from "$components/Button";
5
+ import Menu from "$components/Menu";
6
+ import theme from "$theme";
7
+ import React from "$react";
8
+ import {isObj,defaultStr,defaultObj} from "$utils";
9
+ import PropTypes from "prop-types";
10
+ import View from "$components/View";
11
+
12
+ /****le selecteur de provider, pour l'authentification */
13
+ const ProviderSelector = React.forwardRef(({providers,anchorProps,containerProps,anchor,activeProvider,testID,onChange,...props},ref)=>{
14
+ activeProvider = defaultObj(activeProvider);
15
+ containerProps = defaultObj(containerProps);
16
+ anchorProps = defaultObj(anchorProps);
17
+ testID = defaultStr(testID,"RN_AuthProviderSelectorComponent");
18
+ const menuItems = [];
19
+ Object.map(providers,(provider)=>{
20
+ if(!isObj(provider) || !provider.id) return;
21
+ provider.icon = activeProvider.id == provider.id ? "check":null;
22
+ provider.onPress = ()=>{
23
+ if(activeProvider.id === provider.id) return;
24
+ activeProvider = provider;
25
+ if(typeof onChange =='function'){
26
+ onChange(provider);
27
+ }
28
+ }
29
+ menuItems.push(provider);
30
+ });
31
+ const desc = activeProvider.desc || "";
32
+ const btnLabel = "Se connecter avec "+(activeProvider.id ? ( "["+activeProvider.label+"]") : "");
33
+ return <View testID={testID+"_Container"} {...containerProps} style={[{maxWidth:'100%'},containerProps.style]}>
34
+ <Menu
35
+ ref = {ref}
36
+ sameWidth
37
+ {...props}
38
+ style = {[{maxWidth:'90%'},props.style]}
39
+ items = {menuItems}
40
+ testID = {testID}
41
+ anchor = {typeof anchor =='function'? (p)=>{
42
+ return anchor({...p,activeProvider});
43
+ } : (p)=>{
44
+ return <Button upperCase={false} testID={testID+"_Anchor"}
45
+ secondary
46
+ mode={"contained"}
47
+ borderRadius={10}
48
+ {...p}
49
+ {...anchorProps}
50
+ style = {[p.style,theme.styles.mv1,theme.styles.p05,anchorProps.style]}
51
+ contentStyle={[
52
+ p.contentStyle,{overflow: 'hidden',textOverflow: 'ellipsis'},
53
+ anchorProps.contentStyle
54
+ ]}
55
+ title = {btnLabel+(desc?(", "+desc):"")}
56
+ labelProps = {{splitText:true}}
57
+
58
+ >
59
+ {btnLabel}
60
+ </Button>
61
+ }}
62
+ />
63
+ </View>
64
+ })
65
+
66
+ ProviderSelector.displayName = "ProviderSelector";
67
+ ProviderSelector.propTypes = {
68
+ activeProvider : PropTypes.object,
69
+ providers : PropTypes.oneOfType([
70
+ PropTypes.arrayOf(PropTypes.object),
71
+ PropTypes.objectOf(PropTypes.object)
72
+ ])
73
+ }
74
+
75
+ export default ProviderSelector;
@@ -6,6 +6,8 @@ import React from "react";
6
6
  import Text from "./Text";
7
7
  import theme from "$theme";
8
8
  import AvatarImage from "./Image";
9
+ import { Pressable } from "react-native";
10
+ import Tooltip from "$components/Tooltip";
9
11
 
10
12
  const defaultSize = 40;
11
13
 
@@ -17,10 +19,11 @@ const defaultSize = 40;
17
19
  */
18
20
  const AvatarComponent = React.forwardRef((props,ref)=>{
19
21
  let Component = undefined;
20
- let {image,icon,testID,color,src,useSuffix,suffix,size,children,label,source,text,...rest} = props;
22
+ let {image,icon,testID,color,title,toolip,src,onPress,containerProps,useSuffix,suffix,size,children,label,source,text,...rest} = props;
21
23
  label = defaultVal(label,text,children);
22
24
  if(typeof label =='number') label = label+"";
23
25
  rest = defaultObj(rest);
26
+ containerProps = defaultObj(containerProps);
24
27
  size = defaultDecimal(size,defaultSize)
25
28
  let cProps = {size};
26
29
  if(source || image || src){
@@ -52,14 +55,16 @@ const AvatarComponent = React.forwardRef((props,ref)=>{
52
55
  style.backgroundColor = color;
53
56
  style.color = Colors.getContrast(color);
54
57
  }
55
- return <Component
56
- {...rest}
57
- {...cProps}
58
- ref={ref}
59
- testID = {defaultStr(testID,"RN_AvatarComponent")}
60
- style = {style}
61
- size= {size}
62
- />
58
+ const c = <Component
59
+ {...rest}
60
+ {...cProps}
61
+ ref={ref}
62
+ title = {onPress?null : defaultVal(toolip,title)}
63
+ testID = {defaultStr(testID,"RN_AvatarComponent")}
64
+ style = {style}
65
+ size= {size}
66
+ />;
67
+ return onPress ? <Tooltip title={title} toolip={toolip} Component = {Pressable} testID={testID+"_Container"} {...containerProps} onPress={onPress}>{c}</Tooltip> : c;
63
68
  });
64
69
 
65
70
  AvatarComponent.displayName = "AvatarComponent";
@@ -68,6 +68,7 @@ const SimpleSelect = React.forwardRef((props,ref)=>{
68
68
  return React.getTextContent(content);
69
69
  }
70
70
  const prevMenuItems = React.usePrevious(menuItems,stableHash);
71
+ const areItemsEquals = prevMenuItems == menuItems;//JSON.stringify(prevMenuItems) == JSON.stringify(menuItems);
71
72
  const prepareItems = React.useCallback(()=>{
72
73
  const items = [];
73
74
  selectedRef.current = null;
@@ -108,8 +109,8 @@ const SimpleSelect = React.forwardRef((props,ref)=>{
108
109
  setState({...state,value:currentSelectedValue,items});
109
110
  },[stableHash(menuItems)])
110
111
  React.useEffect(()=>{
111
- if(defaultValue == value && menuItems == prevMenuItems) return;
112
- if(menuItems != prevMenuItems){
112
+ if(compare(defaultValue == value) && areItemsEquals) return;
113
+ if(!areItemsEquals){
113
114
  prepareItems();
114
115
  } else {
115
116
  selectValue(defaultValue);
@@ -133,7 +134,7 @@ const SimpleSelect = React.forwardRef((props,ref)=>{
133
134
  context.getValue = ()=> value;
134
135
 
135
136
  React.useEffect(()=>{
136
- if((value !== undefined || prevValue !== undefined) && compare(value,prevValue)) return;
137
+ if(compare(value,prevValue)) return;
137
138
  if(onChange){
138
139
  onChange(defaultObj(selectedRef.current));
139
140
  }