@nexxtmove/ui 0.1.24 → 0.1.26

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,158 @@
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
+
6
+ defineOptions({
7
+ name: 'NexxtTimelinePhaseblock',
8
+ })
9
+ import NexxtTimelineEvent from '../TimelineEvent/TimelineEvent.vue'
10
+ import { PHASE_MAP, type TimelinePhase } from '../TimelineEvent/TimelineTypes'
11
+
12
+ const props = defineProps<{
13
+ phase: TimelinePhase
14
+ /** Index within the filtered phases array (used to determine phase direction/date). */
15
+ index: number
16
+ /** The full filtered phases list, needed to look up the previous phase. */
17
+ phases: TimelinePhase[]
18
+ isSplitView: boolean
19
+ isLast: boolean
20
+ }>()
21
+
22
+ const gradientClasses = computed(() => {
23
+ const currentPhaseValue = props.phase.phase.value
24
+ // chronologicalPredecessor is the phase that happened BEFORE this one in time.
25
+ // Since the list is newest -> oldest, index + 1 is chronologically older.
26
+ // In the UI, index + 1 is positioned BELOW the current phase.
27
+ const chronologicalPredecessor = props.phases[props.index + 1]
28
+
29
+ if (!chronologicalPredecessor) return ''
30
+
31
+ // The gradient flows from TOP to BOTTOM (bg-gradient-to-b).
32
+ // The top color (from) is the current phase.
33
+ // The bottom color (to) is the previous phase (chronological predecessor).
34
+ const fromColorClass = PHASE_MAP[currentPhaseValue].fromColor
35
+ const toColorClass = PHASE_MAP[chronologicalPredecessor.phase.value].toColor
36
+
37
+ return `${fromColorClass} ${toColorClass}`
38
+ })
39
+
40
+ const formatDate = (dateString: string | null) => {
41
+ if (!dateString) return ''
42
+ const date = new Date(dateString)
43
+ const datePart = date.toLocaleDateString('nl-NL', {
44
+ day: 'numeric',
45
+ month: 'short',
46
+ year: 'numeric',
47
+ })
48
+ const timePart = date.toLocaleTimeString('nl-NL', {
49
+ hour: '2-digit',
50
+ minute: '2-digit',
51
+ })
52
+ return `${datePart} om ${timePart}`
53
+ }
54
+
55
+ const getPhaseDate = () => {
56
+ const prevPhase = props.phases[props.index + 1]
57
+ if (!prevPhase || props.phase.phase.value > prevPhase.phase.value) {
58
+ return formatDate(props.phase.entered_at)
59
+ }
60
+ return formatDate(props.phase.exited_at)
61
+ }
62
+
63
+ const getPhaseDirection = () => {
64
+ const prevPhase = props.phases[props.index + 1]
65
+ if (!prevPhase) return null
66
+ return props.phase.phase.value > prevPhase.phase.value ? 'up' : 'down'
67
+ }
68
+ </script>
69
+
70
+ <template>
71
+ <div class="relative z-10 flex flex-col gap-16" :data-phase="phase.phase.value">
72
+ <template v-if="index === 0 && isSplitView">
73
+ <div class="relative z-10 bg-white">
74
+ <div class="flex items-center justify-between px-4 py-2">
75
+ <span class="flex gap-1">
76
+ Outbound
77
+ <NexxtTooltip>
78
+ <NexxtIcon name="circle-info" class="h-4 w-4 text-xs text-gray-600" />
79
+ <template #tooltip><span class="text-sm">Vanuit Nexxtmove</span></template>
80
+ </NexxtTooltip>
81
+ </span>
82
+ <span class="flex gap-1">
83
+ Inbound
84
+ <NexxtTooltip as-child>
85
+ <NexxtIcon name="circle-info" class="h-4 w-4 text-xs text-gray-600" />
86
+ <template #tooltip><span class="text-sm">Vanuit relatie</span></template>
87
+ </NexxtTooltip>
88
+ </span>
89
+ </div>
90
+ </div>
91
+ </template>
92
+ <!-- Left timeline line (always shown) -->
93
+ <div
94
+ class="absolute top-0 bottom-0 left-5 w-0 border-l"
95
+ :class="PHASE_MAP[phase.phase.value].color"
96
+ ></div>
97
+
98
+ <!-- Right timeline line (split view only) -->
99
+ <div
100
+ v-if="isSplitView"
101
+ class="absolute top-0 right-5 bottom-0 w-0 border-l"
102
+ :class="PHASE_MAP[phase.phase.value].color"
103
+ ></div>
104
+
105
+ <!-- Events -->
106
+ <NexxtTimelineEvent
107
+ v-for="ev in phase.events"
108
+ :key="ev.id"
109
+ :event="ev"
110
+ :split-view="isSplitView"
111
+ />
112
+
113
+ <!-- Phase separator badge (not shown for the very first phase) -->
114
+ <div
115
+ v-if="index !== phases.length - 1"
116
+ class="relative flex flex-col items-center bg-white pt-8 pb-24 text-center"
117
+ :class="{ 'pl-16': !isSplitView }"
118
+ >
119
+ <div
120
+ class="flex items-center gap-2 rounded-full px-12 py-4"
121
+ :class="[PHASE_MAP[phase.phase.value].bgColor, PHASE_MAP[phase.phase.value].textColor]"
122
+ >
123
+ <span class="text-sm font-semibold tracking-wider uppercase">
124
+ {{ PHASE_MAP[phase.phase.value].label }}
125
+ </span>
126
+ <template v-if="getPhaseDirection()">
127
+ <NexxtIcon
128
+ :name="getPhaseDirection() === 'up' ? 'arrow-up' : 'arrow-down'"
129
+ class="h-4 w-4 text-white"
130
+ />
131
+ </template>
132
+ </div>
133
+
134
+ <span class="mt-2 font-medium text-xs text-gray-500">
135
+ {{ getPhaseDate() }}
136
+ </span>
137
+
138
+ <div
139
+ v-if="isSplitView"
140
+ class="mt-4 h-px w-[75%]"
141
+ :class="PHASE_MAP[phase.phase.value].bgColor"
142
+ ></div>
143
+
144
+ <div v-if="!isLast" class="h-1"></div>
145
+
146
+ <div
147
+ class="absolute top-0 bottom-0 left-5 w-[1px] bg-linear-to-b"
148
+ :class="gradientClasses"
149
+ ></div>
150
+
151
+ <div
152
+ v-if="isSplitView"
153
+ class="absolute top-0 right-5 bottom-0 w-[1px] bg-linear-to-b"
154
+ :class="gradientClasses"
155
+ ></div>
156
+ </div>
157
+ </div>
158
+ </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
+ }