Skip to content

Commit 2659448

Browse files
authored
Merge pull request #194 from EnCiv/status-box#192
Status box#192
2 parents 6b5b703 + 2a9ce62 commit 2659448

File tree

8 files changed

+189
-14
lines changed

8 files changed

+189
-14
lines changed

app/components/sign-up.jsx

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import cx from 'classnames'
55
import { createUseStyles } from 'react-jss'
66
import { useAuth } from 'civil-client'
77
import { Button } from './button'
8-
import SvgAlertTriangle from '../svgr/alert-triangle'
8+
import StatusBox from '../components/status-box'
99

1010
function SignUp(props, ref) {
1111
const {
@@ -219,18 +219,18 @@ function SignUp(props, ref) {
219219
</label>
220220
</div>
221221
</div>
222-
<div className={cx(classes.error, !state.error && classes.disabled)}>
223-
<span>
224-
<SvgAlertTriangle width="3rem" />
225-
Oops! {state.error}
226-
</span>
227-
</div>
228-
<div className={cx(classes.info, !state.info && classes.disabled)}>
229-
<span>{state.info}</span>
230-
</div>
231-
<div className={cx(classes.success, !state.success && classes.disabled)}>
232-
<span>{state.success}</span>
233-
</div>
222+
<StatusBox
223+
className={cx(classes.error, !state.error && classes.disabled)}
224+
status="error"
225+
subject={state.error}
226+
/>
227+
<StatusBox className={cx(classes.info, !state.info && classes.disabled)} status="notice" subject={state.info} />
228+
<StatusBox
229+
className={cx(classes.success, !state.success && classes.disabled)}
230+
status="done"
231+
subject={state.success}
232+
/>
233+
234234
<div className={classes.btnContainer}>
235235
<Button
236236
className={cx(classes.btn, isLogIn && classes.disabled)}

app/components/status-box.js

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// https://github.com/EnCiv/civil-pursuit/issues/192
2+
3+
import React from 'react'
4+
import { createUseStyles } from 'react-jss'
5+
import cx from 'classnames'
6+
7+
import SvgAlertTriangle from '../svgr/alert-triangle'
8+
import SvgCheckedCircle from '../svgr/checked-circle'
9+
import SvgWarningTriangle from '../svgr/warning-triangle'
10+
import SvgNoticeCircle from '../svgr/notice-circle'
11+
12+
function StatusBox(props) {
13+
const { className, status = '', subject = '', description = '', ...otherProps } = props
14+
const classes = useStylesFromThemeFunction(props)
15+
16+
let leadText
17+
let Icon
18+
if (status === 'error') {
19+
Icon = SvgAlertTriangle
20+
}
21+
if (status === 'done') {
22+
Icon = SvgCheckedCircle
23+
}
24+
if (status === 'warn') {
25+
Icon = SvgWarningTriangle
26+
}
27+
if (status === 'notice') {
28+
Icon = SvgNoticeCircle
29+
} else {
30+
console.error(`${status} is not a valid status for StatusBox.`)
31+
}
32+
33+
return (
34+
<div className={cx(classes.wrapper, className)} {...otherProps}>
35+
<div className={classes.message}>
36+
{Icon && <Icon className={classes.icon} />}
37+
<span className={classes.subject}>{subject}</span>
38+
{description}
39+
</div>
40+
</div>
41+
)
42+
}
43+
44+
const useStylesFromThemeFunction = createUseStyles(theme => ({
45+
wrapper: props => ({
46+
padding: '1rem',
47+
width: 'auto',
48+
display: 'inline-flex',
49+
boxShadow: theme.boxShadow,
50+
borderRadius: '0.5rem',
51+
backgroundColor: (() => {
52+
if (props.status === 'error') {
53+
return theme.colors.statusBoxErrorBackground
54+
}
55+
if (props.status === 'done') {
56+
return theme.colors.statusBoxDoneBackground
57+
}
58+
if (props.status === 'warn') {
59+
return theme.colors.statusBoxWarnBackground
60+
}
61+
if (props.status === 'notice') {
62+
return theme.colors.statusBoxNoticeBackground
63+
} else {
64+
return theme.colors.colorPrimary
65+
}
66+
})(),
67+
border: `0.125rem solid ${(() => {
68+
if (props.status === 'error') {
69+
return theme.colors.statusBoxErrorBorder
70+
}
71+
if (props.status === 'done') {
72+
return theme.colors.statusBoxDoneBorder
73+
}
74+
if (props.status === 'warn') {
75+
return theme.colors.statusBoxWarnBorder
76+
}
77+
if (props.status === 'notice') {
78+
return theme.colors.statusBoxNoticeBorder
79+
} else {
80+
return ''
81+
}
82+
})()}`,
83+
}),
84+
message: {
85+
...theme.font,
86+
display: 'flex',
87+
alignItems: 'center',
88+
},
89+
subject: {
90+
fontWeight: 'bold',
91+
padding: '0rem 1rem',
92+
},
93+
icon: {
94+
width: '1.5rem',
95+
height: 'auto',
96+
top: '50%',
97+
},
98+
}))
99+
100+
export default StatusBox

app/components/theme.js

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ const Theme = {
3939
statusBadgeInactiveBackground: '#FFFFFF',
4040
statusBadgeErrorBorder: '#BF1300',
4141
statusBadgeErrorBackground: '#F9E7E5',
42+
statusBoxErrorBackground: '#F9E7E5',
43+
statusBoxErrorBorder: '#BF1300',
44+
statusBoxDoneBackground: '#E6F3EB',
45+
statusBoxDoneBorder: '#005621',
46+
statusBoxWarnBackground: '#FFF3D0',
47+
statusBoxWarnBorder: '#EBDCB3',
48+
statusBoxNoticeBackground: '#DCE8F2',
49+
statusBoxNoticeBorder: '#ACC2E2',
4250
roundTrackerBackground: '#FDFDF7',
4351
inactiveGray: '#D9D9D9',
4452
stepContainerActive: 'rgba(6, 51, 92, 0.10)',

assets/svg/alert-triangle.svg

+1-1
Loading

assets/svg/checked-circle.svg

+4
Loading

assets/svg/notice-circle.svg

+12
Loading

assets/svg/warning-triangle.svg

+12
Loading

stories/status-box.stories.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import StatusBox from '../app/components/status-box'
2+
3+
export default {
4+
component: StatusBox,
5+
args: {},
6+
}
7+
8+
export const statusUndefined = { args: { subject: "This isn't defined." } }
9+
10+
export const statusError = {
11+
args: {
12+
status: 'error',
13+
subject: 'Oops!',
14+
description: 'You have an error!',
15+
},
16+
}
17+
18+
export const statusDone = {
19+
args: {
20+
status: 'done',
21+
subject: 'Finished!',
22+
description: 'You are done!',
23+
},
24+
}
25+
export const statusWarn = {
26+
args: {
27+
status: 'warn',
28+
subject: 'Please Review',
29+
description: 'You are being warned!',
30+
},
31+
}
32+
33+
export const statusNotice = {
34+
args: {
35+
status: 'notice',
36+
subject: 'Notice',
37+
description: 'You are being notified!',
38+
},
39+
}

0 commit comments

Comments
 (0)