UNPKG

@progress/kendo-react-buttons

Version:

All you need in React Button in one package: disabled/enabled states, built-in styles and more. KendoReact Buttons package

9 lines (8 loc) 3.16 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 e=require("react"),ee=require("@progress/kendo-webspeech-common"),te=require("../Button.js"),u=require("@progress/kendo-react-common"),M=require("@progress/kendo-svg-icons"),a=require("../messages/index.js"),ne=require("@progress/kendo-react-intl"),I=require("../package-metadata.js"),y=e.forwardRef((r,A)=>{const q=!u.validatePackage(I.packageMetadata,{component:"SpeechToTextButton"}),B=u.getLicenseMessage(I.packageMetadata),h=ne.useLocalization(),{fillMode:E="solid",rounded:L="medium",size:z="medium",themeColor:H="base",ariaLabel:d,svgIcon:S,disabled:N,iconSize:O="medium",title:f,className:F,id:P,style:W,lang:k="en-US",continuous:b=!1,interimResults:v=!1,maxAlternatives:T=1,integrationMode:K="webSpeech",onStart:g,onResult:i,onEnd:m,onError:s,...j}=r,o=e.useRef(null),n=e.useRef(!1),[c,l]=e.useState(!1),U=e.useCallback(async()=>{n.current=!0,l(!0),g&&await g()},[g]),D=e.useCallback(async()=>{n.current=!1,l(!1),m&&await m()},[m]),G=e.useCallback(t=>{const w=t.results,C=w[w.length-1],$=Array.from(C).map(x=>({transcript:x.transcript,confidence:x.confidence}));i==null||i({isFinal:C.isFinal,alternatives:$})},[i]),J=e.useCallback(t=>{l(!1),n.current=!1,s==null||s({errorMessage:t.error})},[s]),Q=()=>{var t;if(typeof window!="undefined"&&!("webkitSpeechRecognition"in window||"SpeechRecognition"in window)){s&&s({errorMessage:"Speech Recognition API is not supported in this browser."});return}(t=o.current)!=null&&t.isActive()&&o.current.stop(),o.current=new ee.KendoSpeechRecognition({lang:k,continuous:b,interimResults:v,maxAlternatives:T,events:{start:U,end:D,result:G,error:J}})},R=e.useCallback(()=>{var t;n.current||(t=o.current)==null||t.start()},[]),p=e.useCallback(()=>{var t;n.current&&((t=o.current)==null||t.stop())},[]),V=e.useCallback(()=>{var t;n.current&&((t=o.current)==null||t.abort(),n.current=!1,l(!1))},[]),X=()=>n.current;e.useImperativeHandle(A,()=>({start:R,stop:p,abort:V,isActive:X})),e.useEffect(()=>(Q(),()=>{n.current&&p()}),[k,b,v,T,K]);const Y=()=>{c?p():R()},Z=r.icon!==void 0||r.iconClass!==void 0,_=e.useMemo(()=>c?M.stopSmIcon:S||M.microphoneOutlineIcon,[c,S]);return e.createElement(e.Fragment,null,e.createElement(te.Button,{id:P,className:u.classNames({"k-speech-to-text-button":!0,"k-listening":c},F),style:W,svgIcon:Z?void 0:_,iconSize:O,fillMode:E,rounded:L,size:z,themeColor:H,"aria-label":d!=null?d:h.toLanguageString(a.speechToTextAriaLabel,a.messages[a.speechToTextAriaLabel]),"aria-pressed":c,disabled:N,title:f!=null?f:h.toLanguageString(a.speechToTextTitle,a.messages[a.speechToTextTitle]),onClick:Y,...j},r.children),q&&e.createElement(u.WatermarkOverlay,{message:B}))});y.displayName="KendoSpeechToTextButton";exports.SpeechToTextButton=y;