Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use checkboxes for tags #13

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
use checkboxes for tags
  • Loading branch information
Brian-Pob committed Apr 16, 2024
commit fb71f521964068560deff623764e7ed8ab72413d
67 changes: 53 additions & 14 deletions src/components/forms/SearchForm.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import {
Form,
FormControl,
Expand All @@ -17,17 +18,20 @@ export function SearchForm() {
const form = useForm({
defaultValues: {
searchText: "",
searchTags: "",
searchTags: [],
searchFilters: "",
},
mode: "onChange",
});

async function onSubmit(values) {
console.log(values);

navigate({ to: "/search/results", search: values });
}

const exampleTags = ["music", "coding", "math"];

return (
<Form {...form}>
<form
Expand All @@ -53,28 +57,63 @@ export function SearchForm() {
</>
)}
/>
<div className="grid grid-flow-col gap-2">
<div className="grid sm:grid-cols-2 gap-2 ">
<FormField
className=""
control={form.control}
name="searchTags"
render={({ field }) => (
<>
<FormItem>
<FormLabel>tags</FormLabel>
<FormControl>
<Input placeholder="tags" {...field} type="text" />
</FormControl>
<FormMessage />
</FormItem>
</>
name="items"
render={() => (
<FormItem className="overflow-hidden">
<div className="-mb-8">
<FormLabel className="text-base">Popular Tags</FormLabel>
</div>
<div
className="flex flex-row overflow-x-auto py-8 gap-4 relative"

>
{exampleTags.map((tag) => (
<FormField
key={tag}
control={form.control}
name="searchTags"
render={({ field }) => {
return (
<FormItem
key={tag}
className="flex flex-row items-start space-x-1 space-y-0"
>
<FormControl>
<Checkbox
checked={field.value?.includes(tag)}
onCheckedChange={(checked) => {
return checked
? field.onChange([...field.value, tag])
: field.onChange(
field.value?.filter(
(value) => value !== tag,
),
);
}}
/>
</FormControl>
<FormLabel className="font-normal">{tag}</FormLabel>
</FormItem>
);
}}
/>
))}
</div>
<FormMessage />
</FormItem>
)}
/>

<FormField
control={form.control}
name="searchFilters"
render={({ field }) => (
<>
<FormItem>
<FormItem className="sm:flex flex-row items-center gap-2 ">
<FormLabel>filters</FormLabel>
<FormControl>
<Input placeholder="filters" {...field} type="text" />
Expand Down