This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(examples): add checkboxes example
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
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
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")); |
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
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"] | ||
} |
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
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; | ||
} | ||
} |