This commit is contained in:
Nathan Bierema 2020-05-21 23:31:35 -05:00
parent b94d6b2b06
commit 788191e6ce
9 changed files with 5019 additions and 40 deletions

View File

@ -1,9 +0,0 @@
{
"plugins": [
"transform-object-rest-spread",
"transform-class-properties"
],
"presets": [
"env", "react"
]
}

View File

@ -27,18 +27,22 @@
}, },
"homepage": "https://github.com/gaearon/react-hot-boilerplate", "homepage": "https://github.com/gaearon/react-hot-boilerplate",
"devDependencies": { "devDependencies": {
"babel-core": "^6.26.0", "@babel/cli": "^7.2.3",
"babel-loader": "^7.1.2", "@babel/core": "^7.2.2",
"babel-plugin-transform-class-properties": "^6.24.1", "@babel/plugin-proposal-class-properties": "^7.3.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0", "@babel/preset-env": "^7.3.1",
"babel-preset-react": "^6.5.0", "@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.9.0",
"@types/react": "^16.3.0",
"@types/react-dom": "^16.3.0",
"typescript": "^3.8.3",
"webpack": "^3.8.1", "webpack": "^3.8.1",
"webpack-dev-server": "^3.10.3" "webpack-dev-server": "^2.4.1"
}, },
"dependencies": { "dependencies": {
"immutable": "^3.8.1", "immutable": "^3.8.1",
"react": "^16.0.0", "react": "^16.3.0",
"react-base16-styling": "^0.5.3", "react-base16-styling": "^0.5.3",
"react-dom": "^16.0.0" "react-dom": "^16.3.0"
} }
} }

View File

@ -1,46 +1,59 @@
import React from 'react'; import React from 'react';
import { Map } from 'immutable'; import { Map } from 'immutable';
import JSONTree from '../../src'; import JSONTree from 'react-json-tree';
import { StylingValue } from 'react-base16-styling';
const getLabelStyle = ({ style }, nodeType, expanded) => ({ const getLabelStyle: StylingValue = (
{ style },
keyPath,
nodeType,
expanded
) => ({
style: { style: {
...style, ...style,
textTransform: expanded ? 'uppercase' : style.textTransform textTransform: expanded ? 'uppercase' : style!.textTransform
} }
}); });
const getBoolStyle = ({ style }, nodeType) => ({ const getBoolStyle: StylingValue = ({ style }, nodeType) => ({
style: { style: {
...style, ...style,
border: nodeType === 'Boolean' ? '1px solid #DD3333' : style.border, border: nodeType === 'Boolean' ? '1px solid #DD3333' : style!.border,
borderRadius: nodeType === 'Boolean' ? 3 : style.borderRadius borderRadius: nodeType === 'Boolean' ? 3 : style!.borderRadius
} }
}); });
const getItemString = type => ( const getItemString = (type: string) => (
<span> <span>
{' // '} {' // '}
{type} {type}
</span> </span>
); );
const getValueLabelStyle = ({ style }, nodeType, keyPath) => ({ const getValueLabelStyle: StylingValue = ({ style }, nodeType, keyPath) => ({
style: { style: {
...style, ...style,
color: color:
!Number.isNaN(keyPath[0]) && !(parseInt(keyPath, 10) % 2) !Number.isNaN(keyPath[0]) && !(parseInt(keyPath, 10) % 2)
? '#33F' ? '#33F'
: style.color : style!.color
} }
}); });
const longString = const longString =
'Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.'; // eslint-disable-line max-len 'Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.Loremipsumdolorsitamet,consecteturadipiscingelit.Namtempusipsumutfelisdignissimauctor.Maecenasodiolectus,finibusegetultricesvel,aliquamutelit.'; // eslint-disable-line max-len
const Custom = function(value) { class Custom {
value: unknown;
constructor(value: unknown) {
this.value = value; this.value = value;
}; }
Custom.prototype[Symbol.toStringTag] = 'Custom';
get [Symbol.toStringTag]() {
return 'Custom';
}
}
const data = { const data = {
array: [1, 2, 3], array: [1, 2, 3],
@ -73,7 +86,7 @@ const data = {
['key', 'value'], ['key', 'value'],
[{ objectKey: 'value' }, { objectKey: 'value' }] [{ objectKey: 'value' }, { objectKey: 'value' }]
]), ]),
map: new window.Map([ map: Map([
['key', 'value'], ['key', 'value'],
[0, 'value'], [0, 'value'],
[{ objectKey: 'value' }, { objectKey: 'value' }] [{ objectKey: 'value' }, { objectKey: 'value' }]
@ -146,7 +159,7 @@ const App = () => (
<JSONTree <JSONTree
data={data} data={data}
theme={{ theme={{
extend: theme, extend: (theme as unknown) as StylingValue,
nestedNodeLabel: getLabelStyle, nestedNodeLabel: getLabelStyle,
value: getBoolStyle, value: getBoolStyle,
valueLabel: getValueLabelStyle valueLabel: getValueLabelStyle

View File

@ -0,0 +1,4 @@
{
"extends": "../../../tsconfig.react.base.json",
"include": ["src"]
}

View File

@ -36,19 +36,25 @@ module.exports = {
'react-json-tree': path.join(__dirname, '..', 'src'), 'react-json-tree': path.join(__dirname, '..', 'src'),
react: path.join(__dirname, 'node_modules', 'react') react: path.join(__dirname, 'node_modules', 'react')
}, },
extensions: ['.js'] extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
}, },
module: { module: {
loaders: [ loaders: [
{ {
test: /\.js$/, test: /\.(ts|js)x?$/,
loaders: ['babel-loader'].filter(Boolean), include: path.join(__dirname, 'src'),
include: path.join(__dirname, 'src') loaders: 'babel-loader',
options: {
rootMode: 'upward'
}
}, },
{ {
test: /\.js$/, test: /\.(ts|js)x?$/,
loaders: ['babel-loader'].filter(Boolean), include: path.join(__dirname, '..', 'src'),
include: path.join(__dirname, '..', 'src') loaders: 'babel-loader',
options: {
rootMode: 'upward'
}
} }
] ]
} }

File diff suppressed because it is too large Load Diff

View File

@ -39,7 +39,7 @@ declare module 'react-base16-styling' {
export type Theme = string | Base16Theme | StylingConfig; export type Theme = string | Base16Theme | StylingConfig;
export type StylingFunction = ( export type StylingFunction = (
keys: string | Array<string | undefined | null>, keys: string | Array<string | false | undefined | null>,
...rest: any[] ...rest: any[]
) => Styling; ) => Styling;