-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Condensed list card components. Apply to ItemsListing page
- Loading branch information
Showing
9 changed files
with
493 additions
and
67 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
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
113 changes: 113 additions & 0 deletions
113
frontends/ol-components/src/components/Card/ListCardCondensed.tsx
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,113 @@ | ||
import React, { FC, ReactNode, Children, isValidElement } from "react" | ||
import styled from "@emotion/styled" | ||
import { theme } from "../ThemeProvider/ThemeProvider" | ||
import { Wrapper } from "./Card" | ||
import { TruncateText } from "../TruncateText/TruncateText" | ||
import { | ||
ListCard, | ||
Body as BaseBody, | ||
LinkContainer, | ||
Container, | ||
Info as BaseInfo, | ||
Title as BaseTitle, | ||
Footer, | ||
Actions as BaseActions, | ||
Bottom as BaseBottom, | ||
} from "./ListCard" | ||
import type { Card as BaseCard } from "./ListCard" | ||
|
||
const Body = styled(BaseBody)` | ||
margin: 16px; | ||
${theme.breakpoints.down("md")} { | ||
margin: 16px; | ||
} | ||
` | ||
|
||
const Info = styled(BaseInfo)` | ||
margin-bottom: 4px; | ||
` | ||
|
||
const Title = styled(BaseTitle)` | ||
height: auto; | ||
margin-bottom: 8px; | ||
margin-right: 82px; | ||
${theme.breakpoints.down("md")} { | ||
height: auto; | ||
${{ ...theme.typography.subtitle2 }} | ||
} | ||
` | ||
|
||
const Bottom = styled(BaseBottom)` | ||
height: auto; | ||
${theme.breakpoints.down("md")} { | ||
height: auto; | ||
} | ||
` | ||
export const Actions = styled(BaseActions)` | ||
bottom: 16px; | ||
right: 16px; | ||
gap: 16px; | ||
${theme.breakpoints.down("md")} { | ||
bottom: 16px; | ||
right: 16px; | ||
gap: 16px; | ||
} | ||
` | ||
const Content = () => <></> | ||
|
||
type CardProps = { | ||
children: ReactNode[] | ReactNode | ||
className?: string | ||
href?: string | ||
} | ||
|
||
type Card = FC<CardProps> & Omit<BaseCard, "Image"> | ||
|
||
const ListCardCondensed: Card = ({ children, className, href }) => { | ||
const _Container = href ? LinkContainer : Container | ||
|
||
let content, info, title, footer, actions | ||
|
||
Children.forEach(children, (child) => { | ||
if (!isValidElement(child)) return | ||
if (child.type === Content) content = child.props.children | ||
else if (child.type === Info) info = child.props.children | ||
else if (child.type === Title) title = child.props.children | ||
else if (child.type === Footer) footer = child.props.children | ||
else if (child.type === Actions) actions = child.props.children | ||
}) | ||
|
||
if (content) { | ||
return ( | ||
<_Container className={className} to={href!}> | ||
{content} | ||
</_Container> | ||
) | ||
} | ||
|
||
return ( | ||
<Wrapper className={className}> | ||
<_Container to={href!}> | ||
<Body> | ||
<Info>{info}</Info> | ||
<Title> | ||
<TruncateText lineClamp={4}>{title}</TruncateText> | ||
</Title> | ||
<Bottom> | ||
<Footer>{footer}</Footer> | ||
</Bottom> | ||
</Body> | ||
</_Container> | ||
{actions && <Actions>{actions}</Actions>} | ||
</Wrapper> | ||
) | ||
} | ||
|
||
ListCardCondensed.Content = Content | ||
ListCardCondensed.Info = Info | ||
ListCardCondensed.Title = Title | ||
ListCardCondensed.Footer = Footer | ||
ListCardCondensed.Actions = Actions | ||
ListCardCondensed.Action = ListCard.Action | ||
|
||
export { ListCardCondensed } |
Oops, something went wrong.