@eturnity/eturnity_reusable_components 7.45.0 → 7.45.1-EPDM-12459.1
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
/* eslint-disable */
|
2
|
+
import { h } from 'vue'
|
3
|
+
import { mount } from '@vue/test-utils'
|
4
|
+
import InfoBanner from '@/components/banner/infoBanner'
|
5
|
+
import theme from '@/assets/theme'
|
6
|
+
|
7
|
+
jest.mock('@/components/icon/iconCache.mjs', () => ({
|
8
|
+
// need to mock this due to how jest handles import.meta
|
9
|
+
fetchIcon: jest.fn(() => Promise.resolve('')),
|
10
|
+
}))
|
11
|
+
|
12
|
+
describe('Info Banner Component', () => {
|
13
|
+
const props = {
|
14
|
+
isOpen: false,
|
15
|
+
buttonLabel: 'Gotcha',
|
16
|
+
}
|
17
|
+
|
18
|
+
const global = {
|
19
|
+
provide: {
|
20
|
+
theme,
|
21
|
+
},
|
22
|
+
}
|
23
|
+
|
24
|
+
it('info banner is shown when isOpen props is true', async () => {
|
25
|
+
const wrapper = mount(InfoBanner, {
|
26
|
+
props,
|
27
|
+
global,
|
28
|
+
})
|
29
|
+
|
30
|
+
const bannerWrapper = wrapper.find('[data-test-id="info_banner_wrapper"]')
|
31
|
+
expect(bannerWrapper.exists()).toBe(true)
|
32
|
+
expect(bannerWrapper.classes()).not.toContain('visible')
|
33
|
+
expect(bannerWrapper.classes()).toContain('hidden')
|
34
|
+
await wrapper.setProps({ isOpen: true })
|
35
|
+
expect(bannerWrapper.classes()).toContain('visible')
|
36
|
+
expect(bannerWrapper.classes()).not.toContain('hidden')
|
37
|
+
})
|
38
|
+
|
39
|
+
it('info banner slots is display when user passed slots content', async () => {
|
40
|
+
const titleText = 'Sample title'
|
41
|
+
const bodyText = 'Sample body text'
|
42
|
+
|
43
|
+
const wrapper = mount(InfoBanner, {
|
44
|
+
props,
|
45
|
+
slots: {
|
46
|
+
title: titleText,
|
47
|
+
body: bodyText,
|
48
|
+
},
|
49
|
+
global,
|
50
|
+
})
|
51
|
+
|
52
|
+
const modalTitleEl = wrapper.find('[data-test-id="modal_title"]')
|
53
|
+
expect(modalTitleEl.text()).toBe(titleText)
|
54
|
+
const modalBodyEl = wrapper.find('[data-test-id="modal_body"]')
|
55
|
+
expect(modalBodyEl.text()).toBe(bodyText)
|
56
|
+
})
|
57
|
+
|
58
|
+
it('info banner on-close event is emitted when modal close button is clicked', async () => {
|
59
|
+
const wrapper = mount(InfoBanner, {
|
60
|
+
props,
|
61
|
+
global,
|
62
|
+
})
|
63
|
+
|
64
|
+
const modalCloseButton = wrapper.find('.close')
|
65
|
+
await modalCloseButton.trigger('click')
|
66
|
+
expect(wrapper.emitted('on-close')).toBeTruthy()
|
67
|
+
const emittedEvent = wrapper.emitted('on-close')
|
68
|
+
expect(emittedEvent).toHaveLength(1)
|
69
|
+
})
|
70
|
+
})
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import InfoBanner from './index.vue'
|
2
|
+
import theme from '@/assets/theme'
|
3
|
+
export default {
|
4
|
+
title: 'InfoBanner',
|
5
|
+
component: InfoBanner,
|
6
|
+
tags: ['autodocs'],
|
7
|
+
}
|
8
|
+
|
9
|
+
// <RCInfoBanner
|
10
|
+
// :isOpen="true"
|
11
|
+
// buttonLabel="Got it"
|
12
|
+
// @on-close="handleClose"
|
13
|
+
// >
|
14
|
+
// <template #title>Sample title</template>
|
15
|
+
// <template #body>Sample body</template>
|
16
|
+
// </RCInfoBanner>
|
17
|
+
|
18
|
+
export const Default = {
|
19
|
+
args: {
|
20
|
+
isOpen: false,
|
21
|
+
buttonLabel: 'Got it',
|
22
|
+
},
|
23
|
+
}
|
24
|
+
|
25
|
+
export const OpenedInfoBanner = {
|
26
|
+
args: {
|
27
|
+
isOpen: true,
|
28
|
+
buttonLabel: 'Got it',
|
29
|
+
},
|
30
|
+
render: (args) => ({
|
31
|
+
components: { InfoBanner },
|
32
|
+
setup() {
|
33
|
+
return { args }
|
34
|
+
},
|
35
|
+
template: `
|
36
|
+
<InfoBanner v-bind="args">
|
37
|
+
<template #title>Sample title</template>
|
38
|
+
<template #body>Sample body</template>
|
39
|
+
</InfoBanner>
|
40
|
+
`,
|
41
|
+
}),
|
42
|
+
}
|
@@ -1,45 +1,75 @@
|
|
1
1
|
<template>
|
2
|
-
<
|
2
|
+
<RCModal
|
3
|
+
data-test-id="info_banner_wrapper"
|
4
|
+
:is-open="isOpen"
|
5
|
+
@on-close="closeModal"
|
6
|
+
>
|
3
7
|
<ModalContainer>
|
4
|
-
<
|
8
|
+
<ModalTitle v-if="$slots.title" data-test-id="modal_title">
|
5
9
|
<slot name="title"></slot>
|
6
|
-
</
|
7
|
-
<
|
10
|
+
</ModalTitle>
|
11
|
+
<TextContainer v-if="$slots.body" data-test-id="modal_body">
|
8
12
|
<slot name="body"></slot>
|
9
|
-
</
|
10
|
-
<
|
11
|
-
<
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
</template>
|
13
|
+
</TextContainer>
|
14
|
+
<ButtonContainer>
|
15
|
+
<RCButton
|
16
|
+
data-test-id="modal_buttons"
|
17
|
+
min-width="150px"
|
18
|
+
:text="buttonText"
|
19
|
+
type="primary"
|
20
|
+
@click="closeModal"
|
21
|
+
/>
|
22
|
+
</ButtonContainer>
|
20
23
|
</ModalContainer>
|
21
|
-
</
|
24
|
+
</RCModal>
|
22
25
|
</template>
|
23
26
|
<script>
|
24
27
|
import styled from 'vue3-styled-components'
|
25
|
-
import
|
28
|
+
import RCModal from '@/components/modals/modal'
|
29
|
+
import RCButton from '@/components/buttons/mainButton'
|
26
30
|
|
27
31
|
const ModalContainer = styled.div`
|
28
32
|
width: 450px;
|
33
|
+
display: flex;
|
34
|
+
flex-direction: column;
|
29
35
|
min-height: 205px;
|
30
36
|
padding: 40px 40px 30px 40px;
|
31
37
|
`
|
38
|
+
|
39
|
+
const ModalTitle = styled.div`
|
40
|
+
color: ${(props) => props.theme.colors.black};
|
41
|
+
font-family: inherit;
|
42
|
+
font-size: 18px;
|
43
|
+
font-style: normal;
|
44
|
+
font-weight: 700;
|
45
|
+
line-height: 120%;
|
46
|
+
text-transform: uppercase;
|
47
|
+
`
|
32
48
|
const ButtonContainer = styled.div`
|
33
49
|
display: inline-flex;
|
34
|
-
|
50
|
+
flex-grow: 1;
|
51
|
+
align-items: flex-end;
|
35
52
|
gap: 20px;
|
36
53
|
`
|
54
|
+
const TextContainer = styled.div`
|
55
|
+
color: ${(props) => props.theme.colors.black};
|
56
|
+
font-family: inherit;
|
57
|
+
font-size: 13px;
|
58
|
+
font-style: normal;
|
59
|
+
font-weight: 400;
|
60
|
+
line-height: normal;
|
61
|
+
padding: 30px 0px;
|
62
|
+
white-space: pre-wrap;
|
63
|
+
`
|
37
64
|
export default {
|
38
65
|
name: 'InfoModal',
|
39
66
|
components: {
|
40
67
|
ModalContainer,
|
68
|
+
ModalTitle,
|
69
|
+
TextContainer,
|
41
70
|
ButtonContainer,
|
42
|
-
|
71
|
+
RCModal,
|
72
|
+
RCButton,
|
43
73
|
},
|
44
74
|
props: {
|
45
75
|
isOpen: {
|
@@ -47,6 +77,16 @@
|
|
47
77
|
default: false,
|
48
78
|
type: Boolean,
|
49
79
|
},
|
80
|
+
buttonLabel: {
|
81
|
+
default: null,
|
82
|
+
type: String,
|
83
|
+
},
|
84
|
+
},
|
85
|
+
computed: {
|
86
|
+
buttonText() {
|
87
|
+
//work around for storybook not finding the $gettext function
|
88
|
+
return this.buttonLabel || this.$gettext('Got it')
|
89
|
+
},
|
50
90
|
},
|
51
91
|
methods: {
|
52
92
|
closeModal() {
|
@@ -120,6 +120,11 @@
|
|
120
120
|
<SelectDropdown
|
121
121
|
v-show="isSelectDropdownShown"
|
122
122
|
ref="dropdown"
|
123
|
+
:style="{
|
124
|
+
transform: `translate(${dropdownPosition?.left}px, ${
|
125
|
+
noRelative ? 'auto' : `${dropdownPosition?.top}px`
|
126
|
+
})`,
|
127
|
+
}"
|
123
128
|
:bg-color="
|
124
129
|
dropdownBgColor || colorMode == 'dark' ? 'black' : 'white'
|
125
130
|
"
|
@@ -344,9 +349,8 @@
|
|
344
349
|
box-sizing: border-box;
|
345
350
|
z-index: ${(props) => (props.isActive ? '2' : '99999')};
|
346
351
|
position: absolute;
|
347
|
-
top:
|
348
|
-
|
349
|
-
left: ${(props) => props.dropdownPosition?.left}px;
|
352
|
+
top: 0px;
|
353
|
+
left: 0px;
|
350
354
|
border: ${BORDER_WIDTH} solid ${(props) => props.theme.colors.grey4};
|
351
355
|
border-radius: 4px;
|
352
356
|
display: flex;
|
@@ -606,6 +610,10 @@
|
|
606
610
|
},
|
607
611
|
dropdownWidth: null,
|
608
612
|
hoveredValue: null,
|
613
|
+
isDisplayedAtBottom: true,
|
614
|
+
selectTopPosition: 0,
|
615
|
+
selectAndDropdownDistance: 0,
|
616
|
+
animationFrameId: null,
|
609
617
|
}
|
610
618
|
},
|
611
619
|
computed: {
|
@@ -676,8 +684,13 @@
|
|
676
684
|
}, 10)
|
677
685
|
await this.$nextTick()
|
678
686
|
this.handleSetDropdownOffet()
|
687
|
+
this.calculateSelectTopPosition()
|
679
688
|
} else {
|
680
689
|
this.dropdownPosition.left = null
|
690
|
+
if (this.animationFrameId) {
|
691
|
+
cancelAnimationFrame(this.animationFrameId)
|
692
|
+
this.animationFrameId = null
|
693
|
+
}
|
681
694
|
setTimeout(() => {
|
682
695
|
this.isClickOutsideActive = false
|
683
696
|
}, 10)
|
@@ -690,11 +703,27 @@
|
|
690
703
|
})
|
691
704
|
}
|
692
705
|
},
|
706
|
+
isSelectDropdownShown(isShown) {
|
707
|
+
if (!isShown) return
|
708
|
+
|
709
|
+
// Need to wait for 1ms to make sure the dropdown menu is shown in the DOM
|
710
|
+
// before getting the distance between the select and the dropdown menu
|
711
|
+
setTimeout(() => {
|
712
|
+
this.getDistanceBetweenSelectAndDropdownMenu()
|
713
|
+
}, 100)
|
714
|
+
},
|
715
|
+
selectTopPosition() {
|
716
|
+
this.dropdownPosition.top =
|
717
|
+
this.selectTopPosition +
|
718
|
+
this.$refs.select.$el.clientHeight +
|
719
|
+
this.selectAndDropdownDistance
|
720
|
+
},
|
693
721
|
},
|
694
722
|
mounted() {
|
695
723
|
this.observeDropdownHeight()
|
696
724
|
this.observeSelectWidth()
|
697
725
|
window.addEventListener('resize', this.handleSetDropdownOffet)
|
726
|
+
document.body.addEventListener('scroll', this.calculateSelectTopPosition)
|
698
727
|
},
|
699
728
|
beforeMount() {
|
700
729
|
this.selectedValue = this.value
|
@@ -703,6 +732,10 @@
|
|
703
732
|
window.removeEventListener('resize', this.handleSetDropdownOffet)
|
704
733
|
if (this.dropdownResizeObserver) this.dropdownResizeObserver.disconnect()
|
705
734
|
if (this.selectResizeObserver) this.selectResizeObserver.disconnect()
|
735
|
+
document.body.removeEventListener(
|
736
|
+
'scroll',
|
737
|
+
this.calculateSelectTopPosition
|
738
|
+
)
|
706
739
|
},
|
707
740
|
unmounted() {
|
708
741
|
document.removeEventListener('click', this.clickOutside)
|
@@ -808,11 +841,11 @@
|
|
808
841
|
return
|
809
842
|
}
|
810
843
|
await this.$nextTick()
|
811
|
-
|
844
|
+
this.isDisplayedAtBottom = await this.generateDropdownPosition()
|
812
845
|
// If the dropdown menu is going to be displayed at the bottom,
|
813
846
|
// we need reverify its position after a dom update (nextTick)
|
814
847
|
await this.$nextTick()
|
815
|
-
if (isDisplayedAtBottom) this.generateDropdownPosition()
|
848
|
+
if (this.isDisplayedAtBottom) this.generateDropdownPosition()
|
816
849
|
},
|
817
850
|
async generateDropdownPosition() {
|
818
851
|
const isDropdownNotCompletelyVisible =
|
@@ -905,6 +938,25 @@
|
|
905
938
|
}
|
906
939
|
}
|
907
940
|
},
|
941
|
+
getDistanceBetweenSelectAndDropdownMenu() {
|
942
|
+
const wholeSelectTopPosition =
|
943
|
+
this.selectTopPosition + this.$refs.select.$el.clientHeight
|
944
|
+
this.selectAndDropdownDistance =
|
945
|
+
this.dropdownPosition.top - wholeSelectTopPosition
|
946
|
+
},
|
947
|
+
calculateSelectTopPosition() {
|
948
|
+
const selectRef = this.$refs.select
|
949
|
+
if (selectRef) {
|
950
|
+
const currentTopPosition =
|
951
|
+
selectRef.$el.getBoundingClientRect().top + window.scrollY
|
952
|
+
if (this.selectTopPosition !== currentTopPosition) {
|
953
|
+
this.selectTopPosition = currentTopPosition
|
954
|
+
}
|
955
|
+
}
|
956
|
+
this.animationFrameId = requestAnimationFrame(
|
957
|
+
this.calculateSelectTopPosition
|
958
|
+
)
|
959
|
+
},
|
908
960
|
},
|
909
961
|
}
|
910
962
|
</script>
|