@janiscommerce/ui-native 1.1.1 → 1.2.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/dist/components/BaseButton/index.d.ts +16 -0
- package/dist/components/BaseButton/index.js +51 -0
- package/dist/components/Icon/index.d.ts +1 -0
- package/dist/components/Input/index.js +0 -1
- package/dist/components/List/index.d.ts +20 -0
- package/dist/components/List/index.js +16 -0
- package/dist/components/ProgressBar/index.d.ts +11 -0
- package/dist/components/ProgressBar/index.js +53 -0
- package/dist/components/ProgressBar/utils/index.d.ts +20 -0
- package/dist/components/ProgressBar/utils/index.js +52 -0
- package/dist/components/Select/index.js +0 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/package.json +6 -4
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { PressableProps, ViewStyle } from 'react-native';
|
|
3
|
+
interface BaseButtonProps extends PressableProps {
|
|
4
|
+
title?: string | null;
|
|
5
|
+
icon?: string;
|
|
6
|
+
iconRight?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
borderRadius?: number;
|
|
9
|
+
pressedColor?: string;
|
|
10
|
+
style?: ViewStyle;
|
|
11
|
+
iconStyle?: ViewStyle;
|
|
12
|
+
textStyle?: ViewStyle;
|
|
13
|
+
children?: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
declare const BaseButton: FC<BaseButtonProps>;
|
|
16
|
+
export default BaseButton;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Pressable, StyleSheet } from 'react-native';
|
|
3
|
+
import { palette } from '../../theme/palette';
|
|
4
|
+
import Text from '../Text';
|
|
5
|
+
import Icon from '../Icon';
|
|
6
|
+
const BaseButton = ({ title = null, icon = null, iconRight = false, disabled = false, borderRadius = 0, pressedColor, style, iconStyle, textStyle, children = null, ...props }) => {
|
|
7
|
+
if (!title && !icon && !children) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const bgColor = !disabled ? palette.primary.main : palette.grey[200];
|
|
11
|
+
const iconPaddingLeft = iconRight && title ? 8 : 0;
|
|
12
|
+
const iconPaddingRight = !iconRight && title ? 8 : 0;
|
|
13
|
+
const styles = StyleSheet.create({
|
|
14
|
+
container: {
|
|
15
|
+
display: 'flex',
|
|
16
|
+
flexDirection: 'row',
|
|
17
|
+
alignItems: 'center',
|
|
18
|
+
justifyContent: 'center',
|
|
19
|
+
paddingHorizontal: 16,
|
|
20
|
+
paddingVertical: 10,
|
|
21
|
+
borderRadius,
|
|
22
|
+
backgroundColor: bgColor,
|
|
23
|
+
},
|
|
24
|
+
icon: {
|
|
25
|
+
color: palette.base.white,
|
|
26
|
+
paddingRight: iconPaddingRight,
|
|
27
|
+
paddingLeft: iconPaddingLeft,
|
|
28
|
+
},
|
|
29
|
+
title: {
|
|
30
|
+
fontSize: 14,
|
|
31
|
+
fontWeight: '500',
|
|
32
|
+
textAlign: 'center',
|
|
33
|
+
color: palette.base.white,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
const noChildren = () => (<>
|
|
37
|
+
{icon && !iconRight && <Icon name={icon} style={[styles.icon, iconStyle]} size={24}/>}
|
|
38
|
+
{title && <Text style={[styles.title, textStyle]}>{title}</Text>}
|
|
39
|
+
{icon && iconRight && <Icon name={icon} style={[styles.icon, iconStyle]} size={24}/>}
|
|
40
|
+
</>);
|
|
41
|
+
/* istanbul ignore next */
|
|
42
|
+
const PressableStyle = ({ pressed }) => {
|
|
43
|
+
const backgroundColor = pressedColor ?? palette.primary.dark;
|
|
44
|
+
const pressedBgColor = pressed ? [{ backgroundColor }] : [];
|
|
45
|
+
return [styles.container, style, ...pressedBgColor];
|
|
46
|
+
};
|
|
47
|
+
return (<Pressable style={PressableStyle} disabled={disabled} {...props}>
|
|
48
|
+
{children ?? noChildren}
|
|
49
|
+
</Pressable>);
|
|
50
|
+
};
|
|
51
|
+
export default BaseButton;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import { TextInput, StyleSheet, View, Text, } from 'react-native';
|
|
3
3
|
import { getBorderColor, getInputInitialState, getLabelColor, getStatusMessageColor, raiseLabel, showStatusMessage, } from './utils';
|
|
4
|
-
// eslint-disable-next-line no-shadow
|
|
5
4
|
export var keyboardTypes;
|
|
6
5
|
(function (keyboardTypes) {
|
|
7
6
|
keyboardTypes["default"] = "default";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { FlatListProps, ScrollViewProps } from 'react-native';
|
|
3
|
+
type TypeData = string | number | object | [] | React.ReactElement;
|
|
4
|
+
type RCProps = {
|
|
5
|
+
item: TypeData;
|
|
6
|
+
index: number;
|
|
7
|
+
};
|
|
8
|
+
type TypeRenderComponent = ({ item, index }: RCProps) => React.ReactElement;
|
|
9
|
+
export declare enum TypeList {
|
|
10
|
+
FlatList = "flatList",
|
|
11
|
+
ScrollView = "scrollView"
|
|
12
|
+
}
|
|
13
|
+
interface ListProps {
|
|
14
|
+
data: TypeData[] | undefined;
|
|
15
|
+
renderComponent: TypeRenderComponent;
|
|
16
|
+
type?: TypeList;
|
|
17
|
+
}
|
|
18
|
+
type MergedProps = ListProps & (FlatListProps<TypeData> | ScrollViewProps);
|
|
19
|
+
declare const List: FC<MergedProps>;
|
|
20
|
+
export default List;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FlatList, ScrollView } from 'react-native';
|
|
3
|
+
export var TypeList;
|
|
4
|
+
(function (TypeList) {
|
|
5
|
+
TypeList["FlatList"] = "flatList";
|
|
6
|
+
TypeList["ScrollView"] = "scrollView";
|
|
7
|
+
})(TypeList || (TypeList = {}));
|
|
8
|
+
const List = ({ data, renderComponent, type = TypeList.FlatList, ...props }) => {
|
|
9
|
+
if (!data?.length) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const FlatListComponent = () => <FlatList data={data} renderItem={renderComponent} {...props}/>;
|
|
13
|
+
const ScrollViewComponent = () => (<ScrollView {...props}>{data.map((item, index) => renderComponent({ item, index }))}</ScrollView>);
|
|
14
|
+
return type === TypeList.FlatList ? <FlatListComponent /> : <ScrollViewComponent />;
|
|
15
|
+
};
|
|
16
|
+
export default List;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { ViewStyle } from 'react-native';
|
|
3
|
+
interface ProgressBarProps {
|
|
4
|
+
value: number;
|
|
5
|
+
totalValue: number;
|
|
6
|
+
isAnimated?: boolean;
|
|
7
|
+
duration?: number;
|
|
8
|
+
style?: ViewStyle;
|
|
9
|
+
}
|
|
10
|
+
declare const ProgressBar: FC<ProgressBarProps>;
|
|
11
|
+
export default ProgressBar;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import { View, StyleSheet, Animated, Easing } from 'react-native';
|
|
3
|
+
import { palette } from '../../theme/palette';
|
|
4
|
+
import { getBarColor, getPercentage } from './utils';
|
|
5
|
+
const ProgressBar = ({ value, totalValue, isAnimated = false, duration = 300, style, ...props }) => {
|
|
6
|
+
const { white } = palette;
|
|
7
|
+
const widthAnimation = useRef(new Animated.Value(0)).current;
|
|
8
|
+
const availableTimeDuration = isAnimated && typeof duration === 'number';
|
|
9
|
+
const timeDuration = availableTimeDuration ? duration : 0;
|
|
10
|
+
const percentValue = getPercentage(value, totalValue);
|
|
11
|
+
const colorValue = getBarColor(percentValue);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (isAnimated) {
|
|
14
|
+
Animated.timing(widthAnimation, {
|
|
15
|
+
toValue: percentValue,
|
|
16
|
+
duration: timeDuration,
|
|
17
|
+
easing: Easing.linear,
|
|
18
|
+
useNativeDriver: false,
|
|
19
|
+
}).start();
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
widthAnimation.setValue(percentValue);
|
|
23
|
+
}
|
|
24
|
+
}, [isAnimated, percentValue, timeDuration, widthAnimation]);
|
|
25
|
+
const styles = StyleSheet.create({
|
|
26
|
+
container: {
|
|
27
|
+
position: 'relative',
|
|
28
|
+
width: '100%',
|
|
29
|
+
height: 4,
|
|
30
|
+
marginTop: 12,
|
|
31
|
+
borderRadius: 2,
|
|
32
|
+
backgroundColor: white.main,
|
|
33
|
+
},
|
|
34
|
+
fill: {
|
|
35
|
+
position: 'absolute',
|
|
36
|
+
left: 0,
|
|
37
|
+
height: 4,
|
|
38
|
+
borderRadius: 2,
|
|
39
|
+
zIndex: 10,
|
|
40
|
+
backgroundColor: colorValue,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
const animationProgress = {
|
|
44
|
+
width: widthAnimation.interpolate({
|
|
45
|
+
inputRange: [0, 100],
|
|
46
|
+
outputRange: ['0%', '100%'],
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
return (<View style={[styles.container, style]} {...props}>
|
|
50
|
+
<Animated.View style={[styles.fill, animationProgress]}/>
|
|
51
|
+
</View>);
|
|
52
|
+
};
|
|
53
|
+
export default ProgressBar;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @name getPercentage
|
|
3
|
+
* @description return the percentage form a partial value and a total value,
|
|
4
|
+
* rounded to the nearest integer
|
|
5
|
+
* @param {number} value the partial value
|
|
6
|
+
* @param {number} totalValue the total value
|
|
7
|
+
* @returns {number|null} the percentage in the range 0-100, or null if receives an invalid param
|
|
8
|
+
* @example getPercentage(45,100) // 45
|
|
9
|
+
* @example getPercentage(22,150) // 15
|
|
10
|
+
*/
|
|
11
|
+
export declare const getPercentage: (value: number, totalValue: number) => number;
|
|
12
|
+
/**
|
|
13
|
+
* @name getBarColor
|
|
14
|
+
* @description Devuelve una función que recibe un objeto con un campo "percentage" y devuelve el color de la barra correcto
|
|
15
|
+
* considerando los diferentes umbrales (25, 50 y 75).
|
|
16
|
+
* @returns {Function} - Una función que recibe un objeto con un campo "percentage" y devuelve el color de la barra correcto.
|
|
17
|
+
* @example getBarColor(30) // '#FF8D10' (naranja)
|
|
18
|
+
* @example getBarColor(90) // '#1DB779' (verde)
|
|
19
|
+
*/
|
|
20
|
+
export declare const getBarColor: (percentage: number) => string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { palette } from '../../../theme/palette';
|
|
2
|
+
const THRESHOLD = {
|
|
3
|
+
warning: 25,
|
|
4
|
+
alert: 50,
|
|
5
|
+
success: 75,
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* @name getPercentage
|
|
9
|
+
* @description return the percentage form a partial value and a total value,
|
|
10
|
+
* rounded to the nearest integer
|
|
11
|
+
* @param {number} value the partial value
|
|
12
|
+
* @param {number} totalValue the total value
|
|
13
|
+
* @returns {number|null} the percentage in the range 0-100, or null if receives an invalid param
|
|
14
|
+
* @example getPercentage(45,100) // 45
|
|
15
|
+
* @example getPercentage(22,150) // 15
|
|
16
|
+
*/
|
|
17
|
+
export const getPercentage = (value, totalValue) => {
|
|
18
|
+
if (typeof totalValue !== 'number' || typeof value !== 'number' || totalValue < 0 || value < 0) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
if (value >= totalValue) {
|
|
22
|
+
return totalValue;
|
|
23
|
+
}
|
|
24
|
+
return Math.round(100 * (value / totalValue));
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @name getBarColor
|
|
28
|
+
* @description Devuelve una función que recibe un objeto con un campo "percentage" y devuelve el color de la barra correcto
|
|
29
|
+
* considerando los diferentes umbrales (25, 50 y 75).
|
|
30
|
+
* @returns {Function} - Una función que recibe un objeto con un campo "percentage" y devuelve el color de la barra correcto.
|
|
31
|
+
* @example getBarColor(30) // '#FF8D10' (naranja)
|
|
32
|
+
* @example getBarColor(90) // '#1DB779' (verde)
|
|
33
|
+
*/
|
|
34
|
+
export const getBarColor = (percentage) => {
|
|
35
|
+
if (typeof percentage !== 'number') {
|
|
36
|
+
return palette.white.main;
|
|
37
|
+
}
|
|
38
|
+
let barColor = '';
|
|
39
|
+
if (percentage >= THRESHOLD.success) {
|
|
40
|
+
barColor = palette.success.main;
|
|
41
|
+
}
|
|
42
|
+
else if (percentage >= THRESHOLD.alert) {
|
|
43
|
+
barColor = palette.alert.main;
|
|
44
|
+
}
|
|
45
|
+
else if (percentage >= THRESHOLD.warning) {
|
|
46
|
+
barColor = palette.warning.main;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
barColor = palette.error.main;
|
|
50
|
+
}
|
|
51
|
+
return barColor;
|
|
52
|
+
};
|
|
@@ -5,7 +5,6 @@ import { formatPlaceholderMulti } from './utils';
|
|
|
5
5
|
import ChevronIcon from './Components/Icons/Chevron';
|
|
6
6
|
import DeleteIcon from './Components/Icons/Delete';
|
|
7
7
|
import Dropdown from './Components/Dropdown';
|
|
8
|
-
// eslint-disable-next-line no-shadow
|
|
9
8
|
var KeyboardTypes;
|
|
10
9
|
(function (KeyboardTypes) {
|
|
11
10
|
KeyboardTypes["Default"] = "default";
|
package/dist/index.d.ts
CHANGED
|
@@ -14,4 +14,7 @@ import RadioButton from './components/RadioButton';
|
|
|
14
14
|
import SwipeUp from './components/SwipeUp';
|
|
15
15
|
import { SwipeUpFlatList, SwipeUpScrollView, SwipeUpView } from './components/SwipeUp/childComponents';
|
|
16
16
|
import Carousel from './components/Carousel';
|
|
17
|
-
|
|
17
|
+
import ProgressBar from './components/ProgressBar';
|
|
18
|
+
import List from './components/List';
|
|
19
|
+
import BaseButton from './components/BaseButton';
|
|
20
|
+
export { Text, Avatar, CheckBox, Icon, Image, Loading, Svg, StatusChip, Input, palette, LoadingFullScreen, RadioButton, Select, SwipeUp, SwipeUpFlatList, SwipeUpScrollView, SwipeUpView, Carousel, ProgressBar, List, BaseButton, };
|
package/dist/index.js
CHANGED
|
@@ -14,4 +14,7 @@ import RadioButton from './components/RadioButton';
|
|
|
14
14
|
import SwipeUp from './components/SwipeUp';
|
|
15
15
|
import { SwipeUpFlatList, SwipeUpScrollView, SwipeUpView, } from './components/SwipeUp/childComponents';
|
|
16
16
|
import Carousel from './components/Carousel';
|
|
17
|
-
|
|
17
|
+
import ProgressBar from './components/ProgressBar';
|
|
18
|
+
import List from './components/List';
|
|
19
|
+
import BaseButton from './components/BaseButton';
|
|
20
|
+
export { Text, Avatar, CheckBox, Icon, Image, Loading, Svg, StatusChip, Input, palette, LoadingFullScreen, RadioButton, Select, SwipeUp, SwipeUpFlatList, SwipeUpScrollView, SwipeUpView, Carousel, ProgressBar, List, BaseButton, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@janiscommerce/ui-native",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "components library for Janis app",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"android": "
|
|
12
|
-
"ios": "
|
|
11
|
+
"android": "node scripts/set-app-mode.js app && react-native run-android",
|
|
12
|
+
"ios": "node scripts/set-app-mode.js app && react-native run-ios",
|
|
13
|
+
"storybook:android": "node scripts/set-app-mode.js storybook && sb-rn-get-stories --config-path .ondevice && react-native run-android",
|
|
14
|
+
"storybook:ios": "node scripts/set-app-mode.js storybook && sb-rn-get-stories --config-path .ondevice && react-native run-ios",
|
|
13
15
|
"start": "react-native start",
|
|
14
16
|
"test": "jest",
|
|
15
17
|
"lint": "eslint .",
|
|
@@ -18,7 +20,7 @@
|
|
|
18
20
|
"test:commit": "jest --colors --bail --findRelatedTests",
|
|
19
21
|
"test:coverage": "tsc --noEmit && jest --collectCoverage --detectOpenHandles",
|
|
20
22
|
"build": "rm -rf dist && tsc && cp -r android ios dist",
|
|
21
|
-
"storybook": "react-native-storybook-server",
|
|
23
|
+
"storybook-server": "react-native-storybook-server",
|
|
22
24
|
"storybook-watcher": "sb-rn-watcher --config-path .ondevice",
|
|
23
25
|
"update-stories": "sb-rn-get-stories --config-path .ondevice",
|
|
24
26
|
"storybook-web": " npm run storybook-web-build && start-storybook -p 6006 --config-dir ./.storybook",
|