blob: 75860f13c34b3bb6116ceecb3d9e9fddba4fc5c3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
import React from 'react';
import styled from 'styled-components';
import { InAppNotificationSubtitle } from '../../shared/notifications';
import { LabelTinySemiBold } from '../lib/components';
import { Link } from '../lib/components/link';
import { formatHtml } from '../lib/html-formatter';
import { ExternalLink } from './ExternalLink';
import { InternalLink } from './InternalLink';
export type NotificationSubtitleProps = {
subtitle?: string | InAppNotificationSubtitle[];
};
const StyledLink = styled(Link)``;
const formatSubtitle = (subtitle: InAppNotificationSubtitle) => {
const content = formatHtml(subtitle.content);
if (subtitle.action) {
switch (subtitle.action.type) {
case 'navigate-internal':
return (
<InternalLink variant="labelTinySemiBold" {...subtitle.action.link}>
<InternalLink.Text>{content}</InternalLink.Text>
</InternalLink>
);
case 'navigate-external':
return (
<ExternalLink variant="labelTinySemiBold" {...subtitle.action.link}>
<ExternalLink.Text>{content}</ExternalLink.Text>
<ExternalLink.Icon icon="external" />
</ExternalLink>
);
case 'run-function':
return (
<StyledLink forwardedAs="button" variant="labelTinySemiBold" {...subtitle.action.button}>
<StyledLink.Text>{content}</StyledLink.Text>
</StyledLink>
);
default:
break;
}
}
return content;
};
export const NotificationSubtitle = ({ subtitle, ...props }: NotificationSubtitleProps) => {
if (!subtitle) {
return null;
}
if (!Array.isArray(subtitle)) {
return (
<LabelTinySemiBold color="whiteAlpha60" {...props}>
{formatHtml(subtitle)}
</LabelTinySemiBold>
);
}
return (
<LabelTinySemiBold color="whiteAlpha60" {...props}>
{subtitle.map((subtitle, index, arr) => {
const content = formatSubtitle(subtitle);
return (
<React.Fragment key={subtitle.content}>
{content}
{index !== arr.length - 1 && ' '}
</React.Fragment>
);
})}
</LabelTinySemiBold>
);
};
|