2021-04-20 04:37:17 +00:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2021-04-16 08:56:07 +00:00
|
|
|
import DOMPurify from 'dompurify';
|
2021-04-04 13:11:17 +00:00
|
|
|
|
2022-02-14 13:41:39 +00:00
|
|
|
export const Text = function Text({ height, properties, styles, darkMode }) {
|
2021-04-30 06:31:32 +00:00
|
|
|
const [loadingState, setLoadingState] = useState(false);
|
2021-04-04 13:11:17 +00:00
|
|
|
|
2022-05-09 08:05:02 +00:00
|
|
|
const { textSize, textColor, textAlign, visibility, disabledState } = styles;
|
2022-04-26 14:04:39 +00:00
|
|
|
|
|
|
|
|
const text = properties.text === 0 || properties.text === false ? properties.text?.toString() : properties.text;
|
|
|
|
|
|
2022-02-14 13:41:39 +00:00
|
|
|
const color = textColor === '#000' ? (darkMode ? '#fff' : '#000') : textColor;
|
2021-12-14 11:17:11 +00:00
|
|
|
|
2021-04-30 06:31:32 +00:00
|
|
|
useEffect(() => {
|
2021-12-14 11:17:11 +00:00
|
|
|
const loadingStateProperty = properties.loadingState;
|
2022-01-04 05:03:07 +00:00
|
|
|
setLoadingState(loadingStateProperty);
|
2021-09-21 13:48:28 +00:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2021-12-14 11:17:11 +00:00
|
|
|
}, [properties.loadingState]);
|
2021-08-30 11:43:05 +00:00
|
|
|
|
2021-04-30 06:31:32 +00:00
|
|
|
const computedStyles = {
|
|
|
|
|
color,
|
2021-06-22 14:32:22 +00:00
|
|
|
height,
|
2021-12-14 11:17:11 +00:00
|
|
|
display: visibility ? 'flex' : 'none',
|
2021-09-21 13:48:28 +00:00
|
|
|
alignItems: 'center',
|
2022-01-18 05:43:41 +00:00
|
|
|
textAlign,
|
2021-04-30 06:31:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2021-12-14 11:17:11 +00:00
|
|
|
<div data-disabled={disabledState} className="text-widget" style={computedStyles}>
|
2022-01-18 05:43:41 +00:00
|
|
|
{!loadingState && (
|
2022-05-09 08:05:02 +00:00
|
|
|
<div
|
|
|
|
|
style={{ width: '100%', fontSize: textSize }}
|
|
|
|
|
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(text) }}
|
|
|
|
|
/>
|
2022-01-18 05:43:41 +00:00
|
|
|
)}
|
2021-04-30 06:31:32 +00:00
|
|
|
{loadingState === true && (
|
2022-01-04 05:03:07 +00:00
|
|
|
<div style={{ width: '100%' }}>
|
|
|
|
|
<center>
|
|
|
|
|
<div className="spinner-border" role="status"></div>
|
|
|
|
|
</center>
|
2021-04-16 08:56:07 +00:00
|
|
|
</div>
|
2021-04-30 06:31:32 +00:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2021-04-02 04:16:26 +00:00
|
|
|
};
|