etendo-ui-library 1.0.32 → 1.0.34

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.
Files changed (32) hide show
  1. package/components/dropdown/Dropdown.stories.tsx +64 -0
  2. package/components/dropdown/Dropdown.styles.tsx +67 -0
  3. package/components/dropdown/Dropdown.test.tsx +32 -0
  4. package/components/dropdown/Dropdown.tsx +70 -0
  5. package/components/dropdown/Dropdown.types.tsx +51 -0
  6. package/components/dropdown/DropdownItem.styles.tsx +42 -0
  7. package/components/dropdown/DropdownItem.test.tsx +22 -0
  8. package/components/dropdown/DropdownItem.tsx +37 -0
  9. package/components/dropdown/__snapshots__/Dropdown.test.tsx.snap +67 -0
  10. package/components/dropdown/__snapshots__/DropdownItem.test.tsx.snap +42 -0
  11. package/components/dropdown/index.ts +3 -0
  12. package/package.json +1 -1
  13. package/storybook-static/{0.af007743.iframe.bundle.js → 0.1350e4a7.iframe.bundle.js} +1 -1
  14. package/storybook-static/{4.05b37fe0.iframe.bundle.js → 4.7a917f47.iframe.bundle.js} +3 -3
  15. package/storybook-static/{4.05b37fe0.iframe.bundle.js.LICENSE.txt → 4.7a917f47.iframe.bundle.js.LICENSE.txt} +0 -0
  16. package/storybook-static/4.7a917f47.iframe.bundle.js.map +1 -0
  17. package/storybook-static/{5.e6214d22.iframe.bundle.js → 5.abca0041.iframe.bundle.js} +1 -1
  18. package/storybook-static/{6.edcb01df.iframe.bundle.js → 6.b577c2c6.iframe.bundle.js} +3 -3
  19. package/storybook-static/{6.edcb01df.iframe.bundle.js.LICENSE.txt → 6.b577c2c6.iframe.bundle.js.LICENSE.txt} +0 -0
  20. package/storybook-static/6.b577c2c6.iframe.bundle.js.map +1 -0
  21. package/storybook-static/{7.7b615c14.iframe.bundle.js → 7.8de0c89c.iframe.bundle.js} +1 -1
  22. package/storybook-static/iframe.html +1 -1
  23. package/storybook-static/main.6ec576c3.iframe.bundle.js +1 -0
  24. package/storybook-static/{runtime~main.bdbd9590.iframe.bundle.js → runtime~main.942fa453.iframe.bundle.js} +1 -1
  25. package/storybook-static/vendors~main.ffe8a230.iframe.bundle.js +3 -0
  26. package/storybook-static/{vendors~main.26d7e09c.iframe.bundle.js.LICENSE.txt → vendors~main.ffe8a230.iframe.bundle.js.LICENSE.txt} +0 -0
  27. package/storybook-static/vendors~main.ffe8a230.iframe.bundle.js.map +1 -0
  28. package/storybook-static/4.05b37fe0.iframe.bundle.js.map +0 -1
  29. package/storybook-static/6.edcb01df.iframe.bundle.js.map +0 -1
  30. package/storybook-static/main.9c767b6a.iframe.bundle.js +0 -1
  31. package/storybook-static/vendors~main.26d7e09c.iframe.bundle.js +0 -3
  32. package/storybook-static/vendors~main.26d7e09c.iframe.bundle.js.map +0 -1
