aio-popup 8.0.1 → 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 +2 -0
- package/index.d.ts +8 -7
- package/index.js +21 -25
- package/package.json +1 -1
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 * {
|
|
@@ -572,6 +573,7 @@
|
|
|
572
573
|
|
|
573
574
|
.aio-popup-confirm {
|
|
574
575
|
overflow: hidden;
|
|
576
|
+
background: #fff;
|
|
575
577
|
}
|
|
576
578
|
|
|
577
579
|
.aio-popup-confirm .aio-popup-body {
|
package/index.d.ts
CHANGED
|
@@ -102,6 +102,7 @@ export type AP_confirm = {
|
|
|
102
102
|
export type AP_prompt = {
|
|
103
103
|
title?: string;
|
|
104
104
|
text: string;
|
|
105
|
+
placeholder?: string;
|
|
105
106
|
subtitle?: string;
|
|
106
107
|
submitText?: string;
|
|
107
108
|
canselText?: string;
|
|
@@ -137,23 +138,23 @@ export type AP_usePopup = {
|
|
|
137
138
|
addConfirm: AP_addConfirm;
|
|
138
139
|
addPrompt: AP_addPrompt;
|
|
139
140
|
};
|
|
140
|
-
export type I_usePopup =
|
|
141
|
+
export type I_usePopup = ReturnType<typeof usePopup>;
|
|
142
|
+
declare const usePopup: (props?: {
|
|
143
|
+
rtl?: boolean;
|
|
144
|
+
id?: string;
|
|
145
|
+
}) => {
|
|
141
146
|
addAlert: AP_addAlert;
|
|
142
147
|
addSnackebar: AP_addSnackebar;
|
|
143
148
|
removeModal: AP_removeModal;
|
|
144
149
|
addModal: AP_addModal;
|
|
145
|
-
getModals:
|
|
150
|
+
getModals: () => AP_modal[];
|
|
146
151
|
addHighlight: AP_addHighlight;
|
|
147
152
|
removeHighlight: AP_removeHighlight;
|
|
148
153
|
render: AP_render;
|
|
149
154
|
addConfirm: AP_addConfirm;
|
|
150
155
|
addPrompt: AP_addPrompt;
|
|
151
|
-
portal: () =>
|
|
156
|
+
portal: () => any;
|
|
152
157
|
};
|
|
153
|
-
declare const usePopup: (props?: {
|
|
154
|
-
rtl?: boolean;
|
|
155
|
-
id?: string;
|
|
156
|
-
}) => I_usePopup;
|
|
157
158
|
export default usePopup;
|
|
158
159
|
export type AP_SnackebarItem = {
|
|
159
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';
|
|
@@ -195,7 +195,7 @@ const usePopup = (props) => {
|
|
|
195
195
|
};
|
|
196
196
|
const addPrompt = (obj) => {
|
|
197
197
|
const id = 'a' + (Math.round(Math.random() * 100000));
|
|
198
|
-
let { title, text = '', subtitle, submitText = 'Submit', canselText = 'close', onSubmit, onCansel = () => { }, modalAttrs, backdropAttrs, headerAttrs, footerAttrs, bodyAttrs } = obj;
|
|
198
|
+
let { title, text = '', subtitle, submitText = 'Submit', placeholder = '', canselText = 'close', onSubmit, onCansel = () => { }, modalAttrs, backdropAttrs, headerAttrs, footerAttrs, bodyAttrs } = obj;
|
|
199
199
|
const submitAttrs = AddToAttrs(obj.submitAttrs, {
|
|
200
200
|
className: 'active', attrs: {
|
|
201
201
|
onClick: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -230,30 +230,26 @@ const usePopup = (props) => {
|
|
|
230
230
|
position: 'center', header: { title, subtitle },
|
|
231
231
|
modalAttrs: AddToAttrs(modalAttrs, { className: 'aio-popup-prompt' }),
|
|
232
232
|
backdropAttrs, headerAttrs, footerAttrs, bodyAttrs,
|
|
233
|
-
body: _jsx(Prompt, { change: (value) => promptTexts.current = Object.assign(Object.assign({}, promptTexts.current), { [id]: value }), placeholder: text }),
|
|
233
|
+
body: _jsx(Prompt, { change: (value) => promptTexts.current = Object.assign(Object.assign({}, promptTexts.current), { [id]: value }), placeholder: placeholder, text: text }),
|
|
234
234
|
footer: (_jsxs(_Fragment, { children: [_jsx("button", Object.assign({}, canselAttrs, { children: canselText })), _jsx("button", Object.assign({}, submitAttrs, { children: submitText }))] }))
|
|
235
235
|
};
|
|
236
236
|
addModal(config);
|
|
237
237
|
};
|
|
238
|
-
const
|
|
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:
|
|
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 = () =>
|
|
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;
|
|
254
|
-
const Prompt = ({ change, placeholder }) => {
|
|
255
|
-
const [
|
|
256
|
-
return (_jsx("textarea", { placeholder: placeholder, value:
|
|
250
|
+
const Prompt = ({ change, placeholder, text = '' }) => {
|
|
251
|
+
const [value, setValue] = useState(text);
|
|
252
|
+
return (_jsx("textarea", { placeholder: placeholder, value: value, onChange: (e) => { const value = e.target.value; setValue(value); change(value); } }));
|
|
257
253
|
};
|
|
258
254
|
const POPUPCTX = createContext({});
|
|
259
255
|
const Popup = ({ modal, isLast }) => {
|
|
@@ -742,16 +738,16 @@ function getEasing(highlight) {
|
|
|
742
738
|
const { easing } = highlight;
|
|
743
739
|
var easingNames = [
|
|
744
740
|
'linear',
|
|
745
|
-
'easeInQuad',
|
|
746
|
-
'easeInSine',
|
|
747
|
-
'easeInCirc',
|
|
748
|
-
'easeInBack',
|
|
749
|
-
'easeOutQuad',
|
|
750
|
-
'easeOutSine',
|
|
751
|
-
'easeOutCirc',
|
|
752
|
-
'easeInOutQuad',
|
|
753
|
-
'easeInOutSine',
|
|
754
|
-
'easeInOutBack',
|
|
741
|
+
'easeInQuad', //1
|
|
742
|
+
'easeInSine', //5
|
|
743
|
+
'easeInCirc', //7
|
|
744
|
+
'easeInBack', //8
|
|
745
|
+
'easeOutQuad', //9
|
|
746
|
+
'easeOutSine', //13
|
|
747
|
+
'easeOutCirc', //15
|
|
748
|
+
'easeInOutQuad', //18
|
|
749
|
+
'easeInOutSine', //22
|
|
750
|
+
'easeInOutBack', //25
|
|
755
751
|
'easeOutBounce', //27
|
|
756
752
|
];
|
|
757
753
|
if (typeof easing === 'number') {
|