import React, { useState, useLayoutEffect, useRef } from 'react';
import { Select, Button, Modal, Toast, ConfigProvider, Notification } from '@douyinfe/semi-ui';
import en_GB from '@douyinfe/semi-ui/locale/source/en_GB';
import { createPortal } from "react-dom";
const Option = Select.Option;
let ind = 0;
const ReachableContext = React.createContext();
const useCreatePortalInBody = () => {
const wrapperRef = useRef(null);
if (wrapperRef.current === null && typeof document !== 'undefined') {
const div = document.createElement('div');
div.setAttribute('data-body-portal', '');
wrapperRef.current = div;
}
useLayoutEffect(() => {
const wrapper = wrapperRef.current;
if (!wrapper || typeof document === 'undefined') {
return;
}
document.querySelector('.test').appendChild(wrapper);
return () => {
document.querySelector('.test').appendChild(wrapper);
}
}, [])
return (children => wrapperRef.current && createPortal(children, wrapperRef.current));
}
const DialogComponent = props => {
const [visible, setVisible] = useState(false);
const handleOk = e => {
setVisible(false);
};
const handleCancel = e => {
setVisible(false);
};
return (
);
};
const UseModalDemo = () => {
const [modal, contextHolder] = Modal.useModal();
const config = { 'title': 'This is a success message', 'content': `${ind}` }
return (
document.getElementById("modal-container")}
locale={en_GB}
>
{/* `contextHolder` should always under the context you want to access */}
{contextHolder}
);
};
const UseNotiDemo = () => {
const [noti, holder] = Notification.useNotification();
const config = { 'title': 'This is a success message', position: 'bottomLeft', 'content': `${ind}` }
return (
{holder}
);
}
const UseToastDemo = () => {
const [toast, holder] = Toast.useToast();
const createBodyPortal = useCreatePortalInBody();
const config = { 'content': {name => `ReachableContext: ${name}-${ind}`}, duration: 0 }
return (
{/*
{holder}
*/}
{createBodyPortal(
{holder}
)}
);
}
export default () => (
document.querySelector('.test')} locale={en_GB}>
);