@@ -0,0 +1,64 @@
1
+ import React from 'react';
2
+ import {Story, Meta} from '@storybook/react';
3
+
4
+ import Dropdown from './Dropdown';
5
+ import {NavbarProps} from '../navbar/Navbar.types';
6
+
7
+ export default {
8
+ title: 'Etendo/Dropdown',
9
+ component: Dropdown,
10
+ argTypes: {},
11
+ } as Meta<typeof Dropdown>;
12
+
13
+ const dataset = [
14
+ {name: 'User', route: '', key: 'user'},
15
+ {name: 'Vehicles', route: '', key: 'vehicles'},
16
+ {name: 'Skills', route: '', key: 'skills'},
17
+ {name: 'Mobile app', route: '', key: 'movilApp'},
18
+ {name: 'Staff', route: '', key: 'staff'},
19
+ {name: 'Routing options', route: '', key: 'routing options'},
20
+ {name: 'Map', route: '', key: 'map'},
21
+ ];
22
+
23
+ const onCheckSelectedMock = () => dataset[0];
24
+
25
+ /* Templates */
26
+ const Template: Story<NavbarProps> = () => (
27
+ <Dropdown
28
+ data={dataset}
29
+ onChangeSelected={onCheckSelectedMock}
30
+ text="Massive load"
31
+ style="primary"
32
+ typeSizeText="small"
33
+ />
34
+ );
35
+
36
+ const Template2: Story<NavbarProps> = () => (
37
+ <Dropdown
38
+ data={dataset}
39
+ onChangeSelected={onCheckSelectedMock}
40
+ text="New vehicle"
41
+ style="primary"
42
+ typeSizeText="medium"
43
+ />
44
+ );
45
+
46
+ const Template3: Story<NavbarProps> = () => (
47
+ <Dropdown
48
+ data={dataset}
49
+ onChangeSelected={onCheckSelectedMock}
50
+ text="Assets"
51
+ style="primary"
52
+ typeSizeText="large"
53
+ />
54
+ );
55
+
56
+ /* Story exports */
57
+ export const DropdownSmallText = Template.bind({});
58
+ DropdownSmallText.args = {};
59
+
60
+ export const DropdownMediumText = Template2.bind({});
61
+ DropdownMediumText.args = {};
62
+
63
+ export const DropdownLargeText = Template3.bind({});
64
+ DropdownLargeText.args = {};
@@ -0,0 +1,67 @@
1
+ /* Imports */
2
+ import {DropdownStyleRecord} from './Dropdown.types';
3
+ import {
4
+ BLUE,
5
+ GREY_BLUE,
6
+ GREY_5,
7
+ GREY_BLUE_50,
8
+ WHITE,
9
+ } from '../../styles/colors';
10
+
11
+ /* Export of different styles */
12
+ export const DropdownStyleVariant: DropdownStyleRecord = {
13
+ /* Primary style */
14
+ primary: {
15
+ container: {
16
+ width: '17%',
17
+ padding: 5,
18
+ },
19
+ dropDownButton: {
20
+ flex: 1,
21
+ backgroundColor: BLUE,
22
+ padding: 11,
23
+ borderRadius: 5,
24
+ flexDirection: 'row',
25
+ justifyContent: 'space-between',
26
+ alignItems: 'center',
27
+ zIndex: 10,
28
+ },
29
+ dropDownButtonText: {
30
+ color: WHITE,
31
+ fontSize: 18,
32
+ fontWeight: '500',
33
+ flex: 1,
34
+ textAlign: 'center',
35
+ },
36
+ iconWithOptionsDisplayed: {
37
+ width: 14,
38
+ height: 14,
39
+ tintColor: WHITE,
40
+ transform: [{rotate: '180deg'}],
41
+ },
42
+ iconWithOptionsNotDisplayed: {
43
+ width: 14,
44
+ height: 14,
45
+ tintColor: WHITE,
46
+ },
47
+ containerOptions: {
48
+ marginTop: 2,
49
+ borderWidth: 1,
50
+ borderColor: GREY_BLUE,
51
+ borderRadius: 3,
52
+ top: -6,
53
+ },
54
+ option: {
55
+ backgroundColor: GREY_5,
56
+ borderBottomWidth: 1.5,
57
+ borderBottomColor: GREY_BLUE_50,
58
+ justifyContent: 'center',
59
+ },
60
+ textOption: {
61
+ margin: 10,
62
+ // fontSize: 18,
63
+ textAlign: 'left',
64
+ fontWeight: '500',
65
+ },
66
+ },
67
+ };
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+ import Dropdown from './Dropdown';
4
+
5
+ const dataset = [
6
+ {name: 'User', route: '', key: 'user'},
7
+ {name: 'Vehicles', route: '', key: 'vehicles'},
8
+ {name: 'Skills', route: '', key: 'skills'},
9
+ {name: 'Mobile app', route: '', key: 'movilApp'},
10
+ {name: 'Staff', route: '', key: 'staff'},
11
+ {name: 'Routing options', route: '', key: 'routing options'},
12
+ {name: 'Map', route: '', key: 'map'},
13
+ ];
14
+
15
+ const onCheckSelectedMock = () => dataset[0];
16
+
17
+ describe('Running Test for Dropdown', () => {
18
+ it('Check Dropdown Disabled', () => {
19
+ const tree = renderer
20
+ .create(
21
+ <Dropdown
22
+ data={dataset}
23
+ onChangeSelected={onCheckSelectedMock}
24
+ text="Massive load"
25
+ style="primary"
26
+ typeSizeText="medium"
27
+ />,
28
+ )
29
+ .toJSON();
30
+ expect(tree).toMatchSnapshot();
31
+ });
32
+ });
@@ -0,0 +1,70 @@
1
+ import React, {useState} from 'react';
2
+ import {View, Text, TouchableOpacity, Image, ScrollView} from 'react-native';
3
+
4
+ import DropdownItem from './DropdownItem';
5
+ import {DropdownStyleVariant} from './Dropdown.styles';
6
+ import {DropdownProps, Info} from './Dropdown.types';
7
+
8
+ const Dropdown = ({
9
+ data,
10
+ onChangeSelected,
11
+ text,
12
+ typeSizeText,
13
+ }: DropdownProps) => {
14
+ const [showOptions, setShowOptions] = useState(false);
15
+ const [toggleItem, setToggleItem] = useState<number>(-1);
16
+
17
+ return (
18
+ <View style={DropdownStyleVariant.primary.container}>
19
+ <TouchableOpacity
20
+ style={DropdownStyleVariant.primary.dropDownButton}
21
+ activeOpacity={1}
22
+ onPress={() => setShowOptions(!showOptions)}
23
+ >
24
+ <Text style={DropdownStyleVariant.primary.dropDownButtonText}>
25
+ {text}
26
+ </Text>
27
+ {showOptions ? (
28
+ <Image
29
+ source={require('../../assets/images/icons/arrowPicker.png')}
30
+ style={DropdownStyleVariant.primary.iconWithOptionsDisplayed}
31
+ resizeMode="contain"
32
+ />
33
+ ) : (
34
+ <Image
35
+ source={require('../../assets/images/icons/arrowPicker.png')}
36
+ style={DropdownStyleVariant.primary.iconWithOptionsNotDisplayed}
37
+ resizeMode="contain"
38
+ />
39
+ )}
40
+ </TouchableOpacity>
41
+
42
+ {showOptions && (
43
+ <ScrollView style={DropdownStyleVariant.primary.containerOptions}>
44
+ {data.map((item: Info, index: number) => {
45
+ return (
46
+ <DropdownItem
47
+ item={item}
48
+ index={index}
49
+ onPress={() => {
50
+ /* Allows to detect the selected item */
51
+ setToggleItem(index);
52
+ onChangeSelected({
53
+ name: item.name,
54
+ route: item.route,
55
+ key: item.key,
56
+ });
57
+ }}
58
+ key={item.key}
59
+ toggleItem={toggleItem}
60
+ sizeText={typeSizeText}
61
+ />
62
+ );
63
+ })}
64
+ </ScrollView>
65
+ )}
66
+ </View>
67
+ );
68
+ };
69
+
70
+ export default Dropdown;
@@ -0,0 +1,51 @@
1
+ /* Imports */
2
+ import {ImageStyle, StyleProp, TextStyle, ViewStyle} from 'react-native';
3
+
4
+ /* Type declaration */
5
+ export type Info = {
6
+ name: string;
7
+ route: string;
8
+ key: string;
9
+ };
10
+
11
+ export interface DropdownProps {
12
+ data: Info[];
13
+ onChangeSelected: (Info: Info | undefined) => Info;
14
+ text: string;
15
+ style?: DropdownStyleType;
16
+ typeSizeText: DropdownStyleFontSize;
17
+ }
18
+
19
+ export interface DropdownItemProps {
20
+ item: Info;
21
+ onPress: () => void;
22
+ index: number;
23
+ toggleItem: number;
24
+ styleText?: DropdownStyleType;
25
+ sizeText: DropdownStyleFontSize;
26
+ }
27
+
28
+ /* Declaration of style types */
29
+ export type DropdownStyleType = 'primary';
30
+ export type DropdownStyleFontSize = 'small' | 'medium' | 'large';
31
+
32
+ export type DropdownStyleRecord = Record<
33
+ DropdownStyleType,
34
+ {
35
+ container: ViewStyle;
36
+ dropDownButton?: ViewStyle;
37
+ dropDownButtonText: TextStyle;
38
+ iconWithOptionsDisplayed: StyleProp<ImageStyle>;
39
+ iconWithOptionsNotDisplayed: StyleProp<ImageStyle>;
40
+ containerOptions: ViewStyle;
41
+ option: ViewStyle;
42
+ textOption: TextStyle;
43
+ }
44
+ >;
45
+
46
+ export type DropdownStyleText = Record<
47
+ DropdownStyleFontSize,
48
+ {
49
+ fontSize: TextStyle;
50
+ }
51
+ >;
@@ -0,0 +1,42 @@
1
+ import {DropdownStyleVariant} from './Dropdown.styles';
2
+ import {DropdownStyleFontSize} from './Dropdown.types';
3
+ import {GREY_5, YELLOW} from '../../styles/colors';
4
+
5
+ /* Styles - This function allows to obtain the text styles of the TabItem component */
6
+ export const getStyle = (toggleItem: number, index: number) => {
7
+ let colorActive: string = YELLOW;
8
+ let colorInactive: string = GREY_5;
9
+
10
+ if (index === toggleItem) {
11
+ return [
12
+ DropdownStyleVariant.primary.option,
13
+ {backgroundColor: colorActive},
14
+ ];
15
+ } else {
16
+ return [
17
+ DropdownStyleVariant.primary.option,
18
+ {backgroundColor: colorInactive},
19
+ ];
20
+ }
21
+ };
22
+
23
+ export const getSizeText = (sizeText: DropdownStyleFontSize) => {
24
+ let fontSize: number = 0;
25
+
26
+ /* Choice of text size based on the size chosen by the programmer */
27
+ switch (sizeText) {
28
+ case 'small':
29
+ fontSize = 14;
30
+ break;
31
+ case 'medium':
32
+ fontSize = 18;
33
+ break;
34
+ case 'large':
35
+ fontSize = 20;
36
+ break;
37
+ default:
38
+ break;
39
+ }
40
+
41
+ return fontSize;
42
+ };
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import renderer from 'react-test-renderer';
3
+ import DropdownItem from './DropdownItem';
4
+
5
+ const item = {name: 'User', route: '', key: 'user'};
6
+
7
+ describe('Running Test for DropdownItem', () => {
8
+ it('Check DropdownItem Disabled', () => {
9
+ const tree = renderer
10
+ .create(
11
+ <DropdownItem
12
+ item={item}
13
+ onPress={() => {}}
14
+ index={0}
15
+ toggleItem={0}
16
+ sizeText={'medium'}
17
+ />,
18
+ )
19
+ .toJSON();
20
+ expect(tree).toMatchSnapshot();
21
+ });
22
+ });
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import {Text, TouchableOpacity} from 'react-native';
3
+
4
+ import {DropdownStyleVariant} from './Dropdown.styles';
5
+ import {DropdownItemProps} from './Dropdown.types';
6
+ import {getSizeText, getStyle} from './DropdownItem.styles';
7
+
8
+ const DropdownItem = ({
9
+ item,
10
+ onPress,
11
+ index,
12
+ toggleItem,
13
+ sizeText,
14
+ }: DropdownItemProps) => {
15
+ return (
16
+ <TouchableOpacity
17
+ style={getStyle(toggleItem, index)}
18
+ onPress={() => {
19
+ onPress();
20
+ }}
21
+ key={item.key}
22
+ activeOpacity={1}
23
+ >
24
+ <Text
25
+ key={item.key}
26
+ style={[
27
+ {fontSize: getSizeText(sizeText)},
28
+ DropdownStyleVariant.primary.textOption,
29
+ ]}
30
+ >
31
+ {item.name}
32
+ </Text>
33
+ </TouchableOpacity>
34
+ );
35
+ };
36
+
37
+ export default DropdownItem;
@@ -0,0 +1,67 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Running Test for Dropdown Check Dropdown Disabled 1`] = `
4
+ <View
5
+ style={
6
+ Object {
7
+ "padding": 5,
8
+ "width": "17%",
9
+ }
10
+ }
11
+ >
12
+ <View
13
+ accessible={true}
14
+ collapsable={false}
15
+ focusable={true}
16
+ onClick={[Function]}
17
+ onResponderGrant={[Function]}
18
+ onResponderMove={[Function]}
19
+ onResponderRelease={[Function]}
20
+ onResponderTerminate={[Function]}
21
+ onResponderTerminationRequest={[Function]}
22
+ onStartShouldSetResponder={[Function]}
23
+ style={
24
+ Object {
25
+ "alignItems": "center",
26
+ "backgroundColor": "#202452",
27
+ "borderRadius": 5,
28
+ "flex": 1,
29
+ "flexDirection": "row",
30
+ "justifyContent": "space-between",
31
+ "opacity": 1,
32
+ "padding": 11,
33
+ "zIndex": 10,
34
+ }
35
+ }
36
+ >
37
+ <Text
38
+ style={
39
+ Object {
40
+ "color": "#FFFFFF",
41
+ "flex": 1,
42
+ "fontSize": 18,
43
+ "fontWeight": "500",
44
+ "textAlign": "center",
45
+ }
46
+ }
47
+ >
48
+ Massive load
49
+ </Text>
50
+ <Image
51
+ resizeMode="contain"
52
+ source={
53
+ Object {
54
+ "testUri": "../../../assets/images/icons/arrowPicker.png",
55
+ }
56
+ }
57
+ style={
58
+ Object {
59
+ "height": 14,
60
+ "tintColor": "#FFFFFF",
61
+ "width": 14,
62
+ }
63
+ }
64
+ />
65
+ </View>
66
+ </View>
67
+ `;
@@ -0,0 +1,42 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Running Test for DropdownItem Check DropdownItem Disabled 1`] = `
4
+ <View
5
+ accessible={true}
6
+ collapsable={false}
7
+ focusable={true}
8
+ onClick={[Function]}
9
+ onResponderGrant={[Function]}
10
+ onResponderMove={[Function]}
11
+ onResponderRelease={[Function]}
12
+ onResponderTerminate={[Function]}
13
+ onResponderTerminationRequest={[Function]}
14
+ onStartShouldSetResponder={[Function]}
15
+ style={
16
+ Object {
17
+ "backgroundColor": "#FAD614",
18
+ "borderBottomColor": "#D3D6E1",
19
+ "borderBottomWidth": 1.5,
20
+ "justifyContent": "center",
21
+ "opacity": 1,
22
+ }
23
+ }
24
+ >
25
+ <Text
26
+ style={
27
+ Array [
28
+ Object {
29
+ "fontSize": 18,
30
+ },
31
+ Object {
32
+ "fontWeight": "500",
33
+ "margin": 10,
34
+ "textAlign": "left",
35
+ },
36
+ ]
37
+ }
38
+ >
39
+ User
40
+ </Text>
41
+ </View>
42
+ `;
@@ -0,0 +1,3 @@
1
+ import Dropdown from './Dropdown';
2
+
3
+ export {Dropdown};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "etendo-ui-library",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "android": "react-native run-android",