Created ft-tooltip component. (#684)

This commit is contained in:
Violet Rose 2020-10-19 07:10:26 -07:00 committed by GitHub
parent 07312ec16a
commit b578be1059
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 133 additions and 0 deletions

View File

@ -0,0 +1,87 @@
.button {
background-color: transparent;
border-style: none;
color: var(--primary-text-color);
cursor: pointer;
font-size: 1rem;
padding: 0;
}
.button:focus + .text,
.button:hover + .text {
opacity: 1;
visibility: visible;
}
.button:focus + .text.bottom,
.button:hover + .text.bottom,
.button:focus + .text.top,
.button:hover + .text.top {
-webkit-transform: translate(-50%, 0);
transform: translate(-50%, 0);
}
.button:focus + .text.left,
.button:hover + .text.left,
.button:focus + .text.right,
.button:hover + .text.right {
-webkit-transform: translate(0, -50%);
transform: translate(0, -50%);
}
.text {
background-color: black;
border-radius: 2px;
color: #fff;
font-size: 1rem;
line-height: 120%;
margin: 0;
max-width: 10em;
min-width: max-content;
opacity: 0;
padding: 10px 8px;
pointer-events: none;
position: absolute;
text-align: center;
transition-duration: 275ms;
transition-property: opacity, transform, visibility;
visibility: hidden;
z-index: 4;
}
.text.bottom {
margin-top: 1em;
top: 100%;
left: 50%;
-webkit-transform: translate(-50%, -1em);
transform: translate(-50%, -1em);
}
.text.left {
margin-right:1em;
right: 100%;
top: 50%;
-webkit-transform: translate(1em, -50%);
transform: translate(1em, -50%);
}
.text.right {
left: 100%;
margin-left: 1em;
top: 50%;
-webkit-transform: translate(-1em, -50%);
transform: translate(-1em, -50%);
}
.text.top {
bottom: 100%;
left: 50%;
margin-bottom: 1em;
-webkit-transform: translate(-50%, 1em);
transform: translate(-50%, 1em);
}
.tooltip {
display: inline-block;
position: relative;
}

View File

@ -0,0 +1,24 @@
import Vue from 'vue'
import { uniqueId } from 'lodash'
export default Vue.extend({
name: 'FtTooltip',
props: {
position: {
type: String,
default: 'bottom',
validator: (value) => value === 'bottom' || value === 'left' || value === 'right' || value === 'top'
},
tooltip: {
type: String,
required: true
}
},
data() {
const id = uniqueId('ft-tooltip-')
return {
id
}
}
})

View File

@ -0,0 +1,22 @@
<template>
<div class="tooltip">
<button
:aria-labelledby="id"
class="button"
type="button"
>
<font-awesome-icon icon="question-circle" />
</button>
<p
:id="id"
class="text"
:class="position"
role="tooltip"
>
{{ tooltip }}
</p>
</div>
</template>
<script src="./ft-tooltip.js" />
<style scoped src="./ft-tooltip.css" />