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

modaler

v1.1.3

Published

A simple pluggable modal container

Downloads

5

Readme

Modaler

一个简单可插拔的 Modal 容器,页面中用到的 Modal 在没有被调用时,不会渲染在组件中。

Getting Started

Installation

npm i modaler --save

注意:插件中用了 React Hooks, 请使用 React v16.8.0 或以上的版本

Usage

Modaler 提供了一个 Provider 组件,包裹在你的程序外边,可以在用到第三方 Modal 组件事动态插入到 document.body 中。

注意:控制 Modal 显示隐藏的时,请使用 props.visible

import React from 'react'
import ReactDOM from 'react-dom'
import ModalProvider from 'modaler'
import Container from './Container'
import modals from './modals'

const App = () => (
  <ModalProvider modalMap={modals} hideDelay={300} fallback={null}>
    <Container />
  </ModalProvider>
)

ReactDOM.render(<App />, document.getElementById('root'))

modals 是一个组件列表的映射,类似下边这样:

// modals.js
import ConfirmModal from './ConfirmModal'

export default {
  CONFIRM_MODAL: ConfirmModal,
}

Modaler 同时提供了一个 useModal 的 Hook,返回一个对象,可以通过 showhide 方法控制 Modal。

// Container.jsx
import React from 'react'
import { useModal } from 'modaler'

const Container = () => {
  const modal = useModal()

  const show = () => {
    modal.show('CONFIRM_MODAL')
  }

  return <button onClick={show}>show Modal</button>
}

export default Container

Api

ModalProviderProps

  • modalMap: Modal 组件以 key value 形式的映射
  • hideDelay: 延时关闭
  • fallback: React.Suspense 中的 fallback

useModal(): object

show(key: string, props: object)

  • key: 想要渲染的 Modal 组件的 key,必填
  • props: 传递给 Modal 组件的 props,默认带有 visible 属性,控制 Modal 组件显示隐藏时请使用该属性

hide(symbol: string, wait: number)

  • symbol: 指定关闭 key 为 symbol 的 Modal 组件
  • wait: 毫秒数,一定时间后销毁 Modal 组件,一般用于有关闭动画的 Modal 组件,默认为 hideDelay

hide(wait: number)

关闭全部 Modal 组件

  • wait: 毫秒数,一定时间后销毁 Modal 组件,一般用于有关闭动画的 Modal 组件,默认为 hideDelay

Demo

git clone [email protected]:Martin0809/modaler.git && cd modaler

npm i
npm start