Skip to content

Commit

Permalink
chore: migrate vui-source changes to v1.0.1 (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrderyk authored Dec 6, 2024
1 parent ec42352 commit 6df318d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
43 changes: 43 additions & 0 deletions src/docs/pages/searchSelect/SingleSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { useState } from "react";
import { VuiButtonSecondary, VuiSearchSelect } from "../../../lib";

const options = [
{ value: "a", label: "Caffeine-free" },
{ value: "b", label: "Freeze dried" },
{ value: "c", label: "Gluten-free" },
{ value: "d", label: "Halal" },
{ value: "e", label: "High fiber" },
{ value: "f", label: "Kosher" },
{ value: "g", label: "Lactose-free" },
{ value: "h", label: "Low-carb" },
{ value: "i", label: "No nuts" },
{ value: "j", label: "Non-GMO" },
{ value: "k", label: "Sugar-free" },
{ value: "l", label: "Vegan" }
];

export const SingleSelect = () => {
const [isOpen, setIsOpen] = useState(false);
const [searchValue, setSearchValue] = useState<string>("");
const [selectedOptions, setSelectedOptions] = useState(["a"]);

return (
<VuiSearchSelect
title="Choose one or none"
isOpen={isOpen}
setIsOpen={setIsOpen}
searchValue={searchValue}
setSearchValue={setSearchValue}
onSelect={(value: string[]) => {
setSelectedOptions(value);
}}
selectedOptions={selectedOptions}
options={options}
isMultiSelect={false}
>
<VuiButtonSecondary color="neutral" size="s">
Meal preference
</VuiButtonSecondary>
</VuiSearchSelect>
);
};
9 changes: 9 additions & 0 deletions src/docs/pages/searchSelect/index.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import { SearchSelect } from "./SearchSelect";
import { Async } from "./Async";
import { SingleSelect } from "./SingleSelect";

const SearchSelectSource = require("!!raw-loader!./SearchSelect");
const AsyncSource = require("!!raw-loader!./Async");
const SingleSelectSource = require("!!raw-loader!./SingleSelect");

export const searchSelect = {
name: "Search Select",
path: "/searchSelect",
examples: [
{
name: "Synchronous search",
component: <SearchSelect />,
source: SearchSelectSource.default.toString()
},
{
name: "Asynchronous search",
component: <Async />,
source: AsyncSource.default.toString()
},
{
name: "Single selection",
component: <SingleSelect />,
source: SingleSelectSource.default.toString()
}
]
};
16 changes: 8 additions & 8 deletions src/lib/components/searchSelect/SearchSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ export const VuiSearchSelect = <T extends unknown = unknown>({
}

onSelect(updatedSelectedOptions);
return;
}

// If the user can only select one option at a time,
// close the search select as soon as they make a choice.
onSelect([value]);
} else {
if (selectedOptions[0] === value) {
// If the user clicks on the selected option, deselect it.
onSelect([]);
return;
}

// Signal the popover to be closed.
setIsOpen(false);
onSelect([value]);
}
};

// If onSearchChange is provided, we don't filter the options here because
Expand Down

0 comments on commit 6df318d

Please sign in to comment.