bitmax-dialog
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -31,3 +31,3 @@ 'use strict'; | ||
setModals = _useState[1]; | ||
function addModal(element, data) { | ||
function addModal(element, data, options) { | ||
return new Promise(function (accept) { | ||
@@ -39,3 +39,4 @@ setModals([].concat(modals, [{ | ||
onClose: accept, | ||
closed: false | ||
closed: false, | ||
options: options | ||
}])); | ||
@@ -73,7 +74,8 @@ }); | ||
function ModalItemProvider(modal) { | ||
var _useState2 = React.useState({ | ||
size: 'sm', | ||
title: '', | ||
closable: false | ||
}), | ||
var defaultOptions = { | ||
size: 'sm', | ||
title: '', | ||
closable: false | ||
}; | ||
var _useState2 = React.useState(_extends({}, defaultOptions, modal.options)), | ||
options = _useState2[0], | ||
@@ -104,4 +106,4 @@ setOptions = _useState2[1]; | ||
var contextRoot = React.useContext(ModalRootContext); | ||
return function (data) { | ||
return contextRoot.addModal(element, data); | ||
return function (data, options) { | ||
return contextRoot.addModal(element, data, options); | ||
}; | ||
@@ -157,3 +159,3 @@ } | ||
className: "dialog-content " + (props.closed ? 'closed' : '') | ||
}, React__default.createElement("div", { | ||
}, props.title && React__default.createElement("div", { | ||
className: "dialog-header" | ||
@@ -160,0 +162,0 @@ }, React__default.createElement("h1", { |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e;function o(){return(o=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}var a=n.createContext({}),r=n.createContext({});function l(e){var a=t.useState({size:"sm",title:"",closable:!1}),l=a[0],i=a[1];return n.createElement(r.Provider,{value:{id:e.id,data:e.data,updateOptions:function(e){i((function(t){return o({},t,e)}))}}},n.createElement(s,{element:e.element,id:e.id,data:e.data,title:l.title,size:l.size,closed:e.closed}))}function i(){var e=t.useContext(r),n=t.useContext(a);return function(t){n.closeModal(e.id,t)}}function c(){var e=t.useContext(r),n=t.useContext(a);return function(){n.removeModal(e.id)}}var d={xs:480,sm:640,md:768,lg:1024,xl:1280,"2xl":1536};function s(e){var t=i(),o=c();return n.createElement("div",{className:"dialog"},n.createElement("div",{onClick:function(){return t()},className:"dialog-backdrop"}),n.createElement("div",{onAnimationEnd:function(e){"exit"==e.animationName&&o()},style:{maxWidth:d[e.size||"md"]},className:"dialog-content "+(e.closed?"closed":"")},n.createElement("div",{className:"dialog-header"},n.createElement("h1",{className:"dialog-title"},e.title),n.createElement("button",{className:"dialog-close",onClick:function(){return t()}},n.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",fill:"currentColor",viewBox:"0 0 16 16"},n.createElement("path",{d:"M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"})))),n.createElement("div",{className:"dialog-body"},n.createElement(e.element,null))))}exports.Dialog=s,exports.ModalItemContext=r,exports.ModalItemProvider=l,exports.ModalProvider=function(e){var r=t.useState([]),i=r[0],c=r[1];return n.createElement(a.Provider,{value:{removeModal:function(e){c(i.filter((function(t){return t.id!==e})))},addModal:function(e,t){return new Promise((function(n){c([].concat(i,[{id:(new Date).getTime().toString(),data:t,element:e,onClose:n,closed:!1}]))}))},closeModal:function(e,t){var n=i.find((function(t){return t.id==e}));null==n||n.onClose(t),c(i.map((function(t){return o({},t,{closed:t.id==e})})))}}},e.children,i.map((function(e){return n.createElement(l,Object.assign({key:e.id},e))})))},exports.ModalRootContext=a,exports.useModalClose=i,exports.useModalData=function(){return t.useContext(r).data},exports.useModalRemove=c,exports.useOpenModal=function(e){var n=t.useContext(a);return function(t){return n.addModal(e,t)}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e;function o(){return(o=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}var a=n.createContext({}),r=n.createContext({});function l(e){var a=t.useState(o({},{size:"sm",title:"",closable:!1},e.options)),l=a[0],i=a[1];return n.createElement(r.Provider,{value:{id:e.id,data:e.data,updateOptions:function(e){i((function(t){return o({},t,e)}))}}},n.createElement(d,{element:e.element,id:e.id,data:e.data,title:l.title,size:l.size,closed:e.closed}))}function i(){var e=t.useContext(r),n=t.useContext(a);return function(t){n.closeModal(e.id,t)}}function c(){var e=t.useContext(r),n=t.useContext(a);return function(){n.removeModal(e.id)}}var s={xs:480,sm:640,md:768,lg:1024,xl:1280,"2xl":1536};function d(e){var t=i(),o=c();return n.createElement("div",{className:"dialog"},n.createElement("div",{onClick:function(){return t()},className:"dialog-backdrop"}),n.createElement("div",{onAnimationEnd:function(e){"exit"==e.animationName&&o()},style:{maxWidth:s[e.size||"md"]},className:"dialog-content "+(e.closed?"closed":"")},e.title&&n.createElement("div",{className:"dialog-header"},n.createElement("h1",{className:"dialog-title"},e.title),n.createElement("button",{className:"dialog-close",onClick:function(){return t()}},n.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",fill:"currentColor",viewBox:"0 0 16 16"},n.createElement("path",{d:"M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708z"})))),n.createElement("div",{className:"dialog-body"},n.createElement(e.element,null))))}exports.Dialog=d,exports.ModalItemContext=r,exports.ModalItemProvider=l,exports.ModalProvider=function(e){var r=t.useState([]),i=r[0],c=r[1];return n.createElement(a.Provider,{value:{removeModal:function(e){c(i.filter((function(t){return t.id!==e})))},addModal:function(e,t,n){return new Promise((function(o){c([].concat(i,[{id:(new Date).getTime().toString(),data:t,element:e,onClose:o,closed:!1,options:n}]))}))},closeModal:function(e,t){var n=i.find((function(t){return t.id==e}));null==n||n.onClose(t),c(i.map((function(t){return o({},t,{closed:t.id==e})})))}}},e.children,i.map((function(e){return n.createElement(l,Object.assign({key:e.id},e))})))},exports.ModalRootContext=a,exports.useModalClose=i,exports.useModalData=function(){return t.useContext(r).data},exports.useModalRemove=c,exports.useOpenModal=function(e){var n=t.useContext(a);return function(t,o){return n.addModal(e,t,o)}}; | ||
//# sourceMappingURL=bitmax-dialog.cjs.production.min.js.map |
@@ -24,3 +24,3 @@ import React, { useState, useContext } from 'react'; | ||
setModals = _useState[1]; | ||
function addModal(element, data) { | ||
function addModal(element, data, options) { | ||
return new Promise(function (accept) { | ||
@@ -32,3 +32,4 @@ setModals([].concat(modals, [{ | ||
onClose: accept, | ||
closed: false | ||
closed: false, | ||
options: options | ||
}])); | ||
@@ -66,7 +67,8 @@ }); | ||
function ModalItemProvider(modal) { | ||
var _useState2 = useState({ | ||
size: 'sm', | ||
title: '', | ||
closable: false | ||
}), | ||
var defaultOptions = { | ||
size: 'sm', | ||
title: '', | ||
closable: false | ||
}; | ||
var _useState2 = useState(_extends({}, defaultOptions, modal.options)), | ||
options = _useState2[0], | ||
@@ -97,4 +99,4 @@ setOptions = _useState2[1]; | ||
var contextRoot = useContext(ModalRootContext); | ||
return function (data) { | ||
return contextRoot.addModal(element, data); | ||
return function (data, options) { | ||
return contextRoot.addModal(element, data, options); | ||
}; | ||
@@ -150,3 +152,3 @@ } | ||
className: "dialog-content " + (props.closed ? 'closed' : '') | ||
}, React.createElement("div", { | ||
}, props.title && React.createElement("div", { | ||
className: "dialog-header" | ||
@@ -153,0 +155,0 @@ }, React.createElement("h1", { |
/// <reference types="react" /> | ||
export declare function useOpenModal(element: () => JSX.Element): (data?: any) => Promise<any>; | ||
export declare function useModalData(): any; | ||
export declare function useModalClose(): (data?: any) => void; | ||
import { ModalOptionsType } from "./types"; | ||
export declare function useOpenModal<S = any>(element: () => JSX.Element): <T = any>(data?: S, options?: Partial<ModalOptionsType>) => Promise<T>; | ||
export declare function useModalData<T = any>(): T; | ||
export declare function useModalClose<T = any>(): (data?: T) => void; | ||
export declare function useModalRemove(): () => void; |
@@ -8,2 +8,3 @@ /// <reference types="react" /> | ||
closed: boolean; | ||
options: Partial<ModalOptionsType>; | ||
}; | ||
@@ -17,3 +18,3 @@ export declare type ModalSizes = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'; | ||
export declare type ModalRootContextProps = { | ||
addModal: (element: () => JSX.Element, data?: any) => Promise<any>; | ||
addModal: <T = any>(element: () => JSX.Element, data?: any, options?: Partial<ModalOptionsType>) => Promise<T>; | ||
removeModal: (id: string) => void; | ||
@@ -20,0 +21,0 @@ closeModal: (id: string, data?: any) => void; |
{ | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
67546
716