@m3ui-vue/m3ui-vue 0.7.1 → 0.8.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/README.md +14 -6
- package/dist/{MMenuItem-xQ1x6-DH.js → MMenuItem-CDWfeU4F.js} +331 -252
- package/dist/MMenuItem-CDWfeU4F.js.map +1 -0
- package/dist/code-editor.d.ts +1 -0
- package/dist/code-editor.js +22 -7
- package/dist/code-editor.js.map +1 -1
- package/dist/components/MButton.vue.d.ts +7 -0
- package/dist/components/MCalendar.vue.d.ts +0 -1
- package/dist/components/MCard.vue.d.ts +2 -0
- package/dist/components/MCarousel.vue.d.ts +12 -14
- package/dist/components/MChatBubble.vue.d.ts +0 -1
- package/dist/components/MCircleProgressBar.vue.d.ts +0 -1
- package/dist/components/MCodeEditor.vue.d.ts +1 -1
- package/dist/components/MConfirmDialog.vue.d.ts +3 -0
- package/dist/components/MDatePicker.vue.d.ts +1 -3
- package/dist/components/MDatePickerModal.vue.d.ts +0 -1
- package/dist/components/MDateRangePicker.vue.d.ts +1 -3
- package/dist/components/MDateRangePickerModal.vue.d.ts +0 -1
- package/dist/components/MDialog.vue.d.ts +23 -7
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MKanban.vue.d.ts +1 -0
- package/dist/components/MListItem.vue.d.ts +11 -6
- package/dist/components/MNavigationRail.vue.d.ts +17 -1
- package/dist/components/MScheduler.vue.d.ts +0 -1
- package/dist/components/MSelect.vue.d.ts +1 -0
- package/dist/components/MShape.vue.d.ts +51 -0
- package/dist/components/MShortNavigationBar.vue.d.ts +34 -0
- package/dist/components/MSimpleCarousel.vue.d.ts +45 -0
- package/dist/components/MSwitch.vue.d.ts +8 -0
- package/dist/components/MTabs.vue.d.ts +3 -0
- package/dist/components/MToggleButton.vue.d.ts +29 -0
- package/dist/components/MTree.vue.d.ts +0 -1
- package/dist/components/MTreeTable.vue.d.ts +1 -0
- package/dist/index.d.ts +9 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +4387 -2525
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +1 -1
- package/dist/styles/palettes.css +659 -0
- package/dist/styles/theme.css +1 -0
- package/dist/styles.css +1 -1
- package/package.json +16 -1
- package/src/__tests__/MCarousel.test.ts +33 -0
- package/src/__tests__/MShape.test.ts +36 -0
- package/src/__tests__/MToggleButton.test.ts +27 -0
- package/src/__tests__/useColorPalette.test.ts +2 -2
- package/src/code-editor.ts +1 -0
- package/src/components/MAutocomplete.vue +40 -27
- package/src/components/MBadge.vue +1 -1
- package/src/components/MBottomSheet.vue +4 -4
- package/src/components/MButton.vue +51 -21
- package/src/components/MButtonGroup.vue +2 -2
- package/src/components/MCalendar.vue +9 -5
- package/src/components/MCard.vue +76 -11
- package/src/components/MCarousel.vue +123 -173
- package/src/components/MChatBubble.vue +0 -1
- package/src/components/MCheckbox.vue +58 -13
- package/src/components/MChip.vue +26 -6
- package/src/components/MCircleProgressBar.vue +7 -4
- package/src/components/MCodeEditor.vue +60 -9
- package/src/components/MColorPicker.vue +9 -8
- package/src/components/MColorPickerModal.vue +2 -2
- package/src/components/MCommandPalette.vue +1 -1
- package/src/components/MConfirmDialog.vue +4 -0
- package/src/components/MContextMenu.vue +27 -6
- package/src/components/MDatePicker.vue +23 -20
- package/src/components/MDatePickerModal.vue +14 -9
- package/src/components/MDateRangePicker.vue +24 -21
- package/src/components/MDateRangePickerModal.vue +12 -7
- package/src/components/MDialog.vue +103 -12
- package/src/components/MFab.vue +10 -7
- package/src/components/MFabMenu.vue +1 -1
- package/src/components/MIconButton.vue +41 -19
- package/src/components/MKanban.vue +5 -1
- package/src/components/MListItem.vue +35 -17
- package/src/components/MLoadingIndicator.vue +14 -7
- package/src/components/MMaskField.vue +14 -6
- package/src/components/MMenu.vue +32 -7
- package/src/components/MMenuItem.vue +2 -2
- package/src/components/MMultiAutocomplete.vue +46 -27
- package/src/components/MMultiSelect.vue +45 -23
- package/src/components/MNavigationBar.vue +5 -10
- package/src/components/MNavigationDrawer.vue +10 -9
- package/src/components/MNavigationRail.vue +335 -22
- package/src/components/MNumberField.vue +14 -6
- package/src/components/MOverlay.vue +1 -1
- package/src/components/MPinInput.vue +7 -4
- package/src/components/MProgressBar.vue +16 -10
- package/src/components/MRadio.vue +54 -12
- package/src/components/MScheduler.vue +10 -6
- package/src/components/MSearchBar.vue +8 -3
- package/src/components/MSegmentedButton.vue +14 -9
- package/src/components/MSelect.vue +49 -33
- package/src/components/MShape.vue +107 -0
- package/src/components/MShortNavigationBar.vue +113 -0
- package/src/components/MSideSheet.vue +1 -1
- package/src/components/MSimpleCarousel.vue +325 -0
- package/src/components/MSnackbar.vue +4 -4
- package/src/components/MSplitButton.vue +32 -17
- package/src/components/MSpotlightSearch.vue +1 -1
- package/src/components/MSwitch.vue +96 -18
- package/src/components/MTabs.vue +16 -12
- package/src/components/MTagInput.vue +33 -22
- package/src/components/MTextField.vue +14 -6
- package/src/components/MTimePicker.vue +9 -9
- package/src/components/MTimePickerModal.vue +16 -16
- package/src/components/MToggleButton.vue +188 -0
- package/src/components/MToolbar.vue +5 -3
- package/src/components/MTooltip.vue +4 -4
- package/src/components/MTopAppBar.vue +19 -7
- package/src/components/MTour.vue +1 -1
- package/src/components/MTree.vue +4 -2
- package/src/components/MTreeTable.vue +5 -1
- package/src/composables/useColorPalette.ts +10 -0
- package/src/index.ts +9 -1
- package/src/styles/palettes.css +659 -0
- package/src/styles/theme.css +1 -0
- package/dist/MMenuItem-xQ1x6-DH.js.map +0 -1
|
@@ -1,129 +1,124 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { ref, computed, onMounted, onBeforeUnmount,
|
|
2
|
+
import { ref, computed, onMounted, onBeforeUnmount, nextTick } from 'vue'
|
|
3
3
|
import MIcon from './MIcon.vue'
|
|
4
4
|
|
|
5
5
|
export interface CarouselItem {
|
|
6
6
|
src: string
|
|
7
7
|
alt?: string
|
|
8
8
|
label?: string
|
|
9
|
-
supportingText?: string
|
|
10
|
-
ratio?: number
|
|
11
9
|
}
|
|
12
10
|
|
|
11
|
+
/*
|
|
12
|
+
* Ported from the real M3 `HorizontalMultiBrowseCarousel` (Carousel.kt/Keylines.kt), not the
|
|
13
|
+
* "flat fixed-width items" look this library's old MCarousel had (now MSimpleCarousel). The real
|
|
14
|
+
* spec's signature behavior: one large "focal" item at rest, with neighbors progressively masked
|
|
15
|
+
* down toward a small "peek" size the further they are from the focal position — items grow/shrink
|
|
16
|
+
* continuously as you scroll, they're not just fixed-size slides.
|
|
17
|
+
*
|
|
18
|
+
* Real defaults ported exactly: minSmallItemWidth = MinSmallItemSize = 40dp, maxSmallItemWidth =
|
|
19
|
+
* MaxSmallItemSize = 56dp, itemSpacing = 0dp, targetSmallSize = clamp(largeSize/3, min, max), and
|
|
20
|
+
* the left-aligned focal convention (createLeftAlignedKeylineList — the focal item sits at the
|
|
21
|
+
* scroll container's left edge, not centered).
|
|
22
|
+
*
|
|
23
|
+
* Deliberately NOT ported: the real `Arrangement.findLowestCostArrangement` combinatorial search
|
|
24
|
+
* that decides exactly how many large/medium/small items fit a given width to the pixel. That's a
|
|
25
|
+
* large amount of code for a difference only visible at unusual width/item-count combinations —
|
|
26
|
+
* this uses a direct triangular falloff from the focal position instead, which converges to the
|
|
27
|
+
* same large-focal-item-with-shrinking-neighbors look for realistic carousels.
|
|
28
|
+
*/
|
|
13
29
|
const props = withDefaults(
|
|
14
30
|
defineProps<{
|
|
15
31
|
items: CarouselItem[]
|
|
16
|
-
|
|
32
|
+
/** Target width of the large, fully-visible focal item, in px (preferredItemWidth). */
|
|
33
|
+
itemWidth?: number
|
|
34
|
+
/** Spacing between item slots, in px. Real default (CarouselDefaults.ItemSpacing) is 0. */
|
|
35
|
+
itemSpacing?: number
|
|
36
|
+
/** Real default (CarouselDefaults.MinSmallItemSize) is 40. */
|
|
37
|
+
minSmallItemWidth?: number
|
|
38
|
+
/** Real default (CarouselDefaults.MaxSmallItemSize) is 56. */
|
|
39
|
+
maxSmallItemWidth?: number
|
|
17
40
|
height?: string
|
|
18
41
|
showArrows?: boolean
|
|
19
|
-
showIndicators?: boolean
|
|
20
42
|
autoplay?: boolean
|
|
21
43
|
interval?: number
|
|
22
|
-
gap?: number
|
|
23
|
-
visibleItems?: number
|
|
24
|
-
animated?: boolean
|
|
25
44
|
}>(),
|
|
26
45
|
{
|
|
27
|
-
|
|
28
|
-
|
|
46
|
+
itemWidth: 280,
|
|
47
|
+
itemSpacing: 0,
|
|
48
|
+
minSmallItemWidth: 40,
|
|
49
|
+
maxSmallItemWidth: 56,
|
|
50
|
+
height: '220px',
|
|
29
51
|
showArrows: true,
|
|
30
|
-
showIndicators: true,
|
|
31
52
|
autoplay: false,
|
|
32
53
|
interval: 5000,
|
|
33
|
-
gap: 8,
|
|
34
|
-
visibleItems: 3,
|
|
35
|
-
animated: false,
|
|
36
54
|
},
|
|
37
55
|
)
|
|
38
56
|
|
|
39
57
|
const emit = defineEmits<{ change: [index: number] }>()
|
|
40
58
|
|
|
41
|
-
const trackEl = ref<HTMLElement>()
|
|
42
|
-
const itemEls = ref<HTMLElement[]>([])
|
|
59
|
+
const trackEl = ref<HTMLElement | null>(null)
|
|
60
|
+
const itemEls = ref<(HTMLElement | null)[]>([])
|
|
61
|
+
const containerWidth = ref(0)
|
|
43
62
|
const activeIndex = ref(0)
|
|
44
|
-
const scrollPos = ref(0)
|
|
45
|
-
const isPageBased = computed(() => props.layout === 'multi-browse' || props.layout === 'uncontained')
|
|
46
63
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const track = trackEl.value
|
|
51
|
-
return Math.max(1, Math.ceil(track.scrollWidth / track.clientWidth))
|
|
52
|
-
})
|
|
64
|
+
function setItemRef(el: unknown, i: number) {
|
|
65
|
+
itemEls.value[i] = (el as HTMLElement) ?? null
|
|
66
|
+
}
|
|
53
67
|
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (track.scrollWidth <= track.clientWidth) return 0
|
|
59
|
-
const _ = scrollPos.value
|
|
60
|
-
return Math.round(track.scrollLeft / track.clientWidth)
|
|
68
|
+
const targetLarge = computed(() => Math.min(props.itemWidth, containerWidth.value || props.itemWidth))
|
|
69
|
+
const targetSmall = computed(() => {
|
|
70
|
+
const raw = targetLarge.value / 3
|
|
71
|
+
return Math.min(Math.max(raw, props.minSmallItemWidth), props.maxSmallItemWidth)
|
|
61
72
|
})
|
|
62
|
-
const itemTransforms = ref<string[]>([])
|
|
63
|
-
const imageTransforms = ref<string[]>([])
|
|
64
|
-
let autoTimer: ReturnType<typeof setInterval> | null = null
|
|
65
|
-
let rafId = 0
|
|
66
|
-
let scrollTimeout: ReturnType<typeof setTimeout> | null = null
|
|
67
73
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
const maskWidths = ref<number[]>([])
|
|
75
|
+
const imgOffsets = ref<number[]>([])
|
|
76
|
+
let rafId = 0
|
|
71
77
|
|
|
72
|
-
// ── Scroll handling (only transforms, never layout) ────────────
|
|
73
78
|
function onScroll() {
|
|
74
79
|
if (rafId) return
|
|
75
80
|
rafId = requestAnimationFrame(() => {
|
|
76
81
|
rafId = 0
|
|
77
|
-
|
|
82
|
+
updateMasks()
|
|
78
83
|
})
|
|
79
|
-
|
|
80
|
-
if (scrollTimeout) clearTimeout(scrollTimeout)
|
|
81
84
|
}
|
|
82
85
|
|
|
83
|
-
function
|
|
86
|
+
function updateMasks() {
|
|
84
87
|
if (!trackEl.value) return
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
const transforms: string[] = []
|
|
91
|
-
const imgTransforms: string[] = []
|
|
88
|
+
const trackLeft = trackEl.value.getBoundingClientRect().left
|
|
89
|
+
const large = targetLarge.value
|
|
90
|
+
const small = targetSmall.value
|
|
91
|
+
const widths: number[] = []
|
|
92
|
+
const offsets: number[] = []
|
|
92
93
|
let closest = 0
|
|
93
94
|
let closestDist = Infinity
|
|
94
95
|
|
|
95
|
-
const refX = props.layout === 'multi-browse' ? trackRect.left : centerX
|
|
96
|
-
|
|
97
96
|
for (let i = 0; i < itemEls.value.length; i++) {
|
|
98
97
|
const el = itemEls.value[i]
|
|
99
|
-
if (!el) {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
transforms.push('')
|
|
110
|
-
} else if (props.layout === 'uncontained' && props.animated) {
|
|
111
|
-
const s = 1 - norm * 0.12
|
|
112
|
-
transforms.push(`scale(${s})`)
|
|
113
|
-
imgTransforms.push('')
|
|
98
|
+
if (!el) { widths.push(large); offsets.push(0); continue }
|
|
99
|
+
const offset = el.getBoundingClientRect().left - trackLeft
|
|
100
|
+
|
|
101
|
+
let width: number
|
|
102
|
+
let imgOffset: number
|
|
103
|
+
if (offset <= 0) {
|
|
104
|
+
// Exiting (or resting) on the left: mask grows in from the left, keep the right portion
|
|
105
|
+
// of the image visible (matches the real maskStart clipping from the item's start edge).
|
|
106
|
+
width = Math.max(large + offset, small)
|
|
107
|
+
imgOffset = -(large - width)
|
|
114
108
|
} else {
|
|
115
|
-
|
|
116
|
-
|
|
109
|
+
// Upcoming on the right: mask shrinks from the right, keep the left portion visible.
|
|
110
|
+
width = Math.max(large - offset, small)
|
|
111
|
+
imgOffset = 0
|
|
117
112
|
}
|
|
113
|
+
widths.push(width)
|
|
114
|
+
offsets.push(imgOffset)
|
|
118
115
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
closest = i
|
|
122
|
-
}
|
|
116
|
+
const dist = Math.abs(offset)
|
|
117
|
+
if (dist < closestDist) { closestDist = dist; closest = i }
|
|
123
118
|
}
|
|
124
119
|
|
|
125
|
-
|
|
126
|
-
|
|
120
|
+
maskWidths.value = widths
|
|
121
|
+
imgOffsets.value = offsets
|
|
127
122
|
|
|
128
123
|
if (closest !== activeIndex.value) {
|
|
129
124
|
activeIndex.value = closest
|
|
@@ -131,107 +126,83 @@ function updateTransforms() {
|
|
|
131
126
|
}
|
|
132
127
|
}
|
|
133
128
|
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return `${(props.items[i]?.ratio ?? 1) * 260}px`
|
|
143
|
-
default:
|
|
144
|
-
return '80%'
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
129
|
+
// The item element's own width IS the animated mask width — not a fixed-width outer "slot"
|
|
130
|
+
// with a shrinking element inside it. That was the first cut of this component, and it was
|
|
131
|
+
// wrong: shrinking an inner element while its outer flex-item stayed at the full large width
|
|
132
|
+
// just left dead space where the flex item used to be, instead of letting flex naturally close
|
|
133
|
+
// the gap by reflowing the next item up against it (exactly what the real component's keyline
|
|
134
|
+
// masking achieves, just via a different mechanism — Compose positions items directly from
|
|
135
|
+
// keyline offsets rather than relying on flow layout, but the visual result needs to be the same:
|
|
136
|
+
// no gaps between items regardless of their current mask size).
|
|
148
137
|
function itemStyle(i: number) {
|
|
149
|
-
|
|
138
|
+
return {
|
|
139
|
+
width: `${maskWidths.value[i] ?? targetLarge.value}px`,
|
|
140
|
+
height: '100%',
|
|
150
141
|
flexShrink: '0',
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const t = itemTransforms.value[i]
|
|
154
|
-
if (t) {
|
|
155
|
-
style.transform = t
|
|
156
|
-
style.transition = 'transform 120ms ease-out'
|
|
142
|
+
overflow: 'hidden',
|
|
143
|
+
position: 'relative' as const,
|
|
157
144
|
}
|
|
158
|
-
return style
|
|
159
145
|
}
|
|
160
146
|
|
|
161
147
|
function imgStyle(i: number) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
148
|
+
return {
|
|
149
|
+
width: `${targetLarge.value}px`,
|
|
150
|
+
height: '100%',
|
|
151
|
+
position: 'absolute' as const,
|
|
152
|
+
left: `${imgOffsets.value[i] ?? 0}px`,
|
|
153
|
+
top: '0',
|
|
154
|
+
}
|
|
165
155
|
}
|
|
166
156
|
|
|
167
|
-
// ── Navigation ─────────────────────────────────────────────────
|
|
168
157
|
function scrollToItem(index: number) {
|
|
169
158
|
const el = itemEls.value[index]
|
|
170
159
|
if (!el || !trackEl.value) return
|
|
171
|
-
|
|
172
|
-
const scrollLeft = el.offsetLeft - (track.clientWidth - el.offsetWidth) / 2
|
|
173
|
-
track.scrollTo({ left: scrollLeft, behavior: 'smooth' })
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function scrollToPage(page: number) {
|
|
177
|
-
if (!trackEl.value) return
|
|
178
|
-
const track = trackEl.value
|
|
179
|
-
track.scrollTo({ left: page * track.clientWidth, behavior: 'smooth' })
|
|
160
|
+
trackEl.value.scrollTo({ left: el.offsetLeft, behavior: 'smooth' })
|
|
180
161
|
}
|
|
181
162
|
|
|
182
163
|
function next() {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
trackEl.value.scrollBy({ left: trackEl.value.clientWidth, behavior: 'smooth' })
|
|
186
|
-
} else {
|
|
187
|
-
const i = activeIndex.value < props.items.length - 1 ? activeIndex.value + 1 : 0
|
|
188
|
-
scrollToItem(i)
|
|
189
|
-
}
|
|
164
|
+
const i = activeIndex.value < props.items.length - 1 ? activeIndex.value + 1 : 0
|
|
165
|
+
scrollToItem(i)
|
|
190
166
|
}
|
|
191
|
-
|
|
192
167
|
function prev() {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
trackEl.value.scrollBy({ left: -trackEl.value.clientWidth, behavior: 'smooth' })
|
|
196
|
-
} else {
|
|
197
|
-
const i = activeIndex.value > 0 ? activeIndex.value - 1 : props.items.length - 1
|
|
198
|
-
scrollToItem(i)
|
|
199
|
-
}
|
|
168
|
+
const i = activeIndex.value > 0 ? activeIndex.value - 1 : props.items.length - 1
|
|
169
|
+
scrollToItem(i)
|
|
200
170
|
}
|
|
201
171
|
|
|
172
|
+
function onKeydown(e: KeyboardEvent) {
|
|
173
|
+
if (e.key === 'ArrowRight') next()
|
|
174
|
+
else if (e.key === 'ArrowLeft') prev()
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
let autoTimer: ReturnType<typeof setInterval> | null = null
|
|
202
178
|
function startAutoplay() {
|
|
203
179
|
stopAutoplay()
|
|
204
|
-
if (props.autoplay && props.items.length > 1)
|
|
205
|
-
autoTimer = setInterval(next, props.interval)
|
|
206
|
-
}
|
|
180
|
+
if (props.autoplay && props.items.length > 1) autoTimer = setInterval(next, props.interval)
|
|
207
181
|
}
|
|
208
|
-
|
|
209
182
|
function stopAutoplay() {
|
|
210
183
|
if (autoTimer) { clearInterval(autoTimer); autoTimer = null }
|
|
211
184
|
}
|
|
212
185
|
|
|
213
|
-
|
|
214
|
-
if (e.key === 'ArrowRight') next()
|
|
215
|
-
else if (e.key === 'ArrowLeft') prev()
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const trackPadding = computed(() => {
|
|
219
|
-
if (props.layout === 'hero') return '0 24px'
|
|
220
|
-
if (props.layout === 'uncontained') return '0 24px'
|
|
221
|
-
return '0'
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
watch(() => props.autoplay, startAutoplay)
|
|
186
|
+
let resizeObserver: ResizeObserver | null = null
|
|
225
187
|
onMounted(() => {
|
|
188
|
+
if (trackEl.value) {
|
|
189
|
+
containerWidth.value = trackEl.value.clientWidth
|
|
190
|
+
resizeObserver = new ResizeObserver(() => {
|
|
191
|
+
if (trackEl.value) containerWidth.value = trackEl.value.clientWidth
|
|
192
|
+
updateMasks()
|
|
193
|
+
})
|
|
194
|
+
resizeObserver.observe(trackEl.value)
|
|
195
|
+
}
|
|
196
|
+
nextTick(updateMasks)
|
|
226
197
|
startAutoplay()
|
|
227
|
-
nextTick(() => updateTransforms())
|
|
228
198
|
})
|
|
229
199
|
onBeforeUnmount(() => {
|
|
230
200
|
stopAutoplay()
|
|
231
201
|
if (rafId) cancelAnimationFrame(rafId)
|
|
202
|
+
resizeObserver?.disconnect()
|
|
232
203
|
})
|
|
233
204
|
|
|
234
|
-
defineExpose({ next, prev, scrollToItem
|
|
205
|
+
defineExpose({ next, prev, scrollToItem })
|
|
235
206
|
</script>
|
|
236
207
|
|
|
237
208
|
<template>
|
|
@@ -245,30 +216,27 @@ defineExpose({ next, prev, scrollToItem, scrollToPage })
|
|
|
245
216
|
<div
|
|
246
217
|
ref="trackEl"
|
|
247
218
|
class="carousel-track flex overflow-x-auto"
|
|
248
|
-
:
|
|
249
|
-
:style="{ height, gap: `${gap}px`, padding: trackPadding }"
|
|
219
|
+
:style="{ height, gap: `${itemSpacing}px` }"
|
|
250
220
|
@scroll.passive="onScroll"
|
|
251
221
|
>
|
|
252
222
|
<div
|
|
253
223
|
v-for="(item, i) in items"
|
|
254
224
|
:key="i"
|
|
255
225
|
:ref="(el) => setItemRef(el, i)"
|
|
256
|
-
class="
|
|
226
|
+
class="rounded-2xl"
|
|
257
227
|
:style="itemStyle(i)"
|
|
258
228
|
>
|
|
259
229
|
<img
|
|
260
230
|
:src="item.src"
|
|
261
231
|
:alt="item.alt ?? item.label ?? ''"
|
|
262
|
-
class="pointer-events-none
|
|
232
|
+
class="pointer-events-none object-cover"
|
|
263
233
|
:style="imgStyle(i)"
|
|
264
234
|
/>
|
|
265
|
-
|
|
266
235
|
<div
|
|
267
|
-
v-if="item.label
|
|
268
|
-
class="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/70 via-black/30 to-transparent px-
|
|
236
|
+
v-if="item.label"
|
|
237
|
+
class="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/70 via-black/30 to-transparent px-4 pb-3 pt-8"
|
|
269
238
|
>
|
|
270
|
-
<p
|
|
271
|
-
<p v-if="item.supportingText" class="mt-0.5 text-body-small text-white/80">{{ item.supportingText }}</p>
|
|
239
|
+
<p class="text-title-medium font-medium text-white">{{ item.label }}</p>
|
|
272
240
|
</div>
|
|
273
241
|
</div>
|
|
274
242
|
</div>
|
|
@@ -289,22 +257,7 @@ defineExpose({ next, prev, scrollToItem, scrollToPage })
|
|
|
289
257
|
<MIcon name="chevron_right" :size="24" />
|
|
290
258
|
</button>
|
|
291
259
|
</template>
|
|
292
|
-
|
|
293
|
-
</div>
|
|
294
|
-
|
|
295
|
-
<div
|
|
296
|
-
v-if="showIndicators && totalPages > 1"
|
|
297
|
-
class="flex justify-center gap-1.5 pt-3"
|
|
298
|
-
>
|
|
299
|
-
<button
|
|
300
|
-
v-for="p in totalPages"
|
|
301
|
-
:key="p"
|
|
302
|
-
type="button"
|
|
303
|
-
class="h-2 cursor-pointer rounded-full transition-all duration-300"
|
|
304
|
-
:class="(p - 1) === activePage ? 'w-5 bg-on-surface' : 'w-2 bg-on-surface/30 hover:bg-on-surface/50'"
|
|
305
|
-
@click="isPageBased ? scrollToPage(p - 1) : scrollToItem(p - 1)"
|
|
306
|
-
/>
|
|
307
|
-
</div>
|
|
260
|
+
</div>
|
|
308
261
|
</template>
|
|
309
262
|
|
|
310
263
|
<style scoped>
|
|
@@ -316,10 +269,7 @@ defineExpose({ next, prev, scrollToItem, scrollToPage })
|
|
|
316
269
|
.carousel-track::-webkit-scrollbar {
|
|
317
270
|
display: none;
|
|
318
271
|
}
|
|
319
|
-
.
|
|
320
|
-
scroll-snap-align: center;
|
|
321
|
-
}
|
|
322
|
-
.snap-start > * {
|
|
272
|
+
.carousel-track > * {
|
|
323
273
|
scroll-snap-align: start;
|
|
324
274
|
}
|
|
325
275
|
</style>
|
|
@@ -14,39 +14,84 @@ withDefaults(
|
|
|
14
14
|
|
|
15
15
|
const emit = defineEmits<{ "update:modelValue": [boolean] }>();
|
|
16
16
|
|
|
17
|
-
// Same 4 named colors + fallback shape as MRadio's checkedColor map.
|
|
17
|
+
// Same 4 named colors + fallback shape as MRadio's checkedColor map. M3's real
|
|
18
|
+
// CheckboxTokens only define Primary (SelectedContainerColor) and Error (as an error
|
|
19
|
+
// STATE, not a color variant) — secondary/tertiary are a deliberate library extension on
|
|
20
|
+
// top of the spec, same status as MSlider's `color`/`icon` props.
|
|
18
21
|
const checkedClasses: Record<string, string> = {
|
|
19
22
|
primary: "border-primary bg-primary text-on-primary",
|
|
20
23
|
secondary: "border-secondary bg-secondary text-on-secondary",
|
|
21
24
|
tertiary: "border-tertiary bg-tertiary text-on-tertiary",
|
|
22
25
|
error: "border-error bg-error text-on-error",
|
|
23
26
|
};
|
|
27
|
+
|
|
28
|
+
// Just the fill color, reused for the hover/press state layer's tint below.
|
|
29
|
+
const checkedBgClasses: Record<string, string> = {
|
|
30
|
+
primary: "bg-primary",
|
|
31
|
+
secondary: "bg-secondary",
|
|
32
|
+
tertiary: "bg-tertiary",
|
|
33
|
+
error: "bg-error",
|
|
34
|
+
};
|
|
24
35
|
</script>
|
|
25
36
|
|
|
26
37
|
<template>
|
|
27
38
|
<label
|
|
28
|
-
class="inline-flex items-center gap-2 select-none"
|
|
39
|
+
class="group inline-flex items-center gap-2 select-none"
|
|
29
40
|
:class="disabled ? 'cursor-not-allowed' : 'cursor-pointer'"
|
|
30
41
|
>
|
|
31
|
-
|
|
42
|
+
<!--
|
|
43
|
+
CheckboxTokens.StateLayerSize = 40dp (was 48px), StateLayerShape = CornerFull. The
|
|
44
|
+
negative margin cancels the touch target's own overhang past the visible 18px box
|
|
45
|
+
(40-18)/2 = 11px per side, so it doesn't push the label text over.
|
|
46
|
+
-->
|
|
47
|
+
<span class="relative -m-[11px] inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-full">
|
|
48
|
+
<!--
|
|
49
|
+
Input must stay nested INSIDE this `relative` span (a true sibling of the state-layer
|
|
50
|
+
/focus-ring spans below, satisfying `peer-*`'s sibling-combinator requirement, but not
|
|
51
|
+
hoisted all the way up to be a direct child of <label>): a sr-only, `position: absolute`
|
|
52
|
+
input with no nearby positioned ancestor made the browser's native focus-scroll
|
|
53
|
+
algorithm treat a distant `overflow: hidden` ancestor as the thing to scroll into view
|
|
54
|
+
on click, which — since that ancestor wasn't meant to scroll at all — blew out to its
|
|
55
|
+
max scrollTop and pushed the entire page off-screen. Real bug, found by testing in the
|
|
56
|
+
docs site; MSwitch's input, nested the same way this one now is again, never had it.
|
|
57
|
+
-->
|
|
58
|
+
<input
|
|
59
|
+
type="checkbox"
|
|
60
|
+
class="peer sr-only"
|
|
61
|
+
:checked="modelValue"
|
|
62
|
+
:disabled="disabled"
|
|
63
|
+
@change="emit('update:modelValue', !modelValue)"
|
|
64
|
+
/>
|
|
65
|
+
<!--
|
|
66
|
+
Hover/press state layer (8%/12%), tinted with the checkbox's own indicator color
|
|
67
|
+
(primary/color prop when checked, on-surface when not) — same `before:`-overlay
|
|
68
|
+
spirit as MButton/MCard/MIconButton, just a real sibling span here since the parent
|
|
69
|
+
span is already used for centering/sizing. `group-*` (not a plain `hover:`) so
|
|
70
|
+
hovering anywhere over the row (including the label text) triggers it, not just
|
|
71
|
+
the small 18px glyph itself.
|
|
72
|
+
-->
|
|
73
|
+
<span
|
|
74
|
+
v-if="!disabled"
|
|
75
|
+
class="pointer-events-none absolute inset-0 rounded-full opacity-0 transition-opacity duration-150 group-hover:opacity-[0.08] group-active:opacity-[0.12]"
|
|
76
|
+
:class="modelValue || indeterminate ? checkedBgClasses[color] : 'bg-on-surface'"
|
|
77
|
+
/>
|
|
78
|
+
<!-- Keyboard-focus ring (FocusIndicatorColor = secondary) -->
|
|
32
79
|
<span
|
|
33
|
-
|
|
80
|
+
v-if="!disabled"
|
|
81
|
+
class="pointer-events-none absolute inset-0 rounded-full ring-0 ring-secondary transition-[box-shadow] duration-150 peer-focus-visible:ring-2"
|
|
82
|
+
/>
|
|
83
|
+
|
|
84
|
+
<span
|
|
85
|
+
class="relative inline-flex h-4.5 w-4.5 items-center justify-center rounded-[2px] border-2 transition-colors"
|
|
34
86
|
:class="
|
|
35
87
|
disabled
|
|
36
88
|
? (modelValue || indeterminate ? 'border-on-surface/38 bg-on-surface/38 text-surface' : 'border-on-surface/38 text-transparent')
|
|
37
|
-
: (modelValue || indeterminate ? checkedClasses[color] : 'border-on-surface-variant text-transparent')
|
|
89
|
+
: (modelValue || indeterminate ? checkedClasses[color] : 'border-on-surface-variant text-transparent group-hover:border-on-surface group-active:border-on-surface')
|
|
38
90
|
"
|
|
39
91
|
>
|
|
40
|
-
<input
|
|
41
|
-
type="checkbox"
|
|
42
|
-
class="sr-only"
|
|
43
|
-
:checked="modelValue"
|
|
44
|
-
:disabled="disabled"
|
|
45
|
-
@change="emit('update:modelValue', !modelValue)"
|
|
46
|
-
/>
|
|
47
92
|
<MIcon
|
|
48
93
|
:name="indeterminate ? 'remove' : 'check'"
|
|
49
|
-
:size="
|
|
94
|
+
:size="18"
|
|
50
95
|
class="transition-[opacity,transform] duration-150"
|
|
51
96
|
:class="modelValue || indeterminate ? 'scale-100 opacity-100' : 'scale-0 opacity-0'"
|
|
52
97
|
/>
|
package/src/components/MChip.vue
CHANGED
|
@@ -39,12 +39,13 @@ const customStyle = computed(() => {
|
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
// M3 disabled tokens: label/icon always at 38% on-surface. Container: neutral/unselected
|
|
42
|
-
// chips are outline-only (no fill), so the outline fades to
|
|
43
|
-
// filled container, so the fill fades to 12%
|
|
42
|
+
// chips are outline-only (no fill), so the outline fades to 10% (UnselectedDisabledOutlineOpacity);
|
|
43
|
+
// every other tone/selected chip has a filled container, so the fill fades to 12%
|
|
44
|
+
// (SelectedDisabledContainerOpacity) instead, with any border dropped.
|
|
44
45
|
const toneClasses = computed(() => {
|
|
45
46
|
if (props.disabled) {
|
|
46
47
|
if (props.tone === 'neutral' && !props.selected && !isCustomColor.value) {
|
|
47
|
-
return 'border border-on-surface/
|
|
48
|
+
return 'border border-on-surface/10 bg-transparent text-on-surface/38'
|
|
48
49
|
}
|
|
49
50
|
return 'border border-transparent bg-on-surface/12 text-on-surface/38'
|
|
50
51
|
}
|
|
@@ -52,7 +53,8 @@ const toneClasses = computed(() => {
|
|
|
52
53
|
return 'border border-transparent bg-[var(--chip-bg)] text-[var(--chip-color)]'
|
|
53
54
|
}
|
|
54
55
|
if (props.tone === 'neutral' && !props.selected) {
|
|
55
|
-
|
|
56
|
+
// ChipsTokens.UnselectedOutlineColor = OutlineVariant, not Outline
|
|
57
|
+
return 'border border-outline-variant bg-transparent text-on-surface-variant'
|
|
56
58
|
}
|
|
57
59
|
const map: Record<string, string> = {
|
|
58
60
|
neutral: 'border border-transparent bg-secondary-container text-on-secondary-container',
|
|
@@ -64,6 +66,23 @@ const toneClasses = computed(() => {
|
|
|
64
66
|
}
|
|
65
67
|
return map[props.tone ?? 'neutral'] ?? map.neutral
|
|
66
68
|
})
|
|
69
|
+
|
|
70
|
+
// ChipsTokens: UnselectedShape = CornerMedium (12dp), SelectedShape = CornerFull — a chip
|
|
71
|
+
// becomes a full pill once selected, it doesn't keep the same small corner radius.
|
|
72
|
+
const shapeClass = computed(() => props.selected ? 'rounded-full' : 'rounded-md')
|
|
73
|
+
|
|
74
|
+
// Hover/press state layer (8%/12%, ChipsTokens has no dedicated token but this matches the
|
|
75
|
+
// universal M3 state-layer convention used everywhere else in this library) via the same
|
|
76
|
+
// `before:`-overlay technique as MButton/MCard/MIconButton — a plain `hover:bg-*` would just
|
|
77
|
+
// replace a filled/selected chip's own background outright instead of overlaying on top of
|
|
78
|
+
// it. `ring-inset` on the focus ring (FocusedIndicatorColor = secondary) because `overflow-
|
|
79
|
+
// hidden` on this same element (needed to clip the state-layer to the chip's shape) would
|
|
80
|
+
// otherwise clip an outset ring's box-shadow too.
|
|
81
|
+
const interactiveClasses =
|
|
82
|
+
"relative cursor-pointer before:content-[''] before:pointer-events-none before:absolute before:inset-0 " +
|
|
83
|
+
'before:bg-current before:opacity-0 before:transition-opacity before:duration-150 ' +
|
|
84
|
+
'hover:before:opacity-[0.08] active:before:opacity-[0.12] ' +
|
|
85
|
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-secondary'
|
|
67
86
|
</script>
|
|
68
87
|
|
|
69
88
|
<template>
|
|
@@ -71,10 +90,11 @@ const toneClasses = computed(() => {
|
|
|
71
90
|
:is="clickable ? 'button' : 'span'"
|
|
72
91
|
:type="clickable ? 'button' : undefined"
|
|
73
92
|
:disabled="clickable && disabled ? true : undefined"
|
|
74
|
-
class="inline-flex h-8 items-center gap-1.5
|
|
93
|
+
class="inline-flex h-8 items-center gap-1.5 overflow-hidden px-3 text-label-large transition-colors"
|
|
75
94
|
:class="[
|
|
95
|
+
shapeClass,
|
|
76
96
|
toneClasses,
|
|
77
|
-
clickable && !disabled ?
|
|
97
|
+
clickable && !disabled ? interactiveClasses : '',
|
|
78
98
|
disabled ? 'cursor-not-allowed' : '',
|
|
79
99
|
]"
|
|
80
100
|
:style="customStyle"
|
|
@@ -14,13 +14,16 @@ const props = withDefaults(
|
|
|
14
14
|
{
|
|
15
15
|
color: "primary",
|
|
16
16
|
variant: "wavy",
|
|
17
|
-
|
|
18
|
-
thickness: 3,
|
|
17
|
+
thickness: 4,
|
|
19
18
|
},
|
|
20
19
|
);
|
|
21
20
|
|
|
22
21
|
const clampedValue = computed(() => Math.min(100, Math.max(0, props.value ?? 0)));
|
|
23
22
|
|
|
23
|
+
// CircularProgressIndicatorTokens: Size=40dp (circle) / WaveSize=48dp (wavy) — the wavy
|
|
24
|
+
// variant's default is intentionally larger to fit the wave amplitude without clipping.
|
|
25
|
+
const effectiveSize = computed(() => props.size ?? (props.variant === "wavy" ? 48 : 40));
|
|
26
|
+
|
|
24
27
|
const svgColorMap: Record<"primary" | "secondary" | "tertiary" | "error", { fill: string; track: string }> = {
|
|
25
28
|
primary: { fill: "var(--color-primary)", track: "var(--color-primary-container)" },
|
|
26
29
|
secondary: { fill: "var(--color-secondary)", track: "var(--color-secondary-container)" },
|
|
@@ -239,7 +242,7 @@ const maskId = useId();
|
|
|
239
242
|
|
|
240
243
|
<div class="relative">
|
|
241
244
|
<svg
|
|
242
|
-
:width="
|
|
245
|
+
:width="effectiveSize" :height="effectiveSize"
|
|
243
246
|
viewBox="0 0 100 100"
|
|
244
247
|
fill="none"
|
|
245
248
|
role="progressbar"
|
|
@@ -315,7 +318,7 @@ const maskId = useId();
|
|
|
315
318
|
text-anchor="middle" dominant-baseline="middle"
|
|
316
319
|
:style="{
|
|
317
320
|
fill: svgColor.fill,
|
|
318
|
-
fontSize: `${
|
|
321
|
+
fontSize: `${effectiveSize < 60 ? 11 : 14}px`,
|
|
319
322
|
fontWeight: '600',
|
|
320
323
|
fontFamily: 'Roboto, sans-serif',
|
|
321
324
|
}"
|