diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index cb4a2215f..a1c1b94de 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -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 diff --git a/package.json b/package.json index 5effbe04e..d04714737 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/Error.tsx b/src/components/Error.tsx index a99cfa1a6..91bd468b6 100644 --- a/src/components/Error.tsx +++ b/src/components/Error.tsx @@ -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 { @@ -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(Sentry.lastEventId()); @@ -36,12 +28,12 @@ export const Error = ({ heading, children, ...props }: ErrorPropTypes) => { return () => clearInterval(intervalId); }, [lastEventId, context.error?.eventId]); - return - {heading ?? `Uh-oh, there's been a glitch`} + return + {heading ?? `Uh-oh, there's been a glitch`} {children ?? <> We're not quite sure what went wrong. Restart your browser. If this doesn't solve the problem, visit our Support Center. } - {context.error?.eventId || lastEventId} - + {context.error?.eventId || lastEventId} + }; diff --git a/src/components/MessageBox.spec.tsx b/src/components/MessageBox.spec.tsx new file mode 100644 index 000000000..e0777ca3c --- /dev/null +++ b/src/components/MessageBox.spec.tsx @@ -0,0 +1,25 @@ +import renderer from 'react-test-renderer'; +import { MessageBox } from './MessageBox'; + +describe('MessageBox', () => { + it('matches snapshot', () => { + const tree = renderer.create( + + ).toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('can override text', () => { + const tree = renderer.create( + Body text + ).toJSON(); + expect(tree).toMatchSnapshot(); + }); + + it('can override margin', () => { + const tree = renderer.create( + Body text + ).toJSON(); + expect(tree).toMatchSnapshot(); + }); +}); diff --git a/src/components/MessageBox.stories.tsx b/src/components/MessageBox.stories.tsx new file mode 100644 index 000000000..83d2f6aa3 --- /dev/null +++ b/src/components/MessageBox.stories.tsx @@ -0,0 +1,9 @@ +import { MessageBox } from './MessageBox'; + +export const Empty = () => ; +export const CustomText = () => + Diffferent body text +; +export const CustomMargin = () => + No submissions are currently available for review. +; diff --git a/src/components/MessageBox.styles.tsx b/src/components/MessageBox.styles.tsx new file mode 100644 index 000000000..4d6119e98 --- /dev/null +++ b/src/components/MessageBox.styles.tsx @@ -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; +`; \ No newline at end of file diff --git a/src/components/MessageBox.tsx b/src/components/MessageBox.tsx new file mode 100644 index 000000000..13d565227 --- /dev/null +++ b/src/components/MessageBox.tsx @@ -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 ( + + + {children} + + + ); +}; diff --git a/src/components/__snapshots__/Error.spec.tsx.snap b/src/components/__snapshots__/Error.spec.tsx.snap index 913e5e967..d81ab1f0f 100644 --- a/src/components/__snapshots__/Error.spec.tsx.snap +++ b/src/components/__snapshots__/Error.spec.tsx.snap @@ -2,17 +2,17 @@ exports[`Error can override text 1`] = `

An important heading

Body text
@@ -20,11 +20,11 @@ exports[`Error can override text 1`] = ` exports[`Error matches snapshot 1`] = `

Uh-oh, there's been a glitch

@@ -37,7 +37,7 @@ exports[`Error matches snapshot 1`] = ` .
diff --git a/src/components/__snapshots__/ErrorModal.spec.tsx.snap b/src/components/__snapshots__/ErrorModal.spec.tsx.snap index cf0bc9e34..f30af2d5a 100644 --- a/src/components/__snapshots__/ErrorModal.spec.tsx.snap +++ b/src/components/__snapshots__/ErrorModal.spec.tsx.snap @@ -86,11 +86,11 @@ exports[`Modal matches snapshot 1`] = `

Uh-oh, there's been a glitch

@@ -103,7 +103,7 @@ exports[`Modal matches snapshot 1`] = ` .
@@ -214,11 +214,11 @@ exports[`Modal matches snapshot when heading and children are set 1`] = `

Scores not sent

@@ -232,7 +232,7 @@ exports[`Modal matches snapshot when heading and children are set 1`] = ` .
diff --git a/src/components/__snapshots__/MessageBox.spec.tsx.snap b/src/components/__snapshots__/MessageBox.spec.tsx.snap new file mode 100644 index 000000000..8c7e8ca2e --- /dev/null +++ b/src/components/__snapshots__/MessageBox.spec.tsx.snap @@ -0,0 +1,38 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MessageBox can override margin 1`] = ` +
+
+ Body text +
+
+`; + +exports[`MessageBox can override text 1`] = ` +
+
+ Body text +
+
+`; + +exports[`MessageBox matches snapshot 1`] = ` +
+
+
+`; diff --git a/src/index.ts b/src/index.ts index 928559b4c..2c6c030bf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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';