ToolJet/frontend/src/Editor/Components/Text.jsx

37 lines
1 KiB
React
Raw Normal View History

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';
export const Text = function Text({ height, properties, styles }) {
2021-04-30 06:31:32 +00:00
const [loadingState, setLoadingState] = useState(false);
const { textColor, visibility, disabledState } = styles;
const text = properties.text ?? '';
const color = textColor;
2021-04-30 06:31:32 +00:00
useEffect(() => {
const loadingStateProperty = properties.loadingState;
if (loadingStateProperty) {
setLoadingState(loadingStateProperty);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [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,
display: visibility ? 'flex' : 'none',
alignItems: 'center',
2021-04-30 06:31:32 +00:00
};
return (
<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>
);
};