Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add left position for card ribbon #68

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/pancake-uikit/src/components/Card/CardRibbon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ const StyledCardRibbon = styled.div<Partial<StyledCardRibbonProps>>`
padding: 0;
padding: 8px 0;
position: absolute;
right: 0;
right: ${({ ribbonPosition }) => (ribbonPosition === "right" ? 0 : "auto")};
top: 0;
text-align: center;
transform: translateX(30%) translateY(0%) rotate(45deg);
transform: ${({ ribbonPosition }) =>
ribbonPosition === "right"
? "translateX(30%) translateY(0%) rotate(45deg)"
: "translateX(0%) translateY(200%) rotate(-45deg)"};
transform-origin: top left;
width: 96px;

Expand Down Expand Up @@ -47,12 +51,16 @@ const StyledCardRibbon = styled.div<Partial<StyledCardRibbonProps>>`
}
`;

const CardRibbon: React.FC<CardRibbonProps> = ({ variantColor, text }) => {
const CardRibbon: React.FC<CardRibbonProps> = ({ variantColor, text, ribbonPosition }) => {
return (
<StyledCardRibbon variantColor={variantColor}>
<StyledCardRibbon variantColor={variantColor} ribbonPosition={ribbonPosition}>
<div title={text}>{text}</div>
</StyledCardRibbon>
);
};

CardRibbon.defaultProps = {
ribbonPosition: "right",
};

export default CardRibbon;
5 changes: 5 additions & 0 deletions packages/pancake-uikit/src/components/Card/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export const Ribbon: React.FC = () => {
<CardBody style={{ height: "150px" }}>Any Color in the theme</CardBody>
</Card>
</Row>
<Row>
<Card ribbon={<CardRibbon variantColor="failure" text="Failure" ribbonPosition="left" />}>
<CardBody style={{ height: "150px" }}>Any Color in the theme</CardBody>
</Card>
</Row>
</div>
);
};
1 change: 1 addition & 0 deletions packages/pancake-uikit/src/components/Card/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Colors } from "../../theme/types";
export interface CardRibbonProps {
variantColor?: keyof Colors;
text: string;
ribbonPosition?: "right" | "left";
}

export type CardTheme = {
Expand Down