Skip to content

Commit 0b9f2ca

Browse files
committed
Updating readme and adding new workflows
1 parent 6e14097 commit 0b9f2ca

File tree

3 files changed

+137
-1
lines changed

3 files changed

+137
-1
lines changed

.github/workflows/on_pre_release.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Pre Release
2+
3+
on:
4+
release:
5+
types: [prereleased]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v1
12+
- uses: actions/setup-node@v1
13+
with:
14+
node-version: 12
15+
registry-url: https://registry.npmjs.org/
16+
- name: npm install
17+
run: npm i
18+
- name: build
19+
run: npm run build
20+
- name: publish
21+
working-directory: ./pkg
22+
run: npm publish --tag next
23+
env:
24+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.github/workflows/on_release.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v1
12+
- uses: actions/setup-node@v1
13+
with:
14+
node-version: 12
15+
registry-url: https://registry.npmjs.org/
16+
- name: npm install
17+
run: npm i
18+
- name: build
19+
run: npm run build
20+
- name: publish
21+
working-directory: ./pkg
22+
run: npm publish
23+
env:
24+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

README.md

+89-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
# Pretty Checkbox React
3030

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.
3232

3333
## Getting Started
3434

@@ -41,6 +41,94 @@ npm i pretty-checkbox pretty-checkbox-react
4141
yarn add pretty-checkbox pretty-checkbox-react
4242
```
4343

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 * as React from '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 &amp; Variants
58+
59+
Like `pretty-checkbox`, `colors`, `variant`, and `shapes` are supported via props:
60+
61+
```tsx
62+
import * as React from 'react';
63+
import { Checkbox } from 'pretty-checkbox-react';
64+
65+
function App() {
66+
return (
67+
<Checkbox color="primary" shape="curve" variant="thick">
68+
Do you agree to the terms and conditions?
69+
</Checkbox>
70+
);
71+
}
72+
```
73+
74+
### Uncontrolled Usage
75+
76+
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 * as React from '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 <Checkbox ref={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:
98+
99+
```tsx
100+
import * as React from 'react';
101+
import { Checkbox, useCheckboxState } from 'pretty-checkbox-react';
102+
103+
function App() {
104+
const checkbox = useCheckboxState();
105+
106+
const onSubmit = React.useCallback(
107+
e => {
108+
e.preventDefault();
109+
110+
if (!checkbox.state) {
111+
// 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+
<form onSubmit={onSubmit}>
120+
<Checkbox name="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:
131+
44132
### Changelog
45133

46134
See the releases page.

0 commit comments

Comments
 (0)