-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support to send alert message with details (#887)
* misc: use notification panel from local project * misc: support to show details in alert * feat: new style alert message * misc: update customized alert icon
- Loading branch information
Showing
11 changed files
with
567 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import React from 'react'; | ||
import { | ||
styled, | ||
RcTypography, | ||
RcLink, | ||
RcIcon, | ||
palette2, | ||
} from '@ringcentral/juno'; | ||
import { | ||
ReportAnIssue, | ||
InfoBorder, | ||
Check, | ||
} from '@ringcentral/juno-icon'; | ||
|
||
const Container = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
`; | ||
|
||
const StyledIcon = styled(RcIcon)` | ||
margin-right: 6px; | ||
vertical-align: middle; | ||
display: inline-block; | ||
`; | ||
|
||
const DetailContainer = styled.div` | ||
margin-top: 4px; | ||
`; | ||
|
||
const DetailTitle = styled(RcTypography)` | ||
margin: 4px 0; | ||
`; | ||
|
||
const ItemText = styled(RcTypography)` | ||
margin-bottom: 4px; | ||
`; | ||
|
||
function Detail({ title, items, onLinkClick }) { | ||
return ( | ||
<DetailContainer> | ||
<DetailTitle variant="body2"> | ||
{title} | ||
</DetailTitle> | ||
{ | ||
items.map((item, idx) => { | ||
if (item.type === 'text' && item.text) { | ||
return ( | ||
<ItemText key={idx} variant="body1"> | ||
{item.text} | ||
</ItemText> | ||
) | ||
} | ||
if (item.type === 'link' && item.text) { | ||
return ( | ||
<ItemText key={idx}> | ||
<RcLink | ||
href={item.href} | ||
onClick={() => onLinkClick(item.id)} | ||
target="_blank" | ||
> | ||
{item.text} | ||
</RcLink> | ||
</ItemText> | ||
); | ||
} | ||
return null; | ||
}) | ||
} | ||
</DetailContainer> | ||
); | ||
} | ||
|
||
const StyleMessage = styled(RcTypography)` | ||
font-size: 1rem; | ||
line-height: 1.5rem; | ||
`; | ||
|
||
export function CustomizedAlert({ | ||
message, | ||
showMore = false, | ||
onLinkClick, | ||
}) { | ||
const { payload, level } = message; | ||
let icon = InfoBorder; | ||
let iconColor; | ||
if (level === 'danger') { | ||
icon = ReportAnIssue; | ||
iconColor = 'danger.f02'; | ||
} else if (level === 'success') { | ||
icon = Check; | ||
iconColor = 'success.f02'; | ||
} | ||
return ( | ||
<Container> | ||
<StyleMessage> | ||
<StyledIcon | ||
symbol={icon} | ||
size="small" | ||
color={iconColor} | ||
/> | ||
{payload && payload.alertMessage} | ||
</StyleMessage> | ||
{showMore && payload.details && payload.details.length > 0 && ( | ||
payload.details.map((detail, idx) => ( | ||
<Detail | ||
key={idx} | ||
title={detail.title} | ||
items={detail.items} | ||
onLinkClick={onLinkClick} | ||
/> | ||
)) | ||
)} | ||
</Container> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.