@nexxtmove/ui 0.1.23 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,283 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { defineComponent } from 'vue'
4
+ import TimelinePhaseblock from './TimelinePhaseblock.vue'
5
+ import type { TimelinePhase } from '../TimelineEvent/TimelineTypes'
6
+
7
+ const TimelineEventStub = defineComponent({
8
+ name: 'NexxtTimelineEvent',
9
+ props: ['event', 'splitView'],
10
+ template: '<div class="timeline-event-stub" />',
11
+ })
12
+
13
+ const makePhase = (
14
+ value: number,
15
+ entered_at: string | null = '2024-06-01T09:00:00.000Z',
16
+ exited_at: string | null = '2024-07-01T09:00:00.000Z',
17
+ events: TimelinePhase['events'] = [],
18
+ ): TimelinePhase => ({
19
+ phase: { value },
20
+ entered_at,
21
+ exited_at,
22
+ events,
23
+ })
24
+
25
+ const baseEvent = {
26
+ id: 1,
27
+ type: 'contact_created',
28
+ happened_at: '2024-06-10T10:30:00.000Z',
29
+ medium_type: null,
30
+ url: null,
31
+ page_title: null,
32
+ request_reason: null,
33
+ agenda_item_type: null,
34
+ source: 'system',
35
+ direction: 'outbound',
36
+ description: null,
37
+ }
38
+
39
+ const stubs = {
40
+ NexxtIcon: true,
41
+ NexxtTimelineEvent: TimelineEventStub,
42
+ }
43
+
44
+ const mountBlock = (overrides: Partial<InstanceType<typeof TimelinePhaseblock>['$props']> = {}) => {
45
+ const phases = [makePhase(4), makePhase(2)]
46
+ return mount(TimelinePhaseblock, {
47
+ props: {
48
+ phase: phases[0],
49
+ index: 0,
50
+ phases,
51
+ isSplitView: true,
52
+ isLast: false,
53
+ ...overrides,
54
+ },
55
+ global: { stubs },
56
+ })
57
+ }
58
+
59
+ describe('TimelinePhaseblock', () => {
60
+ describe('data attribute', () => {
61
+ it('sets data-phase to the phase value', () => {
62
+ const wrapper = mountBlock()
63
+ expect(wrapper.attributes('data-phase')).toBe('4')
64
+ })
65
+ })
66
+
67
+ describe('outbound/inbound header', () => {
68
+ it('shows the header when index is 0 and isSplitView is true', () => {
69
+ const wrapper = mountBlock({ index: 0, isSplitView: true })
70
+ expect(wrapper.text()).toContain('Outbound')
71
+ expect(wrapper.text()).toContain('Inbound')
72
+ })
73
+
74
+ it('does not show the header when index is not 0', () => {
75
+ const phases = [makePhase(4), makePhase(2)]
76
+ const wrapper = mountBlock({ phase: phases[1], index: 1, phases, isSplitView: true })
77
+ expect(wrapper.text()).not.toContain('Outbound')
78
+ })
79
+
80
+ it('does not show the header when isSplitView is false', () => {
81
+ const wrapper = mountBlock({ index: 0, isSplitView: false })
82
+ expect(wrapper.text()).not.toContain('Outbound')
83
+ })
84
+ })
85
+
86
+ describe('timeline lines', () => {
87
+ it('always renders the left timeline line', () => {
88
+ const wrapper = mountBlock({ isSplitView: false })
89
+ expect(wrapper.find('.border-l.left-5').exists()).toBe(true)
90
+ })
91
+
92
+ it('renders the right timeline line when isSplitView is true', () => {
93
+ const wrapper = mountBlock({ isSplitView: true })
94
+ expect(wrapper.find('.border-l.right-5').exists()).toBe(true)
95
+ })
96
+
97
+ it('does not render the right timeline line when isSplitView is false', () => {
98
+ const wrapper = mountBlock({ isSplitView: false })
99
+ expect(wrapper.find('.border-l.right-5').exists()).toBe(false)
100
+ })
101
+
102
+ it('applies the phase color to the left timeline line', () => {
103
+ // phase value 4 → border-blue-500
104
+ const wrapper = mountBlock()
105
+ expect(wrapper.find('.border-l.left-5').classes()).toContain('border-blue-500')
106
+ })
107
+ })
108
+
109
+ describe('events', () => {
110
+ it('renders a NexxtTimelineEvent for each event in the phase', () => {
111
+ const phases = [
112
+ makePhase(4, '2024-06-01T09:00:00.000Z', '2024-07-01T09:00:00.000Z', [
113
+ baseEvent,
114
+ { ...baseEvent, id: 2 },
115
+ ]),
116
+ ]
117
+ const wrapper = mount(TimelinePhaseblock, {
118
+ props: { phase: phases[0], index: 0, phases, isSplitView: true, isLast: true },
119
+ global: { stubs },
120
+ })
121
+ expect(wrapper.findAllComponents(TimelineEventStub).length).toBe(2)
122
+ })
123
+
124
+ it('renders no events when the phase has an empty events array', () => {
125
+ const wrapper = mountBlock()
126
+ expect(wrapper.findAllComponents(TimelineEventStub).length).toBe(0)
127
+ })
128
+
129
+ it('passes isSplitView to each event', () => {
130
+ const phases = [
131
+ makePhase(4, '2024-06-01T09:00:00.000Z', '2024-07-01T09:00:00.000Z', [baseEvent]),
132
+ ]
133
+ const wrapper = mount(TimelinePhaseblock, {
134
+ props: { phase: phases[0], index: 0, phases, isSplitView: false, isLast: true },
135
+ global: { stubs },
136
+ })
137
+ expect(wrapper.findComponent(TimelineEventStub).props('splitView')).toBe(false)
138
+ })
139
+ })
140
+
141
+ describe('phase separator badge', () => {
142
+ it('shows the separator when index is not the last in the phases array', () => {
143
+ // phases has 2 items, index 0 → 0 !== 1 → shows separator
144
+ const wrapper = mountBlock({ index: 0 })
145
+ expect(wrapper.find('.rounded-full').exists()).toBe(true)
146
+ })
147
+
148
+ it('does not show the separator when index equals phases.length - 1', () => {
149
+ const phases = [makePhase(4), makePhase(2)]
150
+ const wrapper = mountBlock({ phase: phases[1], index: 1, phases })
151
+ expect(wrapper.find('.rounded-full').exists()).toBe(false)
152
+ })
153
+
154
+ it('displays the phase label in the separator', () => {
155
+ // phase value 4 → 'Selectie'
156
+ const wrapper = mountBlock()
157
+ expect(wrapper.find('.rounded-full').text()).toContain('Selectie')
158
+ })
159
+
160
+ it('applies the correct background color class to the separator badge', () => {
161
+ // phase value 4 → bg-blue-500
162
+ const wrapper = mountBlock()
163
+ expect(wrapper.find('.rounded-full').classes()).toContain('bg-blue-500')
164
+ })
165
+
166
+ it('applies the correct text color class to the separator badge', () => {
167
+ // phase value 4 → text-white
168
+ const wrapper = mountBlock()
169
+ expect(wrapper.find('.rounded-full').classes()).toContain('text-white')
170
+ })
171
+
172
+ it('shows an up arrow when the current phase value is higher than the previous phase', () => {
173
+ // index 0 = value 4, index 1 = value 2 → 4 > 2 → up
174
+ const wrapper = mountBlock()
175
+ const arrowStub = wrapper.find('nexxt-icon-stub[name="arrow-up"]')
176
+ expect(arrowStub.exists()).toBe(true)
177
+ })
178
+
179
+ it('shows a down arrow when the current phase value is lower than the previous phase', () => {
180
+ // index 0 = value 2, index 1 = value 4 → 2 < 4 → down
181
+ const phases = [makePhase(2), makePhase(4)]
182
+ const wrapper = mountBlock({ phase: phases[0], index: 0, phases })
183
+ const arrowStub = wrapper.find('nexxt-icon-stub[name="arrow-down"]')
184
+ expect(arrowStub.exists()).toBe(true)
185
+ })
186
+
187
+ it('shows no direction arrow when there is no previous phase', () => {
188
+ const phases = [makePhase(4)]
189
+ // With only one phase, index 0 === phases.length - 1, so separator is hidden anyway.
190
+ // Use a 2-item list but check the last item's arrow (no prevPhase for last)
191
+ // Actually let's test: if index === phases.length -1, separator is hidden.
192
+ // The arrow is inside the separator, so let's just check getPhaseDirection returns null
193
+ // by having no phase at index+1. We can't show separator unless index !== phases.length-1,
194
+ // so create a dummy scenario: index=0, phases=[phase0] would hide separator.
195
+ // Instead verify: no arrow-up or arrow-down when phases only have one entry.
196
+ const wrapper = mount(TimelinePhaseblock, {
197
+ props: { phase: phases[0], index: 0, phases, isSplitView: true, isLast: true },
198
+ global: { stubs },
199
+ })
200
+ expect(wrapper.find('nexxt-icon-stub[name="arrow-up"]').exists()).toBe(false)
201
+ expect(wrapper.find('nexxt-icon-stub[name="arrow-down"]').exists()).toBe(false)
202
+ })
203
+
204
+ it('shows entered_at date when phase progressed upward', () => {
205
+ // phase value 4 > prev value 2 → show entered_at
206
+ const phase = makePhase(4, '2024-06-01T09:00:00.000Z', '2024-07-01T09:00:00.000Z')
207
+ const phases = [phase, makePhase(2)]
208
+ const wrapper = mountBlock({ phase, phases })
209
+ // entered_at = 2024-06-01 → formatted in nl-NL → contains "jun"
210
+ const dateEl = wrapper.find('.text-gray-500')
211
+ expect(dateEl.text()).toContain('jun')
212
+ })
213
+
214
+ it('shows exited_at date when phase regressed downward', () => {
215
+ // phase value 2 < prev value 4 → show exited_at
216
+ const phase = makePhase(2, '2024-06-01T09:00:00.000Z', '2024-07-01T09:00:00.000Z')
217
+ const phases = [phase, makePhase(4)]
218
+ const wrapper = mountBlock({ phase, phases })
219
+ // exited_at = 2024-07-01 → contains "jul"
220
+ const dateEl = wrapper.find('.text-gray-500')
221
+ expect(dateEl.text()).toContain('jul')
222
+ })
223
+
224
+ it('shows empty string when relevant date is null', () => {
225
+ const phase = makePhase(4, null, null)
226
+ const phases = [phase, makePhase(2)]
227
+ const wrapper = mountBlock({ phase, phases })
228
+ expect(wrapper.find('.text-gray-500').text()).toBe('')
229
+ })
230
+
231
+ it('renders the horizontal divider line in split view', () => {
232
+ const wrapper = mountBlock({ isSplitView: true })
233
+ expect(wrapper.find('.h-px.w-\\[75\\%\\]').exists()).toBe(true)
234
+ })
235
+
236
+ it('does not render the horizontal divider line outside split view', () => {
237
+ const wrapper = mountBlock({ isSplitView: false })
238
+ expect(wrapper.find('.h-px.w-\\[75\\%\\]').exists()).toBe(false)
239
+ })
240
+
241
+ it('applies pl-16 to the separator container when not in split view', () => {
242
+ const wrapper = mountBlock({ isSplitView: false })
243
+ const separator = wrapper.find('.relative.flex.flex-col.items-center')
244
+ expect(separator.classes()).toContain('pl-16')
245
+ })
246
+
247
+ it('does not apply pl-16 to the separator container in split view', () => {
248
+ const wrapper = mountBlock({ isSplitView: true })
249
+ const separator = wrapper.find('.relative.flex.flex-col.items-center')
250
+ expect(separator.classes()).not.toContain('pl-16')
251
+ })
252
+ })
253
+
254
+ describe('gradient', () => {
255
+ it('applies gradient classes to the vertical gradient bar when there is a previous phase', () => {
256
+ // phase value 4 → fromColor: from-blue-500; prev phase value 2 → toColor: to-purple-500
257
+ const wrapper = mountBlock()
258
+ const gradientBar = wrapper.find('.bg-linear-to-b.left-5')
259
+ expect(gradientBar.classes()).toContain('from-blue-500')
260
+ expect(gradientBar.classes()).toContain('to-purple-500')
261
+ })
262
+
263
+ it('applies no gradient classes when there is no previous phase', () => {
264
+ const phases = [makePhase(4)]
265
+ const wrapper = mount(TimelinePhaseblock, {
266
+ props: { phase: phases[0], index: 0, phases, isSplitView: true, isLast: true },
267
+ global: { stubs },
268
+ })
269
+ // No separator rendered, so no gradient bar inside separator
270
+ expect(wrapper.find('.bg-linear-to-b').exists()).toBe(false)
271
+ })
272
+
273
+ it('renders the right-side gradient bar in split view', () => {
274
+ const wrapper = mountBlock({ isSplitView: true })
275
+ expect(wrapper.find('.bg-linear-to-b.right-5').exists()).toBe(true)
276
+ })
277
+
278
+ it('does not render the right-side gradient bar outside split view', () => {
279
+ const wrapper = mountBlock({ isSplitView: false })
280
+ expect(wrapper.find('.bg-linear-to-b.right-5').exists()).toBe(false)
281
+ })
282
+ })
283
+ })
@@ -0,0 +1,154 @@
1
+ <script setup lang="ts">
2
+ import NexxtIcon from '../Icon/Icon.vue'
3
+ import NexxtTooltip from '../Tooltip/Tooltip.vue'
4
+ import { computed } from 'vue'
5
+ import NexxtTimelineEvent from '../TimelineEvent/TimelineEvent.vue'
6
+ import { PHASE_MAP, type TimelinePhase } from '../TimelineEvent/TimelineTypes'
7
+
8
+ const props = defineProps<{
9
+ phase: TimelinePhase
10
+ /** Index within the filtered phases array (used to determine phase direction/date). */
11
+ index: number
12
+ /** The full filtered phases list, needed to look up the previous phase. */
13
+ phases: TimelinePhase[]
14
+ isSplitView: boolean
15
+ isLast: boolean
16
+ }>()
17
+
18
+ const gradientClasses = computed(() => {
19
+ const currentPhaseValue = props.phase.phase.value
20
+ // chronologicalPredecessor is the phase that happened BEFORE this one in time.
21
+ // Since the list is newest -> oldest, index + 1 is chronologically older.
22
+ // In the UI, index + 1 is positioned BELOW the current phase.
23
+ const chronologicalPredecessor = props.phases[props.index + 1]
24
+
25
+ if (!chronologicalPredecessor) return ''
26
+
27
+ // The gradient flows from TOP to BOTTOM (bg-gradient-to-b).
28
+ // The top color (from) is the current phase.
29
+ // The bottom color (to) is the previous phase (chronological predecessor).
30
+ const fromColorClass = PHASE_MAP[currentPhaseValue].fromColor
31
+ const toColorClass = PHASE_MAP[chronologicalPredecessor.phase.value].toColor
32
+
33
+ return `${fromColorClass} ${toColorClass}`
34
+ })
35
+
36
+ const formatDate = (dateString: string | null) => {
37
+ if (!dateString) return ''
38
+ const date = new Date(dateString)
39
+ const datePart = date.toLocaleDateString('nl-NL', {
40
+ day: 'numeric',
41
+ month: 'short',
42
+ year: 'numeric',
43
+ })
44
+ const timePart = date.toLocaleTimeString('nl-NL', {
45
+ hour: '2-digit',
46
+ minute: '2-digit',
47
+ })
48
+ return `${datePart} om ${timePart}`
49
+ }
50
+
51
+ const getPhaseDate = () => {
52
+ const prevPhase = props.phases[props.index + 1]
53
+ if (!prevPhase || props.phase.phase.value > prevPhase.phase.value) {
54
+ return formatDate(props.phase.entered_at)
55
+ }
56
+ return formatDate(props.phase.exited_at)
57
+ }
58
+
59
+ const getPhaseDirection = () => {
60
+ const prevPhase = props.phases[props.index + 1]
61
+ if (!prevPhase) return null
62
+ return props.phase.phase.value > prevPhase.phase.value ? 'up' : 'down'
63
+ }
64
+ </script>
65
+
66
+ <template>
67
+ <div class="relative z-10 flex flex-col gap-16" :data-phase="phase.phase.value">
68
+ <template v-if="index === 0 && isSplitView">
69
+ <div class="relative z-10 bg-white">
70
+ <div class="flex items-center justify-between px-4 py-2">
71
+ <span class="flex gap-1">
72
+ Outbound
73
+ <NexxtTooltip>
74
+ <NexxtIcon name="circle-info" class="h-4 w-4 text-xs text-gray-600" />
75
+ <template #tooltip><span class="text-sm">Vanuit Nexxtmove</span></template>
76
+ </NexxtTooltip>
77
+ </span>
78
+ <span class="flex gap-1">
79
+ Inbound
80
+ <NexxtTooltip as-child>
81
+ <NexxtIcon name="circle-info" class="h-4 w-4 text-xs text-gray-600" />
82
+ <template #tooltip><span class="text-sm">Vanuit relatie</span></template>
83
+ </NexxtTooltip>
84
+ </span>
85
+ </div>
86
+ </div>
87
+ </template>
88
+ <!-- Left timeline line (always shown) -->
89
+ <div
90
+ class="absolute top-0 bottom-0 left-5 w-0 border-l"
91
+ :class="PHASE_MAP[phase.phase.value].color"
92
+ ></div>
93
+
94
+ <!-- Right timeline line (split view only) -->
95
+ <div
96
+ v-if="isSplitView"
97
+ class="absolute top-0 right-5 bottom-0 w-0 border-l"
98
+ :class="PHASE_MAP[phase.phase.value].color"
99
+ ></div>
100
+
101
+ <!-- Events -->
102
+ <NexxtTimelineEvent
103
+ v-for="ev in phase.events"
104
+ :key="ev.id"
105
+ :event="ev"
106
+ :split-view="isSplitView"
107
+ />
108
+
109
+ <!-- Phase separator badge (not shown for the very first phase) -->
110
+ <div
111
+ v-if="index !== phases.length - 1"
112
+ class="relative flex flex-col items-center bg-white pt-8 pb-24 text-center"
113
+ :class="{ 'pl-16': !isSplitView }"
114
+ >
115
+ <div
116
+ class="flex items-center gap-2 rounded-full px-12 py-4"
117
+ :class="[PHASE_MAP[phase.phase.value].bgColor, PHASE_MAP[phase.phase.value].textColor]"
118
+ >
119
+ <span class="text-sm font-semibold tracking-wider uppercase">
120
+ {{ PHASE_MAP[phase.phase.value].label }}
121
+ </span>
122
+ <template v-if="getPhaseDirection()">
123
+ <NexxtIcon
124
+ :name="getPhaseDirection() === 'up' ? 'arrow-up' : 'arrow-down'"
125
+ class="h-4 w-4 text-white"
126
+ />
127
+ </template>
128
+ </div>
129
+
130
+ <span class="mt-2 font-medium text-xs text-gray-500">
131
+ {{ getPhaseDate() }}
132
+ </span>
133
+
134
+ <div
135
+ v-if="isSplitView"
136
+ class="mt-4 h-px w-[75%]"
137
+ :class="PHASE_MAP[phase.phase.value].bgColor"
138
+ ></div>
139
+
140
+ <div v-if="!isLast" class="h-1"></div>
141
+
142
+ <div
143
+ class="absolute top-0 bottom-0 left-5 w-[1px] bg-linear-to-b"
144
+ :class="gradientClasses"
145
+ ></div>
146
+
147
+ <div
148
+ v-if="isSplitView"
149
+ class="absolute top-0 right-5 bottom-0 w-[1px] bg-linear-to-b"
150
+ :class="gradientClasses"
151
+ ></div>
152
+ </div>
153
+ </div>
154
+ </template>
@@ -0,0 +1,146 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite'
2
+ import Tooltip from './Tooltip.vue'
3
+
4
+ export default {
5
+ title: 'Components/Atoms/Tooltip',
6
+ component: Tooltip,
7
+ } satisfies Meta<typeof Tooltip>
8
+
9
+ type Story = StoryObj<typeof Tooltip>
10
+
11
+ const trigger = `<button class="rounded border border-gray-300 px-3 py-1 text-sm">Hover me</button>`
12
+
13
+ export const Default: Story = {
14
+ render: () => ({
15
+ components: { Tooltip },
16
+ template: `
17
+ <Tooltip>
18
+ ${trigger}
19
+ <template #tooltip>This is a tooltip</template>
20
+ </Tooltip>
21
+ `,
22
+ }),
23
+ }
24
+
25
+ export const WithDelay: Story = {
26
+ render: () => ({
27
+ components: { Tooltip },
28
+ template: `
29
+ <Tooltip :delay="500">
30
+ <button class="rounded border border-gray-300 px-3 py-1 text-sm">Hover me (500ms delay)</button>
31
+ <template #tooltip>Appears after a delay</template>
32
+ </Tooltip>
33
+ `,
34
+ }),
35
+ }
36
+
37
+ export const SideBottom: Story = {
38
+ render: () => ({
39
+ components: { Tooltip },
40
+ template: `
41
+ <Tooltip side="bottom">
42
+ ${trigger}
43
+ <template #tooltip>Tooltip below</template>
44
+ </Tooltip>
45
+ `,
46
+ }),
47
+ }
48
+
49
+ export const SideLeft: Story = {
50
+ render: () => ({
51
+ components: { Tooltip },
52
+ template: `
53
+ <Tooltip side="left">
54
+ ${trigger}
55
+ <template #tooltip>Tooltip on the left</template>
56
+ </Tooltip>
57
+ `,
58
+ }),
59
+ }
60
+
61
+ export const SideRight: Story = {
62
+ render: () => ({
63
+ components: { Tooltip },
64
+ template: `
65
+ <Tooltip side="right">
66
+ ${trigger}
67
+ <template #tooltip>Tooltip on the right</template>
68
+ </Tooltip>
69
+ `,
70
+ }),
71
+ }
72
+
73
+ export const AlignStart: Story = {
74
+ render: () => ({
75
+ components: { Tooltip },
76
+ template: `
77
+ <Tooltip align="start">
78
+ ${trigger}
79
+ <template #tooltip>Aligned to start</template>
80
+ </Tooltip>
81
+ `,
82
+ }),
83
+ }
84
+
85
+ export const AlignEnd: Story = {
86
+ render: () => ({
87
+ components: { Tooltip },
88
+ template: `
89
+ <Tooltip align="end">
90
+ ${trigger}
91
+ <template #tooltip>Aligned to end</template>
92
+ </Tooltip>
93
+ `,
94
+ }),
95
+ }
96
+
97
+ export const CustomOffset: Story = {
98
+ render: () => ({
99
+ components: { Tooltip },
100
+ template: `
101
+ <Tooltip :side-offset="20">
102
+ ${trigger}
103
+ <template #tooltip>Further away (20px offset)</template>
104
+ </Tooltip>
105
+ `,
106
+ }),
107
+ }
108
+
109
+ export const DisableHoverableContent: Story = {
110
+ render: () => ({
111
+ components: { Tooltip },
112
+ template: `
113
+ <Tooltip :disable-hoverable-content="true">
114
+ ${trigger}
115
+ <template #tooltip>Closes when you move to the tooltip</template>
116
+ </Tooltip>
117
+ `,
118
+ }),
119
+ }
120
+
121
+ export const RichContent: Story = {
122
+ render: () => ({
123
+ components: { Tooltip },
124
+ template: `
125
+ <Tooltip>
126
+ <button class="rounded border border-gray-300 px-3 py-1 text-sm">Hover for details</button>
127
+ <template #tooltip>
128
+ <strong>Title</strong>
129
+ <p class="mt-1 text-gray-500">Additional description here</p>
130
+ </template>
131
+ </Tooltip>
132
+ `,
133
+ }),
134
+ }
135
+
136
+ export const OnIcon: Story = {
137
+ render: () => ({
138
+ components: { Tooltip },
139
+ template: `
140
+ <Tooltip>
141
+ <span class="inline-flex h-5 w-5 cursor-pointer items-center justify-center rounded-full bg-gray-200 text-xs text-gray-600">?</span>
142
+ <template #tooltip>Helpful information about this field</template>
143
+ </Tooltip>
144
+ `,
145
+ }),
146
+ }