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

45 lines
1.3 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, darkMode }) {
2021-04-30 06:31:32 +00:00
const [loadingState, setLoadingState] = useState(false);
const { textSize, textColor, textAlign, visibility, disabledState } = styles;
const text = properties.text === 0 || properties.text === false ? properties.text?.toString() : properties.text;
const color = textColor === '#000' ? (darkMode ? '#fff' : '#000') : textColor;
2021-04-30 06:31:32 +00:00
useEffect(() => {
const loadingStateProperty = properties.loadingState;
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',
textAlign,
2021-04-30 06:31:32 +00:00
};
return (
<div data-disabled={disabledState} className="text-widget" style={computedStyles}>
{!loadingState && (
<div
style={{ width: '100%', fontSize: textSize }}
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(text) }}
/>
)}
2021-04-30 06:31:32 +00:00
{loadingState === true && (
<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>
);
};