{"version":3,"file":"Search.cjs","sources":["../../../../src/components/search/Search.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React, { forwardRef, useRef } from \"react\";\nimport { mergeRefs } from \"../../utilities/mergeRefs.js\";\nimport { InputGroup } from \"../input-group/index.js\";\nimport { SearchButton } from \"./SearchButton.js\";\nimport type { SearchInputProps } from \"./types.js\";\n\nexport const Search = forwardRef<HTMLInputElement, SearchInputProps>(\n    function Search(props, forwardedRef): React.JSX.Element {\n        const {\n            label = \"Søk\",\n            className,\n            errorLabel,\n            helpLabel,\n            labelProps = { srOnly: true },\n            supportLabelProps,\n            tooltip,\n            description,\n            name = \"q\",\n            placeholder = \"Søk\",\n            spellCheck = false,\n            icon = \"search\",\n            children,\n            value,\n            ...rest\n        } = props;\n\n        const inputGroupProps = {\n            label,\n            errorLabel,\n            helpLabel,\n            labelProps,\n            supportLabelProps,\n            tooltip,\n            description,\n        };\n\n        const internalRef = useRef<HTMLInputElement>(null);\n        const ref = mergeRefs(internalRef, forwardedRef);\n\n        const handleClick = () => {\n            if (internalRef.current) {\n                const nativeInputValueSetter = Object.getOwnPropertyDescriptor(\n                    window.HTMLInputElement.prototype,\n                    \"value\",\n                )?.set;\n                nativeInputValueSetter?.call(internalRef.current, \"\");\n                const event = new Event(\"change\", { bubbles: true });\n                internalRef.current.dispatchEvent(event);\n                internalRef.current.focus();\n            }\n        };\n\n        return (\n            <div className={clsx(\"jkl-search\", className)}>\n                <InputGroup\n                    {...inputGroupProps}\n                    label={label}\n                    data-testid=\"jkl-search\"\n                    render={(inputProps) => (\n                        <div className=\"input-wrapper\" data-icon={icon}>\n                            <input\n                                ref={ref}\n                                type=\"search\"\n                                name={name}\n                                placeholder={placeholder}\n                                spellCheck={spellCheck}\n                                {...inputProps}\n                                {...rest}\n                            />\n                            <button\n                                className=\"clear-button\"\n                                type=\"button\"\n                                onClick={handleClick}\n                            >\n                                <span className=\"jkl-sr-only\">\n                                    Tilbakestill søkefeltet\n                                </span>\n                            </button>\n                        </div>\n                    )}\n                />\n                {children}\n            </div>\n        );\n    },\n) as ReturnType<typeof forwardRef<HTMLInputElement, SearchInputProps>> & {\n    Button: typeof SearchButton;\n};\n\nSearch.Button = SearchButton;\n"],"names":["Search","forwardRef","props","forwardedRef","label","className","errorLabel","helpLabel","labelProps","srOnly","supportLabelProps","tooltip","description","name","placeholder","spellCheck","icon","children","value","rest","inputGroupProps","internalRef","useRef","ref","mergeRefs","handleClick","current","Object","getOwnPropertyDescriptor","window","HTMLInputElement","prototype","set","call","event","Event","bubbles","dispatchEvent","focus","clsx","jsx","InputGroup","render","inputProps","jsxs","type","onClick","Button","SearchButton"],"mappings":"4cAOaA,EAASC,EAAAA,WAClB,SAAgBC,EAAOC,GACnB,MACIC,MAAAA,EAAQ,MACRC,UAAAA,EACAC,WAAAA,EACAC,UAAAA,EACAC,WAAAA,EAAa,CAAEC,QAAQ,GACvBC,kBAAAA,EACAC,QAAAA,EACAC,YAAAA,EACAC,KAAAA,EAAO,IACPC,YAAAA,EAAc,MACdC,WAAAA,GAAa,EACbC,KAAAA,EAAO,SACPC,SAAAA,EACAC,MAAAA,KACGC,GACHjB,EAEEkB,EAAkB,CACpBhB,MAAAA,EACAE,WAAAA,EACAC,UAAAA,EACAC,WAAAA,EACAE,kBAAAA,EACAC,QAAAA,EACAC,YAAAA,GAGES,EAAcC,EAAAA,OAAyB,MACvCC,EAAMC,EAAAA,UAAUH,EAAalB,GAE7BsB,EAAc,KAChB,GAAIJ,EAAYK,QAAS,CACUC,OAAOC,yBAClCC,OAAOC,iBAAiBC,UACxB,UACDC,KACqBC,KAAKZ,EAAYK,QAAS,IAClD,MAAMQ,EAAQ,IAAIC,MAAM,SAAU,CAAEC,SAAS,IAC7Cf,EAAYK,QAAQW,cAAcH,GAClCb,EAAYK,QAAQY,OACxB,GAGJ,cACK,MAAA,CAAIjC,UAAWkC,EAAAA,KAAK,aAAclC,GAC/BY,SAAA,CAAAuB,EAAAA,IAACC,EAAAA,WAAA,IACOrB,E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