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
|
|
|
|
2021-12-14 11:17:11 +00:00
|
|
|
export const Text = function Text({ height, properties, styles }) {
|
2021-04-30 06:31:32 +00:00
|
|
|
const [loadingState, setLoadingState] = useState(false);
|
2021-04-04 13:11:17 +00:00
|
|
|
|
2021-12-14 11:17:11 +00:00
|
|
|
const { textColor, visibility, disabledState } = styles;
|
|
|
|
|
const text = properties.text ?? '';
|
|
|
|
|
const color = textColor;
|
|
|
|
|
|
2021-04-30 06:31:32 +00:00
|
|
|
useEffect(() => {
|
2021-12-14 11:17:11 +00:00
|
|
|
const loadingStateProperty = properties.loadingState;
|
|
|
|
|
if (loadingStateProperty) {
|
|
|
|
|
setLoadingState(loadingStateProperty);
|
2021-04-04 13:11:17 +00:00
|
|
|
}
|
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',
|
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}>
|
|
|
|
|
{!loadingState && <div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(text) }} />}
|
2021-04-30 06:31:32 +00:00
|
|
|
{loadingState === true && (
|
|
|
|
|
<div>
|
2021-07-03 18:07:51 +00:00
|
|
|
<div className="skeleton-line w-10"></div>
|
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
|
|
|
};
|