Skip to content

Commit

Permalink
Add docz (#153)
Browse files Browse the repository at this point in the history
* minimal setup docz

* chore: remove and ignore docz build folder

* chore: add logo and primary color

* fix: update dependencies

* add more mdx to docz

* add Touch.mdx to docz

* add Hover.mdx to docz

* add Focus.mdx to docz

* add Active.mdx to docz

* add FocusManager.mdx to docz

* add State.mdx and Interval.mdx to docz

* add Form.mdx to docz

* add Counter.mdx to docz

* add Compose.mdx to docz

* add compose.mdx and composeEvents.mdx to docz

* add Introduction and Guide to docz

* add ordering to menus

* deployment scripts

* add setOn setOff to Toggle docs

* remove FocusManager.mdx

* edit readme
  • Loading branch information
renatorib committed Oct 16, 2018
1 parent 18d1365 commit a83c97c
Show file tree
Hide file tree
Showing 44 changed files with 5,659 additions and 2,560 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.flow
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.log
.docz
node_modules
dist
269 changes: 4 additions & 265 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<br />

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

## Highlights

- :ok_hand: Dependency free
- :electric_plug: Plug and play
- :crystal_ball: Tree shaking friendly (ESM, no side effects)
Expand Down Expand Up @@ -58,270 +58,9 @@ import { Pagination, Tabs, Checkbox } from './MyDumbComponents'

</details>

## ⚠️ Master is unstable

> This branch is **unstable** and is in **active development**.
> For the latest stable version go to [0.1-stable branch](https://github.com/renatorib/react-powerplug/tree/0.1-stable)
## Components

> **_Note_** _This is a kind of a cheat sheet for fast search._
> _If you want a more detailed **API Reference** and examples for each component see [full docs](/docs)_
| Component | Component Props | Render Props | |
| ---------------------------- | ----------------------- | ---------------------------------------------- | --------------------------------------------------------------------------- |
| <h6>STATE CONTAINERS</h6> |
| **\<State>** | `{ initial, onChange }` | `{ state, setState }` | [:point_down:](#state) [:books:](docs/components/State.md) |
| **\<Toggle>** | `{ initial, onChange }` | `{ on, toggle, set, setOn, setOff }` | [:point_down:](#toggle) [:books:](docs/components/Toggle.md) |
| **\<Counter>** | `{ initial, onChange }` | `{ count, inc, dec, incBy, decBy, set }` | [:point_down:](#counter) [:books:](docs/components/Counter.md) |
| **\<Value>** | `{ initial, onChange }` | `{ value, set }` | [:point_down:](#value) [:books:](docs/components/Value.md) |
| **\<Map>** | `{ initial, onChange }` | `{ set, get, over, values }` | [:point_down:](#map) [:books:](docs/components/Map.md) |
| **\<Set>** | `{ initial, onChange }` | `{ values, add, clear, remove, has }` | [:point_down:](#set) [:books:](docs/components/Set.md) |
| **\<List>** | `{ initial, onChange }` | `{ list, first, last, push, pull, sort, set }` | [:point_down:](#list) [:books:](docs/components/List.md) |
| <h6>FEEDBACK CONTAINERS</h6> |
| **\<Hover>** | `{ onChange }` | `{ hovered, bind }` | [:point_down:](#hover) [:books:](docs/components/Hover.md) |
| **\<Active>** | `{ onChange }` | `{ active, bind }` | [:point_down:](#active) [:books:](docs/components/Active.md) |
| **\<Focus>** | `{ onChange }` | `{ focused, bind }` | [:point_down:](#focus) [:books:](docs/components/Focus.md) |
| **\<Touch>** | `{ onChange }` | `{ touched, bind }` | [:point_down:](#touch) [:books:](docs/components/Touch.md) |
| <h6>FORM CONTAINERS</h6> |
| **\<Input>** | `{ initial, onChange }` | `{ set, value, bind }` | [:point_down:](#input) [:books:](docs/components/Input.md) |
| **\<Form>** | `{ initial, onChange }` | `{ input, values }` | [:point_down:](#form) [:books:](docs/components/Form.md) |
| <h6>OTHER</h6> |
| **\<Interval>** | `{ delay }` | `{ stop, start, toggle }` | [:point_down:](#interval) [:books:](docs/components/Interval.md) |
| **\<Compose>** | `{ components }` | _depends on components prop_ | [:point_down:](#composing-components) [:books:](docs/components/Compose.md) |

## Utilities

| Name | |
| ----------------------------- | -------------------------------------- |
| compose(...components) | [:books:](docs/utils/compose.md) |
| composeEvents(...objOfEvents) | [:books:](docs/utils/composeEvents.md) |

## Examples

#### State

```jsx
<State initial={{ loading: false, data: null }}>
{({ state, setState }) => (
<DataReceiver
data={state.data}
onStart={() => setState({ loading: true })}
onFinish={data => setState({ data, loading: false })}
/>
)}
</State>
```

#### Toggle

```jsx
<Toggle initial={true}>
{({ on, toggle }) => <Checkbox checked={on} onChange={toggle} />}
</Toggle>
```

#### Counter

```jsx
<Counter initial={0}>
{({ count, inc, dec }) => (
<CartItem
productName="Lorem ipsum"
unitPrice={19.9}
count={count}
onAdd={inc}
onRemove={dec}
/>
)}
</Counter>
```

#### Value

```jsx
<Value initial="React">
{({ value, set }) => (
<Select
label="Choose one"
options={['React', 'Angular', 'Vue']}
value={value}
onChange={set}
/>
)}
</Value>
```

#### Map

```jsx
<Map initial={{ sounds: true, graphics: 'medium' }}>
{({ set, get }) => (
<Settings>
<ToggleCheck checked={get('sounds')} onChange={c => set('sounds', c)}>
Game Sounds
</ToggleCheck>
<Select
label="Graphics"
options={['low', 'medium', 'high']}
selected={get('graphics')}
onSelect={value => set('graphics', value)}
/>
</Settings>
)}
</Map>
```

#### Set

```jsx
<Set initial={['react', 'babel']}>
{({ values, remove, add }) => (
<TagManager>
<FormInput onSubmit={add} />
{values.map(tag => <Tag onRemove={() => remove(tag)}>{tag}</Tag>)}
</TagManager>
)}
</Set>
```

#### List
## Guide & Documentation

```jsx
<List initial={['Buy new shoes']}>
{({ list, pull, push }) => (
<Todo>
<TodoFormInput onSubmit={push} />
{list.map(todo => (
<TodoItem onDelete={() => pull(i => i === todo)}>{todo}</TodoItem>
))}
</Todo>
)}
</List>
```

#### Hover

```jsx
<Hover>
{({ hovered, bind }) => (
<div {...bind}>
You are {hovered ? 'hovering' : 'not hovering'} this div.
</div>
)}
</Hover>
```

#### Active

```jsx
<Active>
{({ active, bind }) => (
<div {...bind}>
You are {active ? 'clicking' : 'not clicking'} this div.
</div>
)}
</Active>
```

#### Touch

```jsx
<Touch>
{({ touched, bind }) => (
<div {...bind}>
You are {touched ? 'touching' : 'not touching'} this div.
</div>
)}
</Touch>
```

#### Focus

```jsx
<Focus>
{({ focused, bind }) => (
<div>
<input {...bind} placeholder="Focus me" />
<div>You are {focused ? 'focusing' : 'not focusing'} input.</div>
</div>
)}
</Focus>
```

#### Input

```jsx
<Input initial="hello world">
{({ bind, value }) => (
<div>
<ControlledInput {...bind} />
<div>You typed {value}</div>
</div>
)}
</Input>
```

#### Form

```jsx
<Form initial={{ subject: '', message: '' }}>
{({ input, values }) => (
<form
onSubmit={e => {
e.preventDefault()
console.log(values)
}}
>
<ControlledInput placeholder="Subject" {...input('subject').bind} />
<ControlledTextArea placeholder="Message" {...input('message').bind} />
<Submit>Send</Submit>
</form>
)}
</Form>
```

### Interval

```jsx
<Interval delay={1000}>
{({ stop, start }) => (
<>
<div>The time is now {new Date().toLocaleTimeString()}</div>
<button onClick={() => stop()}>Stop interval</button>
<button onClick={() => start()}>Start interval</button>
</>
)}
</Interval>
```

# Composing Components

If you want to avoid 'render props hell' you can compose two or more components in a single one.
**[:books: For complete guide, see docs](docs/components/Compose.md)**

```jsx
import { Compose } from 'react-powerplug'

<Compose components={[Toggle, Counter]}>
{(toggle, counter) => (/* ... */)}
</Compose>
```

```jsx
import { compose } from 'react-powerplug'

const ToggleCounter = compose(
<Counter initial={5} />,
<Toggle initial={false} />
)

<ToggleCounter>
{(toggle, counter) => (
<ProductCard {...} />
)}
</ToggleCounter>
```
http://rena.to/react-powerplug/

---

Expand Down
49 changes: 49 additions & 0 deletions docs/Guide.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: Guide
route: /guide
order: 19
---

# Guide

## Creating a Dumb Component

Dumb Component, Presentational Component or (sometimes) Controlled Component is a component
responsible **only for displaying content without any logic behind**. Usually they
receive specific props, and if they are interactive, it exposes events like onClick, onChange, etc.

A Styled Component a good example.

```jsx
import React from "react";
import styled from "styled-components";

const DumbCheckbox = styled("div")`
cursor: pointer;
&:before {
content: '${props => (props.checked ? "" : "")} ';
}
`;

const App = () => (
<DumbCheckbox>Check me</DumbCheckbox>
);
```

## Using React PowerPlug

Now that you have your Dumb Component, you can pass state to it.
Using react-powerplug this step is trivial and pretty simple.

```jsx
import { Toggle } from "react-powerplug";

<Toggle>
{({ on, toggle }) => (
<DumbCheckbox checked={on} onClick={toggle}>
Check me
</DumbCheckbox>
)}
</Toggle>
```

53 changes: 53 additions & 0 deletions docs/Introduction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
name: Introduction
route: /
order: 20
---

# Introduction

**React PowerPlug is a set of pluggable renderless components and utils** that provides
different types of state and logics so you can use with your dumb components. It creates
a state and pass down the logic to the children, so you can handle your data.
Read about [Render Props](https://reactjs.org/docs/render-props.html) pattern.

- Dependency free
- Super tiny (~3kb)
- Plug and play
- Tree shaking friendly (ESM, no side effects)
- Well documented
- Bunch of awesome utilities

## Quick Examples

```jsx
import { State, Toggle } from 'react-powerplug'
import { Pagination, Tabs, Checkbox } from './MyDumbComponents'
```

```jsx
<State initial={{ offset: 0, limit: 10, totalCount: 200 }}>
{({ state, setState }) => (
<Pagination {...state} onChange={(offset) => setState({ offset })} />
)}
</State>
```

```jsx
<Toggle initial={true}>
{({ on, toggle }) => (
<Checkbox checked={on} onChange={toggle} />
)}
</Toggle>
```

You can also use a `render` prop instead

```jsx
<Toggle
initial={false}
render={({ on, toggle }) => (
<Checkbox checked={on} onChange={toggle} />
)}
/>
```
Loading

0 comments on commit a83c97c

Please sign in to comment.