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

Commit 6df865e

Browse files
Added usage example and more component docs
1 parent e3d8e54 commit 6df865e

File tree

2 files changed

+129
-12
lines changed

2 files changed

+129
-12
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: 125 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,160 @@
11
# React dat.GUI
22

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 a `dat.GUI` into your React app.
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.
44

5-
For those that haven't used or seen dat.GUI before, it's basically an object mutation GUI. 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.
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.
66

77
## Demo
88

9-
http://rohandeshpande.com/react-dat-gui
9+
[Checkout the demo!](http://rohandeshpande.com/react-dat-gui)
10+
11+
The demo is a deployed version of the latest production build of `./example`.
1012

1113
## Installation
1214

1315
```
1416
npm i -S react-dat-gui
15-
1617
```
1718

1819
## Usage
1920

20-
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. These props are then passed down to all children.
21+
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:
2122

2223
```
23-
// TODO code sample
24+
import '../node_modules/react-dat-gui/build/react-dat-gui.css';
25+
import React, { Component } from 'react';
26+
27+
import DatGui, { DatBoolean, DatButton, DatNumber, DatString } from 'react-dat-gui';
28+
29+
class App extends Component {
30+
state = {
31+
data: {
32+
package: 'react-dat-gui',
33+
power: 9000,
34+
isAwesome: true,
35+
feelsLike: '#2FA1D6',
36+
}
37+
}
38+
39+
update = data => this.setState({ data })
40+
41+
render() {
42+
const { data } = this.state;
43+
44+
return (
45+
<DatGui data={data} onUpdate={this.update}>
46+
<DatString path='package' label='Package' />
47+
<DatNumber path='power' label='Power' min={9000} max={9999} step={1} />
48+
<DatBoolean path='isAwesome' label='Awesome?' />
49+
<DatColor path='feelsLike' label='Feels Like' />
50+
</DatGui>
51+
)
52+
}
2453
```
2554

26-
27-
Any updates will update the state of the `DatGui` component and trigger whatever else needs to happen in your `onUpdate` method.
55+
This will give you a dat.GUI controller which can perform live mutations to the `data` in the `App` component's state.
2856

2957
## Components
3058

31-
### DatGui
59+
### `DatGui`
3260

3361
This is the main container component for your GUI.
3462

35-
### `DatString`
63+
#### props
64+
65+
##### required
66+
67+
* `data` - The data your dat.GUI controller will mutate
68+
* `onUpdate` - The method which will be called whenever an update is handled by the controller
69+
* `children` - The dat.GUI components that make up the controller
70+
71+
##### optional
72+
73+
* `liveUpdate` - Determines if live updates should occur, defaults to `true`
74+
* `labelWidth` - The width of the labels in pixels, defaults to `40`
75+
* `className` - The class name to set on the `DatGui` div
76+
* `style` - The style object to set on the `DatGui` div
77+
78+
### `DatBoolean`
79+
80+
todo
81+
82+
#### props
83+
84+
##### required
85+
86+
##### optional
87+
88+
### `DatButton`
89+
90+
todo
91+
92+
#### props
93+
94+
##### required
95+
96+
##### optional
97+
98+
### `DatColor`
99+
100+
todo
101+
102+
#### props
103+
104+
##### required
105+
106+
##### optional
36107

37-
A simple string component that can be used
108+
### `DatFolder`
109+
110+
todo
111+
112+
#### props
113+
114+
##### required
115+
116+
##### optional
38117

39118
### DatNumber
40119

41-
A number component, for updating numeric values.
120+
A number component for updating numeric values. Will render a slider if `min`, `max` and `step` props are supplied.
121+
122+
#### props
123+
124+
##### required
125+
126+
##### optional
127+
128+
### `DatPresets`
129+
130+
todo
131+
132+
#### props
133+
134+
##### required
135+
136+
##### optional
137+
138+
### `DatSelect`
139+
140+
todo
42141

43142
#### props
44143

144+
##### required
145+
146+
##### optional
147+
148+
### `DatString`
149+
150+
A simple text input component that can be used to mutate strings.
151+
152+
#### props
153+
154+
##### required
155+
156+
##### optional
157+
45158
## What's missing
46159

47160
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. 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, 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. Local storage however is in the roadmap and will probably be done very soon.

0 commit comments

Comments
 (0)