mirror of https://github.com/grafana/grafana
parent
e40d21459a
commit
104292df63
@ -1,60 +1,82 @@ |
||||
// import React, { PureComponent } from 'react';
|
||||
// import Select as ReactSelect from 'react-select';
|
||||
// import DescriptionOption from './DescriptionOption';
|
||||
// import IndicatorsContainer from './IndicatorsContainer';
|
||||
// import ResetStyles from './ResetStyles';
|
||||
//
|
||||
// export interface OptionType {
|
||||
// label: string;
|
||||
// value: string;
|
||||
// }
|
||||
//
|
||||
// interface Props {
|
||||
// defaultValue?: any;
|
||||
// getOptionLabel: (item: T) => string;
|
||||
// getOptionValue: (item: T) => string;
|
||||
// onChange: (item: T) => {} | void;
|
||||
// options: T[];
|
||||
// placeholder?: string;
|
||||
// width?: number;
|
||||
// value: T;
|
||||
// className?: string;
|
||||
// }
|
||||
//
|
||||
// export class Select<T> extends PureComponent<Props<T>> {
|
||||
// static defaultProps = {
|
||||
// width: null,
|
||||
// className: '',
|
||||
// }
|
||||
//
|
||||
// render() {
|
||||
// const { defaultValue, getOptionLabel, getOptionValue, onSelected, options, placeholder, width, value, className } = this.props;
|
||||
// let widthClass = '';
|
||||
// if (width) {
|
||||
// widthClass = 'width-'+width;
|
||||
// }
|
||||
//
|
||||
// return (
|
||||
// <ReactSelect
|
||||
// classNamePrefix="gf-form-select-box"
|
||||
// className={`gf-form-input gf-form-input--form-dropdown ${widthClass} ${className}`}
|
||||
// components={{
|
||||
// Option: DescriptionOption,
|
||||
// IndicatorsContainer,
|
||||
// }}
|
||||
// defaultValue={defaultValue}
|
||||
// value={value}
|
||||
// getOptionLabel={getOptionLabel}
|
||||
// getOptionValue={getOptionValue}
|
||||
// menuShouldScrollIntoView={false}
|
||||
// isSearchable={false}
|
||||
// onChange={onSelected}
|
||||
// options={options}
|
||||
// placeholder={placeholder || 'Choose'}
|
||||
// styles={ResetStyles}
|
||||
// />
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// export default Select;
|
||||
// Libraries
|
||||
import classNames from 'classnames'; |
||||
import React, { PureComponent } from 'react'; |
||||
import { default as ReactSelect } from 'react-select'; |
||||
|
||||
// Components
|
||||
import DescriptionOption from './DescriptionOption'; |
||||
import IndicatorsContainer from './IndicatorsContainer'; |
||||
import ResetStyles from './ResetStyles'; |
||||
|
||||
export interface SelectOptionItem { |
||||
label?: string; |
||||
value?: string; |
||||
imgUrl?: string; |
||||
description?: string; |
||||
[key: string]: any; |
||||
} |
||||
|
||||
interface Props { |
||||
defaultValue?: any; |
||||
getOptionLabel?: (item: SelectOptionItem) => string; |
||||
getOptionValue?: (item: SelectOptionItem) => string; |
||||
onChange: (item: SelectOptionItem) => {} | void; |
||||
options: SelectOptionItem[]; |
||||
placeholder?: string; |
||||
width?: number; |
||||
value: SelectOptionItem; |
||||
className?: string; |
||||
components: object; |
||||
} |
||||
|
||||
export class Select extends PureComponent<Props> { |
||||
static defaultProps = { |
||||
width: null, |
||||
className: '', |
||||
components: {}, |
||||
}; |
||||
|
||||
render() { |
||||
const { |
||||
defaultValue, |
||||
getOptionLabel, |
||||
getOptionValue, |
||||
onChange, |
||||
options, |
||||
placeholder, |
||||
width, |
||||
value, |
||||
className, |
||||
} = this.props; |
||||
|
||||
let widthClass = ''; |
||||
if (width) { |
||||
widthClass = 'width-' + width; |
||||
} |
||||
|
||||
const selectClassNames = classNames('gf-form-input', 'gf-form-input--form-dropdown', widthClass, className); |
||||
|
||||
return ( |
||||
<ReactSelect |
||||
classNamePrefix="gf-form-select-box" |
||||
className={selectClassNames} |
||||
components={{ |
||||
Option: DescriptionOption, |
||||
IndicatorsContainer, |
||||
}} |
||||
defaultValue={defaultValue} |
||||
value={value} |
||||
getOptionLabel={getOptionLabel} |
||||
getOptionValue={getOptionValue} |
||||
menuShouldScrollIntoView={false} |
||||
isSearchable={false} |
||||
onChange={onChange} |
||||
options={options} |
||||
placeholder={placeholder || 'Choose'} |
||||
styles={ResetStyles} |
||||
/> |
||||
); |
||||
} |
||||
} |
||||
|
||||
export default Select; |
||||
|
Loading…
Reference in new issue