Skip to content

Commit d5c32d2

Browse files
authored
CORE-1257: MessageBox component (#101)
* create new MessageBox component * create new stores and snaps * bump version * update jira-linked-action * remove unused ModalBodyHeading style * update snaps * export MessageBox * return ModalBodyHeading * update snaps * export MessageBox styles
1 parent 8c95b76 commit d5c32d2

File tree

11 files changed

+140
-27
lines changed

11 files changed

+140
-27
lines changed

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: Jira
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: openstax/[email protected].14
13+
- uses: openstax/[email protected].15
1414
with:
1515
jira_site: openstax
1616
jira_project: DISCO

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openstax/ui-components",
3-
"version": "1.18.5",
3+
"version": "1.18.6",
44
"license": "MIT",
55
"source": "./src/index.ts",
66
"types": "./dist/index.d.ts",

src/components/Error.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from "react";
22
import * as Sentry from '@sentry/react';
3-
import { ModalBody, ModalBodyHeading } from "./Modal";
4-
import styled from "styled-components";
5-
import { colors } from "../../src/theme";
3+
import { BoxBody, BoxHeading, BoxEventId } from "./MessageBox.styles";
64
import { ErrorContext } from "../contexts";
75

86
export interface ErrorPropTypes {
@@ -11,12 +9,6 @@ export interface ErrorPropTypes {
119
heading?: string;
1210
}
1311

14-
const EventId = styled.div`
15-
font-size: 1.4rem;
16-
color: ${colors.palette.neutralMedium};
17-
margin-top: 1.6rem;
18-
`;
19-
2012
export const Error = ({ heading, children, ...props }: ErrorPropTypes) => {
2113
const context = React.useContext(ErrorContext);
2214
const [lastEventId, setLastEventId] = React.useState<string | undefined>(Sentry.lastEventId());
@@ -36,12 +28,12 @@ export const Error = ({ heading, children, ...props }: ErrorPropTypes) => {
3628
return () => clearInterval(intervalId);
3729
}, [lastEventId, context.error?.eventId]);
3830

39-
return <ModalBody {...props} data-testid='error'>
40-
<ModalBodyHeading>{heading ?? `Uh-oh, there's been a glitch`}</ModalBodyHeading>
31+
return <BoxBody {...props} data-testid='error'>
32+
<BoxHeading>{heading ?? `Uh-oh, there's been a glitch`}</BoxHeading>
4133
{children ?? <>
4234
We're not quite sure what went wrong. Restart your browser. If this doesn't solve
4335
the problem, visit our <a href="https://openstax.secure.force.com/help" target="_blank">Support Center</a>.
4436
</>}
45-
<EventId data-testid='event-id'>{context.error?.eventId || lastEventId}</EventId>
46-
</ModalBody>
37+
<BoxEventId data-testid='event-id'>{context.error?.eventId || lastEventId}</BoxEventId>
38+
</BoxBody>
4739
};

src/components/MessageBox.spec.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import renderer from 'react-test-renderer';
2+
import { MessageBox } from './MessageBox';
3+
4+
describe('MessageBox', () => {
5+
it('matches snapshot', () => {
6+
const tree = renderer.create(
7+
<MessageBox />
8+
).toJSON();
9+
expect(tree).toMatchSnapshot();
10+
});
11+
12+
it('can override text', () => {
13+
const tree = renderer.create(
14+
<MessageBox>Body text</MessageBox>
15+
).toJSON();
16+
expect(tree).toMatchSnapshot();
17+
});
18+
19+
it('can override margin', () => {
20+
const tree = renderer.create(
21+
<MessageBox customMargin='10rem 0 10rem 0'>Body text</MessageBox>
22+
).toJSON();
23+
expect(tree).toMatchSnapshot();
24+
});
25+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { MessageBox } from './MessageBox';
2+
3+
export const Empty = () => <MessageBox />;
4+
export const CustomText = () => <MessageBox>
5+
Diffferent body text
6+
</MessageBox>;
7+
export const CustomMargin = () => <MessageBox customMargin='10rem auto'>
8+
No submissions are currently available for review.
9+
</MessageBox>;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import styled from "styled-components";
2+
import { colors } from "../../src/theme";
3+
4+
const modalPadding = 3;
5+
6+
export const BoxWrapper = styled.div<{
7+
margin?: string;
8+
}>`
9+
margin: ${props => props.margin ?? '0 auto'};
10+
max-width: 90.2rem;
11+
border: 0.1rem solid ${colors.palette.pale};
12+
`;
13+
14+
export const BoxHeading = styled.h3`
15+
font-weight: 400;
16+
font-size: 2.2rem;
17+
margin-top: 0;
18+
`;
19+
20+
export const BoxBody = styled.div`
21+
font-size: 1.6rem;
22+
padding: ${modalPadding}rem;
23+
`;
24+
25+
export const BoxEventId = styled.div`
26+
font-size: 1.4rem;
27+
color: ${colors.palette.neutralMedium};
28+
margin-top: 1.6rem;
29+
`;

src/components/MessageBox.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from "react";
2+
import { BoxWrapper, BoxBody } from "./MessageBox.styles";
3+
4+
export interface MessageBoxProps {
5+
customMargin?: string;
6+
children?: React.ReactNode;
7+
}
8+
9+
export const MessageBox = ({ children, customMargin, ...props }: MessageBoxProps) => {
10+
11+
return (
12+
<BoxWrapper margin={customMargin}>
13+
<BoxBody {...props} data-testid='message-box'>
14+
{children}
15+
</BoxBody>
16+
</BoxWrapper>
17+
);
18+
};

src/components/__snapshots__/Error.spec.tsx.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22

33
exports[`Error can override text 1`] = `
44
<div
5-
className="sc-jSMfEi cWLUhq"
5+
className="sc-dkzDqf iJAkzW"
66
data-testid="error"
77
>
88
<h3
9-
className="sc-eCYdqJ hrmHjt"
9+
className="sc-gsnTZi jDaiGk"
1010
>
1111
An important heading
1212
</h3>
1313
Body text
1414
<div
15-
className="sc-papXJ dnjAXW"
15+
className="sc-hKMtZM bkppVE"
1616
data-testid="event-id"
1717
/>
1818
</div>
1919
`;
2020

2121
exports[`Error matches snapshot 1`] = `
2222
<div
23-
className="sc-jSMfEi cWLUhq"
23+
className="sc-dkzDqf iJAkzW"
2424
data-testid="error"
2525
>
2626
<h3
27-
className="sc-eCYdqJ hrmHjt"
27+
className="sc-gsnTZi jDaiGk"
2828
>
2929
Uh-oh, there's been a glitch
3030
</h3>
@@ -37,7 +37,7 @@ exports[`Error matches snapshot 1`] = `
3737
</a>
3838
.
3939
<div
40-
className="sc-papXJ dnjAXW"
40+
className="sc-hKMtZM bkppVE"
4141
data-testid="event-id"
4242
/>
4343
</div>

src/components/__snapshots__/ErrorModal.spec.tsx.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ exports[`Modal matches snapshot 1`] = `
8686
</button>
8787
</header>
8888
<div
89-
class="sc-papXJ jvMkIj"
89+
class="sc-breuTD eiboLU"
9090
data-testid="error"
9191
>
9292
<h3
93-
class="sc-ftvSup dzrTqv"
93+
class="sc-evZas buXsYK"
9494
>
9595
Uh-oh, there's been a glitch
9696
</h3>
@@ -103,7 +103,7 @@ exports[`Modal matches snapshot 1`] = `
103103
</a>
104104
.
105105
<div
106-
class="sc-crXcEl gaTpxy"
106+
class="sc-ksZaOG cPKkuS"
107107
data-testid="event-id"
108108
/>
109109
</div>
@@ -214,11 +214,11 @@ exports[`Modal matches snapshot when heading and children are set 1`] = `
214214
</button>
215215
</header>
216216
<div
217-
class="sc-papXJ jvMkIj"
217+
class="sc-breuTD eiboLU"
218218
data-testid="error"
219219
>
220220
<h3
221-
class="sc-ftvSup dzrTqv"
221+
class="sc-evZas buXsYK"
222222
>
223223
Scores not sent
224224
</h3>
@@ -232,7 +232,7 @@ exports[`Modal matches snapshot when heading and children are set 1`] = `
232232
</a>
233233
.
234234
<div
235-
class="sc-crXcEl gaTpxy"
235+
class="sc-ksZaOG cPKkuS"
236236
data-testid="event-id"
237237
/>
238238
</div>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`MessageBox can override margin 1`] = `
4+
<div
5+
className="sc-bczRLJ ezbLuP"
6+
>
7+
<div
8+
className="sc-dkzDqf iJAkzW"
9+
data-testid="message-box"
10+
>
11+
Body text
12+
</div>
13+
</div>
14+
`;
15+
16+
exports[`MessageBox can override text 1`] = `
17+
<div
18+
className="sc-bczRLJ ewgpZQ"
19+
>
20+
<div
21+
className="sc-dkzDqf iJAkzW"
22+
data-testid="message-box"
23+
>
24+
Body text
25+
</div>
26+
</div>
27+
`;
28+
29+
exports[`MessageBox matches snapshot 1`] = `
30+
<div
31+
className="sc-bczRLJ ewgpZQ"
32+
>
33+
<div
34+
className="sc-dkzDqf iJAkzW"
35+
data-testid="message-box"
36+
/>
37+
</div>
38+
`;

0 commit comments

Comments
 (0)