Skip to content

Commit 5f77e75

Browse files
ROOS-338: Heading component updated to support Icons and changed HTML structure of the component (#1583)
1 parent 208ce1d commit 5f77e75

File tree

6 files changed

+70
-30
lines changed

6 files changed

+70
-30
lines changed

.changeset/calm-olives-exercise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nl-rvo/component-library-react": minor
3+
---
4+
5+
Update Heading component so html strutures inside of content to be properly handled

.changeset/clever-rocks-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nl-rvo/css-heading": minor
3+
---
4+
5+
Update Heading component to support Icons before and after and not have issues with spans or other html inside the content of the Heading

.changeset/rare-carpets-double.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nl-rvo/component-library-css": minor
3+
---
4+
5+
Remove styling from heading css that is not used anymore for the component

components/heading/src/index.scss

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
color: var(--rvo-color-lintblauw);
1111
display: flex;
1212

13-
& .rvo-icon {
14-
--utrecht-icon-color: var(--rvo-color-lintblauw);
15-
}
16-
1713
&--normal {
1814
font-weight: var(--rvo-font-weight-normal);
1915
}
@@ -32,26 +28,13 @@
3228
margin-block-start: var(--utrecht-heading-#{$i}-margin-block-start);
3329
}
3430
}
35-
}
3631

37-
// If there is an RVO Icon available then override the sizes through these selectors
38-
h1.rvo-heading,
39-
h2.rvo-heading {
40-
.rvo-icon {
41-
--utrecht-icon-size: var(--rvo-icon-xl-width);
32+
&__icon {
33+
display: flex;
4234
}
43-
}
44-
45-
h3.rvo-heading,
46-
h4.rvo-heading {
47-
.rvo-icon {
48-
--utrecht-icon-size: var(--rvo-icon-lg-width);
49-
}
50-
}
5135

52-
h5.rvo-heading,
53-
h6.rvo-heading {
54-
.rvo-icon {
55-
--utrecht-icon-size: var(--rvo-icon-md-width);
36+
&__content {
37+
display: block;
38+
font-size: inherit;
5639
}
5740
}

components/heading/stories/heading.stories.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Heading, Icon } from '@nl-rvo/component-library-react';
1+
import { Heading } from '@nl-rvo/component-library-react';
22
import { defaultArgs } from '@nl-rvo/component-library-react/src/components/heading/defaultArgs';
33
import type { Meta, StoryObj } from '@storybook/react-webpack5';
44

@@ -13,6 +13,13 @@ const argTypes = {
1313
fontWeightNormal: {
1414
control: 'boolean',
1515
},
16+
showIcon: {
17+
options: ['no', 'before', 'after'],
18+
control: { type: 'select' },
19+
},
20+
icon: {
21+
control: 'string',
22+
},
1623
children: {
1724
table: {
1825
disable: true,
@@ -46,9 +53,8 @@ export const HeadingIconBefore: Story = {
4653
args: defaultArgs,
4754
name: 'Heading with Icon Before',
4855
render: (args) => (
49-
<Heading {...args}>
50-
<Icon icon={'home'} />
51-
Heading with Icon
56+
<Heading {...args} showIcon="before" icon="home">
57+
Heading with Icon before
5258
</Heading>
5359
),
5460
};
@@ -57,9 +63,8 @@ export const HeadingIconAfter: Story = {
5763
args: defaultArgs,
5864
name: 'Heading with Icon After',
5965
render: (args) => (
60-
<Heading {...args}>
61-
Heading with Icon
62-
<Icon icon={'home'} />
66+
<Heading {...args} showIcon="before" icon="home">
67+
Heading with Icon after
6368
</Heading>
6469
),
6570
};

packages/component-library-react/src/components/heading/index.tsx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import clsx from 'clsx';
66
import React, { createElement, ReactNode } from 'react';
77
import parseContentMarkup from '../../utils/parseContentMarkup';
88
import '@nl-rvo/component-library-css/dist/components/heading.css';
9+
import Icon from '../icon';
10+
import { IconType } from '../icon/types';
911

1012
export interface IHeadingProps extends React.HTMLAttributes<HTMLHeadingElement> {
1113
type: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
1214
noMargins?: boolean;
1315
fontWeightNormal?: boolean;
1416
children?: string | ReactNode;
1517
className?: string;
18+
showIcon?: 'before' | 'after';
19+
icon?: IconType;
1620
}
1721

1822
export const Heading: React.FC<IHeadingProps> = ({
@@ -21,8 +25,29 @@ export const Heading: React.FC<IHeadingProps> = ({
2125
fontWeightNormal,
2226
className,
2327
children,
28+
showIcon,
29+
icon,
2430
...rest
2531
}: IHeadingProps) => {
32+
let iconSize: 'xl' | 'lg' | 'md' = 'xl';
33+
switch (type) {
34+
case 'h1':
35+
case 'h2':
36+
iconSize = 'xl';
37+
break;
38+
case 'h3':
39+
case 'h4':
40+
iconSize = 'lg';
41+
break;
42+
case 'h5':
43+
case 'h6':
44+
iconSize = 'md';
45+
break;
46+
default:
47+
iconSize = 'xl';
48+
break;
49+
}
50+
2651
const Tag = createElement(
2752
type,
2853
{
@@ -36,7 +61,19 @@ export const Heading: React.FC<IHeadingProps> = ({
3661
),
3762
...rest,
3863
},
39-
children && parseContentMarkup(children),
64+
<>
65+
{showIcon === 'before' && icon && (
66+
<div className="rvo-heading__icon">
67+
<Icon icon={icon} color="lintblauw" size={iconSize} />
68+
</div>
69+
)}
70+
<div className="rvo-heading__content">{children && parseContentMarkup(children)}</div>
71+
{showIcon === 'after' && icon && (
72+
<div className="rvo-heading__icon">
73+
<Icon icon={icon} color="lintblauw" size={iconSize} />
74+
</div>
75+
)}
76+
</>,
4077
);
4178

4279
return Tag;

0 commit comments

Comments
 (0)