import { xmodal } from 'react-ui-xmodal';
import 'react-ui-xmodal/dist/react-ui-xmodal.css';
const App = () => {
const showToast = (pos: 'top' | 'center' | 'bottom' = 'center') => {
xmodal.showToast({
msg: 'This is a toast message.',
duration: 1,
pos,
});
};
const makeContentElem = () => {
const elem = document.createElement('div');
elem.innerText = 'div 앨리먼트로 입력한 본문 입니다.';
elem.className = 'user-class';
elem.style.width = '500px';
elem.style.height = '400px';
return elem;
};
const showDialog = () => {
xmodal.showDialog({
title: '사용자 알림 창',
content: makeContentElem(),
buttonList: [
{
text: 'cancel',
func: () => {
console.log('cancel');
xmodal.hideDialog();
},
},
{
text: 'ok',
func: () => {
console.log('ok');
xmodal.hideDialog();
},
default: true,
},
],
onloadFunc: () => {
console.log('onload function');
},
});
};
const showDialog2 = () => {
xmodal.showDialog({
content:
'단순한 알림만 보여줍니다.|버튼이 없는 창 입니다.|창 외부를 클릭하거나 ESC 를 누르면 닫힙니다.',
overlayClose: true,
escClose: true,
});
};
const showDialog3 = () => {
xmodal.showDialog({
content:
'단순한 알림만 보여줍니다.|아래 닫힘 버튼을 누르면 닫힙니다.',
buttonList: [
{
text: '닫힘',
func: () => {
xmodal.hideDialog();
},
default: true,
},
],
});
};
return (
<div className="content-container">
<button
onClick={() => showToast('top')}
>
toast message (top)
</button>
<button
onClick={() => showToast('center')}
>
toast message (center)
</button>
<button
onClick={() => showToast('bottom')}
>
toast message (bottom)
</button>
<button
onClick={() => showDialog()}
>
dialog
</button>
<button
onClick={() => showDialog3()}
>
dialog (no title)
</button>
<button
onClick={() => showDialog2()}
>
dialog (no title, no foot)
</button>
</div>
);
};
export default App;