Files
gitbook/packages/react-contentkit/src/ElementModal.tsx
T
Samy Pessé 70c6c9df42 First pass at implementing ContentKit (#69)
* Start

* Try webframe

* Lint and format

* Move to package

* Continue

* Implement card and cleanup contexts

* Start code blocks

* Start rendering image

* Continue with card

* Start stack

* Start text

* Start modal

* Format

* Continue

* Fix TS errors

* Cleanup

* Make markdown work with server components

* Format

* Add visual test

* Lint and format

* Fix lifecycle

* Implement textinput

* Divider

* Remove console logs

* Remove listSpaceIntegrationsBlocks
2024-02-28 14:46:47 +01:00

58 lines
1.8 KiB
TypeScript

'use client';
import { ContentKitModal } from '@gitbook/api';
import { ContentKitClientElementProps } from './types';
import classNames from 'classnames';
import { useContentKitClientContext } from './context';
import React from 'react';
export function ElementModal(
props: ContentKitClientElementProps<ContentKitModal> & {
subtitle: React.ReactNode | null;
children: React.ReactNode;
},
) {
const { element, subtitle, children } = props;
const clientContext = useContentKitClientContext();
// TODO:
// - close button
// - invalid rendering on close?
// - submit
const [opened, setOpened] = React.useState(false);
React.useEffect(() => {
setOpened(true);
}, []);
const onClose = async () => {
await clientContext.dispatchAction({
action: '@ui.modal.close',
returnValue: element.returnValue || {},
});
};
return (
<div className={classNames('contentkit-modal-backdrop')} onClick={onClose}>
<div
className={classNames(
'contentkit-modal',
opened ? 'contentkit-modal-opened' : null,
)}
onClick={(event) => {
event.stopPropagation();
}}
>
<div className={classNames('contentkit-modal-header')}>
{element.title ? (
<h1 className={classNames('contentkit-modal-title')}>{element.title}</h1>
) : null}
{subtitle ? <div className="contentkit-modal-subtitle">{subtitle}</div> : null}
</div>
<div className={classNames('contentkit-modal-body')}>{children}</div>
</div>
</div>
);
}