Skip to content

Commit

Permalink
Merge pull request #22 from Amsterdam/feature/modal-component
Browse files Browse the repository at this point in the history
Added Modal component
  • Loading branch information
remyvdwereld authored Aug 5, 2024
2 parents 66959fb + aeafde4 commit cab3887
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/app/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { ReactNode } from "react"
import styled from "styled-components"
import { Icon } from "@amsterdam/design-system-react"
import { CloseIcon } from "@amsterdam/design-system-react-icons"

type Props = {
title?: string
open?: boolean
onOk?: () => void
onCancel?: () => void
children?: ReactNode
}

const Wrapper = styled.div`
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgba(0, 0, 0, 0.5); /* Black with opacity */
`

const Container = styled.div`
background-color: white;
margin: 25% auto; /* 15% from the top and centered */
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
max-width: 500px;
box-shadow: 0px 0px 10px 2px rgba(0, 0, 0, 0.3);
border-radius: 10px;
`

const Heading = styled.div`
padding: 0 20px;
`

const StyledIcon = styled(Icon)`
float: right;
cursor: pointer;
&:hover,
&:focus {
opacity: 0.5;
text-decoration: none;
}
`

const Content = styled.div`
border-top: 1px solid #e0e0e0;
padding: 20px;
`

export const Modal: React.FC<Props> = ({ title, open = true, onCancel, children }) => open ? (
<Wrapper onClick={ onCancel }>
<Container
onClick={(e) => {
// do not close modal if anything inside modal content is clicked
e.stopPropagation()
}}
>
<Heading>
<StyledIcon
size="level-5"
svg={ CloseIcon }
onClick={ onCancel }
/>
<h2>{ title }</h2>
</Heading>
<Content>
{ children }
</Content>
</Container>
</Wrapper>
) : null

export default Modal
1 change: 1 addition & 0 deletions src/app/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./DefaultLayout/DefaultLayout"
export * from "./Modal/Modal"
export * from "./NavMenu/NavMenu"
export * from "./PageHeading/PageHeading"
export * from "./RouterLink/RouterLink"
Expand Down

0 comments on commit cab3887

Please sign in to comment.