Skip to content

Commit

Permalink
fix: fix shortenTextAfterLength props. #15
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Sep 21, 2023
1 parent 5fb4f29 commit e8ad00e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ export interface JsonViewProps<T> extends React.DetailedHTMLProps<React.HTMLAttr
displayDataTypes?: boolean;
/** When set to `true`, `objects` and `arrays` are labeled with size @default true */
displayObjectSize?: boolean;
/** Shorten long JSON strings, Set to `0` to disable this feature @default 20 */
/** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
shortenTextAfterLength?: number;
/** Define the root node name. @default undefined */
keyName?: string | number;
Expand Down
2 changes: 1 addition & 1 deletion core/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface JsonViewProps<T extends object>
displayDataTypes?: boolean;
/** When set to `true`, `objects` and `arrays` are labeled with size @default true */
displayObjectSize?: boolean;
/** Shorten long JSON strings, Set to `0` to disable this feature @default 20 */
/** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
shortenTextAfterLength?: number;
/** Define the root node name. @default undefined */
keyName?: string | number;
Expand Down
2 changes: 1 addition & 1 deletion core/src/node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const RootNode = forwardRef(
highlightUpdates = true,
objectSortKeys = false,
indentWidth = 15,
shortenTextAfterLength = 20,
shortenTextAfterLength = 30,
collapsed,
level = 1,
keyid = 'root',
Expand Down
8 changes: 3 additions & 5 deletions core/src/value.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FC, PropsWithChildren } from 'react';
import { Fragment, forwardRef, useMemo, useState } from 'react';
import { Fragment, forwardRef, useMemo, useEffect, useState } from 'react';
import { Meta } from './comps/meta';
import { Copied } from './copied';
import type { JsonViewProps } from './';
Expand Down Expand Up @@ -153,10 +153,8 @@ const RenderShortenTextValue: FC<PropsWithChildren<RenderStringValueProps>> = ({
}) => {
const childrenStr = children as string;
const [shorten, setShorten] = useState(length && childrenStr.length >= length);
const click = () => {
if (length && childrenStr.length <= length) return setShorten(false);
setShorten(!shorten);
};
useEffect(() => setShorten(length && childrenStr.length >= length), [length]);
const click = () => setShorten(!shorten);
const text = shorten ? `${childrenStr.slice(0, length)}...` : childrenStr;
return (
<RenderStringValue {...rest} style={{ ...style, cursor: 'pointer' }} onClick={click}>
Expand Down

0 comments on commit e8ad00e

Please sign in to comment.