Skip to content

Commit

Permalink
feat(components): add border to Card
Browse files Browse the repository at this point in the history
  • Loading branch information
enjojoy committed Jan 20, 2025
1 parent 2946049 commit a56ae2b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/components/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +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 +60,7 @@ const CardContainer = styled.div<
$isClickable: boolean;
$variant?: CardVariant;
$hasLabel: boolean;
$border?: string;
} & TransientProps<AllowedFrameProps>
>`
width: 100%;
Expand All @@ -65,6 +69,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 @@ -102,6 +107,7 @@ type CommonCardProps = AccessibilityProps & {
className?: string;
label?: ReactNode;
variant?: CardVariant;
border?: string;
'data-testid'?: string;
};

Expand All @@ -121,6 +127,7 @@ const CardComponent = forwardRef<HTMLDivElement, CardPropsWithTransientProps>(
tabIndex,
label,
variant,
border,
'data-testid': dataTest,
...rest
},
Expand All @@ -137,6 +144,7 @@ const CardComponent = forwardRef<HTMLDivElement, CardPropsWithTransientProps>(
$isClickable={Boolean(onClick)}
$variant={variant}
$hasLabel={Boolean(label)}
$border={border}
onClick={onClick}
onMouseEnter={onMouseEnter}
className={className}
Expand All @@ -163,6 +171,7 @@ export const Card = forwardRef<HTMLDivElement, CardProps>(
className,
tabIndex,
children,
border,
variant,
'data-testid': dataTest,
...rest
Expand All @@ -185,12 +194,12 @@ export const Card = forwardRef<HTMLDivElement, CardProps>(
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} ref={ref} border={border} />
);
},
);

0 comments on commit a56ae2b

Please sign in to comment.