1
0
Fork 0
mirror of https://codeberg.org/MarkusThielker/next-ory.git synced 2025-04-13 13:08:41 +00:00
next-ory/dashboard/src/components/search-input.tsx
2025-01-04 13:29:19 +01:00

42 lines
1.1 KiB
TypeScript

'use client';
import { Input } from '@/components/ui/input';
import { useRouter, useSearchParams } from 'next/navigation';
import { ChangeEvent, HTMLInputTypeAttribute } from 'react';
interface SearchInputProps {
value: string;
placeholder: string;
queryParamKey: string;
type?: HTMLInputTypeAttribute;
className?: string;
}
export function SearchInput({ value, placeholder, queryParamKey, type, className }: SearchInputProps) {
const router = useRouter();
const params = useSearchParams();
const onSearchChange = (event: ChangeEvent<HTMLInputElement>) => {
const value = event.target.value;
const newParams = new URLSearchParams(params.toString());
if (value.length < 1) {
newParams.delete(queryParamKey);
} else {
newParams.set(queryParamKey, value);
}
router.replace('?' + newParams.toString());
};
return (
<Input
value={value}
type={type ?? 'text'}
placeholder={placeholder}
className={className}
onChange={onSearchChange}/>
);
}