@mongez/react-atom
Version:
A simple state management tool for React Js.
44 lines (42 loc) • 802 B
JavaScript
import { atom } from "./react-atom.mjs";
//#region ../@mongez/react-atom/src/portal-atom.ts
/**
* 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,
data: {}
},
actions: {
open(data) {
this.merge({
opened: true,
data
});
},
close() {
this.change("opened", false);
},
toggle(data) {
if (this.get("opened")) return this.change("opened", false);
this.merge({
opened: true,
data
});
},
useOpened() {
return this.use("opened");
},
useData() {
return this.use("data");
}
}
});
}
//#endregion
export { portalAtom };
//# sourceMappingURL=portal-atom.mjs.map