-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Komponenten ble i utgangspunktet kopiert fra et annet sted. Vi hadde lik bruk begge steder den ble brukt.
- Loading branch information
Showing
5 changed files
with
26 additions
and
103 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
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,9 @@ | ||
import { PageHeader } from 'components/PageHeader/index'; | ||
import { render, screen } from 'setUpTest'; | ||
|
||
describe('PageHeader', () => { | ||
test('har overskrift på nivå 1', () => { | ||
render(<PageHeader>Overskriften</PageHeader>); | ||
expect(screen.getByRole('heading', { level: 1, name: 'Overskriften' })).toBeVisible(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,78 +1,19 @@ | ||
import React, { forwardRef, HTMLAttributes, useMemo } from 'react'; | ||
import { BodyShort, Heading } from '@navikt/ds-react'; | ||
import React from 'react'; | ||
import { Heading } from '@navikt/ds-react'; | ||
import * as classes from 'components/PageHeader/PageHeader.module.css'; | ||
|
||
export interface PageHeaderProps extends HTMLAttributes<HTMLDivElement> { | ||
/** | ||
* PageHeader title | ||
*/ | ||
export interface PageHeaderProps { | ||
children: string | React.ReactNode; | ||
/** | ||
* Pictogram placed in PageHeader | ||
*/ | ||
illustration?: React.ReactNode; | ||
/** | ||
* Short text placed under title | ||
*/ | ||
description?: string; | ||
/** | ||
* Predefined variants for PageHeader | ||
* @default "guide" | ||
*/ | ||
variant?: 'situation' | 'product' | 'guide'; | ||
/** | ||
* Decides how to align content | ||
* @default "left" | ||
*/ | ||
align?: 'left' | 'center'; | ||
} | ||
|
||
// eslint-disable-next-line react/display-name | ||
const PageHeader = forwardRef<HTMLDivElement, PageHeaderProps>( | ||
( | ||
{ children, className, illustration, description, variant = 'guide', align = 'left', ...rest }, | ||
ref | ||
) => { | ||
const variantClass = useMemo(() => { | ||
switch (variant) { | ||
case 'situation': | ||
return 'navdsPageHeaderSituation'; | ||
case 'product': | ||
return 'navdsPageHeaderProduct'; | ||
default: | ||
return 'navdsPageHeaderGuide'; | ||
} | ||
}, [variant]); | ||
const alignClass = useMemo(() => { | ||
switch (align) { | ||
case 'center': | ||
return 'navdsPageHeaderCenter'; | ||
default: | ||
return 'navdsPageHeaderLeft'; | ||
} | ||
}, [align]); | ||
return ( | ||
<div className={classes?.pageHeaderWrapper}> | ||
<div | ||
ref={ref} | ||
className={`${classes?.navdsPageHeader} ${className} ${classes?.[variantClass]} ${classes?.[alignClass]}`} | ||
{...rest} | ||
> | ||
{illustration && ( | ||
<div className={classes?.navdsPageHeaderIllustration}>{illustration}</div> | ||
)} | ||
<div className="navdsPageHeaderWrapper"> | ||
<Heading className="navdsPageHeaderTitle" size="xlarge" level="1"> | ||
{children} | ||
</Heading> | ||
{description && ( | ||
<BodyShort className="navdsPageHeaderDescription">{description}</BodyShort> | ||
)} | ||
</div> | ||
</div> | ||
export const PageHeader = ({ children }: PageHeaderProps) => { | ||
return ( | ||
<div className={classes.pageHeaderWrapper}> | ||
<div className={`${classes.navdsPageHeader} ${classes.navdsPageHeaderGuide} ${classes.navdsPageHeaderCenter}`}> | ||
<Heading size="xlarge" level="1"> | ||
{children} | ||
</Heading> | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
export default PageHeader; | ||
</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