-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
205 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { cva } from "class-variance-authority"; | ||
import { FormControl, FormField, FormItem, FormMessage } from "../ui/form"; | ||
import { | ||
Select, | ||
SelectValue, | ||
SelectContent, | ||
SelectItem, | ||
SelectTrigger, | ||
} from "../ui/select"; | ||
import { ChevronsUpIcon, EqualIcon, MinusIcon } from "lucide-react"; | ||
|
||
export default function DropField({ control, name, items, variant }: any) { | ||
if(variant === 'difficulty'){ | ||
return ( | ||
<FormField | ||
control={control} | ||
name={name} | ||
key={name} | ||
render={({ field }: any) => ( | ||
<FormItem className="mt-1"> | ||
<Select onValueChange={field.onChange} defaultValue={field.value}> | ||
<FormControl> | ||
<SelectTrigger> | ||
<SelectValue className="text-xs" placeholder={field.value} /> | ||
</SelectTrigger> | ||
</FormControl> | ||
<SelectContent> | ||
{items.map((item: any) => ( | ||
<SelectItem key={item.value} value={item.value} className="flex"> | ||
<div className="flex text-xs"> | ||
<div className=" flex items-center align-middle content-center mr-2"> | ||
{item.text === 'Easy' && <MinusIcon className="text-success" size={12}/>} | ||
{item.text === 'Medium' && <EqualIcon className="text-alert" size={12}/>} | ||
{item.text === 'Hard' && <ChevronsUpIcon className="text-warning" size={12}/>} | ||
</div> | ||
<div className="text-xs"> | ||
{item.text} | ||
</div> | ||
</div> | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
<FormMessage className="text-red-100" /> | ||
</FormItem> | ||
)} | ||
/> | ||
); | ||
} | ||
return ( | ||
<FormField | ||
control={control} | ||
name={name} | ||
key={name} | ||
render={({ field }: any) => ( | ||
<FormItem> | ||
<Select onValueChange={field.onChange} defaultValue={field.value}> | ||
<FormControl> | ||
<SelectTrigger className=""> | ||
<SelectValue placeholder={field.value} /> | ||
</SelectTrigger> | ||
</FormControl> | ||
<SelectContent> | ||
{items.map((item: any) => ( | ||
<SelectItem key={item.value} value={item.value}> | ||
{item.text} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
<FormMessage className="text-warning" /> | ||
</FormItem> | ||
)} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { CaretSortIcon } from "@radix-ui/react-icons"; | ||
import { Button } from "../ui/button"; | ||
import { FormControl, FormField, FormItem, FormMessage } from "../ui/form"; | ||
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"; | ||
import { Command, CommandGroup, CommandInput, CommandItem } from "../ui/command"; | ||
import { CommandEmpty } from "cmdk"; | ||
import { ScrollArea } from "../ui/scroll-area"; | ||
import { CheckIcon } from "lucide-react"; | ||
import { cn } from "@/lib/utils"; | ||
|
||
export default function SearchFilterField({ control, name, key, items, form }: any){ | ||
return( | ||
<FormField | ||
control={control} | ||
name={name} | ||
key={key} | ||
render={({ field }: any) => ( | ||
<FormItem className="flex flex-col mt-1" key="issue_form_item"> | ||
<Popover> | ||
<PopoverTrigger asChild> | ||
<FormControl> | ||
<Button | ||
variant="dropdown" | ||
role="combobox" | ||
key="issue_button" | ||
className={cn( | ||
"m-0 p-2 text-xs", | ||
!field.value && | ||
"text-muted-foreground font-normal", | ||
)} | ||
> | ||
{field.value | ||
? items?.data.find( | ||
(tutor: any) => | ||
tutor.name === field.value, | ||
)?.name | ||
: "select an issue"} | ||
<CaretSortIcon | ||
key="issue_sort_icon" | ||
className="h-3 w-3 shrink-0" | ||
/> | ||
</Button> | ||
</FormControl> | ||
</PopoverTrigger> | ||
<PopoverContent | ||
key="issue_content" | ||
className="h-full p-0" | ||
> | ||
<Command> | ||
<CommandInput | ||
placeholder="search..." | ||
className="h-8 my-1" | ||
key="issue_input" | ||
/> | ||
<CommandEmpty>nothing found...</CommandEmpty> | ||
<CommandGroup key="issue_command_group"> | ||
<ScrollArea className="h-fit rounded-md border"> | ||
{items?.data.map((tutor: any) => ( | ||
<CommandItem | ||
value={tutor.name} | ||
key={`${tutor.name}${tutor.MSOID}`} | ||
onSelect={() => { | ||
{ | ||
form.setValue("tutor", tutor.name); | ||
} | ||
}} | ||
> | ||
{tutor.name} | ||
<CheckIcon | ||
key={`issue-${tutor.name}-check-icon`} | ||
className={cn( | ||
"ml-auto h-3 w-3", | ||
tutor.name === field.value | ||
? "opacity-100" | ||
: "opacity-0", | ||
)} | ||
/> | ||
</CommandItem> | ||
))} | ||
</ScrollArea> | ||
</CommandGroup> | ||
</Command> | ||
</PopoverContent> | ||
</Popover> | ||
<FormMessage className="text-warning" /> | ||
</FormItem> | ||
)} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters