aio-popup 8.1.0 → 8.2.1

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
@@ -20,6 +20,10 @@
20
20
  flex-shrink: 0;
21
21
  }
22
22
 
23
+ .aio-popup-backdrop.rtl {
24
+ direction: rtl;
25
+ }
26
+
23
27
  .aio-popup {
24
28
  border-radius: 4px;
25
29
  transition: .3s;
@@ -31,7 +35,7 @@
31
35
  outline: none;
32
36
  z-index: 10;
33
37
  position: absolute;
34
- border:1px solid #ddd;
38
+ border: 1px solid #ddd;
35
39
  }
36
40
 
37
41
  .aio-popup.rtl {
@@ -41,7 +45,9 @@
41
45
  .aio-popup.not-mounted {
42
46
  transition: .3s;
43
47
  }
44
-
48
+ .aio-popup-popover{
49
+ overflow:hidden;
50
+ }
45
51
  /**********position (fullscreen)*******/
46
52
  .aio-popup-position-fullscreen>.aio-popup.not-mounted {
47
53
  transform: scale(0);
@@ -192,6 +198,9 @@
192
198
  overflow-y: auto;
193
199
  box-sizing: border-box;
194
200
  }
201
+ .aio-popup-modal .aio-popup-body {
202
+ background: #fff;
203
+ }
195
204
 
196
205
  .aio-popup-body * {
197
206
  box-sizing: border-box;
@@ -370,7 +379,7 @@
370
379
  align-items: center;
371
380
  box-sizing: border-box;
372
381
  padding: 0 12px;
373
- gap:6px;
382
+ gap: 6px;
374
383
  }
375
384
 
376
385
  .aio-popup-time {
@@ -812,72 +821,72 @@
812
821
  border-radius:6px;
813
822
  border:1px solid #eee;
814
823
  } */
815
- .aio-loading {
816
- z-index: 100000000000000000000000000000;
817
- position: fixed;
818
- direction: ltr;
819
- width: 100%;
820
- height: 100%;
821
- top: 0;
822
- left: 0;
823
- display: flex;
824
- align-items: center;
825
- align-items: center;
826
- justify-content: center;
824
+ .aio-loading {
825
+ z-index: 100000000000000000000000000000;
826
+ position: fixed;
827
+ direction: ltr;
828
+ width: 100%;
829
+ height: 100%;
830
+ top: 0;
831
+ left: 0;
832
+ display: flex;
833
+ align-items: center;
834
+ align-items: center;
835
+ justify-content: center;
827
836
  }
828
837
 
829
838
  .aio-loading-container-0 {
830
- border-radius: 12px;
831
- height: 72px;
832
- width: 72px;
833
- display: flex;
834
- align-items: center;
835
- justify-content: center;
836
- background: rgba(0, 0, 0, 0.7);
837
- opacity: 1;
838
- animation-name: aioloadingopacity;
839
- animation-duration: 2s;
840
- animation-fill-mode: forwards;
839
+ border-radius: 12px;
840
+ height: 72px;
841
+ width: 72px;
842
+ display: flex;
843
+ align-items: center;
844
+ justify-content: center;
845
+ background: rgba(0, 0, 0, 0.7);
846
+ opacity: 1;
847
+ animation-name: aioloadingopacity;
848
+ animation-duration: 2s;
849
+ animation-fill-mode: forwards;
841
850
  }
842
851
 
843
852
  .aio-loading-0 {
844
- width: 60px;
845
- display: flex;
846
- align-items: center;
847
- justify-content: center;
853
+ width: 60px;
854
+ display: flex;
855
+ align-items: center;
856
+ justify-content: center;
848
857
  }
849
858
 
850
859
  .aio-loading-item-0 {
851
- width: 4px;
852
- height: 36px;
853
- background: rgb(255, 255, 255);
854
- margin: 0px 1.5px;
855
- border-radius: 0px;
860
+ width: 4px;
861
+ height: 36px;
862
+ background: rgb(255, 255, 255);
863
+ margin: 0px 1.5px;
864
+ border-radius: 0px;
856
865
  }
857
866
 
858
867
  @keyframes aioloading0 {
859
868
 
860
- 0%,
861
- 40%,
862
- 100% {
863
- transform: scaleY(0.4);
864
- }
869
+ 0%,
870
+ 40%,
871
+ 100% {
872
+ transform: scaleY(0.4);
873
+ }
865
874
 
866
- 20% {
867
- transform: scaleY(1.0);
868
- }
875
+ 20% {
876
+ transform: scaleY(1.0);
877
+ }
869
878
  }
870
879
 
871
880
  @keyframes aioloadingopacity {
872
- 0% {
873
- opacity: 0;
874
- }
881
+ 0% {
882
+ opacity: 0;
883
+ }
875
884
 
876
- 50% {
877
- opacity: 0;
878
- }
885
+ 50% {
886
+ opacity: 0;
887
+ }
879
888
 
880
- 100% {
881
- opacity: 1;
882
- }
889
+ 100% {
890
+ opacity: 1;
891
+ }
883
892
  }
package/index.d.ts CHANGED
@@ -38,6 +38,8 @@ export type AP_modal = {
38
38
  pageSelector?: string;
39
39
  focus?: boolean;
40
40
  backdropClose?: boolean;
41
+ ref?: any;
42
+ isPopover?: boolean;
41
43
  };
42
44
  export type AP_alert = {
43
45
  rtl?: boolean;
@@ -116,45 +118,23 @@ export type AP_prompt = {
116
118
  headerAttrs?: any;
117
119
  footerAttrs?: any;
118
120
  };
119
- type AP_removeModal = (arg?: string) => void;
120
- type AP_addAlert = (p: AP_alert) => void;
121
- type AP_addSnackebar = (item: AP_snackebar) => void;
122
- type AP_addModal = (o: AP_modal) => void;
123
- type AP_addHighlight = (highlight: AP_highlight) => void;
124
- type AP_removeHighlight = () => void;
125
- type AP_getModals = () => AP_modal[];
126
- type AP_addConfirm = (item: AP_confirm) => void;
127
- type AP_addPrompt = (item: AP_prompt) => void;
128
- type AP_render = (caller?: string) => ReactNode;
129
- export type AP_usePopup = {
130
- addAlert: AP_addAlert;
131
- addSnackebar: AP_addSnackebar;
132
- removeModal: AP_removeModal;
133
- addModal: AP_addModal;
134
- getModals: AP_getModals;
135
- addHighlight: AP_addHighlight;
136
- removeHighlight: AP_removeHighlight;
137
- render: AP_render;
138
- addConfirm: AP_addConfirm;
139
- addPrompt: AP_addPrompt;
140
- };
141
- export type I_usePopup = {
142
- addAlert: AP_addAlert;
143
- addSnackebar: AP_addSnackebar;
144
- removeModal: AP_removeModal;
145
- addModal: AP_addModal;
146
- getModals: AP_getModals;
147
- addHighlight: AP_addHighlight;
148
- removeHighlight: AP_removeHighlight;
149
- render: AP_render;
150
- addConfirm: AP_addConfirm;
151
- addPrompt: AP_addPrompt;
152
- portal: () => void;
153
- };
121
+ export type I_usePopup = ReturnType<typeof usePopup>;
154
122
  declare const usePopup: (props?: {
155
123
  rtl?: boolean;
156
124
  id?: string;
157
- }) => I_usePopup;
125
+ }) => {
126
+ addAlert: (obj: AP_alert) => void;
127
+ addSnackebar: (item: AP_snackebar) => void;
128
+ removeModal: (arg?: string) => Promise<void>;
129
+ addModal: (o: AP_modal) => void;
130
+ getModals: () => AP_modal[];
131
+ addHighlight: (highlight: AP_highlight) => void;
132
+ removeHighlight: () => void;
133
+ render: (caller?: string) => import("react/jsx-runtime").JSX.Element;
134
+ addConfirm: (obj: AP_confirm) => void;
135
+ addPrompt: (obj: AP_prompt) => void;
136
+ portal: () => any;
137
+ };
158
138
  export default usePopup;
159
139
  export type AP_SnackebarItem = {
160
140
  item: AP_snackebar;
package/index.js CHANGED
@@ -8,12 +8,11 @@ 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';
15
15
  import './index.css';
16
- const CTX = createContext({});
17
16
  function Align(p) {
18
17
  let { modal, target, fitHorizontal, rtl, limitTo, pageSelector } = p;
19
18
  const page = modal.parents('.aio-popup-backdrop');
@@ -97,6 +96,11 @@ function AddToAttrs(attrs, p) {
97
96
  let newStyle = Object.assign(Object.assign({}, attrs.style), style);
98
97
  return Object.assign(Object.assign(Object.assign({}, attrs), { className: newClassName, style: newStyle }), p.attrs);
99
98
  }
99
+ const MainContext = createContext({});
100
+ const MainProvider = ({ value, children }) => {
101
+ return _jsx(MainContext, { value: value, children: children });
102
+ };
103
+ const useMainProvider = () => useContext(MainContext);
100
104
  const usePopup = (props) => {
101
105
  let [modals, setModals] = useState([]);
102
106
  const promptTexts = useRef({});
@@ -111,7 +115,7 @@ const usePopup = (props) => {
111
115
  if (o.id === undefined) {
112
116
  o.id = 'popup' + Math.round(Math.random() * 1000000);
113
117
  }
114
- let newModal = o;
118
+ let newModal = Object.assign(Object.assign({}, o), { rtl: o.rtl === true || (props === null || props === void 0 ? void 0 : props.rtl) === true });
115
119
  setModals(prevModals => {
116
120
  let newModals = prevModals.filter(({ id }) => id !== o.id);
117
121
  return [...newModals, newModal];
@@ -235,19 +239,15 @@ const usePopup = (props) => {
235
239
  };
236
240
  addModal(config);
237
241
  };
238
- const getContext = () => {
239
- return {
240
- rtl: !!props && !!props.rtl,
241
- snackebarItems: snackebarItemsRef.current,
242
- removeSnackebar, removeModal
243
- };
244
- };
242
+ const mainContext = useMemo(() => ({ rtl: !!(props === null || props === void 0 ? void 0 : props.rtl), snackebarItems, removeSnackebar, removeModal, id: props === null || props === void 0 ? void 0 : props.id }), [props === null || props === void 0 ? void 0 : props.rtl, snackebarItems]);
245
243
  const render = (caller) => {
246
- return (_jsxs(CTX.Provider, { value: getContext(), children: [modalsRef.current.map((modal, i) => {
247
- return (_jsx(Popup, { modal: modal, isLast: i === modalsRef.current.length - 1, renderCaller: caller }, modal.id));
244
+ return (_jsxs(MainProvider, { value: mainContext, children: [modalsRef.current.map((modal, i) => {
245
+ return (_jsx("div", { style: { display: 'content' }, ref: modal.ref, children: _jsx(Popup, { modal: modal, isLast: i === modalsRef.current.length - 1, renderCaller: caller }, modal.id) }));
248
246
  }), snackebarItems.map((item, i) => _jsx(SnackebarItem, { item: item, index: i }, item.id)), !!highlight && _jsx(Highlight, { highlight: highlight })] }));
249
247
  };
250
- const portal = () => ReactDOM.createPortal(render(), document.body);
248
+ const portal = useMemo(() => {
249
+ return () => ReactDOM.createPortal(render(), document.body);
250
+ }, [modals, snackebarItems, highlight]);
251
251
  return { addAlert, addSnackebar, removeModal, addModal, getModals, addHighlight, removeHighlight, render, addConfirm, addPrompt, portal };
252
252
  };
253
253
  export default usePopup;
@@ -257,7 +257,7 @@ const Prompt = ({ change, placeholder, text = '' }) => {
257
257
  };
258
258
  const POPUPCTX = createContext({});
259
259
  const Popup = ({ modal, isLast }) => {
260
- const mainContext = useContext(CTX);
260
+ const mainContext = useMainProvider();
261
261
  let { modalAttrs = {}, position = 'fullscreen', getTarget } = modal;
262
262
  let [temp] = useState({ dom: createRef(), backdropDom: createRef(), dui: undefined });
263
263
  let [popoverStyle, setPopoverStyle] = useState({});
@@ -335,6 +335,12 @@ const Popup = ({ modal, isLast }) => {
335
335
  }
336
336
  function getClassName() {
337
337
  let className = 'aio-popup';
338
+ if (modal.isPopover) {
339
+ className += ' aio-popup-popover';
340
+ }
341
+ else {
342
+ className += ' aio-popup-modal';
343
+ }
338
344
  className += mainContext.rtl ? ' rtl' : ' ltr';
339
345
  if (firstMount) {
340
346
  className += ' not-mounted';
@@ -345,10 +351,12 @@ const Popup = ({ modal, isLast }) => {
345
351
  return className;
346
352
  }
347
353
  const getContext = () => ({ modal, isLast, state, setState, onKeyDown });
354
+ console.log(mainContext.id);
348
355
  return (_jsx(POPUPCTX.Provider, { value: getContext(), children: _jsx(ModalBackdrop, { firstMount: !!firstMount, backdropDom: temp.backdropDom, isModalMouseDown: isModalMouseDown, children: _jsxs("div", Object.assign({}, getModalProps(), { children: [_jsx(ModalHeader, {}), _jsx(ModalBody, {}, modal.id), _jsx(ModalFooter, {})] }), modal.id) }, modal.id) }));
349
356
  };
350
357
  const ModalBackdrop = ({ children, firstMount, backdropDom, isModalMouseDown }) => {
351
- const { removeModal, rtl } = useContext(CTX);
358
+ const { removeModal, rtl, id: containerId } = useMainProvider();
359
+ console.log(containerId);
352
360
  let { modal, onKeyDown } = useContext(POPUPCTX);
353
361
  let { backdropAttrs = {}, id, position = 'fullscreen' } = modal;
354
362
  function backClick(e) {
@@ -371,7 +379,7 @@ const ModalBackdrop = ({ children, firstMount, backdropDom, isModalMouseDown })
371
379
  return _jsx("div", Object.assign({}, AddToAttrs(backdropAttrs, { className, attrs }), { children: children }));
372
380
  };
373
381
  const ModalHeader = () => {
374
- const { removeModal } = useContext(CTX);
382
+ const { removeModal } = useMainProvider();
375
383
  let { modal, state, setState } = useContext(POPUPCTX);
376
384
  if (!modal.header) {
377
385
  return null;
@@ -396,7 +404,7 @@ const ModalHeaderElement = ({ type }) => {
396
404
  return _jsx("div", { className: `aio-popup-header-${type}`, "data-subtitle": type === 'title' ? header.subtitle : undefined, children: header[type] });
397
405
  };
398
406
  const ModalClose = () => {
399
- const { removeModal } = useContext(CTX);
407
+ const { removeModal } = useMainProvider();
400
408
  let { modal, state, setState } = useContext(POPUPCTX), { header } = modal;
401
409
  if (typeof header === 'function' || !header) {
402
410
  return null;
@@ -433,7 +441,7 @@ const ModalFooter = () => {
433
441
  };
434
442
  const SBCTX = createContext({});
435
443
  const SnackebarItem = (props) => {
436
- const mainContext = useContext(CTX);
444
+ const mainContext = useMainProvider();
437
445
  let { item } = props;
438
446
  let { time = 8, id, align = ['right', 'top'] } = item;
439
447
  if (align[1] !== 'top' && align[1] !== 'bottom') {
@@ -537,24 +545,24 @@ export function Alert(props) {
537
545
  $(`.aio-popup-alert-container.${$$.id} .aio-popup-time`).html($$.getBarRender());
538
546
  },
539
547
  getRender() {
540
- return (`
541
- <div class='aio-popup-alert-container not-mounted ${$$.id} aio-popup-alert-container-center${!!className ? ` ${className}` : ''}'>
542
- <div class='aio-popup-alert aio-popup-alert-${type}'>
543
- <div class='aio-popup-alert-header'>${$$.getIcon()}</div>
544
- <div class='aio-popup-alert-body aio-popup-scroll'>
545
- <div class='aio-popup-alert-title'>${ReactDOMServer.renderToStaticMarkup(title)}</div>
546
- <div class='aio-popup-alert-text' style="text-align:${rtl ? 'right' : 'left'}">${text}</div>
547
- </div>
548
- <div class='aio-popup-alert-footer'>
549
- ${onClose !== false ? `<button class='aio-popup-alert-close ${$$.id}'>${closeText}</button>` : ''}
548
+ return (`
549
+ <div class='aio-popup-alert-container not-mounted ${$$.id} aio-popup-alert-container-center${!!className ? ` ${className}` : ''}'>
550
+ <div class='aio-popup-alert aio-popup-alert-${type}'>
551
+ <div class='aio-popup-alert-header'>${$$.getIcon()}</div>
552
+ <div class='aio-popup-alert-body aio-popup-scroll'>
553
+ <div class='aio-popup-alert-title'>${ReactDOMServer.renderToStaticMarkup(title)}</div>
554
+ <div class='aio-popup-alert-text' style="text-align:${rtl ? 'right' : 'left'}">${text}</div>
555
+ </div>
556
+ <div class='aio-popup-alert-footer'>
557
+ ${onClose !== false ? `<button class='aio-popup-alert-close ${$$.id}'>${closeText}</button>` : ''}
550
558
  ${actions.map((o) => {
551
559
  const { className, id, text } = o;
552
560
  return `<button data-action='${id}' class='aio-popup-alert-action${className ? ' ' + className : ''}'>${text}</button>`;
553
- }).join(' ')}
554
- </div>
555
- <div class='aio-popup-time'></div>
556
- </div>
557
- </div>
561
+ }).join(' ')}
562
+ </div>
563
+ <div class='aio-popup-time'></div>
564
+ </div>
565
+ </div>
558
566
  `);
559
567
  },
560
568
  close() {
@@ -742,16 +750,16 @@ function getEasing(highlight) {
742
750
  const { easing } = highlight;
743
751
  var easingNames = [
744
752
  'linear',
745
- 'easeInQuad', //1
746
- 'easeInSine', //5
747
- 'easeInCirc', //7
748
- 'easeInBack', //8
749
- 'easeOutQuad', //9
750
- 'easeOutSine', //13
751
- 'easeOutCirc', //15
752
- 'easeInOutQuad', //18
753
- 'easeInOutSine', //22
754
- 'easeInOutBack', //25
753
+ 'easeInQuad',
754
+ 'easeInSine',
755
+ 'easeInCirc',
756
+ 'easeInBack',
757
+ 'easeOutQuad',
758
+ 'easeOutSine',
759
+ 'easeOutCirc',
760
+ 'easeInOutQuad',
761
+ 'easeInOutSine',
762
+ 'easeInOutBack',
755
763
  'easeOutBounce', //27
756
764
  ];
757
765
  if (typeof easing === 'number') {
@@ -781,15 +789,15 @@ export class Loading {
781
789
  constructor(loader) {
782
790
  this.loader = '0';
783
791
  this.getLoader_0 = () => {
784
- return (`
785
- <div class="aio-loading-container-0">
786
- <div class="aio-loading-0">
792
+ return (`
793
+ <div class="aio-loading-container-0">
794
+ <div class="aio-loading-0">
787
795
  ${new Array(5).fill(0).map((o, i) => {
788
796
  if (o) { }
789
797
  return this.getLoaderItem_0(`0.${i}`);
790
- }).join(' ')}
791
- </div>
792
- </div>
798
+ }).join(' ')}
799
+ </div>
800
+ </div>
793
801
  `);
794
802
  };
795
803
  this.getLoaderItem_0 = (ease) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-popup",
3
- "version": "8.1.0",
3
+ "version": "8.2.1",
4
4
  "description": "handle all types of popup and modals in react",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/alert1.css DELETED
@@ -1,68 +0,0 @@
1
- .aio-popup-alert {
2
- overflow: unset !important;
3
- }
4
-
5
- .aio-popup-alert svg {
6
- transform: translateY(-24px);
7
- fill: #fff !important;
8
- border-radius: 100%;
9
- padding: 12px;
10
- }
11
- .aio-popup-alert-error svg {
12
- background: #f14747;
13
- }
14
- .aio-popup-alert-error .aio-popup-time-bar {
15
- background: #f14747;
16
- }
17
- .aio-popup-alert-error .aio-popup-alert-footer button{
18
- background: #f14747;
19
- }
20
- .aio-popup-alert-success svg {
21
- background: #6EBC3D;
22
- }
23
- .aio-popup-alert-success .aio-popup-time-bar {
24
- background: #6EBC3D;
25
- }
26
- .aio-popup-alert-success .aio-popup-alert-footer button{
27
- background: #6EBC3D;
28
- }
29
- .aio-popup-alert-warning svg {
30
- background: #ff7800;
31
- }
32
- .aio-popup-alert-warning .aio-popup-time-bar {
33
- background: #ff7800;
34
- }
35
- .aio-popup-alert-warning .aio-popup-alert-footer button{
36
- background: #ff7800;
37
- }
38
- .aio-popup-alert-info svg {
39
- background: #0069ff;
40
- }
41
- .aio-popup-alert-info .aio-popup-time-bar {
42
- background: #0069ff;
43
- }
44
- .aio-popup-alert-info .aio-popup-alert-footer button{
45
- background: #0069ff;
46
- }
47
- .aio-popup-alert-header {
48
- height:48px;
49
- }
50
- .aio-popup-alert-text {
51
- color:#888;
52
- font-size:14px;
53
- }
54
- .aio-popup-alert-subtext {
55
- color:#444;
56
- font-size:14px;
57
- justify-content: center;
58
- display:flex;
59
- }
60
- .aio-popup-alert-footer {
61
- justify-content: center;
62
- padding:16px;
63
- height:unset;
64
- }
65
- .aio-popup-alert-footer button{
66
- width:100%;
67
- height:36px;
68
- }
package/alert2.css DELETED
@@ -1,70 +0,0 @@
1
- .aio-popup-alert {
2
- overflow: hidden !important;
3
- border-radius:8px;
4
- }
5
-
6
- .aio-popup-alert svg {
7
- fill: #fff !important;
8
- border-radius: 100%;
9
- padding: 12px;
10
- }
11
- .aio-popup-alert-error .aio-popup-alert-header {
12
- background: #f14747;
13
- }
14
- .aio-popup-alert-error .aio-popup-time-bar {
15
- background: #f14747;
16
- }
17
- .aio-popup-alert-error .aio-popup-alert-footer button{
18
- background: #f14747;
19
- }
20
- .aio-popup-alert-success .aio-popup-alert-header {
21
- background: #6EBC3D;
22
- }
23
- .aio-popup-alert-success .aio-popup-time-bar {
24
- background: #6EBC3D;
25
- }
26
- .aio-popup-alert-success .aio-popup-alert-footer button{
27
- background: #6EBC3D;
28
- }
29
- .aio-popup-alert-warning .aio-popup-alert-header {
30
- background: #ff7800;
31
- }
32
- .aio-popup-alert-warning .aio-popup-time-bar {
33
- background: #ff7800;
34
- }
35
- .aio-popup-alert-warning .aio-popup-alert-footer button{
36
- background: #ff7800;
37
- }
38
- .aio-popup-alert-info .aio-popup-alert-header {
39
- background: #0069ff;
40
- }
41
- .aio-popup-alert-info .aio-popup-time-bar {
42
- background: #0069ff;
43
- }
44
- .aio-popup-alert-info .aio-popup-alert-footer button{
45
- background: #0069ff;
46
- }
47
- .aio-popup-alert-header {
48
- height:144px;
49
- }
50
- .aio-popup-alert-text {
51
- color:#000;
52
- font-size:18px;
53
- padding:16px;
54
- }
55
- .aio-popup-alert-subtext {
56
- color:#444;
57
- font-size:14px;
58
- justify-content: center;
59
- display:flex;
60
- }
61
- .aio-popup-alert-footer {
62
- justify-content: center;
63
- padding:36px;
64
- height:unset;
65
- }
66
- .aio-popup-alert-footer button{
67
- width:100%;
68
- height:36px;
69
- border-radius:24px;
70
- }