Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Jira
runs-on: ubuntu-latest
steps:
- uses: openstax/jira-linked-action@v0.1.14
- uses: openstax/jira-linked-action@v0.1.15
with:
jira_site: openstax
jira_project: DISCO
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openstax/ui-components",
"version": "1.18.5",
"version": "1.18.6",
"license": "MIT",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
Expand Down
18 changes: 5 additions & 13 deletions src/components/Error.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from "react";
import * as Sentry from '@sentry/react';
import { ModalBody, ModalBodyHeading } from "./Modal";
import styled from "styled-components";
import { colors } from "../../src/theme";
import { BoxBody, BoxHeading, BoxEventId } from "./MessageBox.styles";
import { ErrorContext } from "../contexts";

export interface ErrorPropTypes {
Expand All @@ -11,12 +9,6 @@ export interface ErrorPropTypes {
heading?: string;
}

const EventId = styled.div`
font-size: 1.4rem;
color: ${colors.palette.neutralMedium};
margin-top: 1.6rem;
`;

export const Error = ({ heading, children, ...props }: ErrorPropTypes) => {
const context = React.useContext(ErrorContext);
const [lastEventId, setLastEventId] = React.useState<string | undefined>(Sentry.lastEventId());
Expand All @@ -36,12 +28,12 @@ export const Error = ({ heading, children, ...props }: ErrorPropTypes) => {
return () => clearInterval(intervalId);
}, [lastEventId, context.error?.eventId]);

return <ModalBody {...props} data-testid='error'>
<ModalBodyHeading>{heading ?? `Uh-oh, there's been a glitch`}</ModalBodyHeading>
return <BoxBody {...props} data-testid='error'>
<BoxHeading>{heading ?? `Uh-oh, there's been a glitch`}</BoxHeading>
{children ?? <>
We're not quite sure what went wrong. Restart your browser. If this doesn't solve
the problem, visit our <a href="https://openstax.secure.force.com/help" target="_blank">Support Center</a>.
</>}
<EventId data-testid='event-id'>{context.error?.eventId || lastEventId}</EventId>
</ModalBody>
<BoxEventId data-testid='event-id'>{context.error?.eventId || lastEventId}</BoxEventId>
</BoxBody>
};
25 changes: 25 additions & 0 deletions src/components/MessageBox.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import renderer from 'react-test-renderer';
import { MessageBox } from './MessageBox';

describe('MessageBox', () => {
it('matches snapshot', () => {
const tree = renderer.create(
<MessageBox />
).toJSON();
expect(tree).toMatchSnapshot();
});

it('can override text', () => {
const tree = renderer.create(
<MessageBox>Body text</MessageBox>
).toJSON();
expect(tree).toMatchSnapshot();
});

it('can override margin', () => {
const tree = renderer.create(
<MessageBox customMargin='10rem 0 10rem 0'>Body text</MessageBox>
).toJSON();
expect(tree).toMatchSnapshot();
});
});
9 changes: 9 additions & 0 deletions src/components/MessageBox.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { MessageBox } from './MessageBox';

export const Empty = () => <MessageBox />;
export const CustomText = () => <MessageBox>
Diffferent body text
</MessageBox>;
export const CustomMargin = () => <MessageBox customMargin='10rem auto'>
No submissions are currently available for review.
</MessageBox>;
29 changes: 29 additions & 0 deletions src/components/MessageBox.styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import styled from "styled-components";
import { colors } from "../../src/theme";

const modalPadding = 3;

export const BoxWrapper = styled.div<{
margin?: string;
}>`
margin: ${props => props.margin ?? '0 auto'};
max-width: 90.2rem;
border: 0.1rem solid ${colors.palette.pale};
`;

export const BoxHeading = styled.h3`
font-weight: 400;
font-size: 2.2rem;
margin-top: 0;
`;

export const BoxBody = styled.div`
font-size: 1.6rem;
padding: ${modalPadding}rem;
`;

export const BoxEventId = styled.div`
font-size: 1.4rem;
color: ${colors.palette.neutralMedium};
margin-top: 1.6rem;
`;
18 changes: 18 additions & 0 deletions src/components/MessageBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";
import { BoxWrapper, BoxBody } from "./MessageBox.styles";

