-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #764 from Amsterdam/WON-67-update-wonen-ui-expanda…
…ble-content Add ExpandableContainer component and integrate it into HolidayRental…
- Loading branch information
Showing
7 changed files
with
326 additions
and
206 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/components/Data/ExpandableContainer/ExpandableContainer.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,74 @@ | ||
import React, { ReactNode, useState } from "react" | ||
import styled from "styled-components" | ||
import { Button, Icon } from "@amsterdam/asc-ui" | ||
import { ExpandMore } from "../../Icons" | ||
|
||
export type StyleProps = { | ||
isOpen?: boolean | ||
} & React.AnchorHTMLAttributes<HTMLAnchorElement> & | ||
React.HTMLAttributes<HTMLDivElement>; | ||
|
||
export const StyledExpandableButton = styled(Button)<StyleProps>` | ||
position: relative; | ||
width: 100%; | ||
height: initial; | ||
background-color: transparent; | ||
padding: 12px 0; | ||
font-size: 18px; | ||
&:hover, | ||
&:focus { | ||
background-color: transparent; | ||
} | ||
span { | ||
span { | ||
transform: rotate(${ ({ isOpen }) => (isOpen ? "180deg" : "0deg") }); | ||
transition: transform 0.3s ease; | ||
} | ||
} | ||
` | ||
|
||
export const StyledExpandableContent = styled.div<StyleProps>` | ||
transition: opacity 0.3s ease-in-out, max-height 0.3s ease-in-out; | ||
opacity: ${ ({ isOpen }) => (isOpen ? 1 : 0) }; | ||
max-height: ${ ({ isOpen }) => (isOpen ? "1000px" : "0") }; | ||
overflow: hidden; | ||
position: relative; | ||
` | ||
|
||
const StyledDiv = styled.div` | ||
margin-bottom: 12px; | ||
` | ||
|
||
type Props = { | ||
title: string | ||
children: ReactNode | ||
defaultOpen?: boolean | ||
} | ||
|
||
const ExpandableContainer: React.FC<Props> = ({ title, children, defaultOpen = false }) => { | ||
const [open, setOpen] = useState(defaultOpen) | ||
|
||
const onClick = () => { | ||
setOpen(!open) | ||
} | ||
|
||
return ( | ||
<StyledDiv> | ||
<StyledExpandableButton | ||
aria-expanded={open} | ||
isOpen={open} | ||
type="button" | ||
variant="blank" | ||
iconRight={<Icon size={20}><ExpandMore /></Icon>} | ||
onClick={onClick} | ||
> | ||
{ title } | ||
</StyledExpandableButton> | ||
<StyledExpandableContent isOpen={open}> | ||
{ children } | ||
</StyledExpandableContent> | ||
</StyledDiv> | ||
) | ||
} | ||
|
||
export default ExpandableContainer |
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
29 changes: 14 additions & 15 deletions
29
src/components/HolidayRentalRegistrations/components/Registration.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
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.