Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: next component #18

Merged
merged 21 commits into from
Sep 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 48 additions & 12 deletions examples/basic/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import JsonViewer from '@textea/json-viewer'
import { TextField } from '@mui/material'
import {
applyValue,
JsonViewer,
JsonViewerOnChange
} from '@textea/json-viewer'
import type React from 'react'
import { useCallback, useState } from 'react'
import { useCallback, useEffect, useState } from 'react'

import type { InteractionProps } from '../../../src/type'

function aPlusB (a:number, b: number) {
function aPlusB (a: number, b: number) {
return a + b
}

const example = {
string: 'this is a test string',
string: 'this is a string',
integer: 42,
array: [1, 2, 3, 'test', NaN],
float: 3.14159,
array: [19, 19, 810, 'test', NaN],
float: 114.514,
undefined,
object: {
'first-child': true,
Expand All @@ -21,17 +24,50 @@ const example = {
},
fn: aPlusB,
string_number: '1234',
timer: 0,
date: new Date('Tue Sep 13 2022 14:07:44 GMT-0500 (Central Daylight Time)')
}

const IndexPage: React.FC = () => {
const [src, setSrc] = useState<object>(() => example)
const handleEdit = useCallback((update: InteractionProps) => {
setSrc(update.updated_src)
const [indent, setIndent] = useState(2)
const [src, setSrc] = useState(() => example)
useEffect(() => {
const loop = () => {
setSrc(src => ({
...src,
timer: src.timer + 1
}))
}
const id = setInterval(loop, 1000)
return () => {
clearInterval(id)
}
}, [])
return (
<div>
<JsonViewer src={src} onEdit={handleEdit}/>
<TextField
value={indent}
type='number'
onChange={
event => {
const indent = parseInt(event.target.value)
if (indent > -1 && indent < 10) {
setIndent(indent)
}
}
}
/>
<JsonViewer
value={src}
indentWidth={indent}
onChange={
useCallback<JsonViewerOnChange>(
(path, oldValue, newValue) => {
setSrc(src => applyValue(src, path, newValue))
}, []
)
}
/>
</div>
)
}
Expand Down
5 changes: 0 additions & 5 deletions examples/next/next-env.d.ts

This file was deleted.

15 changes: 0 additions & 15 deletions examples/next/next.config.js

This file was deleted.

24 changes: 0 additions & 24 deletions examples/next/package.json

This file was deleted.

57 changes: 0 additions & 57 deletions examples/next/pages/index.tsx

This file was deleted.

20 changes: 0 additions & 20 deletions examples/next/tsconfig.json

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"tree-view",
"treeview"
],
"types": "src/type.d.ts",
"types": "dist/src/index.d.ts",
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
Expand All @@ -35,7 +35,6 @@
}
},
"files": [
"src/**.d.ts",
"dist"
],
"scripts": {
Expand Down
150 changes: 0 additions & 150 deletions src/components/ArrayGroup.jsx

This file was deleted.

Loading