redux-devtools/packages/react-json-tree/src/JSONArrayNode.tsx
Nathan Bierema 40ac89aff9
feature(react-json-tree): convert react-json-tree to TypeScript (#601)
* eslint base

* stash

* setup

* stash

* stash

* Add jest.config.js

* caught
2020-08-21 20:13:24 -04:00

36 lines
920 B
TypeScript

import React from 'react';
import PropTypes from 'prop-types';
import JSONNestedNode from './JSONNestedNode';
import { CircularPropsPassedThroughJSONNode } from './types';
// Returns the "n Items" string for this node,
// generating and caching it if it hasn't been created yet.
function createItemString(data: any) {
return `${(data as unknown[]).length} ${
(data as unknown[]).length !== 1 ? 'items' : 'item'
}`;
}
interface Props extends CircularPropsPassedThroughJSONNode {
data: any;
nodeType: string;
}
// Configures <JSONNestedNode> to render an Array
const JSONArrayNode: React.FunctionComponent<Props> = ({ data, ...props }) => (
<JSONNestedNode
{...props}
data={data}
nodeType="Array"
nodeTypeIndicator="[]"
createItemString={createItemString}
expandable={data.length > 0}
/>
);
JSONArrayNode.propTypes = {
data: PropTypes.array,
};
export default JSONArrayNode;