UNPKG

@payfit/unity-components

Version:

113 lines (112 loc) • 4.32 kB
import { Spinner as e } from "../spinner/Spinner.js"; import { useResizable as t } from "../../hooks/use-resizable.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 { TextArea as c } from "react-aria-components/TextArea"; //#region src/core/components/text-area/TextArea.tsx var l = r({ slots: { base: "uy:flex uy:border uy:border-solid uy:rounded-100 uy:sm:rounded-75 uy:focus-within:outline-none uy:focus-within:ring-2 uy:focus-within:ring-utility-focus-ring uy:focus-within:ring-offset-2 uy:active:border-border-form-active uy:overflow-hidden uy:relative", inputWrapper: "uy:flex uy:gap-50 uy:flex-grow uy:pt-125 uy:sm:pt-100 uy:pb-125 uy:sm:pb-100 uy:pl-150 uy:pr-150 uy:rounded-100 uy:sm:rounded-75", input: "uy:flex-grow uy:flex-shrink uy:outline-none uy:typography-body uy:placeholder:text-content-neutral-lowest uy:resize-none", state: "uy:flex uy:gap-50 uy:flex-shrink-0 uy:basis-250", resizeHandle: "uy:absolute uy:bottom-25 uy:right-25 uy:w-100 uy:h-100 uy:cursor-se-resize uy:flex uy:items-center uy:justify-center" }, variants: { isInvalid: { true: { base: "uy:border-border-form-error uy:bg-surface-form-error", inputWrapper: "uy:bg-surface-form-error", input: "uy:bg-surface-form-error", state: "uy:text-content-form-error" } }, isReadOnly: { true: { base: "uy:border-border-form-disabled uy:bg-surface-form-disabled", inputWrapper: "uy:border-border-form-disabled uy:bg-surface-form-disabled", input: "uy:bg-surface-form-disabled uy:text-content-form-readonly" } }, isDisabled: { true: { base: "uy:border-border-form-disabled uy:bg-surface-form-disabled", inputWrapper: "uy:bg-surface-form-disabled uy:text-content-form-disabled", input: "uy:bg-surface-form-disabled uy:text-content-form-disabled" } } }, compoundVariants: [{ isInvalid: !1, isDisabled: !1, isReadOnly: !1, className: { base: "uy:border-border-form-enabled uy:bg-surface-form-enabled", inputWrapper: "uy:border-border-form-enabled uy:bg-surface-form-enabled", input: "uy:text-content-form-enabled uy:bg-surface-form-enabled", state: "uy:text-content-form-disabled" } }], defaultVariants: { isInvalid: !1, isDisabled: !1, isReadOnly: !1 } }), u = n(({ isInvalid: n, isLoading: r, isDisabled: u, isReadOnly: d, isResizable: f = !1, ...p }, m) => { let { t: h } = o("unity"), { containerRef: g, handleResizeStart: _ } = t({ isDisabled: !f || u || d }), { base: v, inputWrapper: y, input: b, state: x, resizeHandle: S } = l({ isInvalid: n, isDisabled: u, isReadOnly: d }); return /* @__PURE__ */ a("div", { ref: g, className: v(), children: [/* @__PURE__ */ a("div", { className: y(), children: [/* @__PURE__ */ i(c, { "data-dd-privacy": "mask", ...p, ref: m, className: b(), "aria-busy": r, "aria-invalid": n, readOnly: d, disabled: u }), /* @__PURE__ */ a("div", { className: x(), children: [r && /* @__PURE__ */ i(e, { color: "inherit", size: "small", label: h((e) => e.unity.component.formField.formInput.spinner.label) }), n && /* @__PURE__ */ i(s, { src: "WarningCircleOutlined", color: "content.form.invalid", alt: h((e) => e.unity.component.formField.formInput.error.alt) })] })] }), f && !u && !d && /* @__PURE__ */ i("div", { className: S(), onMouseDown: _, role: "button", tabIndex: 0, "aria-label": h((e) => e.unity.component.formField.textarea.resizeHandle.label), onKeyDown: (e) => { (e.key === "Enter" || e.key === " ") && (e.preventDefault(), g.current?.querySelector("textarea")?.focus()); }, children: /* @__PURE__ */ a("svg", { role: "presentation", width: "8", height: "8", viewBox: "0 0 8 8", fill: "none", children: [/* @__PURE__ */ i("path", { d: "M0.72774 8L0 7.28745L7.27226 0L8 0.712547L0.72774 8Z", fill: "#8B8D98" }), /* @__PURE__ */ i("path", { d: "M4.73172 8L4 7.27073L7.26828 4L8 4.72927L4.73172 8Z", fill: "#8B8D98" })] }) })] }); }); u.displayName = "TextArea"; //#endregion export { u as TextArea, l as textArea };