Skip to content

Commit

Permalink
feat(popup): add tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkaintas committed Jul 27, 2022
1 parent 7e0c82c commit fa68416
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
'vue/multi-word-component-names': [
'error',
{
ignores: ['Header'],
ignores: ['Header', 'Tooltip'],
},
],
},
Expand Down
5 changes: 5 additions & 0 deletions client/src/assets/svg/info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions client/src/assets/svg/rectangle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions client/src/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ const channelStore = useChannelStore();
</template>

<style scoped lang="scss">
@import '../mediaqueries.scss';
.header {
display: flex;
justify-content: space-between;
padding: var(--padding);
padding-bottom: 5px;
height: 10%;
@include for-phone-only {
height: 15%;
}
}
.center {
Expand Down
6 changes: 4 additions & 2 deletions client/src/components/PopUp.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script setup lang="ts">
import { usePopUpStore } from '../stores/popup';
import GenericButton from './GenericButton.vue';
import Tooltip from './Tooltip.vue';
const store = usePopUpStore();
</script>

<template>
<div v-if="store.title" class="popup__wrapper">
<div class="popup">
<div class="title">{{ store.title }}</div>
<Tooltip v-if="store.tooltipText" :text="store.tooltipText" />
<div class="text" v-if="store.text" data-testid="popup-text">
{{ store.text }}
</div>
Expand All @@ -33,11 +35,11 @@ const store = usePopUpStore();
@import '../mediaqueries.scss';
.popup {
width: 50%;
max-width: 50%;
min-height: 200px;
border-radius: 15px;
background-color: white;
padding: 50px;
padding: 50px 100px;
padding-bottom: 40px;
display: flex;
flex-direction: column;
Expand Down
81 changes: 81 additions & 0 deletions client/src/components/Tooltip.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<script setup lang="ts">
defineProps<{
text: string;
}>();
</script>

<template>
<div class="tooltip" data-testid="tooltip">
<img src="../assets/svg/info.svg" alt="?" />
<div class="tooltip-text">
{{ text }}
</div>
</div>
</template>

<style scoped lang="scss">
@import '../mediaqueries.scss';
.tooltip {
position: absolute;
right: 70px;
transform: translateY(-20px);
img {
width: 20px;
height: 20px;
}
@include for-phone-only {
right: 20px;
transform: translateY(-30px);
}
.tooltip-text {
visibility: hidden;
opacity: 0;
transition: opacity 0.2s;
background-color: black;
color: #fff;
padding: 16px;
width: 300px;
background: #4e4e56;
border-radius: 8px 8px 0px 8px;
font-size: 14px;
line-height: 1.2;
position: absolute;
z-index: 1;
bottom: calc(100% + 15px);
right: calc(100% - 20px);
&::after {
content: url('../assets/svg/rectangle.svg');
position: absolute;
transform: scaleX(-1);
top: calc(100% - 1px);
right: 0;
}
@include for-desktop-up {
width: 300px;
bottom: calc(100% + 15px);
border-radius: 8px 8px 8px 0px;
left: 0;
&::after {
content: url('../assets/svg/rectangle.svg');
position: absolute;
transform: unset;
top: calc(100% - 1px);
right: unset;
left: 0;
}
}
@include for-phone-only {
width: 70vw;
max-width: 300px;
}
}
img:hover ~ .tooltip-text {
visibility: visible;
opacity: 1;
}
}
</style>
4 changes: 4 additions & 0 deletions client/src/stores/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface PopUpData {
secBtnText?: string;
mainBtnAction: () => void;
secBtnAction?: () => void;
tooltipText?: string;
}

export const usePopUpStore = defineStore('popup', {
Expand All @@ -18,6 +19,7 @@ export const usePopUpStore = defineStore('popup', {
secBtnText: '',
mainBtnAction: () => void 0,
secBtnAction: () => void 0,
tooltipText: undefined,
} as PopUpData),
actions: {
showPopUp(options: PopUpData) {
Expand All @@ -28,6 +30,7 @@ export const usePopUpStore = defineStore('popup', {
this.secBtnText = options.secBtnText ?? '';
this.mainBtnAction = options.mainBtnAction;
this.secBtnAction = options.secBtnAction;
this.tooltipText = options.tooltipText;
},
resetPopUp() {
this.title = '';
Expand All @@ -36,6 +39,7 @@ export const usePopUpStore = defineStore('popup', {
this.secBtnText = '';
this.mainBtnAction = () => void 0;
this.secBtnAction = () => void 0;
this.tooltipText = undefined;
},
},
});
11 changes: 11 additions & 0 deletions client/tests/popup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const fakePopUpData: Required<PopUpData> = {
secBtnText: 'Second button',
mainBtnAction: () => counter.value++,
secBtnAction: () => counter.value--,
tooltipText: 'This is a tooltip',
};

const singleButtonPopUpData: PopUpData = {
Expand Down Expand Up @@ -66,5 +67,15 @@ describe('PopUp', () => {
expect(() => {
popUpEl.getByTestId('popup-text');
}).toThrow('Unable to find an element by: [data-testid="popup-text"]');
expect(() => {
popUpEl.getByTestId('tooltip');
}).toThrow('Unable to find an element by: [data-testid="tooltip"]');
});

it('displays popup with tooltip', async () => {
const popUpEl = renderPopUp(fakePopUpData);
expect(popUpEl.getByTestId('tooltip')).toBeTruthy();
const tooltipTextEl = popUpEl.getByText(fakePopUpData.tooltipText);
expect(tooltipTextEl).toBeTruthy();
});
});

0 comments on commit fa68416

Please sign in to comment.