UNPKG

react-circular-reveal

Version:

Quickly and easily add Material Design's "Circular Reveal" animation in your web app.

669 lines (560 loc) 22.6 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("react")); else if(typeof define === 'function' && define.amd) define(["react"], factory); else if(typeof exports === 'object') exports["react-circular-reveal"] = factory(require("react")); else root["react-circular-reveal"] = factory(root["React"]); })(window, function(__WEBPACK_EXTERNAL_MODULE__0__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 1); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE__0__; /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { module.exports = __webpack_require__(6); /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { var content = __webpack_require__(3); if (typeof content === 'string') { content = [[module.i, content, '']]; } var options = {} options.insert = "head"; options.singleton = false; var update = __webpack_require__(5)(content, options); if (content.locals) { module.exports = content.locals; } /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { exports = module.exports = __webpack_require__(4)(false); // Module exports.push([module.i, "\r\n.circular-reveal__overlay {\r\n position: relative;\r\n pointer-events: all;\r\n overflow: hidden;\r\n}\r\n\r\n.circular-reveal__revealCurtain {\r\n position: absolute;\r\n width: 0;\r\n height: 0;\r\n border-radius: 50%;\r\n overflow: hidden;\r\n}\r\n\r\n.circular-reveal__revealContent {\r\n position: absolute;\r\n left: 0;\r\n right: 0;\r\n top: 0;\r\n bottom: 0;\r\n min-width: 500px;\r\n}\r\n", ""]); /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ // css base code, injected by the css-loader // eslint-disable-next-line func-names module.exports = function (useSourceMap) { var list = []; // return the list of modules as css string list.toString = function toString() { return this.map(function (item) { var content = cssWithMappingToString(item, useSourceMap); if (item[2]) { return "@media ".concat(item[2], "{").concat(content, "}"); } return content; }).join(''); }; // import a list of modules into the list // eslint-disable-next-line func-names list.i = function (modules, mediaQuery) { if (typeof modules === 'string') { // eslint-disable-next-line no-param-reassign modules = [[null, modules, '']]; } var alreadyImportedModules = {}; for (var i = 0; i < this.length; i++) { // eslint-disable-next-line prefer-destructuring var id = this[i][0]; if (id != null) { alreadyImportedModules[id] = true; } } for (var _i = 0; _i < modules.length; _i++) { var item = modules[_i]; // skip already imported module // this implementation is not 100% perfect for weird media query combinations // when a module is imported multiple times with different media queries. // I hope this will never occur (Hey this way we have smaller bundles) if (item[0] == null || !alreadyImportedModules[item[0]]) { if (mediaQuery && !item[2]) { item[2] = mediaQuery; } else if (mediaQuery) { item[2] = "(".concat(item[2], ") and (").concat(mediaQuery, ")"); } list.push(item); } } }; return list; }; function cssWithMappingToString(item, useSourceMap) { var content = item[1] || ''; // eslint-disable-next-line prefer-destructuring var cssMapping = item[3]; if (!cssMapping) { return content; } if (useSourceMap && typeof btoa === 'function') { var sourceMapping = toComment(cssMapping); var sourceURLs = cssMapping.sources.map(function (source) { return "/*# sourceURL=".concat(cssMapping.sourceRoot).concat(source, " */"); }); return [content].concat(sourceURLs).concat([sourceMapping]).join('\n'); } return [content].join('\n'); } // Adapted from convert-source-map (MIT) function toComment(sourceMap) { // eslint-disable-next-line no-undef var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))); var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64); return "/*# ".concat(data, " */"); } /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var stylesInDom = {}; var isOldIE = function isOldIE() { var memo; return function memorize() { if (typeof memo === 'undefined') { // Test for IE <= 9 as proposed by Browserhacks // @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805 // Tests for existence of standard globals is to allow style-loader // to operate correctly into non-standard environments // @see https://github.com/webpack-contrib/style-loader/issues/177 memo = Boolean(window && document && document.all && !window.atob); } return memo; }; }(); var getTarget = function getTarget() { var memo = {}; return function memorize(target) { if (typeof memo[target] === 'undefined') { var styleTarget = document.querySelector(target); // Special case to return head of iframe instead of iframe itself if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) { try { // This will throw an exception if access to iframe is blocked // due to cross-origin restrictions styleTarget = styleTarget.contentDocument.head; } catch (e) { // istanbul ignore next styleTarget = null; } } memo[target] = styleTarget; } return memo[target]; }; }(); function listToStyles(list, options) { var styles = []; var newStyles = {}; for (var i = 0; i < list.length; i++) { var item = list[i]; var id = options.base ? item[0] + options.base : item[0]; var css = item[1]; var media = item[2]; var sourceMap = item[3]; var part = { css: css, media: media, sourceMap: sourceMap }; if (!newStyles[id]) { styles.push(newStyles[id] = { id: id, parts: [part] }); } else { newStyles[id].parts.push(part); } } return styles; } function addStylesToDom(styles, options) { for (var i = 0; i < styles.length; i++) { var item = styles[i]; var domStyle = stylesInDom[item.id]; var j = 0; if (domStyle) { domStyle.refs++; for (; j < domStyle.parts.length; j++) { domStyle.parts[j](item.parts[j]); } for (; j < item.parts.length; j++) { domStyle.parts.push(addStyle(item.parts[j], options)); } } else { var parts = []; for (; j < item.parts.length; j++) { parts.push(addStyle(item.parts[j], options)); } stylesInDom[item.id] = { id: item.id, refs: 1, parts: parts }; } } } function insertStyleElement(options) { var style = document.createElement('style'); if (typeof options.attributes.nonce === 'undefined') { var nonce = true ? __webpack_require__.nc : undefined; if (nonce) { options.attributes.nonce = nonce; } } Object.keys(options.attributes).forEach(function (key) { style.setAttribute(key, options.attributes[key]); }); if (typeof options.insert === 'function') { options.insert(style); } else { var target = getTarget(options.insert || 'head'); if (!target) { throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid."); } target.appendChild(style); } return style; } function removeStyleElement(style) { // istanbul ignore if if (style.parentNode === null) { return false; } style.parentNode.removeChild(style); } /* istanbul ignore next */ var replaceText = function replaceText() { var textStore = []; return function replace(index, replacement) { textStore[index] = replacement; return textStore.filter(Boolean).join('\n'); }; }(); function applyToSingletonTag(style, index, remove, obj) { var css = remove ? '' : obj.css; // For old IE /* istanbul ignore if */ if (style.styleSheet) { style.styleSheet.cssText = replaceText(index, css); } else { var cssNode = document.createTextNode(css); var childNodes = style.childNodes; if (childNodes[index]) { style.removeChild(childNodes[index]); } if (childNodes.length) { style.insertBefore(cssNode, childNodes[index]); } else { style.appendChild(cssNode); } } } function applyToTag(style, options, obj) { var css = obj.css; var media = obj.media; var sourceMap = obj.sourceMap; if (media) { style.setAttribute('media', media); } if (sourceMap && btoa) { css += "\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))), " */"); } // For old IE /* istanbul ignore if */ if (style.styleSheet) { style.styleSheet.cssText = css; } else { while (style.firstChild) { style.removeChild(style.firstChild); } style.appendChild(document.createTextNode(css)); } } var singleton = null; var singletonCounter = 0; function addStyle(obj, options) { var style; var update; var remove; if (options.singleton) { var styleIndex = singletonCounter++; style = singleton || (singleton = insertStyleElement(options)); update = applyToSingletonTag.bind(null, style, styleIndex, false); remove = applyToSingletonTag.bind(null, style, styleIndex, true); } else { style = insertStyleElement(options); update = applyToTag.bind(null, style, options); remove = function remove() { removeStyleElement(style); }; } update(obj); return function updateStyle(newObj) { if (newObj) { if (newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap) { return; } update(obj = newObj); } else { remove(); } }; } module.exports = function (list, options) { options = options || {}; options.attributes = typeof options.attributes === 'object' ? options.attributes : {}; // Force single-tag solution on IE6-9, which has a hard limit on the # of <style> // tags it will allow on a page if (!options.singleton && typeof options.singleton !== 'boolean') { options.singleton = isOldIE(); } var styles = listToStyles(list, options); addStylesToDom(styles, options); return function update(newList) { var mayRemove = []; for (var i = 0; i < styles.length; i++) { var item = styles[i]; var domStyle = stylesInDom[item.id]; if (domStyle) { domStyle.refs--; mayRemove.push(domStyle); } } if (newList) { var newStyles = listToStyles(newList, options); addStylesToDom(newStyles, options); } for (var _i = 0; _i < mayRemove.length; _i++) { var _domStyle = mayRemove[_i]; if (_domStyle.refs === 0) { for (var j = 0; j < _domStyle.parts.length; j++) { _domStyle.parts[j](); } delete stylesInDom[_domStyle.id]; } } }; }; /***/ }), /* 6 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); // EXTERNAL MODULE: external {"root":"React","commonjs2":"react","commonjs":"react","amd":"react"} var external_root_React_commonjs2_react_commonjs_react_amd_react_ = __webpack_require__(0); var external_root_React_commonjs2_react_commonjs_react_amd_react_default = /*#__PURE__*/__webpack_require__.n(external_root_React_commonjs2_react_commonjs_react_amd_react_); // EXTERNAL MODULE: ./.tmp/CircularRevealPanel.css var CircularRevealPanel = __webpack_require__(2); // CONCATENATED MODULE: ./.tmp/CircularRevealPanel.js var CurtainEvent = /** @class */ (function () { function CurtainEvent(type, curtainElemRef, revealContentElemRef) { this.type = type; this.curtainElemRef = curtainElemRef; this.revealContentElemRef = revealContentElemRef; } return CurtainEvent; }()); var CircularRevealPanel_CircularRevealPanel = function (_a) { var reveal = _a.reveal, children = _a.children, contentMinWidth = _a.contentMinWidth, revealContent = _a.revealContent, revealCurtainContent = _a.revealCurtainContent, speed = _a.speed, onChange = _a.onChange; var mousePositionRef = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_["useRef"])({ x: 0, y: 0 }); var forward = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_["useRef"])(false); var animating = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_["useRef"])(reveal); var opened = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_["useRef"])(reveal); var revealCurtainRef = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_["useRef"])(null); var revealOverlayRef = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_["useRef"])(null); var revealContentRef = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_["useRef"])(null); var onMouseMove = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_["useCallback"])(function (e) { if (revealOverlayRef.current && !animating.current) { mousePositionRef.current.x = e.clientX - revealOverlayRef.current.getBoundingClientRect().left; mousePositionRef.current.y = e.clientY - revealOverlayRef.current.getBoundingClientRect().top; } }, [animating]); var globalID = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_["useRef"])(-1); var sizeRef = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_["useRef"])(1); var resizeCurtainFunction; if (typeof speed === 'function') { resizeCurtainFunction = speed; } else { switch (speed) { case 'very slow': resizeCurtainFunction = function (size, opening) { return opening ? size + Math.max(size / 15, 1) : size - Math.max(size / 15, 1); }; break; case 'slow': resizeCurtainFunction = function (size, opening) { return opening ? size + Math.max(size / 6, 2) : size - Math.max(size / 6, 2); }; break; case 'normal': resizeCurtainFunction = function (size, opening) { return opening ? size + Math.max(size / 3, 5) : size - Math.max(size / 3, 5); }; break; case 'fast': resizeCurtainFunction = function (size, opening) { return opening ? size + Math.max(size / 3, 20) : size - Math.max(size / 3, 20); }; break; default: throw new Error('react-circular-reveal: Invalid speed value.'); } } var animateCurtain = function () { if (revealCurtainRef.current && revealOverlayRef.current && revealContentRef.current) { var size = sizeRef.current; var mousePos = mousePositionRef.current; var curtainStyle = revealCurtainRef.current.style; var revealCurtainStyle = revealContentRef.current.style; var overlayRect = revealOverlayRef.current.getBoundingClientRect(); var overlayWidth = overlayRect.width; var maxCircularSize = Math.max(overlayRect.height, overlayRect.width) * 2.5; curtainStyle.width = size + 'px'; curtainStyle.height = size + 'px'; curtainStyle.left = mousePos.x - size / 2 + 'px'; curtainStyle.top = mousePos.y - size / 2 + 'px'; revealCurtainStyle.minWidth = Math.min(overlayWidth, contentMinWidth) + 'px'; revealCurtainStyle.width = overlayWidth + 'px'; revealCurtainStyle.top = size / 2 - mousePos.y + 'px'; revealCurtainStyle.left = size / 2 - mousePos.x + 'px'; if ((forward.current && size < maxCircularSize) || (!forward.current && size > 0)) { sizeRef.current = resizeCurtainFunction(size, forward.current); globalID.current = requestAnimationFrame(animateCurtain); } else { animating.current = false; // at the end of closing, we make sure the curtain has 0 dimensions so that it does not interfere with // anything else until reopened. if (!forward.current) { curtainStyle.width = '0px'; curtainStyle.height = '0px'; } if (onChange) { onChange(new CurtainEvent(forward.current ? 'CURTAIN_OPENED' : 'CURTAIN_CLOSED', revealCurtainRef.current, revealContentRef.current)); } } } }; var doReveal = function () { animating.current = true; opened.current = !opened.current; if (onChange) { onChange(new CurtainEvent(!forward.current ? 'CURTAIN_OPENING' : 'CURTAIN_CLOSING', revealCurtainRef.current, revealContentRef.current)); } if (globalID.current !== -1) { cancelAnimationFrame(globalID.current); globalID.current = -1; } forward.current = !forward.current; animateCurtain(); }; if (reveal !== opened.current && !animating.current) { doReveal(); } return external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.createElement("div", { ref: revealOverlayRef, className: 'circular-reveal__overlay', onMouseMove: onMouseMove }, children, external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.createElement("div", { ref: revealCurtainRef, className: 'circular-reveal__revealCurtain' }, external_root_React_commonjs2_react_commonjs_react_amd_react_default.a.createElement("div", { ref: revealContentRef, className: 'circular-reveal__revealContent' }, revealContent), revealCurtainContent)); }; CircularRevealPanel_CircularRevealPanel.defaultProps = { contentMinWidth: 500, reveal: false, speed: 'normal' }; // CONCATENATED MODULE: ./.tmp/index.js /* concated harmony reexport CurtainEvent */__webpack_require__.d(__webpack_exports__, "CurtainEvent", function() { return CurtainEvent; }); /* concated harmony reexport CircularRevealPanel */__webpack_require__.d(__webpack_exports__, "CircularRevealPanel", function() { return CircularRevealPanel_CircularRevealPanel; }); /***/ }) /******/ ]); });