Created
December 9, 2016 21:57
-
-
Save tuxsudo/7fc37efa5aa2bc4e89ca618959b3c0ad to your computer and use it in GitHub Desktop.
Confirm React Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.wrapper { | |
padding: 1em; | |
text-align: center; | |
} | |
.title { | |
font-family: var(--serif, Serif); | |
font-weight: normal; | |
text-transform: capitalize; | |
} | |
.text { | |
font-family: var(--sans-serif, sans-serif); | |
} | |
.confirm, | |
.cancel { | |
/*Needed for unit tests...*/ | |
} | |
.buttons { | |
display: flex; | |
justify-content: center; | |
margin-top: 2em; | |
} | |
.buttons > *:not(:last-child) { | |
margin-right: 1em; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import styles from './Confirm.css'; | |
import join from 'join-classnames'; | |
import Button from '../Button'; | |
const makeHiddensFromObject = obj => ( | |
Object.keys(obj).map( (key, i) => | |
<input key={i} type="hidden" name={key} value={obj[key]} /> | |
) | |
); | |
export default ({ | |
title="Are you sure?", | |
action, | |
method, | |
hiddenData={}, | |
text, | |
cancelLabel="No", | |
confirmLabel="Yes", | |
onSubmit, | |
onConfirm, | |
onCancel, | |
className | |
}) => ( | |
<form onSubmit={onSubmit} action={action} method={method} className={join(styles.wrapper, className)}> | |
<h1 className={styles.title}>{title}</h1> | |
{text && <p className={styles.text}>{text}</p>} | |
<div>{makeHiddensFromObject(hiddenData)}</div> | |
<div className={styles.buttons}> | |
{onCancel && ( | |
<Button | |
emphasis={false} | |
className={styles.cancel} | |
onClick={onCancel} | |
value={cancelLabel} | |
/> | |
)} | |
<Button | |
type={action||method||!onConfirm?"submit":"button"} | |
className={styles.confirm} | |
onClick={onConfirm} | |
value={confirmLabel} | |
/> | |
</div> | |
</form> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment