/** * Copyright 2018-present Facebook. * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * @format */ import { isColorLike } from '@o/color' import React, { PureComponent } from 'react' import { DataInspectorControlled, DataInspectorExpanded, DataValueExtractor } from './DataInspectorControlled' type DataInspectorProps = { /** * Object to inspect. */ data: any /** * Object to compare with the provided `data` property. * Differences will be styled accordingly in the UI. */ diff?: any /** * Whether to expand the root by default. */ expandRoot?: boolean /** * An optional callback that will explode a value into its type and value. * Useful for inspecting serialised data. */ extractValue?: DataValueExtractor /** * Callback when a value is edited. */ setValue?: (path: Array, val: any) => void /** * Whether all objects and arrays should be collapsed by default. */ collapsed?: boolean /** * Object of all properties that will have tooltips */ tooltips?: Object } type DataInspectorState = { expanded: DataInspectorExpanded } /** * Wrapper around `DataInspector` that handles expanded state. * * If you require lower level access to the state then use `DataInspector` * directly. */ export class DataInspector extends PureComponent { constructor(props: DataInspectorProps, context: Object) { super(props, context) this.state = { expanded: {}, } } onExpanded = (expanded: DataInspectorExpanded) => { this.setState({ expanded }) } extractValue = value => { if (typeof value === 'string' && isColorLike(value)) { return { type: 'color', value, mutable: true, } } } setValue = (a, b) => { console.log(a, b) } render() { return ( ) } }