Skip to content

Commit b19847e

Browse files
authored
✨ Added possibility of react node as child for InformationalNotice (#1186)
1 parent bf60f78 commit b19847e

3 files changed

Lines changed: 42 additions & 5 deletions

File tree

src/molecules/InformationalNotice/InformationalNotice.stories.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { Typography } from '@equinor/eds-core-react';
12
import { info_circle } from '@equinor/eds-icons';
23
import { Meta, StoryObj } from '@storybook/react-vite';
34

45
import { InformationalNotice } from './InformationalNotice';
6+
import { spacings } from 'src/atoms/style';
7+
import { Chip } from 'src/molecules/Chip/Chip';
58
import { VariantShowcase } from 'src/storybook/VariantShowcase';
69

710
import { expect } from 'storybook/test';
@@ -37,7 +40,7 @@ export const Default: Story = {
3740
'd',
3841
info_circle.svgPathData as string
3942
);
40-
await expect(canvas.getByText(args.children)).toBeInTheDocument();
43+
await expect(canvas.getByText(args.children as string)).toBeInTheDocument();
4144
},
4245
};
4346

@@ -57,3 +60,32 @@ export const Variants: Story = {
5760
/>
5861
),
5962
};
63+
64+
export const ElementsAsChildren: Story = {
65+
args: {
66+
children: (
67+
<>
68+
<Typography variant="body_long">
69+
<b>Section mismatch.</b> The current sections differ from Wellcom.
70+
Please review before proceeding.
71+
</Typography>
72+
<div style={{ display: 'flex', gap: spacings.small }}>
73+
<Typography variant="body_long">
74+
<b>Sections missing:</b>
75+
</Typography>
76+
<Chip>18&#34;</Chip>
77+
<Chip>8&#34;</Chip>
78+
</div>
79+
</>
80+
),
81+
},
82+
decorators: (StoryFn) => (
83+
<div style={{ width: '400px' }}>
84+
<StoryFn />
85+
</div>
86+
),
87+
play: async ({ canvas }) => {
88+
await expect(canvas.getByText('18"')).toBeInTheDocument();
89+
await expect(canvas.getByText('8"')).toBeInTheDocument();
90+
},
91+
};

src/molecules/InformationalNotice/InformationalNotice.styles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { InformationalNoticeProps } from './InformationalNotice';
2-
import { colors, spacings } from 'src/atoms/style';
2+
import { colors, shape, spacings } from 'src/atoms/style';
33

44
import styled, { css } from 'styled-components';
55

@@ -28,6 +28,7 @@ interface ContainerProps {
2828
export const Container = styled.div<ContainerProps>`
2929
display: grid;
3030
grid-template-columns: auto 1fr;
31+
border-radius: ${shape.corners.borderRadius};
3132
background: ${({ $color }) =>
3233
$color === 'white'
3334
? colors.ui.background__default.rgba

src/molecules/InformationalNotice/InformationalNotice.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC } from 'react';
1+
import { FC, ReactNode } from 'react';
22

33
import { Icon, Typography } from '@equinor/eds-core-react';
44
import { info_circle } from '@equinor/eds-icons';
@@ -10,7 +10,7 @@ import { colors } from 'src/atoms/style';
1010
export interface InformationalNoticeProps {
1111
color?: 'grey' | 'white';
1212
spacing?: 'compact' | 'comfortable';
13-
children: string;
13+
children: string | ReactNode | ReactNode[];
1414
}
1515

1616
export const InformationalNotice: FC<InformationalNoticeProps> = ({
@@ -24,6 +24,10 @@ export const InformationalNotice: FC<InformationalNoticeProps> = ({
2424
color={colors.text.static_icons__default.rgba}
2525
size={getIconSize(spacing)}
2626
/>
27-
<Typography variant="body_long">{children}</Typography>
27+
{typeof children === 'string' ? (
28+
<Typography variant="body_long">{children}</Typography>
29+
) : (
30+
children
31+
)}
2832
</Container>
2933
);

0 commit comments

Comments
 (0)