Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(button): 버튼 아이콘에도 색상 테마 적용 #44

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions apps/docs/src/stories/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Meta, StoryObj } from '@storybook/react';
import { Button } from 'ui';
import { IconCheck } from '../../../../packages/icons/src';

interface ButtonOwnProps {
size?: 'sm' | 'md' | 'lg';
Expand All @@ -21,8 +22,8 @@ export default {
backgrounds: {
default: 'dark', // 기본 배경을 'dark'로 설정
values: [
{ name: 'dark', value: "#0F1012" }, // 'dark' 배경의 색상을 검정색으로 지정
{ name: 'white', value: '#ffffff' }
{ name: 'dark', value: '#0F1012' }, // 'dark' 배경의 색상을 검정색으로 지정
{ name: 'white', value: '#ffffff' },
],
},
},
Expand All @@ -47,6 +48,7 @@ export const Another: StoryObj<ButtonStoryProps> = {
theme: 'red',
rounded: 'lg',
disabled: false,
LeftIcon: IconCheck,
},
};

Expand All @@ -58,4 +60,4 @@ export const Disabled: StoryObj<ButtonStoryProps> = {
rounded: 'lg',
disabled: true,
},
};
};
14 changes: 7 additions & 7 deletions packages/ui/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import React from 'react';
import * as S from './style.css';
import { createButtonVariant } from './utils';

type IconProps = { color?: string };
import { createButtonVariant, getIconStyles } from './utils';

interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
children?: React.ReactNode;
className?: string;
size?: 'sm' | 'md' | 'lg';
theme?: 'white' | 'black' | 'blue' | 'red';
rounded?: 'md' | 'lg';
LeftIcon?: React.ComponentType<IconProps>;
RightIcon?: React.ComponentType<IconProps>;
LeftIcon?: React.ComponentType<any>;
RightIcon?: React.ComponentType<any>;
Comment on lines +11 to +12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any 어쩌다가 등장했나요..!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

누군가가 이것을 .. ComponentType<IconProps>로 수정해주시구 ..... 컨플릭트 해소해주신 후 머지해주신다면 .... 정말 감사하겠습니다!!!!!

}

function Button({
Expand All @@ -25,14 +23,16 @@ function Button({
...buttonElementProps
}: ButtonProps) {
const variant = createButtonVariant(theme, rounded, size);
const iconStyles = getIconStyles(theme, size);

return (
<button
className={`${S.root} ${variant} ${className}`}
{...buttonElementProps}
>
{LeftIcon && <LeftIcon />}
{LeftIcon && <LeftIcon style={iconStyles} />}
<span>{children}</span>
{RightIcon && <RightIcon />}
{RightIcon && <RightIcon style={iconStyles} />}
</button>
);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/ui/Button/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ export const fontSizes: Record<ButtonSizeTheme, string> = {
md: '14px',
lg: '18px',
};

export const iconSizes: Record<ButtonSizeTheme, string> = {
sm: '16px',
md: '20px',
lg: '24px',
};
15 changes: 14 additions & 1 deletion packages/ui/Button/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { colorThemeToTextColor } from './constants';
import { colorThemeToTextColor, iconSizes, textColors } from './constants';
import { sprinkles } from './style.css';
import { ButtonColorTheme, ButtonRadiusTheme, ButtonSizeTheme } from './types';

Expand All @@ -23,3 +23,16 @@ export function createButtonVariant(
fontSize: sizeTheme,
});
}

export function getIconStyles(
colorTheme: ButtonColorTheme,
sizeTheme: ButtonSizeTheme
): React.CSSProperties {
const iconSize = iconSizes[sizeTheme];
const iconColor = textColors[colorThemeToTextColor[colorTheme]];
return {
color: iconColor,
width: iconSize,
height: iconSize,
};
}