xion 1fbf1b64d9 feat: 静态类中的函数继承范性
model onClose and ondestory函数
createDOMElemnet 从jsx
2024-09-21 17:40:53 +08:00

205 lines
5.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { calc } from 'antd/es/theme/internal';
import { DialogModal, Modal, modalStore } from '@kevisual/ui';
import { useEffect, useRef } from 'react';
import '@kevisual/ui/src/index.css';
import { createDOMElement } from './create-dom';
// import '@kevisual/ui/src/components/modal/index.css';
export const App = () => {
const showModel = () => {
//
};
return (
<div className='flex flex-col w-full h-full bg-gray-400'>
<div className='p-2 bg-white rounded-md border-b rounded-s rounded-e'>Model</div>
<div
className='mt-2 mx-4 bg-white p-2 rounded-md border shadow-sm flex flex-wrap gap-2'
style={{
height: 'calc(100vh - 100px)',
overflow: 'auto',
}}>
<ModelOne />
<ModelTwo />
<ModelTwo2 />
<ModelThree />
</div>
</div>
);
};
const ModelOne = () => {
const ref = useRef<HTMLDivElement>(null);
const showModel = () => {
const model = Modal.render(ref.current!, {});
};
return (
<div>
<div className='w-96 p-4 rounded-md shadow-md bg-slate-200'>
model one
<div className='cursor-pointer p-2 border' onClick={showModel}>
show
</div>
<div ref={ref}> Model的渲染内容</div>
</div>
</div>
);
};
const ModelTwo = () => {
const ref = useRef<HTMLDivElement>(null);
const showModel = () => {
const model = DialogModal.render(ref.current!, {
dialogTitle: 'Dialog Modal',
width: '400px',
dialogTitleCloseIcon: true,
contentStyle: {
// maxHeight: '100px',
// overflow: 'auto',
},
});
};
return (
<div>
<div className='w-96 p-4 rounded-md shadow-md bg-slate-200'>
model two
<div className='cursor-pointer p-2 border' onClick={showModel}>
show
</div>
<div ref={ref}>
Modal Dialog
<div></div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
</div>
</div>
);
};
const ModelTwo2 = () => {
const ref = useRef<HTMLDivElement>(null);
const showModel = () => {
const div = createDOMElement(refHide);
const model = DialogModal.render(ref.current! || div, {
dialogTitle: 'Dialog Modal',
width: '400px',
dialogTitleCloseIcon: true,
contentStyle: {
// maxHeight: '100px',
// overflow: 'auto',
},
});
};
const refHide = (
<div ref={ref}>
Modal Dialog
<div></div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
);
return (
<div>
<div className='w-96 p-4 rounded-md shadow-md bg-slate-200'>
model two -ref的模块没有真实渲染到节点createDOMElement
<div className='cursor-pointer p-2 border' onClick={showModel}>
show
</div>
<div className='hidden'>{refHide}</div>
</div>
</div>
);
};
const ModelThree = () => {
const ref = useRef<HTMLDivElement>(null);
let dialog = useRef<DialogModal | null>(null);
const showModel = () => {
const model = DialogModal.render(ref.current!, {
dialogTitle: 'Dialog Modal',
width: '400px',
dialogTitleCloseIcon: true,
open: false,
contentStyle: {
// maxHeight: '100px',
// overflow: 'auto',
},
});
const modals = modalStore.getState().modals;
console.log('modals', modals.length, model);
dialog.current = model;
};
return (
<div>
<div className='w-96 p-4 rounded-md shadow-md bg-slate-200'>
model 3
<div className='cursor-pointer p-2 border' onClick={showModel}>
show
</div>
<div ref={ref}>
Modal Dialog
<div></div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
<div
onClick={() => {
if (dialog.current) {
dialog.current.setOpen(true);
}
console.log('open', dialog.current);
}}>
</div>
</div>
</div>
);
};
const Model4 = () => {
const ref = useRef<HTMLDivElement>(null);
let dialog = useRef<DialogModal | null>(null);
const showModel = () => {
const model = DialogModal.create({
dialogTitle: 'Dialog Modal',
width: '400px',
dialogTitleCloseIcon: true,
open: false,
contentStyle: {
// maxHeight: '100px',
// overflow: 'auto',
},
});
const modals = modalStore.getState().modals;
console.log('modals', modals.length, model);
dialog.current = model;
};
return (
<div>
<div className='w-96 p-4 rounded-md shadow-md bg-slate-200'>
model 4
<div className='cursor-pointer p-2 border' onClick={showModel}>
show
</div>
<div ref={ref}>
Modal Dialog
<div></div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
<div
onClick={() => {
if (dialog.current) {
dialog.current.setOpen(true);
}
console.log('open', dialog.current);
}}>
</div>
</div>
</div>
);
};