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(Card): add Card component based on gbl-web #3

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
Binary file added .ladle/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/Card.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Card from './Card'

export const Default = () => (
<Card
backgroundSrc="https://www.gbl.uzh.ch/images/uploads/pfm_game.png"
tags={['DBF', 'Simulation', 'Investing']}
title="Portfolio Management Simulation"
onClick={() => null}
/>
)

export const ContentOnly = () => <Card />
75 changes: 75 additions & 0 deletions src/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { twMerge } from 'tailwind-merge'

import Button from './Button'

export interface CardProps {
backgroundSrc?: string
className?: string
disabled?: boolean
tags?: string[]
title?: string

onClick?: () => void
}

const defaultProps = {
disabled: false,
tags: [],
}

export function Card({
backgroundSrc,
className,
disabled,
tags,
title,
onClick,
}: CardProps) {
if (onClick) {
return (
<Button
fluid
disabled={disabled}
onClick={onClick}
className={twMerge(
'p-0 border-none outline outline-1 outline-uzh-grey-60',
className,
disabled
? 'cursor-default hover:bg-inherit hover:text-inherit hover:border-inherit'
: 'hover:shadow-lg hover:outline-uzh-red-100'
)}
>
<div className={twMerge('w-full h-full relative', 'min-h-[200px]')}>
{tags && tags.length > 0 && (
<div className="absolute top-0 z-10 flex flex-row flex-wrap gap-1 p-2">
{tags.map((tag) => (
<div>{tag}</div>
))}
</div>
)}

{title && (
<div className="absolute left-0 right-0 z-10 py-1 text-lg font-bold text-center bg-white bg-opacity-70 bottom-3">
{title}
</div>
)}

<img
className={twMerge(
'z-0 w-full rounded opacity-80',
'grayscale filter hover:filter-none'
)}
src={backgroundSrc}
alt={`Image of ${title}`}
/>
</div>
</Button>
)
}

return <div>hello</div>
}

Card.defaultProps = defaultProps

export default Card