import {designComponent, getComponentCls, onMounted, PropType, reactive, useClasses, useRefList} from "@peryl/react-compose"; import {iNoticeServiceOption, NoticeDirection} from "./noitice.service.utils"; import {List} from "../List"; import {Notice} from "./Notice"; import {createServiceReadyObserver} from "../Application/utils/createServiceReadyObserver"; export const NoticeContainer = designComponent({ name: 'notice-container', props: { horizontal: { type: String as PropType, required: true }, vertical: { type: String as PropType, required: true }, duration: { type: String, default: "30px" }, }, emits: { onReady: () => true, }, setup({ props, event }) { const serviceReadyObserver = createServiceReadyObserver(); onMounted(() => event.emit.onReady()); const classes = useClasses(() => [ getComponentCls('notice-container'), `notice-container-${props.horizontal}-${props.vertical}` ]); const state = reactive({ options: [] as iNoticeServiceOption[] }); const { refList, onRefList } = useRefList<{ props: { option: iNoticeServiceOption } }>(); const styles = { padding: props.duration }; const utils = { close: (i: number) => { state.options.splice(i, 1); } }; return { refer: { props, getNotice: async (option: iNoticeServiceOption) => { state.options.push(option); return serviceReadyObserver.getNewIns(state.options); }, }, render: () => (
{state.options.map((option, index) =>
utils.close(index)} onReady={() => serviceReadyObserver.onReady({ option, ins: refList[index] })} />
)}
) }; }, });