Skip to content
This repository was archived by the owner on Mar 9, 2023. It is now read-only.

Commit 64dceb2

Browse files
authored
Merge pull request #28 from line/copy-pivot-table
Add copy-to-clipboard button to menu
2 parents 03d3a9f + c6ef1a7 commit 64dceb2

File tree

3 files changed

+77
-6
lines changed

3 files changed

+77
-6
lines changed

package-lock.json

Lines changed: 34 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vue-pivot-table-plus",
33
"description": "A customized vue component for pivot table",
44
"private": false,
5-
"version": "0.6.2",
5+
"version": "0.7.0",
66
"author": "LINE Corporation",
77
"license": "Apache-2.0",
88
"repository": {
@@ -17,6 +17,7 @@
1717
},
1818
"dependencies": {
1919
"bootstrap-vue": "^2.18.1",
20+
"clipboard": "^2.0.6",
2021
"core-js": "^2.6.11",
2122
"javascript-natural-sort": "^0.7.1",
2223
"jquery": "^3.5.1",

src/Pivot.vue

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
</div>
5151

5252
<!-- Table -->
53-
<div class="col table-responsive pivottable">
53+
<div class="p-0 position-relative col table-responsive pivottable">
5454
<pivot-table
5555
ref="pivottable"
5656
:data="data"
@@ -70,18 +70,25 @@
7070
<slot name="loading"></slot>
7171
</template>
7272
</pivot-table>
73+
<transition name="copied-alert">
74+
<div v-if="showCopiedAlert" class="alert alert-secondary pivot-copied-alert">
75+
Copied to clipboard
76+
</div>
77+
</transition>
7378
</div>
7479

7580
<div v-if="showSettings" class="table-option-button circle-background bg-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-b-tooltip:hover title="Show menu"></div>
7681
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
77-
<a class="dropdown-item" href="#!" @click="_clickedSaveButton('csv')">Save table in CSV</a>
78-
<a class="dropdown-item" href="#!" @click="_clickedSaveButton('tsv')">Save table in TSV</a>
82+
<button ref="pivot-copy-button" class="dropdown-item" >Copy table to clipboard</button>
83+
<button class="dropdown-item" @click="_clickedSaveButton('csv')">Save table in CSV</button>
84+
<button class="dropdown-item" @click="_clickedSaveButton('tsv')">Save table in TSV</button>
7985
</div>
8086
</div>
8187
</div>
8288
</template>
8389

8490
<script>
91+
import Clipboard from 'clipboard'
8592
import PivotTable from './PivotTable.vue'
8693
import naturalSort from 'javascript-natural-sort'
8794
import Draggable from 'vuedraggable'
@@ -161,12 +168,23 @@ export default {
161168
colFields: this.fields.colFields,
162169
fieldsOrder: this.fields.fieldsOrder
163170
},
164-
dragging: false
171+
dragging: false,
172+
showCopiedAlert: false
165173
}
166174
},
167175
created () {
168176
this._sortFields(this.internal.fieldsOrder)
169177
},
178+
mounted () {
179+
const self = this
180+
const clipboard = new Clipboard(self.$refs['pivot-copy-button'], {
181+
target: () => self.$refs.pivottable.$el
182+
})
183+
clipboard.on('success', (e) => {
184+
e.clearSelection()
185+
self.onPivotTableCopied(e)
186+
})
187+
},
170188
computed: {
171189
dragAreaClass: function () {
172190
return this.dragging ? 'drag-area--highlight' : null
@@ -239,6 +257,10 @@ export default {
239257
this.internal.fieldsOrder = { ...this.internal.fieldsOrder, [label]: 'desc' }
240258
}
241259
this._sortFields(this.internal.fieldsOrder)
260+
},
261+
onPivotTableCopied () {
262+
this.showCopiedAlert = true
263+
setTimeout(() => { this.showCopiedAlert = false }, 700)
242264
}
243265
}
244266
}
@@ -360,6 +382,7 @@ $carret-bold-svg: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/200
360382
}
361383
362384
.pivottable {
385+
margin: 0 15px;
363386
& ~ .table-option-button {
364387
opacity: 0;
365388
}
@@ -381,4 +404,18 @@ $hamburger-svg: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/
381404
border-width: 2px !important;
382405
left: $base-space*3 + 10rem - $border-space*3;
383406
}
407+
408+
.pivot-copied-alert {
409+
position: absolute;
410+
bottom: 1rem;
411+
right: 1rem;
412+
}
413+
414+
.copied-alert-enter-active {
415+
opacity: 0.6;
416+
}
417+
.copied-alert-leave-active {
418+
opacity: 0;
419+
transition: all 0.7s ease;
420+
}
384421
</style>

0 commit comments

Comments
 (0)