Skip to content

Commit ed96303

Browse files
Merge pull request #1697 from navikt/in-kontekst-varsel
Varsel i kontekst
2 parents ca7ab80 + 472c8b6 commit ed96303

File tree

10 files changed

+85
-5
lines changed

10 files changed

+85
-5
lines changed

src/components/ContentMapper.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { FormsOverviewPage } from 'components/pages/forms-overview-page/FormsOve
2929
import { VideoPage } from './pages/video-page/VideoPage';
3030
import { CalculatorPage } from './pages/calculator-page/CalculatorPage';
3131
import { UserTestsConfigPreviewPage } from 'components/pages/user-tests-config-preview-page/UserTestsConfigPreviewPage';
32+
import { AlertInContextPage } from './pages/alert-in-context-page/AlertInContextPage';
3233

3334
const contentToReactComponent: {
3435
[key in ContentType]?: React.FunctionComponent<ContentProps<key>>;
@@ -59,6 +60,7 @@ const contentToReactComponent: {
5960
[ContentType.FormsOverview]: FormsOverviewPage,
6061
[ContentType.Calculator]: CalculatorPage,
6162
[ContentType.UserTestsConfig]: UserTestsConfigPreviewPage,
63+
[ContentType.AlertInContext]: AlertInContextPage,
6264

6365
[ContentType.AreaPage]: DynamicPage,
6466
[ContentType.FrontPage]: DynamicPage,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.alertInContext {
2+
margin: 0 0 1rem 0;
3+
border: 0;
4+
padding-top: var(--a-spacing-3);
5+
padding-bottom: var(--a-spacing-3);
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import { AlertData } from 'types/content-props/alerts';
3+
import { AlertBox } from '../alert-box/AlertBox';
4+
5+
import style from './AlertInContext.module.scss';
6+
7+
type Props = {
8+
alert: AlertData;
9+
};
10+
11+
export const AlertInContext = ({ alert }: Props) => {
12+
if (!alert) {
13+
return null;
14+
}
15+
16+
const variant = alert.data.type === 'critical' ? 'warning' : 'info';
17+
18+
return (
19+
<AlertBox className={style.alertInContext} variant={variant}>
20+
{alert.data.text}
21+
</AlertBox>
22+
);
23+
};

src/components/_common/form-details/FormDetails.tsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ParsedHtml } from '../parsed-html/ParsedHtml';
55
import { FormDetailsData, Variation } from 'types/content-props/form-details';
66
import { FormDetailsButton } from './FormDetailsButton';
77
import { InfoBox } from '../info-box/InfoBox';
8+
import { AlertInContext } from '../alert-in-context/AlertInContext';
89

910
import style from './FormDetails.module.scss';
1011

@@ -39,8 +40,14 @@ export const FormDetails = ({
3940
showTitleAsLevel4 = false, // Temporary solution until all product pages have been re-organized.
4041
} = displayConfig;
4142

42-
const { formNumbers, formType, languageDisclaimer, ingress, title } =
43-
formDetails;
43+
const {
44+
formNumbers,
45+
formType,
46+
languageDisclaimer,
47+
ingress,
48+
title,
49+
alerts,
50+
} = formDetails;
4451

4552
const variations = formType.reduce((acc, cur) => {
4653
const { _selected } = cur;
@@ -111,6 +118,10 @@ export const FormDetails = ({
111118
</div>
112119
)}
113120
{languageDisclaimer && <InfoBox>{languageDisclaimer}</InfoBox>}
121+
{alerts &&
122+
alerts.map((alert, index) => (
123+
<AlertInContext key={index} alert={alert} />
124+
))}
114125
{variations.length > 0 && (
115126
<div className={style.variation}>
116127
{variations.map((variation, index) => (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@use 'common' as common;
2+
3+
$margin: 2rem;
4+
5+
.alertInContextPage {
6+
display: flex;
7+
flex-direction: column;
8+
max-width: common.$sectionMaxWidth;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
3+
import { AlertInContext } from 'components/_common/alert-in-context/AlertInContext';
4+
import { AlertData } from 'types/content-props/alerts';
5+
6+
import style from './AlertInContextPage.module.scss';
7+
8+
export const AlertInContextPage = (props: AlertData) => {
9+
return (
10+
<div className={style.alertInContextPage}>
11+
<AlertInContext alert={props} />
12+
</div>
13+
);
14+
};

src/components/parts/form-details/FormDetailsPart.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { FormDetailsProps } from 'types/component-props/parts/form-details';
33
import { EditorHelp } from 'components/_editor-only/editor-help/EditorHelp';
44
import { FormDetails } from 'components/_common/form-details/FormDetails';
55
import { FilteredContent } from '../../_common/filtered-content/FilteredContent';
6-
import {
7-
ContentType,
8-
} from 'types/content-props/_content-common';
6+
import { ContentType } from 'types/content-props/_content-common';
97

108
export const FormDetailsPart = ({ config, pageProps }: FormDetailsProps) => {
119
const { targetFormDetails, ...displayConfig } = config;

src/types/content-props/_content-common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export enum ContentType {
100100
FormsOverview = 'no.nav.navno:forms-overview',
101101
UserTestsConfig = 'no.nav.navno:user-tests-config',
102102
Video = 'no.nav.navno:video',
103+
AlertInContext = 'no.nav.navno:alert-in-context',
103104
}
104105

105106
export type ContentAndMediaCommonProps = {

src/types/content-props/alerts.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { OptionSetSingle } from 'types/util-types';
2+
3+
export interface AlertData {
4+
data: {
5+
type: 'information' | 'critical';
6+
text: string;
7+
target: {
8+
_selected: string;
9+
formDetails: OptionSetSingle<{
10+
targetContent: string;
11+
}>;
12+
};
13+
};
14+
}

src/types/content-props/form-details.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { OptionSetSingle } from 'types/util-types';
22
import { ContentCommonProps, ContentType } from './_content-common';
33
import { ProcessedHtmlProps } from 'types/processed-html-props';
44
import { LinkSelectable } from 'types/component-props/_mixins';
5+
import { AlertData } from './alerts';
56

67
export type FormComplaintTypes = 'complaint' | 'appeal';
78

@@ -16,6 +17,7 @@ export interface FormDetailsData {
1617
title?: string;
1718
ingress?: ProcessedHtmlProps;
1819
languageDisclaimer?: string;
20+
alerts: AlertData[];
1921
formType: OptionSetSingle<{
2022
application: {
2123
variations: Variation[];

0 commit comments

Comments
 (0)