|
17 | 17 | <br />
|
18 | 18 |
|
19 | 19 | > **React PowerPlug is a set of pluggable renderless components and helpers** that provides different types of state and logic utilities that you can use with your dumb components. It creates state and passes down the logic to the children, so you can handle your data. Read about the [Render Props](https://reactjs.org/docs/render-props.html) pattern.
|
20 |
| - |
21 |
| - |
| 20 | +
|
22 | 21 | ## Highlights
|
| 22 | + |
23 | 23 | - :ok_hand: Dependency free
|
24 | 24 | - :electric_plug: Plug and play
|
25 | 25 | - :crystal_ball: Tree shaking friendly (ESM, no side effects)
|
@@ -58,270 +58,9 @@ import { Pagination, Tabs, Checkbox } from './MyDumbComponents'
|
58 | 58 |
|
59 | 59 | </details>
|
60 | 60 |
|
61 |
| -## ⚠️ Master is unstable |
62 |
| - |
63 |
| -> This branch is **unstable** and is in **active development**. |
64 |
| -> For the latest stable version go to [0.1-stable branch](https://github.com/renatorib/react-powerplug/tree/0.1-stable) |
65 |
| -
|
66 |
| -## Components |
67 |
| - |
68 |
| -> **_Note_** _This is a kind of a cheat sheet for fast search._ |
69 |
| -> _If you want a more detailed **API Reference** and examples for each component see [full docs](/docs)_ |
70 |
| -
|
71 |
| -| Component | Component Props | Render Props | | |
72 |
| -| ---------------------------- | ----------------------- | ---------------------------------------------- | --------------------------------------------------------------------------- | |
73 |
| -| <h6>STATE CONTAINERS</h6> | |
74 |
| -| **\<State>** | `{ initial, onChange }` | `{ state, setState }` | [:point_down:](#state) [:books:](docs/components/State.md) | |
75 |
| -| **\<Toggle>** | `{ initial, onChange }` | `{ on, toggle, set, setOn, setOff }` | [:point_down:](#toggle) [:books:](docs/components/Toggle.md) | |
76 |
| -| **\<Counter>** | `{ initial, onChange }` | `{ count, inc, dec, incBy, decBy, set }` | [:point_down:](#counter) [:books:](docs/components/Counter.md) | |
77 |
| -| **\<Value>** | `{ initial, onChange }` | `{ value, set }` | [:point_down:](#value) [:books:](docs/components/Value.md) | |
78 |
| -| **\<Map>** | `{ initial, onChange }` | `{ set, get, over, values }` | [:point_down:](#map) [:books:](docs/components/Map.md) | |
79 |
| -| **\<Set>** | `{ initial, onChange }` | `{ values, add, clear, remove, has }` | [:point_down:](#set) [:books:](docs/components/Set.md) | |
80 |
| -| **\<List>** | `{ initial, onChange }` | `{ list, first, last, push, pull, sort, set }` | [:point_down:](#list) [:books:](docs/components/List.md) | |
81 |
| -| <h6>FEEDBACK CONTAINERS</h6> | |
82 |
| -| **\<Hover>** | `{ onChange }` | `{ hovered, bind }` | [:point_down:](#hover) [:books:](docs/components/Hover.md) | |
83 |
| -| **\<Active>** | `{ onChange }` | `{ active, bind }` | [:point_down:](#active) [:books:](docs/components/Active.md) | |
84 |
| -| **\<Focus>** | `{ onChange }` | `{ focused, bind }` | [:point_down:](#focus) [:books:](docs/components/Focus.md) | |
85 |
| -| **\<Touch>** | `{ onChange }` | `{ touched, bind }` | [:point_down:](#touch) [:books:](docs/components/Touch.md) | |
86 |
| -| <h6>FORM CONTAINERS</h6> | |
87 |
| -| **\<Input>** | `{ initial, onChange }` | `{ set, value, bind }` | [:point_down:](#input) [:books:](docs/components/Input.md) | |
88 |
| -| **\<Form>** | `{ initial, onChange }` | `{ input, values }` | [:point_down:](#form) [:books:](docs/components/Form.md) | |
89 |
| -| <h6>OTHER</h6> | |
90 |
| -| **\<Interval>** | `{ delay }` | `{ stop, start, toggle }` | [:point_down:](#interval) [:books:](docs/components/Interval.md) | |
91 |
| -| **\<Compose>** | `{ components }` | _depends on components prop_ | [:point_down:](#composing-components) [:books:](docs/components/Compose.md) | |
92 |
| - |
93 |
| -## Utilities |
94 |
| - |
95 |
| -| Name | | |
96 |
| -| ----------------------------- | -------------------------------------- | |
97 |
| -| compose(...components) | [:books:](docs/utils/compose.md) | |
98 |
| -| composeEvents(...objOfEvents) | [:books:](docs/utils/composeEvents.md) | |
99 |
| - |
100 |
| -## Examples |
101 |
| - |
102 |
| -#### State |
103 |
| - |
104 |
| -```jsx |
105 |
| -<State initial={{ loading: false, data: null }}> |
106 |
| - {({ state, setState }) => ( |
107 |
| - <DataReceiver |
108 |
| - data={state.data} |
109 |
| - onStart={() => setState({ loading: true })} |
110 |
| - onFinish={data => setState({ data, loading: false })} |
111 |
| - /> |
112 |
| - )} |
113 |
| -</State> |
114 |
| -``` |
115 |
| - |
116 |
| -#### Toggle |
117 |
| - |
118 |
| -```jsx |
119 |
| -<Toggle initial={true}> |
120 |
| - {({ on, toggle }) => <Checkbox checked={on} onChange={toggle} />} |
121 |
| -</Toggle> |
122 |
| -``` |
123 |
| - |
124 |
| -#### Counter |
125 |
| - |
126 |
| -```jsx |
127 |
| -<Counter initial={0}> |
128 |
| - {({ count, inc, dec }) => ( |
129 |
| - <CartItem |
130 |
| - productName="Lorem ipsum" |
131 |
| - unitPrice={19.9} |
132 |
| - count={count} |
133 |
| - onAdd={inc} |
134 |
| - onRemove={dec} |
135 |
| - /> |
136 |
| - )} |
137 |
| -</Counter> |
138 |
| -``` |
139 |
| - |
140 |
| -#### Value |
141 |
| - |
142 |
| -```jsx |
143 |
| -<Value initial="React"> |
144 |
| - {({ value, set }) => ( |
145 |
| - <Select |
146 |
| - label="Choose one" |
147 |
| - options={['React', 'Angular', 'Vue']} |
148 |
| - value={value} |
149 |
| - onChange={set} |
150 |
| - /> |
151 |
| - )} |
152 |
| -</Value> |
153 |
| -``` |
154 |
| - |
155 |
| -#### Map |
156 |
| - |
157 |
| -```jsx |
158 |
| -<Map initial={{ sounds: true, graphics: 'medium' }}> |
159 |
| - {({ set, get }) => ( |
160 |
| - <Settings> |
161 |
| - <ToggleCheck checked={get('sounds')} onChange={c => set('sounds', c)}> |
162 |
| - Game Sounds |
163 |
| - </ToggleCheck> |
164 |
| - <Select |
165 |
| - label="Graphics" |
166 |
| - options={['low', 'medium', 'high']} |
167 |
| - selected={get('graphics')} |
168 |
| - onSelect={value => set('graphics', value)} |
169 |
| - /> |
170 |
| - </Settings> |
171 |
| - )} |
172 |
| -</Map> |
173 |
| -``` |
174 |
| - |
175 |
| -#### Set |
176 |
| - |
177 |
| -```jsx |
178 |
| -<Set initial={['react', 'babel']}> |
179 |
| - {({ values, remove, add }) => ( |
180 |
| - <TagManager> |
181 |
| - <FormInput onSubmit={add} /> |
182 |
| - {values.map(tag => <Tag onRemove={() => remove(tag)}>{tag}</Tag>)} |
183 |
| - </TagManager> |
184 |
| - )} |
185 |
| -</Set> |
186 |
| -``` |
187 |
| - |
188 |
| -#### List |
| 61 | +## Guide & Documentation |
189 | 62 |
|
190 |
| -```jsx |
191 |
| -<List initial={['Buy new shoes']}> |
192 |
| - {({ list, pull, push }) => ( |
193 |
| - <Todo> |
194 |
| - <TodoFormInput onSubmit={push} /> |
195 |
| - {list.map(todo => ( |
196 |
| - <TodoItem onDelete={() => pull(i => i === todo)}>{todo}</TodoItem> |
197 |
| - ))} |
198 |
| - </Todo> |
199 |
| - )} |
200 |
| -</List> |
201 |
| -``` |
202 |
| - |
203 |
| -#### Hover |
204 |
| - |
205 |
| -```jsx |
206 |
| -<Hover> |
207 |
| - {({ hovered, bind }) => ( |
208 |
| - <div {...bind}> |
209 |
| - You are {hovered ? 'hovering' : 'not hovering'} this div. |
210 |
| - </div> |
211 |
| - )} |
212 |
| -</Hover> |
213 |
| -``` |
214 |
| - |
215 |
| -#### Active |
216 |
| - |
217 |
| -```jsx |
218 |
| -<Active> |
219 |
| - {({ active, bind }) => ( |
220 |
| - <div {...bind}> |
221 |
| - You are {active ? 'clicking' : 'not clicking'} this div. |
222 |
| - </div> |
223 |
| - )} |
224 |
| -</Active> |
225 |
| -``` |
226 |
| - |
227 |
| -#### Touch |
228 |
| - |
229 |
| -```jsx |
230 |
| -<Touch> |
231 |
| - {({ touched, bind }) => ( |
232 |
| - <div {...bind}> |
233 |
| - You are {touched ? 'touching' : 'not touching'} this div. |
234 |
| - </div> |
235 |
| - )} |
236 |
| -</Touch> |
237 |
| -``` |
238 |
| - |
239 |
| -#### Focus |
240 |
| - |
241 |
| -```jsx |
242 |
| -<Focus> |
243 |
| - {({ focused, bind }) => ( |
244 |
| - <div> |
245 |
| - <input {...bind} placeholder="Focus me" /> |
246 |
| - <div>You are {focused ? 'focusing' : 'not focusing'} input.</div> |
247 |
| - </div> |
248 |
| - )} |
249 |
| -</Focus> |
250 |
| -``` |
251 |
| - |
252 |
| -#### Input |
253 |
| - |
254 |
| -```jsx |
255 |
| -<Input initial="hello world"> |
256 |
| - {({ bind, value }) => ( |
257 |
| - <div> |
258 |
| - <ControlledInput {...bind} /> |
259 |
| - <div>You typed {value}</div> |
260 |
| - </div> |
261 |
| - )} |
262 |
| -</Input> |
263 |
| -``` |
264 |
| - |
265 |
| -#### Form |
266 |
| - |
267 |
| -```jsx |
268 |
| -<Form initial={{ subject: '', message: '' }}> |
269 |
| - {({ input, values }) => ( |
270 |
| - <form |
271 |
| - onSubmit={e => { |
272 |
| - e.preventDefault() |
273 |
| - console.log(values) |
274 |
| - }} |
275 |
| - > |
276 |
| - <ControlledInput placeholder="Subject" {...input('subject').bind} /> |
277 |
| - <ControlledTextArea placeholder="Message" {...input('message').bind} /> |
278 |
| - <Submit>Send</Submit> |
279 |
| - </form> |
280 |
| - )} |
281 |
| -</Form> |
282 |
| -``` |
283 |
| - |
284 |
| -### Interval |
285 |
| - |
286 |
| -```jsx |
287 |
| -<Interval delay={1000}> |
288 |
| - {({ stop, start }) => ( |
289 |
| - <> |
290 |
| - <div>The time is now {new Date().toLocaleTimeString()}</div> |
291 |
| - <button onClick={() => stop()}>Stop interval</button> |
292 |
| - <button onClick={() => start()}>Start interval</button> |
293 |
| - </> |
294 |
| - )} |
295 |
| -</Interval> |
296 |
| -``` |
297 |
| - |
298 |
| -# Composing Components |
299 |
| - |
300 |
| -If you want to avoid 'render props hell' you can compose two or more components in a single one. |
301 |
| -**[:books: For complete guide, see docs](docs/components/Compose.md)** |
302 |
| - |
303 |
| -```jsx |
304 |
| -import { Compose } from 'react-powerplug' |
305 |
| - |
306 |
| -<Compose components={[Toggle, Counter]}> |
307 |
| - {(toggle, counter) => (/* ... */)} |
308 |
| -</Compose> |
309 |
| -``` |
310 |
| - |
311 |
| -```jsx |
312 |
| -import { compose } from 'react-powerplug' |
313 |
| - |
314 |
| -const ToggleCounter = compose( |
315 |
| - <Counter initial={5} />, |
316 |
| - <Toggle initial={false} /> |
317 |
| -) |
318 |
| - |
319 |
| -<ToggleCounter> |
320 |
| - {(toggle, counter) => ( |
321 |
| - <ProductCard {...} /> |
322 |
| - )} |
323 |
| -</ToggleCounter> |
324 |
| -``` |
| 63 | +http://rena.to/react-powerplug/ |
325 | 64 |
|
326 | 65 | ---
|
327 | 66 |
|
|
0 commit comments