Skip to content

Commit

Permalink
feat: add tooltip to table
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Jun 17, 2021
1 parent 4dd47c0 commit 48f3ea2
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 20 deletions.
11 changes: 9 additions & 2 deletions packages/ui/assets/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
--bg: #2D2C39;
--responsive-menu: #fdfdfd;
--text: #fdfdfd;
--link: #E54343;
--text-background: #2d2c39d3;
--default-border: 1px solid #fdfdfd;

Expand Down Expand Up @@ -68,6 +67,10 @@
--text-background: #2d2c39d3;
--default-border: 1px solid #fdfdfd;

//Tooltip

--tooltip-background: #FFFFFF10;

// Select

--selected-background: #37414c;
Expand Down Expand Up @@ -130,6 +133,10 @@
--text-background: #ffffffd3;
--default-border: 1px solid #2D2C39;

//Tooltip

--tooltip-background: #2d2c3910;

// Select

--selected-background: linear-gradient(90deg, #3f92a5 0%, #41bea5 57%);;
Expand All @@ -149,7 +156,7 @@
--network-color: #41BEA5;
--name-color: #1F1F24;
--value-color: #1F1F24;
--card-box-shadow: rgba(100, 100, 111, 0.2) 0 7px 29px 0;
--card-box-shadow: #1f1f2421 0 4px 16px;
--mainnet-network-color: #41BEA5de;
--rinkeby-network-color: #BEA241de;
--goerli-network-color: #4182bede;
Expand Down
1 change: 0 additions & 1 deletion packages/ui/components/DataFeedDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export default {
return this.feed.requests.map((request) => {
return {
witnetLink: request.drTxHash,
etherscanLink: request.address,
data: {
label: this.feed.label,
value: request.result,
Expand Down
120 changes: 120 additions & 0 deletions packages/ui/components/DataTooltip.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<template>
<div class="container" @mouseout="hide()">
<div
v-if="showTooltip"
class="tooltip"
:style="{ top: valueTopPosition, left: valueLeftPosition }"
>
{{ value }}
</div>
<div :ref="label" class="truncate" @mousemove="show()">
{{ value }}
</div>
<div
ref="copy"
class="copy"
@click="copy"
@mousemove="showCopyTooltip = true"
@mouseleave="showCopyTooltip = false"
>
<div
v-if="copied"
class="copy-tooltip"
:style="{ top: copyTopPosition, left: copyLeftPosition }"
>
{{ $t('copied') }}
</div>
<div
v-if="showCopyTooltip"
class="copy-tooltip"
:style="{ top: copyTopPosition, left: copyLeftPosition }"
>
{{ $t('copy') }}
</div>
<font-awesome-icon class="icon" icon="copy" />
</div>
</div>
</template>

<script>
import { copyToClipboard } from '@/utils/copyToClipboard'
export default {
props: {
value: {
type: String,
required: true,
},
label: {
type: String,
required: true,
},
},
data() {
return {
showTooltip: false,
showCopyTooltip: false,
copied: false,
}
},
computed: {
valueTopPosition() {
return `${this.$refs[this.label].offsetTop - 50}px`
},
valueLeftPosition() {
return `${this.$refs[this.label].offsetLeft + 10}px`
},
copyTopPosition() {
return `${this.$refs.copy.offsetTop - 30}px`
},
copyLeftPosition() {
return `${this.$refs.copy.offsetLeft + 10}px`
},
},
methods: {
copy() {
this.showCopyTooltip = false
copyToClipboard(this.value)
this.copied = true
setTimeout(() => {
this.copied = false
}, 500)
},
show() {
this.showTooltip =
this.$refs[this.label].offsetWidth < this.$refs[this.label].scrollWidth
},
hide() {
this.showTooltip = false
},
},
}
</script>

<style lang="scss" scoped>
.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.tooltip,
.copy-tooltip {
position: absolute;
display: inline-block;
font-size: 16px;
padding: 8px;
border-radius: 4px;
background-color: var(--bg);
color: var(--text);
}
.container {
display: flex;
justify-content: space-between;
}
.copy {
padding: 16px;
margin: -16px;
font-size: 12px;
cursor: pointer;
}
</style>
1 change: 1 addition & 0 deletions packages/ui/components/Fieldset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default {
}
.content {
background: var(--fieldset-background);
box-shadow: var(--card-box-shadow);
border-radius: 4px;
height: max-content;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default {
color: var(--text);
align-items: center;
text-decoration: none;
margin: 24px 32px;
margin: 16px 24px;
&:hover {
color: var(--text-hover);
}
Expand Down
20 changes: 6 additions & 14 deletions packages/ui/components/Transaction.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<template>
<li class="item-container">
<div class="attribute-container links">
<div class="attribute truncate">{{ witnetLink }}</div>
<DataTooltip
:label="`${witnetLink}1`"
class="attribute"
:value="witnetLink"
/>
</div>
<div class="attribute-container values-time">
<div class="attribute">{{ value }}</div>
<DataTooltip :label="`${value}2`" class="attribute" :value="value" />
<div class="attribute">
{{ calculateTimeAgo(timestamp, $i18n.locale) }}
</div>
Expand All @@ -23,10 +27,6 @@ export default {
type: String,
required: true,
},
etherscanLink: {
type: String,
required: true,
},
data: {
type: Object,
required: true,
Expand All @@ -46,11 +46,3 @@ export default {
},
}
</script>

<style lang="scss" scoped>
.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
1 change: 0 additions & 1 deletion packages/ui/components/TransactionsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
:key="transaction.witnetLink"
:class="{ blur: index % 2 }"
:witnet-link="transaction.witnetLink"
:etherscan-link="transaction.etherscanLink"
:data="transaction.data"
:timestamp="transaction.timestamp"
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default {

fontawesome: {
icons: {
solid: ['faMoon', 'faSun', 'faArrowAltCircleLeft'],
solid: ['faMoon', 'faSun', 'faArrowAltCircleLeft', 'faCopy'],
},
},

Expand Down
9 changes: 9 additions & 0 deletions packages/ui/utils/copyToClipBoard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function copyToClipboard(str) {
const listener = function (ev) {
ev.preventDefault()
ev.clipboardData.setData('text/plain', str)
}
document.addEventListener('copy', listener)
document.execCommand('copy')
document.removeEventListener('copy', listener)
}

0 comments on commit 48f3ea2

Please sign in to comment.