11import { hooks } from 'botframework-webchat-api' ;
2+ import { validateProps } from 'botframework-webchat-api/internal' ;
23import classNames from 'classnames' ;
3- import PropTypes from 'prop-types ' ;
4- import React from 'react ' ;
4+ import React , { memo } from 'react ' ;
5+ import { boolean , object , optional , pipe , readonly , type InferInput } from 'valibot ' ;
56
6- import useStyleSet from '../hooks/useStyleSet' ;
77import { useStyleToEmotionObject } from '../hooks/internal/styleToEmotionObject' ;
8+ import useStyleSet from '../hooks/useStyleSet' ;
89
910const { useAvatarForBot, useAvatarForUser } = hooks ;
1011
@@ -17,7 +18,18 @@ const ROOT_STYLE = {
1718 }
1819} ;
1920
20- const InitialsAvatar = ( { fromUser } ) => {
21+ const initialsAvatarPropsSchema = pipe (
22+ object ( {
23+ fromUser : optional ( boolean ( ) )
24+ } ) ,
25+ readonly ( )
26+ ) ;
27+
28+ type InitialsAvatarProps = InferInput < typeof initialsAvatarPropsSchema > ;
29+
30+ function InitialsAvatar ( props : InitialsAvatarProps ) {
31+ const { fromUser = false } = validateProps ( initialsAvatarPropsSchema , props ) ;
32+
2133 const [ { initials : avatarInitialsForBot } ] = useAvatarForBot ( ) ;
2234 const [ { initials : avatarInitialsForUser } ] = useAvatarForUser ( ) ;
2335 const [ { initialsAvatar : initialsAvatarStyleSet } ] = useStyleSet ( ) ;
@@ -37,14 +49,7 @@ const InitialsAvatar = ({ fromUser }) => {
3749 < div className = "webchat__initialsAvatar__initials" > { fromUser ? avatarInitialsForUser : avatarInitialsForBot } </ div >
3850 </ div >
3951 ) ;
40- } ;
41-
42- InitialsAvatar . defaultProps = {
43- fromUser : false
44- } ;
45-
46- InitialsAvatar . propTypes = {
47- fromUser : PropTypes . bool
48- } ;
52+ }
4953
50- export default InitialsAvatar ;
54+ export default memo ( InitialsAvatar ) ;
55+ export { initialsAvatarPropsSchema , type InitialsAvatarProps } ;
0 commit comments