You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+89-1
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@
28
28
29
29
# Pretty Checkbox React
30
30
31
-
Pretty Checkbox React is a pretty small react wrapper around the the pretty awesome library pretty checkbox.
31
+
Pretty Checkbox React (PCR for short) is a small react wrapper around the the pretty awesome library pretty checkbox.
32
32
33
33
## Getting Started
34
34
@@ -41,6 +41,94 @@ npm i pretty-checkbox pretty-checkbox-react
41
41
yarn add pretty-checkbox pretty-checkbox-react
42
42
```
43
43
44
+
## Basic Usage
45
+
46
+
PCR components are easy to use and require no additional setup. They support controlled and uncontrolled modes and pass pretty much all props down to the underlying `input` element.
47
+
48
+
```tsx
49
+
import*asReactfrom'react';
50
+
import { Checkbox } from'pretty-checkbox-react';
51
+
52
+
function App() {
53
+
return <Checkbox>Do you agree to the terms and conditions?</Checkbox>;
54
+
}
55
+
```
56
+
57
+
### Colors & Variants
58
+
59
+
Like `pretty-checkbox`, `colors`, `variant`, and `shapes` are supported via props:
Add a `ref` and get access to the input element. Uncontrolled mode allows for seamless integration with form solutions like `react-hook-form`:
77
+
78
+
```tsx
79
+
import*asReactfrom'react';
80
+
import { Checkbox } from'pretty-checkbox-react';
81
+
82
+
function App() {
83
+
const ref =React.useRef(null);
84
+
85
+
React.useEffect(() => {
86
+
if (ref.current) {
87
+
// do something awesome
88
+
}
89
+
}, []);
90
+
91
+
return <Checkboxref={ref}>Do you agree to the terms and conditions?</Checkbox>;
92
+
}
93
+
```
94
+
95
+
### Controlled Mode
96
+
97
+
For your state needs, PCR components can be controlled, too. For convenience, there are hooks provided that abstract the typical, mundane tasks or creating stateful components:
// update the state manually from the `confirm` result
112
+
checkbox.setState(confirm('Do you agree to the terms and conditions?'));
113
+
}
114
+
},
115
+
[checkbox]
116
+
);
117
+
118
+
return (
119
+
<formonSubmit={onSubmit}>
120
+
<Checkboxname="tac"value=""{...checkbox}>
121
+
Do you agree to the terms and conditions?
122
+
</Checkbox>
123
+
</form>
124
+
);
125
+
}
126
+
```
127
+
128
+
### Loading CSS
129
+
130
+
PCR provides an API around `pretty-checkbox` which means the CSS needs to get loaded by your application. If you're using webpack, [`css-loader`](https://webpack.js.org/loaders/css-loader/) probably would be ideal since you can import it alongside your app. Not using webpack? Add it to your `index.html`:+1:
0 commit comments