From c11bceb2cea9548947b724a179518ac0ea280b62 Mon Sep 17 00:00:00 2001 From: wendell0316 Date: Thu, 27 Apr 2023 09:43:56 +0800 Subject: [PATCH] feat: add more props for popup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: popup可以接受外部参数 目前配置都是固定的,对于一些简单定制化的需求无法满足 * feat: 增加类型约束,固定可修改项 * Revert "feat: 增加类型约束,固定可修改项" This reverts commit 7e3b4dd1fafce56bfb94d7f77fda729eec4066d0. * feat: 添加类型 --- .../src/components/popup/index.tsx | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/packages/editor-skeleton/src/components/popup/index.tsx b/packages/editor-skeleton/src/components/popup/index.tsx index 68897d61a..1367723a1 100644 --- a/packages/editor-skeleton/src/components/popup/index.tsx +++ b/packages/editor-skeleton/src/components/popup/index.tsx @@ -4,6 +4,22 @@ import { uniqueId } from '@alilc/lowcode-utils'; import { IEventBus, createModuleEventBus } from '@alilc/lowcode-editor-core'; import './style.less'; +export interface PopupExtProps { + width?: number; + hasMask?: boolean; + trigger?: ReactNode; + canCloseByOutSideClick?: boolean + className?: string; + safeNode?: string[]; +} + +interface PopupProps extends PopupExtProps{ + content?: ReactNode, + title?: ReactNode, + actionKey?: string +} + + export const PopupContext = createContext({} as any); export class PopupPipe { @@ -11,7 +27,7 @@ export class PopupPipe { private currentId?: string; - create(props?: object): { + create(props?: PopupExtProps): { send: (content: ReactNode, title: ReactNode) => void; show: (target: Element) => void; } { @@ -45,13 +61,13 @@ export class PopupPipe { }; } - private popup(props: object, target?: Element) { + private popup(props: PopupProps, target?: Element) { Promise.resolve().then(() => { this.emitter.emit('popupchange', props, target); }); } - onPopupChange(fn: (props: object, target?: Element) => void): () => void { + onPopupChange(fn: (props: PopupProps, target?: Element) => void): () => void { this.emitter.on('popupchange', fn); return () => { this.emitter.removeListener('popupchange', fn); @@ -86,18 +102,23 @@ export default class PopupService extends Component<{ } } +interface StateType extends PopupProps { + visible?: boolean, + offsetX?: number, + pos?: {top: number, height: number} +} export class PopupContent extends PureComponent<{ safeId?: string; popupContainer?: string }> { static contextType = PopupContext; popupContainerId = uniqueId('popupContainer'); - state: any = { + state: StateType = { visible: false, offsetX: -300, }; private dispose = (this.context as PopupPipe).onPopupChange((props, target) => { - const state: any = { + const state: StateType = { ...props, visible: true, }; @@ -132,7 +153,7 @@ export class PopupContent extends PureComponent<{ safeId?: string; popupContaine }; render() { - const { content, visible, title, actionKey, pos, offsetX } = this.state; + const { content, visible, title, actionKey, pos, offsetX, width = 360, hasMask = false, canCloseByOutSideClick = true, safeNode = [] } = this.state; if (!visible) { return null; } @@ -146,10 +167,10 @@ export class PopupContent extends PureComponent<{ safeId?: string; popupContaine return ( { if (avoidLaterHidden) { return; @@ -160,11 +181,11 @@ export class PopupContent extends PureComponent<{ safeId?: string; popupContaine }} trigger={
} triggerType="click" - canCloseByOutSideClick + canCloseByOutSideClick={canCloseByOutSideClick} animation={false} onClose={this.onClose} id={this.props.safeId} - safeNode={id} + safeNode={[id, ...safeNode]} closeable container={this.props.popupContainer} >