mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-02-01 04:04:25 +03:00
6954eb9580
* Add Emotion to RTK Query monitor * Add other Emotion setup * Start transition * Convert more styling to Emotion * Convert more styling to Emotion * Finish convert styling to Emotion * import type * Fix test * Remove unused styling * Remove more unused styling * Remove more unused styling * Remove jss * Cleanup * Create perfect-otters-help.md * Update perfect-otters-help.md
95 lines
2.4 KiB
TypeScript
95 lines
2.4 KiB
TypeScript
import { createSelector, Selector } from '@reduxjs/toolkit';
|
|
import React, { ComponentProps, ReactNode } from 'react';
|
|
import { JSONTree } from 'react-json-tree';
|
|
import { Base16Theme } from 'react-base16-styling';
|
|
import { getJsonTreeTheme, StyleUtilsContext } from '../styles/themes';
|
|
import { getItemString, labelRenderer } from '../styles/tree';
|
|
import { identity } from '../utils/object';
|
|
|
|
export interface TreeViewProps
|
|
extends Partial<
|
|
Pick<
|
|
ComponentProps<typeof JSONTree>,
|
|
'keyPath' | 'shouldExpandNodeInitially' | 'hideRoot'
|
|
>
|
|
> {
|
|
data: unknown;
|
|
isWideLayout: boolean;
|
|
before?: ReactNode;
|
|
after?: ReactNode;
|
|
children?: ReactNode;
|
|
rootProps?: Partial<
|
|
Omit<React.HTMLAttributes<HTMLDivElement>, 'className' | 'style'>
|
|
>;
|
|
}
|
|
|
|
export class TreeView extends React.PureComponent<TreeViewProps> {
|
|
static defaultProps = {
|
|
hideRoot: true,
|
|
shouldExpandNodeInitially: (
|
|
keyPath: (string | number)[],
|
|
value: unknown,
|
|
layer: number,
|
|
): boolean => {
|
|
return layer < 2;
|
|
},
|
|
};
|
|
|
|
readonly selectTheme: Selector<
|
|
Base16Theme,
|
|
ReturnType<typeof getJsonTreeTheme>,
|
|
never
|
|
> = createSelector<
|
|
[(base16Theme: Base16Theme) => Base16Theme],
|
|
ReturnType<typeof getJsonTreeTheme>
|
|
>(identity, getJsonTreeTheme);
|
|
|
|
constructor(props: TreeViewProps) {
|
|
super(props);
|
|
}
|
|
|
|
render(): ReactNode {
|
|
const {
|
|
data,
|
|
before,
|
|
after,
|
|
children,
|
|
keyPath,
|
|
shouldExpandNodeInitially,
|
|
hideRoot,
|
|
rootProps,
|
|
} = this.props;
|
|
|
|
return (
|
|
<StyleUtilsContext.Consumer>
|
|
{({ invertTheme, base16Theme }) => {
|
|
return (
|
|
<div
|
|
{...rootProps}
|
|
css={{
|
|
overflowX: 'auto',
|
|
overflowY: 'auto',
|
|
padding: '0.5em 1em',
|
|
}}
|
|
>
|
|
{before}
|
|
<JSONTree
|
|
keyPath={keyPath}
|
|
shouldExpandNodeInitially={shouldExpandNodeInitially}
|
|
data={data}
|
|
labelRenderer={labelRenderer}
|
|
theme={this.selectTheme(base16Theme)}
|
|
invertTheme={invertTheme}
|
|
getItemString={getItemString}
|
|
hideRoot={hideRoot}
|
|
/>
|
|
{after}
|
|
{children}
|
|
</div>
|
|
);
|
|
}}
|
|
</StyleUtilsContext.Consumer>
|
|
);
|
|
}
|
|
}
|