-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathcomponent.tsx
42 lines (38 loc) · 1.08 KB
/
component.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React from 'react'
import { toPathString, StringEdit, type CustomNodeProps } from '@json-edit-react'
export interface BigIntProps {
style?: React.CSSProperties
descriptionStyle?: React.CSSProperties
}
export const BigIntComponent: React.FC<CustomNodeProps<BigIntProps>> = (props) => {
const {
setValue,
isEditing,
setIsEditing,
getStyles,
nodeData,
customNodeProps = {},
value,
handleEdit,
...rest
} = props
const { path } = nodeData
const { style = { color: '#006291', fontSize: '90%' } } = customNodeProps
const editDisplayValue = typeof value === 'bigint' ? String(value) : (value as string)
return isEditing ? (
<StringEdit
pathString={toPathString(path)}
styles={getStyles('input', nodeData)}
value={editDisplayValue}
setValue={setValue as React.Dispatch<React.SetStateAction<string>>}
{...rest}
handleEdit={() => {
handleEdit(BigInt(nodeData.value as string))
}}
/>
) : (
<span onDoubleClick={() => setIsEditing(true)} style={style}>
{value as bigint}
</span>
)
}