-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Card ribbon * fix: Circular dependency problem * build: Card folder structure * chore: Updated stories, comments * refactor: Moved Pancake theme out of types to avoid circular dependencies
- Loading branch information
1 parent
5d5db86
commit 257a49c
Showing
11 changed files
with
194 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react"; | ||
import StyledCard from "./StyledCard"; | ||
import { CardProps } from "./types"; | ||
|
||
const Card: React.FC<CardProps> = ({ ribbon, children, ...props }) => { | ||
return ( | ||
<StyledCard {...props}> | ||
{ribbon} | ||
{children} | ||
</StyledCard> | ||
); | ||
}; | ||
export default Card; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from "react"; | ||
import styled, { DefaultTheme } from "styled-components"; | ||
import { CardRibbonProps } from "./types"; | ||
|
||
interface StyledCardRibbonProps extends CardRibbonProps { | ||
theme: DefaultTheme; | ||
} | ||
|
||
const StyledCardRibbon = styled.div<Partial<StyledCardRibbonProps>>` | ||
background-color: ${({ variantColor = "secondary", theme }) => theme.colors[variantColor]}; | ||
color: white; | ||
margin: 0; | ||
padding: 0; | ||
padding: 8px 0; | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
text-align: center; | ||
transform: translateX(30%) translateY(0%) rotate(45deg); | ||
transform-origin: top left; | ||
width: 112px; | ||
&:before, | ||
&:after { | ||
background-color: ${({ variantColor = "secondary", theme }) => theme.colors[variantColor]}; | ||
content: ""; | ||
height: 100%; | ||
margin: 0 -1px; /* Removes tiny gap */ | ||
position: absolute; | ||
top: 0; | ||
width: 100%; | ||
} | ||
&:before { | ||
right: 100%; | ||
} | ||
&:after { | ||
left: 100%; | ||
} | ||
& > div { | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
width: 112px; | ||
} | ||
`; | ||
|
||
const CardRibbon: React.FC<CardRibbonProps> = ({ variantColor, text }) => { | ||
return ( | ||
<StyledCardRibbon variantColor={variantColor}> | ||
<div title={text}>{text}</div> | ||
</StyledCardRibbon> | ||
); | ||
}; | ||
|
||
export default CardRibbon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import styled, { DefaultTheme } from "styled-components"; | ||
import { CardProps } from "./types"; | ||
|
||
interface StyledCardProps extends CardProps { | ||
theme: DefaultTheme; | ||
} | ||
|
||
/** | ||
* Priority: Warning --> Success --> Active | ||
*/ | ||
const getBoxShadow = ({ isActive, isSuccess, isWarning, theme }: StyledCardProps) => { | ||
if (isWarning) { | ||
return theme.card.boxShadowWarning; | ||
} | ||
|
||
if (isSuccess) { | ||
return theme.card.boxShadowSuccess; | ||
} | ||
|
||
if (isActive) { | ||
return theme.card.boxShadowActive; | ||
} | ||
|
||
return theme.card.boxShadow; | ||
}; | ||
|
||
const StyledCard = styled.div<StyledCardProps>` | ||
background-color: ${({ theme }) => theme.card.background}; | ||
border: ${({ theme }) => theme.card.boxShadow}; | ||
border-radius: 32px; | ||
box-shadow: ${getBoxShadow}; | ||
color: ${({ theme }) => theme.colors.text}; | ||
overflow: hidden; | ||
padding: 24px; | ||
position: relative; | ||
`; | ||
|
||
StyledCard.defaultProps = { | ||
isActive: false, | ||
isSuccess: false, | ||
isWarning: false, | ||
}; | ||
|
||
export default StyledCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,2 @@ | ||
import styled, { DefaultTheme } from "styled-components"; | ||
|
||
interface CardProps { | ||
isActive?: boolean; | ||
isSuccess?: boolean; | ||
isWarning?: boolean; | ||
theme: DefaultTheme; | ||
} | ||
|
||
/** | ||
* Priority: Warning --> Success --> Active | ||
*/ | ||
const getBoxShadow = ({ isActive, isSuccess, isWarning, theme }: CardProps) => { | ||
if (isWarning) { | ||
return theme.card.boxShadowWarning; | ||
} | ||
|
||
if (isSuccess) { | ||
return theme.card.boxShadowSuccess; | ||
} | ||
|
||
if (isActive) { | ||
return theme.card.boxShadowActive; | ||
} | ||
|
||
return theme.card.boxShadow; | ||
}; | ||
|
||
const Card = styled.div<CardProps>` | ||
background-color: ${({ theme }) => theme.card.background}; | ||
border: ${({ theme }) => theme.card.boxShadow}; | ||
border-radius: 32px; | ||
box-shadow: ${getBoxShadow}; | ||
color: ${({ theme }) => theme.colors.text}; | ||
padding: 24px; | ||
margin: 2px; | ||
`; | ||
|
||
Card.defaultProps = { | ||
isActive: false, | ||
isSuccess: false, | ||
isWarning: false, | ||
}; | ||
|
||
export default Card; | ||
export { default as Card } from "./Card"; | ||
export { default as CardRibbon } from "./CardRibbon"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
import { Colors } from "../../theme/types"; | ||
|
||
export interface CardRibbonProps { | ||
variantColor?: keyof Colors; | ||
text: string; | ||
} | ||
|
||
export type CardTheme = { | ||
background: string; | ||
boxShadow: string; | ||
boxShadowActive: string; | ||
boxShadowSuccess: string; | ||
boxShadowWarning: string; | ||
}; | ||
|
||
export interface CardProps { | ||
isActive?: boolean; | ||
isSuccess?: boolean; | ||
isWarning?: boolean; | ||
ribbon?: React.ReactNode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters