11import * as React from 'react' ;
22import cx from 'classnames' ;
3- import { IHasCX , IHasRawProps } from '@epam/uui-core' ;
3+ import { IHasCX , IHasRawProps , isFontAvailable } from '@epam/uui-core' ;
44import css from './TextPlaceholder.module.scss' ;
55import { PropsWithChildren } from 'react' ;
66
@@ -14,7 +14,9 @@ export interface ITextPlaceholderProps extends IHasRawProps<React.HTMLAttributes
1414export type TextPlaceholderProps = PropsWithChildren < ITextPlaceholderProps > ;
1515
1616export const TextPlaceholder : React . FunctionComponent < PropsWithChildren < ITextPlaceholderProps > > = ( props ) => {
17- const pattern = ' ' ;
17+ const [ isFontFailed , setIsFontFailed ] = React . useState ( false ) ;
18+
19+ const pattern = 'x' ;
1820 const text = React . useMemo ( ( ) => {
1921 const words = [ ] ;
2022 for ( let i = 0 ; i < ( props . wordsCount || 1 ) ; i ++ ) {
@@ -24,16 +26,21 @@ export const TextPlaceholder: React.FunctionComponent<PropsWithChildren<ITextPla
2426 return words ;
2527 } , [ props . wordsCount ] ) ;
2628
29+ React . useEffect ( ( ) => {
30+ isFontAvailable ( '1em Redacted' ) . then ( ( isAvailable ) => setIsFontFailed ( ! isAvailable ) ) ;
31+ } , [ ] ) ;
32+
2733 return (
28- < div aria-busy = { true } className = { cx ( css . root , 'uui-text-placeholder' ) } { ...props . rawProps } >
34+ < div aria-busy = { true } aria-hidden = "true" className = { cx ( css . root , 'uui-text-placeholder' ) } { ...props . rawProps } >
2935 { text . map ( ( it : string , index : number ) => (
3036 < span
3137 key = { index }
3238 className = { cx ( [
33- props . cx , css . loadingWord , ! props . isNotAnimated && css . animatedLoading ,
39+ props . cx , css . loadingWord , ! props . isNotAnimated && css . animatedLoading , isFontFailed && css . fontFailed ,
3440 ] ) }
35- dangerouslySetInnerHTML = { { __html : it } }
36- />
41+ >
42+ { it }
43+ </ span >
3744 ) ) }
3845 </ div >
3946 ) ;
0 commit comments