Files
grungnet/src/components/Select.js

72 lines
2.0 KiB
JavaScript
Raw Normal View History

import React from "react";
import ReactSelect from "react-select";
2020-10-01 15:04:45 +10:00
import Creatable from "react-select/creatable";
import { useThemeUI } from "theme-ui";
2020-10-01 15:04:45 +10:00
function Select({ creatable, ...props }) {
const { theme } = useThemeUI();
2020-10-01 15:04:45 +10:00
const Component = creatable ? Creatable : ReactSelect;
return (
2020-10-01 15:04:45 +10:00
<Component
styles={{
menu: (provided, state) => ({
...provided,
backgroundColor: theme.colors.background,
2020-10-15 16:27:20 +11:00
color: theme.colors.text,
borderRadius: "4px",
borderColor: theme.colors.gray,
borderStyle: "solid",
borderWidth: "1px",
fontFamily: theme.fonts.body2,
2020-10-15 16:27:20 +11:00
opacity: state.isDisabled ? 0.5 : 1,
}),
control: (provided, state) => ({
...provided,
backgroundColor: theme.colors.background,
2020-10-15 16:27:20 +11:00
color: theme.colors.text,
borderColor: theme.colors.text,
2020-10-15 16:27:20 +11:00
opacity: state.isDisabled ? 0.5 : 1,
}),
2020-10-15 16:27:20 +11:00
singleValue: (provided) => ({
...provided,
2020-10-15 16:27:20 +11:00
color: theme.colors.text,
fontFamily: theme.fonts.body2,
}),
option: (provided, state) => ({
...provided,
2020-10-15 16:27:20 +11:00
color: theme.colors.text,
opacity: state.isDisabled ? 0.5 : 1,
}),
dropdownIndicator: (provided, state) => ({
...provided,
2020-10-15 16:27:20 +11:00
color: theme.colors.text,
":hover": {
color: state.isDisabled
? theme.colors.disabled
: theme.colors.primary,
},
}),
2020-10-01 15:04:45 +10:00
input: (provided, state) => ({
...provided,
2020-10-15 16:27:20 +11:00
color: theme.colors.text,
opacity: state.isDisabled ? 0.5 : 1,
2020-10-01 15:04:45 +10:00
}),
}}
theme={(t) => ({
...t,
colors: {
...t.colors,
primary: theme.colors.primary,
primary50: theme.colors.secondary,
primary25: theme.colors.highlight,
},
})}
{...props}
/>
);
}
export default Select;