1 | import { createStyling } from 'react-base16-styling';
|
2 | import solarized from './themes/solarized.js';
|
3 | const colorMap = (theme) => ({
|
4 | BACKGROUND_COLOR: theme.base00,
|
5 | TEXT_COLOR: theme.base07,
|
6 | STRING_COLOR: theme.base0B,
|
7 | DATE_COLOR: theme.base0B,
|
8 | NUMBER_COLOR: theme.base09,
|
9 | BOOLEAN_COLOR: theme.base09,
|
10 | NULL_COLOR: theme.base08,
|
11 | UNDEFINED_COLOR: theme.base08,
|
12 | FUNCTION_COLOR: theme.base08,
|
13 | SYMBOL_COLOR: theme.base08,
|
14 | LABEL_COLOR: theme.base0D,
|
15 | ARROW_COLOR: theme.base0D,
|
16 | ITEM_STRING_COLOR: theme.base0B,
|
17 | ITEM_STRING_EXPANDED_COLOR: theme.base03,
|
18 | });
|
19 | const valueColorMap = (colors) => ({
|
20 | String: colors.STRING_COLOR,
|
21 | Date: colors.DATE_COLOR,
|
22 | Number: colors.NUMBER_COLOR,
|
23 | Boolean: colors.BOOLEAN_COLOR,
|
24 | Null: colors.NULL_COLOR,
|
25 | Undefined: colors.UNDEFINED_COLOR,
|
26 | Function: colors.FUNCTION_COLOR,
|
27 | Symbol: colors.SYMBOL_COLOR,
|
28 | });
|
29 | const getDefaultThemeStyling = (theme) => {
|
30 | const colors = colorMap(theme);
|
31 | return {
|
32 | tree: {
|
33 | border: 0,
|
34 | padding: 0,
|
35 | marginTop: '0.5em',
|
36 | marginBottom: '0.5em',
|
37 | marginLeft: '0.125em',
|
38 | marginRight: 0,
|
39 | listStyle: 'none',
|
40 | MozUserSelect: 'none',
|
41 | WebkitUserSelect: 'none',
|
42 | backgroundColor: colors.BACKGROUND_COLOR,
|
43 | },
|
44 | value: ({ style }, nodeType, keyPath) => ({
|
45 | style: {
|
46 | ...style,
|
47 | paddingTop: '0.25em',
|
48 | paddingRight: 0,
|
49 | marginLeft: '0.875em',
|
50 | WebkitUserSelect: 'text',
|
51 | MozUserSelect: 'text',
|
52 | wordWrap: 'break-word',
|
53 | paddingLeft: keyPath.length > 1 ? '2.125em' : '1.25em',
|
54 | textIndent: '-0.5em',
|
55 | wordBreak: 'break-all',
|
56 | },
|
57 | }),
|
58 | label: {
|
59 | display: 'inline-block',
|
60 | color: colors.LABEL_COLOR,
|
61 | },
|
62 | valueLabel: {
|
63 | margin: '0 0.5em 0 0',
|
64 | },
|
65 | valueText: ({ style }, nodeType) => ({
|
66 | style: {
|
67 | ...style,
|
68 | color: valueColorMap(colors)[nodeType],
|
69 | },
|
70 | }),
|
71 | itemRange: (styling, expanded) => ({
|
72 | style: {
|
73 | paddingTop: expanded ? 0 : '0.25em',
|
74 | cursor: 'pointer',
|
75 | color: colors.LABEL_COLOR,
|
76 | },
|
77 | }),
|
78 | arrow: ({ style }, nodeType, expanded) => ({
|
79 | style: {
|
80 | ...style,
|
81 | marginLeft: 0,
|
82 | transition: '150ms',
|
83 | WebkitTransition: '150ms',
|
84 | MozTransition: '150ms',
|
85 | WebkitTransform: expanded ? 'rotateZ(90deg)' : 'rotateZ(0deg)',
|
86 | MozTransform: expanded ? 'rotateZ(90deg)' : 'rotateZ(0deg)',
|
87 | transform: expanded ? 'rotateZ(90deg)' : 'rotateZ(0deg)',
|
88 | transformOrigin: '45% 50%',
|
89 | WebkitTransformOrigin: '45% 50%',
|
90 | MozTransformOrigin: '45% 50%',
|
91 | position: 'relative',
|
92 | lineHeight: '1.1em',
|
93 | fontSize: '0.75em',
|
94 | },
|
95 | }),
|
96 | arrowContainer: ({ style }, arrowStyle) => ({
|
97 | style: {
|
98 | ...style,
|
99 | display: 'inline-block',
|
100 | paddingRight: '0.5em',
|
101 | paddingLeft: arrowStyle === 'double' ? '1em' : 0,
|
102 | cursor: 'pointer',
|
103 | },
|
104 | }),
|
105 | arrowSign: {
|
106 | color: colors.ARROW_COLOR,
|
107 | },
|
108 | arrowSignInner: {
|
109 | position: 'absolute',
|
110 | top: 0,
|
111 | left: '-0.4em',
|
112 | },
|
113 | nestedNode: ({ style }, keyPath, nodeType, expanded, expandable) => ({
|
114 | style: {
|
115 | ...style,
|
116 | position: 'relative',
|
117 | paddingTop: '0.25em',
|
118 | marginLeft: keyPath.length > 1 ? '0.875em' : 0,
|
119 | paddingLeft: !expandable ? '1.125em' : 0,
|
120 | },
|
121 | }),
|
122 | rootNode: {
|
123 | padding: 0,
|
124 | margin: 0,
|
125 | },
|
126 | nestedNodeLabel: ({ style }, keyPath, nodeType, expanded, expandable) => ({
|
127 | style: {
|
128 | ...style,
|
129 | margin: 0,
|
130 | padding: 0,
|
131 | WebkitUserSelect: expandable ? 'inherit' : 'text',
|
132 | MozUserSelect: expandable ? 'inherit' : 'text',
|
133 | cursor: expandable ? 'pointer' : 'default',
|
134 | },
|
135 | }),
|
136 | nestedNodeItemString: ({ style }, keyPath, nodeType, expanded) => ({
|
137 | style: {
|
138 | ...style,
|
139 | paddingLeft: '0.5em',
|
140 | cursor: 'default',
|
141 | color: expanded
|
142 | ? colors.ITEM_STRING_EXPANDED_COLOR
|
143 | : colors.ITEM_STRING_COLOR,
|
144 | },
|
145 | }),
|
146 | nestedNodeItemType: {
|
147 | marginLeft: '0.3em',
|
148 | marginRight: '0.3em',
|
149 | },
|
150 | nestedNodeChildren: ({ style }, nodeType, expanded) => ({
|
151 | style: {
|
152 | ...style,
|
153 | padding: 0,
|
154 | margin: 0,
|
155 | listStyle: 'none',
|
156 | display: expanded ? 'block' : 'none',
|
157 | },
|
158 | }),
|
159 | rootNodeChildren: {
|
160 | padding: 0,
|
161 | margin: 0,
|
162 | listStyle: 'none',
|
163 | },
|
164 | };
|
165 | };
|
166 | const createStylingFromTheme = createStyling(getDefaultThemeStyling, {
|
167 | defaultBase16: solarized,
|
168 | });
|
169 | export default createStylingFromTheme;
|