-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tooltip): initial implementation (#101)
- Loading branch information
Showing
14 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Tooltip by default renders correctly 1`] = `<div role="tooltip" class="vnt-tooltip" style="position: absolute; left: 0px; top: 0px; margin: 0px;">Tooltip text</div>`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { createLocalVue, shallowMount } from '@vue/test-utils'; | ||
import { VntTooltip } from '@/components'; | ||
import { isInstalled } from './utils'; | ||
|
||
describe('Tooltip', () => { | ||
let localVue, wrapper; | ||
|
||
beforeAll(() => { | ||
localVue = createLocalVue(); | ||
localVue.use(VntTooltip); | ||
}); | ||
|
||
test('can be installed separately', () => { | ||
expect(isInstalled(localVue, VntTooltip)).toBe(true); | ||
}); | ||
|
||
describe('by default', () => { | ||
|
||
beforeAll(() => { | ||
wrapper = shallowMount(VntTooltip, { | ||
localVue, | ||
slots: { | ||
default: 'Tooltip text' | ||
} | ||
}); | ||
}); | ||
|
||
test('renders correctly', () => { | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('doesn\'t break when destroyed', () => { | ||
wrapper.destroy(); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ module.exports = { | |
'select', | ||
'slider', | ||
'toggle', | ||
'tooltip', | ||
'website' | ||
] | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<template> | ||
<div class="playground"> | ||
<vnt-button> | ||
Hover me | ||
<vnt-tooltip>Tooltip text</vnt-tooltip> | ||
</vnt-button> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { VntTooltip, VntButton } from '../../../src/components'; | ||
export default { | ||
name: 'TooltipBasic', | ||
components: { | ||
VntButton, | ||
VntTooltip | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Tooltip | ||
|
||
[[toc]] | ||
|
||
## Basic | ||
|
||
<tooltip-basic /> | ||
|
||
```html | ||
<vnt-button> | ||
Hover me | ||
<vnt-tooltip>Tooltip text</vnt-tooltip> | ||
</vnt-button> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Tooltip | ||
|
||
## How to use | ||
|
||
```html | ||
<div> | ||
Hover me to see a tooltip. | ||
<vnt-tooltip> | ||
Tooltip text | ||
</vnt-tooltip> | ||
</div> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<template> | ||
<div class="vnt-tooltip" | ||
role="tooltip"> | ||
<slot></slot> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { createPopper } from '@popperjs/core'; | ||
const showEvents = ['mouseenter', 'focus']; | ||
const hideEvents = ['mouseleave', 'blur']; | ||
export default { | ||
name: 'VntTooltip', | ||
mounted() { | ||
const parent = this.$parent.$el; | ||
const tooltip = createPopper(parent, this.$el, { | ||
placement: 'top', | ||
modifiers: [ | ||
{ | ||
name: 'offset', | ||
options: { | ||
offset: [8, 8] | ||
} | ||
}, | ||
{ | ||
name: 'flip', | ||
options: { | ||
fallbackPlacements: ['top-start', 'top-end', 'right', 'left', 'bottom'] | ||
} | ||
} | ||
] | ||
}); | ||
showEvents.forEach(event => { | ||
parent.addEventListener(event, () => this.$el.setAttribute('data-show', '')); | ||
}); | ||
hideEvents.forEach(event => { | ||
parent.addEventListener(event, () => this.$el.removeAttribute('data-show')); | ||
}); | ||
this.$tooltip = tooltip; | ||
}, | ||
destroyed() { | ||
this.$tooltip.destroy(); | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang="scss"> | ||
@import '../../scss/mixins/component'; | ||
.vnt-tooltip { | ||
@include component-base; | ||
display: none; | ||
border: 1px solid #ccc; | ||
background: #f2f2f2; | ||
padding: 8px; | ||
font-size: 12px; | ||
line-height: 1.33; | ||
} | ||
.vnt-tooltip[data-show] { | ||
display: block; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Tooltip from './Tooltip.vue'; | ||
|
||
Tooltip.install = function (Vue) { | ||
Vue.component(Tooltip.name, Tooltip); | ||
}; | ||
|
||
export default Tooltip; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { storiesOf } from '@storybook/vue'; | ||
|
||
/* eslint no-undef: 0 */ | ||
storiesOf('Tooltip', module) | ||
.add('button', () => ({ | ||
template: ` | ||
<vnt-button style="margin: 80px"> | ||
Hover me | ||
<vnt-tooltip>Tooltip text</vnt-tooltip> | ||
</vnt-button> | ||
` | ||
})) | ||
.add('text', () => ({ | ||
template: ` | ||
<p style="margin: 80px; width: 300px; padding: 4px;"> | ||
Lorem ipsum dolor sit amet | ||
<vnt-tooltip>Tooltip text</vnt-tooltip> | ||
</p> | ||
` | ||
})) | ||
.add('image', () => ({ | ||
template: ` | ||
<figure style="width: 200px; height: 150px; margin: 50px"> | ||
<img src="https://dummyimage.com/200x150/000/fff.jpg&text=Test+image" width="200" height="150" /> | ||
<vnt-tooltip>Tooltip text</vnt-tooltip> | ||
</picture> | ||
` | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters