generated from DTS-STN/next-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #922 from DTS-STN/alert
142179 - Refactor Alert and Heading
- Loading branch information
Showing
10 changed files
with
121 additions
and
36 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,85 @@ | ||
/* eslint-disable @next/next/no-img-element */ | ||
|
||
interface ContextualAlertProps { | ||
id: string | ||
heading: string | ||
body: Body | ||
type: AlertType | ||
iconId: string | ||
iconAltText: string | ||
asHtml?: boolean | ||
} | ||
|
||
type AlertType = 'warning' | 'info' | 'success' | 'danger' | ||
type Body = string | React.ReactElement | React.ReactElement[] | ||
|
||
const ALERT_MAPPINGS = { | ||
warning: { | ||
img: '/warning_img.svg', | ||
color: '#EE7100', | ||
}, | ||
danger: { | ||
img: '/danger_img.svg', | ||
color: '#BC3331', | ||
}, | ||
info: { | ||
img: '/info_img.svg', | ||
color: '#269ABC', | ||
}, | ||
success: { | ||
img: '/success_img.svg', | ||
color: '#278400', | ||
}, | ||
} | ||
|
||
export const ContextualAlert: React.FC<ContextualAlertProps> = ({ | ||
id, | ||
heading, | ||
body, | ||
type, | ||
iconId, | ||
iconAltText, | ||
asHtml, | ||
}) => { | ||
const alertType = ALERT_MAPPINGS[type].img | ||
const alertColor = ALERT_MAPPINGS[type].color | ||
|
||
const headingClass = | ||
'font-header-gc font-[700] text-[24px] leading-[26px] text-[#333333]' | ||
const bodyClass = | ||
'font-sans font-[400] text-[20px] leading-[33px] text-[#333333] pt-2' | ||
|
||
return ( | ||
<div id={id} className="relative min-w-290px ml-[24px]"> | ||
<div className="absolute top-3.5 -left-2.5 bg-white py-1"> | ||
<img | ||
id={iconId} | ||
src={alertType} | ||
alt={iconAltText} | ||
className="h-6 w-6" | ||
/> | ||
</div> | ||
<div | ||
style={{ borderColor: alertColor }} | ||
className={`overflow-auto border-l-4 pl-[24px] py-[16px] leading-8`} | ||
> | ||
{asHtml ? ( | ||
<p | ||
className={headingClass} | ||
dangerouslySetInnerHTML={{ __html: heading }} | ||
/> | ||
) : ( | ||
<p className={headingClass}>{heading}</p> | ||
)} | ||
{asHtml && typeof body === 'string' ? ( | ||
<div | ||
className={bodyClass} | ||
dangerouslySetInnerHTML={{ __html: body }} | ||
/> | ||
) : ( | ||
<div className={bodyClass}>{body}</div> | ||
)} | ||
</div> | ||
</div> | ||
) | ||
} |
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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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