react-hook-popup
Advanced tools
Comparing version 0.0.5-alpha.2 to 0.0.5-alpha.3
@@ -1,1 +0,5 @@ | ||
export {SnackBar, SnackBarProps} from "./Snackbar/index.js"; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SnackBar = void 0; | ||
var Snackbar_1 = require("./Snackbar"); | ||
Object.defineProperty(exports, "SnackBar", { enumerable: true, get: function () { return Snackbar_1.SnackBar; } }); |
@@ -1,1 +0,5 @@ | ||
export {SnackBar, SnackBarProps} from "./SnackBar.js"; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SnackBar = void 0; | ||
var SnackBar_1 = require("./SnackBar"); | ||
Object.defineProperty(exports, "SnackBar", { enumerable: true, get: function () { return SnackBar_1.SnackBar; } }); |
@@ -1,17 +0,34 @@ | ||
import React, {useEffect} from "../../web_modules/react.js"; | ||
import "./snackbar.css.proxy.js"; | ||
const DEFAULT_VARIANT = "info"; | ||
const DEFAULT_TIMEOUT = 4e3; | ||
export const SnackBar = ({ | ||
children, | ||
handleClose, | ||
variant = DEFAULT_VARIANT, | ||
timeout = DEFAULT_TIMEOUT | ||
}) => { | ||
useEffect(() => { | ||
setTimeout(handleClose, timeout); | ||
}, []); | ||
return /* @__PURE__ */ React.createElement("div", { | ||
className: `rhp-snackbar ${variant}` | ||
}, children); | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SnackBar = void 0; | ||
var react_1 = __importStar(require("react")); | ||
require("./snackbar.scss"); | ||
var DEFAULT_VARIANT = 'info'; | ||
var DEFAULT_TIMEOUT = 4000; | ||
var SnackBar = function (_a) { | ||
var children = _a.children, handleClose = _a.handleClose, _b = _a.variant, variant = _b === void 0 ? DEFAULT_VARIANT : _b, _c = _a.timeout, timeout = _c === void 0 ? DEFAULT_TIMEOUT : _c; | ||
react_1.useEffect(function () { | ||
setTimeout(handleClose, timeout); | ||
}, []); | ||
return react_1.default.createElement("div", { className: "rhp-snackbar " + variant }, children); | ||
}; | ||
exports.SnackBar = SnackBar; |
@@ -1,19 +0,23 @@ | ||
import {useContext, useEffect} from "../web_modules/react.js"; | ||
import {PopupContext as PopupContext2} from "../PopupContext.js"; | ||
export function usePopup(key, popupRenderer) { | ||
const {registerPopup, unRegisterPopup, displayPopup, closePopup} = useContext(PopupContext2); | ||
useEffect(() => { | ||
registerPopup(key, popupRenderer); | ||
return () => { | ||
unRegisterPopup(key); | ||
}; | ||
}, []); | ||
return [ | ||
(message) => { | ||
displayPopup(key, message); | ||
}, | ||
() => { | ||
closePopup(key); | ||
} | ||
]; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.usePopup = void 0; | ||
var react_1 = require("react"); | ||
var PopupContext_1 = require("../PopupContext"); | ||
function usePopup(key, popupRenderer) { | ||
var _a = react_1.useContext(PopupContext_1.PopupContext), registerPopup = _a.registerPopup, unRegisterPopup = _a.unRegisterPopup, displayPopup = _a.displayPopup, closePopup = _a.closePopup; | ||
react_1.useEffect(function () { | ||
registerPopup(key, popupRenderer); | ||
return function () { | ||
unRegisterPopup(key); | ||
}; | ||
}, []); | ||
return [ | ||
function (message) { | ||
displayPopup(key, message); | ||
}, | ||
function () { | ||
closePopup(key); | ||
}, | ||
]; | ||
} | ||
exports.usePopup = usePopup; |
@@ -1,11 +0,18 @@ | ||
import React from "../web_modules/react.js"; | ||
import {SnackBar} from "../components/index.js"; | ||
import {usePopup as usePopup2} from "./usePopup.js"; | ||
const DEFAULT_KEY = "rhp-snackbar"; | ||
export function useSnackBar({key, variant, timeout} = {}) { | ||
return usePopup2(key || DEFAULT_KEY, ({message, handleClose}) => /* @__PURE__ */ React.createElement(SnackBar, { | ||
variant, | ||
timeout, | ||
handleClose | ||
}, message)); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.useSnackBar = void 0; | ||
var react_1 = __importDefault(require("react")); | ||
var components_1 = require("../components"); | ||
var usePopup_1 = require("./usePopup"); | ||
var DEFAULT_KEY = 'rhp-snackbar'; | ||
function useSnackBar(_a) { | ||
var _b = _a === void 0 ? {} : _a, key = _b.key, variant = _b.variant, timeout = _b.timeout; | ||
return usePopup_1.usePopup(key || DEFAULT_KEY, function (_a) { | ||
var message = _a.message, handleClose = _a.handleClose; | ||
return (react_1.default.createElement(components_1.SnackBar, { variant: variant, timeout: timeout, handleClose: handleClose }, message)); | ||
}); | ||
} | ||
exports.useSnackBar = useSnackBar; |
@@ -1,2 +0,7 @@ | ||
export {PopupProvider} from "./PopupProvider.js"; | ||
export {usePopup} from "./hooks/usePopup.js"; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.usePopup = exports.PopupProvider = void 0; | ||
var PopupProvider_1 = require("./PopupProvider"); | ||
Object.defineProperty(exports, "PopupProvider", { enumerable: true, get: function () { return PopupProvider_1.PopupProvider; } }); | ||
var usePopup_1 = require("./hooks/usePopup"); | ||
Object.defineProperty(exports, "usePopup", { enumerable: true, get: function () { return usePopup_1.usePopup; } }); |
@@ -1,16 +0,19 @@ | ||
import {createContext} from "./web_modules/react.js"; | ||
import {consts as consts2} from "./utils/consts.js"; | ||
export const PopupContext = createContext({ | ||
registerPopup: () => { | ||
throw new Error(consts2.CONTEXT_ERROR_MESSAGE); | ||
}, | ||
unRegisterPopup: () => { | ||
throw new Error(consts2.CONTEXT_ERROR_MESSAGE); | ||
}, | ||
displayPopup: () => { | ||
throw new Error(consts2.CONTEXT_ERROR_MESSAGE); | ||
}, | ||
closePopup: () => { | ||
throw new Error(consts2.CONTEXT_ERROR_MESSAGE); | ||
} | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PopupContext = void 0; | ||
var react_1 = require("react"); | ||
var consts_1 = require("./utils/consts"); | ||
exports.PopupContext = react_1.createContext({ | ||
registerPopup: function () { | ||
throw new Error(consts_1.consts.CONTEXT_ERROR_MESSAGE); | ||
}, | ||
unRegisterPopup: function () { | ||
throw new Error(consts_1.consts.CONTEXT_ERROR_MESSAGE); | ||
}, | ||
displayPopup: function () { | ||
throw new Error(consts_1.consts.CONTEXT_ERROR_MESSAGE); | ||
}, | ||
closePopup: function () { | ||
throw new Error(consts_1.consts.CONTEXT_ERROR_MESSAGE); | ||
}, | ||
}); |
@@ -1,38 +0,59 @@ | ||
import React, {useState} from "./web_modules/react.js"; | ||
import {PopupContext as PopupContext2} from "./PopupContext.js"; | ||
import { | ||
addPopup, | ||
removePopup, | ||
setPopupClosed, | ||
setPopupMessage, | ||
setPopupOpen | ||
} from "./utils/reducers.js"; | ||
export const PopupProvider = ({children}) => { | ||
const [popups, setPopups] = useState({}); | ||
const registerPopup = (key, popupRenderer) => { | ||
setPopups((previous) => addPopup(previous, key, popupRenderer)); | ||
}; | ||
const unRegisterPopup = (key) => { | ||
setPopups((previous) => removePopup(previous, key)); | ||
}; | ||
const displayPopup = (key, message) => { | ||
setPopups((previous) => setPopupOpen(previous, key)); | ||
setPopups((previous) => setPopupMessage(previous, key, message)); | ||
}; | ||
const closePopup = (key) => { | ||
setPopups((previous) => setPopupClosed(previous, key)); | ||
}; | ||
return /* @__PURE__ */ React.createElement(PopupContext2.Provider, { | ||
value: { | ||
registerPopup, | ||
unRegisterPopup, | ||
displayPopup, | ||
closePopup | ||
} | ||
}, children, Object.entries(popups).map(([key, popup]) => { | ||
return popup.open && React.cloneElement(popup.renderer?.({ | ||
message: popup.message, | ||
handleClose: () => closePopup(key) | ||
}), {key}); | ||
})); | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PopupProvider = void 0; | ||
var react_1 = __importStar(require("react")); | ||
var PopupContext_1 = require("./PopupContext"); | ||
var reducers_1 = require("./utils/reducers"); | ||
var PopupProvider = function (_a) { | ||
var children = _a.children; | ||
var _b = react_1.useState({}), popups = _b[0], setPopups = _b[1]; | ||
var registerPopup = function (key, popupRenderer) { | ||
setPopups(function (previous) { return reducers_1.addPopup(previous, key, popupRenderer); }); | ||
}; | ||
var unRegisterPopup = function (key) { | ||
setPopups(function (previous) { return reducers_1.removePopup(previous, key); }); | ||
}; | ||
var displayPopup = function (key, message) { | ||
setPopups(function (previous) { return reducers_1.setPopupOpen(previous, key); }); | ||
setPopups(function (previous) { return reducers_1.setPopupMessage(previous, key, message); }); | ||
}; | ||
var closePopup = function (key) { | ||
setPopups(function (previous) { return reducers_1.setPopupClosed(previous, key); }); | ||
}; | ||
return (react_1.default.createElement(PopupContext_1.PopupContext.Provider, { value: { | ||
registerPopup: registerPopup, | ||
unRegisterPopup: unRegisterPopup, | ||
displayPopup: displayPopup, | ||
closePopup: closePopup, | ||
} }, | ||
children, | ||
Object.entries(popups).map(function (_a) { | ||
var _b; | ||
var key = _a[0], popup = _a[1]; | ||
return (popup.open && | ||
react_1.default.cloneElement((_b = popup.renderer) === null || _b === void 0 ? void 0 : _b.call(popup, { | ||
message: popup.message, | ||
handleClose: function () { return closePopup(key); }, | ||
}), { key: key })); | ||
}))); | ||
}; | ||
exports.PopupProvider = PopupProvider; |
@@ -1,4 +0,7 @@ | ||
export const consts = { | ||
CONTEXT_ERROR_MESSAGE: "An error has occured with the react-hook-popup library", | ||
UNFOUND_POPUP: (key) => `Attempted to act on a non-existing popup with key: ${key}` | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.consts = void 0; | ||
exports.consts = { | ||
CONTEXT_ERROR_MESSAGE: 'An error has occured with the react-hook-popup library', | ||
UNFOUND_POPUP: function (key) { return "Attempted to act on a non-existing popup with key: " + key; }, | ||
}; |
@@ -1,48 +0,67 @@ | ||
import {enforceExistingPopup} from "./utils.js"; | ||
export function addPopup(popups, key, renderer) { | ||
if (popups[key]) { | ||
return popups; | ||
} | ||
return { | ||
...popups, | ||
[key]: { | ||
renderer, | ||
open: false | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setPopupMessage = exports.setPopupClosed = exports.setPopupOpen = exports.removePopup = exports.addPopup = void 0; | ||
var utils_1 = require("./utils"); | ||
function addPopup(popups, key, renderer) { | ||
var _a; | ||
if (popups[key]) { | ||
return popups; | ||
} | ||
}; | ||
return __assign(__assign({}, popups), (_a = {}, _a[key] = { | ||
renderer: renderer, | ||
open: false, | ||
}, _a)); | ||
} | ||
export function removePopup(popups, key) { | ||
if (!popups[key]) { | ||
return popups; | ||
} | ||
const {[key]: _, ...updatedPopups} = popups; | ||
return updatedPopups; | ||
exports.addPopup = addPopup; | ||
function removePopup(popups, key) { | ||
if (!popups[key]) { | ||
return popups; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
var _a = popups, _b = key, _ = _a[_b], updatedPopups = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]); | ||
return updatedPopups; | ||
} | ||
exports.removePopup = removePopup; | ||
function togglePopupOpenState(popups, key, value) { | ||
enforceExistingPopup(popups, key); | ||
return { | ||
...popups, | ||
[key]: { | ||
...popups[key], | ||
open: value | ||
} | ||
}; | ||
var _a; | ||
utils_1.enforceExistingPopup(popups, key); | ||
return __assign(__assign({}, popups), (_a = {}, _a[key] = __assign(__assign({}, popups[key]), { open: value }), _a)); | ||
} | ||
export function setPopupOpen(popups, key) { | ||
enforceExistingPopup(popups, key); | ||
return togglePopupOpenState(popups, key, true); | ||
function setPopupOpen(popups, key) { | ||
utils_1.enforceExistingPopup(popups, key); | ||
return togglePopupOpenState(popups, key, true); | ||
} | ||
export function setPopupClosed(popups, key) { | ||
enforceExistingPopup(popups, key); | ||
return togglePopupOpenState(popups, key, false); | ||
exports.setPopupOpen = setPopupOpen; | ||
function setPopupClosed(popups, key) { | ||
utils_1.enforceExistingPopup(popups, key); | ||
return togglePopupOpenState(popups, key, false); | ||
} | ||
export function setPopupMessage(popups, key, message) { | ||
enforceExistingPopup(popups, key); | ||
return { | ||
...popups, | ||
[key]: { | ||
...popups[key], | ||
message | ||
} | ||
}; | ||
exports.setPopupClosed = setPopupClosed; | ||
function setPopupMessage(popups, key, message) { | ||
var _a; | ||
utils_1.enforceExistingPopup(popups, key); | ||
return __assign(__assign({}, popups), (_a = {}, _a[key] = __assign(__assign({}, popups[key]), { message: message }), _a)); | ||
} | ||
exports.setPopupMessage = setPopupMessage; |
@@ -1,6 +0,10 @@ | ||
import {consts as consts2} from "./consts.js"; | ||
export function enforceExistingPopup(popups, key) { | ||
if (!popups[key]) { | ||
throw new Error(consts2.UNFOUND_POPUP(key)); | ||
} | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.enforceExistingPopup = void 0; | ||
var consts_1 = require("./consts"); | ||
function enforceExistingPopup(popups, key) { | ||
if (!popups[key]) { | ||
throw new Error(consts_1.consts.UNFOUND_POPUP(key)); | ||
} | ||
} | ||
exports.enforceExistingPopup = enforceExistingPopup; |
{ | ||
"name": "react-hook-popup", | ||
"version": "0.0.5-alpha.2", | ||
"version": "0.0.5-alpha.3", | ||
"description": "Easily manage popups like alerts and modals in React with a single hook", | ||
"homepage": "https://github.com/aidanjw1/react-hook-popup#readme", | ||
"repository": "github:aidanjw1/react-hook-popup", | ||
"keywords": [ | ||
"react", | ||
"react hooks", | ||
"hooks", | ||
"typescript", | ||
"popups", | ||
"alerts" | ||
], | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "snowpack build && npm run build-cleanup", | ||
"build": "npm run build:ts && npm run build:sass", | ||
"build:ts": "tsc", | ||
"build:sass": "sass src/:dist/", | ||
"build-cleanup": "rm -r dist/web_modules && rm -r dist/sass && rm -r dist/__snowpack__", | ||
@@ -20,3 +30,2 @@ "typecheck": "tsc --noEmit", | ||
"devDependencies": { | ||
"@snowpack/plugin-sass": "^1.1.2", | ||
"@types/enzyme": "^3.10.8", | ||
@@ -36,3 +45,3 @@ "@types/enzyme-adapter-react-16": "^1.0.6", | ||
"react-dom": "^16.14.0", | ||
"snowpack": "^2.18.2", | ||
"sass": "^1.30.0", | ||
"ts-jest": "^26.4.4", | ||
@@ -42,4 +51,4 @@ "typescript": "^4.1.2" | ||
"peerDependencies": { | ||
"react": "^16.14.0" | ||
"react": "*" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
18338
17
29
357