UNPKG

@progress/kendo-react-labels

Version:

React Labels package provides components for labelling form editors. KendoReact Labels package

57 lines (56 loc) 2.07 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2026 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import * as s from "react"; import e from "prop-types"; import { useUnstyled as z, classNames as E, uLabel as I } from "@progress/kendo-react-common"; import { labelsOptional as b, messages as O } from "./messages/index.mjs"; import { useLocalization as T } from "@progress/kendo-react-intl"; const y = (g) => { const { id: L, editorId: o, editorRef: l, editorDisabled: a, children: n, editorValid: c, style: N, className: r, optional: k } = g, v = T(), m = k ? v.toLanguageString(b, O[b]) : "", C = m && /* @__PURE__ */ s.createElement("span", { className: "k-label-optional" }, m), p = z(), u = p && p.uLabel, D = s.useCallback( (i) => { var d, f; if (!a) { if (l != null && l.current) { l.current.focus && (i.preventDefault(), l.current.focus()); const t = l.current.actionElement; t && (i.preventDefault(), t.click()); } else if (o) { const t = document.getElementById(o); t && (i.preventDefault(), (d = t.focus) == null || d.call(t), (f = t.click) == null || f.call(t)); } } }, [l, o, a] ), h = s.useMemo( () => E( I.label({ c: u, empty: !n, invalid: c === !1, disabled: a === !0 }), r ), [u, n, c, a, r] ); return /* @__PURE__ */ s.createElement("label", { id: L, htmlFor: o, onClick: D, style: N, className: h }, n, C); }; y.propTypes = { id: e.string, editorId: e.string, editorRef: e.oneOfType([e.func, e.shape({ current: e.any })]), editorValid: e.bool, editorDisabled: e.bool, style: e.object, className: e.string, optional: e.bool }; y.displayName = "KendoReactLabel"; export { y as Label };