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

@_nu/react-dialog

v1.2.6

Published

A fully accessible、flexible、unstyled React dialog component

Downloads

95

Readme

@_nu/react-dialog

npm package npm downloads github

一个兼顾无障碍范围,易用性,且没有 UI 依赖的 React 对话框组件.

@_nu/react-dialog 本身不会输出任何样式,所有 demo 样式均来自于@_nu/css-dialog

安装

$ npm i @_nu/react-dialog

二次封装

在你的项目组件库文件夹中创建一个新的 Dialog 组件.

components/
   └── Dialog/
       ├── index.d.ts   // 定义文件,为了更好的代码提示
       ├── index.js     // 主文件
       └── style.css    // 样式文件
import React from 'react';
import { NuDialog, NuMask, NuModal, NuClose } from '@_nu/react-dialog';
import '@_nu/css-dialog';
import '@_nu/css-dialog/lib/skins/middle.css';
import '@_nu/css-dialog/lib/skins/top.css';
import '@_nu/css-dialog/lib/skins/left.css';
import '@_nu/css-dialog/lib/skins/bottom.css';
import '@_nu/css-dialog/lib/skins/right.css';
import './style.css';

function Dialog({ children, onClose, ...otherProps }) {
  return (
    <NuModal onClose={onClose} {...otherProps}>
      <NuMask onClick={onClose} />
      <NuDialog>
        {children}
        <NuClose onClick={onClose} />
      </NuDialog>
    </NuModal>
  );
}

export default Dialog;

使用

import React, { useState } from "react";
import Dialog from "./components/Dialog";

function Demo() {
  const [open, setOpen] = useState(false);
  return (
    <div>
      <button type="button" onClick={() => setOpen(true)}>
        open
      </button>
      <Dialog open={open} onClose={() => setOpen(false)}>
        <h3>hello world!</h3>
        <p>Happy to see you again.</p>
      </Dialog>
    </div>
  );
}
export default App;

Dom

<dialog tabindex="0" role="dialog" class="nu_modal _middle" aria-describedby="alert-dialog-description" open>
  <button type="button" title="Mask" aria-label="Mask" class="nu_mask "></button>
  <section role="document" class="nu_dialog">
      {children}
      <button aria-label="Close" type="button" class="nu_dialog_close " title="Close" tabindex="0">×</button>
  </section>
</dialog>

子组件

| props | 功能 | API | | :------- | ----------------- | --------------------------------: | | Modal | 弹窗组件 | 点击查看 | | Portal | 已内置在 Modal 中 | 点击查看 | | Mask | 蒙层组件 | 点击查看 | | Dialog | 内容容器组件 | 点击查看 | | Close | 关闭按钮 | 点击查看 |

// @_nu/react-dialog
import NuModal from './Modal';
import NuMask from './Mask';
import NuDialog from './Dialog';
import NuClose from './Close';
import NuPortal from './Portal';

export default NuDialog;
export { NuMask, NuModal, NuClose, NuPortal };

Transition

.nu_dialog {
  transform: translate(0, -50px);
}
._top .nu_dialog {
  transform: translate(0, -50px);
}
._bottom .nu_dialog {
  transform: translate(0, 50px);
}
._right .nu_dialog {
  transform: translate(50px, 0);
}
._left .nu_dialog {
  transform: translate(-50px, 0);
}

/* 默认终点状态 */
.nu_modal[open] .nu_dialog{
    transform: translate(0, 0);
}

你只需要定义 .nu_dialog 的起点状态即可。

技术方案

@_nu/react-dialog 灵感来自以下几个优秀的开源框架: