Line data Source code
1 : import * as React from 'react';
2 : import * as styles from './json_view.module.css';
3 : import { useJsonViewerState } from './json_view_state.js';
4 :
5 : export interface CountInfoCompProps<T extends object> {
6 : value?: T;
7 : }
8 :
9 1 : export function JsonItemCount<T extends object>(
10 1 : props: CountInfoCompProps<T> & React.HTMLAttributes<HTMLElement>,
11 1 : ) {
12 1 : const { displayObjectSize } = useJsonViewerState();
13 1 : if (!displayObjectSize) return null;
14 :
15 1 : const len = Object.keys(props.value ?? {}).length;
16 1 : const children = `${len} item${len === 1 ? '' : 's'}`;
17 :
18 1 : return (
19 1 : <span className={styles.item_count}>
20 1 : {children}
21 1 : </span>
22 : );
23 1 : };
|