fix: keep icon color if defined as part of button (#479)

This commit is contained in:
Jakub Kotula 2023-09-15 15:27:18 +02:00 committed by GitHub
parent 90ffafd4ad
commit a43b5a6a02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
"@status-im/components": patch
---
fix: keep icon color if defined as part of button

View File

@ -1,3 +1,4 @@
import { PopupIcon } from '@status-im/icons'
import { action } from '@storybook/addon-actions' import { action } from '@storybook/addon-actions'
import { Stack } from 'tamagui' import { Stack } from 'tamagui'
@ -82,6 +83,14 @@ export const PrimaryIconBefore: Story = {
}, },
} }
export const PrimaryIconBeforeDifferentColor: Story = {
name: 'Primary icon before/Different color',
args: {
children: 'Click me',
icon: <PopupIcon size={20} color="$yellow-50" />,
},
}
export const PrimaryIconAfter: Story = { export const PrimaryIconAfter: Story = {
name: 'Primary/Icon after', name: 'Primary/Icon after',
args: { args: {
@ -89,6 +98,15 @@ export const PrimaryIconAfter: Story = {
iconAfter: icon, iconAfter: icon,
}, },
} }
export const PrimaryIconAfterDifferentColor: Story = {
name: 'Primary/Icon after/Different color',
args: {
children: 'Click me',
iconAfter: <PopupIcon size={20} color="$yellow-50" />,
},
}
export const PrimaryIconOnly: Story = { export const PrimaryIconOnly: Story = {
name: 'Primary/Icon only', name: 'Primary/Icon only',
args: { args: {

View File

@ -82,11 +82,17 @@ const Button = (props: Props, ref: Ref<View>) => {
iconOnly={iconOnly} iconOnly={iconOnly}
width={fullWidth ? '100%' : 'auto'} width={fullWidth ? '100%' : 'auto'}
> >
{icon ? cloneElement(icon, { color: textColor || '$neutral-40' }) : null} {icon
? cloneElement(icon, {
color: iconOnly ? textColor : icon.props.color ?? textColor,
})
: null}
<Text weight="medium" color={textColor} size={textSize}> <Text weight="medium" color={textColor} size={textSize}>
{children} {children}
</Text> </Text>
{iconAfter ? cloneElement(iconAfter, { color: textColor }) : null} {iconAfter
? cloneElement(iconAfter, { color: iconAfter.props.color ?? textColor })
: null}
</Base> </Base>
) )
} }