redux-devtools/packages/react-json-tree/src/JSONIterableNode.tsx
Nathan Bierema bbb1a40395
Convert React packages to ESM (#1650)
* react-base16-styling

* Use inline react-base16-styling themes

* Fix

* Format

* Fix

* Fixes

* Transform more

* react-json-tree

* Update lock

* Remove unnecessary

* react-dock

* Move to dep

* Lock

* Fix

* Fix

* Create tame-eagles-relax.md
2024-04-07 21:04:45 +00:00

42 lines
1.0 KiB
TypeScript

import React from 'react';
import JSONNestedNode from './JSONNestedNode.js';
import type { CommonInternalProps } from './types.js';
// Returns the "n Items" string for this node,
// generating and caching it if it hasn't been created yet.
function createItemString(data: any, limit: number) {
let count = 0;
let hasMore = false;
if (Number.isSafeInteger(data.size)) {
count = data.size;
} else {
// eslint-disable-next-line no-unused-vars
for (const entry of data) {
if (limit && count + 1 > limit) {
hasMore = true;
break;
}
count += 1;
}
}
return `${hasMore ? '>' : ''}${count} ${count !== 1 ? 'entries' : 'entry'}`;
}
interface Props extends CommonInternalProps {
data: unknown;
nodeType: string;
}
// Configures <JSONNestedNode> to render an iterable
export default function JSONIterableNode(props: Props) {
return (
<JSONNestedNode
{...props}
nodeType="Iterable"
nodeTypeIndicator="()"
createItemString={createItemString}
expandable
/>
);
}