diff options
| author | Oliver <oliver@mohlin.dev> | 2025-03-14 15:34:36 +0100 |
|---|---|---|
| committer | Markus Pettersson <markus.pettersson@mullvad.net> | 2025-03-19 15:06:37 +0100 |
| commit | 5463e9647404d880bd4527b54028893ebf7e5106 (patch) | |
| tree | d4a5ae68f234318125f48fd9091a07c384e9610f | |
| parent | 57878dba214e6ec7a079ee25c2ae5d4682513ea8 (diff) | |
| download | mullvadvpn-5463e9647404d880bd4527b54028893ebf7e5106.tar.xz mullvadvpn-5463e9647404d880bd4527b54028893ebf7e5106.zip | |
Add NotificationSubtitle
| -rw-r--r-- | desktop/packages/mullvad-vpn/src/renderer/components/NotificationSubtitle.tsx | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/NotificationSubtitle.tsx b/desktop/packages/mullvad-vpn/src/renderer/components/NotificationSubtitle.tsx new file mode 100644 index 0000000000..fc5a4600d1 --- /dev/null +++ b/desktop/packages/mullvad-vpn/src/renderer/components/NotificationSubtitle.tsx @@ -0,0 +1,71 @@ +import React from 'react'; +import styled from 'styled-components'; + +import { InAppNotificationSubtitle } from '../../shared/notifications'; +import { Icon, LabelTiny } from '../lib/components'; +import { Colors } from '../lib/foundations'; +import { formatHtml } from '../lib/html-formatter'; +import { ExternalLink } from './ExternalLink'; +import { InternalLink } from './InternalLink'; + +export type NotificationSubtitleProps = { + subtitle?: string | InAppNotificationSubtitle[]; +}; + +const StyledIcon = styled(Icon)` + display: inline-flex; + vertical-align: middle; +`; + +const formatSubtitle = (subtitle: InAppNotificationSubtitle) => { + const content = formatHtml(subtitle.content); + if (subtitle.action) { + switch (subtitle.action.type) { + case 'navigate-internal': + return ( + <InternalLink variant="labelTiny" {...subtitle.action.link}> + {content} + </InternalLink> + ); + case 'navigate-external': + return ( + <ExternalLink variant="labelTiny" {...subtitle.action.link}> + {content} + <StyledIcon icon="external" size="small" /> + </ExternalLink> + ); + default: + break; + } + } + return content; +}; + +export const NotificationSubtitle = ({ subtitle, ...props }: NotificationSubtitleProps) => { + if (!subtitle) { + return null; + } + + if (!Array.isArray(subtitle)) { + return ( + <LabelTiny color={Colors.white60} {...props}> + {formatHtml(subtitle)} + </LabelTiny> + ); + } + + return ( + <LabelTiny color={Colors.white60} {...props}> + {subtitle.map((subtitle, index, arr) => { + const content = formatSubtitle(subtitle); + + return ( + <React.Fragment key={subtitle.content}> + {content} + {index !== arr.length - 1 && ' '} + </React.Fragment> + ); + })} + </LabelTiny> + ); +}; |
