Skip to content

Commit

Permalink
[NEW] Emphasis Elements (italic, strike and bold) in Message Parser C…
Browse files Browse the repository at this point in the history
…omponents (#27003)
  • Loading branch information
hugocostadev authored Nov 18, 2022
1 parent 5c4c331 commit 19d1dc3
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions packages/gazzodown/src/elements/LinkSpan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,29 @@ type LinkSpanProps = {

const LinkSpan = ({ href, label }: LinkSpanProps): ReactElement => {
const children = useMemo(() => {
switch (label.type) {
case 'PLAIN_TEXT':
return <PlainSpan text={label.value} />;
const labelArray = Array.isArray(label) ? label : [label];

case 'STRIKE':
return <StrikeSpan children={label.value} />;
const labelElements = labelArray.map((child, index) => {
switch (child.type) {
case 'PLAIN_TEXT':
return <PlainSpan key={index} text={child.value} />;

case 'ITALIC':
return <ItalicSpan children={label.value} />;
case 'STRIKE':
return <StrikeSpan key={index} children={child.value} />;

case 'BOLD':
return <BoldSpan children={label.value} />;
case 'ITALIC':
return <ItalicSpan key={index} children={child.value} />;

default:
return null;
}
}, [label.type, label.value]);
case 'BOLD':
return <BoldSpan key={index} children={child.value} />;

default:
return null;
}
});

return labelElements;
}, [label]);

if (isExternal(href)) {
return (
Expand Down

0 comments on commit 19d1dc3

Please sign in to comment.