UNPKG

@progress/kendo-react-labels

Version:

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

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