aio-popup 8.1.0 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.css CHANGED
@@ -191,6 +191,7 @@
191
191
  width: 100%;
192
192
  overflow-y: auto;
193
193
  box-sizing: border-box;
194
+ background:#fff;
194
195
  }
195
196
 
196
197
  .aio-popup-body * {
package/index.d.ts CHANGED
@@ -138,23 +138,23 @@ export type AP_usePopup = {
138
138
  addConfirm: AP_addConfirm;
139
139
  addPrompt: AP_addPrompt;
140
140
  };
141
- export type I_usePopup = {
141
+ export type I_usePopup = ReturnType<typeof usePopup>;
142
+ declare const usePopup: (props?: {
143
+ rtl?: boolean;
144
+ id?: string;
145
+ }) => {
142
146
  addAlert: AP_addAlert;
143
147
  addSnackebar: AP_addSnackebar;
144
148
  removeModal: AP_removeModal;
145
149
  addModal: AP_addModal;
146
- getModals: AP_getModals;
150
+ getModals: () => AP_modal[];
147
151
  addHighlight: AP_addHighlight;
148
152
  removeHighlight: AP_removeHighlight;
149
153
  render: AP_render;
150
154
  addConfirm: AP_addConfirm;
151
155
  addPrompt: AP_addPrompt;
152
- portal: () => void;
156
+ portal: () => any;
153
157
  };
154
- declare const usePopup: (props?: {
155
- rtl?: boolean;
156
- id?: string;
157
- }) => I_usePopup;
158
158
  export default usePopup;
159
159
  export type AP_SnackebarItem = {
160
160
  item: AP_snackebar;
package/index.js CHANGED
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
11
- import { createRef, useEffect, useState, createContext, useContext, useRef } from 'react';
11
+ import { createRef, useEffect, useState, createContext, useContext, useRef, useMemo } from 'react';
12
12
  import * as ReactDOMServer from 'react-dom/server';
13
13
  import ReactDOM from 'react-dom';
14
14
  import { $, anime } from 'aio-deps';
@@ -235,19 +235,15 @@ const usePopup = (props) => {
235
235
  };
236
236
  addModal(config);
237
237
  };
238
- const getContext = () => {
239
- return {
240
- rtl: !!props && !!props.rtl,
241
- snackebarItems: snackebarItemsRef.current,
242
- removeSnackebar, removeModal
243
- };
244
- };
238
+ const ctx = useMemo(() => ({ rtl: !!(props === null || props === void 0 ? void 0 : props.rtl), snackebarItems, removeSnackebar, removeModal }), [props === null || props === void 0 ? void 0 : props.rtl, snackebarItems]);
245
239
  const render = (caller) => {
246
- return (_jsxs(CTX.Provider, { value: getContext(), children: [modalsRef.current.map((modal, i) => {
240
+ return (_jsxs(CTX.Provider, { value: ctx, children: [modalsRef.current.map((modal, i) => {
247
241
  return (_jsx(Popup, { modal: modal, isLast: i === modalsRef.current.length - 1, renderCaller: caller }, modal.id));
248
242
  }), snackebarItems.map((item, i) => _jsx(SnackebarItem, { item: item, index: i }, item.id)), !!highlight && _jsx(Highlight, { highlight: highlight })] }));
249
243
  };
250
- const portal = () => ReactDOM.createPortal(render(), document.body);
244
+ const portal = useMemo(() => {
245
+ return () => ReactDOM.createPortal(render(), document.body);
246
+ }, [modals, snackebarItems, highlight]);
251
247
  return { addAlert, addSnackebar, removeModal, addModal, getModals, addHighlight, removeHighlight, render, addConfirm, addPrompt, portal };
252
248
  };
253
249
  export default usePopup;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-popup",
3
- "version": "8.1.0",
3
+ "version": "8.2.0",
4
4
  "description": "handle all types of popup and modals in react",
5
5
  "main": "index.js",
6
6
  "scripts": {