UNPKG

@payfit/unity-components

Version:

109 lines (108 loc) • 4.78 kB
import { Spinner as e } from "../spinner/Spinner.js"; import { CircularIconButton as t } from "../icon-button/CircularIconButton.js"; import { forwardRef as n } from "react"; import { uyTv as r } from "@payfit/unity-themes"; import { jsx as i, jsxs as a } from "react/jsx-runtime"; import { useTranslation as o } from "react-i18next"; import { Icon as s } from "@payfit/unity-icons"; import { Input as c } from "react-aria-components/Input"; import { SearchField as l } from "react-aria-components/SearchField"; import { FieldError as u } from "react-aria-components/FieldError"; //#region src/core/components/search/Search.tsx var d = r({ slots: { base: [ "uy:w-full uy:flex uy:h-5.5 uy:sm:h-500 uy:gap-100 uy:transition-colors uy:py-125 uy:sm:py-100 uy:px-150 uy:rounded-100 uy:sm:rounded-75 uy:bg-surface-form-high-enabled uy:items-center", "uy:focus-within:outline-none uy:focus-within:ring-2 uy:focus-within:ring-utility-focus-ring uy:focus-within:ring-offset-2 uy:focus-within:bg-surface-form-high-focus", "uy:active:border uy:active:border-solid uy:active:border-border-form-active", "uy:group-data-[disabled=true]:border uy:group-data-[disabled=true]:border-solid uy:group-data-[disabled=true]:border-border-form-disabled uy:group-data-[disabled=true]:bg-surface-form-high-disabled uy:hover:group-data-[disabled=true]:bg-surface-form-high-disabled uy:hover:group-data-[disabled=true]:border-border-form-disabled uy:group-data-[disabled=true]:cursor-not-allowed", "uy:group-data-[invalid=true]:border uy:group-data-[invalid=true]:border-solid uy:group-data-[invalid=true]:border-border-form-error uy:group-data-[invalid=true]:bg-surface-form-high-error" ], input: [ "uy:h-300 uy:min-w-0 uy:typography-body uy:flex-grow uy:outline-none uy:[&::-webkit-search-cancel-button]:hidden", "uy:enabled:text-content-form-enabled", "uy:hover:text-content-form-hover", "uy:focus-visible:text-content-form-focus", "uy:active:text-content-form-active", "uy:group-data-[invalid=true]:bg-surface-form-high-error", "uy:group-data-[disabled=true]:cursor-not-allowed" ], icon: ["uy:group-data-[disabled=true]:text-content-neutral-lowest-disabled"], invalidIcon: ["uy:hidden", "uy:group-data-[invalid=true]:block"], wrapperState: ["uy:flex uy:shrink-0 uy:items-center"], feedbackText: ["uy:typography-body-small-strong uy:text-content-form-invalid"], closeButton: ["uy:text-content-neutral-enabled uy:group-data-[empty=true]:hidden"] }, variants: { isReadOnly: { true: { base: "uy:bg-surface-form-high-disabled", icon: "uy:text-content-neutral-lowest-disabled", button: "uy:bg-surface-form-high-error uy:text-content-neutral-disabled", input: "uy:bg-surface-form-high-disabled uy:text-content-form-read-only uy:placeholder-content-form-read-only" }, false: { base: ["uy:bg-surface-form-high-enabled", "uy:hover:border-border-form-hover uy:hover:bg-surface-form-high-hover"], icon: "uy:text-content-neutral-lowest", input: "uy:bg-text-content-form-active uy:placeholder-content-neutral-lowest" } } } }), f = ({ t: e, placeholder: t, isDisabled: n }) => n ? "" : t || e((e) => e.unity.component.search.placeholder), p = n(({ isLoading: n = !1, isInvalid: r, isDisabled: p, isReadOnly: m, name: h, placeholder: g, feedbackText: _, label: v, ...y }, b) => { let { base: x, icon: S, input: C, invalidIcon: w, wrapperState: T, feedbackText: E, closeButton: D } = d({ isReadOnly: m }), { t: O } = o("unity"); return /* @__PURE__ */ a(l, { "aria-label": v, className: "uy:group", name: h, ref: b, isInvalid: r, isDisabled: p || m, isReadOnly: m, ...y, children: [/* @__PURE__ */ a("div", { className: x(), children: [ /* @__PURE__ */ i(s, { src: "MagnifyingGlassOutlined", className: S(), "aria-hidden": "true" }), /* @__PURE__ */ i(c, { className: C(), placeholder: f({ t: O, placeholder: g, isDisabled: p }) }), /* @__PURE__ */ a("div", { className: T(), children: [ /* @__PURE__ */ i(s, { className: w(), src: "WarningCircleOutlined", color: "content.form.invalid", alt: O((e) => e.unity.component.formField.formInput.error.alt) }), n && /* @__PURE__ */ i(e, { label: O((e) => e.unity.component.common.loading.label), color: "primary", size: "small", "aria-hidden": "true" }), /* @__PURE__ */ i(t, { asElement: "button", title: O((e) => e.unity.component.common.clear.title), className: D(), icon: "CloseOutlined" }) ] }) ] }), /* @__PURE__ */ i(u, { className: E(), children: _ })] }); }); p.displayName = "Search"; //#endregion export { p as Search, d as search };