|
1 | | -<h4 align="center">Quickly integrate pretty checkbox Components (checkbox, switch, radio) with React</h4> |
2 | | - |
3 | | -<p align="center"> |
4 | | - <a href="https://github.com/atomicpages/pretty-checkbox-react/releases"> |
5 | | - <img src="https://img.shields.io/github/release/atomicpages/pretty-checkbox-react.svg?style=flat-square&colorA=8033b0&colorB=75b7dd" alt="Github Release"> |
6 | | - </a> |
7 | | - <a href="https://github.com/atomicpages/pretty-checkbox-react/blob/master/LICENSE"> |
8 | | - <img alt="License: MIT" src="https://img.shields.io/github/license/atomicpages/pretty-checkbox-react.svg?style=flat-square"> |
9 | | - </a> |
10 | | - <a href="https://www.npmjs.com/package/pretty-checkbox-react" target="_blank" rel="nofollow noreferred noopener"> |
11 | | - <img src="https://img.shields.io/npm/dm/pretty-checkbox-react.svg?style=flat-square" alt="Downloads"> |
12 | | - </a> |
13 | | - <a href="https://travis-ci.org/atomicpages/pretty-checkbox-react" target="_blank" rel="nofollow noreferred noopener"> |
14 | | - <img alt="Build Status" src="https://img.shields.io/travis/atomicpages/pretty-checkbox-react.svg?style=flat-square"> |
15 | | - </a> |
16 | | - <a href='https://coveralls.io/github/atomicpages/pretty-checkbox-react?branch=master' target="_blank" rel="nofollow noreferred noopener"> |
17 | | - <img alt="Coverage Status" src="https://img.shields.io/coveralls/github/atomicpages/pretty-checkbox-react/master.svg?style=flat-square"> |
18 | | - </a> |
19 | | - <a href="https://codeclimate.com/github/atomicpages/pretty-checkbox-react/maintainability" target="_blank" rel="nofollow noreferred noopener"> |
20 | | - <img src="https://api.codeclimate.com/v1/badges/e7cca7813f2905d7aca7/maintainability" /> |
21 | | - </a> |
22 | | -</p> |
23 | | -<br> |
24 | | - |
25 | | -<div align="center"> |
26 | | - <img src="preview.gif" alt="Pretty checkbox preview" /> |
27 | | -</div> |
28 | | - |
29 | | -### Demos and Docs |
30 | | -Checkout the awesome [doc website](https://atomicpages.github.io/pretty-checkbox-react/home/) with sweet code examples that will update in real time after you make changes! |
31 | | - |
32 | | -#### Code Sandbox |
33 | | -Fancy something else? Want a standalone example? Looking for customize the `pretty-checkbox` theme? How about forking and testing your own changes in code sandbox? It will allow you to prototype and make complex examples all within your browser. |
34 | | - |
35 | | -[](https://codesandbox.io/s/40v46649m0) |
36 | | - |
37 | | -### Browser |
38 | | -Include the script file and all dependencies. |
39 | | - |
40 | | -> Note: keep reading for examples using webpack/rollup/or some other modern web bundler. |
41 | | -
|
42 | | -```html |
43 | | -<script type="text/javascript" src="node_modules/react/umd/react.production.min.js"></script> |
44 | | -<script type="text/javascript" src="node_modules/react-dom/umd/react-dom.production.min.js"></script> |
45 | | -<script type="text/javascript" src="node_modules/pretty-checkbox-react/dist/pretty-checkbox-react.min.js"></script> |
| 1 | +# Getting Started |
46 | 2 |
|
47 | | -<script type="text/javascript"> |
48 | | -function App() { |
49 | | - return React.createElement( |
50 | | - PrettyCheckboxReact.Checkbox, |
51 | | - { |
52 | | - animation: 'smooth', |
53 | | - shape: 'curve' |
54 | | - }, |
55 | | - React.createElement( |
56 | | - 'label', |
57 | | - null, |
58 | | - 'Check me!' |
59 | | - ) |
60 | | - ) |
61 | | -} |
| 3 | +## Installing |
| 4 | + |
| 5 | +Getting `pretty-checkbox-react` is easy |
| 6 | + |
| 7 | +{% hint style="info" %} |
| 8 | +`pretty-checkbox` is a peer dependency of pretty-checkbox-react so you need to be sure to install this as well |
| 9 | +{% endhint %} |
| 10 | + |
| 11 | +```bash |
| 12 | +npm i pretty-checkbox-react pretty-checkbox --save |
| 13 | + |
| 14 | +# or with yarn |
| 15 | +yarn add pretty-checkbox-react pretty-checkbox |
| 16 | +``` |
| 17 | + |
| 18 | +### Usage |
| 19 | + |
| 20 | +Pretty Checkbox React \(PCR\) can be used directly in the browser via UMD or inside a modern bundlers like webpack, rollup, or browserify. |
62 | 21 |
|
63 | | -ReactDOM.render(App, document.querySelector('body')); |
| 22 | +{% code title="index.html" %} |
| 23 | +```markup |
| 24 | +<script src="https://unpkg.com/react/umd/react.production.min.js"></script> |
| 25 | +<script src="https://unpkg.com/react-dom/umd/react-dom.production.min.js"></script> |
| 26 | +<script src="https://unpkg.com/pretty-checkbox-react/dist-browser/index.js"></script> |
| 27 | +
|
| 28 | +<script type="text/javascript"> |
| 29 | + function App() { |
| 30 | + return React.createElement( |
| 31 | + PrettyCheckboxReact.Checkbox, |
| 32 | + Object.assign( |
| 33 | + { |
| 34 | + animation: "smooth", |
| 35 | + shape: "curve" |
| 36 | + }, |
| 37 | + PrettyCheckboxReact.useCheckboxState() |
| 38 | + ), |
| 39 | + "Yes, I want emails!" |
| 40 | + ); |
| 41 | + } |
| 42 | +
|
| 43 | + ReactDOM.render(React.createElement(App), document.querySelector("body")); |
64 | 44 | </script> |
| 45 | +
|
65 | 46 | ``` |
| 47 | +{% endcode %} |
66 | 48 |
|
67 | | -#### Webpack + Rollup |
68 | | -If you're using webpack or rollup then with JSX you can write this more succulently: |
| 49 | +If you're using a modern bundler then the syntax is a bit easier: |
69 | 50 |
|
| 51 | +{% code title="index.js" %} |
70 | 52 | ```jsx |
71 | 53 | import React from 'react'; |
72 | 54 | import ReactDOM from 'react-dom'; |
73 | | - |
74 | | -import { Checkbox } from 'pretty-checkbox-react'; |
| 55 | +import { Checkbox, useCheckboxState } from 'pretty-checkbox-react'; |
75 | 56 |
|
76 | 57 | function App() { |
77 | | - return <Checkbox animation="smooth" shape="curve">Check me!</Checkbox>; |
| 58 | + const checkbox = useCheckboxState(); |
| 59 | + |
| 60 | + return <Checkbox {...checkbox}>Hello</Checkbox> |
78 | 61 | } |
79 | 62 |
|
80 | | -ReactDOM.render(App, document.querySelector('body')); |
| 63 | +ReactDOM.render(<App />, document.getElementById('root')); |
81 | 64 | ``` |
| 65 | +{% endcode %} |
82 | 66 |
|
83 | | -### Getting Started |
84 | | -Install `pretty-checkbox` and `pretty-checkbox-react` through NPM or yarn: |
85 | | - |
86 | | -```bash |
87 | | -yarn pretty-checkbox pretty-checkbox-react # or |
88 | | -npm i pretty-checkbox pretty-checkbox-react --save |
89 | | -``` |
90 | | - |
91 | | -> `pretty-checkbox` is a _peer_ dependency so you need to install it yourself or reference the CSS manually! |
92 | | -
|
93 | | -Make the dependencies available and begin using! `pretty-checkbox-react` exposes three components for your use: |
94 | | - |
95 | | -* Checkbox |
96 | | -* Radio |
97 | | -* Switch |
98 | | - |
99 | | -### Contributions |
100 | | -Shout out to [Lokesh](https://github.com/lokesh-coder) for creating the original [pretty-checkbox library](https://github.com/lokesh-coder/pretty-checkbox) :star: |
| 67 | +For more details about the components available, see each component for more examples and APIs. |
101 | 68 |
|
102 | | -### License |
103 | | -This project is licensed under the MIT License |
0 commit comments