|
1 | 1 | # React dat.GUI
|
2 | 2 |
|
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. |
4 | 4 |
|
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. |
6 | 6 |
|
7 | 7 | ## Demo
|
8 | 8 |
|
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`. |
10 | 12 |
|
11 | 13 | ## Installation
|
12 | 14 |
|
13 | 15 | ```
|
14 | 16 | npm i -S react-dat-gui
|
15 |
| -
|
16 | 17 | ```
|
17 | 18 |
|
18 | 19 | ## Usage
|
19 | 20 |
|
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: |
21 | 22 |
|
22 | 23 | ```
|
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 | + } |
24 | 53 | ```
|
25 | 54 |
|
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. |
28 | 56 |
|
29 | 57 | ## Components
|
30 | 58 |
|
31 |
| -### DatGui |
| 59 | +### `DatGui` |
32 | 60 |
|
33 | 61 | This is the main container component for your GUI.
|
34 | 62 |
|
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 |
36 | 107 |
|
37 |
| -A simple string component that can be used |
| 108 | +### `DatFolder` |
| 109 | + |
| 110 | +todo |
| 111 | + |
| 112 | +#### props |
| 113 | + |
| 114 | +##### required |
| 115 | + |
| 116 | +##### optional |
38 | 117 |
|
39 | 118 | ### DatNumber
|
40 | 119 |
|
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 |
42 | 141 |
|
43 | 142 | #### props
|
44 | 143 |
|
| 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 | + |
45 | 158 | ## What's missing
|
46 | 159 |
|
47 | 160 | 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