mirror of
https://github.com/The-Low-Code-Foundation/OpenNoodl.git
synced 2026-01-11 14:52:55 +01:00
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import React from 'react';
|
|
|
|
import Layout from '../../../layout';
|
|
import PointerListeners from '../../../pointerlisteners';
|
|
import { Noodl } from '../../../types';
|
|
|
|
export interface TextProps extends Noodl.ReactProps {
|
|
as?: keyof React.JSX.IntrinsicElements | React.ComponentType<unknown>;
|
|
|
|
textStyle: Noodl.TextStyle;
|
|
text: string;
|
|
|
|
sizeMode?: Noodl.SizeMode;
|
|
width?: string;
|
|
height?: string;
|
|
fixedWidth?: boolean;
|
|
fixedHeight?: boolean;
|
|
|
|
// Extra Attributes
|
|
dom: Record<string, unknown>;
|
|
}
|
|
|
|
export function Text(props: TextProps) {
|
|
const Component = props.as || 'div';
|
|
|
|
const style = {
|
|
...props.textStyle,
|
|
...props.style
|
|
};
|
|
|
|
Layout.size(style, props);
|
|
Layout.align(style, props);
|
|
|
|
style.color = props.noodlNode.context.styles.resolveColor(style.color);
|
|
|
|
// Respect '\n' in the string
|
|
if (props.sizeMode === 'contentSize' || props.sizeMode === 'contentWidth') {
|
|
style.whiteSpace = 'pre';
|
|
} else {
|
|
style.whiteSpace = 'pre-wrap';
|
|
style.overflowWrap = 'anywhere';
|
|
}
|
|
|
|
if (style.opacity === 0) {
|
|
style.pointerEvents = 'none';
|
|
}
|
|
|
|
return (
|
|
<Component
|
|
className={['ndl-visual-text', props.className].join(' ')}
|
|
{...props.dom}
|
|
{...PointerListeners(props)}
|
|
style={style}
|
|
>
|
|
{String(props.text)}
|
|
</Component>
|
|
);
|
|
}
|