Skip to content

Commit

Permalink
fix(Button): added state for btn and removed some types
Browse files Browse the repository at this point in the history
  • Loading branch information
vpsmolina committed Aug 13, 2024
1 parent 1f0881c commit 25ff1f8
Show file tree
Hide file tree
Showing 12 changed files with 392 additions and 158 deletions.
31 changes: 8 additions & 23 deletions packages/core/src/cta/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {FC, forwardRef, PropsWithChildren} from 'react';

import {getCounterType} from '../../utils';
import {getCounterType, getDefaultFont, getSpinnerColor} from '../../utils';
import {ITouchableOpacity, TouchableOpacity} from '../../../basic';
import useStyles from '../../../styles/hooks/useStyles';
import {TypographyLegacy} from '../../../typography';
Expand All @@ -9,9 +9,8 @@ import {ISizeSpinner} from '../../../progress/components/Spinner/types';
import {ICounterSize} from '../../../other';
import Counter from '../../../other/components/Badge/Counter/Counter';

import {IButtonProps, IButtonSize, IButtonTypes} from './types';
import {IButtonProps, IButtonSize, IButtonTypes, IStateBtn} from './types';
import stylesCreate from './stylesCreate';
import {getDefaultFont} from './getDefaultFont';

const Button = forwardRef<ITouchableOpacity, IButtonProps>((props, ref) => {
const {
Expand All @@ -27,21 +26,20 @@ const Button = forwardRef<ITouchableOpacity, IButtonProps>((props, ref) => {
font,
count,
textProps,
state = disabled ? IStateBtn.disabled : IStateBtn.default,
...otherProps
} = props;
const [styles, theme] = useStyles(
stylesCreate,
disabled ? IButtonTypes.disabled : type,
type,
size,
Boolean(leftIcon),
Boolean(rightIcon),
Boolean(text),
state,
);

const defaultFont = getDefaultFont(
size,
disabled ? IButtonTypes.disabled : type,
);
const defaultFont = getDefaultFont(size, type, state);

const counterSize =
size === IButtonSize.small ? ICounterSize.small : ICounterSize.medium;
Expand All @@ -61,24 +59,11 @@ const Button = forwardRef<ITouchableOpacity, IButtonProps>((props, ref) => {
</TouchableOpacity>
);

const getSpinnerColor = (): string => {
if (disabled) {
return theme.colors.IconWhite;
}
switch (type) {
case IButtonTypes.secondary:
case IButtonTypes.tertiary:
return theme.colors.IconBase;
default:
return theme.colors.IconWhite;
}
};

if (loading || type === IButtonTypes.loading) {
return (
<Container>
<Spinner
fill={getSpinnerColor()}
fill={getSpinnerColor({type, state, theme})}
size={size === IButtonSize.small ? ISizeSpinner.XXS : ISizeSpinner.XS}
/>
</Container>
Expand All @@ -101,7 +86,7 @@ const Button = forwardRef<ITouchableOpacity, IButtonProps>((props, ref) => {
<Counter
count={count}
size={counterSize}
type={getCounterType(type)}
type={getCounterType({type, state})}
style={styles.counter}
/>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ exports[`@lad-tech/mobydick-core/Button renders correctly destructive 1`] = `
"minHeight": 20,
},
{
"color": "#F54C3D",
"color": "#2B78EE",
"paddingHorizontal": 6,
"textAlign": "center",
},
Expand Down Expand Up @@ -662,7 +662,7 @@ exports[`@lad-tech/mobydick-core/Button renders correctly loading disabled 1`] =
}
>
<SvgMock
fill="#FFFFFF"
fill="#D0D6E0"
height="24"
width="24"
/>
Expand Down Expand Up @@ -932,7 +932,7 @@ exports[`@lad-tech/mobydick-core/Button renders correctly loading types 4`] = `
{
"alignItems": "center",
"alignSelf": "center",
"backgroundColor": "#FFFFFF",
"backgroundColor": "#2B78EE",
"borderRadius": 12,
"height": 24,
"justifyContent": "center",
Expand All @@ -957,7 +957,7 @@ exports[`@lad-tech/mobydick-core/Button renders correctly loading types 4`] = `
"minHeight": 20,
},
{
"color": "#2B78EE",
"color": "#FFFFFF",
"paddingHorizontal": 6,
"textAlign": "center",
},
Expand Down Expand Up @@ -1089,7 +1089,7 @@ exports[`@lad-tech/mobydick-core/Button renders correctly loading types 6`] = `
{
"alignItems": "center",
"alignSelf": "stretch",
"backgroundColor": "#F2F4F7",
"backgroundColor": "#2B78EE",
"borderRadius": 12,
"flexDirection": "row",
"justifyContent": "center",
Expand All @@ -1099,45 +1099,23 @@ exports[`@lad-tech/mobydick-core/Button renders correctly loading types 6`] = `
}
>
<View
collapsable={false}
style={
[
{
"alignItems": "center",
"alignSelf": "center",
"backgroundColor": "#FFFFFF",
"borderRadius": 12,
"height": 24,
"justifyContent": "center",
"minWidth": 24,
"zIndex": 1,
},
{
"marginLeft": 2,
},
]
}
>
<Text
allowFontScaling={true}
style={
[
{
"color": "#FFFFFF",
"fontFamily": "Inter-SemiBold",
"fontSize": 16,
"lineHeight": 20,
"minHeight": 20,
},
{
"alignSelf": "center",
"transform": [
{
"color": "#9BA1B0",
"paddingHorizontal": 6,
"textAlign": "center",
"rotate": "0deg",
},
]
],
}
>
23
</Text>
}
>
<SvgMock
fill="#FFFFFF"
height="24"
width="24"
/>
</View>
</View>
`;
Expand Down Expand Up @@ -1175,7 +1153,7 @@ exports[`@lad-tech/mobydick-core/Button renders correctly loading types 7`] = `
{
"alignItems": "center",
"alignSelf": "stretch",
"backgroundColor": "#2B78EE",
"backgroundColor": "#F2F4F7",
"borderRadius": 12,
"flexDirection": "row",
"justifyContent": "center",
Expand All @@ -1185,23 +1163,45 @@ exports[`@lad-tech/mobydick-core/Button renders correctly loading types 7`] = `
}
>
<View
collapsable={false}
style={
{
"alignSelf": "center",
"transform": [
[
{
"alignItems": "center",
"alignSelf": "center",
"backgroundColor": "#FFFFFF",
"borderRadius": 12,
"height": 24,
"justifyContent": "center",
"minWidth": 24,
"zIndex": 1,
},
{
"marginLeft": 2,
},
]
}
>
<Text
allowFontScaling={true}
style={
[
{
"rotate": "0deg",
"color": "#FFFFFF",
"fontFamily": "Inter-SemiBold",
"fontSize": 16,
"lineHeight": 20,
"minHeight": 20,
},
],
{
"color": "#2B78EE",
"paddingHorizontal": 6,
"textAlign": "center",
},
]
}
}
>
<SvgMock
fill="#FFFFFF"
height="24"
width="24"
/>
>
23
</Text>
</View>
</View>
`;
Expand Down Expand Up @@ -1279,7 +1279,7 @@ exports[`@lad-tech/mobydick-core/Button renders correctly loading types 8`] = `
"minHeight": 20,
},
{
"color": "#F54C3D",
"color": "#2B78EE",
"paddingHorizontal": 6,
"textAlign": "center",
},
Expand Down
37 changes: 0 additions & 37 deletions packages/core/src/cta/components/Button/getDefaultFont.tsx

This file was deleted.

Loading

0 comments on commit 25ff1f8

Please sign in to comment.