Skip to content

Commit

Permalink
feat(components): add border option for Card component
Browse files Browse the repository at this point in the history
  • Loading branch information
enjojoy committed Jan 23, 2025
1 parent e441a1a commit afaf832
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/components/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ export const allowedCardFrameProps = [
] as const satisfies FramePropsKeys[];
type AllowedFrameProps = Pick<FrameProps, (typeof allowedCardFrameProps)[number]>;

const Container = styled.div<{ $fillType: FillType } & TransientProps<AllowedFrameProps>>`
const Container = styled.div<
{ $fillType: FillType; $border?: string } & TransientProps<AllowedFrameProps>
>`
width: 100%;
border-radius: ${borders.radii.md};
background: ${({ theme, $fillType }) =>
$fillType !== 'none' && theme.backgroundTertiaryDefaultOnElevation0};
padding: ${spacingsPx.xxxs};
border: ${({ $border }) => $border || 'none'};
${withFrameProps}
`;

Expand All @@ -57,6 +59,7 @@ const CardContainer = styled.div<
$isClickable: boolean;
$variant?: CardVariant;
$hasLabel: boolean;
$border?: string;
} & TransientProps<AllowedFrameProps>
>`
width: 100%;
Expand All @@ -65,6 +68,7 @@ const CardContainer = styled.div<
position: relative;
padding: ${mapPaddingTypeToPadding};
border-radius: ${borders.radii.md};
border: ${({ $border }) => $border || 'none'};
transition:
background 0.3s,
box-shadow 0.2s,
Expand Down Expand Up @@ -103,6 +107,7 @@ type CommonCardProps = AccessibilityProps & {
label?: ReactNode;
variant?: CardVariant;
'data-testid'?: string;
border?: string;
};

export type CardPropsWithTransientProps = CommonCardProps & TransientProps<AllowedFrameProps>;
Expand All @@ -122,6 +127,7 @@ const CardComponent = forwardRef<HTMLDivElement, CardPropsWithTransientProps>(
label,
variant,
'data-testid': dataTest,
border,
...rest
},
ref,
Expand All @@ -137,6 +143,7 @@ const CardComponent = forwardRef<HTMLDivElement, CardPropsWithTransientProps>(
$isClickable={Boolean(onClick)}
$variant={variant}
$hasLabel={Boolean(label)}
$border={border}
onClick={onClick}
onMouseEnter={onMouseEnter}
className={className}
Expand Down Expand Up @@ -165,6 +172,7 @@ export const Card = forwardRef<HTMLDivElement, CardProps>(
children,
variant,
'data-testid': dataTest,
border,
...rest
},
ref,
Expand All @@ -181,16 +189,17 @@ export const Card = forwardRef<HTMLDivElement, CardProps>(
label,
variant,
'data-testid': dataTest,
border,
};
const frameProps = pickAndPrepareFrameProps(rest, allowedCardFrameProps);

return label ? (
<Container $fillType={fillType} {...frameProps}>
<Container $fillType={fillType} {...frameProps} $border={border}>
<LabelContainer $paddingType={paddingType}>{label}</LabelContainer>
<CardComponent {...commonProps} ref={ref} />
</Container>
) : (
<CardComponent {...commonProps} {...frameProps} ref={ref} />
<CardComponent {...commonProps} {...frameProps} border={border} ref={ref} />
);
},
);

0 comments on commit afaf832

Please sign in to comment.