Skip to content

Commit e99f6cc

Browse files
authored
Update README.md
1 parent d805168 commit e99f6cc

File tree

1 file changed

+72
-51
lines changed

1 file changed

+72
-51
lines changed

README.md

Lines changed: 72 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ This is a solution for create forms from JSON source automatically (with some mi
44
## Demo
55
https://codepen.io/iroshan/pen/ReZxZy
66

7+
## API
8+
9+
JSONEditor(Element container) - set the root element for the editor
10+
setTitle(string title) - set the title of the editor
11+
setJSON(JSON json) - set JSON for edit
12+
getJSON() - get edited JSON
13+
714
## Example
815
HTML:
916
```html
@@ -15,90 +22,101 @@ CSS:
1522
/* THEME */
1623

1724
.json-editor-container {
18-
transition: all 0.5s ease-in-out;
19-
border: none;
20-
border-left: 1px solid rgba(255, 255, 255, 0.2);
21-
background: #282c34;
22-
margin: 0;
23-
padding: 3px;
24-
padding-left: 15px;
25-
max-height: 10000px;
25+
transition : all 0.5s ease-in-out;
26+
border : none;
27+
border-left : 1px solid rgba(255, 255, 255, 0.2);
28+
background : #282c34;
29+
margin : 0;
30+
padding : 3px;
31+
padding-left : 15px;
32+
max-height : 10000px;
2633
}
2734

2835
.json-editor-container:last-child {
29-
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
30-
border-radius: 0 0 0 5px;
36+
border-bottom : 1px solid rgba(255, 255, 255, 0.2);
37+
border-radius : 0 0 0 5px;
3138
}
3239

3340
.json-editor-container.root {
34-
padding: 3px;
35-
margin: 0;
36-
border: none;
37-
border-radius: 5px;
41+
padding : 3px;
42+
margin : 0;
43+
border : none;
44+
border-radius : 5px;
3845
}
3946

4047
.json-editor-container.root > .json-editor-container {
41-
border-left: none;
42-
padding-left: 3px;
48+
border-left : none;
49+
padding-left : 3px;
4350
}
4451

4552
.json-editor-container.root > .json-editor-container:last-child {
46-
border-bottom: none;
53+
border-bottom : none;
4754
}
4855

4956
.json-editor-container.hidden-property {
50-
opacity: 0.3;
51-
max-height: 40px;
57+
opacity : 0.3;
58+
max-height : 40px;
5259
}
5360

5461
.json-editor-container input[type="checkbox"] {
55-
vertical-align: top;
56-
margin-top: 13px;
57-
margin-left: 5px;
62+
vertical-align : top;
63+
margin-top : 13px;
64+
margin-left : 5px;
5865
}
5966

6067
.json-editor-container label {
61-
color: #d19a66;
62-
height: 22px;
63-
vertical-align: top;
64-
margin-top: 13px;
65-
white-space: nowrap;
66-
overflow: hidden;
67-
text-overflow: ellipsis;
68-
width: calc(30% - 25px);
68+
color : #d19a66;
69+
height : 22px;
70+
vertical-align : top;
71+
margin-top : 13px;
72+
white-space : nowrap;
73+
overflow : hidden;
74+
text-overflow : ellipsis;
75+
width : calc(30% - 25px);
6976
}
7077

7178
.json-editor-container.root > label {
72-
width: calc(100% - 10px);
79+
width : calc(100% - 10px);
7380
}
7481

7582
.json-editor-container input[type="text"],
7683
.json-editor-container select {
77-
vertical-align: top;
78-
width: calc(70% - 25px);
79-
border-radius: 5px;
80-
padding: 5px;
81-
height: 20px;
82-
background: rgba(255, 255, 255, 0.8);
84+
vertical-align : top;
85+
width : calc(70% - 25px);
86+
border-radius : 5px;
87+
padding : 5px;
88+
height : 20px;
89+
background : rgba(255, 255, 255, 0.8);
8390
}
8491

8592
.json-editor-container select {
86-
height: 30px;
87-
width: calc(70% - 15px);
93+
height : 30px;
94+
width : calc(70% - 15px);
8895
}
8996

9097
.json-editor-container input[type="checkbox"]:focus,
9198
.json-editor-container input[type="text"]:focus,
9299
.json-editor-container select:focus {
93-
background: rgba(255, 255, 255, 0.9);
94-
box-shadow: 0 0 4px 4px rgba(255, 255, 255, 0.2);
100+
background : rgba(255, 255, 255, 0.9);
101+
box-shadow : 0 0 4px 4px rgba(255, 255, 255, 0.2);
102+
}
103+
104+
.json-editor-container label ~ input[type="checkbox"]:after {
105+
padding-left : 20px;
106+
color : rgba(255, 255, 255, 0.5);
107+
content : "false";
108+
}
109+
110+
.json-editor-container label ~ input[type="checkbox"]:checked:after {
111+
content : "true";
112+
color : white;
95113
}
96114

97115
@media screen and (max-width: 600px) {
98116
.json-editor-container {
99-
margin: 1px;
100-
padding: 1px;
101-
padding-left: 5px;
117+
margin : 1px;
118+
padding : 1px;
119+
padding-left : 5px;
102120
}
103121
}
104122
```
@@ -110,12 +128,15 @@ var json = {
110128
first: 0,
111129
second: 1
112130
},
113-
int: 0,
114-
float: 0.1,
131+
number: 0.1,
115132
string: "hello",
116-
boolean: {
133+
boolean: true,
134+
booleanEnum: { // enum
117135
type: "enum",
118-
values: ["True", "False"]
136+
values: [
137+
"True",
138+
"False"
139+
]
119140
},
120141
enum: { // special type
121142
type: "enum",
@@ -145,11 +166,11 @@ var json = {
145166
2
146167
]
147168
};
148-
169+
// HOW TO USE
149170
var container = document.querySelector("#json-container");
150-
var editor = new JSONEditor();
171+
var editor = new JSONEditor(container);
151172
editor.setTitle("Edit JSON");
152-
editor.setJSON(container, json);
173+
editor.setJSON(json);
153174
container.addEventListener("change", function() {
154175
console.clear();
155176
console.log(editor.getJSON());

0 commit comments

Comments
 (0)