Skip to content

Commit

Permalink
Merge pull request #189 from AppQuality/develop
Browse files Browse the repository at this point in the history
feat: Allow creating options on dropdown (#188)
  • Loading branch information
d-beezee authored Apr 26, 2024
2 parents fab85f4 + 5396f5d commit cf2ebcc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
25 changes: 25 additions & 0 deletions src/stories/Dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,28 @@ MultiDropdown.args = {
name: "colors",
options: colourOptions,
};

export const CreatableDropdown = Template.bind({});
CreatableDropdown.args = {
className: "creatable-single",
defaultValue: colourOptions[0],
name: "color",
onCreateOption: async (inputValue: string) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
alert(`Creating ${inputValue}`);
},
options: colourOptions,
};

export const CreatableMultiDropdown = Template.bind({});
CreatableMultiDropdown.args = {
isMulti: true,
className: "creatable-multi",
defaultValue: colourOptions[0],
name: "color",
onCreateOption: async (inputValue: string) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
alert(`Creating ${inputValue}`);
},
options: colourOptions,
};
14 changes: 10 additions & 4 deletions src/stories/Dropdown/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import ReactSelect, { Props, GroupBase, StylesConfig } from "react-select5";
import { aqTheme, customComponents } from "./styles";
import ReactSelect, { GroupBase, Props, StylesConfig } from "react-select5";
import Creatable from "react-select5/creatable";
import { aqBootstrapTheme } from "../theme/defaultTheme";
import { aqTheme, customComponents } from "./styles";

export function Dropdown<
Option,
IsMulti extends boolean = false,
Group extends GroupBase<Option> = GroupBase<Option>,
>(props: Props<Option, IsMulti, Group>) {
>(
props: Props<Option, IsMulti, Group> & {
onCreateOption?: (inputValue: string) => Promise<void>;
},
) {
const customStyle: StylesConfig<Option, IsMulti, Group> = {
control: (provided, state) => {
let borderColor = aqBootstrapTheme.colors.elementGeneric;
Expand Down Expand Up @@ -201,8 +206,9 @@ export function Dropdown<
},
};

const Component = props.onCreateOption ? Creatable : ReactSelect;
return (
<ReactSelect
<Component
theme={(theme) => ({
...theme,
...aqTheme,
Expand Down

0 comments on commit cf2ebcc

Please sign in to comment.