Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
chore(examples): add checkboxes example
Browse files Browse the repository at this point in the history
  • Loading branch information
wellyshen committed Dec 28, 2020
1 parent ef1e0d3 commit d2072e4
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
32 changes: 32 additions & 0 deletions examples/checkboxs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from "react";
import { render } from "react-dom";
import { useForm } from "react-cool-form";

import "./styles.scss";

const Field = ({ label, id, ...rest }) => (
<div>
<label htmlFor={id}>{label}</label>
<input id={id} {...rest} />
</div>
);

function App() {
const { form, reset } = useForm({
onSubmit: (values) => alert(JSON.stringify(values, undefined, 2))
});

React.useEffect(() => {
reset({ firstName: "Welly", lastName: "Shen" });
}, [reset]);

return (
<form ref={form} noValidate>
<Field label="First Name" id="first-name" name="firstName" />
<Field label="Last Name" id="last-name" name="lastName" />
<input type="submit" />
</form>
);
}

render(<App />, document.getElementById("root"));
18 changes: 18 additions & 0 deletions examples/checkboxs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "rcf-checkboxes",
"version": "0.0.0",
"description": "The checkboxes example of RCF.",
"main": "index.js",
"dependencies": {
"react": "^17.0.1",
"react-cool-form": "latest",
"react-dom": "^17.0.1",
"react-scripts": "^4.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"eject": "react-scripts eject"
},
"browserslist": [">0.2%", "not dead", "not ie <= 11", "not op_mini all"]
}
36 changes: 36 additions & 0 deletions examples/checkboxs/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
body {
font-family: sans-serif;
background: #222;
}

form {
margin: 5rem auto 0;
width: 24rem;

div {
width: inherit;
margin-bottom: 1rem;
}

label {
display: block;
color: #fff;
}

input {
margin: 0.5rem 0;
padding: 0.5rem;
width: inherit;
height: 2rem;
border: none;
border-radius: 4px;
box-sizing: border-box;
}

input[type="submit"] {
height: 2.8rem;
font-size: 1rem;
background: #faa627;
cursor: pointer;
}
}

0 comments on commit d2072e4

Please sign in to comment.