UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

35 lines 2.02 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { forwardRef, useContext } from "react"; import { MagnifyingGlassIcon } from "@navikt/aksel-icons"; import { Button } from "../../button/index.js"; import { useRenameCSS } from "../../theme/Theme.js"; import { composeEventHandlers } from "../../util/composeEventHandlers.js"; import { useI18n } from "../../util/i18n/i18n.hooks.js"; import { SearchContext } from "./context.js"; const SearchButton = forwardRef((_a, ref) => { var _b; var { className, children, disabled, onClick } = _a, rest = __rest(_a, ["className", "children", "disabled", "onClick"]); const { cn } = useRenameCSS(); const translate = useI18n("Search"); const context = useContext(SearchContext); if (context === null) { console.warn("<Search.Button> has to be wrapped in <Search />"); return null; } const { size, variant, handleClick } = context; return (React.createElement(Button, Object.assign({ type: "submit" }, rest, { ref: ref, size: size, variant: variant === "secondary" ? "secondary" : "primary", className: cn("navds-search__button-search", className), disabled: (_b = context === null || context === void 0 ? void 0 : context.disabled) !== null && _b !== void 0 ? _b : disabled, onClick: composeEventHandlers(onClick, handleClick), icon: React.createElement(MagnifyingGlassIcon, Object.assign({}, (children ? { "aria-hidden": true } : { title: translate("search") }))) }), children)); }); export default SearchButton; //# sourceMappingURL=SearchButton.js.map