0.9.4 • Published 2 years ago

uxcore-cascade-select v0.9.4

Weekly downloads
19
License
MIT
Repository
github
Last release
2 years ago

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

NameTypeRequiredDefaultComments
prefixClsstringfalse'kuma-cascader'默认的类名前缀
classNamestringfalse''自定义类名
optionsarrayfalse[]选项数据源,格式可见下方Demo
valuearrayfalse[]可由外部控制的值
defaultValuearrayfalse[]初始默认值
dropdownClassNamestringfalse''dropdown 容器的自定义样式
placeholderstringfalse'Please Select' or '请选择'placeholder
onChangefunctionfalsefunction(value, selectedOptions)选择完成后回调
disabledbooleanfalsefalse是否禁用
clearablebooleanfalsefalse是否支持清除
changeOnSelectbooleanfalsefalse是否将每次选择立刻显示在控件中
expandTriggerstringfalse'click'次级菜单展开方式,支持 clickhover
beforeRenderfunctionfalse(value, selectedOptions) => selectedOptions.map(o => o && o.label).join(' / ')处理要显示的内容
cascadeSizenumberfalse3级联的层级数
getPopupContainerfunction():HTMLElementfalse/返回一个 html 元素用作 Popup 面板的容器,默认是插在body 中的一个 div
localestringfalse'zh-cn''en-us'
miniModebooleanfalsetrue是否是简洁显示风格
columnWidthnumberfalsenulldropdown中每一列的宽度, 如为空,整体宽度等于input输入框的宽度
displayModestringfalsedropdownselect 或者 dropdown 或者 search(已废弃)
getSelectPlaceholderfuncfalsefunction(idx){ return '请选择' }select显示模式下的placeholder生成函数
sizestringfalselarge尺寸,枚举值:large, middle, small
isMustSelectLeafboolfalsefalse是否必须选择到叶子节点
onSelectfunctionfalsenull异步加载层级,需要 return 一个数组,具体用法参考下方 demo
onlyStringValuebooleanfalsefalse选中数据之后的值,直接给字符串而不是级联结构
searchOptionfunctionfalsenull(已废弃) 开启关键词搜索的配置,当 dispalyMode 为 search 时启用,具体配置方式参考下方
showSearchbooleanfalsefalse是否开启搜索模式
onSearchfunctionfalsenull开启关键词过滤模式,可以通过外部重新设置 options,onSearch 不能与 optionFilterProps 和 optionFilterCount 一起使用,onSearch 优先级更高
optionFilterPropsstring[]false['label']showSearch=true 时,optionFilterProp 为 optionsi 中的属性名称,此时搜索会进行过滤
optionFilterCountnumberfalse20当使用过滤功能时 dropdown 里最多显示的条数
cascaderHeightnumberfalsenull级联选择区域的高度
useFullPathValuebooleanfalsefalse使用全路径值匹配模式,该模式允许父子级,不同子级的 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

NameTypeRequiredDefaultComments
valuearrayYes[]受控值
optionsarrayYes[]候选集,格式参考上方
onChangefunctionYesnullvalue 改变的回调函数
columnWidthnumberNonull每一列的宽度
cascaderHeightnumberNOnull级联选择区域的高度
renderCustomItemfunctionNonull自定义渲染选项
0.9.4

2 years ago

0.9.3

2 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.8.0

4 years ago

0.7.25

4 years ago

0.7.24

4 years ago

0.7.23

5 years ago

0.7.22

5 years ago

0.7.21

5 years ago

0.7.20

5 years ago

0.7.19

5 years ago

0.7.18

6 years ago

0.7.17

6 years ago

0.7.16

6 years ago

0.7.15

6 years ago

0.7.14

6 years ago

0.7.13

6 years ago

0.7.12

6 years ago

0.7.11

6 years ago

0.7.10

6 years ago

0.7.9

6 years ago

0.7.8

6 years ago

0.7.7

6 years ago

0.7.6

6 years ago

0.7.6-beta.1

6 years ago

0.7.5

6 years ago

0.7.4

6 years ago

0.7.3

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.5

6 years ago

0.6.4

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.8

7 years ago

0.5.7

7 years ago

0.5.6

7 years ago

0.5.5

7 years ago

0.5.4

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.2-beta.1

7 years ago

0.5.1

7 years ago

0.5.1-beta.1

7 years ago

0.5.0

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.5-beta.1

7 years ago

0.3.4

7 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.11

8 years ago

0.2.10

8 years ago

0.2.9

8 years ago

0.2.8

8 years ago

0.2.7

8 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.12

8 years ago

0.1.11

8 years ago

0.1.10

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago