Skip to content

Commit 8f1e79c

Browse files
committed
Add support for icons to NoteBox.
A part of this involved increasing padding and border-width to compensate for the additional space needed for the icon.
1 parent 7b84bdc commit 8f1e79c

2 files changed

Lines changed: 123 additions & 17 deletions

File tree

packages/libs/coreui/src/components/containers/NoteBox.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import { css } from '@emotion/react';
22
import React, { ReactNode } from 'react';
33
import { error, warning, mutedBlue } from '../../definitions/colors';
4+
import { Error, Info, Warning } from '@material-ui/icons';
45

56
export interface Props {
67
type: 'info' | 'warning' | 'error';
8+
showIcon?: boolean;
79
children: ReactNode;
810
}
911

1012
const baseCss = css`
11-
border-left: 0.25em solid var(--note-box-border-color);
13+
border-left: 0.35em solid var(--note-box-border-color);
1214
border-radius: 0.25em;
13-
padding: 0.5em 1em;
15+
padding: 1em 3em;
1416
background: var(--note-box-bg-color);
1517
gap: 1em;
1618
margin-bottom: 1em;
19+
position: relative;
1720
`;
1821

1922
const infoCss = css`
@@ -36,12 +39,33 @@ const errorCss = css`
3639
${baseCss};
3740
`;
3841

42+
const iconCss = css`
43+
position: absolute;
44+
left: 0.5em;
45+
font-size: 1.5em;
46+
`;
47+
3948
export function NoteBox(props: Props) {
4049
const finalCss =
4150
props.type === 'warning'
4251
? warningCss
4352
: props.type === 'error'
4453
? errorCss
4554
: infoCss;
46-
return <div css={finalCss}>{props.children}</div>;
55+
56+
const Icon =
57+
props.showIcon === true
58+
? props.type === 'info'
59+
? Info
60+
: props.type === 'warning'
61+
? Warning
62+
: props.type === 'error'
63+
? Error
64+
: null
65+
: null;
66+
return (
67+
<div css={finalCss}>
68+
{Icon ? <Icon css={iconCss} /> : null} {props.children}
69+
</div>
70+
);
4771
}

packages/libs/coreui/src/stories/containers/NoteBox.stories.tsx

Lines changed: 96 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,25 @@ export default {
1111

1212
const Template: Story<Props> = function Template(props) {
1313
return (
14-
<UIThemeProvider
15-
theme={{
16-
palette: {
17-
primary: { hue: mutedGreen, level: 500 },
18-
secondary: { hue: mutedMagenta, level: 500 },
19-
},
20-
}}
21-
>
22-
<NoteBox {...props} />
23-
</UIThemeProvider>
14+
<div style={{ fontFamily: 'sans-serif' }}>
15+
<UIThemeProvider
16+
theme={{
17+
palette: {
18+
primary: { hue: mutedGreen, level: 500 },
19+
secondary: { hue: mutedMagenta, level: 500 },
20+
},
21+
}}
22+
>
23+
<NoteBox {...props} />
24+
</UIThemeProvider>
25+
</div>
2426
);
2527
};
2628

27-
export const Info = Object.assign(Template.bind({}), {
29+
export const InfoWithoutIcon = Object.assign(Template.bind({}), {
2830
args: {
2931
type: 'info',
32+
showIcon: false,
3033
children: (
3134
<div>
3235
This is some general information about the content that follows on the
@@ -36,18 +39,20 @@ export const Info = Object.assign(Template.bind({}), {
3639
},
3740
});
3841

39-
export const Warning = Object.assign(Template.bind({}), {
42+
export const WarningWithoutIcon = Object.assign(Template.bind({}), {
4043
args: {
4144
type: 'warning',
45+
showIcon: false,
4246
children: (
4347
<div>This is a warning about the content that follows on the page.</div>
4448
),
4549
},
4650
});
4751

48-
export const Error = Object.assign(Template.bind({}), {
52+
export const ErrorWithoutIcon = Object.assign(Template.bind({}), {
4953
args: {
5054
type: 'error',
55+
showIcon: false,
5156
children: (
5257
<div>
5358
This is an error message about the content that follows on the page.
@@ -56,9 +61,10 @@ export const Error = Object.assign(Template.bind({}), {
5661
},
5762
});
5863

59-
export const LongContent = Object.assign(Template.bind({}), {
64+
export const LongContentWithoutIcon = Object.assign(Template.bind({}), {
6065
args: {
6166
type: 'info',
67+
showIcon: false,
6268
children: (
6369
<div>
6470
Lorem ipsum odor amet, consectetuer adipiscing elit. Faucibus morbi ac
@@ -72,3 +78,79 @@ export const LongContent = Object.assign(Template.bind({}), {
7278
),
7379
},
7480
});
81+
82+
export const InfoWithIcon = Object.assign(Template.bind({}), {
83+
args: {
84+
type: 'info',
85+
showIcon: true,
86+
children: (
87+
<div>
88+
This is some general information about the content that follows on the
89+
page.
90+
</div>
91+
),
92+
},
93+
});
94+
95+
export const WarningWithIcon = Object.assign(Template.bind({}), {
96+
args: {
97+
type: 'warning',
98+
showIcon: true,
99+
children: (
100+
<div>This is a warning about the content that follows on the page.</div>
101+
),
102+
},
103+
});
104+
105+
export const ErrorWithIcon = Object.assign(Template.bind({}), {
106+
args: {
107+
type: 'error',
108+
showIcon: true,
109+
children: (
110+
<div>
111+
This is an error message about the content that follows on the page.
112+
</div>
113+
),
114+
},
115+
});
116+
117+
export const LongContentWithIcon = Object.assign(Template.bind({}), {
118+
args: {
119+
type: 'info',
120+
showIcon: true,
121+
children: (
122+
<div>
123+
Lorem ipsum odor amet, consectetuer adipiscing elit. Faucibus morbi ac
124+
ultrices purus urna tristique mattis consequat. Posuere volutpat
125+
facilisi natoque dictumst dignissim magna dapibus. Taciti vel a etiam
126+
curabitur velit torquent. Fusce interdum dictum vulputate sollicitudin
127+
nulla. Orci placerat congue odio aptent enim mauris. Turpis nec rhoncus
128+
eleifend eleifend eget. Auctor sed nullam vestibulum quisque egestas;
129+
nullam aenean ante.
130+
</div>
131+
),
132+
},
133+
});
134+
135+
export const ExpandableContentWithIcon = Object.assign(Template.bind({}), {
136+
args: {
137+
type: 'info',
138+
showIcon: true,
139+
children: (
140+
<details>
141+
<summary style={{ cursor: 'pointer' }}>
142+
There are some interesting things about this...
143+
</summary>
144+
<p>
145+
Lorem ipsum odor amet, consectetuer adipiscing elit. Faucibus morbi ac
146+
ultrices purus urna tristique mattis consequat. Posuere volutpat
147+
facilisi natoque dictumst dignissim magna dapibus. Taciti vel a etiam
148+
curabitur velit torquent. Fusce interdum dictum vulputate sollicitudin
149+
nulla. Orci placerat congue odio aptent enim mauris. Turpis nec
150+
rhoncus eleifend eleifend eget. Auctor sed nullam vestibulum quisque
151+
egestas; nullam aenean ante.
152+
</p>
153+
</details>
154+
),
155+
},
156+
});

0 commit comments

Comments
 (0)