UNPKG

@payfit/unity-components

Version:

53 lines (52 loc) 1.82 kB
import { forwardRef as e } from "react"; import { uyTv as t } from "@payfit/unity-themes"; import { jsx as n, jsxs as r } from "react/jsx-runtime"; import { useIntl as i } from "react-intl"; import { InputContext as a } from "react-aria-components/Input"; import { Label as o } from "react-aria-components/Label"; import { useSlottedContext as s } from "react-aria-components/slots"; import { mergeProps as c } from "react-aria/mergeProps"; //#region src/components/label/Label.tsx var l = t({ slots: { base: "uy:typography-body-strong uy:text-content-neutral-enabled uy:leading-[1lh]", asterisk: "uy:text-content-danger uy:inline-block uy:ml-25", optionalTag: "uy:typography-body uy:inline-block uy:ml-25" }, variants: { variant: { strong: { base: "uy:typography-body-strong" }, body: { base: "uy:typography-body" } } }, defaultVariants: { variant: "strong" } }), u = e(({ children: e, ...t }, u) => { let d = i(), { isRequired: f = !1, requiredVariant: p = "required", ...m } = c({ isRequired: s(a)?.["aria-required"] }, t), { base: h, asterisk: g, optionalTag: _ } = l(); return /* @__PURE__ */ r(o, { "data-dd-privacy": "allow", ...m, ref: u, className: h({ className: t.className }), children: [ e, p === "required" && f && /* @__PURE__ */ r("span", { className: g(), children: ["*", /* @__PURE__ */ n("span", { className: "uy:sr-only", children: d.formatMessage({ id: "unity:component:label:required", defaultMessage: "required" }) })] }), p === "optional" && !f && /* @__PURE__ */ n("span", { className: _({ className: t.className }), children: d.formatMessage({ id: "unity:component:label:optional", defaultMessage: "(optional)" }) }) ] }); }); u.displayName = "Label"; //#endregion export { u as Label };