aio-popup 8.2.0 → 8.2.2

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.
Files changed (4) hide show
  1. package/index.css +61 -53
  2. package/index.d.ts +11 -31
  3. package/index.js +53 -41
  4. package/package.json +1 -1
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);
@@ -191,7 +197,9 @@
191
197
  width: 100%;
192
198
  overflow-y: auto;
193
199
  box-sizing: border-box;
194
- background:#fff;
200
+ }
201
+ .aio-popup-modal .aio-popup-body {
202
+ background: #fff;
195
203
  }
196
204
 
197
205
  .aio-popup-body * {
@@ -371,7 +379,7 @@
371
379
  align-items: center;
372
380
  box-sizing: border-box;
373
381
  padding: 0 12px;
374
- gap:6px;
382
+ gap: 6px;
375
383
  }
376
384
 
377
385
  .aio-popup-time {
@@ -813,72 +821,72 @@
813
821
  border-radius:6px;
814
822
  border:1px solid #eee;
815
823
  } */
816
- .aio-loading {
817
- z-index: 100000000000000000000000000000;
818
- position: fixed;
819
- direction: ltr;
820
- width: 100%;
821
- height: 100%;
822
- top: 0;
823
- left: 0;
824
- display: flex;
825
- align-items: center;
826
- align-items: center;
827
- 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;
828
836
  }
829
837
 
830
838
  .aio-loading-container-0 {
831
- border-radius: 12px;
832
- height: 72px;
833
- width: 72px;
834
- display: flex;
835
- align-items: center;
836
- justify-content: center;
837
- background: rgba(0, 0, 0, 0.7);
838
- opacity: 1;
839
- animation-name: aioloadingopacity;
840
- animation-duration: 2s;
841
- 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;
842
850
  }
843
851
 
844
852
  .aio-loading-0 {
845
- width: 60px;
846
- display: flex;
847
- align-items: center;
848
- justify-content: center;
853
+ width: 60px;
854
+ display: flex;
855
+ align-items: center;
856
+ justify-content: center;
849
857
  }
850
858
 
851
859
  .aio-loading-item-0 {
852
- width: 4px;
853
- height: 36px;
854
- background: rgb(255, 255, 255);
855
- margin: 0px 1.5px;
856
- border-radius: 0px;
860
+ width: 4px;
861
+ height: 36px;
862
+ background: rgb(255, 255, 255);
863
+ margin: 0px 1.5px;
864
+ border-radius: 0px;
857
865
  }
858
866
 
859
867
  @keyframes aioloading0 {
860
868
 
861
- 0%,
862
- 40%,
863
- 100% {
864
- transform: scaleY(0.4);
865
- }
869
+ 0%,
870
+ 40%,
871
+ 100% {
872
+ transform: scaleY(0.4);
873
+ }
866
874
 
867
- 20% {
868
- transform: scaleY(1.0);
869
- }
875
+ 20% {
876
+ transform: scaleY(1.0);
877
+ }
870
878
  }
871
879
 
