Files
oranguru/src/Former/FormerWrappers.tsx
Hein e777e1fa3a chore(form): 🗑️ remove unused form components and types
* Refactor Former components to streamline functionality
* Update stories to reflect changes in form structure
2026-01-14 21:56:55 +02:00

117 lines
3.0 KiB
TypeScript

import {
Drawer,
type DrawerProps,
Modal,
type ModalProps,
Popover,
type PopoverProps,
} from '@mantine/core';
import type { FormerProps } from './Former.types';
import { Former } from './Former';
export const FormerDialog = (props: { former: FormerProps } & DrawerProps) => {
const { children, former, onClose, opened, ...rest } = props;
return (
<Former
{...former}
onClose={onClose}
opened={opened}
wrapper={(children, opened, onClose, _onOpen, getState) => {
const values = getState('values');
const request = getState('request');
const uniqueKeyField = getState('uniqueKeyField') ?? 'id';
return (
<Drawer
closeOnClickOutside={false}
h={'100%'}
title={
request === 'delete'
? `Delete Record - ${values?.[uniqueKeyField]}`
: request === 'insert'
? 'New Record'
: `Edit Record - ${values?.[uniqueKeyField]}`
}
{...rest}
onClose={() => onClose?.()}
opened={opened ?? false}
>
{children}
</Drawer>
);
}}
>
{children}
</Former>
);
};
export const FormerModel = (props: { former: FormerProps } & ModalProps) => {
const { children, former, onClose, opened, ...rest } = props;
return (
<Former
{...former}
onClose={onClose}
opened={opened}
wrapper={(children, opened, onClose, _onOpen, getState) => {
const values = getState('values');
const request = getState('request');
const uniqueKeyField = getState('uniqueKeyField') ?? 'id';
return (
<Modal
closeOnClickOutside={false}
h={'100%'}
title={
request === 'delete'
? `Delete Record - ${values?.[uniqueKeyField]}`
: request === 'insert'
? 'New Record'
: `Edit Record - ${values?.[uniqueKeyField]}`
}
{...rest}
onClose={() => onClose?.()}
opened={opened ?? false}
>
{children}
</Modal>
);
}}
>
{children}
</Former>
);
};
export const FormerPopover = (
props: { former: FormerProps; target: React.ReactNode } & PopoverProps
) => {
const { children, former, onClose, opened, target, ...rest } = props;
return (
<Former
{...former}
onClose={onClose}
opened={opened}
wrapper={(children, opened, onClose) => {
return (
<Popover
closeOnClickOutside={false}
middlewares={{ inline: true }}
trapFocus
width={250}
withArrow
{...rest}
onClose={() => onClose?.()}
opened={opened ?? false}
>
<Popover.Target>{target}</Popover.Target>
<Popover.Dropdown>{children}</Popover.Dropdown>
</Popover>
);
}}
>
{children}
</Former>
);
};