-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Tooltip.vue #97
base: v3
Are you sure you want to change the base?
Changes from all commits
0a7cc99
cbdb424
1ffcb5d
280db1d
f55cccf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,21 @@ | |
<div class="tooltip"> | ||
<div ref="target" class="target" @mouseenter="onMouseEnter" | ||
@mouseleave="onMouseLeave"> | ||
<slot/> | ||
<slot /> | ||
<transition name="fade"> | ||
<Popper v-if="show" ref="popper" :transition-delay="0" | ||
:boundaries-element="boundariesElement" | ||
:target-element="$refs.target" :placement="placement" :offset="offset"> | ||
<span v-if=label ref="label" class="label no-click" :disabled="disabled"> | ||
{{ label }} | ||
</span> | ||
<span v-else ref="label" class="label" :disabled="disabled" @mouseenter="onMouseEnter" | ||
@mouseleave="onMouseLeave"> | ||
<slot name="label"></slot> | ||
</span> | ||
</Popper> | ||
</transition> | ||
</div> | ||
<transition name="fade"> | ||
<Popper v-if="show" ref="popper" :transition-delay="300" | ||
:boundaries-element="boundariesElement" | ||
:target-element="$refs.target" :placement="placement" :offset="offset"> | ||
<span ref="label" class="label" :disabled="disabled">{{ label }}</span> | ||
</Popper> | ||
</transition> | ||
</div> | ||
</template> | ||
|
||
|
@@ -23,48 +29,58 @@ | |
props: { | ||
label: { | ||
type: String, | ||
required: true | ||
}, | ||
placement: { | ||
type: String, | ||
default: 'bottom' | ||
default: 'bottom', | ||
}, | ||
disabled: { | ||
type: Boolean, | ||
default: false | ||
default: false, | ||
}, | ||
offset: { | ||
type: String, | ||
default: '0,5' | ||
default: '0,5', | ||
}, | ||
appendToBody: { | ||
type: Boolean, | ||
default: false | ||
default: false, | ||
}, | ||
boundariesElement: { | ||
type: String, | ||
default: 'viewport' | ||
} | ||
default: 'viewport', | ||
}, | ||
delay: { | ||
type: Number, | ||
default: 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say to go with the default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should change the default behaviour |
||
}, | ||
}, | ||
data() { | ||
return { | ||
show: false | ||
timeoutId: undefined, | ||
show: false, | ||
}; | ||
}, | ||
methods: { | ||
onMouseEnter() { | ||
this.show = true; | ||
if (this.appendToBody) { | ||
this.$nextTick(() => { | ||
this.append(); | ||
}); | ||
} | ||
if (this.timeoutId) clearTimeout(this.timeoutId); | ||
this.timeoutId = setTimeout(() => { | ||
this.show = true; | ||
if (this.appendToBody) { | ||
this.$nextTick(() => { | ||
this.append(); | ||
}); | ||
} | ||
}, this.delay); | ||
}, | ||
onMouseLeave() { | ||
if (this.appendToBody) { | ||
document.body.removeChild(this.$refs.label); | ||
} | ||
this.show = false; | ||
if (this.timeoutId) clearTimeout(this.timeoutId); | ||
this.timeoutId = setTimeout(() => { | ||
if (this.appendToBody) { | ||
document.body.removeChild(this.$refs.label); | ||
} | ||
this.show = false; | ||
}, this.delay); | ||
}, | ||
append() { | ||
document.body.appendChild(this.$refs.label); | ||
|
@@ -73,8 +89,8 @@ | |
this.$refs.popper.update(); | ||
} | ||
}, 0); | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
|
@@ -92,12 +108,15 @@ | |
font-weight: 400; | ||
box-shadow: 0 1px 2px 1px rgba(0, 1, 0, 0.2); | ||
white-space: nowrap; | ||
pointer-events: none; | ||
border-radius: 3px; | ||
background-color: var(--ds-background-neutral-bold, #172b4d); | ||
color: var(--ds-text-inverse, #FFF); | ||
} | ||
|
||
.no-click { | ||
pointer-events: none; | ||
} | ||
|
||
.fade-enter-active, | ||
.fade-leave-active { | ||
transition: opacity 0.3s; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<template> | ||
<div class="buttons-group"> | ||
<Tooltip | ||
v-for="placement in placements" | ||
:key="placement" | ||
delay=500 | ||
:placement="placement"> | ||
<template #label> | ||
<b>I support html elements </b> 😜 | ||
</template> | ||
<Button>Hover over me!</Button> | ||
</Tooltip> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import Tooltip from '@/components/Tooltip/Tooltip'; | ||
import Button from '@/components/Button/Button'; | ||
|
||
export default { | ||
name: 'TooltipWithHtmlLabelStory', | ||
components: { Tooltip, Button }, | ||
data() { | ||
return { | ||
placements: ['top', 'right', 'bottom', 'left'] | ||
}; | ||
} | ||
}; | ||
</script> | ||
<style scoped> | ||
.buttons-group { | ||
max-width: 800px; | ||
margin-top: 50px; | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
</style> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two tooltips, one being empty.
On Storybook (http://localhost:9001/?path=/story/tooltip--tooltip):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed