Skip to content

Commit

Permalink
crear componente button
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Morales committed Apr 15, 2024
1 parent 767c58c commit a5d3718
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 108 deletions.
7 changes: 4 additions & 3 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ const App = () => (
icon='box'

Check failure on line 9 in App.tsx

View workflow job for this annotation

GitHub Actions / Build

Replace `'box'` with `"box"`

Check warning on line 9 in App.tsx

View workflow job for this annotation

GitHub Actions / Build

Unexpected usage of singlequote
isLoading={false}
type={Type.Main}
variant={Variant.Contained}
color={Color.Success}
iconPosition={IconPosition.Left}
variant={Variant.Outlined}
color={Color.Primary}
// iconPosition={IconPosition.Right}
disabled={false}
style={{width: '100%'}}

Check warning on line 16 in App.tsx

View workflow job for this annotation

GitHub Actions / Build

Inline style: { width: '100%' }
/>
</View>
);
Expand Down
6 changes: 1 addition & 5 deletions src/components/BaseButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,19 @@ export interface BaseButtonProps extends PressableProps {
}

const BaseButton: FC<BaseButtonProps> = ({
borderRadius = 50,
borderRadius = 0,
children = null,
style,
...props
}) => {
if(!children) return null;

Check warning on line 17 in src/components/BaseButton/index.tsx

View workflow job for this annotation

GitHub Actions / Build

Expected space(s) after "if"

Check warning on line 17 in src/components/BaseButton/index.tsx

View workflow job for this annotation

GitHub Actions / Build

Expected { after 'if' condition

const validatePaddingVertical = scaledForDevice(10, moderateScale);
const validatePaddingHorizontal = scaledForDevice(16, horizontalScale);
const validateBorderRadius = scaledForDevice(borderRadius, moderateScale);

const styles = StyleSheet.create({
container: {
alignItems: 'center',
justifyContent: 'center',
paddingHorizontal: validatePaddingHorizontal,
paddingVertical: validatePaddingVertical,
borderRadius: validateBorderRadius,
},
});
Expand Down
13 changes: 13 additions & 0 deletions src/components/Button/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const verticalHeights = ['top', 'bottom'];
const defaultColor = 'primary';
const defaultType = 'main';
const defaultVariant = 'contained';
const defaultIconPosition = 'left';

export {
verticalHeights,
defaultColor,
defaultType,
defaultVariant,
defaultIconPosition

Check warning on line 12 in src/components/Button/constants/index.ts

View workflow job for this annotation

GitHub Actions / Build

Missing trailing comma
}

Check warning on line 13 in src/components/Button/constants/index.ts

View workflow job for this annotation

GitHub Actions / Build

Newline required at end of file but not found
3 changes: 3 additions & 0 deletions src/components/Button/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('Button', () => {
/* global expect */
});
5 changes: 4 additions & 1 deletion src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export enum Color {

export enum IconPosition {
Left = 'left',
Right = 'rigth',
Right = 'right',
Top = 'top',
Bottom = 'bottom',
}
Expand Down Expand Up @@ -69,6 +69,7 @@ const Button: FC<ButtonProps> = ({
...props
}) => {
const [isPressed, setIsPressed] = useState<Boolean>(false);
const hasIconAndText = !!icon && !!value;

const params = {
type,
Expand All @@ -78,6 +79,7 @@ const Button: FC<ButtonProps> = ({
isLoading,
isPressed,
disabled,
hasIconAndText,
};
const buttonStyle = getMixedButtonStyles(params)
const styles = StyleSheet.create(buttonStyle);
Expand Down Expand Up @@ -113,6 +115,7 @@ const Button: FC<ButtonProps> = ({
onPressIn={useCallback(handleOnPressIn, [setIsPressed, isPressed])}
onPressOut={useCallback(handleOnPressOut, [setIsPressed, isPressed])}
disabled={disabled || isLoading}
borderRadius={50}
{...props}>
{isLoading ? LoadingCompontent : WrapperComponent}
</BaseButton>
Expand Down
136 changes: 136 additions & 0 deletions src/components/Button/theme/configs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { moderateScale, scaledForDevice } from '../../../../scale';
import { base, black, grey} from '../../../../theme/palette';
import { SelectedColor } from "../../types"

export const colorConfig = (selectedColor: SelectedColor) => {
return {
main: {
background: {
contained: selectedColor.main,
outlined: selectedColor.light,
text: 'transparent'
},
border: {
contained: 'transparent',
outlined: grey[300],
text: 'transparent'
},
text: {
main: {
contained: base.white,
outlined: black.main,
text: selectedColor.main,
},
secondary: {
contained: base.white,
outlined: selectedColor.main,
text: black.main,
}
},
},
pressed: {
background: {
contained: selectedColor.dark,
outlined: selectedColor.light,
text: grey[100],
},
border: {
contained: 'transparent',
outlined: selectedColor.main,
text: 'transparent',
},
text: {
main: {
contained: base.white,
outlined: black.main,
text: selectedColor.main,
},
secondary: {
contained: base.white,
outlined: selectedColor.main,
text: selectedColor.dark,
}
}
},
disabled: {
background: {
contained: grey[200],
outlined: grey[100],
text: 'transparent'
},
border: {
main: {
contained: 'transparent',
outlined: 'transparent',
text: 'transparent'
},
secondary: {
contained: 'transparent',
outlined: grey[300],
text: 'transparent'
}
},
text: {
main: {
contained: grey[400],
outlined: grey[300],
text: grey[300],
},
secondary: {
contained: grey[400],
outlined: grey[300],
text: grey[300],
}
},
},
}
}

export const stlyeConfig = {
container: {
height: {
main: scaledForDevice(50, moderateScale),
secondary: scaledForDevice(42, moderateScale),
},
shadow : {
// android
shadowColor: '#000',
elevation: 5,
// IOS
shadowOpacity: 0.25,
shadowRadius: 3.84,
shadowOffset: {
width: 0,
height: scaledForDevice(3, moderateScale),
},
}
},
directionWrapper: {
center: {
justifyContent: 'center',
alignItems: 'center'
},
flexDirection: {
left: 'row',
right: 'row-reverse',
top: 'column',
bottom: 'column-reverse',
}
},
text: {
fontWeight: '500',
textAlign: 'center',
},
icon: {
margin: {
top: {},
bottom: {},
left: {
right: scaledForDevice(8, moderateScale)
},
right: {
marginLeft: scaledForDevice(8, moderateScale)
},
}
}
}
45 changes: 1 addition & 44 deletions src/components/Button/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { alert, base, black, error, grey, primary, success, warning} from '../../../theme/palette';
import type { SelectedColor } from './types';
import { alert, base, black, error, primary, success, warning} from '../../../theme/palette';

export const themeColors = {
primary: {
Expand Down Expand Up @@ -32,46 +31,4 @@ export const themeColors = {
main: alert.main,
dark: alert.dark,
}
}

export const mixedColors = (selectedColor: SelectedColor) => {
return {
mainBgColor: {
contained: selectedColor.main,
outlined: selectedColor.light,
text: 'transparent'
},
mainBorderColor: {
contained: 'transparent',
outlined: grey[300],
text: 'transparent'
},
pressedBgColor: {
contained: selectedColor.dark,
outlined: selectedColor.light,
text: 'transparent'
},
pressedBorderColor: {
contained: 'transparent',
outlined: selectedColor.main,
text: 'transparent'
},
disabledBgColor: {
contained: grey[200],
outlined: grey[100],
text: 'transparent'
},
disabledBorderColor: {
main: {
contained: 'transparent',
outlined: 'transparent',
text: 'transparent'
},
secondary: {
contained: 'transparent',
outlined: grey[300],
text: 'transparent'
}
}
}
}
5 changes: 0 additions & 5 deletions src/components/Button/theme/types.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { Color, IconPosition, Type, Variant } from "../";

export interface SelectedColor {
light: string,
main: string,
dark: string,
}

export interface Params {
type: Type,
variant: Variant,
Expand All @@ -25,4 +31,24 @@ export interface ContainerStyle {
color: Color,
variant: Variant,
type: Type,
iconPosition: IconPosition,
}

export interface TextStyle {
type: Type,
variant: Variant,
color: Color,
disabled: Boolean,
isLoading: Boolean,
isPressed: Boolean,
hasIconAndText?: Boolean,
iconPosition: IconPosition,
}

export interface LoadingStyle {
color: Color,
}

export interface DirectionStyle {
iconPosition: IconPosition,
}
Loading

0 comments on commit a5d3718

Please sign in to comment.