872
880
  @keyframes aioloadingopacity {
873
- 0% {
874
- opacity: 0;
875
- }
881
+ 0% {
882
+ opacity: 0;
883
+ }
876
884
 
877
- 50% {
878
- opacity: 0;
879
- }
885
+ 50% {
886
+ opacity: 0;
887
+ }
880
888
 
881
- 100% {
882
- opacity: 1;
883
- }
889
+ 100% {
890
+ opacity: 1;
891
+ }
884
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,43 +118,21 @@ 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
121
  export type I_usePopup = ReturnType<typeof usePopup>;
142
122
  declare const usePopup: (props?: {
143
123
  rtl?: boolean;
144
124
  id?: string;
145
125
  }) => {
146
- addAlert: AP_addAlert;
147
- addSnackebar: AP_addSnackebar;
148
- removeModal: AP_removeModal;
149
- addModal: AP_addModal;
126
+ addAlert: (obj: AP_alert) => void;
127
+ addSnackebar: (item: AP_snackebar) => void;
128
+ removeModal: (arg?: string) => Promise<void>;
129
+ addModal: (o: AP_modal) => void;
150
130
  getModals: () => AP_modal[];
151
- addHighlight: AP_addHighlight;
152
- removeHighlight: AP_removeHighlight;
153
- render: AP_render;
154
- addConfirm: AP_addConfirm;
155
- addPrompt: AP_addPrompt;
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;
156
136
  portal: () => any;
157
137
  };
158
138
  export default usePopup;
package/index.js CHANGED
@@ -13,7 +13,6 @@ 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,10 +239,10 @@ const usePopup = (props) => {
235
239
  };
236
240
  addModal(config);
237
241
  };
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]);
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]);
239
243
  const render = (caller) => {
240
- return (_jsxs(CTX.Provider, { value: ctx, children: [modalsRef.current.map((modal, i) => {
241
- 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) }));
242
246
  }), snackebarItems.map((item, i) => _jsx(SnackebarItem, { item: item, index: i }, item.id)), !!highlight && _jsx(Highlight, { highlight: highlight })] }));
243
247
  };
244
248
  const portal = useMemo(() => {
@@ -253,7 +257,7 @@ const Prompt = ({ change, placeholder, text = '' }) => {
253
257
  };
254
258
  const POPUPCTX = createContext({});
255
259
  const Popup = ({ modal, isLast }) => {
256
- const mainContext = useContext(CTX);
260
+ const mainContext = useMainProvider();
257
261
  let { modalAttrs = {}, position = 'fullscreen', getTarget } = modal;
258
262
  let [temp] = useState({ dom: createRef(), backdropDom: createRef(), dui: undefined });
259
263
  let [popoverStyle, setPopoverStyle] = useState({});
@@ -331,6 +335,12 @@ const Popup = ({ modal, isLast }) => {
331
335
  }
332
336
  function getClassName() {
333
337
  let className = 'aio-popup';
338
+ if (modal.isPopover) {
339
+ className += ' aio-popup-popover';
340
+ }
341
+ else {
342
+ className += ' aio-popup-modal';
343
+ }
334
344
  className += mainContext.rtl ? ' rtl' : ' ltr';
335
345
  if (firstMount) {
336
346
  className += ' not-mounted';
@@ -341,10 +351,12 @@ const Popup = ({ modal, isLast }) => {
341
351
  return className;
342
352
  }
343
353
  const getContext = () => ({ modal, isLast, state, setState, onKeyDown });
354
+ console.log(mainContext.id);
344
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) }));
345
356
  };