export interface MessageBoxProps {
customMargin?: string;
children?: React.ReactNode;
}

export const MessageBox = ({ children, customMargin, ...props }: MessageBoxProps) => {

return (
<BoxWrapper margin={customMargin}>
<BoxBody {...props} data-testid='message-box'>
{children}
</BoxBody>
</BoxWrapper>
);
};
12 changes: 6 additions & 6 deletions src/components/__snapshots__/Error.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

exports[`Error can override text 1`] = `
<div
className="sc-jSMfEi cWLUhq"
className="sc-dkzDqf iJAkzW"
data-testid="error"
>
<h3
className="sc-eCYdqJ hrmHjt"
className="sc-gsnTZi jDaiGk"
>
An important heading
</h3>
Body text
<div
className="sc-papXJ dnjAXW"
className="sc-hKMtZM bkppVE"
data-testid="event-id"
/>
</div>
`;

exports[`Error matches snapshot 1`] = `
<div
className="sc-jSMfEi cWLUhq"
className="sc-dkzDqf iJAkzW"
data-testid="error"
>
<h3
className="sc-eCYdqJ hrmHjt"
className="sc-gsnTZi jDaiGk"
>
Uh-oh, there's been a glitch
</h3>
Expand All @@ -37,7 +37,7 @@ exports[`Error matches snapshot 1`] = `
</a>
.
<div
className="sc-papXJ dnjAXW"
className="sc-hKMtZM bkppVE"
data-testid="event-id"
/>
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/components/__snapshots__/ErrorModal.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ exports[`Modal matches snapshot 1`] = `
</button>
</header>
<div
class="sc-papXJ jvMkIj"
class="sc-breuTD eiboLU"
data-testid="error"
>
<h3
class="sc-ftvSup dzrTqv"
class="sc-evZas buXsYK"
>
Uh-oh, there's been a glitch
</h3>
Expand All @@ -103,7 +103,7 @@ exports[`Modal matches snapshot 1`] = `
</a>
.
<div
class="sc-crXcEl gaTpxy"
class="sc-ksZaOG cPKkuS"
data-testid="event-id"
/>
</div>
Expand Down Expand Up @@ -214,11 +214,11 @@ exports[`Modal matches snapshot when heading and children are set 1`] = `
</button>
</header>
<div
class="sc-papXJ jvMkIj"
class="sc-breuTD eiboLU"
data-testid="error"
>
<h3
class="sc-ftvSup dzrTqv"
class="sc-evZas buXsYK"
>
Scores not sent
</h3>
Expand All @@ -232,7 +232,7 @@ exports[`Modal matches snapshot when heading and children are set 1`] = `
</a>
.
<div
class="sc-crXcEl gaTpxy"
class="sc-ksZaOG cPKkuS"
data-testid="event-id"
/>
</div>
Expand Down
38 changes: 38 additions & 0 deletions src/components/__snapshots__/MessageBox.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MessageBox can override margin 1`] = `
<div
className="sc-bczRLJ ezbLuP"
>
<div
className="sc-dkzDqf iJAkzW"
data-testid="message-box"
>
Body text
</div>
</div>
`;

exports[`MessageBox can override text 1`] = `
<div
className="sc-bczRLJ ewgpZQ"
>
<div
className="sc-dkzDqf iJAkzW"
data-testid="message-box"
>
Body text
</div>
</div>
`;

exports[`MessageBox matches snapshot 1`] = `
<div
className="sc-bczRLJ ewgpZQ"
>
<div
className="sc-dkzDqf iJAkzW"
data-testid="message-box"
/>
</div>
`;
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export * from './components/Checkbox/Checkbox';
export * from './components/Tree/TreeCheckbox';
export * from './components/DropdownMenu';
export * from './components/Error';
export * from './components/MessageBox';
export * from './components/MessageBox.styles';
export * from './components/ErrorBoundary';
export * from './components/ErrorMessage';
export * from './components/ErrorModal';
Expand Down
Loading