Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 19 additions & 4 deletions src/components/atoms/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { cn } from "@/lib/utils"
import { CloseIcon } from "@/icons"
import { useEffect, useState } from "react"
import { EyeMini, EyeSlashMini } from "@medusajs/icons"
import { IconButton } from "../IconButton/IconButton"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not used so import can be removed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed


interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
label?: string
icon?: React.ReactNode
clearable?: boolean
error?: boolean
changeValue?: (value: string) => void
onIconClick?: () => void
iconAriaLabel?: string
}

export function Input({
Expand All @@ -20,6 +23,8 @@ export function Input({
className,
error,
changeValue,
onIconClick,
iconAriaLabel,
...props
}: InputProps) {
const [showPassword, setShowPassword] = useState(false)
Expand Down Expand Up @@ -47,10 +52,20 @@ export function Input({
}

return (
<label className="label-md">
{label}
<div className="flex flex-col">
<label className="label-md">{label}</label>
<div className="relative mt-2">
{icon && (
{icon && onIconClick && (
<button
onClick={onIconClick}
className="flex items-center justify-center rounded-sm transition-all duration-300 ease-out button-transparent h-[32px] w-[32px] absolute top-[8px] left-[8px]"
aria-label={iconAriaLabel}
>
{icon}
</button>
)}

{icon && !onIconClick && (
<span className="absolute top-0 left-[16px] h-full flex items-center">
{icon}
</span>
Expand Down Expand Up @@ -87,6 +102,6 @@ export function Input({
</button>
)}
</div>
</label>
</div>
)
}
11 changes: 9 additions & 2 deletions src/components/molecules/NavbarSearch/NavbarSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,29 @@ export const NavbarSearch = () => {

const [search, setSearch] = useState(searchParams.get("query") || "")

const submitHandler = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
const handleSearch = () => {
if (search) {
redirect(`/categories?query=${search}`)
} else {
redirect(`/categories`)
}
}

const submitHandler = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
handleSearch()
}

return (
<form className="flex items-center" method="POST" onSubmit={submitHandler}>
<Input
icon={<SearchIcon />}
onIconClick={handleSearch}
iconAriaLabel="Search"
placeholder="Search product"
value={search}
changeValue={setSearch}
type="search"
/>
<input type="submit" className="hidden" />
</form>
Expand Down