Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

142179 - Refactor Alert and Heading #922

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions components/Forms/ContextualAlert.tsx
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>
)
}
16 changes: 6 additions & 10 deletions components/Forms/ErrorsSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { useTranslation } from '../Hooks'
import { WebTranslations } from '../../i18n/web'
import {
ContextualAlert as Message,
Link as DSLink,
} from '@dts-stn/service-canada-design-system'
import { Link as DSLink } from '@dts-stn/service-canada-design-system'
import { ContextualAlert as Message } from './ContextualAlert'
import { Language } from '../../utils/api/definitions/enums'

export const ErrorsSummary: any = ({ errorFields }) => {
Expand Down Expand Up @@ -43,12 +41,10 @@ export const ErrorsSummary: any = ({ errorFields }) => {
<Message
id={`form-errors-${errorFields.length}`}
type="danger"
message_heading={
tsln.errorBoxTitle + errorFields.length + titleTranslation
}
message_body={messageBody}
alert_icon_id="form-errors"
alert_icon_alt_text={tsln.warningText}
heading={tsln.errorBoxTitle + errorFields.length + titleTranslation}
body={messageBody}
iconId="form-errors"
iconAltText={tsln.warningText}
/>
</div>
)
Expand Down
24 changes: 9 additions & 15 deletions components/Layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
Heading,
ContextualAlert as Message,
} from '@dts-stn/service-canada-design-system'
import { ContextualAlert as Message } from '../Forms/ContextualAlert'
import { useRouter } from 'next/router'
import React from 'react'
import { WebTranslations } from '../../i18n/web'
Expand Down Expand Up @@ -132,21 +129,18 @@ export const Layout: React.VFC<{
logoAltText: tsln.logoAltText,
}}
/>
<Heading
id="applicationTitle"
title={title}
className="mb-8 mt-4 sm:mt-12 sm:w-[100%]"
/>
<h1 id="applicationTitle" className="h1 my-8">
shawn320 marked this conversation as resolved.
Show resolved Hide resolved
{title}
</h1>
<div className="mb-6">
<Message
id={'wip'}
alert_icon_id={'testkey'}
alert_icon_alt_text={tsln.warningText}
iconId={'testkey'}
iconAltText={tsln.warningText}
type={'info'}
message_heading={tsln.workInProgress}
message_body={tsln.workInProgressBody}
whiteBG={true}
asHtml={true}
heading={tsln.workInProgress}
body={tsln.workInProgressBody}
asHtml
/>
</div>
{children}
Expand Down
17 changes: 7 additions & 10 deletions components/QuestionsPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
AccordionForm,
ContextualAlert as Message,
} from '@dts-stn/service-canada-design-system'
import { AccordionForm } from '@dts-stn/service-canada-design-system'
import { ContextualAlert as Message } from '../Forms/ContextualAlert'
import { debounce } from 'lodash'
import { useRouter } from 'next/router'
import React, { useEffect, useState } from 'react'
Expand Down Expand Up @@ -274,13 +272,12 @@ export const QuestionsPage: React.VFC = ({}) => {
<div className="mt-6 md:pr-12 msg-container border-warning">
<Message
id={field.key}
alert_icon_id={field.key}
alert_icon_alt_text={tsln.warningText}
iconId={field.key}
iconAltText={tsln.warningText}
type={'warning'}
message_heading={tsln.unableToProceed}
message_body={field.error}
asHtml={true}
whiteBG={true}
heading={tsln.unableToProceed}
body={field.error}
asHtml
/>
</div>
)}
Expand Down
3 changes: 3 additions & 0 deletions public/danger_img.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/info_img.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/success_img.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/warning_img.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@

/* typography gc overrides */
.h1 {
@apply text-h1 font-bold mb-[15px] font-header-gc border-b border-header-rule text-content;
@apply text-h1 font-bold mb-[15px] font-header-gc border-b border-header-rule text-content pb-2;
}

.h2 {
Expand Down