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

@uiw/react-dropdown

v4.22.3

Published

Dropdown component

Downloads

691

Readme

Dropdown 下拉菜单

Buy me a coffee Open in unpkg NPM Downloads npm version

向下弹出的列表。

import { Dropdown } from 'uiw';
// or
import Dropdown from '@uiw/react-dropdown';

基本用法

import React from 'react';
import { Dropdown, Menu, ButtonGroup, Button, Divider, Icon } from 'uiw';

const menu = (
  <div>
    <Menu bordered style={{ minWidth: 120 }}>
      <Menu.Item icon="reload" text="重新加载" />
      <Menu.Item icon="heart-on" text="另存为" active />
      <Menu.Item icon="appstore" text="应用商城" />
      <Menu.Item icon="bar-chart" text="月统计报表" />
      <Menu.Item icon="setting" text="偏好设置" />
    </Menu>
  </div>
);

class Demo extends React.Component {
  render() {
    return (
      <div>
        <Dropdown menu={menu}>
          <a href='#' onClick={e => e.preventDefault()}>
            鼠标经过出现菜单 <Icon type="down" />
          </a>
        </Dropdown>
        <Dropdown trigger="click" menu={menu}>
          <a href='#' onClick={e => e.preventDefault()}>
            点击我出现下拉菜单 <Icon type="down" />
          </a>
        </Dropdown>
      </div>
    )
  }
}

export default Demo;

被禁用

import React from 'react';
import { Dropdown, Menu, ButtonGroup, Button } from 'uiw';

const menu = (
  <div>
    <Menu bordered style={{ maxWidth: 200 }}>
      <Menu.Item icon="reload" text="重新加载" />
      <Menu.Divider />
      <Menu.Item icon="heart-on" text="另存为" active />
      <Menu.Item icon="appstore" text="应用商城" />
      <Menu.Item icon="bar-chart" text="月统计报表导出" />
      <Menu.Item icon="setting" text="偏好设置" />
    </Menu>
  </div>
);

export default function Demo() {
  return(
    <div>
      <ButtonGroup style={{ marginRight: 5, display: 'inline-block' }}>
        <Button disabled icon="copy">点击右边</Button>
        <Dropdown disabled trigger="click" placement="bottomRight" menu={menu}>
          <Button icon="more" />
        </Dropdown>
      </ButtonGroup>
      <Dropdown disabled menu={menu}>
        <Button basic type="link"> (超连接样式)link </Button>
      </Dropdown>
      <Dropdown disabled menu={menu}>
        <Button type="primary">主要按钮</Button>
      </Dropdown>
      <Dropdown disabled menu={menu}>
        <Button type="success">成功按钮</Button>
      </Dropdown>
      <Dropdown disabled menu={menu}>
        <Button type="warning">警告按钮</Button>
      </Dropdown>
      <Dropdown disabled menu={menu}>
        <Button type="danger">错误按钮</Button>
      </Dropdown>
      <Dropdown disabled menu={menu}>
        <Button type="light">亮按钮</Button>
      </Dropdown>
      <Dropdown disabled menu={menu}>
        <Button type="dark">暗按钮</Button>
      </Dropdown>
    </div>
  );
}

弹出位置

import React from 'react';
import { Dropdown, Menu, Divider, ButtonGroup, Button } from 'uiw';

const menu = (
  <div>
    <Menu bordered style={{ maxWidth: 200 }}>
      <Menu.Item icon="reload" text="重新加载" />
      <Menu.Divider />
      <Menu.Item icon="heart-on" text="另存为" active />
      <Menu.Item icon="appstore" text="应用商城" />
      <Menu.Item icon="bar-chart" text="月统计报表导出" />
      <Menu.Item icon="setting" text="偏好设置" />
    </Menu>
  </div>
);

export default function Demo() {
  return(
    <div>
      <ButtonGroup style={{ marginRight: 5, display: 'inline-block' }}>
        <Button icon="copy">top</Button>
        <Dropdown trigger="click" placement="top" menu={menu}>
          <Button icon="more" />
        </Dropdown>
      </ButtonGroup>
      <Dropdown menu={menu} trigger="click" placement="topLeft">
        <Button type="primary">topLeft</Button>
      </Dropdown>
      <Dropdown menu={menu} trigger="click" placement="topRight">
        <Button type="success">topRight</Button>
      </Dropdown>
      <Divider />
      <Dropdown menu={menu} trigger="click" placement="bottomRight">
        <Button type="light">bottomRight</Button>
      </Dropdown>
      <Dropdown menu={menu} trigger="click" placement="bottom">
        <Button type="warning">bottom</Button>
      </Dropdown>
      <Dropdown menu={menu} trigger="click" placement="bottomLeft">
        <Button type="danger">bottomLeft</Button>
      </Dropdown>
      <Dropdown menu={menu} trigger="click" placement="right">
        <Button type="dark">right</Button>
      </Dropdown>
    </div>
  );
}

选择器

import React from 'react';
import { Dropdown, Menu, Button, Icon } from 'uiw';

function Select(props) {
  const { option, onChange } = props;
  const [open, setOpen] = React.useState(false);
  const [value, setValue] = React.useState(props.value);
  const label = option.find(item => value === item.value);

  React.useEffect(() => {
    if (props.value !== value) {
      setValue(props.value);
    }
  }, [props.value]);

  return (
    <Dropdown
      trigger="click"
      onVisibleChange={(isOpen) => setOpen(isOpen)}
      isOpen={open}
      menu={
        <div>
          <Menu bordered style={{ minWidth: 120 }}>
            {option.map((item, idx) => {
              const active = value === item.value;
              return (
                <Menu.Item
                  key={idx}
                  active={active}
                  text={item.label}
                  onClick={(e) => {
                    setValue(item.value)
                    setOpen(false)
                    onChange && onChange(item.value, e)
                  }}
                />
              );
            })}
          </Menu>
        </div>
      }
    >
      <Button type="link">{label.label}<Icon type={open ? 'up' : 'down'} /></Button>
    </Dropdown>
  )
}

const option = [
  { label: '往返', value: 1 },
  { label: '单程', value: 2 },
  { label: '联程', value: 3 },
  { label: 'Nomad', value: 4 },
];

const option2 = [
  { label: '经济舱', value: 1 },
  { label: '豪华经济舱', value: 2 },
  { label: '商务舱', value: 3 },
  { label: '头等舱', value: 4 },
];


export default function Demo() {
  return(
    <div>
      <Select option={option} value={1} onChange={(item) => { console.log('item', item); }} />
      <Select option={option2} value={2} onChange={(item) => { console.log('item', item); }} />
    </div>
  );
}

Props

| 参数 | 说明 | 类型 | 默认值 | | -------- | -------- | -------- | -------- | | menu | 菜单 | <Menu> | - | | disabled | 菜单是否禁用 | Boolean | - | | trigger<OverlayTrigger> | 悬停/点击弹出窗口 | Enum{hover, click, focus} | hover | | placement<OverlayTrigger> | 指定弹出框位置,支持 12 个访问展示菜单。 | Enum{} | bottomLeft |

更多属性文档请参考 OverlayTrigger