@m3ui-vue/m3ui-vue 1.3.8 → 1.4.1
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 +1102 -20
- 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/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/MCountdown.vue.d.ts +80 -0
- package/dist/components/MCreditCardInput.vue.d.ts +75 -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/MTicket.vue.d.ts +83 -0
- 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/mortgage.d.ts +37 -0
- package/dist/composables/useLocale.d.ts +131 -0
- package/dist/draw.js +2 -2
- package/dist/flow.js +1 -1
- package/dist/gantt.js +1 -1
- package/dist/index.d.ts +37 -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 +10125 -5263
- 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__/MCountdown.test.ts +75 -0
- package/src/__tests__/MCreditCardInput.test.ts +122 -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__/MVitalsChart.test.ts +49 -0
- package/src/__tests__/clearToNull.test.ts +30 -0
- package/src/__tests__/mortgage.test.ts +25 -0
- package/src/__tests__/ssr.test.ts +11 -0
- package/src/components/MAutocomplete.vue +2 -2
- 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/MCountdown.vue +200 -0
- package/src/components/MCreditCardInput.vue +351 -0
- 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/MSelect.vue +2 -2
- package/src/components/MTicket.vue +209 -0
- package/src/components/MVitalsChart.vue +303 -0
- package/src/composables/_printElement.ts +36 -0
- package/src/composables/cardBrand.ts +104 -0
- package/src/composables/mortgage.ts +70 -0
- package/src/composables/useLocale.ts +277 -0
- package/src/index.ts +37 -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/useLocale-D2ucaY-l.js.map +0 -1
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/** One choice in a `ProductOptionGroup`. */
|
|
3
|
+
export interface ProductOption {
|
|
4
|
+
value: string
|
|
5
|
+
label: string
|
|
6
|
+
/** Price added by this option (per unit; negative lowers it) */
|
|
7
|
+
price?: number
|
|
8
|
+
/** Swatch color for `display: 'swatches'` (any CSS color) */
|
|
9
|
+
color?: string
|
|
10
|
+
/** Swatch image for `display: 'swatches'` */
|
|
11
|
+
image?: string
|
|
12
|
+
/** A line under the label in list display */
|
|
13
|
+
description?: string
|
|
14
|
+
disabled?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A group of options of a product: a size, a color, extras, the sides of a combo.
|
|
19
|
+
* - `single`: pick one (radio list, chips or swatches). Its value is a string.
|
|
20
|
+
* - `multiple`: pick several, between `min` and `max` (checkbox list or chips). Its value is a string array.
|
|
21
|
+
* - `quantity`: a count of each option, up to `max` in total (+/− rows). Its value is `{ [option]: count }`.
|
|
22
|
+
*/
|
|
23
|
+
export interface ProductOptionGroup {
|
|
24
|
+
key: string
|
|
25
|
+
label: string
|
|
26
|
+
type?: 'single' | 'multiple' | 'quantity'
|
|
27
|
+
/** How the options are drawn. Defaults to `list` (`chips` for sizes is a good fit, `swatches` for colors) */
|
|
28
|
+
display?: 'list' | 'chips' | 'swatches'
|
|
29
|
+
/** A single group must have a choice */
|
|
30
|
+
required?: boolean
|
|
31
|
+
/** Least selections / units in a multiple or quantity group */
|
|
32
|
+
min?: number
|
|
33
|
+
/** Most selections / units in a multiple or quantity group */
|
|
34
|
+
max?: number
|
|
35
|
+
options: ProductOption[]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type ProductSelection = Record<string, string | string[] | Record<string, number> | undefined>
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<script setup lang="ts">
|
|
42
|
+
/**
|
|
43
|
+
* Picks the variant and extras of a product with the price updating live: a size and color in a store, the
|
|
44
|
+
* doneness, sides and extras of a dish, the drinks of a combo. Groups are single choice, multiple choice (with
|
|
45
|
+
* min/max) or per-option quantities; `isAvailable` crosses out combinations that don't exist (a size out of stock in
|
|
46
|
+
* that color). The add button stays disabled until every group is satisfied.
|
|
47
|
+
*
|
|
48
|
+
* @slot header Content above the groups (the product's photo, name, description)
|
|
49
|
+
* @slot option Replaces an option's label in list display. Slot props: `{ group, option, selected, available }`
|
|
50
|
+
* @slot action Replaces the add button. Slot props: `{ valid, total, quantity, add }`
|
|
51
|
+
* @event update:modelValue The selection, keyed by group key — powers v-model
|
|
52
|
+
* @event update:quantity Units of the product — powers v-model:quantity
|
|
53
|
+
* @event add Emitted by the add button with `{ selection, quantity, unitPrice, total }`
|
|
54
|
+
*/
|
|
55
|
+
import { computed } from 'vue'
|
|
56
|
+
import MIcon from './MIcon.vue'
|
|
57
|
+
import MRadio from './MRadio.vue'
|
|
58
|
+
import MCheckbox from './MCheckbox.vue'
|
|
59
|
+
import MIconButton from './MIconButton.vue'
|
|
60
|
+
import MButton from './MButton.vue'
|
|
61
|
+
import { useLocale } from '../composables/useLocale'
|
|
62
|
+
import { vRipple } from '../directives/vRipple'
|
|
63
|
+
|
|
64
|
+
const locale = useLocale()
|
|
65
|
+
|
|
66
|
+
const props = withDefaults(
|
|
67
|
+
defineProps<{
|
|
68
|
+
/** The option groups */
|
|
69
|
+
groups: ProductOptionGroup[]
|
|
70
|
+
/** The selection (v-model), keyed by group key */
|
|
71
|
+
modelValue?: ProductSelection
|
|
72
|
+
/** Price of the product before options */
|
|
73
|
+
basePrice?: number
|
|
74
|
+
/** Units of the product (v-model:quantity). Pass `null` to hide the quantity stepper */
|
|
75
|
+
quantity?: number | null
|
|
76
|
+
/** Most units of the product */
|
|
77
|
+
maxQuantity?: number
|
|
78
|
+
/** ISO 4217 code to format prices */
|
|
79
|
+
currency?: string
|
|
80
|
+
/** Label of the add button; without it there is no button */
|
|
81
|
+
actionLabel?: string
|
|
82
|
+
/**
|
|
83
|
+
* Whether an option can be picked given the rest of the selection, e.g. a size out of stock in the chosen
|
|
84
|
+
* color. Unavailable options are crossed out and can't be picked
|
|
85
|
+
*/
|
|
86
|
+
isAvailable?: (group: ProductOptionGroup, option: ProductOption, selection: ProductSelection) => boolean
|
|
87
|
+
disabled?: boolean
|
|
88
|
+
}>(),
|
|
89
|
+
{
|
|
90
|
+
modelValue: () => ({}),
|
|
91
|
+
basePrice: 0,
|
|
92
|
+
quantity: 1,
|
|
93
|
+
maxQuantity: 99,
|
|
94
|
+
disabled: false,
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
const emit = defineEmits<{
|
|
99
|
+
'update:modelValue': [ProductSelection]
|
|
100
|
+
'update:quantity': [number]
|
|
101
|
+
add: [{ selection: ProductSelection; quantity: number; unitPrice: number; total: number }]
|
|
102
|
+
}>()
|
|
103
|
+
|
|
104
|
+
const sel = computed(() => props.modelValue)
|
|
105
|
+
|
|
106
|
+
function typeOf(g: ProductOptionGroup) {
|
|
107
|
+
return g.type ?? 'single'
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function single(g: ProductOptionGroup) {
|
|
111
|
+
const v = sel.value[g.key]
|
|
112
|
+
return typeof v === 'string' ? v : undefined
|
|
113
|
+
}
|
|
114
|
+
function multi(g: ProductOptionGroup): string[] {
|
|
115
|
+
const v = sel.value[g.key]
|
|
116
|
+
return Array.isArray(v) ? v : []
|
|
117
|
+
}
|
|
118
|
+
function counts(g: ProductOptionGroup): Record<string, number> {
|
|
119
|
+
const v = sel.value[g.key]
|
|
120
|
+
return v && typeof v === 'object' && !Array.isArray(v) ? v : {}
|
|
121
|
+
}
|
|
122
|
+
function countOf(g: ProductOptionGroup) {
|
|
123
|
+
return typeOf(g) === 'multiple'
|
|
124
|
+
? multi(g).length
|
|
125
|
+
: typeOf(g) === 'quantity'
|
|
126
|
+
? Object.values(counts(g)).reduce((s, n) => s + n, 0)
|
|
127
|
+
: single(g) ? 1 : 0
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function set(g: ProductOptionGroup, v: ProductSelection[string]) {
|
|
131
|
+
emit('update:modelValue', { ...sel.value, [g.key]: v })
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function available(g: ProductOptionGroup, o: ProductOption) {
|
|
135
|
+
if (o.disabled) return false
|
|
136
|
+
return props.isAvailable ? props.isAvailable(g, o, sel.value) : true
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function isSelected(g: ProductOptionGroup, o: ProductOption) {
|
|
140
|
+
const t = typeOf(g)
|
|
141
|
+
return t === 'single' ? single(g) === o.value : t === 'multiple' ? multi(g).includes(o.value) : (counts(g)[o.value] ?? 0) > 0
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function pick(g: ProductOptionGroup, o: ProductOption) {
|
|
145
|
+
if (props.disabled || !available(g, o)) return
|
|
146
|
+
const t = typeOf(g)
|
|
147
|
+
if (t === 'single') {
|
|
148
|
+
if (single(g) === o.value) {
|
|
149
|
+
if (!g.required) set(g, undefined)
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
set(g, o.value)
|
|
153
|
+
} else if (t === 'multiple') {
|
|
154
|
+
const cur = multi(g)
|
|
155
|
+
if (cur.includes(o.value)) set(g, cur.filter((v) => v !== o.value))
|
|
156
|
+
else if (g.max === 1) set(g, [o.value])
|
|
157
|
+
else if (g.max === undefined || cur.length < g.max) set(g, [...cur, o.value])
|
|
158
|
+
} else {
|
|
159
|
+
step(g, o, 1)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function step(g: ProductOptionGroup, o: ProductOption, d: number) {
|
|
164
|
+
if (props.disabled) return
|
|
165
|
+
const c = { ...counts(g) }
|
|
166
|
+
const next = (c[o.value] ?? 0) + d
|
|
167
|
+
if (next < 0) return
|
|
168
|
+
if (d > 0 && (!available(g, o) || (g.max !== undefined && countOf(g) >= g.max))) return
|
|
169
|
+
if (next === 0) delete c[o.value]
|
|
170
|
+
else c[o.value] = next
|
|
171
|
+
set(g, c)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function atMax(g: ProductOptionGroup) {
|
|
175
|
+
return g.max !== undefined && countOf(g) >= g.max
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Rule text and whether it's satisfied, per group */
|
|
179
|
+
function rule(g: ProductOptionGroup): { text: string; ok: boolean; required: boolean } {
|
|
180
|
+
const t = typeOf(g)
|
|
181
|
+
const n = countOf(g)
|
|
182
|
+
if (t === 'single') return { text: g.required ? locale.configRequired : locale.configOptional, ok: !g.required || n === 1, required: !!g.required }
|
|
183
|
+
const min = g.min ?? 0
|
|
184
|
+
const max = g.max
|
|
185
|
+
let text: string
|
|
186
|
+
if (min > 0 && max === min) text = locale.configChooseExactly.replace('{n}', String(min))
|
|
187
|
+
else if (min > 0) text = locale.configChooseAtLeast.replace('{n}', String(min))
|
|
188
|
+
else if (max !== undefined) text = locale.configChooseUpTo.replace('{n}', String(max))
|
|
189
|
+
else text = locale.configOptional
|
|
190
|
+
return { text, ok: n >= min && (max === undefined || n <= max), required: min > 0 }
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const valid = computed(() => props.groups.every((g) => rule(g).ok))
|
|
194
|
+
|
|
195
|
+
const unitPrice = computed(() => {
|
|
196
|
+
let p = props.basePrice
|
|
197
|
+
for (const g of props.groups) {
|
|
198
|
+
for (const o of g.options) {
|
|
199
|
+
if (!o.price) continue
|
|
200
|
+
const t = typeOf(g)
|
|
201
|
+
if (t === 'quantity') p += o.price * (counts(g)[o.value] ?? 0)
|
|
202
|
+
else if (isSelected(g, o)) p += o.price
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return Math.round(p * 100) / 100
|
|
206
|
+
})
|
|
207
|
+
const qty = computed(() => props.quantity ?? 1)
|
|
208
|
+
const total = computed(() => Math.round(unitPrice.value * qty.value * 100) / 100)
|
|
209
|
+
|
|
210
|
+
function money(n: number, signed = false) {
|
|
211
|
+
const s = new Intl.NumberFormat(locale.lang, props.currency ? { style: 'currency', currency: props.currency } : { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(Math.abs(n))
|
|
212
|
+
return signed ? `${n < 0 ? '−' : '+'}${s}` : s
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function setQty(d: number) {
|
|
216
|
+
const next = Math.min(props.maxQuantity, Math.max(1, qty.value + d))
|
|
217
|
+
if (next !== qty.value) emit('update:quantity', next)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function add() {
|
|
221
|
+
if (!valid.value || props.disabled) return
|
|
222
|
+
emit('add', { selection: sel.value, quantity: qty.value, unitPrice: unitPrice.value, total: total.value })
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function selectedLabel(g: ProductOptionGroup) {
|
|
226
|
+
return g.options.find((o) => o.value === single(g))?.label
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
defineExpose({ valid, unitPrice, total })
|
|
230
|
+
</script>
|
|
231
|
+
|
|
232
|
+
<template>
|
|
233
|
+
<div class="m3-product-configurator flex flex-col gap-2 text-on-surface">
|
|
234
|
+
<slot name="header" />
|
|
235
|
+
|
|
236
|
+
<section
|
|
237
|
+
v-for="g in groups"
|
|
238
|
+
:key="g.key"
|
|
239
|
+
class="flex flex-col"
|
|
240
|
+
role="group"
|
|
241
|
+
:aria-labelledby="`m3pc-${g.key}`"
|
|
242
|
+
:data-group="g.key"
|
|
243
|
+
>
|
|
244
|
+
<div class="flex items-center gap-2 py-2">
|
|
245
|
+
<h3 :id="`m3pc-${g.key}`" class="flex-1 text-title-medium">
|
|
246
|
+
{{ g.label }}<span v-if="(g.display === 'swatches' || g.display === 'chips') && typeOf(g) === 'single' && selectedLabel(g)" class="text-body-large text-on-surface-variant">: {{ selectedLabel(g) }}</span>
|
|
247
|
+
</h3>
|
|
248
|
+
<span
|
|
249
|
+
class="rounded-sm px-2 py-0.5 text-label-medium"
|
|
250
|
+
:class="rule(g).ok
|
|
251
|
+
? 'bg-surface-container-high text-on-surface-variant'
|
|
252
|
+
: rule(g).required ? 'bg-error-container text-on-error-container' : 'bg-surface-container-high text-on-surface-variant'"
|
|
253
|
+
data-rule
|
|
254
|
+
>
|
|
255
|
+
<MIcon v-if="rule(g).ok && rule(g).required" name="check" :size="14" class="-mt-0.5 me-0.5 align-middle" />{{ rule(g).text }}
|
|
256
|
+
</span>
|
|
257
|
+
</div>
|
|
258
|
+
|
|
259
|
+
<!-- Swatches -->
|
|
260
|
+
<div v-if="g.display === 'swatches'" class="flex flex-wrap gap-3 pb-2">
|
|
261
|
+
<button
|
|
262
|
+
v-for="o in g.options"
|
|
263
|
+
:key="o.value"
|
|
264
|
+
v-ripple
|
|
265
|
+
type="button"
|
|
266
|
+
class="m3-pc-swatch relative h-11 w-11 overflow-hidden rounded-full"
|
|
267
|
+
:class="{ 'is-selected': isSelected(g, o), 'is-unavailable': !available(g, o) }"
|
|
268
|
+
:style="{ background: o.image ? `center / cover url(${o.image})` : o.color }"
|
|
269
|
+
:aria-label="o.price ? `${o.label} ${money(o.price, true)}` : o.label"
|
|
270
|
+
:aria-pressed="isSelected(g, o)"
|
|
271
|
+
:disabled="disabled || !available(g, o)"
|
|
272
|
+
:title="o.label"
|
|
273
|
+
:data-option="o.value"
|
|
274
|
+
@click="pick(g, o)"
|
|
275
|
+
/>
|
|
276
|
+
</div>
|
|
277
|
+
|
|
278
|
+
<!-- Chips -->
|
|
279
|
+
<div v-else-if="g.display === 'chips'" class="flex flex-wrap gap-2 pb-2">
|
|
280
|
+
<button
|
|
281
|
+
v-for="o in g.options"
|
|
282
|
+
:key="o.value"
|
|
283
|
+
v-ripple
|
|
284
|
+
type="button"
|
|
285
|
+
class="m3-pc-chip relative flex h-10 min-w-12 items-center justify-center gap-1 overflow-hidden rounded-sm border px-4 text-label-large transition-colors"
|
|
286
|
+
:class="isSelected(g, o)
|
|
287
|
+
? 'border-transparent bg-secondary-container text-on-secondary-container'
|
|
288
|
+
: 'border-outline-variant text-on-surface-variant'"
|
|
289
|
+
:aria-pressed="isSelected(g, o)"
|
|
290
|
+
:disabled="disabled || !available(g, o) || (!isSelected(g, o) && typeOf(g) === 'multiple' && atMax(g) && g.max !== 1)"
|
|
291
|
+
:data-option="o.value"
|
|
292
|
+
@click="pick(g, o)"
|
|
293
|
+
>
|
|
294
|
+
<MIcon v-if="isSelected(g, o)" name="check" :size="18" />
|
|
295
|
+
<span :class="{ 'line-through': !available(g, o) }">{{ o.label }}</span>
|
|
296
|
+
<span v-if="o.price" class="opacity-70">{{ money(o.price, true) }}</span>
|
|
297
|
+
</button>
|
|
298
|
+
</div>
|
|
299
|
+
|
|
300
|
+
<!-- List -->
|
|
301
|
+
<ul v-else role="list" class="flex flex-col">
|
|
302
|
+
<li v-for="o in g.options" :key="o.value" :data-option="o.value">
|
|
303
|
+
<div
|
|
304
|
+
v-if="typeOf(g) === 'quantity'"
|
|
305
|
+
class="flex min-h-14 items-center gap-3 py-1"
|
|
306
|
+
:class="{ 'opacity-40': !available(g, o) && !counts(g)[o.value] }"
|
|
307
|
+
>
|
|
308
|
+
<div class="min-w-0 flex-1">
|
|
309
|
+
<slot name="option" :group="g" :option="o" :selected="isSelected(g, o)" :available="available(g, o)">
|
|
310
|
+
<div class="text-body-large">{{ o.label }}</div>
|
|
311
|
+
<div v-if="o.description" class="text-body-medium text-on-surface-variant">{{ o.description }}</div>
|
|
312
|
+
</slot>
|
|
313
|
+
</div>
|
|
314
|
+
<span v-if="o.price" class="text-body-medium text-on-surface-variant tabular-nums">{{ money(o.price, true) }}</span>
|
|
315
|
+
<div class="flex items-center gap-1">
|
|
316
|
+
<MIconButton
|
|
317
|
+
v-if="counts(g)[o.value]"
|
|
318
|
+
icon="remove"
|
|
319
|
+
size="sm"
|
|
320
|
+
variant="outlined"
|
|
321
|
+
:aria-label="`${locale.configDecrease}: ${o.label}`"
|
|
322
|
+
:disabled="disabled"
|
|
323
|
+
@click="step(g, o, -1)"
|
|
324
|
+
/>
|
|
325
|
+
<span v-if="counts(g)[o.value]" class="min-w-6 text-center text-title-medium tabular-nums" data-count>{{ counts(g)[o.value] }}</span>
|
|
326
|
+
<MIconButton
|
|
327
|
+
icon="add"
|
|
328
|
+
size="sm"
|
|
329
|
+
variant="tonal"
|
|
330
|
+
:aria-label="`${locale.configIncrease}: ${o.label}`"
|
|
331
|
+
:disabled="disabled || !available(g, o) || atMax(g)"
|
|
332
|
+
@click="step(g, o, 1)"
|
|
333
|
+
/>
|
|
334
|
+
</div>
|
|
335
|
+
</div>
|
|
336
|
+
<label
|
|
337
|
+
v-else
|
|
338
|
+
class="flex min-h-14 cursor-pointer items-center gap-2 py-1"
|
|
339
|
+
:class="{ 'cursor-default opacity-40': !available(g, o) || (typeOf(g) === 'multiple' && !isSelected(g, o) && atMax(g) && g.max !== 1) }"
|
|
340
|
+
>
|
|
341
|
+
<MRadio
|
|
342
|
+
v-if="typeOf(g) === 'single'"
|
|
343
|
+
:model-value="single(g) ?? null"
|
|
344
|
+
:value="o.value"
|
|
345
|
+
:disabled="disabled || !available(g, o)"
|
|
346
|
+
@update:model-value="pick(g, o)"
|
|
347
|
+
@click="single(g) === o.value && pick(g, o)"
|
|
348
|
+
/>
|
|
349
|
+
<MCheckbox
|
|
350
|
+
v-else
|
|
351
|
+
:model-value="isSelected(g, o)"
|
|
352
|
+
:disabled="disabled || !available(g, o) || (!isSelected(g, o) && atMax(g) && g.max !== 1)"
|
|
353
|
+
@update:model-value="pick(g, o)"
|
|
354
|
+
/>
|
|
355
|
+
<div class="min-w-0 flex-1">
|
|
356
|
+
<slot name="option" :group="g" :option="o" :selected="isSelected(g, o)" :available="available(g, o)">
|
|
357
|
+
<div class="text-body-large" :class="{ 'line-through': !available(g, o) }">{{ o.label }}</div>
|
|
358
|
+
<div v-if="o.description" class="text-body-medium text-on-surface-variant">{{ o.description }}</div>
|
|
359
|
+
</slot>
|
|
360
|
+
</div>
|
|
361
|
+
<span v-if="!available(g, o)" class="text-label-medium text-on-surface-variant">{{ locale.configUnavailable }}</span>
|
|
362
|
+
<span v-else-if="o.price" class="text-body-medium text-on-surface-variant tabular-nums">{{ money(o.price, true) }}</span>
|
|
363
|
+
</label>
|
|
364
|
+
</li>
|
|
365
|
+
</ul>
|
|
366
|
+
</section>
|
|
367
|
+
|
|
368
|
+
<div v-if="quantity !== null || actionLabel || $slots.action" class="mt-2 flex items-center gap-3">
|
|
369
|
+
<div v-if="quantity !== null" class="flex items-center gap-1 rounded-full border border-outline-variant p-1" role="group" :aria-label="locale.configQuantity">
|
|
370
|
+
<MIconButton icon="remove" size="sm" :aria-label="locale.configDecrease" :disabled="disabled || qty <= 1" @click="setQty(-1)" />
|
|
371
|
+
<span class="min-w-6 text-center text-title-medium tabular-nums" data-quantity>{{ qty }}</span>
|
|
372
|
+
<MIconButton icon="add" size="sm" :aria-label="locale.configIncrease" :disabled="disabled || qty >= maxQuantity" @click="setQty(1)" />
|
|
373
|
+
</div>
|
|
374
|
+
<slot name="action" :valid="valid" :total="total" :quantity="qty" :add="add">
|
|
375
|
+
<MButton v-if="actionLabel" class="flex-1" :disabled="disabled || !valid" data-action @click="add">
|
|
376
|
+
{{ actionLabel }} · <span class="tabular-nums">{{ money(total) }}</span>
|
|
377
|
+
</MButton>
|
|
378
|
+
</slot>
|
|
379
|
+
</div>
|
|
380
|
+
</div>
|
|
381
|
+
</template>
|
|
382
|
+
|
|
383
|
+
<style>
|
|
384
|
+
.m3-pc-swatch {
|
|
385
|
+
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-on-surface) 16%, transparent);
|
|
386
|
+
outline-offset: 3px;
|
|
387
|
+
}
|
|
388
|
+
.m3-pc-swatch.is-selected {
|
|
389
|
+
outline: 2px solid var(--color-primary);
|
|
390
|
+
}
|
|
391
|
+
.m3-pc-swatch:focus-visible {
|
|
392
|
+
outline: 3px solid var(--color-secondary);
|
|
393
|
+
}
|
|
394
|
+
.m3-pc-swatch.is-unavailable {
|
|
395
|
+
opacity: 0.5;
|
|
396
|
+
cursor: default;
|
|
397
|
+
}
|
|
398
|
+
.m3-pc-swatch.is-unavailable::after {
|
|
399
|
+
content: '';
|
|
400
|
+
position: absolute;
|
|
401
|
+
inset: 0;
|
|
402
|
+
background: linear-gradient(to top right, transparent calc(50% - 1px), var(--color-on-surface) 50%, transparent calc(50% + 1px));
|
|
403
|
+
}
|
|
404
|
+
.m3-pc-chip:disabled {
|
|
405
|
+
opacity: 0.38;
|
|
406
|
+
cursor: default;
|
|
407
|
+
}
|
|
408
|
+
.m3-pc-chip:focus-visible {
|
|
409
|
+
outline: 3px solid var(--color-secondary);
|
|
410
|
+
outline-offset: 2px;
|
|
411
|
+
}
|
|
412
|
+
</style>
|