-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(treeshaking): added treeshaking for multiple child component
- Loading branch information
Showing
14 changed files
with
197 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
1. PhoneBook | ||
2. Share | ||
01. AutoFillOtp | ||
02. Bluetooth | ||
03. CopyToClipboard | ||
04. LiveLocationTracking | ||
05. LocateMe | ||
06. MobileNavBar | ||
07. PhoneBook | ||
08. Scanner | ||
09. Share | ||
10. TextToSpeech | ||
11. VoiceRecognition |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import Start from './StartTextToSpeech'; | ||
import Stop from './StopTextToSpeech'; | ||
import Init from './InitTextToSpeech'; | ||
import TextToSpeechStart from './TextToSpeechStart'; | ||
import TextToSpeechStop from './TextToSpeechStop'; | ||
import TextToSpeechInit from './TextToSpeechInit'; | ||
|
||
export default { | ||
Start, | ||
Stop, | ||
Init, | ||
export { | ||
TextToSpeechStart, | ||
TextToSpeechStop, | ||
TextToSpeechInit, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
|
||
function TextToSpeechStart({ children, handlePlay, isAudioOn }) { | ||
return !isAudioOn && React.Children.map(children || 'Start', (child) => React.cloneElement(typeof child === 'string' ? <span>{child}</span> : child, { | ||
onClick: handlePlay, | ||
type: 'ttsStart', | ||
})); | ||
} | ||
|
||
export default TextToSpeechStart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
|
||
function TextToSpeechStop({ children, handleStop, isAudioOn }) { | ||
return isAudioOn && React.Children.map(children || 'Stop', (child) => React.cloneElement(typeof child === 'string' ? <span>{child}</span> : child, { | ||
onClick: handleStop, | ||
type: 'ttsStop', | ||
})); | ||
} | ||
|
||
export default TextToSpeechStop; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import VoiceRecognition from './VoiceRecognitionInit'; | ||
import VoiceRecognitionIcon from './VoiceRecognitionIcon'; | ||
import VoiceRecognitionModal from './VoiceRecognitionModal'; | ||
|
||
export { | ||
VoiceRecognition, | ||
VoiceRecognitionIcon, | ||
VoiceRecognitionModal, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
|
||
function VoiceRecognitionIcon({ children, onClick }) { | ||
return React.Children.map(children || 'Voice Recognition', (child) => React.cloneElement(typeof child === 'string' ? <span>{child}</span> : child, { | ||
onClick, | ||
})); | ||
} | ||
|
||
export default VoiceRecognitionIcon; |
111 changes: 111 additions & 0 deletions
111
__app/component/VoiceRecognition/VoiceRecognitionInit.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Wrapper from '../Wrapper/Wrapper'; | ||
// import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
|
||
// import './voiceSearch.css'; | ||
// import Modal from '../../components/Modal/Modal'; | ||
// import VoiceLoader from './VoiceLoader'; | ||
// import LoadingDots from '../../components/LoadingDots/LoadingDots'; | ||
|
||
function VoiceRecognition({ | ||
disbaleToast, | ||
successCb, | ||
successMsg, | ||
failureCb, | ||
failureMsg, | ||
cb, | ||
children, | ||
}) { | ||
const [modalVisible, setModalVisible] = useState(false); | ||
const [voiceText, setVoiceText] = useState(''); | ||
const [isLoadingDots, setIsLoadingDots] = useState(true); | ||
|
||
const listen = () => { | ||
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition; | ||
const recognition = new SpeechRecognition(); | ||
|
||
recognition.continuous = false; | ||
recognition.lang = 'en-US'; | ||
recognition.interimResults = true; | ||
recognition.maxAlternatives = 1; | ||
recognition.onresult = (event) => { | ||
const text = event.results[0][0].transcript; | ||
setVoiceText(text); | ||
if (event.results[0].isFinal) { | ||
setTimeout(() => { | ||
cb(text, true); | ||
setModalVisible(false); | ||
setVoiceText(''); | ||
}, 1500); | ||
} | ||
}; | ||
recognition.start(); | ||
recognition.onsoundstart = () => { | ||
setIsLoadingDots(false); | ||
}; | ||
recognition.onsoundend = () => { | ||
setIsLoadingDots(true); | ||
}; | ||
recognition.onerror = () => { | ||
setModalVisible(false); | ||
}; | ||
recognition.onend = () => { | ||
recognition.abort(); | ||
recognition.onresult = () => {}; | ||
recognition.stop(); | ||
setTimeout(() => setModalVisible(false), 1500); | ||
}; | ||
setModalVisible(true); | ||
}; | ||
|
||
return React.Children.map(children, (child) => React.cloneElement(child, { | ||
onClick: child.type.name === 'VoiceRecognitionIcon' ? listen : () => {}, | ||
disbaleToast, | ||
successCb, | ||
successMsg, | ||
failureCb, | ||
failureMsg, | ||
})); | ||
} | ||
|
||
VoiceRecognition.isBrowserSupport = () => globalThis.speechSynthesis | ||
&& globalThis.speechSynthesis?.cancel | ||
&& globalThis.speechSynthesis?.speak | ||
&& true; | ||
|
||
VoiceRecognition.propTypes = { | ||
disbaleToast: PropTypes.bool, | ||
successCb: PropTypes.func, | ||
failureCb: PropTypes.func, | ||
successMsg: PropTypes.string, | ||
failureMsg: PropTypes.object, | ||
}; | ||
|
||
VoiceRecognition.defaultProps = { | ||
disbaleToast: false, | ||
successCb: () => {}, | ||
failureCb: () => {}, | ||
successMsg: '', | ||
failureMsg: { | ||
unSupported: '', | ||
error: '', | ||
}, | ||
}; | ||
|
||
export default Wrapper(VoiceRecognition); | ||
|
||
// { | ||
// <FontAwesomeIcon icon="fa-solid fa-microphone" | ||
// size="xl" style={{ color: 'var(--secondary)' }} className="voiceIcon" onClick={listen} /> | ||
|
||
// modalVisible ? ( | ||
// <Modal modalTitle="Listening..." onClickCloseIcon={() => | ||
// setModalVisible(false)} titleClasses="listen" modalClass="voice-modal"> | ||
// <div className="voice-text">{voiceText}</div> | ||
// <div className="loading-container"> | ||
// {isLoadingDots ? <LoadingDots /> : <VoiceLoader />} | ||
// </div> | ||
// </Modal> | ||
// ) : null | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react'; | ||
|
||
export default function VoiceRecognitionModal() { | ||
return ( | ||
<div>VoiceRecognitionModal</div> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters