mirror of
https://github.com/sergi0g/cup.git
synced 2025-11-08 05:03:49 -05:00
refactor: search component
This commit is contained in:
@@ -24,6 +24,7 @@ const SORT_ORDER = [
|
|||||||
function App() {
|
function App() {
|
||||||
const [data, setData] = useState<Data | null>(null);
|
const [data, setData] = useState<Data | null>(null);
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
|
|
||||||
if (!data) return <Loading onLoad={setData} />;
|
if (!data) return <Loading onLoad={setData} />;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -63,7 +64,9 @@ function App() {
|
|||||||
<LastChecked datetime={data.last_updated} />
|
<LastChecked datetime={data.last_updated} />
|
||||||
<RefreshButton />
|
<RefreshButton />
|
||||||
</div>
|
</div>
|
||||||
<Search onChange={setSearchQuery} />
|
<div className="flex gap-2 px-6 text-black dark:text-white">
|
||||||
|
<Search onChange={setSearchQuery} />
|
||||||
|
</div>
|
||||||
<ul>
|
<ul>
|
||||||
{Object.entries(
|
{Object.entries(
|
||||||
data.images.reduce<Record<string, typeof data.images>>(
|
data.images.reduce<Record<string, typeof data.images>>(
|
||||||
|
|||||||
@@ -23,32 +23,30 @@ export default function Search({
|
|||||||
onChange("");
|
onChange("");
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div className={`w-full px-6 text-black dark:text-white`}>
|
<div
|
||||||
<div
|
className={`flex w-full items-center rounded-md border border-${theme}-200 dark:border-${theme}-700 gap-1 px-2 bg-${theme}-100 dark:bg-${theme}-900 group relative flex-nowrap`}
|
||||||
className={`flex w-full items-center rounded-md border border-${theme}-200 dark:border-${theme}-700 gap-1 px-2 bg-${theme}-100 dark:bg-${theme}-900 peer flex-nowrap`}
|
>
|
||||||
>
|
<SearchIcon
|
||||||
<SearchIcon
|
className={`size-5 text-${theme}-600 dark:text-${theme}-400`}
|
||||||
className={`size-5 text-${theme}-600 dark:text-${theme}-400`}
|
/>
|
||||||
/>
|
<div className="w-full">
|
||||||
<div className="w-full">
|
<input
|
||||||
<input
|
className={`h-10 w-full text-sm text-${theme}-800 dark:text-${theme}-200 peer bg-transparent focus:outline-none placeholder:text-${theme}-600 placeholder:dark:text-${theme}-400`}
|
||||||
className={`h-10 w-full text-sm text-${theme}-800 dark:text-${theme}-200 peer bg-transparent focus:outline-none placeholder:text-${theme}-600 placeholder:dark:text-${theme}-400`}
|
placeholder="Search"
|
||||||
placeholder="Search"
|
onChange={handleChange}
|
||||||
onChange={handleChange}
|
value={searchQuery}
|
||||||
value={searchQuery}
|
></input>
|
||||||
></input>
|
|
||||||
</div>
|
|
||||||
{showClear && (
|
|
||||||
<button
|
|
||||||
onClick={handleClear}
|
|
||||||
className={`hover:text-${theme}-600 dark:hover:text-${theme}-400 transition-colors duration-200`}
|
|
||||||
>
|
|
||||||
<X className="size-5" />
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
{showClear && (
|
||||||
|
<button
|
||||||
|
onClick={handleClear}
|
||||||
|
className={`hover:text-${theme}-600 dark:hover:text-${theme}-400 transition-colors duration-200`}
|
||||||
|
>
|
||||||
|
<X className="size-5" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<div
|
<div
|
||||||
className="relative left-1/2 h-[8px] w-0 -translate-x-1/2 -translate-y-[8px] rounded-md border-b-2 border-b-blue-600 transition-all duration-200 peer-has-[:focus]:w-full"
|
className="absolute -bottom-px left-1/2 h-full w-0 -translate-x-1/2 rounded-md border-b-2 border-b-blue-600 transition-all duration-200 group-has-[:focus]:w-[calc(100%+2px)]"
|
||||||
style={{ clipPath: "inset(calc(100% - 2px) 0 0 0)" }}
|
style={{ clipPath: "inset(calc(100% - 2px) 0 0 0)" }}
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -32,19 +32,11 @@ export default {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /text-(gray|neutral)-600/,
|
pattern: /text-(gray|neutral)-600/,
|
||||||
variants: ["dark", "hover"],
|
variants: ["*", "dark", "hover", "placeholder"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /text-(gray|neutral)-400/,
|
pattern: /text-(gray|neutral)-400/,
|
||||||
variants: ["dark", "dark:hover"],
|
variants: ["*:dark", "dark", "dark:hover", "placeholder:dark"],
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: /text-(gray|neutral)-600/,
|
|
||||||
variants: ["placeholder"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: /text-(gray|neutral)-400/,
|
|
||||||
variants: ["placeholder:dark"],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /text-(gray|neutral)-700/,
|
pattern: /text-(gray|neutral)-700/,
|
||||||
|
|||||||
Reference in New Issue
Block a user