import { Button, Checkbox, FormControlLabel, styled } from '@mui/material'; import { Banner } from 'component/banners/Banner/Banner'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { FormSwitch } from 'component/common/FormSwitch/FormSwitch'; import GeneralSelect from 'component/common/GeneralSelect/GeneralSelect'; import { HelpIcon } from 'component/common/HelpIcon/HelpIcon'; import Input from 'component/common/Input/Input'; import { BannerVariant } from 'interfaces/banner'; import { ChangeEvent, Dispatch, SetStateAction, useState } from 'react'; import Visibility from '@mui/icons-material/Visibility'; import { BannerDialog } from 'component/banners/Banner/BannerDialog/BannerDialog'; const StyledForm = styled('div')(({ theme }) => ({ display: 'flex', flexDirection: 'column', gap: theme.spacing(4), })); const StyledBannerPreview = styled('div')(({ theme }) => ({ display: 'flex', flexDirection: 'column', alignItems: 'center', padding: theme.spacing(1.5), gap: theme.spacing(1.5), border: `1px solid ${theme.palette.divider}`, borderRadius: theme.shape.borderRadiusMedium, })); const StyledBannerPreviewDescription = styled('p')(({ theme }) => ({ fontSize: theme.fontSizes.smallBody, color: theme.palette.text.secondary, })); const StyledRaisedSection = styled('div')(({ theme }) => ({ background: theme.palette.background.elevation1, padding: theme.spacing(2, 3), borderRadius: theme.shape.borderRadiusLarge, })); const StyledSection = styled('div')(({ theme }) => ({ display: 'flex', flexDirection: 'column', gap: theme.spacing(1.5), })); const StyledSectionLabel = styled('p')(({ theme }) => ({ fontWeight: theme.fontWeight.bold, })); const StyledFieldGroup = styled('div')(({ theme }) => ({ display: 'flex', flexDirection: 'column', gap: theme.spacing(1), })); const StyledInputDescription = styled('p')(({ theme }) => ({ display: 'flex', color: theme.palette.text.primary, })); const StyledInput = styled(Input)({ width: '100%', }); const StyledTooltip = styled('div')(({ theme }) => ({ display: 'flex', flexDirection: 'column', padding: theme.spacing(0.5), gap: theme.spacing(0.5), })); const StyledSelect = styled(GeneralSelect)(({ theme }) => ({ width: '100%', maxWidth: theme.spacing(50), })); const StyledPreviewButton = styled(Button)(({ theme }) => ({ marginRight: 'auto', })); const VARIANT_OPTIONS = [ { key: 'info', label: 'Information' }, { key: 'warning', label: 'Warning' }, { key: 'error', label: 'Error' }, { key: 'success', label: 'Success' }, ]; type IconOption = 'Default' | 'Custom' | 'None'; type LinkOption = 'Link' | 'Dialog' | 'None'; interface IBannerFormProps { enabled: boolean; message: string; variant: BannerVariant; sticky: boolean; icon: string; link: string; linkText: string; dialogTitle: string; dialog: string; setEnabled: Dispatch>; setMessage: Dispatch>; setVariant: Dispatch>; setSticky: Dispatch>; setIcon: Dispatch>; setLink: Dispatch>; setLinkText: Dispatch>; setDialogTitle: Dispatch>; setDialog: Dispatch>; } export const BannerForm = ({ enabled, message, variant, sticky, icon, link, linkText, dialogTitle, dialog, setEnabled, setMessage, setVariant, setSticky, setIcon, setLink, setLinkText, setDialogTitle, setDialog, }: IBannerFormProps) => { const [previewDialogOpen, setPreviewDialogOpen] = useState(false); const [iconOption, setIconOption] = useState( icon === '' ? 'Default' : icon === 'none' ? 'None' : 'Custom', ); const [linkOption, setLinkOption] = useState( link === '' ? 'None' : link === 'dialog' ? 'Dialog' : 'Link', ); return ( Banner preview: Banner status Configuration What type of banner is it? setVariant(variant as BannerVariant) } options={VARIANT_OPTIONS} /> What icon should be displayed on the banner? { setIconOption(iconOption as IconOption); if (iconOption === 'None') { setIcon('none'); } else { setIcon(''); } }} options={['Default', 'Custom', 'None'].map( (option) => ({ key: option, label: option, }), )} /> Which custom icon?

Choose an icon from{' '} Material Symbols .

For example, if you want to display the "Rocket Launch" icon, you can enter "rocket_launch" in the field below.

} />
) => setIcon(e.target.value) } autoComplete='off' /> } /> What is your banner message?

Markdown {' '} is supported.

} />
) => setMessage(e.target.value) } autoComplete='off' required />
Banner action What action should be available in the banner? { setLinkOption(linkOption as LinkOption); if (linkOption === 'Dialog') { setLink('dialog'); } else { setLink(''); } setLinkText(''); setDialogTitle(''); setDialog(''); }} options={['None', 'Link', 'Dialog'].map((option) => ({ key: option, label: option, }))} /> What URL should be opened? ) => setLink(e.target.value) } onBlur={() => { if (!linkText) setLinkText(link); }} autoComplete='off' /> } /> What is the action text? ) => setLinkText(e.target.value) } autoComplete='off' /> } /> What is the dialog title? , ) => setDialogTitle(e.target.value)} autoComplete='off' /> What is the dialog content?

Markdown {' '} is supported.

} />
, ) => setDialog(e.target.value)} autoComplete='off' />
} onClick={() => setPreviewDialogOpen(true)} > Preview dialog {dialog!} } />
Sticky banner setSticky(e.target.checked)} /> } label='Make the banner sticky on the screen when scrolling' />
); };