| undefined) => {
const underLine = style?.underline ? 'underline' : 'none';
return style?.strikethrough ? 'line-through' : underLine;
}, []);
const getFontStyle = (style: RichTextContentStringStyle) =>
style?.italics ? 'italic' : 'normal';
const handleEnter = useCallback(
(e: React.KeyboardEvent) => {
if (e.key === 'Enter') {
e.preventDefault();
const responseStrings = handleInputChange();
if (handleSubmit) {
handleSubmit({
id: segmentId,
order: 1,
variant: 'input',
type: RichTextContentSegmentTypeEnum.Paragraph,
strings: responseStrings as RichTextContentSegmentString[],
});
}
}
},
[localStrings]
);
return (
{strings.map(({ id, style, value, onNewLine }) => {
if (value === LineBreak.space) {
return (
);
} else {
return (
<>
{value}
>
);
}
})}
);
};
type RichTextContentSegmentProps = RichTextContentSegment & {
variant: 'input' | 'blur';
};
export type RichTextContentProps = {
/**
* content contains the rich text content which is holding the segments array
*/
richTextContent: RichTextContentSegment;
setRichTextContent: ({ id, strings, type, order, variant }: RichTextContentSegmentProps) => void;
placeholder: string;
handleSubmit?: ({ id, strings, type, order, variant }: RichTextContentSegmentProps) => void;
segmentStyle?: LocalSegmentStyleProps;
};
interface SelectedTextProps {
start: HTMLElement;
end: HTMLElement;
}
interface LocalSegmentStyleProps {
isBold: boolean;
isItalic: boolean;
isCode: boolean;
isUnderLine: boolean;
isStrikeThrough: boolean;
}