aio-popup 6.6.2 → 7.0.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
@@ -32,6 +32,7 @@
32
32
  outline: none;
33
33
  z-index: 10;
34
34
  position: absolute;
35
+ border:1px solid #ddd;
35
36
  }
36
37
 
37
38
  .aio-popup.rtl {
@@ -149,7 +150,6 @@
149
150
  color: #323130;
150
151
  padding: 6px 12px;
151
152
  font-size: 14px;
152
- font-weight: bold;
153
153
  min-height: 36px;
154
154
  gap: 12px;
155
155
  align-items: center;
@@ -193,6 +193,7 @@
193
193
  width: 100%;
194
194
  overflow-y: auto;
195
195
  box-sizing: border-box;
196
+ border-radius:6px;
196
197
  }
197
198
 
198
199
  .aio-popup-body * {
package/index.d.ts CHANGED
@@ -17,7 +17,6 @@ export type AP_header = {
17
17
  setState: (state: any) => void;
18
18
  }) => void);
19
19
  };
20
- type AP_setAttrs = (mode: AP_attrsKey) => any;
21
20
  export type AP_modal = {
22
21
  getTarget?: () => any;
23
22
  limitTo?: string;
@@ -31,9 +30,14 @@ export type AP_modal = {
31
30
  body: ReactNode;
32
31
  animate?: boolean;
33
32
  fitHorizontal?: boolean;
34
- setAttrs?: AP_setAttrs;
33
+ backdropAttrs?: any;
34
+ modalAttrs?: any;
35
+ bodyAttrs?: any;
36
+ headerAttrs?: any;
37
+ footerAttrs?: any;
35
38
  pageSelector?: string;
36
39
  focus?: boolean;
40
+ backdropClose?: boolean;
37
41
  };
38
42
  export type AP_alert = {
39
43
  rtl?: boolean;
@@ -89,7 +93,11 @@ export type AP_confirm = {
89
93
  onCansel?: () => void;
90
94
  submitAttrs?: any;
91
95
  canselAttrs?: any;
92
- setAttrs?: AP_setAttrs;
96
+ backdropAttrs?: any;
97
+ modalAttrs?: any;
98
+ bodyAttrs?: any;
99
+ headerAttrs?: any;
100
+ footerAttrs?: any;
93
101
  };
94
102
  export type AP_prompt = {
95
103
  title?: string;
@@ -101,7 +109,11 @@ export type AP_prompt = {
101
109
  onCansel?: () => void;
102
110
  submitAttrs?: any;
103
111
  canselAttrs?: any;
104
- setAttrs?: AP_setAttrs;
112
+ backdropAttrs?: any;
113
+ modalAttrs?: any;
114
+ bodyAttrs?: any;
115
+ headerAttrs?: any;
116
+ footerAttrs?: any;
105
117
  };
106
118
  type AP_removeModal = (arg?: string) => void;
107
119
  type AP_addAlert = (p: AP_alert) => void;
package/index.js CHANGED
@@ -11,8 +11,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
11
11
  import { createRef, useEffect, useState, createContext, useContext, useRef } from 'react';
12
12
  import * as ReactDOMServer from 'react-dom/server';
13
13
  import ReactDOM from 'react-dom';
14
- import anime from "animejs/lib/anime.es.js";
15
- import $ from 'jquery';
14
+ import { $, anime } from 'aio-depencencies';
16
15
  import './index.css';
17
16
  const CTX = createContext({});
18
17
  function Align(p) {
@@ -165,7 +164,7 @@ const usePopup = (props) => {
165
164
  const addHighlight = (highlight) => setHighlight(highlight);
166
165
  const removeHighlight = () => setHighlight(undefined);
167
166
  const addConfirm = (obj) => {
168
- let { title, subtitle, text, submitText = 'Yes', canselText = 'No', onSubmit, onCansel = () => { }, setAttrs = () => { return {}; } } = obj;
167
+ let { title, subtitle, text, submitText = 'Yes', canselText = 'No', onSubmit, onCansel = () => { }, modalAttrs, backdropAttrs, headerAttrs, footerAttrs, bodyAttrs } = obj;
169
168
  const submitAttrs = AddToAttrs(obj.submitAttrs, {
170
169
  className: 'active', attrs: {
171
170
  onClick: () => __awaiter(void 0, void 0, void 0, function* () {
@@ -188,17 +187,15 @@ const usePopup = (props) => {
188
187
  });
189
188
  let config = {
190
189
  position: 'center', header: { title, subtitle }, body: _jsx(_Fragment, { children: text }),
191
- setAttrs: (key) => {
192
- let attrs = setAttrs(key);
193
- return key === 'modal' ? AddToAttrs(attrs, { className: 'aio-popup-confirm' }) : attrs;
194
- },
190
+ modalAttrs: AddToAttrs(modalAttrs, { className: 'aio-popup-confirm' }),
191
+ backdropAttrs, headerAttrs, footerAttrs, bodyAttrs,
195
192
  footer: (_jsxs(_Fragment, { children: [_jsx("button", Object.assign({}, canselAttrs, { children: canselText })), _jsx("button", Object.assign({}, submitAttrs, { children: submitText }))] }))
196
193
  };
197
194
  addModal(config);
198
195
  };
199
196
  const addPrompt = (obj) => {
200
197
  const id = 'a' + (Math.round(Math.random() * 100000));
201
- let { title, text = '', subtitle, submitText = 'Submit', canselText = 'close', onSubmit, onCansel = () => { }, setAttrs = () => { return {}; } } = obj;
198
+ let { title, text = '', subtitle, submitText = 'Submit', canselText = 'close', onSubmit, onCansel = () => { }, modalAttrs, backdropAttrs, headerAttrs, footerAttrs, bodyAttrs } = obj;
202
199
  const submitAttrs = AddToAttrs(obj.submitAttrs, {
203
200
  className: 'active', attrs: {
204
201
  onClick: () => __awaiter(void 0, void 0, void 0, function* () {
@@ -223,16 +220,16 @@ const usePopup = (props) => {
223
220
  type: 'button'
224
221
  }
225
222
  });
226
- const canselAttrs = AddToAttrs(obj.canselAttrs, { attrs: {
223
+ const canselAttrs = AddToAttrs(obj.canselAttrs, {
224
+ attrs: {
227
225
  onClick: () => { onCansel(); removeModal(); },
228
226
  type: 'button'
229
- } });
227
+ }
228
+ });
230
229
  let config = {
231
230
  position: 'center', header: { title, subtitle },
232
- setAttrs: (key) => {
233
- let attrs = setAttrs(key);
234
- return key === 'modal' ? AddToAttrs(attrs, { className: 'aio-popup-prompt' }) : attrs;
235
- },
231
+ modalAttrs: AddToAttrs(modalAttrs, { className: 'aio-popup-prompt' }),
232
+ backdropAttrs, headerAttrs, footerAttrs, bodyAttrs,
236
233
  body: _jsx(Prompt, { change: (value) => promptTexts.current = Object.assign(Object.assign({}, promptTexts.current), { [id]: value }), placeholder: text }),
237
234
  footer: (_jsxs(_Fragment, { children: [_jsx("button", Object.assign({}, canselAttrs, { children: canselText })), _jsx("button", Object.assign({}, submitAttrs, { children: submitText }))] }))
238
235
  };
@@ -261,14 +258,13 @@ const Prompt = ({ change, placeholder }) => {
261
258
  const POPUPCTX = createContext({});
262
259
  const Popup = ({ modal, isLast }) => {
263
260
  const mainContext = useContext(CTX);
264
- let { setAttrs = () => { return {}; }, position = 'fullscreen', getTarget } = modal;
261
+ let { modalAttrs = {}, position = 'fullscreen', getTarget } = modal;
265
262
  let [temp] = useState({ dom: createRef(), backdropDom: createRef(), dui: undefined });
266
263
  let [popoverStyle, setPopoverStyle] = useState({});
267
264
  let modalMouseDown = useRef(false);
268
265
  //bar taraf kardane moshkele mozakhrafe click rooye backdrop ke az har ja mouse ro roosh vel mikoni modal baste mishe
269
266
  const isModalMouseDown = () => modalMouseDown.current;
270
267
  let [state, setState] = useState(modal.state);
271
- let attrs = setAttrs('modal') || {};
272
268
  const firstMount = useRef(false);
273
269
  useEffect(() => () => { $(window).unbind('click', handleBackClick); });
274
270
  useEffect(() => {
@@ -303,9 +299,9 @@ const Popup = ({ modal, isLast }) => {
303
299
  mainContext.removeModal();
304
300
  }
305
301
  function getModalProps() {
306
- let style = Object.assign(Object.assign({}, popoverStyle), attrs.style);
302
+ let style = Object.assign(Object.assign({}, popoverStyle), modalAttrs.style);
307
303
  let ev = "ontouchstart" in document.documentElement ? 'onTouchStart' : 'onMouseDown';
308
- return Object.assign(Object.assign({}, attrs), { ref: temp.dom, "data-id": modal.id, tabIndex: 0, onKeyDown, [ev]: mouseDown, className: getClassName(), style: Object.assign({}, style), onClick: (e) => { e.stopPropagation(); } });
304
+ return Object.assign(Object.assign({}, modalAttrs), { ref: temp.dom, "data-id": modal.id, tabIndex: 0, onKeyDown, [ev]: mouseDown, className: getClassName(), style: Object.assign({}, style), onClick: (e) => { e.stopPropagation(); } });
309
305
  }
310
306
  function getPopoverStyle() {
311
307
  if (!getTarget) {
@@ -315,7 +311,7 @@ const Popup = ({ modal, isLast }) => {
315
311
  if (!target || !target.length) {
316
312
  return {};
317
313
  }
318
- let p = { modal: $(temp.dom.current), target, fitHorizontal: modal.fitHorizontal, limitTo: modal.limitTo, attrs, rtl: mainContext.rtl, pageSelector: modal.pageSelector };
314
+ let p = { modal: $(temp.dom.current), target, fitHorizontal: modal.fitHorizontal, limitTo: modal.limitTo, attrs: modalAttrs, rtl: mainContext.rtl, pageSelector: modal.pageSelector };
319
315
  let style = Align(p);
320
316
  let res = Object.assign(Object.assign({}, style), { position: 'absolute' });
321
317
  return res;
@@ -343,8 +339,8 @@ const Popup = ({ modal, isLast }) => {
343
339
  if (firstMount) {
344
340
  className += ' not-mounted';
345
341
  }
346
- if (attrs.className) {
347
- className += ' ' + attrs.className;
342
+ if (modalAttrs.className) {
343
+ className += ' ' + modalAttrs.className;
348
344
  }
349
345
  return className;
350
346
  }
@@ -354,8 +350,7 @@ const Popup = ({ modal, isLast }) => {
354
350
  const ModalBackdrop = ({ children, firstMount, backdropDom, isModalMouseDown }) => {
355
351
  const { removeModal, rtl } = useContext(CTX);
356
352
  let { modal, onKeyDown } = useContext(POPUPCTX);
357
- let { setAttrs = () => { return {}; }, id, position = 'fullscreen' } = modal;
358
- const [attrs] = useState(setAttrs('backdrop') || {});
353
+ let { backdropAttrs = {}, id, position = 'fullscreen' } = modal;
359
354
  function backClick(e) {
360
355
  if (isModalMouseDown()) {
361
356
  return;
@@ -367,18 +362,13 @@ const ModalBackdrop = ({ children, firstMount, backdropDom, isModalMouseDown })
367
362
  if (!target.hasClass('aio-popup-backdrop')) {
368
363
  return;
369
364
  }
370
- removeModal();
371
- }
372
- function getProps() {
373
- let className = 'aio-popup-backdrop';
374
- className += ` aio-popup-position-${position}`;
375
- className += rtl ? ' rtl' : ' ltr';
376
- if (firstMount) {
377
- className += ' not-mounted';
365
+ if (modal.backdropClose !== false) {
366
+ removeModal();
378
367
  }
379
- return AddToAttrs(attrs, { className, attrs: { ref: backdropDom, onKeyDown, tabIndex: 0, ['data-id']: id, onClick: attrs.onClick ? attrs.onClick : backClick } });
380
368
  }
381
- return _jsx("div", Object.assign({}, getProps(), { children: children }));
369
+ const className = ['aio-popup-backdrop', `aio-popup-position-${position}`, rtl ? 'rtl' : 'ltr', firstMount ? 'not-mounted' : undefined];
370
+ const attrs = { ref: backdropDom, onKeyDown, tabIndex: 0, ['data-id']: id, onClick: backdropAttrs.onClick ? backdropAttrs.onClick : backClick };
371
+ return _jsx("div", Object.assign({}, AddToAttrs(backdropAttrs, { className, attrs }), { children: children }));
382
372
  };
383
373
  const ModalHeader = () => {
384
374
  const { removeModal } = useContext(CTX);
@@ -386,15 +376,14 @@ const ModalHeader = () => {
386
376
  if (!modal.header) {
387
377
  return null;
388
378
  }
389
- let { setAttrs = () => { return {}; } } = modal;
390
- let attrs = setAttrs('header') || {};
379
+ let { headerAttrs = {} } = modal;
391
380
  if (modal.header && modal.header.html) {
392
381
  return modal.header.html({ removeModal: removeModal, state, setState });
393
382
  }
394
383
  if (typeof modal.header !== 'object') {
395
384
  return null;
396
385
  }
397
- return (_jsxs("div", Object.assign({}, AddToAttrs(attrs, { className: 'aio-popup-header' }), { children: [_jsx(ModalHeaderElement, { type: 'before' }, 'before'), _jsx(ModalHeaderElement, { type: 'title' }, 'title'), _jsx(ModalHeaderElement, { type: 'after' }, 'after'), _jsx(ModalClose, {})] })));
386
+ return (_jsxs("div", Object.assign({}, AddToAttrs(headerAttrs, { className: 'aio-popup-header' }), { children: [_jsx(ModalHeaderElement, { type: 'before' }, 'before'), _jsx(ModalHeaderElement, { type: 'title' }, 'title'), _jsx(ModalHeaderElement, { type: 'after' }, 'after'), _jsx(ModalClose, {})] })));
398
387
  };
399
388
  const ModalHeaderElement = ({ type }) => {
400
389
  let { modal } = useContext(POPUPCTX), { header } = modal;
@@ -428,22 +417,19 @@ const ModalClose = () => {
428
417
  };
429
418
  const ModalBody = () => {
430
419
  const { modal } = useContext(POPUPCTX);
431
- let { body, setAttrs = () => { return {}; } } = modal;
432
- let attrs = setAttrs('body') || {};
420
+ let { body, bodyAttrs = {} } = modal;
433
421
  if (!body || body === null) {
434
422
  return null;
435
423
  }
436
- return (_jsx("div", Object.assign({}, AddToAttrs(attrs, { className: 'aio-popup-body aio-popup-scroll' }), { children: body })));
424
+ return (_jsx("div", Object.assign({}, AddToAttrs(bodyAttrs, { className: 'aio-popup-body aio-popup-scroll' }), { children: body })));
437
425
  };
438
426
  const ModalFooter = () => {
439
427
  const { modal } = useContext(POPUPCTX);
440
- let { setAttrs = () => { return {}; }, footer } = modal;
428
+ let { footerAttrs = {}, footer } = modal;
441
429
  if (!footer) {
442
430
  return null;
443
431
  }
444
- let Attrs = setAttrs('footer') || {};
445
- const attrs = AddToAttrs(Attrs, { className: 'aio-popup-footer' });
446
- return _jsx("div", Object.assign({}, attrs, { children: footer }));
432
+ return _jsx("div", Object.assign({}, AddToAttrs(footerAttrs, { className: 'aio-popup-footer' }), { children: footer }));
447
433
  };
448
434
  const SBCTX = createContext({});
449
435
  const SnackebarItem = (props) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aio-popup",
3
- "version": "6.6.2",
3
+ "version": "7.0.0",
4
4
  "description": "handle all types of popup and modals in react",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -12,8 +12,7 @@
12
12
  "url": "git+https://github.com/mohammadFeiz/aio-popup.git"
13
13
  },
14
14
  "dependencies": {
15
- "jquery": "^3.6.1",
16
- "animejs": "^3.2.1"
15
+ "aio-depencencies": "latest"
17
16
  },
18
17
  "keywords": [
19
18
  "popup",