346
357
  const ModalBackdrop = ({ children, firstMount, backdropDom, isModalMouseDown }) => {
347
- const { removeModal, rtl } = useContext(CTX);
358
+ const { removeModal, rtl, id: containerId } = useMainProvider();
359
+ console.log(containerId);
348
360
  let { modal, onKeyDown } = useContext(POPUPCTX);
349
361
  let { backdropAttrs = {}, id, position = 'fullscreen' } = modal;
350
362
  function backClick(e) {
@@ -367,7 +379,7 @@ const ModalBackdrop = ({ children, firstMount, backdropDom, isModalMouseDown })
367
379
  return _jsx("div", Object.assign({}, AddToAttrs(backdropAttrs, { className, attrs }), { children: children }));
368
380
  };
369
381
  const ModalHeader = () => {
370
- const { removeModal } = useContext(CTX);
382
+ const { removeModal } = useMainProvider();
371
383
  let { modal, state, setState } = useContext(POPUPCTX);
372
384
  if (!modal.header) {
373
385
  return null;
@@ -392,7 +404,7 @@ const ModalHeaderElement = ({ type }) => {
392
404
  return _jsx("div", { className: `aio-popup-header-${type}`, "data-subtitle": type === 'title' ? header.subtitle : undefined, children: header[type] });
393
405
  };
394
406
  const ModalClose = () => {
395
- const { removeModal } = useContext(CTX);
407
+ const { removeModal } = useMainProvider();
396
408
  let { modal, state, setState } = useContext(POPUPCTX), { header } = modal;
397
409
  if (typeof header === 'function' || !header) {
398
410
  return null;
@@ -429,7 +441,7 @@ const ModalFooter = () => {
429
441
  };
430
442
  const SBCTX = createContext({});
431
443
  const SnackebarItem = (props) => {
432
- const mainContext = useContext(CTX);
444
+ const mainContext = useMainProvider();
433
445
  let { item } = props;
434
446
  let { time = 8, id, align = ['right', 'top'] } = item;
435
447
  if (align[1] !== 'top' && align[1] !== 'bottom') {
@@ -533,24 +545,24 @@ export function Alert(props) {
533
545
  $(`.aio-popup-alert-container.${$$.id} .aio-popup-time`).html($$.getBarRender());
534
546
  },
535
547
  getRender() {
536
- return (`
537
- <div class='aio-popup-alert-container not-mounted ${$$.id} aio-popup-alert-container-center${!!className ? ` ${className}` : ''}'>
538
- <div class='aio-popup-alert aio-popup-alert-${type}'>
539
- <div class='aio-popup-alert-header'>${$$.getIcon()}</div>
540
- <div class='aio-popup-alert-body aio-popup-scroll'>
541
- <div class='aio-popup-alert-title'>${ReactDOMServer.renderToStaticMarkup(title)}</div>
542
- <div class='aio-popup-alert-text' style="text-align:${rtl ? 'right' : 'left'}">${text}</div>
543
- </div>
544
- <div class='aio-popup-alert-footer'>
545
- ${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>` : ''}
546
558
  ${actions.map((o) => {
547
559
  const { className, id, text } = o;
548
560
  return `<button data-action='${id}' class='aio-popup-alert-action${className ? ' ' + className : ''}'>${text}</button>`;
549
- }).join(' ')}
550
- </div>
551
- <div class='aio-popup-time'></div>
552
- </div>
553
- </div>
561
+ }).join(' ')}
562
+ </div>
563
+ <div class='aio-popup-time'></div>
564
+ </div>
565
+ </div>
554
566
  `);
555
567
  },
556
568
  close() {
@@ -738,16 +750,16 @@ function getEasing(highlight) {
738
750
  const { easing } = highlight;
739
751
  var easingNames = [
740
752
  'linear',
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
753
+ 'easeInQuad',
754
+ 'easeInSine',
755
+ 'easeInCirc',
756
+ 'easeInBack',
757
+ 'easeOutQuad',
758
+ 'easeOutSine',
759
+ 'easeOutCirc',
760
+ 'easeInOutQuad',
761
+ 'easeInOutSine',
762
+ 'easeInOutBack',
751
763
  'easeOutBounce', //27
752
764
  ];
753
765
  if (typeof easing === 'number') {
@@ -777,15 +789,15 @@ export class Loading {
777
789
  constructor(loader) {
778
790
  this.loader = '0';
779
791
  this.getLoader_0 = () => {
780
- return (`
781
- <div class="aio-loading-container-0">
782
- <div class="aio-loading-0">
792
+ return (`
793
+ <div class="aio-loading-container-0">
794
+ <div class="aio-loading-0">
783
795
  ${new Array(5).fill(0).map((o, i) => {
784
796
  if (o) { }
785
797
  return this.getLoaderItem_0(`0.${i}`);
786
- }).join(' ')}
787
- </div>
788
- </div>
798
+ }).join(' ')}
799
+ </div>
800
+ </div>
789
801
  `);
790
802
  };
791
803
  this.getLoaderItem_0 = (ease) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-popup",
3
- "version": "8.2.0",
3
+ "version": "8.2.2",
4
4
  "description": "handle all types of popup and modals in react",
5
5
  "main": "index.js",
6
6
  "scripts": {