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

40 lines
1.1 KiB
React
Raw Normal View History

import React from 'react';
import { resolve_references } from '@/_helpers/utils';
2021-04-16 08:56:07 +00:00
import DOMPurify from 'dompurify';
export const Text = function Text({ id, width, height, component, onComponentClick, currentState }) {
const text = component.definition.properties.text.value;
const color = component.definition.styles.textColor.value;
let data = text;
if(currentState) {
const matchedParams = text.match(/\{\{(.*?)\}\}/g);
2021-04-06 03:15:10 +00:00
if (matchedParams) {
for(const param of matchedParams) {
const resolvedParam = resolve_references(param, currentState, '');
2021-04-06 03:15:10 +00:00
console.log('resolved param', param, resolvedParam);
data = data.replace(param, resolvedParam);
}
}
}
2021-04-16 08:56:07 +00:00
const computedStyles = {
color,
width,
height,
}
return (
2021-04-16 08:56:07 +00:00
<div style={computedStyles} onClick={() => onComponentClick(id, component) }>
<div
dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(data)}}
/>
</div>
);
};