diff --git a/README.md b/README.md index 560e475..548fe4a 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ import ReactJsonView from '@microlink/react-json-view' | `onAdd` | `(add)=>{}` | `false` | When a callback function is passed in, `add` functionality is enabled. The callback is invoked before additions are completed. Returning `false` from `onAdd` will prevent the change from being made. [see: onAdd docs](#onedit-onadd-and-ondelete-interaction) | | `defaultValue` | `string \| number \| boolean \| array \| object` | `null` | Sets the default value to be used when adding an item to JSON. | | `onDelete` | `(delete)=>{}` | `false` | When a callback function is passed in, `delete` functionality is enabled. The callback is invoked before deletions are completed. Returning `false` from `onDelete` will prevent the change from being made. [see: onDelete docs](#onedit-onadd-and-ondelete-interaction) | -| `onSelect` | `(select)=>{}` | `false` | When a function is passed in, clicking a value triggers the `onSelect` method to be called. | +| `onSelect` | `(select)=>{}` | `false` | When a function is passed in, clicking a value or a key triggers the `onSelect` method to be called. | | `sortKeys` | `boolean` | `false` | Set to `true` to sort object keys. | | `quotesOnKeys` | `boolean` | `true` | Set to `false` to remove quotes from keys (e.g., `"name":` vs. `name:`). | | `validationMessage` | `string` | "Validation Error" | Custom message for validation failures to `onEdit`, `onAdd`, or `onDelete` callbacks. | diff --git a/docs/src/js/components/Demo.js b/docs/src/js/components/Demo.js index 8fa9edd..7ef8307 100644 --- a/docs/src/js/components/Demo.js +++ b/docs/src/js/components/Demo.js @@ -4,7 +4,6 @@ import ReactJson from './../../../../src/js/index' import Code from './../helpers/Code' import './../../style/scss/rjv-demo.scss' -import 'react-select/dist/react-select.css' // index entrypoint component class Demo extends React.PureComponent { @@ -24,6 +23,7 @@ class Demo extends React.PureComponent { onAdd: true, onEdit: true, onDelete: true, + onSelect: true, displayObjectSize: true, enableClipboard: true, indentWidth: 4, @@ -88,7 +88,7 @@ class Demo extends React.PureComponent { componentDidMount () { this.updateStyles() - this.observer = new MutationObserver(this.updateStyles) + this.observer = new window.MutationObserver(this.updateStyles) this.observer.observe(document.querySelector('.react-json-view'), { attributes: true, childList: true, @@ -129,6 +129,7 @@ class Demo extends React.PureComponent { onAdd, onEdit, onDelete, + onSelect, displayObjectSize, enableClipboard, theme, @@ -157,21 +158,6 @@ class Demo extends React.PureComponent { .react-json-view { border: 1px solid ${this.state.siteTheme.borderColor}; } - - .Select-control, - .Select.is-open>.Select-control, - .Select-option, - .Select-option.is-selected, - .Select-option.is-focused { - background-color: ${this.state.siteTheme.bgColor}; - color: ${this.state.siteTheme.color}; - } - .Select-option.is-focused { - opacity: 0.8; - } - .Select.has-value.Select--single>.Select-control .Select-value .Select-value-label, .Select.has-value.is-pseudo-focused.Select--single>.Select-control .Select-value .Select-value-label { - color: ${this.state.siteTheme.color}; - } `} )} @@ -210,6 +196,13 @@ class Demo extends React.PureComponent { } : false } + onSelect={ + onSelect + ? e => { + console.log(e) + } + : false + } displayObjectSize={displayObjectSize} enableClipboard={enableClipboard} indentWidth={indentWidth} @@ -253,6 +246,10 @@ class Demo extends React.PureComponent {
ctrl/cmd + click enter edit mode
@@ -293,7 +290,7 @@ class Demo extends React.PureComponent {
)
}
- if (on_add_enabled) {
+ if (onAddEnabled) {
notes.push(
When adding a new key, try Enter to submit
@@ -314,8 +311,8 @@ class Demo extends React.PureComponent {