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

@typedarray/arco-design-modal

v0.2.4

Published

基于 `@arco-design/web-react` [Modal](https://arco.design/react/components/modal) 的弹窗管理器,支持 [React Context](https://reactjs.org/docs/context.html)

Downloads

64

Readme

@typedarray/arco-design-modal

基于 @arco-design/web-react Modal 的弹窗管理器,支持 React Context

const modalRef = useRef<Modal>();

const flag = await modalRef.current?.confirm({
  title: '标题',
  content: '内容',
  flags: Modal.OK | Modal.CANCEL | Modal.YES | Modal.NO | Modal.CLOSE
});
if (flag & Modal.OK) {
  console.log('你点击了‘确定’');
}

<Modal ref={modalRef} />;

Install 安装

Available as an npm package @typedarray/arco-design-modal

// with npm
npm install @typedarray/arco-design-modal

// with yarn
yarn add @typedarray/arco-design-modal

Usage 使用方法

import Modal from '@typedarray/arco-design-modal';

const modalRef = useRef<Modal>();

const flag = await modalRef.current?.confirm({
  title: '标题',
  content: '内容'
});
if (flag & Modal.OK) {
  console.log('你点击了‘确定’');
}

<Modal ref={modalRef} />;

Features 功能

  1. 支持 Context

通过方法去使用对话框,像是 Modal.confirm Modal.warning,因为是通过 ReactDOM.render 直接渲染,所以不在上下文中,因此拿不到 Context
如果希望获取上下文 Context,那么可以将 <Modal ref={modalRef}/> 放到上下文中,通过 useRef 调用。

  1. 自定义最多 5 个按钮(确定 / 取消 / / / 关闭
modalRef.current?.confirm({
  title: '标题',
  content: '内容',
  flags: Modal.OK | Modal.CANCEL | Modal.YES | Modal.NO | Modal.CLOSE, // 需要显示的按钮
});
  1. 自定义按钮排序
modalRef.current?.confirm({
  title: '标题',
  content: '内容',
  flags: [Modal.YES, Modal.NO, Modal.OK, Modal.CANCEL, Modal.CLOSE], // 按钮按数组排序
});
  1. 自动随父节点销毁,无需手动 Modal.destroyAll

  2. 其他用法,支持 show confirm info success warning error

  3. innerRef 可以获取到 children 数据状态

const InnerComponent = () => {
  const { innerRef } = useContext(ModalContext);
  const [state, setState] = useState(0);
  useEffect(() => {
    innerRef.current = state;
  }, [state]);
  return (
    <>
      {state}
      <button onClick={() => setState(state - 1)}>-</button>
      <button onClick={() => setState(state + 1)}>+</button>
    </>
  );
};

modalRef.current?.show(
  {
    title: '标题',
    onClose: async (flag, innerRef) => {
      if (flag & Modal.OK) {
        console.log('OK', innerRef.current);
      }
    },
  },
  <InnerComponent />
);

Props 属性参数

  • icon 标题前的图标
  • title 标题
  • content / children 弹窗内容
  • flags 要展示的按钮 包括 Modal.OK Modal.CANCEL Modal.YES Modal.NO Modal.CLOSE 使用位或运算符 | 连接,或者数组
  • children 属性可以单独作为第二个参数
  • 其他属性参考 @arco-design/web-react Modal 组件