2022-06-01 14:04:58 +00:00
|
|
|
import {
|
2022-07-12 02:25:25 +00:00
|
|
|
ModalButtonBar,
|
2022-06-01 14:04:58 +00:00
|
|
|
ModalContent,
|
|
|
|
|
ModalOverlay,
|
|
|
|
|
ModalRoot,
|
2022-07-12 02:25:25 +00:00
|
|
|
ModalTitleBar,
|
2022-06-01 14:04:58 +00:00
|
|
|
} from '../elements/ModalPrimitives'
|
2023-01-18 10:16:30 +00:00
|
|
|
import { Box, VStack } from '../elements/LayoutPrimitives'
|
2022-06-01 14:04:58 +00:00
|
|
|
import { StyledText } from '../elements/StyledText'
|
2022-06-02 13:34:17 +00:00
|
|
|
import { useState } from 'react'
|
2022-06-03 08:23:05 +00:00
|
|
|
import { FormInputProps, GeneralFormInput } from '../elements/FormElements'
|
2022-06-01 14:04:58 +00:00
|
|
|
|
2022-06-01 14:28:46 +00:00
|
|
|
export interface FormModalProps {
|
2022-06-01 14:04:58 +00:00
|
|
|
inputs?: FormInputProps[]
|
|
|
|
|
title: string
|
|
|
|
|
acceptButtonLabel?: string
|
|
|
|
|
onSubmit: () => void
|
|
|
|
|
onOpenChange: (open: boolean) => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function FormModal(props: FormModalProps): JSX.Element {
|
2022-06-02 13:34:17 +00:00
|
|
|
const [inputs, setInputs] = useState<FormInputProps[]>(props.inputs || [])
|
|
|
|
|
|
2022-06-01 14:04:58 +00:00
|
|
|
return (
|
|
|
|
|
<ModalRoot defaultOpen onOpenChange={props.onOpenChange}>
|
|
|
|
|
<ModalOverlay />
|
2022-06-03 02:42:00 +00:00
|
|
|
<ModalContent
|
|
|
|
|
onPointerDownOutside={(event) => {
|
|
|
|
|
event.preventDefault()
|
|
|
|
|
props.onOpenChange(false)
|
|
|
|
|
}}
|
2022-07-12 01:14:19 +00:00
|
|
|
css={{ overflow: 'auto', px: '24px' }}
|
2022-06-03 02:42:00 +00:00
|
|
|
>
|
|
|
|
|
<VStack>
|
2023-01-18 10:16:30 +00:00
|
|
|
<ModalTitleBar
|
|
|
|
|
title={props.title}
|
|
|
|
|
onOpenChange={props.onOpenChange}
|
|
|
|
|
/>
|
2022-06-03 02:42:00 +00:00
|
|
|
<Box css={{ width: '100%' }}>
|
2022-06-01 14:28:46 +00:00
|
|
|
<form
|
|
|
|
|
onSubmit={(event) => {
|
|
|
|
|
event.preventDefault()
|
|
|
|
|
props.onSubmit()
|
|
|
|
|
props.onOpenChange(false)
|
|
|
|
|
}}
|
|
|
|
|
>
|
2022-06-02 13:34:17 +00:00
|
|
|
{inputs.map((input, index) => (
|
2022-07-12 01:14:19 +00:00
|
|
|
<VStack key={index}>
|
2023-01-18 10:16:30 +00:00
|
|
|
<StyledText
|
|
|
|
|
style={'menuTitle'}
|
|
|
|
|
css={{ pt: index > 0 ? '10px' : 'unset' }}
|
|
|
|
|
>
|
2022-07-12 02:25:25 +00:00
|
|
|
{input.label}
|
2023-01-18 10:16:30 +00:00
|
|
|
</StyledText>
|
2022-07-12 01:14:19 +00:00
|
|
|
<Box css={{ width: '100%' }}>
|
2022-06-03 08:23:05 +00:00
|
|
|
<GeneralFormInput {...input} />
|
2022-06-03 02:42:00 +00:00
|
|
|
</Box>
|
2022-07-12 01:14:19 +00:00
|
|
|
</VStack>
|
2022-06-01 14:04:58 +00:00
|
|
|
))}
|
2023-01-18 10:16:30 +00:00
|
|
|
<ModalButtonBar
|
|
|
|
|
onOpenChange={props.onOpenChange}
|
|
|
|
|
acceptButtonLabel={props.acceptButtonLabel}
|
|
|
|
|
/>
|
2022-06-01 14:04:58 +00:00
|
|
|
</form>
|
|
|
|
|
</Box>
|
|
|
|
|
</VStack>
|
|
|
|
|
</ModalContent>
|
|
|
|
|
</ModalRoot>
|
|
|
|
|
)
|
|
|
|
|
}
|