UNPKG

1.84 kBJavaScriptView Raw
1// ES6 + inline style port of JSONViewer https://bitbucket.org/davevedder/react-json-viewer/
2// all credits and original code to the author
3// Dave Vedder <veddermatic@gmail.com> http://www.eskimospy.com/
4// port by Daniele Zannotti http://www.github.com/dzannotti <dzannotti@me.com>
5import React, { useMemo } from 'react';
6import { invertTheme } from 'react-base16-styling';
7import JSONNode from './JSONNode.js';
8import createStylingFromTheme from './createStylingFromTheme.js';
9const identity = (value) => value;
10const expandRootNode = (keyPath, data, level) => level === 0;
11const defaultItemString = (type, data, itemType, itemString) => (React.createElement("span", null,
12 itemType,
13 " ",
14 itemString));
15const defaultLabelRenderer = ([label]) => React.createElement("span", null,
16 label,
17 ":");
18const noCustomNode = () => false;
19export function JSONTree({ data: value, theme, invertTheme: shouldInvertTheme, keyPath = ['root'], labelRenderer = defaultLabelRenderer, valueRenderer = identity, shouldExpandNodeInitially = expandRootNode, hideRoot = false, getItemString = defaultItemString, postprocessValue = identity, isCustomNode = noCustomNode, collectionLimit = 50, sortObjectKeys = false, }) {
20 const styling = useMemo(() => createStylingFromTheme(shouldInvertTheme ? invertTheme(theme) : theme), [theme, shouldInvertTheme]);
21 return (React.createElement("ul", { ...styling('tree') },
22 React.createElement(JSONNode, { keyPath: hideRoot ? [] : keyPath, value: postprocessValue(value), isCustomNode: isCustomNode, styling: styling, labelRenderer: labelRenderer, valueRenderer: valueRenderer, shouldExpandNodeInitially: shouldExpandNodeInitially, hideRoot: hideRoot, getItemString: getItemString, postprocessValue: postprocessValue, collectionLimit: collectionLimit, sortObjectKeys: sortObjectKeys })));
23}