-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): add base card list (#233)
* feat(client): add base card list * fix(client): add specific date for fields stories
- Loading branch information
1 parent
ae6c905
commit a7979b0
Showing
16 changed files
with
295 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import styled from 'styled-components'; | ||
|
||
import { IconButton } from '../buttons'; | ||
import Card from '../Card'; | ||
|
||
export const Wrapper = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
align-items: flex-start; | ||
flex-wrap: wrap; | ||
`; | ||
|
||
export const StyledCard = styled(Card)` | ||
position: relative; | ||
width: 100%; | ||
max-width: 340px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: flex-start; | ||
flex-direction: column; | ||
padding: 24px; | ||
> * { | ||
display: block; | ||
margin-top: 20px; | ||
} | ||
> *:first-child, | ||
*:nth-child(2) { | ||
margin-top: 0; | ||
} | ||
${({ theme: { down, breakpoints } }) => ` | ||
${down(breakpoints.md)} { | ||
max-width: 100%; | ||
} | ||
`}; | ||
`; | ||
|
||
export const FiltersButton = styled(IconButton)` | ||
svg { | ||
color: ${({ theme }) => theme.palette.primary.light}; | ||
} | ||
`; | ||
|
||
export const EditButton = styled(IconButton)` | ||
position: absolute; | ||
top: 10px; | ||
right: 10px; | ||
svg { | ||
color: ${({ theme }) => theme.palette.text.primary}; | ||
} | ||
`; | ||
|
||
export const CardsWrapper = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
align-items: flex-start; | ||
flex-wrap: wrap; | ||
> *:not(:last-child) { | ||
margin-bottom: 40px; | ||
} | ||
${({ theme: { up, breakpoints } }) => ` | ||
${up(breakpoints.md)} { | ||
> *:nth-child(2n + 1) { | ||
margin-right: 40px; | ||
} | ||
} | ||
`}; | ||
`; | ||
|
||
export const TitleWrapper = styled.div` | ||
* { | ||
font-size: 24px; | ||
line-height: 23px; | ||
font-weight: 700; | ||
} | ||
`; | ||
|
||
export const FiltersContainer = styled.div` | ||
display: flex; | ||
width: 100%; | ||
padding: 40px 20px; | ||
justify-content: space-between; | ||
align-items: center; | ||
max-width: 740px; | ||
`; | ||
|
||
export const CardFieldContainer = styled.div` | ||
display: flex; | ||
`; |
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,6 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
interface CardListProps { | ||
children: ReactNode; | ||
resource: string; | ||
} |
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,80 @@ | ||
import React, { Children, cloneElement, isValidElement } from 'react'; | ||
import { useQuery } from 'react-query'; | ||
import { useHistory } from 'react-router-dom'; | ||
|
||
import { routes } from '../../constants'; | ||
import { EditIcon, FiltersIcon } from '../../icons'; | ||
import { ApiList } from '../../interfaces/api.types'; | ||
import { getLabelFromSource } from '../../utils'; | ||
import { BaseFieldProps, BaseRecordField } from '../fields/Fields.types'; | ||
import { | ||
CardFieldContainer, | ||
CardsWrapper, | ||
EditButton, | ||
FiltersButton, | ||
FiltersContainer, | ||
StyledCard, | ||
TitleWrapper, | ||
Wrapper, | ||
} from './CardList.styled'; | ||
import { CardListProps } from './CardList.types'; | ||
|
||
const CardList = ({ children, resource }: CardListProps) => { | ||
const queryResult = useQuery<ApiList<BaseRecordField>>(`/${resource}`); | ||
const records = queryResult.data?.data; | ||
const history = useHistory(); | ||
|
||
const onClickEdit = (id: string) => { | ||
// TODO: move to user details | ||
console.log(id); | ||
history.push(routes.authorized.appBar.admin.USERS); | ||
}; | ||
|
||
return ( | ||
<Wrapper data-testid="cardList"> | ||
<FiltersContainer> | ||
{/* TODO: add search input */} | ||
<p>Search</p> | ||
<FiltersButton> | ||
<FiltersIcon /> | ||
</FiltersButton> | ||
</FiltersContainer> | ||
<CardsWrapper> | ||
{records?.map((record) => { | ||
const { id } = record; | ||
return ( | ||
<StyledCard key={id}> | ||
<EditButton onClick={() => onClickEdit(id)}> | ||
<EditIcon /> | ||
</EditButton> | ||
{Children.map(children, (child) => { | ||
if (!isValidElement(child)) { | ||
return null; | ||
} | ||
|
||
const { source, asTitle, label, noLabel } = child.props as BaseFieldProps<unknown>; | ||
|
||
if (asTitle) { | ||
return <TitleWrapper>{cloneElement(child, { record })}</TitleWrapper>; | ||
} | ||
|
||
const internalLabel = label || getLabelFromSource(source || ''); | ||
|
||
return ( | ||
<CardFieldContainer key={`${id}-${source}`}> | ||
{!noLabel && <p>{internalLabel}: </p>} | ||
{cloneElement(child, { record })} | ||
</CardFieldContainer> | ||
); | ||
})} | ||
</StyledCard> | ||
); | ||
})} | ||
</CardsWrapper> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
CardList.displayName = 'CardList'; | ||
|
||
export default CardList; |
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { forwardRef, memo, Ref, SVGProps } from 'react'; | ||
import { useTheme } from 'styled-components'; | ||
|
||
const EditIcon = (props: SVGProps<SVGSVGElement>, svgRef?: Ref<SVGSVGElement>) => { | ||
const { palette } = useTheme(); | ||
return ( | ||
<svg | ||
width="32" | ||
height="33" | ||
viewBox="0 0 32 33" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
ref={svgRef} | ||
{...props} | ||
> | ||
<path | ||
d="M27.4367 2.04214L30.3368 4.94231C31.1179 5.72335 31.1179 6.98969 30.3368 7.77073L12.3687 25.7389L5.2849 28.3805C4.48208 28.6798 3.69915 27.8969 3.99853 27.0941L6.64007 20.0103L24.6082 2.04214C25.3893 1.26109 26.6556 1.26109 27.4367 2.04214Z" | ||
fill="currentColor" | ||
/> | ||
<rect | ||
x="22.1641" | ||
y="3.24976" | ||
width="10" | ||
height="3.06086" | ||
transform="rotate(45 22.1641 3.24976)" | ||
fill={palette.background.paper} | ||
/> | ||
</svg> | ||
); | ||
}; | ||
|
||
export default memo(forwardRef(EditIcon)); |
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,20 @@ | ||
import React, { forwardRef, memo, Ref, SVGProps } from 'react'; | ||
|
||
const FiltersIcon = (props: SVGProps<SVGSVGElement>, svgRef?: Ref<SVGSVGElement>) => ( | ||
<svg | ||
width="29" | ||
height="31" | ||
viewBox="0 0 24 26" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
ref={svgRef} | ||
{...props} | ||
> | ||
<path | ||
d="M22.6667 0H1.33333C0.596 0 0 0.596 0 1.33333V4.78667C0 5.484 0.284 6.16933 0.777333 6.66267L8 13.8853V24C8 24.4627 8.24 24.8907 8.63333 25.1347C8.84667 25.2667 9.08933 25.3333 9.33333 25.3333C9.53733 25.3333 9.74133 25.2867 9.92933 25.1933L15.2627 22.5267C15.7147 22.3 16 21.8387 16 21.3333V13.8853L23.2227 6.66267C23.716 6.16933 24 5.484 24 4.78667V1.33333C24 0.596 23.404 0 22.6667 0ZM13.724 12.3907C13.4733 12.64 13.3333 12.9787 13.3333 13.3333V20.5093L10.6667 21.8427V13.3333C10.6667 12.9787 10.5267 12.64 10.276 12.3907L2.66667 4.78667V2.66667H21.3347L21.3373 4.77733L13.724 12.3907Z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
); | ||
|
||
export default memo(forwardRef(FiltersIcon)); |
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
Oops, something went wrong.