-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5de9011
commit 105a32d
Showing
4 changed files
with
135 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
--- | ||
order: 1 | ||
title: 级联选择器 | ||
desc: 扩展菜单 | ||
--- | ||
|
||
```jsx | ||
|
||
import React, { useState } from 'react'; | ||
import { CCascader, Input, Checkbox } from 'cloud-react'; | ||
const LABEL_ENUM = { | ||
fj: '贵州 - 黔西南布依族苗族自治州', | ||
fuzhou: '福州', | ||
mawei: '马尾', | ||
mawei1: '马尾1', | ||
quanzhou: '泉州', | ||
zj: '浙江', | ||
hangzhou: '杭州', | ||
yuhang: '余杭', | ||
bj: '北京', | ||
chaoyang: '朝阳区', | ||
haidian: '海淀区' | ||
} | ||
|
||
const addressOptions = [{ | ||
label: '贵州 - 黔西南布依族苗族自治州', | ||
value: 'fj', | ||
children: [{ | ||
label: '福州', | ||
value: 'fuzhou', | ||
children: [{ | ||
label: '马尾', | ||
value: 'mawei', | ||
},{ | ||
label: '马尾1', | ||
value: 'mawei1', | ||
}], | ||
}, { | ||
label: '泉州', | ||
value: 'quanzhou', | ||
}], | ||
}, { | ||
label: '浙江', | ||
value: 'zj', | ||
children: [{ | ||
label: '杭州', | ||
value: 'hangzhou', | ||
children: [{ | ||
label: '余杭', | ||
value: 'yuhang', | ||
}], | ||
}], | ||
}, { | ||
label: '北京', | ||
value: 'bj', | ||
children: [{ | ||
label: '朝阳区', | ||
value: 'chaoyang', | ||
}, { | ||
label: '海淀区', | ||
value: 'haidian', | ||
}], | ||
}]; | ||
|
||
export default function Demo() { | ||
const [ checked, setChecked] = useState(false); | ||
const [ value, setValue ] = useState([['zj']]); | ||
const [ inputValue, setInputValue] =useState('浙江'); | ||
|
||
const onChange = (value, selectedOptions, isSelectedAll) => { | ||
setValue(value); | ||
setChecked(!!isSelectedAll); | ||
setInputValue(isSelectedAll ? '全部' : value.map(x => x[x.length - 1]).map(x => LABEL_ENUM[x]).join(',')); | ||
} | ||
|
||
const filter = (inputValue, path) => { | ||
return path.some(option => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1); | ||
} | ||
|
||
const handleALlChange = value => { | ||
setChecked(value); | ||
if (value) { | ||
setValue([['zj'], ['fj'], ['bj']]); | ||
return; | ||
} | ||
setValue([]); | ||
} | ||
return ( | ||
<div> | ||
<div style={{ marginBottom: 24 }}>多选级联组件</div> | ||
<CCascader | ||
options={addressOptions} | ||
onChange={onChange} | ||
placeholder="Please select" | ||
value={value} | ||
multiple | ||
allowClear | ||
showSearch={{ filter: filter }} | ||
dropdownRender={menus => ( | ||
<div> | ||
{menus} | ||
<hr /> | ||
<Checkbox checked={checked} onChange={handleALlChange} style={{ marginLeft: 12 }}> | ||
全选 | ||
</Checkbox> | ||
</div> | ||
)}> | ||
<Input | ||
placeholder={'请选择'} | ||
value={inputValue} | ||
style={{ width: 170, fontSize: '12px' }} | ||
/> | ||
</CCascader> | ||
</div> | ||
); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters