Skip to content

Commit

Permalink
feat: next component (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 authored Sep 17, 2022
1 parent c9f6d32 commit d354967
Show file tree
Hide file tree
Showing 55 changed files with 933 additions and 3,739 deletions.
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

0 comments on commit d354967

Please sign in to comment.