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

@yhwang911/yh-ui-react

v1.0.8

Published

一个React+TS组件库! / a React+TS based highly popular management component ui lib!

Downloads

2

Readme

@安装使用

# 没有安装nrm源管理工具时...
npm i -g nrm

# NPM全局切换到官方源
nrm use npm

# 安装UI/React
npm i @yhwang911/yh-ui-react

使用弹窗

import React, { useState } from "react";

// 引入弹窗
import { YhPopup } from "@yhwang911/yh-ui-react";

export default function PopupDemo() {
  // 用一个state控制要不要显示弹窗
  const [showPopup, setShowPopup] = useState(false);

  return (
    <div>
      <h3>PopupDemo</h3>
      <button onClick={() => setShowPopup(true)}>显示弹窗</button>

      {/* 需要时显示弹窗显示弹窗 */}
      {showPopup && (
        // closer={setShowPopup} 告诉组件哪个state在控制弹窗的显隐 它好在必要时帮你关闭弹窗
        // title="我的弹窗" 弹窗标题
        // onConfirm={() => console.log("已确定")} 点击确定时的回调
        // <p>This is a modal content</p> 自定义弹窗内容
        <YhPopup
          closer={setShowPopup}
          title="我的弹窗"
          onConfirm={() => console.log("已确定")}
        >
          <p>This is a modal content</p>
        </YhPopup>
      )}
    </div>
  );
}

执行效果

image.png

使用表格

import React from "react";

// 引入超级表格
import { YhTableX } from "@yhwang911/yh-ui-react";

/* 造一堆测试数据 */
import { getStudents } from "../common/mockdata";
const students = getStudents(20, true);

/* 格式化数据字段 */
const formatters = {
  // 用一个a标签去显示学生姓名
  name: (key: string, item: any) => <a href={`/${item.id}`}>{item[key]}</a>,

  // 用a标签嵌套img显示学生头像
  avatar: (key: string, item: any) => (
    <a href={`/${item.id}`}>
      <img style={{ width: 40 }} src={`${item[key]}`} alt="" />
    </a>
  ),
};

/* 数据多选发生变化时回调 */
const onSelectedItemsChanged = (items: Set<Record<string, any>>) => {
  console.log("onSelectedItemsChanged", items);
};

/* 组合组件:自带筛选器和分页器的超级表格 */
export default function TableXDemo() {
  return (
    <div>
      TableXDemo
      {/* 
       data={students} 表格数据
       width={800}  设置表格宽度
       formatters={formatters} 字段的具体显示方式
       sortables={["name","age","score"]} 哪些字段支持排序
       pageSize={10} 一页显示多少条数据
       onSelectedItemsChanged={onSelectedItemsChanged} 多选发生变化时回调
      */}
      <YhTableX
        data={students}
        // width={800}
        formatters={formatters}
        sortables={["name", "age", "score"]}
        pageSize={10}
        onSelectedItemsChanged={onSelectedItemsChanged}
      ></YhTableX>
    </div>
  );
}

执行效果 image.png

使用导入导出为xlsx

import { useState, useRef } from 'react'
import { YhImport, YhExport } from '@yhwang911/yh-ui-react'
export default function App () {
  const ExportRef: any = useRef(null)
  // 数据
  const [row, setRow] = useState([
    { id: 1, name: '养老保险', personage: 40, firm: 35, img: '/public/vite.svg', linkname: '百度', link: 'https://www.baidu.com/', total: 1200 },
    { id: 2, name: '医疗保险', personage: 100, firm: 30, img: '/public/vite.svg', linkname: '百度', link: 'https://www.baidu.com/', total: 1200 },
    { id: 3, name: '失业保险', personage: 25, firm: 35, img: '/public/vite.svg', linkname: '百度', link: 'https://www.baidu.com/', total: 1200 }
  ])
  // 标题
  const columns = [
    { key: 'id', label: 'ID', type: 'sort' },
    { key: 'name', label: '缴纳项目', type: 'normal' },
    { key: 'personage', label: '个人', type: 'normal' },
    { key: 'firm', label: '企业', type: 'sort' },
    { key: 'img', label: '照片', type: 'image' },
    { key: 'total', label: '合计', type: 'normal' }
  ]
  // 导出
  const exportXlsx = () => {
    if (ExportRef.current) {
      ExportRef.current.exportXlsx()
    }
  }
  // 导入
  const importXlsx = (data: Array<any>) => {
    console.log(data, 'data');
    setRow([...row, ...data])
  }
  return (
    <>
      {/* 导出 */}
      <YhExport dataSource={row} columns={columns} ref={ExportRef}>
        <button onClick={exportXlsx}>导出</button>
      </YhExport>
      {/* 导入 */}
      <YhImport columns={columns} importXlsx={importXlsx} inputShow={false}></YhImport>

    </>
  )
}