From c086e55f898081abb421dc9c40d1e7b21407b8db Mon Sep 17 00:00:00 2001 From: fritzschoff Date: Tue, 26 Apr 2022 16:23:07 +0100 Subject: [PATCH] fix(card): fixed card border --- src/components/Card.tsx | 26 ++++++++++++++++++-------- stories/Card.stories.tsx | 21 +++++++++++++++++---- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/components/Card.tsx b/src/components/Card.tsx index b5431a9..9c7c9e4 100644 --- a/src/components/Card.tsx +++ b/src/components/Card.tsx @@ -1,10 +1,14 @@ -import React, { PropsWithChildren } from 'react'; +import React, { HTMLAttributes, PropsWithChildren } from 'react'; import styled from 'styled-components'; import colors from '../styles/colors'; import { Colors } from '../types'; -interface CardProps { - withBorderColor?: { color: Colors; withGlow: boolean }; +interface CardProps extends HTMLAttributes { + withBorderColor?: { + color?: Colors; + gradient?: keyof typeof colors.gradients; + withGlow?: boolean; + }; withBackgroundColor?: Colors; } @@ -17,6 +21,7 @@ export default function Card({ if (withBorderColor) { return ( + {children} @@ -37,20 +42,25 @@ export default function Card({ return {children}; } -const StyledGradientWrapper = styled.div<{ withBorderColor?: Colors; withGlow: boolean }>` +const StyledGradientWrapper = styled.div<{ + withBorderColor?: Colors; + withGlow?: boolean; + withBorderGradient?: keyof typeof colors.gradients; +}>` width: 100%; height: 100%; - background: ${({ withBorderColor }) => withBorderColor}; + background: ${({ withBorderColor, withBorderGradient }) => + withBorderColor ? withBorderColor : withBorderGradient && colors.gradients[withBorderGradient]}; box-shadow: ${({ withBorderColor, withGlow }) => withGlow && `0 0 10px ${withBorderColor}`}; padding: 1px; border-radius: 4px; `; -const StyledBackgroundWrapper = styled.div<{ color: Colors }>` +const StyledBackgroundWrapper = styled.div<{ backgroundColor: Colors }>` width: 100%; height: 100%; border-radius: 5px; - background: ${({ color }) => colors[color]}; + background: ${({ backgroundColor }) => colors[backgroundColor]}; padding: 1px; border-radius: 4px; `; diff --git a/stories/Card.stories.tsx b/stories/Card.stories.tsx index ac2e235..53296d6 100644 --- a/stories/Card.stories.tsx +++ b/stories/Card.stories.tsx @@ -12,19 +12,32 @@ export default { export const Template: ComponentStory = (args) => (
- +
+); + +export const WithBorderColor: ComponentStory = (args) => ( +
); Template.args = { + withBorderColor: { gradient: 'rainbow', withGlow: true }, + children: [ +
+
hello
,
world
, +
, + , + ], +}; + +WithBorderColor.args = { + withBackgroundColor: 'lightBlue', children: [
- {' '}
hello
,
world
,
, -
hello
, -
world
, + , ], };