npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mobrix-engine-plugin-modal

v1.0.1

Published

Manage your web app modal with mobrix-engine system

Downloads

3

Readme

MoBrix-engine-plugin-modal

NPM npm npm bundle size Maintenance


Manage your web app modal with mobrix-engine system


Summary


Getting started

Installation

If you want to use this plugin with MoBrix-engine, install it:

npm i mobrix-engine-plugin-modal

Usage

Check mobrix-engine guide to init the system

Include this plugin inside your mobrix-engine config, optionally with modal field set, to customize onModalOpen and onModalClose callbacks:

const { modalPlugin } = require("mobrix-engine-plugin-modal");

const config = {
  appName: "custom-app",
  plugins: [modalPlugin],
  modal: {
    onModalClose: [() => alert("modal closed")],
    onModalOpen: [() => alert("modal opened")],
  },
};

module.exports = { config };

Then you can drive your modal component (in this example it is used MoBrix-ui modal), with selectors:

import { isModalVisible, getModalType } from "mobrix-engine-plugin-modal";
import { Modal } from "mobrix-ui";

const forms = {
  formOne: () => <div>Form one</div>,
  formTwo: () => <div>Form two</div>,
};

export const CustomComponent = () => {
  const isVisible = useSelectors(isModalVisible);
  const type = useSelectors(getModalType);
  const Content = forms[type] || () => <div/>;

  return (
    <Modal hide={!isVisible}>
      <Content />
    </Modal>
  );
};

API

Config

This plugin adds adds a custom field inside mobrix-engine config, modal. Inside this field, there are the plugin settings:

| Setting | Description | | -------------- | ----------------------------------------------------------------- | | onModalClose | array of functions, that are called everytime the modal is closed | | onModalOpen | array of functions, that are called everytime the modal is opened |

Actions

| Action creator | Arguments | Effect | | ------------------- | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | | openModal | - type: modal form type to open - context : (optional) custom data associated with the given modal form | Open the modal, and optionally set the actual context | | closeModal | / | Close the modal, and reset the context | | setModalContext | - context : custom modal context to set | (similar to openModa and closeModal, but doesn't affect the visibility or the form type) | | setModalForm | - type : modal form type to set | Set modal form type (similar to openModa and closeModal, but doesn't affect the context or the visibiity) | | setModalVisiblity | - visibility : modal visibility to set | Set modal visibility (similar to openModa and closeModal, but doesn't affect the context or the form type) |

Import them from this lib:

import {
  closeModal,
  openModal,
  setModalContext,
  setModalForm,
  setModalVisiblity,
} from "mobrix-engine-plugin-modal";

Then dispatch them from any part of your app:

import { isModalVisible, getModalType } from "mobrix-engine-plugin-modal";
import { useDispatch, useSelector } from "react-redux";

import { Button } from "mobrix-ui";

export const ModalButton = () => {
  const dispatch = useDispatch();

  return (
    <Button
      onClick={() => {
        dispatch(openModal("formOne"));
      }}
    >
      Open form one
    </Button>
  );
};

Selectors

| Selectors | Returns | | ----------------- | -------------------------------------------------------------------------------- | | getModalView | Modal state, or default state if not enabled | | getModalType | Modal type, that can be used as a key to find the right component to show | | getModalContext | Modal context, a custom object associated to the actual modal type (can be null) | | isModalVisible | Modal visibility, to determine when show or hide the Modal component |

Import them from this lib:

import {
  getModalContext,
  getModalType,
  getModalView,
  isModalVisible,
} from "mobrix-engine-plugin-modal";

Then use them from any part of your app:

import { isModalVisible, getModalType } from "mobrix-engine-plugin-modal";
import { useSelector } from "react-redux";

import { Button } from "mobrix-ui";

export const ModalDebugComponent = () => {
  const type = useSelector(getModalType);
  const isVisible = useSelector(isModalVisible);

  return (
    <div>
      <p>{`Actual form type is set to ${type}`}</p>
      <p>{{`Modal is ${isVisible?"opened":"closed"}`}}</p>
  </div>
  );
};

Integration with other plugins

  • This plugin expose some fields to work with any other plugin. If you want to interact with it, using your custom plugin, add an interaction with mobrix-engine-modal plugin into you custom plugin. There you can add your callbacks to modal fields (check config section for details). For example, to add a custom function to be called when modal is opened, inside the format function of your custom plugin:
//Just a skeleton of a custom plugin that interacts with modal plugin
const customPlugin = () => ({
  // Custom plugin stuffs

  interactions: [
    {
      plugin: "mobrix-engine-modal",
      effect: (modalConfig) => {
        //Add the custom callback
        modalConfig.onModalOpened.push(() => {
          alert("Modal opened");
        });
      },
    },
  ],
});
  • Additionally, if you use mobrix-engine-plugin-url-checker too, you can open the modal directly from URL, with query parameters, by passing the modal parameter with the form type you want to open. Try it with MoBrix-engine playground (look the query parameters) - https://cianciarusocataldo.github.io/mobrix-engine?modal=TestModal


Included libraries


Authors


License

This project is licensed under the MIT License - see the LICENSE file for details