diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 4c76c1dfb7..91b8d4bc34 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -89,7 +89,7 @@ "react-mailchimp-subscribe": "^2.1.3", "react-markdown": "^8.0.3", "react-redux": "^8.0.2", - "react-select": "^5.8.1", + "react-select": "^5.8.3", "react-table": "^7.8.0", "react-toastify": "^9.1.3", "sanitize-html": "^2.12.1", @@ -21259,9 +21259,9 @@ } }, "node_modules/react-select": { - "version": "5.8.1", - "resolved": "https://registry.npmjs.org/react-select/-/react-select-5.8.1.tgz", - "integrity": "sha512-RT1CJmuc+ejqm5MPgzyZujqDskdvB9a9ZqrdnVLsvAHjJ3Tj0hELnLeVPQlmYdVKCdCpxanepl6z7R5KhXhWzg==", + "version": "5.8.3", + "resolved": "https://registry.npmjs.org/react-select/-/react-select-5.8.3.tgz", + "integrity": "sha512-lVswnIq8/iTj1db7XCG74M/3fbGB6ZaluCzvwPGT5ZOjCdL/k0CLWhEK0vCBLuU5bHTEf6Gj8jtSvi+3v+tO1w==", "license": "MIT", "dependencies": { "@babel/runtime": "^7.12.0", diff --git a/frontend/package.json b/frontend/package.json index b9e85254a5..a0bc59fbc5 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -102,7 +102,7 @@ "react-mailchimp-subscribe": "^2.1.3", "react-markdown": "^8.0.3", "react-redux": "^8.0.2", - "react-select": "^5.8.1", + "react-select": "^5.8.3", "react-table": "^7.8.0", "react-toastify": "^9.1.3", "sanitize-html": "^2.12.1", diff --git a/frontend/src/components/v2/CreatableSelect/CreatableSelect.tsx b/frontend/src/components/v2/CreatableSelect/CreatableSelect.tsx new file mode 100644 index 0000000000..b662ab1217 --- /dev/null +++ b/frontend/src/components/v2/CreatableSelect/CreatableSelect.tsx @@ -0,0 +1,68 @@ +import { GroupBase } from "react-select"; +import ReactSelectCreatable, { CreatableProps } from "react-select/creatable"; +import { twMerge } from "tailwind-merge"; + +import { ClearIndicator, DropdownIndicator, MultiValueRemove, Option } from "../Select/components"; + +export const CreatableSelect = ({ + isMulti, + closeMenuOnSelect, + ...props +}: CreatableProps>) => { + return ( + ({ + ...base, + "input:focus": { + boxShadow: "none" + } + }), + multiValueLabel: (base) => ({ + ...base, + whiteSpace: "normal", + overflow: "visible" + }), + control: (base) => ({ + ...base, + transition: "none" + }) + }} + components={{ DropdownIndicator, ClearIndicator, MultiValueRemove, Option }} + classNames={{ + container: () => "w-full font-inter", + control: ({ isFocused }) => + twMerge( + isFocused ? "border-primary-400/50" : "border-mineshaft-600 hover:border-gray-400", + "border w-full p-0.5 rounded-md text-mineshaft-200 font-inter bg-mineshaft-900 hover:cursor-pointer" + ), + placeholder: () => "text-mineshaft-400 text-sm pl-1 py-0.5", + input: () => "pl-1 py-0.5", + valueContainer: () => `p-1 max-h-[14rem] ${isMulti ? "!overflow-y-scroll" : ""} gap-1`, + singleValue: () => "leading-7 ml-1", + multiValue: () => "bg-mineshaft-600 rounded items-center py-0.5 px-2 gap-1.5", + multiValueLabel: () => "leading-6 text-sm", + multiValueRemove: () => "hover:text-red text-bunker-400", + indicatorsContainer: () => "p-1 gap-1", + clearIndicator: () => "p-1 hover:text-red text-bunker-400", + indicatorSeparator: () => "bg-bunker-400", + dropdownIndicator: () => "text-bunker-200 p-1", + menu: () => + "mt-2 border text-sm text-mineshaft-200 bg-mineshaft-900 border-mineshaft-600 rounded-md", + groupHeading: () => "ml-3 mt-2 mb-1 text-mineshaft-400 text-sm", + option: ({ isFocused, isSelected }) => + twMerge( + isFocused && "bg-mineshaft-700 active:bg-mineshaft-600", + isSelected && "text-mineshaft-200", + "hover:cursor-pointer text-xs px-3 py-2" + ), + noOptionsMessage: () => "text-mineshaft-400 p-2 rounded-md" + }} + {...props} + /> + ); +}; diff --git a/frontend/src/components/v2/CreatableSelect/index.tsx b/frontend/src/components/v2/CreatableSelect/index.tsx new file mode 100644 index 0000000000..7a8676c3b6 --- /dev/null +++ b/frontend/src/components/v2/CreatableSelect/index.tsx @@ -0,0 +1 @@ +export * from "./CreatableSelect"; diff --git a/frontend/src/components/v2/FilterableSelect/FilterableSelect.tsx b/frontend/src/components/v2/FilterableSelect/FilterableSelect.tsx index 5333d79d2a..6c474907f7 100644 --- a/frontend/src/components/v2/FilterableSelect/FilterableSelect.tsx +++ b/frontend/src/components/v2/FilterableSelect/FilterableSelect.tsx @@ -1,50 +1,7 @@ -import Select, { - ClearIndicatorProps, - components, - DropdownIndicatorProps, - MultiValueRemoveProps, - OptionProps, - Props -} from "react-select"; -import { faCheckCircle, faCircleXmark } from "@fortawesome/free-regular-svg-icons"; -import { faChevronDown, faXmark } from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import Select, { Props } from "react-select"; import { twMerge } from "tailwind-merge"; -const DropdownIndicator = (props: DropdownIndicatorProps) => { - return ( - - - - ); -}; - -const ClearIndicator = (props: ClearIndicatorProps) => { - return ( - - - - ); -}; - -const MultiValueRemove = (props: MultiValueRemoveProps) => { - return ( - - - - ); -}; - -const Option = ({ isSelected, children, ...props }: OptionProps) => { - return ( - - {children} - {isSelected && ( - - )} - - ); -}; +import { ClearIndicator, DropdownIndicator, MultiValueRemove, Option } from "../Select/components"; export const FilterableSelect = ({ isMulti, closeMenuOnSelect, ...props }: Props) => (