Skip to content

Commit 7f0f746

Browse files
committed
💄 Improve table editing UI
1 parent 3bab59c commit 7f0f746

1 file changed

Lines changed: 150 additions & 10 deletions

File tree

ui.html

Lines changed: 150 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,135 @@
1+
<link rel="preconnect" href="https://fonts.googleapis.com">
2+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
3+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap" rel="stylesheet">
14
<style>
2-
html,
5+
* {
6+
box-sizing: border-box;
7+
}
8+
9+
html {
10+
font-family: Inter;
11+
scroll-padding-top: 80px;
12+
}
313
body {
4-
padding: 0;
514
margin: 0;
615
}
716

817
div {
918
display: flex;
1019
gap: 0.5rem;
20+
height: 40px;
21+
align-items: center;
22+
justify-content: center;
23+
background-color: #2C2C2C;
24+
position: sticky;
25+
top: 0px;
1126
}
1227

1328
table {
14-
width: 100vw;
29+
margin-top: 8px;
30+
width: 100%;
31+
border-collapse: collapse;
32+
}
33+
34+
thead {
35+
position: sticky;
36+
top: 40px;
37+
height: 40px;
38+
background-color: #FFFFFF;
39+
}
40+
41+
td {
42+
text-align: center;
43+
}
44+
45+
button {
46+
height: 32px;
47+
line-height: 30px;
48+
max-width: 200px;
49+
border-radius: 6px;
50+
border: 1px solid rgba(255, 255, 255, 0.8);
51+
background-color: initial;
52+
color: #ffffff;
53+
font-family: Inter;
54+
font-weight: 500;
55+
padding: 0;
56+
}
57+
58+
59+
button[type=submit] {
60+
padding: 0px 11px;
61+
border: none;
62+
background-color: #18A0FB;
63+
color: #FFFFFF;
64+
}
65+
66+
button[type=button] {
67+
padding: 0px 11px;
68+
}
69+
70+
button[type=reset] {
71+
width: 32px;
72+
line-height: 32px;
73+
display: inline-grid;
74+
place-items: center;
75+
color: #333333;
76+
fill: #333333;
77+
border: none;
78+
border-radius: 2px;
79+
}
80+
81+
button[type=reset]:hover {
82+
background-color: rgba(0, 0, 0, 0.06);
1583
}
1684

1785
input,
1886
select {
1987
width: 100%;
2088
}
2189

22-
input[type=button] {
23-
width: 1.5rem;
24-
height: 1.5rem;
25-
display: inline-grid;
26-
place-items: center;
90+
input[type=text] {
91+
background-color: #FFFFFF;
92+
color: rgba(0, 0, 0, 0.8);
93+
font-family: Inter;
94+
border: none;
95+
padding: 7px;
96+
border-radius: 2px;
97+
border-color: rgba(0, 0, 0, 0.1);
98+
border-style: solid;
99+
border-width: 1px;
100+
}
101+
102+
input[type=text]:focus,
103+
input[type=text]:focus-visible {
104+
border-color: #18A0FB;
105+
outline-color: #18A0FB;
106+
outline-width: 1px;
107+
}
108+
109+
input[type=checkbox] {
110+
width: auto;
111+
}
112+
113+
select {
114+
height: 32px;
115+
border-radius: 2px;
116+
border: 1px solid rgba(0, 0, 0, 0.1);
117+
}
118+
119+
select:active,
120+
select:focus,
121+
select:focus-visible {
122+
border-color: #18A0FB;
123+
outline-color: #18A0FB;
124+
outline-width: 1px;
125+
}
126+
127+
.drag-target-top {
128+
border-top: 2px solid black;
129+
}
130+
131+
.drag-target-bottom {
132+
border-bottom: 2px solid black;
27133
}
28134
</style>
29135
<script src="https://unpkg.com/vue@3"></script>
@@ -43,7 +149,8 @@
43149
</tr>
44150
</thead>
45151
<tbody>
46-
<tr ref="columns" v-for="(column, index) in columns" draggable="true" @dragend="dragEnd" @dragover="dragOver">
152+
<tr ref="columns" v-for="(column, index) in columns" draggable="true" @dragstart="dragStart" @dragend="dragEnd"
153+
@dragover="dragOver" @dragleave="dragLeave">
47154
<td>
48155
<input v-model="column.name" type="text" />
49156
</td>
@@ -105,7 +212,13 @@
105212
<input v-model="column.nullable" type="checkbox" />
106213
</td>
107214
<td>
108-
<input type="button" @click="remove(index)" value="-" />
215+
<button type="reset" @click="remove(index)">
216+
<svg width="12" height="16" viewBox="0 0 12 16" fill="none" xmlns="http://www.w3.org/2000/svg">
217+
<path
218+
d="M0 3H1.5M12 3H10.5M3.5 3V2.5C3.5 1.67157 4.17157 1 5 1H7C7.82843 1 8.5 1.67157 8.5 2.5V3M3.5 3H8.5M3.5 3H1.5M8.5 3H10.5M10.5 3V13.5C10.5 14.3284 9.82843 15 9 15H3C2.17157 15 1.5 14.3284 1.5 13.5V3M4.5 6.5V10.5M7.5 6.5V10.5"
219+
stroke="black" />
220+
</svg>
221+
</button>
109222
</td>
110223
</tr>
111224
</tbody>
@@ -117,6 +230,7 @@
117230
return {
118231
columns: [],
119232
row: null,
233+
changedRow: null,
120234
}
121235
},
122236
mounted() {
@@ -141,6 +255,9 @@
141255
remove(index) {
142256
this.columns.splice(index, 1)
143257
},
258+
dragStart(event) {
259+
this.changedRow = event.currentTarget
260+
},
144261
dragEnd(event) {
145262
let rows = this.$refs.columns
146263
let newIndex = rows.indexOf(this.row)
@@ -150,7 +267,30 @@
150267
this.columns.splice(newIndex, 0, currentColumn[0])
151268
},
152269
dragOver(event) {
270+
let rows = this.$refs.columns
271+
272+
this.row = event.currentTarget
273+
274+
let newIndex = rows.indexOf(this.row)
275+
let prevIndex = rows.indexOf(this.changedRow)
276+
277+
let targetClass = ""
278+
if (newIndex == prevIndex) {
279+
return
280+
}
281+
282+
if (newIndex < prevIndex) {
283+
targetClass = "drag-target-top"
284+
} else {
285+
targetClass = "drag-target-bottom"
286+
}
287+
288+
this.row.classList.add(targetClass)
289+
},
290+
dragLeave(event) {
153291
this.row = event.currentTarget
292+
293+
this.row.classList.remove("drag-target-bottom", "drag-target-top")
154294
}
155295
},
156296
}).mount("article")

0 commit comments

Comments
 (0)