Skip to content

Commit

Permalink
refactor: 프로젝트 코드 컨벤션관련 defaultValue, spred props, 의미에 맞는 네이밍, 증복코드 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
bytrustu committed Mar 6, 2024
1 parent b6d8a1d commit 58c6df2
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 106 deletions.
4 changes: 2 additions & 2 deletions src/components/CardDisplay/CardAddDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { styleToken } from '@/shared/styles';
type CardAddDisplayProps = {
onClick?: () => void;
};
export const CardAddDisplay = (props: CardAddDisplayProps) => (
export const CardAddDisplay = ({ onClick }: CardAddDisplayProps) => (
<Button
alignItems="center"
justifyContent="center"
width="208px"
height="130px"
backgroundColor={styleToken.color.gray300}
onClick={onClick}
_hover={{ backgroundColor: styleToken.color.gray300 }}
{...props}
>
<Typography variant="headline" fontSize="36px" color={styleToken.color.gray600}>
+
Expand Down
11 changes: 1 addition & 10 deletions src/components/CardProvider/CardProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import { createContext, useState, useContext, PropsWithChildren, useMemo } from 'react';

type CardState = {
cardNumber: string[];
expirationDate: string;
ownerName: string;
securityCode: string;
label: string;
color: string;
description: string;
};
import { CardState } from '@/type';

type CardContextType = {
card: CardState;
Expand Down
67 changes: 31 additions & 36 deletions src/components/CardSelectBottomSheet/CardSelectBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,38 @@ type CardSelectBottomSheetProps = {
onSubmit?: (cardBrand: CardBrand) => void;
};

export const CardSelectBottomSheet = ({ onOverlayClick, onSubmit }: CardSelectBottomSheetProps) => {
const handleOverlayClick = () => {
onOverlayClick?.();
};
return (
<BackDrop onClick={handleOverlayClick}>
<VStack
position="absolute"
bottom="0"
left="0"
width="100%"
height="230px"
backgroundColor="white"
borderRadius="5px 5px 15px 15px"
export const CardSelectBottomSheet = ({ onOverlayClick, onSubmit }: CardSelectBottomSheetProps) => (
<BackDrop onClick={onOverlayClick}>
<VStack
position="absolute"
bottom="0"
left="0"
width="100%"
height="230px"
backgroundColor="white"
borderRadius="5px 5px 15px 15px"
>
<Grid
gridTemplateColumns="repeat(4, 1fr)"
alignItems="center"
justifyContent="center"
height="100%"
padding="20px 20px"
>
<Grid
gridTemplateColumns="repeat(4, 1fr)"
alignItems="center"
justifyContent="center"
height="100%"
padding="20px 20px"
>
{CARD_BRANDS.map(({ label, color }) => (
<CardSelectButton
key={`card-select-${label}`}
color={color}
label={label}
onClick={() => {
onSubmit?.({ label, color });
}}
/>
))}
</Grid>
</VStack>
</BackDrop>
);
};
{CARD_BRANDS.map(({ label, color }) => (
<CardSelectButton
key={`card-select-${label}`}
color={color}
label={label}
onClick={() => {
onSubmit?.({ label, color });
}}
/>
))}
</Grid>
</VStack>
</BackDrop>
);

type CardSelectButtonProps = {
onClick: () => void;
Expand Down
9 changes: 1 addition & 8 deletions src/pages/CardListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ export const CardListPage = () => {
<VStack gap="20px" padding="20px 0">
{ownerCards.map((ownerCard, index) => (
<VStack key={`card-list-${index}`} gap="10px" alignItems="center" justifyContent="center">
<CardDisplay
size="small"
label={ownerCard.label}
color={ownerCard.color}
cardNumber={ownerCard.cardNumber}
expirationDate={ownerCard.expirationDate}
ownerName={ownerCard.ownerName}
/>
<CardDisplay size="small" {...ownerCard} />
<Typography variant="body" textAlign="center">
{ownerCard.description}
</Typography>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ButtonVariant, ButtonVariantState, ButtonColorScheme } from './Button.type';
import { styleToken } from '@/shared/styles';

export const buttonColorMap = {
export const buttonColorToken = {
teal: {
solid: {
default: {
Expand Down Expand Up @@ -79,8 +78,3 @@ export const buttonColorMap = {
},
},
} as const;

export const getButtonColor = (colorScheme: ButtonColorScheme, variant: ButtonVariant, state: ButtonVariantState) => {
const colorInfo = buttonColorMap[colorScheme][variant];
return colorInfo[state];
};
23 changes: 12 additions & 11 deletions src/shared/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { HTMLProps, PropsWithChildren } from 'react';
import styled from '@emotion/styled';
import { getButtonColor } from './Button.token.ts';
import { ButtonHoverProps, ButtonOptionalProps } from './Button.type';
import { getButtonColor } from './Button.util';
import { styleToken } from '@/shared/styles';
import type { AsProps, StyleProps } from '@/shared/types';

type ButtonProps = PropsWithChildren<
StyleProps & AsProps & HTMLProps<HTMLButtonElement> & ButtonOptionalProps & ButtonHoverProps
>;

export const Button = ({ children, type, variant, colorScheme, ...rest }: ButtonProps) => {
const buttonType = type || 'button';
const buttonVariant = variant || 'solid';
const buttonColorScheme = colorScheme || 'teal';
return (
<Root type={buttonType} variant={buttonVariant} colorScheme={buttonColorScheme} {...rest}>
{children}
</Root>
);
};
export const Button = ({
children,
type = 'button',
variant = 'solid',
colorScheme = 'teal',
...rest
}: ButtonProps) => (
<Root type={type} variant={variant} colorScheme={colorScheme} {...rest}>
{children}
</Root>
);

const Root = styled.button<ButtonProps & Required<ButtonOptionalProps> & ButtonHoverProps>`
width: ${({ width }) => width || 'auto'};
Expand Down
7 changes: 7 additions & 0 deletions src/shared/components/Button/Button.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { buttonColorToken } from './Button.token';
import type { ButtonColorScheme, ButtonVariant, ButtonVariantState } from './Button.type';

export const getButtonColor = (colorScheme: ButtonColorScheme, variant: ButtonVariant, state: ButtonVariantState) => {
const colorInfo = buttonColorToken[colorScheme][variant];
return colorInfo[state];
};
42 changes: 25 additions & 17 deletions src/shared/components/Circle/Circle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@ import type { AsProps, StyleProps } from '@/shared/types';

type CircleProps = PropsWithChildren<StyleProps & AsProps>;

export const Circle = ({ children, ...props }: CircleProps) => {
const { display, alignItems, justifyContent, width, height, borderRadius, backgroundColor } = props;
const circleProps = {
display: display || 'flex',
alignItems: alignItems || 'center',
justifyContent: justifyContent || 'center',
width: width || '37px',
height: height || '37px',
borderRadius: borderRadius || '50%',
backgroundColor: backgroundColor || styleToken.color.gray200,
};
return (
<Root as="span" {...circleProps} {...props}>
{children}
</Root>
);
};
export const Circle = ({
children,
display = 'flex',
alignItems = 'center',
justifyContent = 'center',
width = '37px',
height = '37px',
borderRadius = '50%',
backgroundColor = styleToken.color.gray200,
...props
}: CircleProps) => (
<Root
as="span"
display={display}
alignItems={alignItems}
justifyContent={justifyContent}
width={width}
height={height}
borderRadius={borderRadius}
backgroundColor={backgroundColor}
{...props}
>
{children}
</Root>
);

const Root = styled(DefaultStyled)<CircleProps>``;

Expand Down
41 changes: 28 additions & 13 deletions src/shared/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,34 @@ export type TextFieldProps = StyleProps &
_focus?: FocusProps;
};

export const TextField = forwardRef<HTMLInputElement, TextFieldProps>((props, ref) => {
const { type, variant, width, height, padding, borderRadius, fontSize, ...restProps } = props;
const buttonProps = {
type: type || 'text',
variant: variant || 'outline',
width: width || styleToken.width.w100,
height: height || '45px',
padding: padding || '13px 12px 13px 11px',
borderRadius: borderRadius || '6px',
fontSize: fontSize || '18px',
};
return <Root as="input" ref={ref} {...buttonProps} {...restProps} />;
});
export const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
(
{
type = 'text',
variant = 'outline',
width = styleToken.width.w100,
height = '45px',
padding = '13px 12px 13px 11px',
borderRadius = '6px',
fontSize = '18px',
...props
},
ref,
) => (
<Root
as="input"
ref={ref}
type={type}
variant={variant}
width={width}
height={height}
padding={padding}
borderRadius={borderRadius}
fontSize={fontSize}
{...props}
/>
),
);

const Root = styled(DefaultStyled)<TextFieldProps>`
${({ width }) => width || styleToken.width.w100};
Expand Down
2 changes: 1 addition & 1 deletion src/shared/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './props/index';
export * from './props';
2 changes: 1 addition & 1 deletion src/shared/utils/replaceMaskText.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const replaceMaskText = (text: string, maskChar?: string) => text.replace(/\d/g, maskChar || '●');
export const replaceMaskText = (text: string, maskChar: string = '●') => text.replace(/\d/g, maskChar);

0 comments on commit 58c6df2

Please sign in to comment.