-
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.
TILA-1851 reservation unit redux (#379)
* TILA-1851 reservation unit redux * TILA-1851 cleanup * TILA-1851 additional tests
- Loading branch information
1 parent
b5fdb9d
commit 51bb9d2
Showing
39 changed files
with
2,108 additions
and
2,379 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
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,72 @@ | ||
import { Button, IconAngleDown, IconAngleUp } from "hds-react"; | ||
import React, { useMemo, useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import styled from "styled-components"; | ||
import { EquipmentType } from "../../modules/gql-types"; | ||
import { getEquipmentList } from "../../modules/reservationUnit"; | ||
import { breakpoint } from "../../modules/style"; | ||
|
||
type Props = { | ||
equipment: EquipmentType[]; | ||
itemsToShow?: number; | ||
}; | ||
|
||
const Wrapper = styled.div``; | ||
|
||
const List = styled.ul` | ||
list-style: none; | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
gap: var(--spacing-2-xs) var(--spacing-m); | ||
padding: 0; | ||
@media (min-width: ${breakpoint.s}) { | ||
grid-template-columns: 1fr 1fr; | ||
row-gap: var(--spacing-s); | ||
} | ||
`; | ||
|
||
const EquipmentItem = styled.li` | ||
font-size: var(--fontsize-body-m); | ||
@media (min-width: ${breakpoint.s}) { | ||
font-size: var(--fontsize-body-l); | ||
} | ||
`; | ||
|
||
const ToggleButton = styled(Button)` | ||
font-size: var(--fontsize-body-m); | ||
`; | ||
|
||
const EquipmentList = ({ equipment, itemsToShow = 6 }: Props): JSX.Element => { | ||
const { t } = useTranslation(); | ||
|
||
const [showAll, setShowAll] = useState(false); | ||
|
||
const equipmentList = useMemo(() => { | ||
const items = showAll ? equipment : equipment.slice(0, itemsToShow); | ||
return getEquipmentList(items); | ||
}, [equipment, showAll, itemsToShow]); | ||
|
||
return ( | ||
<Wrapper> | ||
<List> | ||
{equipmentList.map((item) => ( | ||
<EquipmentItem key={item}>{item}</EquipmentItem> | ||
))} | ||
</List> | ||
{itemsToShow < equipment.length && ( | ||
<ToggleButton | ||
variant="supplementary" | ||
size="small" | ||
onClick={() => setShowAll(!showAll)} | ||
iconRight={showAll ? <IconAngleUp /> : <IconAngleDown />} | ||
> | ||
{t(`common:show${showAll ? "Less" : "More"}`)} | ||
</ToggleButton> | ||
)} | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export default EquipmentList; |
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.