Skip to content

Commit 89121da

Browse files
committed
Merge master into alltid-vise-aktuell-maalgruppetekst
2 parents 4a54ad7 + 268fce2 commit 89121da

File tree

12 files changed

+52
-47
lines changed

12 files changed

+52
-47
lines changed

src/components/_common/copyLink/copyLink.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ type CopyLinkProps = {
1212
anchor: string;
1313
heading: string;
1414
className?: string;
15-
label?: string;
15+
showLabel?: boolean;
1616
};
1717

1818
const linkCopiedDisplayTimeMs = 2500;
1919

20-
export const CopyLink = ({ anchor, heading, label, className }: CopyLinkProps) => {
20+
export const CopyLink = ({ anchor, heading, className, showLabel = true }: CopyLinkProps) => {
2121
const [showCopyTooltip, setShowCopyTooltip] = useState(false);
2222
const { language } = usePageContentProps();
2323
const { layoutConfig } = useLayoutConfig();
@@ -52,7 +52,7 @@ export const CopyLink = ({ anchor, heading, label, className }: CopyLinkProps) =
5252
aria-label={`${getLabel('copyLinkTo')}: "${heading}"`}
5353
>
5454
<LinkIcon className={style.anchorIcon} aria-hidden />
55-
{label || getLabel('copyLink')}
55+
{showLabel && getLabel('copyLink')}
5656
</a>
5757
<span
5858
className={classNames(

src/components/_common/headers/Header.module.scss

+6
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@
1111
box-shadow: none;
1212
}
1313
}
14+
15+
.anchor {
16+
font-size: inherit;
17+
color: inherit;
18+
text-decoration: inherit;
19+
}
+21-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React from 'react';
22
import { Heading } from '@navikt/ds-react';
3-
import { onlyText } from 'utils/react-children';
43
import { classNames } from 'utils/classnames';
54
import { Level, levelToSize, Size } from 'types/typo-style';
6-
import { CopyLink } from 'components/_common/copyLink/copyLink';
75

86
// eslint-disable-next-line css-modules/no-unused-class
97
import style from './Header.module.scss';
@@ -12,22 +10,37 @@ type Props = {
1210
children: React.ReactNode;
1311
level: Level;
1412
size?: Size;
15-
hideCopyButton?: boolean;
1613
anchorId?: string;
14+
addAnchorId?: boolean;
1715
className?: string;
1816
};
1917

20-
export const Header = ({ children, size, level, hideCopyButton, anchorId, className }: Props) => {
18+
export const Header = ({
19+
children,
20+
size,
21+
level,
22+
anchorId,
23+
className,
24+
addAnchorId = true, // Can be set to false if anchor is added outside of Header
25+
}: Props) => {
2126
const anchor = anchorId ? (anchorId.startsWith('#') ? anchorId : `#${anchorId}`) : undefined;
22-
2327
const fallbackSizeByLevel = levelToSize[level] || 'large';
2428

2529
return (
26-
<div className={classNames(style.header, className)} id={anchorId} tabIndex={-1}>
30+
<div
31+
className={classNames(style.header, className)}
32+
id={addAnchorId ? anchorId : undefined}
33+
tabIndex={-1}
34+
>
2735
<Heading size={size || fallbackSizeByLevel} level={level}>
28-
{children}
36+
{anchor && level === '2' ? (
37+
<a href={anchor} className={style.anchor}>
38+
{children}
39+
</a>
40+
) : (
41+
children
42+
)}
2943
</Heading>
30-
{anchor && !hideCopyButton && <CopyLink heading={onlyText(children)} anchor={anchor} />}
3144
</div>
3245
);
3346
};

src/components/layouts/flex-cols/FlexColsLayout.module.scss

+5
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@
135135
}
136136
}
137137

138+
.anchorOffset {
139+
position: relative;
140+
transform: translateY(calc(var(--a-spacing-20) * -1));
141+
}
142+
138143
.shelfHeader:before {
139144
@include common.header-before-rectangle();
140145
}

src/components/layouts/flex-cols/FlexColsLayout.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const FlexColsLayout = ({ pageProps, layoutProps }: Props) => {
2020
}
2121

2222
const { config } = layoutProps;
23-
const { numCols, justifyContent, toggleCopyButton, collapse, title, anchorId } = config;
23+
const { numCols, justifyContent, collapse, title, anchorId } = config;
2424

2525
const regionStyle = {
2626
...(justifyContent && { justifyContent }),
@@ -36,13 +36,7 @@ export const FlexColsLayout = ({ pageProps, layoutProps }: Props) => {
3636
return (
3737
<LayoutContainer pageProps={pageProps} layoutProps={layoutProps} className={style.flexCols}>
3838
{title && (
39-
<Header
40-
level={'2'}
41-
size={'large'}
42-
hideCopyButton={!toggleCopyButton}
43-
anchorId={anchorId}
44-
className={style.header}
45-
>
39+
<Header level={'2'} size={'large'} anchorId={anchorId} className={style.header}>
4640
{title}
4741
</Header>
4842
)}

src/components/layouts/flex-cols/ProductPageFlexColsLayout.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const ProductPageFlexColsLayout = ({ pageProps, layoutProps }: Props) =>
2121
}
2222

2323
const { config } = layoutProps;
24-
const { title, anchorId, toggleCopyButton } = config;
24+
const { title, anchorId } = config;
2525

2626
const calculateColCount = () => {
2727
return regionProps.components.length % 3 === 0 ? 3 : 2;
@@ -34,13 +34,7 @@ export const ProductPageFlexColsLayout = ({ pageProps, layoutProps }: Props) =>
3434
layoutProps={layoutProps}
3535
>
3636
{title && (
37-
<Header
38-
level="2"
39-
size="large"
40-
hideCopyButton={!toggleCopyButton}
41-
anchorId={anchorId}
42-
className={style.header}
43-
>
37+
<Header level="2" size="large" anchorId={anchorId} className={style.header}>
4438
{title}
4539
</Header>
4640
)}

src/components/layouts/flex-cols/SituationPageFlexColsLayout.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const SituationPageFlexColsLayout = ({ pageProps, layoutProps }: Props) =
2121
}
2222

2323
const { config } = layoutProps;
24-
const { title, numCols, justifyContent, anchorId, toggleCopyButton } = config;
24+
const { title, numCols, justifyContent, anchorId } = config;
2525

2626
const regionStyle = {
2727
...(justifyContent && { justifyContent }),
@@ -50,12 +50,13 @@ export const SituationPageFlexColsLayout = ({ pageProps, layoutProps }: Props) =
5050
layoutProps={layoutProps}
5151
>
5252
<div className={style.contentWrapper}>
53+
<div className={style.anchorOffset} id={anchorId} />
5354
{title && (
5455
<Header
5556
level="2"
5657
size="large"
57-
hideCopyButton={!toggleCopyButton}
5858
anchorId={anchorId}
59+
addAnchorId={false}
5960
className={classNames(style.header, isShelf && style.shelfHeader)}
6061
>
6162
{title}

src/components/layouts/section-with-header/SectionWithHeaderLayout.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,11 @@ export const SectionWithHeaderLayout = ({ pageProps, layoutProps }: Props) => {
7575
pageProps={pageProps}
7676
layoutProps={layoutProps}
7777
layoutStyle={border && getBorderStyle(border)}
78-
id={!showIcon ? anchorId : undefined}
7978
tabIndex={-1}
8079
>
8180
{showIcon && (
8281
<div
8382
className={'icon-container'}
84-
id={anchorId} // Ensures anchor links scrolls to the correct position if the icon is rendered
8583
tabIndex={-1}
8684
style={{
8785
...(icon.color && { backgroundColor: icon.color }),
@@ -99,11 +97,13 @@ export const SectionWithHeaderLayout = ({ pageProps, layoutProps }: Props) => {
9997
/>
10098
</div>
10199
)}
100+
<div className={style.anchorOffset} id={anchorId} />
102101
{title && (
103102
<Header
104103
size="large"
105104
level="2"
106-
hideCopyButton={true}
105+
anchorId={anchorId}
106+
addAnchorId={false}
107107
className={classNames(style.header, !!iconImgProps && style.headerWithIcon)}
108108
>
109109
{title}

src/components/layouts/section-with-header/SectionWithHeaderLayoutV2.module.scss

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ $defaultBgColor: white;
4242
@include common.header-before-rectangle();
4343
}
4444

45+
.anchorOffset {
46+
position: relative;
47+
transform: translateY(calc(var(--a-spacing-20) * -1));
48+
}
49+
4550
.header {
4651
margin-bottom: var(--a-spacing-4);
4752
color: var(--brand-purple-deep);

src/components/macros/header-with-anchor/MacroHeaderWithAnchor.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ export const MacroHeaderWithAnchor = ({ config }: MacroHeaderWithAnchorProps) =>
2323
}
2424

2525
return (
26-
<Header
27-
level={level}
28-
size={size}
29-
anchorId={id}
30-
hideCopyButton={true}
31-
className={style.headerWithAnchor}
32-
>
26+
<Header level={level} size={size} anchorId={id} className={style.headerWithAnchor}>
3327
{headerText}
3428
</Header>
3529
);

src/components/parts/header/HeaderPart.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ export const HeaderPart = ({ config }: PartComponentProps<PartType.Header>) => {
2727
const size = headingToSize[tag];
2828

2929
return (
30-
<Header
31-
level={level}
32-
size={size}
33-
anchorId={anchorId}
34-
hideCopyButton={true}
35-
className={style.headerPart}
36-
>
30+
<Header level={level} size={size} anchorId={anchorId} className={style.headerPart}>
3731
{title}
3832
</Header>
3933
);

src/types/component-props/_mixins.ts

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export type HeaderWithAnchorMixin = {
1010
title: string;
1111
description?: string;
1212
anchorId: string;
13-
toggleCopyButton: boolean;
1413
};
1514

1615
export enum Audience {

0 commit comments

Comments
 (0)