import { uuid } from '../_utils/utils'; import snippets from './snippets'; export default { snippets, componentName: 'Select', title: 'Selector', category: 'Form', props: [ { name: 'defaultValue', title: { label: 'default value', tip: 'default selected value' }, propType: { type: 'oneOfType', value: [ 'string', { type: 'arrayOf', value: 'string' }, 'number', { type: 'arrayOf', value: 'number' }, ], }, }, { name: 'value', title: { label: 'current value', tip: 'current value' }, propType: { type: 'oneOfType', value: [ 'string', { type: 'arrayOf', value: 'string' }, 'number', { type: 'arrayOf', value: 'number' }, ], }, }, { name: 'options', title: { label: 'options', tip: 'options' }, propType: { type: 'arrayOf', value: { type: 'shape', value: [ { name: 'label', propType: 'string', description: '选项名', defaultValue: '选项名', }, { name: 'value', propType: ['string', 'number'], description: '选项值', defaultValue: '选项值', }, { name: 'disabled', propType: 'bool', description: '是否禁用', defaultValue: false, }, ], }, }, setter: { componentName: 'ArraySetter', props: { itemSetter: { componentName: 'ObjectSetter', props: { config: { items: [ { name: 'label', title: 'option name', setter: ['StringSetter', 'VariableSetter'], isRequired: true }, { name: 'value', title: 'option value', setter: ['StringSetter', 'NumberSetter', 'VariableSetter'], isRequired: true }, { name: 'disabled', title: 'disabled', setter: ['BoolSetter', 'VariableSetter'], }, ], }, }, initialValue: () => { return { label: 'option name', value: uuid(), disabled: false, }; }, }, }, }, }, { name: 'allowClear', title: { label: 'allow clearing', tip: 'support clearing' }, propType: 'bool', defaultValue: false, setter: 'BoolSetter' }, { name: 'autoFocus', title: { label: 'auto focus', tip: 'get automatic focus' }, propType: 'bool', defaultValue: false, setter: 'BoolSetter' }, { name: 'defaultActiveFirstOption', title: { label: 'Highlight first option', tip: 'highlight the first option by default' }, propType: 'bool', defaultValue: true, setter: 'BoolSetter' }, { name: 'disabled', title: { label: 'disabled', tip: 'disabled' }, propType: 'bool', defaultValue: false, setter: 'BoolSetter' }, { name: 'labelInValue', title: { label: 'value contains label', tip: 'Wrap the label of each option into value', }, propType: 'bool', defaultValue: false, setter: 'BoolSetter' }, { name: 'mode', title: { label: 'Multiple choice/single choice', tip: 'Multiple selection/single selection' }, setter: { componentName: 'RadioGroupSetter', props: { options: [ { title: 'single', value: 'single', }, { title: 'multiple', value: 'multiple', }, { title: 'any content', value: 'tags', }, ], }, }, propType: { type: 'oneOf', value: ['single', 'multiple', 'tags'] }, }, { name: 'maxTagCount', title: { label: 'max tag count', tip: 'Maximum number of tags to display' }, condition(target) { return target.getProps().getPropValue('mode') === 'tags'; }, propType: 'number', }, { name: 'maxTagTextLength', title: { label: 'max tag text length', tip: 'Maximum displayed tag text length' }, condition(target) { return target.getProps().getPropValue('mode') === 'tags'; }, propType: 'number', }, { name: 'notFoundContent', title: { label: 'not found content', tip: 'prompt copy when search is empty' }, propType: 'string', setter: 'StringSetter' }, { name: 'placeholder', title: { label: 'place holder', tip: 'Select box default text' }, propType: 'string', setter: 'StringSetter' }, { name: 'showArrow', title: { label: 'show arrow', tip: 'Whether to display the small drop-down arrow' }, propType: 'bool', setter: 'BoolSetter' }, { name: 'showSearch', title: { label: 'show search', tip: 'show search' }, propType: 'bool', defaultValue: false, setter: 'BoolSetter' }, { name: 'size', title: { label: 'size', tip: 'select box size' }, setter: { componentName: 'RadioGroupSetter', props: { options: [ { title: 'large', value: 'large', }, { title: 'middle', value: 'middle', }, { title: 'small', value: 'small', }, ], }, }, propType: { type: 'oneOf', value: ['large', 'middle', 'small'] }, defaultValue: 'middle', }, { name: 'loading', title: { label: 'loading', tip: 'loading status' }, propType: 'bool', defaultValue: false, setter: 'BoolSetter' }, { name: 'bordered', title: { label: 'bordered', tip: 'show border' }, propType: 'bool', defaultValue: true, setter: 'BoolSetter' }, { name: 'filterOption', title: { label: 'filter options', tip: 'filter based on input' }, propType: { type: 'oneOfType', value: ['bool', 'func'], }, defaultValue: true, }, { name: 'optionFilterProp', title: { label: 'fields to filter on', tip: 'fields to filter on' }, propType: { type: 'oneOf', value: ['value', 'label'], }, defaultValue: 'value', }, // { // name: 'suffixIcon', // title: { label: 'self suffix icon', tip: 'Customized select box suffix icon' }, // propType: 'node', // }, // { // name: 'removeIcon', // title: { label: 'remove icon', tip: 'Customized checkbox clear icon' }, // propType: 'node', // }, // { // name: 'clearIcon', // title: { label: 'Customized multi-select box clear icon', tip: 'Customized multi-select box clear icon' }, // propType: 'node', // }, // { // name: 'menuItemSelectedIcon', // title: { // label: 'Customize the icon of the currently selected item during multi-selection', // tip: 'Customize the icon of the currently selected item during multi-selection', // }, // propType: 'node', // }, { name: 'tokenSeparators', title: { label: 'separator for automatic word segmentation', tip: 'Separator for automatic word segmentation' }, propType: { type: 'arrayOf', value: 'string' }, }, { name: 'onBlur', title: { label: 'on blur', tip: 'on when focus is lost' }, propType: 'func', }, { name: 'onChange', title: { label: 'select on function', tip: 'This function is called when the option is selected or the value of the input changes.', }, propType: 'func', }, { name: 'onDeselect', title: { label: 'on deselected', tip: 'Called when unselected. The parameter is the value (or key) value of the selected item. It only takes effect in multiple or tags mode.', }, propType: 'func', }, { name: 'onFocus', title: { label: 'on focus', tip: 'on when getting focus' }, propType: 'func', }, { name: 'onInputKeyDown', title: { label: 'on input key down', tip: 'on when key is pressed' }, propType: 'func', }, { name: 'onMouseEnter', title: { label: 'on when mouse moves in', tip: 'on when mouse moves in' }, propType: 'func', }, { name: 'onMouseLeave', title: { label: 'on when mouse is moved out', tip: 'on when mouse is moved out' }, propType: 'func', }, { name: 'onPopupScroll', title: { label: 'on when scrolling the dropdown list', tip: 'on when scrolling the dropdown list' }, propType: 'func', }, { name: 'onSearch', title: { label: 'on when the text box value changes', tip: 'on when the text box value changes' }, propType: 'func', }, { name: 'onSelect', title: { label: 'on slected', tip: 'Called when selected, the parameter is the value (or key) value of the selected item', }, propType: 'func', }, { name: 'onDropdownVisibleChange', title: { label: 'expand dropdown menu on', tip: 'Expand dropdown menu callback' }, propType: 'func', }, ], configure: { supports: { style: true, events: [ { name: 'onBlur', template: "onBlur(${extParams}){\n// 失去焦点时回调\nconsole.log('onBlur');}", }, { name: 'onChange', template: "onChange(value,option,${extParams}){\n// 选中 option,或 input 的 value 变化时,调用此函数\nconsole.log('onChange',value,option);}", }, { name: 'onDeselect', template: "onDeselect(value,${extParams}){\n// 取消选中时调用\nconsole.log('onDeselect',value);}", }, { name: 'onFocus', template: "onFocus(${extParams}){\n// 获得焦点时回调\nconsole.log('onFocus');}", }, { name: 'onInputKeyDown', template: "onInputKeyDown(${extParams}){\n// 按键按下时回调\nconsole.log('onInputKeyDown');}", }, { name: 'onMouseEnter', template: "onMouseEnter(${extParams}){\n// 鼠标移入时回调\nconsole.log('onMouseEnter');}", }, { name: 'onMouseLeave', template: "onMouseLeave(${extParams}){\n// 鼠标移出时回调\nconsole.log('onMouseLeave');}", }, { name: 'onPopupScroll', template: "onPopupScroll(${extParams}){\n// 下拉列表滚动时的回调\nconsole.log('onPopupScroll');}", }, { name: 'onSearch', template: "onSearch(value,${extParams}){\n// 文本框值变化时回调\nconsole.log('onSearch',value);}", }, { name: 'onSelect', template: "onSelect(value,option,${extParams}){\n// 被选中时调用\nconsole.log('onSelect',value,option);}", }, { name: 'onDropdownVisibleChange', template: "onDropdownVisibleChange(open,${extParams}){\n// 展开下拉菜单的回调\nconsole.log('onDropdownVisibleChange',open);}", }, ], }, }, };