Skip to content

Commit

Permalink
feat: downloadable asset card
Browse files Browse the repository at this point in the history
  • Loading branch information
jeangovil committed Oct 20, 2023
1 parent 0262fdd commit ab2106a
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import DiscordWhiteSvg from '../../static/icons/discord-white.svg'
import TelegramWhiteSvg from '../../static/icons/telegram-white.svg'
import XSvg from '../../static/icons/x.svg'
import Avatar from '../../static/icons/avatar.svg'
import DownloadSvg from '../../static/icons/download.svg'

type TIconProps = {
size?: 's' | 'm' | 'l'
Expand Down Expand Up @@ -227,3 +228,9 @@ export const IconAvatar = (props: TIconProps): JSX.Element => (
<Avatar />
</Icon>
)

export const IconDownload = (props: TIconProps): JSX.Element => (
<Icon {...props}>
<DownloadSvg />
</Icon>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
@use '../../../css/utils';
@use '../../../css/lsd';

.mdx-asset-card {
width: 216px;
display: flex;
flex-direction: column;
align-items: flex-start;
border: 1px solid rgb(var(--lsd-border-primary));
border-bottom: none;
text-decoration: none !important;
min-height: 144px;
}

.mdx-asset-card__inner {
width: 100%;
padding: 16px 16px 32px 16px;
}

.mdx-asset-card__title {
margin-bottom: 16px;
}

.mdx-asset-card__image {
img {
width: 100%;
height: 100%;
object-fit: contain;
object-position: center center;
}
}

.mdx-asset-card__downloadables {
width: 100%;
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: stretch;

& > * {
flex-grow: 1;
font-size: 12px;
text-decoration: none !important;
text-underline-offset: unset !important;

button {
width: 100%;
justify-content: space-between;
text-decoration: none;
}

&:first-child button {
border-left: none;
}

&:last-child button {
border-right: none;
}

&:not(:last-child) button {
border-right: none;
}
}
}

.mdx-asset-card:not(.mdx-asset-card--downloadable) {
.mdx-asset-card__inner {
border-bottom: 1px solid rgb(var(--lsd-border-primary));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { Button, Typography } from '@acid-info/lsd-react'
import clsx from 'clsx'
import React from 'react'
import { KeepRatio } from '../../KeepRatio'
import './AssetCard.scss'
import { IconDownload } from '../../Icon'

export type AssetCardProps = Omit<React.HTMLProps<HTMLDivElement>, 'title'> & {
title?: React.ReactNode
previewSrc: string
downloadable?: {
src: string
title: React.ReactNode
}[]
}

export const AssetCard: React.FC<AssetCardProps> = ({
title,
previewSrc,
downloadable,
...props
}) => {
const isDownloadable = downloadable && downloadable.length > 0

return (
<div
{...props}
className={clsx(
props.className,
'mdx-asset-card',
isDownloadable && 'mdx-asset-card--downloadable',
)}
>
<div className="mdx-asset-card__inner">
{title && (
<Typography
component="div"
variant="subtitle1"
className="mdx-asset-card__title"
>
{title}
</Typography>
)}
<KeepRatio
width={16}
height={9}
fullWidth
rootProps={{ className: 'mdx-asset-card__image' }}
>
<img
src={previewSrc}
alt={(typeof title === 'string' && title) || 'asset image'}
/>
</KeepRatio>
</div>
{
// TODO: use LSD ButtonGroup
}
{isDownloadable && (
<div className="mdx-asset-card__downloadables">
{downloadable.map((downloadable, index) => (
<a href={downloadable.src} download>
<Button
key={index}
variant="outlined"
size="small"
icon={<IconDownload />}
>
{downloadable.title}
</Button>
</a>
))}
</div>
)}
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './AssetCard'
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './AppCard'
export * from './AssetCard'
export * from './Box'
export * from './CallToActionButton'
export * from './CallToActionSection'
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ab2106a

Please sign in to comment.