upd: search
This commit is contained in:
@@ -1,19 +1,42 @@
|
|||||||
import { useTheme } from "@/providers/ThemeProvider";
|
import { useTheme } from "@/providers/ThemeProvider";
|
||||||
import { Feather } from "@expo/vector-icons";
|
import { Feather } from "@expo/vector-icons";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { TouchableOpacity } from "react-native";
|
||||||
import { InputForm } from "./inputForm";
|
import { InputForm } from "./inputForm";
|
||||||
|
|
||||||
export default function InputSearch({ onChange, width, value, bg }: { onChange?: (val: string) => void, width?: number, value?: string, bg?: string }) {
|
export default function InputSearch({ onChange, width, value, bg }: { onChange?: (val: string) => void, width?: number, value?: string, bg?: string }) {
|
||||||
const { colors } = useTheme();
|
const { colors } = useTheme();
|
||||||
|
const [internalValue, setInternalValue] = useState(value ?? "");
|
||||||
|
|
||||||
|
const displayValue = value !== undefined ? value : internalValue;
|
||||||
|
|
||||||
|
const handleChange = (val: string) => {
|
||||||
|
setInternalValue(val);
|
||||||
|
onChange?.(val);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClear = () => {
|
||||||
|
setInternalValue("");
|
||||||
|
onChange?.("");
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InputForm
|
<InputForm
|
||||||
type="default"
|
type="default"
|
||||||
placeholder="Pencarian"
|
placeholder="Pencarian"
|
||||||
round
|
round
|
||||||
itemLeft={<Feather name="search" size={20} color={colors.dimmed} />}
|
itemLeft={<Feather name="search" size={20} color={colors.dimmed} />}
|
||||||
onChange={onChange}
|
itemRight={
|
||||||
|
displayValue ? (
|
||||||
|
<TouchableOpacity onPress={handleClear}>
|
||||||
|
<Feather name="x" size={20} color={colors.dimmed} />
|
||||||
|
</TouchableOpacity>
|
||||||
|
) : undefined
|
||||||
|
}
|
||||||
|
onChange={handleChange}
|
||||||
width={width}
|
width={width}
|
||||||
bg={bg}
|
bg={bg}
|
||||||
value={value}
|
value={displayValue}
|
||||||
mb={false}
|
mb={false}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user