UNPKG

@mongez/react-atom

Version:

A simple state management tool for React Js.

41 lines (40 loc) 1.12 kB
import {atom}from'./react-atom.js';/** * Create a portal atom * This atom is used to create a portal (a modal, a tooltip, a dropdown, etc.) */ function portalAtom(name, opened = false) { return atom({ key: `${name}-portal`, default: { opened: opened, data: {}, }, actions: { open(data) { this.merge({ opened: true, data, }); }, close() { this.change("opened", false); }, toggle(data) { const opened = this.get("opened"); if (opened) { return this.change("opened", false); } this.merge({ opened: true, data, }); }, useOpened() { return this.use("opened"); }, useData() { return this.use("data"); }, }, }); }export{portalAtom};//# sourceMappingURL=portal-atom.js.map