"use client" import * as React from "react" import { Search, X } from "lucide-react" import { cn } from "../../lib/utils" import { Input } from "./input" /** * Replaces `@wordpress/components`' `SearchControl` (2 sites: Paginator, LoincSearch). * * An adapter, not a rename. `onChange` receives the STRING, not the event, exactly as WP's did - * both sites pass a handler that takes a search term straight through to a query. * * WP's defaults are reproduced because both call sites rely on them and pass no label at all: * `label` defaults to "Search" and `hideLabelFromVision` to true, so the field keeps an accessible * name it never showed. Dropping that would leave two unnamed search boxes. * * The magnifier and the clear button are WP's too, not additions: WP swaps the icon for a reset * button once the field has a value, and the reset calls `onChange('')`. * * `className` and `style` land on the wrapper, which is where WP put them - `.wp-search-control` * sets a width and Paginator sets a bottom margin, and both expect the outer box. * `__nextHasNoMarginBottom` is not accepted; call sites drop it. */ export interface SearchControlProps extends Omit, "onChange" | "value" | "size"> { label?: React.ReactNode help?: React.ReactNode hideLabelFromVision?: boolean value?: string /** WP's contract: the VALUE, not the event. */ onChange: (value: string) => void /** WP's own sizes. Neither call site sets it. */ size?: "default" | "compact" } function SearchControl({ label = "Search", help, hideLabelFromVision = true, value = "", onChange, placeholder = "Search", className, style, size = "default", disabled, id, ...props }: SearchControlProps) { const generated = React.useId().replace(/:/g, "") const inputId = id ?? `search-control-${generated}` const helpId = help ? `${inputId}-help` : undefined return (
{label && ( )}
{help && (

{help}

)}
) } export { SearchControl }