104 lines
3.1 KiB
TypeScript
104 lines
3.1 KiB
TypeScript
import {
|
|
ModalContent,
|
|
ModalOverlay,
|
|
ModalRoot,
|
|
} from '../elements/ModalPrimitives'
|
|
import { Box, HStack, VStack } from '../elements/LayoutPrimitives'
|
|
import { Button } from '../elements/Button'
|
|
import { StyledText } from '../elements/StyledText'
|
|
import { useState } from 'react'
|
|
import { FormInputProps, GeneralFormInput } from '../elements/FormElements'
|
|
import { theme } from '../tokens/stitches.config'
|
|
import { X } from 'phosphor-react'
|
|
|
|
export interface FormModalProps {
|
|
inputs?: FormInputProps[]
|
|
title: string
|
|
acceptButtonLabel?: string
|
|
onSubmit: () => void
|
|
onOpenChange: (open: boolean) => void
|
|
}
|
|
|
|
export function FormModal(props: FormModalProps): JSX.Element {
|
|
const [inputs, setInputs] = useState<FormInputProps[]>(props.inputs || [])
|
|
|
|
return (
|
|
<ModalRoot defaultOpen onOpenChange={props.onOpenChange}>
|
|
<ModalOverlay />
|
|
<ModalContent
|
|
onPointerDownOutside={(event) => {
|
|
event.preventDefault()
|
|
props.onOpenChange(false)
|
|
}}
|
|
css={{ overflow: 'auto', px: '24px' }}
|
|
>
|
|
<VStack>
|
|
<HStack
|
|
distribution="between"
|
|
alignment="center"
|
|
css={{ height: '68px', width: '100%' }}
|
|
>
|
|
<StyledText style="modalHeadline" css={{ }}>
|
|
{props.title}
|
|
</StyledText>
|
|
<Button
|
|
css={{ ml: 'auto' }}
|
|
style="ghost"
|
|
onClick={() => {
|
|
props.onOpenChange(false)
|
|
}}
|
|
>
|
|
<X
|
|
size={24}
|
|
color={theme.colors.textNonessential.toString()}
|
|
/>
|
|
</Button>
|
|
</HStack>
|
|
|
|
<Box css={{ width: '100%' }}>
|
|
<form
|
|
onSubmit={(event) => {
|
|
event.preventDefault()
|
|
props.onSubmit()
|
|
props.onOpenChange(false)
|
|
}}
|
|
>
|
|
{inputs.map((input, index) => (
|
|
<VStack key={index}>
|
|
<StyledText style={'menuTitle'} css={{ pt: index > 0 ? '10px' : 'unset' }}>
|
|
{input.label}
|
|
</StyledText>
|
|
<Box css={{ width: '100%' }}>
|
|
<GeneralFormInput {...input} />
|
|
</Box>
|
|
</VStack>
|
|
))}
|
|
<HStack
|
|
alignment="center"
|
|
distribution="end"
|
|
css={{
|
|
gap: '10px',
|
|
width: '100%',
|
|
height: '80px',
|
|
}}
|
|
>
|
|
<Button style={'ctaOutlineYellow'} type="button" onClick={(event) => {
|
|
console.log('cancelinmg')
|
|
event.preventDefault()
|
|
props.onOpenChange(false)
|
|
}}
|
|
>
|
|
{'Cancel'}
|
|
</Button>
|
|
<Button style={'ctaDarkYellow'}>
|
|
{props.acceptButtonLabel || 'Submit'}
|
|
</Button>
|
|
</HStack>
|
|
</form>
|
|
</Box>
|
|
</VStack>
|
|
</ModalContent>
|
|
</ModalRoot>
|
|
)
|
|
}
|