UNPKG

@progress/kendo-react-labels

Version:

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

9 lines (8 loc) 1.81 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react"),e=require("prop-types"),r=require("@progress/kendo-react-common"),i=require("./messages/index.js"),C=require("@progress/kendo-react-intl");function D(l){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const o in l)if(o!=="default"){const t=Object.getOwnPropertyDescriptor(l,o);Object.defineProperty(a,o,t.get?t:{enumerable:!0,get:()=>l[o]})}}return a.default=l,Object.freeze(a)}const n=D(v),u=l=>{const{id:a,editorId:o,editorRef:t,editorDisabled:s,children:c,editorValid:d,style:O,className:b,optional:k}=l,L=C.useLocalization(),p=k?L.toLanguageString(i.labelsOptional,i.messages[i.labelsOptional]):"",N=p&&n.createElement("span",{className:"k-label-optional"},p),m=r.useUnstyled(),f=m&&m.uLabel,R=n.useCallback(y=>{if(t&&t.current&&!s){t.current.focus&&(y.preventDefault(),t.current.focus());const g=t.current.actionElement;g&&(y.preventDefault(),g.click())}},[t]),j=n.useMemo(()=>r.classNames(r.uLabel.label({c:f,empty:!c,invalid:d===!1,disabled:s===!0}),b),[f,c,d,s,b]);return n.createElement("label",{id:a,htmlFor:o,onClick:R,style:O,className:j},c,N)};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";exports.Label=u;