Skip to content

Commit bc701aa

Browse files
committed
feat: add components.copied props.
1 parent e22f52c commit bc701aa

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

core/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ export default JsonView;
411411

412412
## Size and dependencies
413413

414-
Here is the size benchmark (using [bundlephobia.com](https://bundlephobia.com)) against similar React libraries (found by https://www.npmjs.com/search?q=react%20json&ranking=popularity):
414+
Here is the size benchmark (using [bundlephobia.com](https://bundlephobia.com)) against similar React libraries (found by [`npmjs.com/search`](https://www.npmjs.com/search?q=react%20json&ranking=popularity)):
415415

416416
| Library | Bundle size | Bundle size (gzip) | Deps | Last commit |
417417
| ------- | ------- | ------- | ------- | ------- |
@@ -420,8 +420,8 @@ Here is the size benchmark (using [bundlephobia.com](https://bundlephobia.com))
420420
| react-json-pretty | [![](https://img.shields.io/bundlephobia/min/react-json-pretty?color=red&label=)](https://bundlephobia.com/result?p=react-json-pretty) | [![](https://img.shields.io/bundlephobia/minzip/react-json-pretty?color=red&label=)](https://bundlephobia.com/result?p=react-json-pretty) | [![](https://badgen.net/bundlephobia/dependency-count/react-json-pretty?color=red&label=)](https://bundlephobia.com/result?p=react-json-pretty) | [![GitHub last commit](https://img.shields.io/github/last-commit/chenckang/react-json-pretty?style=flat&label=last)](https://github.com/chenckang/react-json-pretty/commits) |
421421
| react-json-inspector | [![](https://img.shields.io/bundlephobia/min/react-json-inspector?color=red&label=)](https://bundlephobia.com/result?p=react-json-inspector) | [![](https://img.shields.io/bundlephobia/minzip/react-json-inspector?color=red&label=)](https://bundlephobia.com/result?p=react-json-inspector) | [![](https://badgen.net/bundlephobia/dependency-count/react-json-inspector?color=red&label=)](https://bundlephobia.com/result?p=react-json-inspector) | [![GitHub last commit](https://img.shields.io/github/last-commit/Lapple/react-json-inspector?style=flat&label=last)](https://github.com/Lapple/react-json-inspector/commits) |
422422
| react-json-tree | [![](https://img.shields.io/bundlephobia/min/react-json-tree?color=red&label=)](https://bundlephobia.com/result?p=react-json-tree) | [![](https://img.shields.io/bundlephobia/minzip/react-json-tree?color=red&label=)](https://bundlephobia.com/result?p=react-json-tree) | [![](https://badgen.net/bundlephobia/dependency-count/react-json-tree?color=red&label=)](https://bundlephobia.com/result?p=react-json-tree) | [![GitHub last commit](https://img.shields.io/github/last-commit/reduxjs/redux-devtools?style=flat&label=last)](https://github.com/reduxjs/redux-devtools/commits) |
423-
| react-json-view | [![](https://img.shields.io/bundlephobia/min/react-json-view?color=red&label=)](https://bundlephobia.com/result?p=react-json-view) | [![](https://img.shields.io/bundlephobia/minzip/react-json-view?color=red&label=)](https://bundlephobia.com/result?p=react-json-view) | [![](https://badgen.net/bundlephobia/dependency-count/react-json-view?color=red&label=)](https://bundlephobia.com/result?p=react-json-view) | [![GitHub last commit](https://img.shields.io/github/last-commit/mac-s-g/react-json-view?style=flat&label=last)](https://github.com/mac-s-g/react-json-view/commits) |
424-
| react-json-tree-viewer | [![](https://img.shields.io/bundlephobia/min/react-json-tree-viewer?color=red&label=)](https://bundlephobia.com/result?p=react-json-tree-viewer) | [![](https://img.shields.io/bundlephobia/minzip/react-json-tree-viewer?color=red&label=)](https://bundlephobia.com/result?p=react-json-tree-viewer) | [![](https://badgen.net/bundlephobia/dependency-count/react-json-tree-viewer?color=red&label=)](https://bundlephobia.com/result?p=react-json-tree-viewer) | [![GitHub last commit](https://img.shields.io/github/last-commit/nsisodiya/react-json-viewer?style=flat&label=last)](https://github.com/nsisodiya/react-json-viewer/commits) |
423+
| react-json-view | [![](https://img.shields.io/bundlephobia/min/react-json-view?color=red&label=)](https://bundlephobia.com/result?p=react-json-view) | [![](https://img.shields.io/bundlephobia/minzip/react-json-view?color=red&label=)](https://bundlephobia.com/result?p=react-json-view) | [![](https://badgen.net/bundlephobia/dependency-count/react-json-view?color=red&label=&t=123)](https://bundlephobia.com/result?p=react-json-view) | [![GitHub last commit](https://img.shields.io/github/last-commit/mac-s-g/react-json-view?style=flat&label=last)](https://github.com/mac-s-g/react-json-view/commits) |
424+
| react-json-tree-viewer | [![](https://img.shields.io/bundlephobia/min/react-json-tree-viewer?color=red&label=)](https://bundlephobia.com/result?p=react-json-tree-viewer) | [![](https://img.shields.io/bundlephobia/minzip/react-json-tree-viewer?color=red&label=)](https://bundlephobia.com/result?p=react-json-tree-viewer) | [![](https://badgen.net/bundlephobia/dependency-count/react-json-tree-viewer?color=red&label=&t=123)](https://bundlephobia.com/result?p=react-json-tree-viewer) | [![GitHub last commit](https://img.shields.io/github/last-commit/nsisodiya/react-json-viewer?style=flat&label=last)](https://github.com/nsisodiya/react-json-viewer/commits) |
425425
| react-domify | [![](https://img.shields.io/bundlephobia/min/react-domify?color=red&label=)](https://bundlephobia.com/result?p=react-domify) | [![](https://img.shields.io/bundlephobia/minzip/react-domify?color=red&label=)](https://bundlephobia.com/result?p=react-domify) | [![](https://badgen.net/bundlephobia/dependency-count/react-domify?color=red&label=)](https://bundlephobia.com/result?p=react-domify) | [![GitHub last commit](https://img.shields.io/github/last-commit/JedWatson/react-domify?style=flat&label=last)](https://github.com/JedWatson/react-domify/commits) |
426426
| react18-json-view | [![](https://img.shields.io/bundlephobia/min/react18-json-view?color=red&label=)](https://bundlephobia.com/result?p=react18-json-view) | [![](https://img.shields.io/bundlephobia/minzip/react18-json-view?color=red&label=)](https://bundlephobia.com/result?p=react18-json-view) | [![](https://badgen.net/bundlephobia/dependency-count/react18-json-view?color=red&label=)](https://bundlephobia.com/result?p=react18-json-view) | [![GitHub last commit](https://img.shields.io/github/last-commit/YYsuni/react18-json-view?style=flat&label=last)](https://github.com/YYsuni/react18-json-view/commits) |
427427

core/src/copied.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { useState } from "react";
1+
import { useState } from 'react';
22

33
export interface CopiedProps<T = object> extends React.SVGProps<SVGSVGElement> {
44
show?: boolean;
55
text?: T;
6+
render?: (props: Omit<CopiedProps<T>, 'render'>) => JSX.Element;
67
}
78

89
export function Copied<T>(props: CopiedProps<T>) {
9-
const { children, style, text = '', show, ...reset } = props;
10+
const { children, style, text = '', render, show, ...reset } = props;
1011
if (!show) return null;
1112
const [copied, setCopied] = useState(false);
1213
const click = (event: React.MouseEvent<SVGSVGElement, MouseEvent>) => {
@@ -32,14 +33,15 @@ export function Copied<T>(props: CopiedProps<T>) {
3233
};
3334
const defalutStyle = { ...style, cursor: 'pointer', marginLeft: 5 } as React.CSSProperties;
3435
const svgProps: React.SVGProps<SVGSVGElement> = {
35-
height: "1em",
36-
width: "1em",
37-
fill: "var(--w-rjv-copied-color, currentColor)",
36+
height: '1em',
37+
width: '1em',
38+
fill: 'var(--w-rjv-copied-color, currentColor)',
3839
onClick: click,
3940
style: defalutStyle,
4041
className: 'w-rjv-copied',
4142
...reset,
4243
}
44+
if (render) return render({ ...props, ...svgProps });
4345
if (copied) {
4446
return (
4547
<svg viewBox="0 0 38 38" {...svgProps} fill="var(--w-rjv-copied-success-color, #28a745)">

core/src/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import React, { useId } from 'react';
22
import { forwardRef } from 'react';
33
import { RooNode, MetaProps, SemicolonProps, EllipsisProps } from './node';
44
import { ValueViewProps } from './value';
5+
import { CopiedProps } from './copied';
56

67
export * from './node';
78
export * from './value';
8-
export interface JsonViewProps<T>
9+
export interface JsonViewProps<T extends object>
910
extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
1011
/** This property contains your input JSON */
1112
value?: T;
@@ -28,6 +29,7 @@ export interface JsonViewProps<T>
2829
arrow?: JSX.Element;
2930
objectKey?: SemicolonProps['render'];
3031
value?: ValueViewProps<T>['renderValue'];
32+
copied?: CopiedProps<T>['render'];
3133
};
3234
}
3335

core/src/node.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const CountInfo: FC<PropsWithChildren<LabelProps>> = ({ children }) => (
7878
</Label>
7979
);
8080

81-
export interface RooNodeProps<T> extends JsonViewProps<T> {
81+
export interface RooNodeProps<T extends object> extends JsonViewProps<T> {
8282
keyName?: string | number;
8383
keyid?: string;
8484
}
@@ -127,7 +127,7 @@ export function RooNode<T extends object>(props: RooNodeProps<T>) {
127127
<TriangleArrow style={arrowStyle} />
128128
);
129129
const [showTools, setShowTools] = useState(false);
130-
const tools = enableClipboard ? <Copied show={showTools} text={value} /> : undefined;
130+
const tools = enableClipboard ? <Copied show={showTools} text={value as T} render={components.copied} /> : undefined;
131131
const mouseEnter = () => setShowTools(true);
132132
const mouseLeave = () => setShowTools(false);
133133
return (

0 commit comments

Comments
 (0)