generalized the react-select component

so tha we can reuse it all over the application.

Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
Akos Kitta
2019-12-05 09:28:45 +01:00
parent a866bde4d1
commit 4129544738
7 changed files with 125 additions and 124 deletions

View File

@@ -0,0 +1,66 @@
import * as React from 'react';
import Select from 'react-select';
import { Styles } from 'react-select/src/styles';
import { Props } from 'react-select/src/components';
import { ThemeConfig } from 'react-select/src/theme';
export class ArduinoSelect<T> extends Select<T> {
constructor(props: Readonly<Props<T>>) {
super(props);
}
render(): React.ReactNode {
const { defaultValue, onChange, options, className } = this.props;
const height = 25;
const styles: Styles = {
control: styles => ({
...styles,
width: 200,
color: 'var(--theia-ui-font-color1)'
}),
dropdownIndicator: styles => ({
...styles,
padding: 0
}),
indicatorSeparator: () => ({
display: 'none'
}),
indicatorsContainer: () => ({
padding: '0px 5px'
}),
menu: styles => ({
...styles,
marginTop: 0
})
};
const theme: ThemeConfig = theme => ({
...theme,
borderRadius: 0,
spacing: {
controlHeight: height,
baseUnit: 2,
menuGutter: 4
}, colors: {
...theme.colors,
// `primary50`??? it's crazy but apparently, without this, we would get a light-blueish
// color when selecting an option in the select by clicking and then not releasing the button.
// https://react-select.com/styles#overriding-the-theme
primary50: 'var(--theia-accent-color4)',
}
});
const DropdownIndicator = () => <span className='fa fa-caret-down caret' />;
return <Select
options={options}
defaultValue={defaultValue}
onChange={onChange}
components={{ DropdownIndicator }}
theme={theme}
styles={styles}
classNamePrefix='arduino-select'
className={className}
isSearchable={false}
/>
}
}