import { EntityManager } from "../../entity/entity-manager"; import { type EntityNamesRecord } from "../../entity/entity-manager"; import { type TemplateOptions } from "../../types/types"; import { Template } from "../template"; export class Template__view_search_input extends Template { constructor() { super("view_search_input"); } getTargetAndPath(names: EntityNamesRecord) { return { target: "web/src/components", path: `${names.fs}/${names.capital}SearchInput.tsx`, }; } override getRequiredDictKeys(): string[] | null { return ["common.searchPlaceholder"]; } async render({ entityId }: TemplateOptions["view_search_input"]) { const names = EntityManager.getNamesFromId(entityId); return { ...this.getTargetAndPath(names), body: ` import { Button, EnumSelect, Input } from "@sonamu-kit/react-components/components"; import { useSonamuBaseContext } from "@sonamu-kit/react-components/contexts"; import type React from "react"; import { useState } from "react"; import { ${names.capital}SearchField, ${names.capital}SearchFieldLabel } from "@/services/sonamu.generated"; import SearchIcon from "~icons/lucide/search"; import { SD } from "@/i18n/sd.generated"; export type ${names.capital}SearchInputProps = { input: { value?: string; onValueChange?: (value: string | null | undefined) => void; }; dropdown: { value?: string; onValueChange?: (value: string | null | undefined) => void; }; }; export function ${names.capital}SearchInput({ input: { value: inputValue, onValueChange: inputOnValueChange }, dropdown: dropdownProps, }: ${names.capital}SearchInputProps) { const [keyword, setKeyword] = useState(inputValue ?? ""); const handleSearch = () => { inputOnValueChange?.(keyword || undefined); }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter") { handleSearch(); } }; return (
{ dropdownProps.onValueChange?.(value as string | null | undefined); }} placeholder={SD("common.search")} className="w-[150px] h-8" />
setKeyword(e.target.value)} onKeyDown={handleKeyDown} />
); } `.trim(), importKeys: [], }; } }