@m3ui-vue/m3ui-vue 1.3.7 → 1.4.0
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.
- package/dist/API.md +1097 -26
- package/dist/{MButton-D5eJiDza.js → MButton-DQMTIlaV.js} +2 -2
- package/dist/{MButton-D5eJiDza.js.map → MButton-DQMTIlaV.js.map} +1 -1
- package/dist/{MDialog-WqB0jewp.js → MDialog-cdgapGfZ.js} +2 -2
- package/dist/{MDialog-WqB0jewp.js.map → MDialog-cdgapGfZ.js.map} +1 -1
- package/dist/{MListItem-Cf-C2Ru-.js → MListItem-ZkSGIIrb.js} +2 -2
- package/dist/{MListItem-Cf-C2Ru-.js.map → MListItem-ZkSGIIrb.js.map} +1 -1
- package/dist/{MLoadingIndicator-D4GzEZoH.js → MLoadingIndicator-U6_oGx8z.js} +2 -2
- package/dist/{MLoadingIndicator-D4GzEZoH.js.map → MLoadingIndicator-U6_oGx8z.js.map} +1 -1
- package/dist/{MSeekBar-B19xoWE3.js → MSeekBar-DTZVizZg.js} +2 -2
- package/dist/{MSeekBar-B19xoWE3.js.map → MSeekBar-DTZVizZg.js.map} +1 -1
- package/dist/{MSlider-9RoiuebS.js → MSlider-CqJkEYRZ.js} +2 -2
- package/dist/{MSlider-9RoiuebS.js.map → MSlider-CqJkEYRZ.js.map} +1 -1
- package/dist/{MSpinner-BNF8MN-L.js → MSpinner-Btgc-0nb.js} +2 -2
- package/dist/{MSpinner-BNF8MN-L.js.map → MSpinner-Btgc-0nb.js.map} +1 -1
- package/dist/{MTextField-CuG0T3qh.js → MTextField-B6M0gJEO.js} +2 -2
- package/dist/{MTextField-CuG0T3qh.js.map → MTextField-B6M0gJEO.js.map} +1 -1
- package/dist/{MTooltip-Bv7yxngk.js → MTooltip-Dspji4XG.js} +4 -4
- package/dist/{MTooltip-Bv7yxngk.js.map → MTooltip-Dspji4XG.js.map} +1 -1
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAudioPlayer.vue.d.ts +2 -2
- package/dist/components/MAvailabilityCalendar.vue.d.ts +83 -0
- package/dist/components/MBadge.vue.d.ts +1 -1
- package/dist/components/MBeforeAfter.vue.d.ts +61 -0
- package/dist/components/MBodyMap.vue.d.ts +70 -0
- package/dist/components/MCandlestickChart.vue.d.ts +82 -0
- package/dist/components/MCertificate.vue.d.ts +76 -0
- package/dist/components/MCreditCardInput.vue.d.ts +75 -0
- package/dist/components/MFlow.vue.d.ts +13 -0
- package/dist/components/MMortgageCalculator.vue.d.ts +83 -0
- package/dist/components/MOdontogram.vue.d.ts +86 -0
- package/dist/components/MOrderBook.vue.d.ts +89 -0
- package/dist/components/MOrderTicket.vue.d.ts +91 -0
- package/dist/components/MPosKeypad.vue.d.ts +84 -0
- package/dist/components/MProductConfigurator.vue.d.ts +136 -0
- package/dist/components/MQuiz.vue.d.ts +102 -0
- package/dist/components/MReceipt.vue.d.ts +93 -0
- package/dist/components/MSeatMap.vue.d.ts +131 -0
- package/dist/components/MSeekBar.vue.d.ts +1 -1
- package/dist/components/MSlider.vue.d.ts +2 -2
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MTicket.vue.d.ts +83 -0
- package/dist/components/MTour.vue.d.ts +52 -2
- package/dist/components/MVideoPlayer.vue.d.ts +1 -1
- package/dist/components/MVitalsChart.vue.d.ts +73 -0
- package/dist/composables/_printElement.d.ts +9 -0
- package/dist/composables/cardBrand.d.ts +25 -0
- package/dist/composables/flowPaths.d.ts +11 -3
- package/dist/composables/mortgage.d.ts +37 -0
- package/dist/composables/useFlow.d.ts +4 -0
- package/dist/composables/useLocale.d.ts +131 -0
- package/dist/draw.js +2 -2
- package/dist/flow.d.ts +1 -1
- package/dist/flow.js +526 -434
- package/dist/flow.js.map +1 -1
- package/dist/{flowPaths-DzW-aiET.js → flowPaths-CcWOKY4Z.js} +5 -5
- package/dist/flowPaths-CcWOKY4Z.js.map +1 -0
- package/dist/gantt.js +2 -2
- package/dist/index.d.ts +35 -0
- package/dist/locales/index.js +924 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +8393 -3613
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +5 -5
- package/dist/media.js +4 -4
- package/dist/pdf.js +4 -4
- package/dist/rich-text-editor.js +4 -4
- package/dist/styles.css +1 -1
- package/dist/{useLocale-D2ucaY-l.js → useLocale-DLKJIRFi.js} +133 -2
- package/dist/useLocale-DLKJIRFi.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MAvailabilityCalendar.test.ts +85 -0
- package/src/__tests__/MBeforeAfter.test.ts +79 -0
- package/src/__tests__/MBodyMap.test.ts +60 -0
- package/src/__tests__/MCandlestickChart.test.ts +66 -0
- package/src/__tests__/MCertificate.test.ts +32 -0
- package/src/__tests__/MCreditCardInput.test.ts +122 -0
- package/src/__tests__/MFlow.test.ts +69 -0
- package/src/__tests__/MMortgageCalculator.test.ts +49 -0
- package/src/__tests__/MOdontogram.test.ts +93 -0
- package/src/__tests__/MOrderBook.test.ts +66 -0
- package/src/__tests__/MOrderTicket.test.ts +68 -0
- package/src/__tests__/MPosKeypad.test.ts +116 -0
- package/src/__tests__/MProductConfigurator.test.ts +73 -0
- package/src/__tests__/MQuiz.test.ts +104 -0
- package/src/__tests__/MReceipt.test.ts +52 -0
- package/src/__tests__/MSeatMap.test.ts +76 -0
- package/src/__tests__/MTicket.test.ts +38 -0
- package/src/__tests__/MTour.test.ts +102 -0
- package/src/__tests__/MVitalsChart.test.ts +49 -0
- package/src/__tests__/mortgage.test.ts +25 -0
- package/src/__tests__/ssr.test.ts +11 -0
- package/src/components/MAvailabilityCalendar.vue +460 -0
- package/src/components/MBeforeAfter.vue +248 -0
- package/src/components/MBodyMap.vue +266 -0
- package/src/components/MCandlestickChart.vue +479 -0
- package/src/components/MCertificate.vue +351 -0
- package/src/components/MCreditCardInput.vue +351 -0
- package/src/components/MFlow.vue +117 -17
- package/src/components/MMortgageCalculator.vue +258 -0
- package/src/components/MOdontogram.vue +462 -0
- package/src/components/MOrderBook.vue +287 -0
- package/src/components/MOrderTicket.vue +217 -0
- package/src/components/MPosKeypad.vue +406 -0
- package/src/components/MProductConfigurator.vue +412 -0
- package/src/components/MQuiz.vue +531 -0
- package/src/components/MReceipt.vue +249 -0
- package/src/components/MSeatMap.vue +431 -0
- package/src/components/MTicket.vue +209 -0
- package/src/components/MTour.vue +145 -27
- package/src/components/MVitalsChart.vue +303 -0
- package/src/composables/_printElement.ts +36 -0
- package/src/composables/cardBrand.ts +104 -0
- package/src/composables/flowPaths.ts +16 -7
- package/src/composables/mortgage.ts +70 -0
- package/src/composables/useFlow.ts +4 -0
- package/src/composables/useLocale.ts +277 -0
- package/src/flow.ts +1 -1
- package/src/index.ts +35 -0
- package/src/locales/de.ts +131 -0
- package/src/locales/es.ts +131 -0
- package/src/locales/fr.ts +131 -0
- package/src/locales/ja.ts +131 -0
- package/src/locales/ko.ts +131 -0
- package/src/locales/pt.ts +131 -0
- package/src/locales/zh.ts +131 -0
- package/dist/flowPaths-DzW-aiET.js.map +0 -1
- package/dist/useLocale-D2ucaY-l.js.map +0 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/** One end of a trip in an `MTicket`: an airport, a station, a terminal. */
|
|
3
|
+
export interface TicketStop {
|
|
4
|
+
/** Short code shown big, e.g. "EZE" or "RET" */
|
|
5
|
+
code: string
|
|
6
|
+
/** City or station name under the code */
|
|
7
|
+
name?: string
|
|
8
|
+
/** Departure / arrival time, shown under the name */
|
|
9
|
+
time?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** A label/value pair on an `MTicket`, e.g. `{ label: 'Gate', value: 'B12' }`. */
|
|
13
|
+
export interface TicketField {
|
|
14
|
+
label: string
|
|
15
|
+
value: string | number
|
|
16
|
+
/** Emphasizes the value (e.g. the seat or the gate) */
|
|
17
|
+
strong?: boolean
|
|
18
|
+
}
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<script setup lang="ts">
|
|
22
|
+
/**
|
|
23
|
+
* A ticket with a tear-off stub: a boarding pass, a bus or train ticket, a concert or cinema entry, a coupon. The
|
|
24
|
+
* stub is separated by a perforated line with two notches cut out, and usually holds the code to scan (put an
|
|
25
|
+
* `MQRCode` or `MBarcode` in the `stub` slot). Trips get a from → to route; any ticket gets a grid of fields.
|
|
26
|
+
*
|
|
27
|
+
* @slot header Replaces the title row in the colored band (e.g. an airline logo and a status chip)
|
|
28
|
+
* @slot default Content of the main part, under the route and fields
|
|
29
|
+
* @slot stub Content of the stub: a QR, a barcode, a number
|
|
30
|
+
*/
|
|
31
|
+
import { computed } from 'vue'
|
|
32
|
+
import MIcon from './MIcon.vue'
|
|
33
|
+
|
|
34
|
+
const ROLES = ['primary', 'secondary', 'tertiary', 'error', 'success']
|
|
35
|
+
|
|
36
|
+
const props = withDefaults(
|
|
37
|
+
defineProps<{
|
|
38
|
+
/** Title in the colored band, e.g. the airline, the event or the movie */
|
|
39
|
+
title?: string
|
|
40
|
+
/** A line under the title, e.g. the venue or the date */
|
|
41
|
+
subtitle?: string
|
|
42
|
+
/** Material Symbol before the title */
|
|
43
|
+
icon?: string
|
|
44
|
+
/** Band color: a role (primary, secondary, tertiary, error, success) or any CSS color */
|
|
45
|
+
color?: string
|
|
46
|
+
/** Where the trip starts */
|
|
47
|
+
from?: TicketStop
|
|
48
|
+
/** Where the trip ends */
|
|
49
|
+
to?: TicketStop
|
|
50
|
+
/** Material Symbol between from and to */
|
|
51
|
+
transport?: string
|
|
52
|
+
/** Label/value pairs in a grid */
|
|
53
|
+
fields?: TicketField[]
|
|
54
|
+
/** Stub beside the main part (an event ticket) or under it (a phone boarding pass) */
|
|
55
|
+
orientation?: 'horizontal' | 'vertical'
|
|
56
|
+
/** Width of the stub in horizontal orientation (any CSS length) */
|
|
57
|
+
stubSize?: string
|
|
58
|
+
/** Radius of the notches cut at the perforation, in px */
|
|
59
|
+
notch?: number
|
|
60
|
+
}>(),
|
|
61
|
+
{
|
|
62
|
+
color: 'primary',
|
|
63
|
+
transport: 'flight',
|
|
64
|
+
fields: () => [],
|
|
65
|
+
orientation: 'horizontal',
|
|
66
|
+
stubSize: '10rem',
|
|
67
|
+
notch: 12,
|
|
68
|
+
},
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
const band = computed(() =>
|
|
72
|
+
ROLES.includes(props.color)
|
|
73
|
+
? { background: `var(--color-${props.color})`, color: `var(--color-on-${props.color})` }
|
|
74
|
+
: { background: props.color, color: '#fff' },
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
const vertical = computed(() => props.orientation === 'vertical')
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<template>
|
|
81
|
+
<div
|
|
82
|
+
class="m3-ticket flex text-on-surface"
|
|
83
|
+
:class="vertical ? 'flex-col' : 'flex-row'"
|
|
84
|
+
:style="{ '--m3-ticket-notch': `${notch}px`, '--m3-ticket-stub': stubSize }"
|
|
85
|
+
:data-orientation="orientation"
|
|
86
|
+
>
|
|
87
|
+
<div class="m3-ticket__main flex min-w-0 flex-1 flex-col overflow-hidden bg-surface-container-lowest">
|
|
88
|
+
<div class="flex items-center gap-3 px-5 py-3" :style="band">
|
|
89
|
+
<slot name="header">
|
|
90
|
+
<MIcon v-if="icon" :name="icon" :size="24" />
|
|
91
|
+
<div class="min-w-0 flex-1">
|
|
92
|
+
<div v-if="title" class="truncate text-title-medium font-medium">{{ title }}</div>
|
|
93
|
+
<div v-if="subtitle" class="truncate text-body-medium opacity-80">{{ subtitle }}</div>
|
|
94
|
+
</div>
|
|
95
|
+
</slot>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<div class="flex flex-1 flex-col gap-4 px-5 py-4">
|
|
99
|
+
<div v-if="from || to" class="flex items-start gap-3" data-route>
|
|
100
|
+
<div v-if="from" class="min-w-0">
|
|
101
|
+
<div class="text-display-small font-medium leading-none tracking-tight">{{ from.code }}</div>
|
|
102
|
+
<div v-if="from.name" class="mt-1 truncate text-body-medium text-on-surface-variant">{{ from.name }}</div>
|
|
103
|
+
<div v-if="from.time" class="text-title-medium tabular-nums">{{ from.time }}</div>
|
|
104
|
+
</div>
|
|
105
|
+
<div class="flex flex-1 items-center gap-1 pt-3 text-on-surface-variant" aria-hidden="true">
|
|
106
|
+
<span class="h-0 flex-1 border-t-2 border-dotted border-outline-variant" />
|
|
107
|
+
<MIcon :name="transport" :size="24" :class="transport === 'flight' ? 'rotate-90' : ''" class="text-primary" />
|
|
108
|
+
<span class="h-0 flex-1 border-t-2 border-dotted border-outline-variant" />
|
|
109
|
+
</div>
|
|
110
|
+
<div v-if="to" class="min-w-0 text-end">
|
|
111
|
+
<div class="text-display-small font-medium leading-none tracking-tight">{{ to.code }}</div>
|
|
112
|
+
<div v-if="to.name" class="mt-1 truncate text-body-medium text-on-surface-variant">{{ to.name }}</div>
|
|
113
|
+
<div v-if="to.time" class="text-title-medium tabular-nums">{{ to.time }}</div>
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
|
|
117
|
+
<dl v-if="fields.length" class="grid grid-cols-[repeat(auto-fill,minmax(5.5rem,1fr))] gap-x-4 gap-y-3">
|
|
118
|
+
<div v-for="f in fields" :key="f.label" class="min-w-0">
|
|
119
|
+
<dt class="truncate text-label-medium uppercase tracking-wide text-on-surface-variant">{{ f.label }}</dt>
|
|
120
|
+
<dd class="truncate" :class="f.strong ? 'text-title-large font-medium text-primary' : 'text-title-medium'">{{ f.value }}</dd>
|
|
121
|
+
</div>
|
|
122
|
+
</dl>
|
|
123
|
+
|
|
124
|
+
<slot />
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
<div
|
|
129
|
+
v-if="$slots.stub"
|
|
130
|
+
class="m3-ticket__stub relative flex shrink-0 flex-col items-center justify-center gap-2 bg-surface-container-lowest p-4"
|
|
131
|
+
>
|
|
132
|
+
<span class="m3-ticket__perforation" aria-hidden="true" />
|
|
133
|
+
<slot name="stub" />
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
</template>
|
|
137
|
+
|
|
138
|
+
<style>
|
|
139
|
+
.m3-ticket {
|
|
140
|
+
filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.15)) drop-shadow(0 1px 3px rgb(0 0 0 / 0.1));
|
|
141
|
+
}
|
|
142
|
+
.m3-ticket__main,
|
|
143
|
+
.m3-ticket__stub {
|
|
144
|
+
--r: var(--m3-ticket-notch);
|
|
145
|
+
}
|
|
146
|
+
/* Each half cuts its own two corners at the perforation, so the notches line up whatever the content size */
|
|
147
|
+
.m3-ticket[data-orientation='horizontal'] .m3-ticket__main {
|
|
148
|
+
border-radius: var(--radius-lg, 16px) 0 0 var(--radius-lg, 16px);
|
|
149
|
+
}
|
|
150
|
+
.m3-ticket[data-orientation='horizontal'] .m3-ticket__stub {
|
|
151
|
+
width: var(--m3-ticket-stub);
|
|
152
|
+
border-radius: 0 var(--radius-lg, 16px) var(--radius-lg, 16px) 0;
|
|
153
|
+
-webkit-mask:
|
|
154
|
+
radial-gradient(circle var(--r) at 0 0, #0000 98%, #000) top / 100% 51% no-repeat,
|
|
155
|
+
radial-gradient(circle var(--r) at 0 100%, #0000 98%, #000) bottom / 100% 51% no-repeat;
|
|
156
|
+
mask:
|
|
157
|
+
radial-gradient(circle var(--r) at 0 0, #0000 98%, #000) top / 100% 51% no-repeat,
|
|
158
|
+
radial-gradient(circle var(--r) at 0 100%, #0000 98%, #000) bottom / 100% 51% no-repeat;
|
|
159
|
+
}
|
|
160
|
+
.m3-ticket[data-orientation='horizontal']:has(.m3-ticket__stub) .m3-ticket__main {
|
|
161
|
+
-webkit-mask:
|
|
162
|
+
radial-gradient(circle var(--r) at 100% 0, #0000 98%, #000) top / 100% 51% no-repeat,
|
|
163
|
+
radial-gradient(circle var(--r) at 100% 100%, #0000 98%, #000) bottom / 100% 51% no-repeat;
|
|
164
|
+
mask:
|
|
165
|
+
radial-gradient(circle var(--r) at 100% 0, #0000 98%, #000) top / 100% 51% no-repeat,
|
|
166
|
+
radial-gradient(circle var(--r) at 100% 100%, #0000 98%, #000) bottom / 100% 51% no-repeat;
|
|
167
|
+
}
|
|
168
|
+
.m3-ticket[data-orientation='vertical'] .m3-ticket__main {
|
|
169
|
+
border-radius: var(--radius-lg, 16px) var(--radius-lg, 16px) 0 0;
|
|
170
|
+
}
|
|
171
|
+
.m3-ticket[data-orientation='vertical'] .m3-ticket__stub {
|
|
172
|
+
border-radius: 0 0 var(--radius-lg, 16px) var(--radius-lg, 16px);
|
|
173
|
+
-webkit-mask:
|
|
174
|
+
radial-gradient(circle var(--r) at 0 0, #0000 98%, #000) left / 51% 100% no-repeat,
|
|
175
|
+
radial-gradient(circle var(--r) at 100% 0, #0000 98%, #000) right / 51% 100% no-repeat;
|
|
176
|
+
mask:
|
|
177
|
+
radial-gradient(circle var(--r) at 0 0, #0000 98%, #000) left / 51% 100% no-repeat,
|
|
178
|
+
radial-gradient(circle var(--r) at 100% 0, #0000 98%, #000) right / 51% 100% no-repeat;
|
|
179
|
+
}
|
|
180
|
+
.m3-ticket[data-orientation='vertical']:has(.m3-ticket__stub) .m3-ticket__main {
|
|
181
|
+
-webkit-mask:
|
|
182
|
+
radial-gradient(circle var(--r) at 0 100%, #0000 98%, #000) left / 51% 100% no-repeat,
|
|
183
|
+
radial-gradient(circle var(--r) at 100% 100%, #0000 98%, #000) right / 51% 100% no-repeat;
|
|
184
|
+
mask:
|
|
185
|
+
radial-gradient(circle var(--r) at 0 100%, #0000 98%, #000) left / 51% 100% no-repeat,
|
|
186
|
+
radial-gradient(circle var(--r) at 100% 100%, #0000 98%, #000) right / 51% 100% no-repeat;
|
|
187
|
+
}
|
|
188
|
+
.m3-ticket:not(:has(.m3-ticket__stub)) .m3-ticket__main {
|
|
189
|
+
border-radius: var(--radius-lg, 16px);
|
|
190
|
+
}
|
|
191
|
+
.m3-ticket__perforation {
|
|
192
|
+
position: absolute;
|
|
193
|
+
--dash: color-mix(in srgb, var(--color-on-surface) 30%, transparent);
|
|
194
|
+
}
|
|
195
|
+
.m3-ticket[data-orientation='horizontal'] .m3-ticket__perforation {
|
|
196
|
+
left: 0;
|
|
197
|
+
top: calc(var(--r) + 4px);
|
|
198
|
+
bottom: calc(var(--r) + 4px);
|
|
199
|
+
width: 2px;
|
|
200
|
+
background: repeating-linear-gradient(to bottom, var(--dash) 0 6px, transparent 6px 12px);
|
|
201
|
+
}
|
|
202
|
+
.m3-ticket[data-orientation='vertical'] .m3-ticket__perforation {
|
|
203
|
+
top: 0;
|
|
204
|
+
left: calc(var(--r) + 4px);
|
|
205
|
+
right: calc(var(--r) + 4px);
|
|
206
|
+
height: 2px;
|
|
207
|
+
background: repeating-linear-gradient(to right, var(--dash) 0 6px, transparent 6px 12px);
|
|
208
|
+
}
|
|
209
|
+
</style>
|
package/src/components/MTour.vue
CHANGED
|
@@ -3,17 +3,33 @@
|
|
|
3
3
|
* A guided, step-by-step walkthrough that highlights a page element per step with an auto-positioned tooltip
|
|
4
4
|
* and a dimming scrim.
|
|
5
5
|
*
|
|
6
|
+
* With `interactive` the page stays usable: no scrim, the target gets a ring drawn over it (the element itself is
|
|
7
|
+
* left alone) and the ring and the tooltip follow it every frame, for targets that move (a canvas being panned, a
|
|
8
|
+
* panel opening). With `v-model:step` the page drives the steps itself (a tutorial that moves on when the user has
|
|
9
|
+
* done what a step asks, or skips the ones already done), and the `content`/`actions` slots replace the text and
|
|
10
|
+
* the buttons.
|
|
11
|
+
*
|
|
12
|
+
* @slot content Replaces a step's title and text. Scope: `{ step, index }`
|
|
13
|
+
* @slot indicator Replaces the "2 / 5" over the step. Scope: `{ index, count }`
|
|
14
|
+
* @slot progress Replaces the progress dots. Scope: `{ index, count }`
|
|
15
|
+
* @slot actions Replaces the Previous/Next buttons. Scope: `{ step, index, isFirst, isLast, next, prev, close }`
|
|
6
16
|
* @event update:modelValue Emitted when the tour opens or closes (Escape-less — closed via the X button,
|
|
7
17
|
* clicking the scrim, or finishing) — powers v-model
|
|
18
|
+
* @event update:step Emitted when the current step changes (v-model:step)
|
|
8
19
|
* @event finish Emitted when the user completes the last step (clicks the finish button)
|
|
9
20
|
*/
|
|
10
|
-
import { ref, computed, watch, nextTick, onBeforeUnmount } from 'vue'
|
|
21
|
+
import { ref, computed, watch, nextTick, onMounted, onBeforeUnmount } from 'vue'
|
|
11
22
|
import MButton from './MButton.vue'
|
|
12
23
|
import MIcon from './MIcon.vue'
|
|
13
24
|
import { useLocale } from '../composables/useLocale'
|
|
14
25
|
|
|
15
26
|
export interface TourStep {
|
|
16
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The element to highlight and point at: a CSS selector, or a function returning the element (looked up again
|
|
29
|
+
* on every frame in `interactive` mode, so it can change). None, or none found: the tooltip sits in the viewport,
|
|
30
|
+
* on its `placement` side (centered without one)
|
|
31
|
+
*/
|
|
32
|
+
target?: string | (() => Element | null | undefined)
|
|
17
33
|
title: string
|
|
18
34
|
content: string
|
|
19
35
|
placement?: 'top' | 'bottom' | 'left' | 'right'
|
|
@@ -30,16 +46,34 @@ const props = defineProps<{
|
|
|
30
46
|
nextLabel?: string
|
|
31
47
|
/** Label for the final step's button (defaults to the locale string, 'Finish') */
|
|
32
48
|
finishLabel?: string
|
|
49
|
+
/** The current step's index (v-model:step); without it the tour keeps its own */
|
|
50
|
+
step?: number
|
|
51
|
+
/**
|
|
52
|
+
* Leaves the page usable while the tour is open: no scrim, a ring drawn over the target instead of lifting the
|
|
53
|
+
* target itself, tooltip and ring following the target as it moves, no scrolling to it
|
|
54
|
+
*/
|
|
55
|
+
interactive?: boolean
|
|
33
56
|
}>()
|
|
34
57
|
|
|
35
58
|
const locale = useLocale()
|
|
36
59
|
|
|
37
60
|
const emit = defineEmits<{
|
|
38
61
|
'update:modelValue': [boolean]
|
|
62
|
+
'update:step': [number]
|
|
39
63
|
finish: []
|
|
40
64
|
}>()
|
|
41
65
|
|
|
42
|
-
const
|
|
66
|
+
const ownStep = ref(0)
|
|
67
|
+
const currentStep = computed({
|
|
68
|
+
get: () => props.step ?? ownStep.value,
|
|
69
|
+
set: (v: number) => {
|
|
70
|
+
ownStep.value = v
|
|
71
|
+
emit('update:step', v)
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
const tooltipEl = ref<HTMLElement | null>(null)
|
|
75
|
+
/** The ring over the target in interactive mode (fixed, viewport coordinates) */
|
|
76
|
+
const ringStyle = ref<Record<string, string> | null>(null)
|
|
43
77
|
const tooltipStyle = ref<Record<string, string>>({})
|
|
44
78
|
const arrowStyle = ref<Record<string, string>>({})
|
|
45
79
|
const placement = ref<'top' | 'bottom' | 'left' | 'right'>('bottom')
|
|
@@ -49,7 +83,20 @@ const isFirst = computed(() => currentStep.value === 0)
|
|
|
49
83
|
const isLast = computed(() => currentStep.value === props.steps.length - 1)
|
|
50
84
|
|
|
51
85
|
let scrollRaf = 0
|
|
52
|
-
|
|
86
|
+
let followRaf = 0
|
|
87
|
+
|
|
88
|
+
function targetOf(st: TourStep | undefined): HTMLElement | null {
|
|
89
|
+
const t = st?.target
|
|
90
|
+
if (!t) return null
|
|
91
|
+
const el = typeof t === 'string' ? document.querySelector(t) : t()
|
|
92
|
+
// Not laid out (display: none, or a closed panel's leftover): as if there were none
|
|
93
|
+
return el && el.getClientRects().length ? (el as HTMLElement) : null
|
|
94
|
+
}
|
|
95
|
+
const same = (a: Record<string, string> | null, b: Record<string, string> | null) => JSON.stringify(a) === JSON.stringify(b)
|
|
96
|
+
function follow() {
|
|
97
|
+
positionTooltip()
|
|
98
|
+
followRaf = requestAnimationFrame(follow)
|
|
99
|
+
}
|
|
53
100
|
function onScrollOrResize() {
|
|
54
101
|
cancelAnimationFrame(scrollRaf)
|
|
55
102
|
scrollRaf = requestAnimationFrame(positionTooltip)
|
|
@@ -58,27 +105,60 @@ function onScrollOrResize() {
|
|
|
58
105
|
function startListeners() {
|
|
59
106
|
window.addEventListener('scroll', onScrollOrResize, true)
|
|
60
107
|
window.addEventListener('resize', onScrollOrResize)
|
|
108
|
+
if (props.interactive) {
|
|
109
|
+
cancelAnimationFrame(followRaf)
|
|
110
|
+
followRaf = requestAnimationFrame(follow)
|
|
111
|
+
}
|
|
61
112
|
}
|
|
62
113
|
|
|
63
114
|
function stopListeners() {
|
|
64
115
|
window.removeEventListener('scroll', onScrollOrResize, true)
|
|
65
116
|
window.removeEventListener('resize', onScrollOrResize)
|
|
66
117
|
cancelAnimationFrame(scrollRaf)
|
|
118
|
+
cancelAnimationFrame(followRaf)
|
|
119
|
+
ringStyle.value = null
|
|
67
120
|
}
|
|
68
121
|
|
|
69
122
|
function positionTooltip() {
|
|
70
123
|
if (!step.value) return
|
|
71
|
-
const el =
|
|
72
|
-
if (!el) return
|
|
73
|
-
|
|
74
|
-
const rect = el.getBoundingClientRect()
|
|
75
|
-
const pad = 12
|
|
76
|
-
const arrowSize = 8
|
|
124
|
+
const el = targetOf(step.value)
|
|
77
125
|
const vw = window.innerWidth
|
|
78
126
|
const vh = window.innerHeight
|
|
79
127
|
const edge = 8
|
|
80
128
|
const tooltipW = Math.min(320, vw - edge * 2)
|
|
81
|
-
|
|
129
|
+
// Its real height once it's there (a slot can make it any height)
|
|
130
|
+
const approxH = tooltipEl.value?.offsetHeight || 220
|
|
131
|
+
|
|
132
|
+
if (!el) {
|
|
133
|
+
// Nothing to point at: on its side of the viewport, or in the middle
|
|
134
|
+
const side = step.value.placement
|
|
135
|
+
const s: Record<string, string> = { width: `${tooltipW}px` }
|
|
136
|
+
if (side === 'left' || side === 'right') {
|
|
137
|
+
s[side] = `${edge * 2}px`
|
|
138
|
+
s.top = '50%'
|
|
139
|
+
s.transform = 'translateY(-50%)'
|
|
140
|
+
} else {
|
|
141
|
+
s.left = `${(vw - tooltipW) / 2}px`
|
|
142
|
+
if (side === 'top') s.top = `${edge * 2}px`
|
|
143
|
+
else if (side === 'bottom') s.bottom = `${edge * 2}px`
|
|
144
|
+
else {
|
|
145
|
+
s.top = '50%'
|
|
146
|
+
s.transform = 'translateY(-50%)'
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!same(tooltipStyle.value, s)) tooltipStyle.value = s
|
|
150
|
+
if (!same(arrowStyle.value, { display: 'none' })) arrowStyle.value = { display: 'none' }
|
|
151
|
+
if (ringStyle.value) ringStyle.value = null
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const rect = el.getBoundingClientRect()
|
|
156
|
+
const pad = 12
|
|
157
|
+
const arrowSize = 8
|
|
158
|
+
if (props.interactive) {
|
|
159
|
+
const r = { left: `${rect.left - 4}px`, top: `${rect.top - 4}px`, width: `${rect.width + 8}px`, height: `${rect.height + 8}px` }
|
|
160
|
+
if (!same(ringStyle.value, r)) ringStyle.value = r
|
|
161
|
+
}
|
|
82
162
|
|
|
83
163
|
let p = step.value.placement ?? 'bottom'
|
|
84
164
|
|
|
@@ -143,21 +223,20 @@ function positionTooltip() {
|
|
|
143
223
|
}
|
|
144
224
|
}
|
|
145
225
|
|
|
146
|
-
tooltipStyle.value = s
|
|
147
|
-
arrowStyle.value = a
|
|
226
|
+
if (!same(tooltipStyle.value, s)) tooltipStyle.value = s
|
|
227
|
+
if (!same(arrowStyle.value, a)) arrowStyle.value = a
|
|
148
228
|
}
|
|
149
229
|
|
|
150
230
|
function scrollToTarget() {
|
|
151
|
-
if (!step.value) return
|
|
152
|
-
|
|
153
|
-
el?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
|
231
|
+
if (!step.value || props.interactive) return
|
|
232
|
+
targetOf(step.value)?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
|
154
233
|
}
|
|
155
234
|
|
|
156
235
|
function highlightTarget() {
|
|
157
236
|
if (!step.value) return
|
|
158
237
|
document.querySelectorAll('.m3-tour-highlight').forEach((el) => el.classList.remove('m3-tour-highlight'))
|
|
159
|
-
|
|
160
|
-
|
|
238
|
+
if (props.interactive) return
|
|
239
|
+
targetOf(step.value)?.classList.add('m3-tour-highlight')
|
|
161
240
|
}
|
|
162
241
|
|
|
163
242
|
function clearHighlight() {
|
|
@@ -180,11 +259,11 @@ function goPrev() {
|
|
|
180
259
|
function close() {
|
|
181
260
|
stopListeners()
|
|
182
261
|
clearHighlight()
|
|
183
|
-
|
|
262
|
+
if (props.step === undefined) ownStep.value = 0
|
|
184
263
|
emit('update:modelValue', false)
|
|
185
264
|
}
|
|
186
265
|
|
|
187
|
-
|
|
266
|
+
function show() {
|
|
188
267
|
if (props.modelValue) {
|
|
189
268
|
nextTick(() => {
|
|
190
269
|
highlightTarget()
|
|
@@ -192,12 +271,26 @@ watch([() => props.modelValue, currentStep], () => {
|
|
|
192
271
|
positionTooltip()
|
|
193
272
|
})
|
|
194
273
|
}
|
|
195
|
-
}
|
|
274
|
+
}
|
|
275
|
+
watch([() => props.modelValue, currentStep], show)
|
|
196
276
|
|
|
197
277
|
watch(() => props.modelValue, (v) => {
|
|
198
278
|
if (v) startListeners()
|
|
199
279
|
else { stopListeners(); clearHighlight() }
|
|
200
280
|
})
|
|
281
|
+
// Mounted already open: no watcher has run yet
|
|
282
|
+
onMounted(() => {
|
|
283
|
+
if (!props.modelValue) return
|
|
284
|
+
startListeners()
|
|
285
|
+
show()
|
|
286
|
+
})
|
|
287
|
+
watch(() => props.interactive, () => {
|
|
288
|
+
if (props.modelValue) {
|
|
289
|
+
stopListeners()
|
|
290
|
+
startListeners()
|
|
291
|
+
highlightTarget()
|
|
292
|
+
}
|
|
293
|
+
})
|
|
201
294
|
|
|
202
295
|
onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
203
296
|
</script>
|
|
@@ -206,13 +299,19 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
|
206
299
|
<Teleport to="body">
|
|
207
300
|
<!-- Overlay -->
|
|
208
301
|
<Transition name="m3-tour" appear>
|
|
209
|
-
<div v-if="modelValue && step" class="fixed inset-0 z-200 bg-scrim/32" @click="close" />
|
|
302
|
+
<div v-if="modelValue && step && !interactive" class="fixed inset-0 z-200 bg-scrim/32" @click="close" />
|
|
210
303
|
</Transition>
|
|
211
304
|
|
|
305
|
+
<!-- The target's ring (interactive) -->
|
|
306
|
+
<div v-if="modelValue && step && interactive && ringStyle" class="m3-tour-ring pointer-events-none fixed z-201 rounded-xl" :style="ringStyle" aria-hidden="true" />
|
|
307
|
+
|
|
212
308
|
<!-- Tooltip -->
|
|
213
309
|
<Transition name="m3-tour" appear>
|
|
214
310
|
<div
|
|
215
311
|
v-if="modelValue && step"
|
|
312
|
+
ref="tooltipEl"
|
|
313
|
+
:role="interactive ? 'region' : 'dialog'"
|
|
314
|
+
:aria-label="step.title"
|
|
216
315
|
class="fixed z-202 w-80 max-w-[calc(100vw-1rem)] rounded-xl bg-surface-container-high p-5 shadow-elevation-3"
|
|
217
316
|
:style="tooltipStyle"
|
|
218
317
|
>
|
|
@@ -221,9 +320,11 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
|
221
320
|
|
|
222
321
|
<!-- Step indicator -->
|
|
223
322
|
<div class="mb-2 flex items-center justify-between">
|
|
224
|
-
<
|
|
225
|
-
|
|
226
|
-
|
|
323
|
+
<slot name="indicator" :index="currentStep" :count="steps.length">
|
|
324
|
+
<span class="text-label-small text-on-surface-variant">
|
|
325
|
+
{{ currentStep + 1 }} / {{ steps.length }}
|
|
326
|
+
</span>
|
|
327
|
+
</slot>
|
|
227
328
|
<button
|
|
228
329
|
:aria-label="locale.close"
|
|
229
330
|
type="button"
|
|
@@ -234,10 +335,13 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
|
234
335
|
</button>
|
|
235
336
|
</div>
|
|
236
337
|
|
|
237
|
-
<
|
|
238
|
-
|
|
338
|
+
<slot name="content" :step="step" :index="currentStep">
|
|
339
|
+
<h3 class="mb-1 text-title-medium font-medium text-on-surface">{{ step.title }}</h3>
|
|
340
|
+
<p class="mb-4 text-body-medium text-on-surface-variant">{{ step.content }}</p>
|
|
341
|
+
</slot>
|
|
239
342
|
|
|
240
343
|
<!-- Progress dots -->
|
|
344
|
+
<slot name="progress" :index="currentStep" :count="steps.length">
|
|
241
345
|
<div class="mb-4 flex justify-center gap-1.5">
|
|
242
346
|
<div
|
|
243
347
|
v-for="(_, i) in steps"
|
|
@@ -246,8 +350,10 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
|
246
350
|
:class="i === currentStep ? 'w-6 bg-primary' : 'w-1.5 bg-outline-variant'"
|
|
247
351
|
/>
|
|
248
352
|
</div>
|
|
353
|
+
</slot>
|
|
249
354
|
|
|
250
355
|
<!-- Actions -->
|
|
356
|
+
<slot name="actions" :step="step" :index="currentStep" :is-first="isFirst" :is-last="isLast" :next="goNext" :prev="goPrev" :close="close">
|
|
251
357
|
<div class="flex justify-between">
|
|
252
358
|
<MButton
|
|
253
359
|
v-if="!isFirst"
|
|
@@ -261,6 +367,7 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
|
261
367
|
{{ isLast ? (finishLabel ?? locale.finish) : (nextLabel ?? locale.next) }}
|
|
262
368
|
</MButton>
|
|
263
369
|
</div>
|
|
370
|
+
</slot>
|
|
264
371
|
</div>
|
|
265
372
|
</Transition>
|
|
266
373
|
</Teleport>
|
|
@@ -274,6 +381,17 @@ onBeforeUnmount(() => { stopListeners(); clearHighlight() })
|
|
|
274
381
|
border-radius: 8px;
|
|
275
382
|
}
|
|
276
383
|
|
|
384
|
+
.m3-tour-ring {
|
|
385
|
+
box-shadow: 0 0 0 3px var(--color-primary), 0 0 0 8px color-mix(in srgb, var(--color-primary) 24%, transparent);
|
|
386
|
+
animation: m3-tour-ring 1.6s ease-in-out infinite;
|
|
387
|
+
}
|
|
388
|
+
@keyframes m3-tour-ring {
|
|
389
|
+
50% { box-shadow: 0 0 0 3px var(--color-primary), 0 0 0 12px color-mix(in srgb, var(--color-primary) 0%, transparent); }
|
|
390
|
+
}
|
|
391
|
+
@media (prefers-reduced-motion: reduce) {
|
|
392
|
+
.m3-tour-ring { animation: none; }
|
|
393
|
+
}
|
|
394
|
+
|
|
277
395
|
.m3-tour-enter-active,
|
|
278
396
|
.m3-tour-leave-active {
|
|
279
397
|
transition: opacity 0.2s ease;
|