@fto-consult/expo-ui 2.10.5 → 2.11.1

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.
@@ -0,0 +1,51 @@
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
+ const fs = require("fs");
6
+ const path = require("path");
7
+ const dir = path.join(__dirname,"src","components","Countries","resources");
8
+ const countries = require(path.join(dir,"countries.json"));
9
+
10
+ const normalized = [];
11
+ const normalizedSQL = [];
12
+ const exportedCountries = [];
13
+
14
+ for(let i in countries){
15
+ const country = countries[i];
16
+ if(!country || !country.name || !country.iso2 || typeof country.iso2 !='string') continue;
17
+ const code = country.iso2.toUpperCase().trim();
18
+ const c = {
19
+ code,
20
+ name : country.name,
21
+ dialCode : country.dialCode,
22
+ };
23
+ exportedCountries.push({
24
+ ...country,
25
+ iso2 : code,
26
+ ...c,
27
+ })
28
+ normalized.push(c);
29
+ normalizedSQL.push("("+escapeQuotes(c.code)+","+escapeQuotes(c.name)+","+escapeQuotes(c.dialCode)+")")
30
+ }
31
+ writeFile(path.join(dir,"countries-normalized.json"),JSON.stringify(exportedCountries, null, 2))
32
+ writeFile(path.join(dir,"countries.sql"),"INSERT INTO countries(code,name,dialCode) \n\tVALUES \n\t\t"+normalizedSQL.join(",\n\t\t"))
33
+ writeFile(path.join(dir,"countries-with-not-extra.json"),JSON.stringify(normalized, null, 2))
34
+
35
+ function writeFile(path, contents, cb) {
36
+ const p = require('path').dirname(path);
37
+ if(!fs.existsSync(p)){
38
+ try {
39
+ fs.mkdirSync(p,{ recursive: true});
40
+ } catch(e){}
41
+ }
42
+ if(fs.existsSync(p)){
43
+ return fs.writeFileSync(path, contents, cb);
44
+ }
45
+ throw {message : 'impossible de créer le repertoire '+p};
46
+ }
47
+
48
+ function escapeQuotes (str){
49
+ if(!str || typeof str !='string') return "''";
50
+ return "'"+str.replace(/'/g, "\\'\\'")+"'";
51
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fto-consult/expo-ui",
3
- "version": "2.10.5",
3
+ "version": "2.11.1",
4
4
  "description": "Bibliothèque de composants UI Expo,react-native",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -65,8 +65,7 @@
65
65
  "@expo/metro-config": "^0.4.0",
66
66
  "@expo/vector-icons": "^13.0.0",
67
67
  "@expo/webpack-config": "^0.17.2",
68
- "@fto-consult/common": "^1.19.5",
69
- "@fto-consult/expo-ui": "^2.9.2",
68
+ "@fto-consult/common": "^1.19.8",
70
69
  "@gorhom/portal": "^1.0.14",
71
70
  "@react-native-async-storage/async-storage": "~1.17.3",
72
71
  "@react-native-community/datetimepicker": "6.5.2",
@@ -1,7 +1,6 @@
1
1
  import Fab from "$ecomponents/Fab";
2
2
  import {isObj,defaultStr,defaultVal,defaultObj} from "$utils";
3
3
  import React from "$react";
4
- import { StyleSheet } from 'react-native';
5
4
  import PropTypes from "prop-types";
6
5
 
7
6
  const SCREEN_INDENT = 20;
@@ -23,23 +22,21 @@ const BackToTopComponent = React.forwardRef((props,ref)=>{
23
22
  const isMounted = React.useIsMounted();
24
23
  const {onPress,accessibilityLabel,onBackToTop,onVisibilityChange,position,icon,...rProps} = props;
25
24
  const rest = defaultObj(rProps);
26
- const [state,setState] = React.useStateIfMounted({
27
- visible : false,
28
- });
25
+ const [visible,setVisible] = React.useState(false);
29
26
  const open = ()=>{
30
- if(!isMounted() || state.visible)return;
31
- setState({...state,visible:true});
27
+ if(!isMounted() || visible)return;
28
+ setVisible(true);
32
29
  }
33
30
  const close = ()=>{
34
- if(!isMounted() || !state.visible)return;
35
- setState({...state,visible:false});
31
+ if(!isMounted() || !visible)return;
32
+ setVisible(false);
36
33
  }
37
34
 
38
35
  const context = {open,close,
39
36
  toggleVisibility:(event)=>{
40
37
  if(!isMounted()) return;
41
38
  let v = toggleVisibility(event);
42
- if(typeof v =='boolean' && v !== state.visible){
39
+ if(typeof v =='boolean' && v !== visible){
43
40
  return v ? open() : close();
44
41
  }
45
42
  return undefined;
@@ -50,7 +47,7 @@ const BackToTopComponent = React.forwardRef((props,ref)=>{
50
47
  if(onVisibilityChange){
51
48
  onVisibilityChange({context,visible});
52
49
  }
53
- },[state.visible])
50
+ },[visible])
54
51
  const style = defaultStr(position).toLowerCase() =='right' ? {
55
52
  right: 0
56
53
  } : {left : 0};
@@ -58,7 +55,7 @@ const BackToTopComponent = React.forwardRef((props,ref)=>{
58
55
  React.useEffect(()=>{
59
56
  React.setRef(ref,context);
60
57
  },[])
61
- return !state.visible ? null : <Fab
58
+ return !visible ? null : <Fab
62
59
  {...rest}
63
60
  accessibilityLabel = {defaultStr(rest.accessibilityLabel,'Retour en haut')}
64
61
  onPress = {(e)=>{
@@ -0,0 +1,31 @@
1
+ import React from "$react";
2
+ import Image from "$components/Image";
3
+ import { getCountry,styles} from "./utils";
4
+ import {isNonNullString,defaultStr,isNumber} from "$utils";
5
+ import View from "$ecomponents/View"
6
+ import theme from "$theme";
7
+ import Label from "$components/Label";
8
+
9
+ export default function CountryFlagComponent({code,label,withName,withCode,text,containerProps,labelProps,withLabel,tesID,...props}){
10
+ if(!isNonNullString(code)) return null;
11
+ const country = getCountry(code);
12
+ tesID = defaultStr(tesID,"RN_CountryFlagComponent");
13
+ if(!country) return <Label tesID={tesID+"_NotFoundCode"}>{code}</Label>;
14
+ //console.log(country," is county");
15
+ containerProps = Object.assign({},containerProps);
16
+ labelProps = Object.assign({},labelProps);
17
+ return <View {...containerProps} testID={tesID} style={[theme.styles.row,containerProps.style]}>
18
+ {(isNonNullString(country.image) || isNumber(country.image)) ?
19
+ <Image
20
+ accessibilityIgnoresInvertColors
21
+ tesID ={tesID+"Image"}
22
+ {...props}
23
+ size = {25}
24
+ style={[props.style]}
25
+ src={country.image}
26
+ /> : null}
27
+ {<Label tesID={tesID+"_Label"} {...labelProps} style={[labelProps.style,{marginLeft:5}]}>
28
+ {withName || withLabel ? country.name : withCode ? country.code.toUpperCase() : null}
29
+ </Label>}
30
+ </View>
31
+ }
@@ -1,6 +1,6 @@
1
1
  import React from "$react";
2
2
  import SimpleSelect from "$ecomponents/SimpleSelect";
3
- import { countries } from "./utils";
3
+ import { countries,styles} from "./utils";
4
4
  import View from "$ecomponents/View";
5
5
  import {StyleSheet,Image} from "react-native";
6
6
  import {defaultObj} from "$utils";
@@ -15,9 +15,10 @@ export const getCountryFieldProps = (props)=>{
15
15
  let {imageProps,...rest} = props;
16
16
  imageProps = defaultObj(imageProps);
17
17
  return {
18
- text : 'Pays',
18
+ label : defaultStr(props.label,props.text,'Pays'),
19
19
  type : 'select',
20
20
  items : countries,
21
+ upper : true,
21
22
  dialogProps : {title:'Sélectionner un pays'},
22
23
  getItemValue : ({item})=>item.code,
23
24
  compare : (a,b)=>{
@@ -50,18 +51,6 @@ SelectCoutryComponent.propTypes = {
50
51
  imageProps : PropTypes.object, ///les props à appliquer aux images affichées
51
52
  }
52
53
 
53
- const styles = StyleSheet.create({
54
- renderedImage : {
55
- flexDirection : "row",
56
- alignItems : 'center',
57
- justifyContent : 'flex-start',
58
- flex : 1,
59
- },
60
- flagImage : {
61
- borderWidth:0,
62
- width : 30,
63
- height : 20,
64
- },
65
- })
54
+
66
55
 
67
56
 
@@ -2,4 +2,6 @@ export * from "./utils";
2
2
 
3
3
  export * from "./SelectCountry";
4
4
 
5
+ export {default as Flag} from "./Flag";
6
+
5
7
  export {default as SelectCountry} from "./SelectCountry";