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

uxcore-cascade-select

v0.9.4

Published

Cascade select field

Downloads

45

Readme

uxcore-cascade-select

React cascade select

NPM version build status Test Coverage Dependency Status devDependency Status NPM downloads

Sauce Test Status

Development

git clone https://github.com/uxcore/uxcore-cascade-select
cd uxcore-cascade-select
npm install
npm run server

if you'd like to save your install time,you can use uxcore-tools globally.

npm install uxcore-tools -g
git clone https://github.com/uxcore/uxcore-cascade-select
cd uxcore-cascade-select
npm install
npm run dep
npm run start

Test Case

npm run test

Coverage

npm run coverage

Demo

http://uxcore.github.io/components/cascade-select

Contribute

Yes please! See the CONTRIBUTING for details.

API

import CascadeSelect from 'uxcore-cascade-select'
import { render } from 'react-dom'

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

Props

| Name | Type | Required | Default | Comments | |---|---|---|---|---| | prefixCls | string | false | 'kuma-cascader' | 默认的类名前缀 | | className | string | false | '' | 自定义类名 | | options | array | false | [] | 选项数据源,格式可见下方Demo | | value | array | false | [] | 可由外部控制的值 | | defaultValue | array | false | [] | 初始默认值 | | dropdownClassName | string | false | '' | dropdown 容器的自定义样式 | placeholder | string | false | 'Please Select' or '请选择' | placeholder | | onChange | function | false | function(value, selectedOptions) | 选择完成后回调 | | disabled | boolean | false | false | 是否禁用 | | clearable | boolean | false | false | 是否支持清除 | | changeOnSelect | boolean | false | false | 是否将每次选择立刻显示在控件中 | | expandTrigger | string | false | 'click' | 次级菜单展开方式,支持 clickhover | | beforeRender | function | false | (value, selectedOptions) => selectedOptions.map(o => o && o.label).join(' / ') | 处理要显示的内容 | | cascadeSize | number | false | 3 | 级联的层级数 | | getPopupContainer | function():HTMLElement | false | / | 返回一个 html 元素用作 Popup 面板的容器,默认是插在body 中的一个 div | | locale | string | false | 'zh-cn' | 'en-us' | miniMode | boolean | false | true | 是否是简洁显示风格 | columnWidth | number | false | null | dropdown中每一列的宽度, 如为空,整体宽度等于input输入框的宽度 | displayMode | string | false | dropdown | select 或者 dropdown 或者 search(已废弃) | getSelectPlaceholder | func | false | function(idx){ return '请选择' } | select显示模式下的placeholder生成函数 | size | string | false | large | 尺寸,枚举值:large, middle, small | isMustSelectLeaf | bool | false | false | 是否必须选择到叶子节点 | onSelect | function | false | null | 异步加载层级,需要 return 一个数组,具体用法参考下方 demo | onlyStringValue | boolean | false | false | 选中数据之后的值,直接给字符串而不是级联结构 | searchOption | function | false | null | (已废弃) 开启关键词搜索的配置,当 dispalyMode 为 search 时启用,具体配置方式参考下方 | showSearch | boolean | false | false | 是否开启搜索模式 | onSearch | function | false | null | 开启关键词过滤模式,可以通过外部重新设置 options,onSearch 不能与 optionFilterProps 和 optionFilterCount 一起使用,onSearch 优先级更高 | optionFilterProps | string[] | false | ['label'] | showSearch=true 时,optionFilterProp 为 options[i] 中的属性名称,此时搜索会进行过滤 | optionFilterCount | number | false | 20 | 当使用过滤功能时 dropdown 里最多显示的条数 | cascaderHeight | number | false | null | 级联选择区域的高度 | useFullPathValue | boolean | false | false | 使用全路径值匹配模式,该模式允许父子级,不同子级的 ID 一致

Demos

props.options

const options = [{
  value: 'zhejiang',
  label: '浙江',
  children: [{
    value: 'hangzhou',
    label: '杭州',
    children: [{
      value: 'xihu',
      label: '西湖',
    }],
  }],
}, {
  value: 'jiangsu',
  label: '江苏',
  children: [{
    value: 'nanjing',
    label: '南京',
    children: [{
      value: 'zhonghuamen',
      label: '中华门',
    }],
  }],
}];

当不指定 dropdown 宽度时,还可以使用css来定制dropdown宽度

.kuma-cascader-submenu-empty,
.kuma-dropdown-menu-submenu {
  width: 400px; // 你想要的 dropdown 宽度
}

props.onSelect

<CascadeSelect
  /**
   * @param resolve 请求成功了调用resolve()
   * @param reject 请求失败则调用reject()
   * @param key key为父级的value
   * @param level level为父级所在的层数,如上面的options的['zhengjiang'], level为1
   */ 
  showSearch={true}
  onSelect={(resolve, reject, key, level) => {
    ajax({
      url: 'xxx/xx.json',
      data: {
        key
      },
      success(content) {
        resolve(content); // content必须为array
      },
      error() {
        reject();
      }
    })
  }}
/>

props.searchOption

{
  doSearch(keyword, afterSearch) { // 异步搜索函数
    // keyword 为搜索的关键词
    // afterSearch 为搜索完成之后需要将结果显示在页面中,afterSearch 接收的参数为 [{ label, value }, ...]
    Fetch('/search?keyword=' + keyword).then(result => afterSearch(result))
  }
}

props.optionFilterProp

<CascadeSelect
  options={this.state.options}
  showSearch={true}
  optionFilterProps={['label']}
  optionFilterCount={10}
/>

只用面板

只是用面板时 props.value 必须是受控模式

<CascadeSelect.CascadeSubmenu
  options={options}
  value={this.state.value}
  onChange={(value) => {
    this.setState({ value });
  }}
  renderCustomItem={(item) => {
    return <span style={{ color: 'red' }}>{item.label}</span>
  }}
/>

CascadeSelect.CascadeSubmenu.props

| Name | Type | Required | Default | Comments | | --- | --- | --- | --- | --- | | value | array | Yes | [] | 受控值 | options | array | Yes | [] | 候选集,格式参考上方 | onChange | function | Yes | null | value 改变的回调函数 | columnWidth | number | No | null | 每一列的宽度 | cascaderHeight | number | NO | null | 级联选择区域的高度 | renderCustomItem | function | No | null | 自定义渲染选项