Skip to content

Instantly share code, notes, and snippets.

@tuxsudo
Created December 9, 2016 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxsudo/7fc37efa5aa2bc4e89ca618959b3c0ad to your computer and use it in GitHub Desktop.
Save tuxsudo/7fc37efa5aa2bc4e89ca618959b3c0ad to your computer and use it in GitHub Desktop.
Confirm React Component
.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;
}
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