1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 18:18:53 +08:00

Make a table/chart area collapsable #18

This commit is contained in:
lana-k
2020-11-14 23:09:31 +01:00
parent d586e43d6e
commit e72510f236
2 changed files with 109 additions and 37 deletions

View File

@@ -13,7 +13,7 @@
ref="left" ref="left"
:size="paneBefore.size" :size="paneBefore.size"
max-size="30" max-size="30"
:style="styles[0]" :style="styles.before"
> >
<slot name="left-pane" /> <slot name="left-pane" />
</div> </div>
@@ -23,19 +23,41 @@
@mousedown="onMouseDown" @mousedown="onMouseDown"
@touchstart="onMouseDown" @touchstart="onMouseDown"
> >
<div class="toggle-btn" @click="toggleFirstPane"> <div
<img :class="[
class="direction-icon" 'toggle-btns',
:src="require('@/assets/images/chevron.svg')" {'both': after.max === 100 && before.max === 100 && after.size > 0 && before.size > 0}
:style="directionIconStyle" ]"
>
<div
v-if="after.max === 100 && after.size > 0"
class="toggle-btn"
@click="togglePane('before')"
> >
<img
class="direction-icon"
:src="require('@/assets/images/chevron.svg')"
:style="directionBeforeIconStyle"
>
</div>
<div
v-if="before.max === 100 && before.size > 0"
class="toggle-btn"
@click="togglePane('after')"
>
<img
class="direction-icon"
:src="require('@/assets/images/chevron.svg')"
:style="directionAfterIconStyle"
>
</div>
</div> </div>
</div> </div>
<!-- splitter end --> <!-- splitter end -->
<div <div
class="splitpanes__pane" class="splitpanes__pane"
ref="right" ref="right"
:style="styles[1]" :style="styles.after"
> >
<slot name="right-pane" /> <slot name="right-pane" />
</div> </div>
@@ -56,7 +78,10 @@ export default {
container: null, container: null,
paneBefore: this.before, paneBefore: this.before,
paneAfter: this.after, paneAfter: this.after,
beforeMinimising: this.before.size, beforeMinimising: {
before: this.before.size,
after: this.after.size
},
touch: { touch: {
mouseDown: false, mouseDown: false,
dragging: false dragging: false
@@ -70,10 +95,10 @@ export default {
}, },
computed: { computed: {
styles () { styles () {
return [ return {
{ [this.horizontal ? 'height' : 'width']: `${this.paneBefore.size}%` }, before: { [this.horizontal ? 'height' : 'width']: `${this.paneBefore.size}%` },
{ [this.horizontal ? 'height' : 'width']: `${this.paneAfter.size}%` } after: { [this.horizontal ? 'height' : 'width']: `${this.paneAfter.size}%` }
] }
}, },
movableSplitterStyle () { movableSplitterStyle () {
const style = { ...this.movableSplitter } const style = { ...this.movableSplitter }
@@ -81,18 +106,29 @@ export default {
style.left += '%' style.left += '%'
return style return style
}, },
expanded () { directionBeforeIconStyle () {
return this.paneBefore.size !== 0 const expanded = this.paneBefore.size !== 0
},
directionIconStyle () {
const translation = 'translate(-50%, -50%)' const translation = 'translate(-50%, -50%)'
if (this.horizontal) { if (this.horizontal) {
return { return {
transform: `${translation} ${this.expanded ? 'rotate(90deg)' : 'rotate(-90deg)'}` transform: `${translation} ${expanded ? 'rotate(90deg)' : 'rotate(-90deg)'}`
} }
} else { } else {
return { return {
transform: `${translation} ${this.expanded ? 'rotate(0deg)' : 'rotate(180deg)'}` transform: `${translation} ${expanded ? 'rotate(0deg)' : 'rotate(180deg)'}`
}
}
},
directionAfterIconStyle () {
const expanded = this.paneAfter.size !== 0
const translation = 'translate(-50%, -50%)'
if (this.horizontal) {
return {
transform: `${translation} ${expanded ? 'rotate(-90deg)' : 'rotate(90deg)'}`
}
} else {
return {
transform: `${translation} ${expanded ? 'rotate(180deg)' : 'rotate(0deg)'}`
} }
} }
} }
@@ -202,14 +238,18 @@ export default {
this.$set(this.movableSplitter, dir, Math.min(Math.max(dragPercentage, 0), paneBefore.max)) this.$set(this.movableSplitter, dir, Math.min(Math.max(dragPercentage, 0), paneBefore.max))
} }
}, },
toggleFirstPane () { togglePane (toggledPane) {
if (this.paneBefore.size > 0) { const pane = toggledPane === 'before' ? this.paneBefore : this.paneAfter
this.beforeMinimising = this.paneBefore.size if (pane.size > 0) {
this.paneBefore.size = 0 this.beforeMinimising.before = this.paneBefore.size
this.beforeMinimising.after = this.paneAfter.size
pane.size = 0
const otherPane = toggledPane === 'before' ? this.paneAfter : this.paneBefore
otherPane.size = 100 - pane.size
} else { } else {
this.paneBefore.size = this.beforeMinimising this.paneBefore.size = this.beforeMinimising.before
this.paneAfter.size = this.beforeMinimising.after
} }
this.paneAfter.size = 100 - this.paneBefore.size
} }
}, },
mounted () { mounted () {
@@ -271,43 +311,75 @@ export default {
} }
.splitpanes--vertical > .splitpanes__splitter, .splitpanes--vertical > .splitpanes__splitter,
.splitpanes--vertical .movable-splitter { .splitpanes--vertical > .movable-splitter {
width: 8px; width: 8px;
z-index: 5; z-index: 5;
height: 100% height: 100%
} }
.splitpanes--horizontal > .splitpanes__splitter, .splitpanes--horizontal > .splitpanes__splitter,
.splitpanes--horizontal .movable-splitter { .splitpanes--horizontal > .movable-splitter {
height: 8px; height: 8px;
width: 100%; width: 100%;
z-index: 5;
} }
.splitpanes__splitter .toggle-btn { /* Toggle buttons */
background-color: var(--color-border-light); .toggle-btns {
border-radius: var(--border-radius-small);
border: 1px solid var(--color-border);
position: absolute; position: absolute;
top: 50%; top: 50%;
left: 50%; left: 50%;
transform: translate(-50%, -50%); transform: translate(-50%, -50%);
box-sizing: border-box; display: flex;
} }
.splitpanes__splitter .toggle-btn:hover { .splitpanes--vertical > .splitpanes__splitter .toggle-btns {
flex-direction: column;
}
.splitpanes--horizontal > .splitpanes__splitter .toggle-btns {
flex-direction: row;
}
.toggle-btn {
background-color: var(--color-border-light);
border-radius: var(--border-radius-small);
border: 1px solid var(--color-border);
box-sizing: border-box;
position: relative;
cursor: pointer; cursor: pointer;
} }
.splitpanes--vertical .toggle-btn { .splitpanes--vertical > .splitpanes__splitter .toggle-btn {
height: 49px; height: 49px;
width: 8px; width: 8px;
} }
.splitpanes--horizontal .toggle-btn {
.splitpanes--horizontal > .splitpanes__splitter .toggle-btn {
width: 49px; width: 49px;
height: 8px; height: 8px;
} }
.splitpanes__splitter .toggle-btn .direction-icon {
.toggle-btn .direction-icon {
position: absolute; position: absolute;
top: 50%; top: 50%;
left: 50%; left: 50%;
} }
.splitpanes--horizontal > .splitpanes__splitter .toggle-btns.both .toggle-btn:first-child {
border-radius: var(--border-radius-small) 0 0 var(--border-radius-small);
}
.splitpanes--horizontal > .splitpanes__splitter .toggle-btns.both .toggle-btn:last-child {
border-radius: 0 var(--border-radius-small) var(--border-radius-small) 0;
margin-left: -1px;
}
.splitpanes--vertical > .splitpanes__splitter .toggle-btns.both .toggle-btn:first-child {
border-radius: var(--border-radius-small) var(--border-radius-small) 0 0;
}
.splitpanes--vertical > .splitpanes__splitter .toggle-btns.both .toggle-btn:last-child {
border-radius: 0 0 var(--border-radius-small) var(--border-radius-small);
margin-top: -1px;
}
</style> </style>

View File

@@ -3,7 +3,7 @@
<splitpanes <splitpanes
class="query-results-splitter" class="query-results-splitter"
horizontal horizontal
:before="{ size: 50, max: 70 }" :before="{ size: 50, max: 100 }"
:after="{ size: 50, max: 100 }" :after="{ size: 50, max: 100 }"
> >
<template #left-pane> <template #left-pane>
@@ -158,7 +158,7 @@ export default {
} }
.query-results-splitter { .query-results-splitter {
height: calc(100vh - 110px); height: calc(100vh - 104px);
background-color: var(--color-bg-light); background-color: var(--color-bg-light);
} }