12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052 |
- import React, { useState } from 'react';
- import { storiesOf } from '@storybook/react';
- import { Icon, Button, Form, Popover, Tag } from '../../index';
- import TreeSelect from '../index';
- import { flattenDeep } from 'lodash-es';
- import CustomTrigger from './CustomTrigger';
- import { IconCreditCard } from '@douyinfe/semi-icons';
- const TreeNode = TreeSelect.TreeNode;
- const stories = storiesOf('TreeSelect', module);
- const treeData1 = [
- {
- label: 'Node1',
- value: '0-0',
- key: '0-0',
- children: [
- {
- label: 'Child Node1',
- value: '0-0-1',
- key: '0-0-1',
- },
- {
- label: 'Child Node2',
- value: '0-0-2',
- key: '0-0-2',
- },
- ],
- },
- {
- label: 'Node2',
- value: '0-1',
- key: '0-1',
- },
- ];
- const treeData2 = [
- {
- label: '亚洲',
- value: 'yazhou',
- key: 'yazhou',
- children: [
- {
- label: '中国',
- value: 'zhongguo',
- key: 'zhongguo',
- children: [
- {
- label: '北京',
- value: 'beijing',
- key: 'beijing',
- },
- {
- label: '上海',
- value: 'shanghai',
- key: 'shanghai',
- },
- ],
- },
- // {
- // label: '日本',
- // value: 'riben',
- // key: 'riben',
- // children: [
- // {
- // label: '东京',
- // value: 'dongjing',
- // key: 'dongjing'
- // },
- // {
- // label: '大阪',
- // value: 'daban',
- // key: 'daban'
- // }
- // ]
- // },
- ],
- },
- {
- label: '北美洲',
- value: 'beimeizhou',
- key: 'beimeizhou',
- children: [
- {
- label: '美国',
- value: 'meiguo',
- key: 'meiguo',
- },
- {
- label: '加拿大',
- value: 'jianada',
- key: 'jianada',
- },
- ],
- },
- ];
- const treeDataWithoutValue = [
- {
- label: '亚洲',
- key: 'yazhou',
- children: [
- {
- label: '中国',
- key: 'zhongguo',
- disabled: true,
- children: [{
- label: '北京',
- key: 'beijing',
- },
- {
- label: '上海',
- key: 'shanghai',
- }]
- },
- {
- label: '日本',
- key: 'riben',
- children: [
- {
- label: '东京',
- key: 'dongjing',
- },
- {
- label: '大阪',
- key: 'daban',
- },
- ],
- },
- ],
- },
- {
- label: '北美洲',
- key: 'beimeizhou',
- children: [
- {
- label: '美国',
- key: 'meiguo',
- },
- {
- label: '加拿大',
- key: 'jianada',
- },
- ],
- },
- ];
- // stories.addDecorator(withKnobs);;
- class SimpleTree extends React.Component {
- render() {
- return (
- <div>
- <TreeSelect
- style={{ width: 300 }}
- // value={this.state.value}
- dropdownStyle={{ maxHeight: 200, overflow: 'auto' }}
- treeData={treeData1}
- placeholder="Please select"
- onExpand={(e, { expanded, node }) => console.log('expand', e, expanded, node)}
- onSelect={(e, bool) => console.log('select', e, bool)}
- onChange={(e, node) => console.log('change', e, node)}
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- // value={this.state.value}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- placeholder="Please select"
- />
- </div>
- );
- }
- }
- // stories.add('tree select', () => <SimpleTree />);
- stories.add('tree select', () => {
- const treeData = [
- {
- label: '亚洲',
- value: 'Asia',
- key: '0',
- children: [
- {
- label: '中国',
- value: 'China',
- key: '0-0',
- children: [
- {
- label: '北京',
- value: 'Beijing',
- key: '0-0-0',
- },
- {
- label: '上海',
- value: 'Shanghai',
- key: '0-0-1',
- },
- ],
- },
- ],
- },
- {
- label: '北美洲',
- value: 'North America',
- key: '1',
- },
- ];
- return (
- <TreeSelect
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- placeholder="请选择"
- />
- );
- });
- // stories.add('large tree', () => (
- // <div>
- // <TreeSelect
- // dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- // treeData={treeData}
- // multiple
- // // motion={false}
- // treeNodeFilterProp='value'
- // placeholder="Please select"
- // />
- // </div>
- // ));
- stories.add('searchable', () => (
- <div>
- <TreeSelect
- style={{ width: 300 }}
- // value={this.state.value}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- filterTreeNode
- treeNodeFilterProp="value"
- placeholder="Please select"
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- // value={this.state.value}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- filterTreeNode
- placeholder="Please select"
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- // value={this.state.value}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- filterTreeNode
- searchAutoFocus
- placeholder="searchAutoFocus"
- />
- </div>
- ));
- stories.add('searchPosition', () => (
- <>
- <TreeSelect
- searchPosition="trigger"
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- filterTreeNode
- placeholder="单选"
- />
- <br />
- <br />
- <TreeSelect
- searchPosition="trigger"
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- filterTreeNode
- maxTagCount={2}
- placeholder="多选"
- />
- <br />
- <br />
- <TreeSelect
- searchPosition="trigger"
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- filterTreeNode
- maxTagCount={2}
- placeholder="searchAutoFocus"
- searchAutoFocus
- />
- </>
- ));
- stories.add('prefix suffix insetLabel', () => (
- <div>
- <TreeSelect
- style={{ width: 300 }}
- // value={this.state.value}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- filterTreeNode
- prefix={<IconCreditCard />}
- treeNodeFilterProp="value"
- placeholder="Please select"
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- // value={this.state.value}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- filterTreeNode
- prefix={<span>1234</span>}
- treeNodeFilterProp="value"
- placeholder="Please select"
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- suffix="RMB"
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- placeholder="Please select"
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- insetLabel="blablabla"
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- placeholder="Please select"
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- insetLabel={<span>1234</span>}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- placeholder="Please select"
- />
- </div>
- ));
- stories.add('validate status', () => (
- <div>
- <TreeSelect
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- validateStatus="warning"
- placeholder="Please select"
- onExpand={(e, { expanded, node }) => console.log('expand', e, expanded, node)}
- onSelect={(e, bool) => console.log('select', e, bool)}
- onChange={e => console.log('change', e)}
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- validateStatus="error"
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- // multiple
- placeholder="Please select"
- />
- </div>
- ));
- stories.add('multiple', () => (
- <div>
- <TreeSelect
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- placeholder="Please select"
- onExpand={(e, { expanded, node }) => console.log('expand', e, expanded, node)}
- onSelect={(e, bool) => console.log('select', e, bool)}
- onChange={e => console.log('change', e)}
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- // value={this.state.value}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- placeholder="Please select"
- />
- </div>
- ));
- stories.add('maxTagCount', () => (
- <div>
- <TreeSelect
- style={{ width: 300 }}
- // value={this.state.value}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- maxTagCount={2}
- placeholder="Please select"
- />
- {/* <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- // value={this.state.value}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- placeholder="Please select"
- /> */}
- </div>
- ));
- stories.add('multiple searchable', () => (
- <div>
- <TreeSelect
- style={{ width: 300 }}
- // value={this.state.value}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- filterTreeNode
- treeNodeFilterProp="value"
- placeholder="Please select"
- />
- </div>
- ));
- stories.add('default values', () => (
- <div>
- <TreeSelect
- style={{ width: 300 }}
- defaultValue={'shanghai'}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- // multiple
- filterTreeNode
- treeNodeFilterProp="value"
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- defaultValue={'shanghai'}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- filterTreeNode
- multiple
- treeNodeFilterProp="value"
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- defaultValue={['shanghai', 'daban', 'dongjing']}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- filterTreeNode
- multiple
- treeNodeFilterProp="value"
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- defaultValue={['meiguo', 'dongjing']}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- filterTreeNode
- multiple
- treeNodeFilterProp="value"
- />
- </div>
- ));
- stories.add('disabled', () => (
- <div>
- <TreeSelect
- style={{ width: 300 }}
- defaultValue={'shanghai'}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- filterTreeNode
- disabled
- treeNodeFilterProp="value"
- placeholder="Please select"
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- defaultValue={'shanghai'}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- filterTreeNode
- disabled
- treeNodeFilterProp="value"
- placeholder="Please select"
- />
- <br />
- <br />
- <TreeSelect
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- filterTreeNode
- disabled
- treeNodeFilterProp="value"
- placeholder="Please select"
- />
- </div>
- ));
- stories.add('optionLabelProp', () => (
- <>
- <TreeSelect
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- filterTreeNode
- treeNodeFilterProp="value"
- treeNodeLabelProp="value"
- placeholder="Please select"
- />
- </>
- ));
- stories.add('valueInArray', () => (
- <>
- <TreeSelect
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- filterTreeNode
- valueInArray
- onChange={(...args) => console.log(args)}
- treeNodeFilterProp="value"
- treeNodeLabelProp="value"
- placeholder="Please select"
- />
- </>
- ));
- stories.add('onBlur/onFocus', () => (
- <>
- <div>single</div>
- <TreeSelect
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- onBlur={(...args) => console.log('blur', args)}
- onFocus={(...args) => console.log('focus', args)}
- placeholder="Please select"
- />
- <div>multiple</div>
- <TreeSelect
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- onBlur={(...args) => console.log('blur', args)}
- onFocus={(...args) => console.log('focus', args)}
- placeholder="Please select"
- />
- </>
- ));
- stories.add('leafOnly', () => (
- <div>
- <TreeSelect
- style={{ width: 300 }}
- // value={this.state.value}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- multiple
- leafOnly
- placeholder="Please select"
- onExpand={(e, { expanded, node }) => console.log('expand', e, expanded, node)}
- onSelect={(e, bool) => console.log('select', e, bool)}
- onChange={e => console.log('change', e)}
- />
- </div>
- ));
- class Demo extends React.Component {
- constructor() {
- super();
- this.state = {
- value: 'shanghai',
- };
- }
- onChange(value) {
- this.setState({ value });
- }
- render() {
- return (
- <TreeSelect
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData2}
- value={this.state.value}
- placeholder="Please select"
- onChange={e => this.onChange(e)}
- />
- );
- }
- }
- stories.add('controlled Component single', () => <Demo />);
- class Demo2 extends React.Component {
- constructor() {
- super();
- this.state = {
- value: ['Shanghai'],
- };
- }
- onChange(value) {
- this.setState({ value });
- }
- render() {
- console.log(this.state.value);
- const treeData = [
- {
- label: '亚洲',
- value: 'Asia',
- key: '0',
- children: [
- {
- label: '中国',
- value: 'China',
- key: '0-0',
- children: [
- {
- label: '北京',
- value: 'Beijing',
- key: '0-0-0',
- },
- {
- label: '上海',
- value: 'Shanghai',
- key: '0-0-1',
- },
- ],
- },
- ],
- },
- {
- label: '北美洲',
- value: 'North America',
- key: '1',
- },
- ];
- return (
- <TreeSelect
- style={{ width: 300 }}
- multiple
- dropdownStyle={{ maxHeight: 200, overflow: 'auto' }}
- treeData={treeData}
- value={this.state.value}
- placeholder="Please select"
- onChange={e => this.onChange(e)}
- />
- );
- }
- }
- stories.add('controlled Component multiple', () => <Demo2 />);
- class Demo3 extends React.Component {
- constructor() {
- super();
- this.state = {
- value: ['Shanghai'],
- };
- }
- // 获取最底层值
- getDeepChildrensByNode = node => {
- return flattenDeep(
- node.map(item => {
- if (item.children) {
- return this.getDeepChildrensByNode(item.children);
- }
- return item.value;
- })
- );
- };
- onChange(value, node) {
- console.log('onchange', value);
- value = this.getDeepChildrensByNode(node);
- console.log('modifiled', value);
- this.setState({ value });
- }
- render() {
- const treeData = [
- {
- label: '亚洲',
- value: 'Asia',
- key: '0',
- children: [
- {
- label: '中国',
- value: 'China',
- key: '0-0',
- children: [
- {
- label: '北京',
- value: 'Beijing',
- key: '0-0-0',
- },
- {
- label: '上海',
- value: 'Shanghai',
- key: '0-0-1',
- },
- ],
- },
- ],
- },
- {
- label: '北美洲',
- value: 'North America',
- key: '1',
- },
- ];
- return (
- <TreeSelect
- style={{ width: 300 }}
- multiple
- dropdownStyle={{ maxHeight: 200, overflow: 'auto' }}
- treeData={treeData}
- value={this.state.value}
- placeholder="Please select"
- onChange={(e, node) => this.onChange(e, node)}
- />
- );
- }
- }
- stories.add('controlled Component multiple value modified', () => <Demo3 />);
- class ConvertDemo extends React.Component {
- constructor(props) {
- super(props);
- this.formApi = null;
- }
- handleChange = val => {
- let finalVal = val;
- let firstClassOption = ['Asia', 'North America'];
- // 在这里去做你的value替换逻辑
- console.log('originVal:' + val);
- if (val.length === 1) {
- // do nothing
- } else {
- if (val.every(item => firstClassOption.includes(item))) {
- finalVal = val[val.length - 1];
- }
- }
- console.log('finalVal:' + finalVal);
- return finalVal;
- };
- render() {
- const treeData = [
- {
- label: '亚洲',
- value: 'Asia',
- key: '0',
- children: [
- {
- label: '中国',
- value: 'China',
- key: '0-0',
- children: [
- {
- label: '北京',
- value: 'Beijing',
- key: '0-0-0',
- },
- {
- label: '上海',
- value: 'Shanghai',
- key: '0-0-1',
- },
- ],
- },
- ],
- },
- {
- label: '北美洲',
- value: 'North America',
- key: '1',
- },
- ];
- return (
- <Form getFormApi={this.getFormApi}>
- <Form.TreeSelect
- field="tree"
- label="节点(TreeSelect)"
- placeholder="请选择服务节点"
- treeData={treeData}
- convert={this.handleChange}
- filterTreeNode
- multiple
- ></Form.TreeSelect>
- </Form>
- );
- }
- }
- stories.add('convert demo', () => <ConvertDemo />);
- stories.add('treeselect defaultOpen in popover', () => (
- <Popover
- content={
- <TreeSelect
- style={{ width: 200 }}
- dropdownStyle={{ width: 200 }}
- treeData={treeData1}
- defaultOpen
- // value={this.state.value}
- // placeholder="Please select"
- // onChange={(e, node) => this.onChange(e, node)}
- />
- }
- >
- <Button style={{ marginLeft: 150 }}>悬停此处</Button>
- </Popover>
- ));
- stories.add(`custom trigger`, () => <CustomTrigger />);
- const AutoParentDemo = () => {
- const [expandedKeys, setExpandedKeys] = useState(['beimeizhou']);
- const [selectedKeys, setSelectedKeys] = useState(['beimeizhou']);
- const [autoExpandParent, setAutoExpandParent] = useState(true);
- const onExpand = expandedKeys => {
- console.log('onExpand', expandedKeys);
- // if not set autoExpandParent to false, if children expanded, parent can not collapse.
- // or, you can remove all expanded children keys.
- setExpandedKeys(expandedKeys);
- setAutoExpandParent(false);
- };
- const onSelect = (selectedKeys, info) => {
- console.log('onSelect:', info);
- setSelectedKeys(selectedKeys);
- };
- return (
- <div>
- <Button onClick={() => {
- setSelectedKeys(['beijing']);
- setExpandedKeys(['beijing']);
- setAutoExpandParent(true);
- }}>Update</Button>
- <TreeSelect
- onExpand={onExpand}
- expandedKeys={expandedKeys}
- autoExpandParent={autoExpandParent}
- onChange={onSelect}
- value={selectedKeys}
- treeData={treeData2}
- // multiple
- />
- </div>
- );
- };
- stories.add('autoExpandParent', () => (
- <>
- <AutoParentDemo />
- </>
- ));
- stories.add('tree without value props', () => (
- <TreeSelect
- treeData={treeDataWithoutValue}
- value="beijing"
- defaultExpandAll
- onChange={(...args) => console.log(args)}
- />
- ));
- stories.add('treeSelect renderSelectedItem', () => {
- const treeData = [
- {
- label: '亚洲',
- value: 'Asia',
- key: '0',
- children: [
- {
- label: '中国',
- value: 'China',
- key: '0-0',
- children: [
- {
- label: '北京',
- value: 'Beijing',
- key: '0-0-0',
- },
- {
- label: '上海',
- value: 'Shanghai',
- key: '0-0-1',
- },
- ],
- },
- ],
- },
- {
- label: '北美洲',
- value: 'North America',
- key: '1',
- },
- {
- label: '南美洲',
- value: 'South America',
- key: '2',
- },
- {
- label: '南极洲',
- value: 'Antarctica',
- key: '3',
- },
- ];
- return (
- <>
- <h4>单选</h4>
- <TreeSelect
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData}
- placeholder="请选择"
- renderSelectedItem={item => `${item.value}-${item.label}`}
- />
- <h4>多选</h4>
- <TreeSelect
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData}
- multiple
- placeholder="请选择"
- renderSelectedItem={(item, { index, onClose }) => ({ content: `${item.value}-${item.label}`, isRenderInTag: true })}
- />
- <h4>多选 + isRenderInTag=false</h4>
- <TreeSelect
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData}
- multiple
- maxTagCount={2}
- placeholder="请选择"
- renderSelectedItem={(item, { index, onClose }) => ({ content: <Tag key={index} color="white">{item.value}</Tag>, isRenderInTag: false })}
- />
- </>
- )
- }
- );
- const DisableStrictlyDemo = () => {
- const [value, setValue] = useState(['Shanghai'])
- const treeData = [
- {
- label: '亚洲',
- value: 'Asia',
- key: '0',
- children: [
- {
- label: '中国',
- value: 'China',
- key: '0-0',
- disabled: true,
- children: [
- {
- label: '北京',
- value: 'Beijing',
- key: '0-0-0',
- },
- {
- label: '上海',
- value: 'Shanghai',
- key: '0-0-1',
- },
- ],
- },
- {
- label: '日本',
- value: 'Japan',
- key: '0-1',
- },
- ],
- },
- {
- label: '北美洲',
- value: 'North America',
- key: '1',
- }
- ]
- return (
- <div>
- <TreeSelect
- style={{ width: 300 }}
- dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
- treeData={treeData}
- disableStrictly
- multiple
- searchPosition="trigger"
- filterTreeNode
- value={value}
- onChange={value=>setValue(value)}
- />
- </div>
- )
- }
- stories.add('disabledStrictly', () => (
- <>
- <DisableStrictlyDemo />
- </>
- ));
|