diff --git a/.ondevice/storybook.requires.js b/.ondevice/storybook.requires.js index 59b7e1d..d808394 100644 --- a/.ondevice/storybook.requires.js +++ b/.ondevice/storybook.requires.js @@ -48,7 +48,7 @@ try { const getStories = () => { return { './storybook/stories/Avatar/Avatar.stories.js': require('../storybook/stories/Avatar/Avatar.stories.js'), - './storybook/stories/BaseButton/BaseButton.stories.js': require('../storybook/stories/BaseButton/BaseButton.stories.js'), + './storybook/stories/Button/Button.stories.js': require('../storybook/stories/Button/Button.stories.js'), './storybook/stories/Carousel/Carousel.stories.js': require('../storybook/stories/Carousel/Carousel.stories.js'), './storybook/stories/CheckBox/CheckBox.stories.js': require('../storybook/stories/CheckBox/CheckBox.stories.js'), './storybook/stories/DesignStystem/Colors.stories.js': require('../storybook/stories/DesignStystem/Colors.stories.js'), diff --git a/.storybook/preview-head.html b/.storybook/preview-head.html index 2b28e9d..22ea202 100644 --- a/.storybook/preview-head.html +++ b/.storybook/preview-head.html @@ -15,6 +15,11 @@ font-style: normal; font-weight: normal; } + + #story--components-button--camera-button-props svg { + stroke: #2979FF; + overflow: visible; + } diff --git a/env.json b/env.json index 4e60c2c..f1e5770 100644 --- a/env.json +++ b/env.json @@ -1 +1 @@ -{"LOAD_STORYBOOK": true, "WEB_MODE": false} \ No newline at end of file +{"LOAD_STORYBOOK": false, "WEB_MODE": false} \ No newline at end of file diff --git a/src/components/BaseButton/index.test.tsx b/src/components/BaseButton/index.test.tsx index 0806874..565f4b5 100644 --- a/src/components/BaseButton/index.test.tsx +++ b/src/components/BaseButton/index.test.tsx @@ -1,19 +1,15 @@ import React from 'react'; import {create} from 'react-test-renderer'; -import {Text, View} from 'react-native'; -import {palette} from '../../theme/palette'; +import {View, Text} from 'react-native'; import BaseButton from './'; const validData = { - title: 'test title', - icon: 'plus_circle', - iconRight: true, - disabled: true, borderRadius: 15, - pressedColor: palette.success.main, - style: {backgroundColor: palette.black.main}, - iconStyle: {backgroundColor: palette.black.main}, - textStyle: {color: palette.black.main}, + children: ( + + Button + + ), }; describe('BaseButton Component', () => { @@ -24,56 +20,12 @@ describe('BaseButton Component', () => { }); }); - describe('render correctly when has minimum props needed, example', () => { - it('title', () => { - const {toJSON} = create(); - expect(toJSON()).toBeTruthy(); - }); - - it('icon', () => { - const {toJSON} = create(); - expect(toJSON()).toBeTruthy(); - }); - - it('children', () => { - const {toJSON} = create( - - - Valid Children - - - ); - expect(toJSON()).toBeTruthy(); - }); - }); - - describe('Icon', () => { - it('is renders right icon when iconRight prop is true', () => { - const {toJSON} = create( - - ); - expect(toJSON()).toBeTruthy(); - }); - - it('is renders left icon when iconRight prop is not passed', () => { - const {toJSON} = create(); - expect(toJSON()).toBeTruthy(); - }); - }); - - describe('pressedColor', () => { - it('it changes when pressedColor props is an string color format', () => { - const {toJSON} = create( - + describe('render correctly when has minimum props needed', () => { + it('when hasnt minimum props needed', () => { + const {root} = create( + {validData.children} ); - expect(toJSON()).toBeTruthy(); - }); - }); - - describe('is disabled', () => { - it('when disabled props is true', () => { - const {toJSON} = create(); - expect(toJSON()).toBeTruthy(); + expect(root).toBeTruthy(); }); }); }); diff --git a/src/components/BaseButton/index.tsx b/src/components/BaseButton/index.tsx index 8472ab5..9fdc1b3 100644 --- a/src/components/BaseButton/index.tsx +++ b/src/components/BaseButton/index.tsx @@ -1,98 +1,44 @@ -import React, {FC} from 'react'; -import {Pressable, PressableProps, ViewStyle, StyleSheet, TextStyle} from 'react-native'; -import {moderateScale, horizontalScale, scaledForDevice} from '../../scale'; -import {palette} from '../../theme/palette'; -import Text from '../Text'; -import Icon from '../Icon'; +import React, {FC, ReactNode} from 'react'; +import {Pressable, PressableProps, StyleSheet} from 'react-native'; +import {moderateScale, scaledForDevice} from '../../scale'; -interface PressableStyleProp { - pressed: boolean; -} - -interface BaseButtonProps extends PressableProps { - title?: string | null; - icon?: string; - iconRight?: boolean; - disabled?: boolean; +export interface BaseButtonProps extends PressableProps { borderRadius?: number; - pressedColor?: string; - style?: ViewStyle; - iconStyle?: ViewStyle; - textStyle?: TextStyle; - children?: React.ReactNode; + children?: ReactNode | null; + pressedStyle?: ReactNode; + style?: any; } const BaseButton: FC = ({ - title = null, - icon = null, - iconRight = false, - disabled = false, borderRadius = 0, - pressedColor, - style, - iconStyle, - textStyle, children = null, + style, + pressedStyle, ...props }) => { - if (!title && !icon && !children) { + if (!children) { return null; } - const bgColor = !disabled ? palette.primary.main : palette.grey[200]; - const iconPaddingLeft = iconRight && title ? 8 : 0; - const iconPaddingRight = !iconRight && title ? 8 : 0; - - const validatePaddingVertical = scaledForDevice(10, moderateScale); - const validatePaddingHorizontal = scaledForDevice(16, horizontalScale); - const validateFontSize = scaledForDevice(14, moderateScale); const validateBorderRadius = scaledForDevice(borderRadius, moderateScale); - const validatePaddingRightIcon = scaledForDevice(iconPaddingRight, horizontalScale); - const validatePaddingLeftIcon = scaledForDevice(iconPaddingLeft, horizontalScale); const styles = StyleSheet.create({ container: { - display: 'flex', - flexDirection: 'row', alignItems: 'center', justifyContent: 'center', - paddingHorizontal: validatePaddingHorizontal, - paddingVertical: validatePaddingVertical, borderRadius: validateBorderRadius, - backgroundColor: bgColor, - }, - icon: { - color: palette.base.white, - paddingRight: validatePaddingRightIcon, - paddingLeft: validatePaddingLeftIcon, - }, - title: { - fontSize: validateFontSize, - fontWeight: '500', - textAlign: 'center', - color: palette.base.white, }, }); - const noChildren = () => ( - <> - {icon && !iconRight && } - {title && {title}} - {icon && iconRight && } - - ); - - /* istanbul ignore next */ - const PressableStyle = ({pressed}: PressableStyleProp) => { - const backgroundColor = pressedColor ?? palette.primary.dark; - const pressedBgColor = pressed ? [{backgroundColor}] : []; - - return [styles.container, style, ...pressedBgColor]; - }; - return ( - - {children ?? noChildren} + [ + styles.container, + style, + pressed && /* istanbul ignore next */ pressedStyle, + ]} + {...props}> + {children} ); }; diff --git a/src/components/Button/index.test.tsx b/src/components/Button/index.test.tsx new file mode 100644 index 0000000..281f056 --- /dev/null +++ b/src/components/Button/index.test.tsx @@ -0,0 +1,43 @@ +import React from 'react'; +import {create} from 'react-test-renderer'; +import {Text} from 'react-native'; +import Icon from '../Icon'; +import Loading from '../Loading'; +import Button from './'; + +const validData = { + isLoading: true, + value: 'Button Test', + icon: 'box', +}; + +jest.spyOn(React, 'useEffect').mockImplementation((f) => f()); +jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper'); + +describe('Button component', () => { + describe('it renders correctly', () => { + it('when it has valie as minimum prop', () => { + const {root} = create(