Skip to content
This repository was archived by the owner on May 15, 2022. It is now read-only.

Commit cadb831

Browse files
Merge branch 'feature/update-readme' into develop
2 parents fa59c4f + 5389aab commit cadb831

File tree

6 files changed

+537
-17
lines changed

6 files changed

+537
-17
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ indent_size = 2
1616
indent_size = 2
1717
indent_style = space
1818

19+
[*.md]
20+
indent_size = 2
21+
indent_style = space
22+
1923
[*.scss]
2024
indent_size = 2
2125
indent_style = space

README.md

Lines changed: 241 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,258 @@
11
# React dat.GUI
22

3-
Currently very much under construction.
3+
This is a fully[*](#whats-missing) featured React port of Google's esteemed [dat.GUI](https://workshop.chromeexperiments.com/examples/gui/#1--Basic-Usage) controller library. It comes packed with all the core components you'll need to cleanly integrate dat.GUIs into your React app.
4+
5+
For those that haven't used or seen dat.GUI before, it's basically a GUI for updating and interacting with objects in real time. It's used extensively in canvas or WebGL rendering demos/apps for libraries such as [three.js](http://threejs.org) but it can also be used to build browser based editing software.
6+
7+
## TOC
8+
9+
- [Demo](#demo)
10+
- [Installation](#installation)
11+
- [Usage](#usage)
12+
- [Docs](#docs)
13+
* [`DatGui`](#datgui)
14+
+ [props](#props)
15+
* [Components](#components)
16+
+ [Common props](#common-props)
17+
+ [`DatBoolean`](#datboolean)
18+
+ [`DatButton`](#datbutton)
19+
+ [`DatColor`](#datcolor)
20+
+ [`DatFolder`](#datfolder)
21+
+ [`DatNumber`](#datnumber)
22+
+ [`DatPresets`](#datpresets)
23+
+ [`DatSelect`](#datselect)
24+
+ [`DatString`](#datstring)
25+
- [Scripts](#scripts)
26+
+ [`build`](#build)
27+
+ [`dev`](#dev)
28+
+ [`dev:migrate`](#devmigrate)
29+
+ [`dev:promote`](#devpromote)
30+
+ [`example`](#example)
31+
+ [`example:deploy`](#exampledeploy)
32+
+ [`test`](#test)
33+
+ [`test:watch`](#testwatch)
34+
+ [`lint`](#lint)
35+
+ [`lint:fix`](#lintfix)
36+
+ [`toc`](#toc)
37+
- [What's missing](#whats-missing)
38+
- [Roadmap](#roadmap)
439

540
## Demo
641

7-
https://react-dat-gui.herokuapp.com/
42+
[Checkout the demo!](https://rohan-deshpande.github.io/react-dat-gui/)
43+
44+
The demo is a deployed version of the latest production build of `./example`. There's also a `dev` directory where you can prototype changes to the source code easily. Both of these have been bootstrapped with `create-react-app`.
845

946
## Installation
1047

1148
```
12-
npm install react-dat-gui --save
49+
npm i -S react-dat-gui
1350
```
1451

1552
## Usage
1653

54+
First you'll need a wrapper component which will handle the updates from your dat.GUI, this component should pass the data for the GUI to control as well as an `onUpdate` function to the `DatGui` container component as props. Here's how you might do that:
55+
1756
```
18-
<Dat data={this.state.data} onUpdate={this.handleUpdate}>
19-
<DatString path="string" label="String" />
20-
<DatNumber path="number" label="Number" min={0} max={100} step={1} />
21-
<DatBoolean path="boolean" label="Boolean" />
22-
<DatButton label="Button" onClick={this.handleClick} />
23-
</Dat>
57+
import '../node_modules/react-dat-gui/build/react-dat-gui.css';
58+
import React, { Component } from 'react';
59+
60+
import DatGui, { DatBoolean, DatButton, DatNumber, DatString } from 'react-dat-gui';
61+
62+
class App extends Component {
63+
state = {
64+
data: {
65+
package: 'react-dat-gui',
66+
power: 9000,
67+
isAwesome: true,
68+
feelsLike: '#2FA1D6',
69+
}
70+
}
71+
72+
update = data => this.setState({ data })
73+
74+
render() {
75+
const { data } = this.state;
76+
77+
return (
78+
<DatGui data={data} onUpdate={this.update}>
79+
<DatString path='package' label='Package' />
80+
<DatNumber path='power' label='Power' min={9000} max={9999} step={1} />
81+
<DatBoolean path='isAwesome' label='Awesome?' />
82+
<DatColor path='feelsLike' label='Feels Like' />
83+
</DatGui>
84+
)
85+
}
2486
```
2587

26-
## CSS
88+
This will give you a dat.GUI controller which can perform live mutations to the `data` in the `App` component's state.
89+
90+
## Docs
91+
92+
### `DatGui`
93+
94+
This is the main container component for your GUI and is the default export from the package.
95+
96+
#### props
97+
98+
##### required
99+
100+
* `data` - The data your dat.GUI controller will mutate
101+
* `onUpdate` - The method which will be called whenever an update is handled by the controller
102+
* `children` - The dat.GUI components that make up the controller
103+
104+
##### optional
105+
106+
* `liveUpdate` - Determines if live updates should occur, defaults to `true`
107+
* `labelWidth` - The width of the labels in pixels, defaults to `40`
108+
* `className` - The class name to set on the `DatGui` div
109+
* `style` - The style object to set on the `DatGui` div
110+
111+
### Components
112+
113+
All of the `react-dat-gui` components should be rendered as children of your `DatGui` parent component.
114+
115+
#### Common props
116+
117+
These components will have a number of props implicitly passed to them via the `DatGui` parent component's `renderChildren` method, but can also require other props to be passed explicitly to them.
118+
119+
Below are docs for the required and optional props you can pass to each component. Check the `renderChildren` method of `src/index.js` to see which other props are passed down implicitly.
120+
121+
##### required
122+
123+
* `path: string` - the path to the value within the `data` object which the component will control, eg., considering your object was `{ foo: 'bar' }`: `<DatString path='foo' />`
124+
* Note, this prop is not required for the following components
125+
* `DatButton`
126+
* `DatFolder`
127+
* `DatPresets`
128+
129+
##### optional
130+
131+
* `label: string` - the label for the controller eg., `<DatString path='message' label='Message' />`
132+
133+
#### `DatBoolean`
134+
135+
Used for controlling boolean values. Renders a checkbox input element.
136+
137+
#### `DatButton`
138+
139+
Can be used for performing any kind of function. Simply pass an `onClick` prop to the component and it will fire whenever the rendered element is clicked.
140+
141+
##### props
142+
143+
###### required
144+
145+
* `onClick :func` - the function to perform with the rendered element is clicked
146+
147+
#### `DatColor`
148+
149+
Uses [`react-color`](https://github.com/casesandberg/react-color/) to render a color picker component that will control color values.
150+
151+
#### `DatFolder`
152+
153+
Component which wraps other components to render them within an expandable/collapsable nested folder.
154+
155+
##### props
156+
157+
###### required
158+
159+
* `title: string` - The folder title eg., `<DatFolder title='MyAwesomeFolder' />`
160+
* `children: array` - The child components to render
161+
162+
#### `DatNumber`
163+
164+
A number component for updating numeric values. Will render a slider if `min`, `max` and `step` props are supplied.
165+
166+
##### props
167+
168+
###### optional
169+
170+
* `min: number` - The minimum range for the number
171+
* `max: number` - The maximum range for the number
172+
* `step: number` - The amount the number should increment each tick
173+
174+
#### `DatPresets`
175+
176+
Presets for the object which your `DatGui` is controlling can be supplied to this component as items in its `options` prop. A select field will be rendered which will allow you to easily switch between the presets.
177+
178+
Each item in this array will need to be in the format `{ 'presetName': ...data, ...preset }` where `...data` is your initial data and `...preset` is your preset.
179+
180+
##### props
181+
182+
###### required
183+
184+
* `options: array` - An array of objects, each in the format `{ 'presetName': ...data, ...preset }`
185+
186+
#### `DatSelect`
187+
188+
A select component for updating a value with one of the options supplied via the `options` prop. The original value from the `path` will always be added to the passed options array as the first item.
189+
190+
##### props
191+
192+
###### required
193+
194+
* `options: array` - A simple array of options to select from eg., `<DatSelect path='fruits' options={['apple', 'orange', 'pear']} />`
195+
196+
#### `DatString`
197+
198+
A simple text input component that can be used to mutate strings.
199+
200+
## Scripts
201+
202+
There are a few NPM scripts in the root `package.json` for developing changes to the repo's source code as well as running tests and deploying the demo.
203+
204+
#### `build`
205+
206+
Builds the package for publishing.
207+
208+
#### `dev`
209+
210+
Runs the app in `./dev`.
211+
212+
#### `dev:migrate`
213+
214+
Migrates the code in `./src` to `./dev/src/react-dat-gui`. Handy for making sure you're developing with the latest source code.
215+
216+
#### `dev:promote`
217+
218+
Promotes the code in `./dev/src/react-dat-gui` back up to the root of the repo. Use this when you're happy with the changes you've been developing.
219+
220+
#### `example`
221+
222+
Runs the app in `./example`.
223+
224+
#### `example:deploy`
225+
226+
Deploys the production build of the app in `./example` to the `gh-pages` branch of this repo.
227+
228+
#### `test`
229+
230+
Runs unit tests.
231+
232+
#### `test:watch`
233+
234+
Runs unit tests and watches for changes.
235+
236+
#### `lint`
237+
238+
Runs `eslint` on the supplied path.
239+
240+
#### `lint:fix`
241+
242+
Runs `eslint --fix` on the supplied path.
243+
244+
#### `toc`
245+
246+
Prints the `README.md` table of contents into the console.
247+
248+
## What's missing
249+
250+
There are still a few features from the original implementation missing from this package. These are mainly related to saving and loading data as well as local storage. Animations for folder expanding/collapsing is also not currently implemented, but shouldn't be too hard to do.
251+
252+
For the first, I think the fact that this is now an NPM module sort of goes against it handling this sort of stuff. Google's original concept was basically a plug and play controller that could do everything if you just slam it into the browser and pass it an object. However, in module form, it's expected that you'll most likely be integrating this with an existing application. In that case, you'll probably have pretty specific needs around how you would like to save/load data into your GUI and so it's been left out for now.
253+
254+
Local storage however is in the roadmap and will probably be done very soon.
27255

28-
* SCSS: `./src/Dat.scss`
29-
* CSS: `./lib/Dat.css`
30-
* CSS minified: `./build/react-dat-gui.min.css`
256+
## Roadmap
257+
* Loading and storing both default and preset data via `localStorage`
258+
* Time travel with undo/redo buttons (edited)

example/package-lock.json

Lines changed: 61 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "react-dat-gui-example",
3+
"homepage": "https://rohan-deshpande.github.io/react-dat-gui",
34
"version": "0.1.0",
45
"private": true,
56
"dependencies": {
@@ -12,6 +13,11 @@
1213
"start": "react-scripts start",
1314
"build": "react-scripts build",
1415
"test": "react-scripts test --env=jsdom",
15-
"eject": "react-scripts eject"
16+
"eject": "react-scripts eject",
17+
"predeploy": "npm run build",
18+
"deploy": "gh-pages -d build"
19+
},
20+
"devDependencies": {
21+
"gh-pages": "^1.0.0"
1622
}
1723
}

0 commit comments

Comments
 (0)