{"version":3,"file":"SearchField.mjs","names":["MagnifyingGlassOutlineIcon"],"sources":["../../../src/search-field/SearchField.tsx"],"sourcesContent":["/*!\n *\n *  Copyright (c) \"Neo4j\"\n *  Neo4j Sweden AB [http://neo4j.com]\n *\n *  This file is part of Neo4j.\n *\n *  Neo4j is free software: you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation, either version 3 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { type ChangeEvent, type ComponentProps, useCallback } from 'react';\n\nimport { useDebounceCallback } from '../hooks/use-debounce-callback';\nimport MagnifyingGlassOutlineIcon from '../icons/generated/custom/MagnifyingGlassOutline';\nimport { TextInput } from '../text-input';\n\ntype SearchFieldTextInputProps = Pick<\n  ComponentProps<typeof TextInput>,\n  | 'className'\n  | 'errorText'\n  | 'helpText'\n  | 'htmlAttributes'\n  | 'isDisabled'\n  | 'isFluid'\n  | 'isLoading'\n  | 'isReadOnly'\n  | 'isSkeletonLoading'\n  | 'onChange'\n  | 'placeholder'\n  | 'ref'\n  | 'size'\n  | 'skeletonProps'\n  | 'style'\n  | 'value'\n>;\n\nexport type SearchFieldProps = SearchFieldTextInputProps & {\n  /**\n   * Accessible name for the search field. The label is announced by assistive\n   * technologies but is not rendered visually.\n   */\n  label: string;\n\n  /**\n   * Called with the search query after typing pauses for `debounceDelay`, and\n   * immediately when the user presses Enter or clears the field.\n   */\n  onSearch?: (query: string) => void;\n\n  /**\n   * Delay in milliseconds before calling `onSearch` after the query changes.\n   * @default 500\n   */\n  debounceDelay?: number;\n};\n\n/**\n * A text input for entering search queries.\n *\n * @remarks\n * SearchField renders a fixed search icon and uses the native `search` input\n * type. `onChange` is called immediately, while `onSearch` is debounced until\n * typing pauses. Pressing Enter or clearing the field calls `onSearch`\n * immediately.\n */\nexport const SearchField = ({\n  debounceDelay = 500,\n  htmlAttributes,\n  label,\n  onChange,\n  onSearch,\n  ...textInputProps\n}: SearchFieldProps) => {\n  const debouncedSearch = useDebounceCallback((query: string) => {\n    onSearch?.(query);\n  }, debounceDelay);\n\n  const handleChange = useCallback(\n    (event: ChangeEvent<HTMLInputElement>) => {\n      onChange?.(event);\n\n      const query = event.target.value;\n      if (query === '') {\n        debouncedSearch.cancel();\n        onSearch?.('');\n        return;\n      }\n\n      debouncedSearch(query);\n    },\n    [debouncedSearch, onChange, onSearch],\n  );\n\n  const handleKeyDown = useCallback(\n    (event: React.KeyboardEvent<HTMLInputElement>) => {\n      htmlAttributes?.onKeyDown?.(event);\n\n      if (\n        event.key === 'Enter' &&\n        !event.defaultPrevented &&\n        !event.nativeEvent.isComposing\n      ) {\n        if (debouncedSearch.isPending()) {\n          debouncedSearch.flush();\n        } else {\n          onSearch?.(event.currentTarget.value);\n        }\n      }\n    },\n    [debouncedSearch, htmlAttributes, onSearch],\n  );\n\n  return (\n    <TextInput\n      {...textInputProps}\n      htmlAttributes={{\n        ...htmlAttributes,\n        'aria-label': label,\n        onKeyDown: handleKeyDown,\n        type: 'search',\n      }}\n      isClearable\n      leadingElement={<MagnifyingGlassOutlineIcon />}\n      onChange={handleChange}\n    />\n  );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6EE;CACA;CACA;CACA;CACA;;;;;;;;;;;AALF,MAAa,eAAe,SAOJ;CAPI,IAAA,EAC1B,gBAAgB,KAChB,gBACA,OACA,UACA,aAAA,MACG,iBAAA,yBAAA,MAAA,SAAA;CAEH,MAAM,kBAAkB,qBAAqB,UAAkB;EAC7D,aAAA,QAAA,aAAA,KAAA,KAAA,SAAW,KAAK;CAClB,GAAG,aAAa;CAEhB,MAAM,eAAe,aAClB,UAAyC;EACxC,aAAA,QAAA,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