Skip to content

Commit

Permalink
fix: icon color not changing on button hover (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
nastyastavitskaya authored Aug 12, 2024
1 parent 78d7854 commit aa07067
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/components/general/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react'

const meta: Meta<typeof Button> = {
title: 'Aquarium/General/Button',
component: props => <Button {...props}>{props.children || 'Button Label'}</Button>,
component: props => <Button {...props}>{props.children ?? 'Button Label'}</Button>,

args: {
block: false,
Expand Down Expand Up @@ -121,6 +121,14 @@ export const WithIconSM: Story = {
},
}

export const WithIconDefaultColorSM: Story = {
args: {
type: 'default',
icon: <Icon name="mpLogo" size="sm" color="default" />,
variant: 'with-new-icon',
},
}

export const RoundIconButton: Story = {
args: {
icon: <Icon name="siteMap" size="xl" />,
Expand Down
17 changes: 16 additions & 1 deletion src/components/general/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from 'react'
import { Button as AntButton } from 'antd'
import { type ButtonProps as AntButtonProps } from 'antd'
import { Icon } from 'src/components'
import type { IIconProps } from 'src/components'
import { ConfigProvider } from 'src/components/other/ConfigProvider/ConfigProvider'
import { type ReactNode } from 'react'

export interface IButtonProps extends AntButtonProps {
/**
Expand All @@ -9,15 +13,26 @@ export interface IButtonProps extends AntButtonProps {
* This will be removed once all icons are updated.
*/
variant?: 'with-new-icon'
icon?: ReactNode
}
export const Button = (props: IButtonProps) => {
const classMap = {
'with-new-icon': 'u-display-flex u-align-items-center u-justify-center',
}

const buttonIcon =
React.isValidElement<IIconProps>(props.icon) && props.icon.type === Icon ? (
<Icon {...props.icon.props} color={props.icon.props.color ?? 'inherit'} />
) : (
props.icon
)

return (
<ConfigProvider>
<AntButton {...props} className={`${props.className}${props.variant ? ` ${classMap[props.variant]}` : ''}`}>
<AntButton
{...props}
icon={buttonIcon}
className={`${props.className}${props.variant ? ` ${classMap[props.variant]}` : ''}`}>
{props.children}
</AntButton>
</ConfigProvider>
Expand Down
1 change: 1 addition & 0 deletions src/components/general/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type IconColor =
| 'text'
| 'strong'
| 'brand'
| 'inherit'

export interface IIconProps {
name: IconNames
Expand Down
4 changes: 4 additions & 0 deletions src/components/general/Icon/icon.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@
.icon-color-black {
color: black;
}

.icon-color-inherit {
color: inherit;
}

0 comments on commit aa07067

Please sign in to comment.