diff --git a/rc-select/rc-select-tests.ts b/rc-select/rc-select-tests.ts new file mode 100644 index 000000000..94cb1541e --- /dev/null +++ b/rc-select/rc-select-tests.ts @@ -0,0 +1,84 @@ +/// +/// + +import React = require('react'); +import Select = require('rc-select'); + +class Component extends React.Component { + + private onChange(value: any) { + console.log('selected', value); + } + + private onSelect(value: string, option: RcSelect.Option) { + console.log('selected value', value); + console.log('selected option', option); + } + + private onSearch() { + console.log('input changed'); + } + + private defaultSelectProps: RcSelect.SelectProps = { + className: "my-select", + prefixCls: "prefix", + animation: "slide-up", + transitionName: "my-animation", + choiceTransitionName: "multiple-animation", + dropdownMatchSelectWidth: true, + dropdownClassName: "my-dropdown", + dropdownStyle: { backgroundColor: "green" }, + dropdownMenuStyle: { backgroundColor: "red" }, + notFoundContent: "Something went wrong...", + showSearch: true, + allowClear: true, + tags: false, + maxTagTextLength: 30, + combobox: false, + multiple: true, + disabled: false, + filterOption: false, + defaultValue: "Option2", + value: "Option2", + defaultLabel: "Option2", + defaultActiveFirstOption: false + }; + + private defaultOptGroupProps: RcSelect.OptGroupProps = { + label: "Option group", + key: "option-group-0", + value: "option-group-0" + }; + + private defaultOptionProps: RcSelect.OptionProps = { + className: "option", + disabled: true, + key: "option-0", + value: "option-0" + }; + + private createOptions(count: number): React.ReactElement[] { + let options: React.ReactElement[] = []; + + for (let i = 0; i < count; i++) { + let props = this.defaultOptionProps; + props.key = `option-${i}`; + props.value = `option-${i}`; + + options.push(React.createElement(Select.Option, props)); + } + + return options; + } + + render() { + + let options: React.ReactElement[] = this.createOptions(10); + + let optionGroup: React.ReactElement = React.createElement(Select.OptGroup, this.defaultOptGroupProps, options); + + let select: React.ReactElement = React.createElement(Select.default, this.defaultSelectProps, optionGroup); + + return select; + } +} diff --git a/rc-select/rc-select.d.ts b/rc-select/rc-select.d.ts new file mode 100644 index 000000000..3377478f6 --- /dev/null +++ b/rc-select/rc-select.d.ts @@ -0,0 +1,67 @@ +// Type definitions for React Select v5.9.0 +// Project: https://github.com/react-component/select +// Definitions by: Denis Tirilis +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare namespace RcSelect { + import React = __React; + interface SelectProps { + className?: string; + prefixCls?: string; + animation?: string; + transitionName?: string; + choiceTransitionName?: string; + dropdownMatchSelectWidth?: boolean; + dropdownClassName?: string; + dropdownStyle?: { [key: string]: string }; + dropdownMenuStyle?: { [key: string]: string }; + notFoundContent?: string; + showSearch?: boolean; + allowClear?: boolean; + tags?: boolean; + maxTagTextLength?: number; + combobox?: boolean; + multiple?: boolean; + disabled?: boolean; + filterOption?: boolean; + optionFilterProp?: string; + optionLabelProp?: string; + defaultValue?: string | Array; + value?: string | Array; + onChange?: (value: string, label: string) => void; + onSearch?: Function; + onSelect?: (value: string, ontion: Option) => void; + onDeselect?: Function; + defaultLabel?: string | Array; + defaultActiveFirstOption?: boolean; + getPopupContainer?: (trigger: Node) => Node; + } + export class Select extends React.Component { } + interface OptionProps { + className?: string; + disabled?: boolean; + key?: string; + value?: string; + } + export class Option extends React.Component { } + + interface OptGroupProps { + label?: string | React.ReactElement; + key?: string; + value?: string; + } + export class OptGroup extends React.Component { } +} +declare module 'rc-select' { + import Select = RcSelect.Select; + import Option = RcSelect.Option; + import OptGroup = RcSelect.OptGroup; + + export default Select; + export { + Option, + OptGroup + }; +}