Skip to content

Commit 51e406c

Browse files
fix(buttons): fixed common buttons disabled colors
1 parent f73c6c1 commit 51e406c

File tree

6 files changed

+63
-17
lines changed

6 files changed

+63
-17
lines changed
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
import React, {type ReactNode} from 'react';
1+
import React from 'react';
22
import {TouchableOpacity, Text, type StyleProp, type TextStyle, type TouchableOpacityProps} from 'react-native';
33

44
import {styles} from './common-button.styles';
5+
import {type IconProps} from '../../../icons/icon-props';
56
import {useTypography} from '../../../typography/useTypography.component';
67

78
export interface CommonButtonProps extends TouchableOpacityProps {
89
title: string;
910

10-
prepend?: ReactNode;
11-
append?: ReactNode;
1211
titleStyle?: StyleProp<TextStyle>;
12+
StartIcon?: React.FC<IconProps>;
13+
EndIcon?: React.FC<IconProps>;
14+
iconProps?: IconProps;
1315
}
1416

15-
export const CommonButton: React.FC<CommonButtonProps> = ({title, prepend, append, titleStyle, style, ...props}) => {
17+
const DEFAULT_ICON_SIZE = 18;
18+
19+
export const CommonButton: React.FC<CommonButtonProps> = ({title, StartIcon, EndIcon, titleStyle, iconProps, style, ...props}) => {
1620
const {labelLarge} = useTypography();
1721

18-
const containerPaddingStart = append || prepend ? 16 : 24;
22+
const containerPaddingStart = StartIcon || EndIcon ? 16 : 24;
1923

2024
return (
2125
<TouchableOpacity style={[styles.container, {paddingStart: containerPaddingStart}, style]} hitSlop={16} {...props}>
22-
{prepend}
26+
{StartIcon && <StartIcon size={DEFAULT_ICON_SIZE} {...iconProps} />}
2327
<Text style={[labelLarge, titleStyle]}>{title}</Text>
24-
{append}
28+
{EndIcon && <EndIcon size={DEFAULT_ICON_SIZE} {...iconProps} />}
2529
</TouchableOpacity>
2630
);
2731
};

src/buttons/common-buttons/elevated-button/ElevatedButton.component.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {StyleSheet} from 'react-native';
33

44
import {styles} from './elevated-button.styles';
55
import {useTheme} from '../../../theme/useTheme.hook';
6+
import {convertToRGBA} from '../../../utils/convert-to-rgba';
67
import {CommonButton, type CommonButtonProps} from '../common-button/CommonButton.component';
78

89
export const ElevatedButton: React.FC<CommonButtonProps> = ({titleStyle, style, ...props}) => {
@@ -12,11 +13,21 @@ export const ElevatedButton: React.FC<CommonButtonProps> = ({titleStyle, style,
1213
() =>
1314
StyleSheet.create(
1415
props.disabled
15-
? {title: {opacity: 0.38, color: surface.text}, container: {opacity: 0.12, backgroundColor: surface.text}}
16+
? {
17+
title: {color: convertToRGBA(surface.text as string, 0.38)},
18+
container: {backgroundColor: convertToRGBA(surface.text as string, 0.12)},
19+
}
1620
: {title: {color: primary.background}, container: {backgroundColor: surfaceContainer.backgroundLow, shadowColor: shadow}}
1721
),
1822
[props.disabled]
1923
);
2024

21-
return <CommonButton style={[colorStyles.container, styles.container, style]} titleStyle={[colorStyles.title, titleStyle]} {...props} />;
25+
return (
26+
<CommonButton
27+
style={[colorStyles.container, styles.container, style]}
28+
titleStyle={[colorStyles.title, titleStyle]}
29+
iconProps={{color: colorStyles.title.color}}
30+
{...props}
31+
/>
32+
);
2233
};

src/buttons/common-buttons/filled-button/FilledButton.component.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {useMemo} from 'react';
22
import {StyleSheet} from 'react-native';
33

44
import {useTheme} from '../../../theme/useTheme.hook';
5+
import {convertToRGBA} from '../../../utils/convert-to-rgba';
56
import {CommonButton, type CommonButtonProps} from '../common-button/CommonButton.component';
67

78
export const FilledButton: React.FC<CommonButtonProps> = ({style, titleStyle, ...props}) => {
@@ -11,11 +12,21 @@ export const FilledButton: React.FC<CommonButtonProps> = ({style, titleStyle, ..
1112
() =>
1213
StyleSheet.create(
1314
props.disabled
14-
? {title: {opacity: 0.38, color: surface.text}, container: {opacity: 0.12, backgroundColor: surface.text}}
15+
? {
16+
title: {color: convertToRGBA(surface.text as string, 0.38)},
17+
container: {backgroundColor: convertToRGBA(surface.text as string, 0.12)},
18+
}
1519
: {title: {color: primary.text}, container: {backgroundColor: primary.background}}
1620
),
1721
[props.disabled]
1822
);
1923

20-
return <CommonButton style={[colorStyles.container, style]} titleStyle={[colorStyles.title, titleStyle]} {...props} />;
24+
return (
25+
<CommonButton
26+
style={[colorStyles.container, style]}
27+
titleStyle={[colorStyles.title, titleStyle]}
28+
iconProps={{color: colorStyles.title.color}}
29+
{...props}
30+
/>
31+
);
2132
};

src/buttons/common-buttons/outlined-button/OutlinedButton.component.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {StyleSheet} from 'react-native';
33

44
import {styles} from './outlined-button.styles';
55
import {useTheme} from '../../../theme/useTheme.hook';
6+
import {convertToRGBA} from '../../../utils/convert-to-rgba';
67
import {CommonButton, type CommonButtonProps} from '../common-button/CommonButton.component';
78

89
export const OutlinedButton: React.FC<CommonButtonProps> = ({titleStyle, style, ...props}) => {
@@ -12,11 +13,18 @@ export const OutlinedButton: React.FC<CommonButtonProps> = ({titleStyle, style,
1213
() =>
1314
StyleSheet.create(
1415
props.disabled
15-
? {title: {opacity: 0.38, color: surface.text}, container: {borderColor: surface.text}}
16+
? {title: {color: convertToRGBA(surface.text as string, 0.38)}, container: {borderColor: convertToRGBA(surface.text as string, 0.12)}}
1617
: {title: {color: primary.background}, container: {borderColor: outline}}
1718
),
1819
[props.disabled]
1920
);
2021

21-
return <CommonButton style={[styles.container, colorStyles.container, style]} titleStyle={[colorStyles.title, titleStyle]} {...props} />;
22+
return (
23+
<CommonButton
24+
iconProps={{color: colorStyles.title.color}}
25+
titleStyle={[colorStyles.title, titleStyle]}
26+
style={[styles.container, colorStyles.container, style]}
27+
{...props}
28+
/>
29+
);
2230
};

src/buttons/common-buttons/text-button/TextButton.component.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {useMemo} from 'react';
22
import {StyleSheet} from 'react-native';
33

44
import {useTheme} from '../../../theme/useTheme.hook';
5+
import {convertToRGBA} from '../../../utils/convert-to-rgba';
56
import {CommonButton, type CommonButtonProps} from '../common-button/CommonButton.component';
67

78
export const TextButton: React.FC<CommonButtonProps> = ({titleStyle, ...props}) => {
@@ -10,10 +11,10 @@ export const TextButton: React.FC<CommonButtonProps> = ({titleStyle, ...props})
1011
const colorStyles = useMemo(
1112
() =>
1213
StyleSheet.create({
13-
title: props.disabled ? {color: surface.text, opacity: 0.38} : {color: primary.background},
14+
title: {color: props.disabled ? convertToRGBA(surface.text as string, 0.38) : primary.background},
1415
}),
1516
[props.disabled]
1617
);
1718

18-
return <CommonButton titleStyle={[colorStyles.title, titleStyle]} {...props} />;
19+
return <CommonButton titleStyle={[colorStyles.title, titleStyle]} iconProps={{color: colorStyles.title.color}} {...props} />;
1920
};

src/buttons/common-buttons/tonal-button/TonalButton.component.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {useMemo} from 'react';
22
import {StyleSheet} from 'react-native';
33

44
import {useTheme} from '../../../theme/useTheme.hook';
5+
import {convertToRGBA} from '../../../utils/convert-to-rgba';
56
import {CommonButton, type CommonButtonProps} from '../common-button/CommonButton.component';
67

78
export const TonalButton: React.FC<CommonButtonProps> = ({titleStyle, style, ...props}) => {
@@ -11,11 +12,21 @@ export const TonalButton: React.FC<CommonButtonProps> = ({titleStyle, style, ...
1112
() =>
1213
StyleSheet.create(
1314
props.disabled
14-
? {title: {opacity: 0.38, color: surface.text}, container: {opacity: 0.12, borderColor: surface.text}}
15+
? {
16+
title: {color: convertToRGBA(surface.text as string, 0.38)},
17+
container: {borderColor: convertToRGBA(surface.text as string, 0.12)},
18+
}
1519
: {title: {color: secondaryContainer.text}, container: {backgroundColor: secondaryContainer.background}}
1620
),
1721
[props.disabled]
1822
);
1923

20-
return <CommonButton style={[colorStyles.container, style]} titleStyle={[colorStyles.title, titleStyle]} {...props} />;
24+
return (
25+
<CommonButton
26+
style={[colorStyles.container, style]}
27+
titleStyle={[colorStyles.title, titleStyle]}
28+
iconProps={{color: colorStyles.title.color}}
29+
{...props}
30+
/>
31+
);
2132
};

0 commit comments

Comments
 (0)