Skip to content

Commit 734b41c

Browse files
committed
feat: add stringEllipsis props. #69
1 parent 725c4ce commit 734b41c

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

core/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,8 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
887887
highlightUpdates?: boolean;
888888
/** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
889889
shortenTextAfterLength?: number;
890+
/** When the text exceeds the length, `...` will be displayed. Currently, this `...` can be customized. @default "..." */
891+
stringEllipsis?: number;
890892
/** Callback function for when a treeNode is expanded or collapsed */
891893
onExpand?: (props: { expand: boolean; value?: T; keyid: string; keyName?: string | number }) => void;
892894
/** Fires event when you copy */

core/src/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export interface JsonViewProps<T extends object>
6666
highlightUpdates?: boolean;
6767
/** Shorten long JSON strings, Set to `0` to disable this feature @default 30 */
6868
shortenTextAfterLength?: number;
69+
/** When the text exceeds the length, `...` will be displayed. Currently, this `...` can be customized. @default "..." */
70+
stringEllipsis?: number;
6971
/** Callback function for when a treeNode is expanded or collapsed */
7072
onExpand?: (props: { expand: boolean; value?: T; keyid: string; keyName?: string | number }) => void;
7173
/** Fires event when you copy */
@@ -116,6 +118,7 @@ const JsonView: JsonViewComponent = forwardRef<HTMLDivElement, JsonViewProps<obj
116118
indentWidth = 15,
117119
displayObjectSize = true,
118120
shortenTextAfterLength = 30,
121+
stringEllipsis,
119122
highlightUpdates = true,
120123
enableClipboard = true,
121124
displayDataTypes = true,
@@ -144,6 +147,7 @@ const JsonView: JsonViewComponent = forwardRef<HTMLDivElement, JsonViewProps<obj
144147
collapsed,
145148
enableClipboard,
146149
shortenTextAfterLength,
150+
stringEllipsis,
147151
highlightUpdates,
148152
onCopied,
149153
onExpand,

core/src/store.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface InitialState<T extends object> {
1515
objectSortKeys?: JsonViewProps<T>['objectSortKeys'];
1616
displayObjectSize?: JsonViewProps<T>['displayObjectSize'];
1717
shortenTextAfterLength?: JsonViewProps<T>['shortenTextAfterLength'];
18+
stringEllipsis?: JsonViewProps<T>['stringEllipsis'];
1819
enableClipboard?: JsonViewProps<T>['enableClipboard'];
1920
highlightUpdates?: JsonViewProps<T>['highlightUpdates'];
2021
collapsed?: JsonViewProps<T>['collapsed'];

core/src/types/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type TypeProps = PropsWithChildren<{
5757

5858
export const TypeString: FC<TypeProps> = ({ children = '', keyName }) => {
5959
const { Str = {}, displayDataTypes } = useTypesStore();
60-
const { shortenTextAfterLength: length = 30 } = useStore();
60+
const { shortenTextAfterLength: length = 30, stringEllipsis = '...' } = useStore();
6161
const { as, render, ...reset } = Str;
6262
const childrenStr = children as string;
6363
const [shorten, setShorten] = useState(length && childrenStr.length > length);
@@ -79,20 +79,20 @@ export const TypeString: FC<TypeProps> = ({ children = '', keyName }) => {
7979
};
8080
}
8181
}
82-
const text = shorten ? `${childrenStr.slice(0, length)}...` : childrenStr;
82+
const text = shorten ? `${childrenStr.slice(0, length)}${stringEllipsis}` : childrenStr;
8383

8484
const isRender = render && typeof render === 'function';
8585
const type = isRender && render({ ...reset, style }, { type: 'type', value: children, keyName });
86+
const cls = shorten ? 'w-rjv-value w-rjv-value-short' : 'w-rjv-value';
8687
const child =
87-
isRender &&
88-
render({ ...reset, children: text, className: 'w-rjv-value' }, { type: 'value', value: children, keyName });
88+
isRender && render({ ...reset, children: text, className: cls }, { type: 'value', value: children, keyName });
8989
return (
9090
<Fragment>
9191
{displayDataTypes && (type || <Comp {...reset} style={style} />)}
9292
{child || (
9393
<Fragment>
9494
<ValueQuote />
95-
<Comp {...reset} className="w-rjv-value">
95+
<Comp {...reset} className={cls}>
9696
{text}
9797
</Comp>
9898
<ValueQuote />

0 commit comments

Comments
 (0)