Skip to content

Commit

Permalink
chore: modal
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicleo committed Mar 11, 2023
1 parent 79b3c4f commit b97ab23
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/zarm/src/modal/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import Modal from './Modal';
import attachPropertiesToComponent from '../utils/attachPropertiesToComponent';
import alert from './Alert';
import confirm from './Confirm';
import attachPropertiesToComponent from '../utils/attachPropertiesToComponent';
import Modal from './Modal';
import { show, clear } from './methods';

export type { ModalProps, ModalCssVars } from './Modal';
export type { ModalCssVars, ModalProps } from './Modal';

export default attachPropertiesToComponent(Modal, {
show,
clear,
alert,
confirm,
});
27 changes: 27 additions & 0 deletions packages/zarm/src/modal/methods.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import { ImperativeHandler, renderImperatively } from '../utils/dom';
import Modal, { ModalProps } from './Modal';

export type ModalShowProps = Omit<ModalProps, 'visible' | 'destroy' | 'forceRender'>;

export type ModalShowHandler = Pick<ImperativeHandler, 'close'>;

const closeFn = new Set<() => void>();

export const show = (props: ModalShowProps) => {
const handler: ModalShowHandler = renderImperatively(
<Modal
{...props}
afterClose={() => {
closeFn.delete(handler.close);
props.afterClose?.();
}}
/>,
);
closeFn.add(handler.close);
return handler;
};

export const clear = () => {
closeFn.forEach((close) => close());
};

0 comments on commit b97ab23

Please sign in to comment.