@m3ui-vue/m3ui-vue 1.1.3 → 1.2.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/README.md +1 -1
- package/dist/API.md +579 -40
- package/dist/MMenuItem-DI351kIf.js +929 -0
- package/dist/MMenuItem-DI351kIf.js.map +1 -0
- package/dist/MSlider-BnEy5ieZ.js +1500 -0
- package/dist/MSlider-BnEy5ieZ.js.map +1 -0
- package/dist/MTextField-BBmkaIbO.js +633 -0
- package/dist/MTextField-BBmkaIbO.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +83 -49
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAnimatedNumber.vue.d.ts +3 -1
- package/dist/components/MButton.vue.d.ts +9 -1
- package/dist/components/MButtonGroup.vue.d.ts +40 -31
- package/dist/components/MCarousel.vue.d.ts +2 -0
- package/dist/components/MChart.vue.d.ts +6 -0
- package/dist/components/MCircleProgressBar.vue.d.ts +5 -3
- package/dist/components/MContainerTransform.vue.d.ts +59 -0
- package/dist/components/MContextMenu.vue.d.ts +2 -2
- package/dist/components/MCopyButton.vue.d.ts +1 -1
- package/dist/components/MDialog.vue.d.ts +8 -5
- package/dist/components/MExportButton.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MFabMenu.vue.d.ts +1 -1
- package/dist/components/MFlex.vue.d.ts +1 -1
- package/dist/components/MIconButton.vue.d.ts +15 -1
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MListItem.vue.d.ts +5 -5
- package/dist/components/MMap.vue.d.ts +20 -2
- package/dist/components/MMapBaseLayers.vue.d.ts +3 -0
- package/dist/components/MMapFilter.vue.d.ts +3 -0
- package/dist/components/MMapLayers.vue.d.ts +3 -0
- package/dist/components/MMenu.vue.d.ts +2 -2
- package/dist/components/MMenuItem.vue.d.ts +7 -3
- package/dist/components/MNavigationDrawer.vue.d.ts +13 -2
- package/dist/components/MNavigationRail.vue.d.ts +1 -1
- package/dist/components/MOverlay.vue.d.ts +12 -1
- package/dist/components/MProgressBar.vue.d.ts +5 -3
- package/dist/components/MPullToRefresh.vue.d.ts +7 -2
- package/dist/components/MRichTextEditor.vue.d.ts +7 -1
- package/dist/components/MSearchField.vue.d.ts +58 -0
- package/dist/components/MSegmentedButton.vue.d.ts +31 -23
- package/dist/components/MSimpleCarousel.vue.d.ts +2 -0
- package/dist/components/MSkeleton.vue.d.ts +6 -3
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +1 -1
- package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +1 -1
- package/dist/components/MTextField.vue.d.ts +5 -1
- package/dist/components/MTimeline.vue.d.ts +85 -22
- package/dist/components/MToolbar.vue.d.ts +32 -5
- package/dist/components/MTooltip.vue.d.ts +1 -1
- package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
- package/dist/components/_MToolbarFab.vue.d.ts +16 -0
- package/dist/composables/_containerTransform.d.ts +48 -0
- package/dist/composables/_mapStyle.d.ts +13 -0
- package/dist/composables/_themeTransition.d.ts +2 -0
- package/dist/composables/_tooltipTrigger.d.ts +22 -0
- package/dist/composables/_useMenuNav.d.ts +28 -0
- package/dist/composables/useAutoGrow.d.ts +21 -0
- package/dist/composables/useColorPalette.d.ts +1 -1
- package/dist/composables/useContainerTransform.d.ts +30 -0
- package/dist/composables/useLocale.d.ts +6 -0
- package/dist/composables/useMap.d.ts +19 -3
- package/dist/composables/useMapFilter.d.ts +4 -1
- package/dist/composables/useMapLayers.d.ts +5 -2
- package/dist/composables/useScrollReveal.d.ts +44 -0
- package/dist/composables/useThemeTokens.d.ts +21 -0
- package/dist/composables/viewportHints.d.ts +27 -0
- package/dist/directives/vClickOutside.d.ts +25 -0
- package/dist/directives/vFocusRing.d.ts +22 -0
- package/dist/directives/vLongPress.d.ts +27 -0
- package/dist/directives/vReveal.d.ts +10 -0
- package/dist/directives/vScrollElevation.d.ts +31 -0
- package/dist/directives/vSkeleton.d.ts +19 -0
- package/dist/directives/vStateLayer.d.ts +20 -0
- package/dist/directives/vSwipe.d.ts +45 -0
- package/dist/directives/vTooltip.d.ts +23 -0
- package/dist/index.d.ts +31 -1
- package/dist/locales/index.js +35 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7692 -6273
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +1 -1
- package/dist/map.js +823 -793
- package/dist/map.js.map +1 -1
- package/dist/motion-DZiXG09o.js +150 -0
- package/dist/motion-DZiXG09o.js.map +1 -0
- package/dist/plugin.d.ts +24 -0
- package/dist/rich-text-editor.js +20 -16
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles/theme.css +63 -0
- package/dist/styles.css +1 -1
- package/dist/{useLocale-SfQHnJfp.js → useLocale-JYxDDeXC.js} +6 -2
- package/dist/useLocale-JYxDDeXC.js.map +1 -0
- package/dist/useThemeTokens-Bv-Uv8eX.js +135 -0
- package/dist/useThemeTokens-Bv-Uv8eX.js.map +1 -0
- package/package.json +2 -1
- package/src/__tests__/MAnimatedNumber.test.ts +24 -2
- package/src/__tests__/MButton.test.ts +22 -0
- package/src/__tests__/MCarousel.test.ts +9 -0
- package/src/__tests__/MChart.test.ts +77 -5
- package/src/__tests__/MContainerTransform.test.ts +279 -0
- package/src/__tests__/MDialog.test.ts +27 -0
- package/src/__tests__/MIconButton.test.ts +33 -0
- package/src/__tests__/MListItemExpandable.test.ts +48 -0
- package/src/__tests__/MListItemShape.test.ts +9 -6
- package/src/__tests__/MListKeyboard.test.ts +90 -0
- package/src/__tests__/MMap.test.ts +53 -1
- package/src/__tests__/MMapLayers.test.ts +46 -2
- package/src/__tests__/MMapTools.test.ts +2 -1
- package/src/__tests__/MMenu.test.ts +104 -1
- package/src/__tests__/MMenuItem.test.ts +18 -0
- package/src/__tests__/MNavigationDrawer.test.ts +80 -0
- package/src/__tests__/MNavigationRail.test.ts +33 -0
- package/src/__tests__/MOverlay.test.ts +49 -0
- package/src/__tests__/MProgressBar.test.ts +41 -0
- package/src/__tests__/MPullToRefresh.test.ts +33 -0
- package/src/__tests__/MRichTextEditor.test.ts +22 -0
- package/src/__tests__/MSearchField.test.ts +71 -0
- package/src/__tests__/MSkeleton.test.ts +38 -0
- package/src/__tests__/MSlider.test.ts +161 -0
- package/src/__tests__/MTimeline.test.ts +238 -0
- package/src/__tests__/MToolbar.test.ts +157 -0
- package/src/__tests__/_fakeMaplibre.ts +3 -1
- package/src/__tests__/attrsFallthrough.test.ts +9 -0
- package/src/__tests__/escapeStack.test.ts +93 -0
- package/src/__tests__/hydration.test.ts +25 -0
- package/src/__tests__/ssr.test.ts +21 -2
- package/src/__tests__/useAutoGrow.test.ts +103 -0
- package/src/__tests__/useScrollReveal.test.ts +102 -0
- package/src/__tests__/useThemeTokens.test.ts +114 -0
- package/src/__tests__/vClickOutside.test.ts +82 -0
- package/src/__tests__/vFocusRing.test.ts +36 -0
- package/src/__tests__/vLongPress.test.ts +81 -0
- package/src/__tests__/vScrollElevation.test.ts +89 -0
- package/src/__tests__/vSkeleton.test.ts +48 -0
- package/src/__tests__/vStateLayer.test.ts +53 -0
- package/src/__tests__/vSwipe.test.ts +93 -0
- package/src/__tests__/vTooltip.test.ts +95 -0
- package/src/__tests__/viewportHints.test.ts +41 -0
- package/src/components/MAnimatedNumber.vue +32 -6
- package/src/components/MAutocomplete.vue +5 -0
- package/src/components/MBottomSheet.vue +4 -1
- package/src/components/MButton.vue +19 -3
- package/src/components/MButtonGroup.vue +22 -17
- package/src/components/MCarousel.vue +7 -1
- package/src/components/MChart.vue +74 -34
- package/src/components/MCircleProgressBar.vue +14 -9
- package/src/components/MCommandPalette.vue +3 -2
- package/src/components/MContainerTransform.vue +321 -0
- package/src/components/MContextMenu.vue +19 -60
- package/src/components/MDialog.vue +31 -6
- package/src/components/MDragDropList.vue +2 -0
- package/src/components/MFab.vue +10 -5
- package/src/components/MIconButton.vue +43 -2
- package/src/components/MKanban.vue +2 -0
- package/src/components/MLightbox.vue +7 -2
- package/src/components/MList.vue +26 -2
- package/src/components/MListItem.vue +138 -84
- package/src/components/MMap.vue +38 -5
- package/src/components/MMapBaseLayers.vue +7 -3
- package/src/components/MMapFilter.vue +7 -4
- package/src/components/MMapGeoJson.vue +1 -1
- package/src/components/MMapLayers.vue +6 -2
- package/src/components/MMapMeasure.vue +5 -2
- package/src/components/MMenu.vue +18 -59
- package/src/components/MMenuItem.vue +11 -2
- package/src/components/MMultiAutocomplete.vue +5 -0
- package/src/components/MNavigationDrawer.vue +96 -11
- package/src/components/MNavigationRail.vue +44 -25
- package/src/components/MOverlay.vue +32 -13
- package/src/components/MProgressBar.vue +25 -27
- package/src/components/MPullToRefresh.vue +20 -1
- package/src/components/MRichTextEditor.vue +19 -5
- package/src/components/MSearchBar.vue +5 -0
- package/src/components/MSearchField.vue +142 -0
- package/src/components/MSegmentedButton.vue +19 -17
- package/src/components/MSelect.vue +10 -1
- package/src/components/MSideSheet.vue +5 -2
- package/src/components/MSimpleCarousel.vue +10 -1
- package/src/components/MSkeleton.vue +30 -8
- package/src/components/MSlider.vue +161 -42
- package/src/components/MSpotlightSearch.vue +3 -2
- package/src/components/MTextField.vue +15 -2
- package/src/components/MTimeline.vue +370 -81
- package/src/components/MToolbar.vue +256 -15
- package/src/components/MTooltip.vue +20 -152
- package/src/components/_MDrawerItemList.vue +25 -6
- package/src/components/_MToolbarFab.vue +14 -0
- package/src/composables/_containerTransform.ts +179 -0
- package/src/composables/_mapStyle.ts +45 -0
- package/src/composables/_themeTransition.ts +2 -0
- package/src/composables/_tooltipTrigger.ts +184 -0
- package/src/composables/_useEscapeStack.ts +2 -0
- package/src/composables/_useMenuNav.ts +209 -0
- package/src/composables/useAutoGrow.ts +78 -0
- package/src/composables/useContainerTransform.ts +59 -0
- package/src/composables/useLocale.ts +10 -0
- package/src/composables/useMap.ts +43 -5
- package/src/composables/useMapFilter.ts +6 -5
- package/src/composables/useMapLayers.ts +7 -6
- package/src/composables/useScrollReveal.ts +151 -0
- package/src/composables/useThemeTokens.ts +116 -0
- package/src/composables/viewportHints.ts +80 -0
- package/src/directives/vClickOutside.ts +90 -0
- package/src/directives/vFocusRing.ts +60 -0
- package/src/directives/vLongPress.ts +134 -0
- package/src/directives/vReveal.ts +57 -0
- package/src/directives/vScrollElevation.ts +116 -0
- package/src/directives/vSkeleton.ts +87 -0
- package/src/directives/vStateLayer.ts +83 -0
- package/src/directives/vSwipe.ts +197 -0
- package/src/directives/vTooltip.ts +128 -0
- package/src/index.ts +31 -1
- package/src/locales/de.ts +4 -0
- package/src/locales/es.ts +4 -0
- package/src/locales/fr.ts +4 -0
- package/src/locales/ja.ts +4 -0
- package/src/locales/ko.ts +4 -0
- package/src/locales/pt.ts +4 -0
- package/src/locales/zh.ts +4 -0
- package/src/map.ts +1 -1
- package/src/plugin.ts +34 -0
- package/src/styles/theme.css +63 -0
- package/dist/MMenuItem-BckcR0nW.js +0 -809
- package/dist/MMenuItem-BckcR0nW.js.map +0 -1
- package/dist/MSlider-LyH_gy8D.js +0 -1411
- package/dist/MSlider-LyH_gy8D.js.map +0 -1
- package/dist/MTextField-FCPOTB0o.js +0 -672
- package/dist/MTextField-FCPOTB0o.js.map +0 -1
- package/dist/composables/_useThemeTokens.d.ts +0 -7
- package/dist/useLocale-SfQHnJfp.js.map +0 -1
- package/src/composables/_useThemeTokens.ts +0 -42
|
@@ -1,31 +1,104 @@
|
|
|
1
|
-
<script
|
|
2
|
-
/**
|
|
3
|
-
* A vertical event timeline with icon dots, dates, and colors — standard single-column or alternating
|
|
4
|
-
* left/right layout.
|
|
5
|
-
*/
|
|
6
|
-
import MIcon from "./MIcon.vue";
|
|
7
|
-
|
|
1
|
+
<script lang="ts">
|
|
8
2
|
export interface TimelineItem {
|
|
3
|
+
/** Stable key for the entry (defaults to its index): set it when entries are added or removed */
|
|
4
|
+
key?: string | number;
|
|
9
5
|
title: string;
|
|
10
6
|
description?: string;
|
|
11
7
|
date?: string;
|
|
12
8
|
icon?: string;
|
|
13
9
|
color?: "primary" | "secondary" | "tertiary" | "error" | "success";
|
|
10
|
+
/** Any CSS color for the dot (and its line), over `color` */
|
|
14
11
|
dotColor?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Progress of a step: `done` (filled, a solid line to the next), `current` (filled, with a pulsing halo) or
|
|
14
|
+
* `pending` (outlined, a dashed line). Over what the timeline's `current` gives it
|
|
15
|
+
*/
|
|
16
|
+
status?: "done" | "current" | "pending";
|
|
17
|
+
/**
|
|
18
|
+
* A group to show it under ("Today", "Yesterday"): a header goes before each run of consecutive entries with the
|
|
19
|
+
* same group, and the line stops at the end of the run
|
|
20
|
+
*/
|
|
21
|
+
group?: string;
|
|
15
22
|
}
|
|
16
23
|
|
|
17
|
-
|
|
24
|
+
export type TimelineStatus = NonNullable<TimelineItem["status"]>;
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<script setup lang="ts" generic="T extends TimelineItem = TimelineItem">
|
|
28
|
+
/**
|
|
29
|
+
* An event timeline with icon dots, dates, and colors — a single column, alternating left/right, or horizontal.
|
|
30
|
+
* With `current` (or items' `status`) it tracks progress: done steps filled with a solid line, the current one
|
|
31
|
+
* pulsing, the rest outlined with a dashed line. Every part can be replaced through slots, which receive
|
|
32
|
+
* `{ item, index }`; your item type flows into them.
|
|
33
|
+
*
|
|
34
|
+
* @slot item Extra content under an entry's description (a card, chips, a button). With `bare`, the entry's whole
|
|
35
|
+
* content. `item-{index}` slots still work for a single entry and win over this one
|
|
36
|
+
* @slot title Replaces an entry's title row (title and date)
|
|
37
|
+
* @slot dot Replaces an entry's dot (an avatar, an image, a custom shape); the line still runs from it
|
|
38
|
+
* @slot group Replaces a group's header (scope: `{ group, items }`, the run of entries under it)
|
|
39
|
+
* @slot opposite Content across the line: on the empty side in the alternating layout, or in a column before the
|
|
40
|
+
* line in the single-column one (dates, times, amounts)
|
|
41
|
+
*/
|
|
42
|
+
import { computed, onBeforeUpdate, onMounted, onUpdated, ref, useSlots } from "vue";
|
|
43
|
+
import MIcon from "./MIcon.vue";
|
|
44
|
+
import MButton from "./MButton.vue";
|
|
45
|
+
import { useLocale } from "../composables/useLocale";
|
|
46
|
+
import { motionSprings } from "../composables/motion";
|
|
47
|
+
import { playSamples, prefersReducedMotion, sampleSpring } from "../composables/_springAnimation";
|
|
48
|
+
|
|
49
|
+
const props = withDefaults(
|
|
18
50
|
defineProps<{
|
|
19
51
|
/** Array of timeline entries — required */
|
|
20
|
-
items:
|
|
52
|
+
items: T[];
|
|
21
53
|
/** Compact spacing between items */
|
|
22
54
|
dense?: boolean;
|
|
23
|
-
/** Alternate items left/right of a central line instead of a single left-aligned column */
|
|
55
|
+
/** Alternate items left/right of a central line instead of a single left-aligned column (vertical only) */
|
|
24
56
|
alternating?: boolean;
|
|
57
|
+
/** Vertical (default) or horizontal: entries side by side along a line, scrolling sideways when they don't fit */
|
|
58
|
+
orientation?: "vertical" | "horizontal";
|
|
59
|
+
/** Leaves each entry's content to the `#item` slot: no title, description or date */
|
|
60
|
+
bare?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Makes it a progress timeline (an order's tracking, a setup's steps): the index of the current step. The ones
|
|
63
|
+
* before are done, the ones after pending; an item's own `status` wins. `items.length` marks them all done
|
|
64
|
+
*/
|
|
65
|
+
current?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Lets the alternating layout fold into a single column (the line on the left, `#opposite` under the content)
|
|
68
|
+
* while the timeline is narrower than 32rem: its own width, so it works in a side column too
|
|
69
|
+
*/
|
|
70
|
+
responsive?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Entries added after it mounts fade and slide in, and the rest move to their new places, on M3 springs (none
|
|
73
|
+
* with reduced motion). Give items a `key`, or an insertion looks like a change to every entry after it
|
|
74
|
+
*/
|
|
75
|
+
animate?: boolean;
|
|
76
|
+
/** Shows only the first entries (a count; groups' headers don't count), with a button for the rest */
|
|
77
|
+
limit?: number;
|
|
78
|
+
/** Whether the entries past `limit` show (v-model:expanded); the timeline keeps its own state otherwise */
|
|
79
|
+
expanded?: boolean;
|
|
25
80
|
}>(),
|
|
26
|
-
{
|
|
81
|
+
{
|
|
82
|
+
dense: false, alternating: false, orientation: "vertical", bare: false, current: undefined, responsive: true,
|
|
83
|
+
animate: true, limit: undefined, expanded: undefined,
|
|
84
|
+
},
|
|
27
85
|
);
|
|
28
86
|
|
|
87
|
+
const emit = defineEmits<{ "update:expanded": [expanded: boolean] }>();
|
|
88
|
+
|
|
89
|
+
defineSlots<{
|
|
90
|
+
item?: (props: { item: T; index: number }) => unknown;
|
|
91
|
+
title?: (props: { item: T; index: number }) => unknown;
|
|
92
|
+
dot?: (props: { item: T; index: number }) => unknown;
|
|
93
|
+
opposite?: (props: { item: T; index: number }) => unknown;
|
|
94
|
+
group?: (props: { group: string; items: T[] }) => unknown;
|
|
95
|
+
[name: `item-${number}`]: ((props: { item: T; index: number }) => unknown) | undefined;
|
|
96
|
+
}>();
|
|
97
|
+
|
|
98
|
+
const slots = useSlots();
|
|
99
|
+
|
|
100
|
+
// Literal class names: Tailwind only generates what appears in the source, so a class built at runtime
|
|
101
|
+
// (`bg-secondary` + '/30') rendered no line for anything but primary
|
|
29
102
|
const dotBg: Record<string, string> = {
|
|
30
103
|
primary: "bg-primary text-on-primary",
|
|
31
104
|
secondary: "bg-secondary text-on-secondary",
|
|
@@ -33,92 +106,308 @@ const dotBg: Record<string, string> = {
|
|
|
33
106
|
error: "bg-error text-on-error",
|
|
34
107
|
success: "bg-success text-on-success",
|
|
35
108
|
};
|
|
109
|
+
const lineBg: Record<string, string> = {
|
|
110
|
+
primary: "bg-primary/30",
|
|
111
|
+
secondary: "bg-secondary/30",
|
|
112
|
+
tertiary: "bg-tertiary/30",
|
|
113
|
+
error: "bg-error/30",
|
|
114
|
+
success: "bg-success/30",
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const t = useLocale();
|
|
118
|
+
|
|
119
|
+
// `limit`: the first entries, then a button for the rest (all of them while expanded)
|
|
120
|
+
const ownExpanded = ref(false);
|
|
121
|
+
const isExpanded = computed(() => props.expanded ?? ownExpanded.value);
|
|
122
|
+
const limited = computed(() => props.limit !== undefined && props.items.length > props.limit);
|
|
123
|
+
const shown = computed(() => (limited.value && !isExpanded.value ? props.items.slice(0, props.limit) : props.items));
|
|
124
|
+
const hiddenCount = computed(() => props.items.length - shown.value.length);
|
|
125
|
+
const toggleLabel = computed(() =>
|
|
126
|
+
isExpanded.value ? t.timelineShowLess : t.timelineShowMore.replace("{count}", String(hiddenCount.value)),
|
|
127
|
+
);
|
|
128
|
+
function toggleExpanded() {
|
|
129
|
+
const next = !isExpanded.value;
|
|
130
|
+
ownExpanded.value = next;
|
|
131
|
+
emit("update:expanded", next);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const keyOf = (item: T, i: number) => item.key ?? i;
|
|
135
|
+
// Null when the timeline isn't about progress (no `current`, no `status`): the plain look
|
|
136
|
+
const statusOf = (item: T, i: number): TimelineStatus | null =>
|
|
137
|
+
item.status ?? (props.current === undefined ? null : i < props.current ? "done" : i === props.current ? "current" : "pending");
|
|
138
|
+
const pending = (item: T, i: number) => statusOf(item, i) === "pending";
|
|
139
|
+
// The line after an entry is dashed (still to come) unless that entry is done and the next one is reached
|
|
140
|
+
const dashed = (i: number) => {
|
|
141
|
+
const here = statusOf(props.items[i]!, i);
|
|
142
|
+
if (here === null) return false;
|
|
143
|
+
const next = props.items[i + 1];
|
|
144
|
+
return here !== "done" || (!!next && statusOf(next, i + 1) === "pending");
|
|
145
|
+
};
|
|
146
|
+
// One dot slot size for every entry: with any icon (or a #dot), small dots sit centered in the same 36px, so dots,
|
|
147
|
+
// line and text stay aligned when entries mix both
|
|
148
|
+
const wide = computed(() => !!slots.dot || props.items.some((item) => item.icon));
|
|
149
|
+
// A `dotColor` paints over the role's background (inline style); the icon keeps the role's on-color
|
|
150
|
+
// A pending step is outlined, its icon in on-surface-variant
|
|
151
|
+
const dotClass = (item: T, i: number, size = item.icon ? "h-9 w-9" : "h-3 w-3") => [
|
|
152
|
+
"relative",
|
|
153
|
+
size,
|
|
154
|
+
pending(item, i) ? "border-2 border-outline-variant bg-surface text-on-surface-variant" : dotBg[item.color ?? "primary"],
|
|
155
|
+
];
|
|
156
|
+
const dotStyle = (item: T, i: number) => (item.dotColor && !pending(item, i) ? { backgroundColor: item.dotColor } : undefined);
|
|
157
|
+
// In a progress timeline a done step's line is solid; otherwise the usual 30% tint
|
|
158
|
+
const lineClass = (item: T, i: number, vertical: boolean) => {
|
|
159
|
+
if (dashed(i)) return vertical ? "border-l-2 border-dashed border-outline-variant" : "border-t-2 border-dashed border-outline-variant";
|
|
160
|
+
if (item.dotColor) return "";
|
|
161
|
+
return statusOf(item, i) === "done" ? dotBg[item.color ?? "primary"]!.split(" ")[0] : lineBg[item.color ?? "primary"];
|
|
162
|
+
};
|
|
163
|
+
const lineStyle = (item: T, i: number) => {
|
|
164
|
+
if (!item.dotColor || dashed(i)) return undefined;
|
|
165
|
+
return { backgroundColor: statusOf(item, i) === "done" ? item.dotColor : `color-mix(in srgb, ${item.dotColor} 30%, transparent)` };
|
|
166
|
+
};
|
|
167
|
+
// `item-{index}` (the original per-entry slot) wins over the generic `#item`
|
|
168
|
+
const itemSlot = (i: number) => (slots[`item-${i}`] ? `item-${i}` : slots.item ? "item" : null) as "item" | null;
|
|
169
|
+
// Groups: a header before each run of entries sharing `group`; the line ends with the run
|
|
170
|
+
const startsGroup = (i: number) => {
|
|
171
|
+
const group = props.items[i]?.group;
|
|
172
|
+
return group != null && (i === 0 || props.items[i - 1]!.group !== group);
|
|
173
|
+
};
|
|
174
|
+
const groupRun = (i: number) => {
|
|
175
|
+
const run: T[] = [];
|
|
176
|
+
for (let j = i; j < props.items.length && props.items[j]!.group === props.items[i]!.group; j++) run.push(props.items[j]!);
|
|
177
|
+
return run;
|
|
178
|
+
};
|
|
179
|
+
const hasGroups = computed(() => props.items.some((item) => item.group != null));
|
|
180
|
+
// The line ends with the last entry shown, and with each group's run
|
|
181
|
+
const isLast = (i: number) =>
|
|
182
|
+
i === shown.value.length - 1 || (hasGroups.value && props.items[i + 1]!.group !== props.items[i]!.group);
|
|
183
|
+
|
|
184
|
+
// ── Enter / move animation ────────────────────────────────────────────────────────────────────────────────────────
|
|
185
|
+
// FLIP, as MDragDropList does: every row's place before an update; after it, new rows slide in and the others spring
|
|
186
|
+
// from where they were. Rows are found by `data-timeline-row` (an entry's key, or `group:<name>` for a header,
|
|
187
|
+
// so a header stays put when an entry joins its group at the top)
|
|
188
|
+
const root = ref<HTMLElement>();
|
|
189
|
+
let mounted = false;
|
|
190
|
+
let before = new Map<string, DOMRect>();
|
|
191
|
+
const rows = () => Array.from(root.value?.querySelectorAll<HTMLElement>(":scope > [data-timeline-row]") ?? []);
|
|
192
|
+
const rowKey = (item: T, i: number) => String(keyOf(item, i));
|
|
193
|
+
|
|
194
|
+
onMounted(() => { mounted = true; });
|
|
195
|
+
onBeforeUpdate(() => {
|
|
196
|
+
before = new Map();
|
|
197
|
+
if (!props.animate || !mounted) return;
|
|
198
|
+
for (const row of rows()) before.set(row.dataset.timelineRow!, row.getBoundingClientRect());
|
|
199
|
+
});
|
|
200
|
+
onUpdated(() => {
|
|
201
|
+
if (!props.animate || !before.size || prefersReducedMotion()) return;
|
|
202
|
+
const along = props.orientation === "horizontal" ? "X" : "Y";
|
|
203
|
+
for (const row of rows()) {
|
|
204
|
+
const was = before.get(row.dataset.timelineRow!);
|
|
205
|
+
const now = row.getBoundingClientRect();
|
|
206
|
+
if (!was) {
|
|
207
|
+
// New: in from a short way back along the timeline, fading in
|
|
208
|
+
playSamples(row, sampleSpring(0, 1, 0, motionSprings.standard.defaultSpatial, 0.001), (p) => ({
|
|
209
|
+
transform: `translate${along}(${(1 - p) * -12}px)`,
|
|
210
|
+
opacity: String(Math.min(1, p * 1.4)),
|
|
211
|
+
}));
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
const dx = was.left - now.left;
|
|
215
|
+
const dy = was.top - now.top;
|
|
216
|
+
if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5) continue;
|
|
217
|
+
playSamples(row, sampleSpring(1, 0, 0, motionSprings.standard.defaultSpatial, 0.001), (p) => ({
|
|
218
|
+
transform: `translate(${dx * p}px, ${dy * p}px)`,
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
before = new Map();
|
|
222
|
+
});
|
|
36
223
|
</script>
|
|
37
224
|
|
|
38
225
|
<template>
|
|
39
|
-
<
|
|
40
|
-
<!--
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
226
|
+
<ol v-if="orientation === 'horizontal'" ref="root" class="flex list-none overflow-x-auto p-0" role="list">
|
|
227
|
+
<!-- Horizontal: entries side by side, the line running between their dots -->
|
|
228
|
+
<li
|
|
229
|
+
:data-timeline-row="rowKey(item, i)"
|
|
230
|
+
v-for="(item, i) in shown"
|
|
231
|
+
:key="keyOf(item, i)"
|
|
232
|
+
:aria-current="statusOf(item, i) === 'current' ? 'step' : undefined"
|
|
233
|
+
class="flex min-w-40 flex-1 flex-col"
|
|
234
|
+
>
|
|
235
|
+
<!-- A group's header above its first dot; the others keep the same height so the dots line up -->
|
|
236
|
+
<div v-if="hasGroups" class="mb-2 min-h-5 pr-3" :aria-hidden="!startsGroup(i) || undefined">
|
|
237
|
+
<template v-if="startsGroup(i)">
|
|
238
|
+
<slot name="group" :group="item.group!" :items="groupRun(i)">
|
|
239
|
+
<p class="text-title-small text-on-surface-variant">{{ item.group }}</p>
|
|
240
|
+
</slot>
|
|
241
|
+
</template>
|
|
242
|
+
</div>
|
|
243
|
+
<div class="flex items-center" :class="wide ? 'h-9' : 'h-3'">
|
|
244
|
+
<span class="flex shrink-0 justify-center" :class="wide ? 'w-9' : ''">
|
|
245
|
+
<slot name="dot" :item="item" :index="i">
|
|
246
|
+
<span class="z-1 flex shrink-0 items-center justify-center rounded-full" :class="dotClass(item, i)" :style="dotStyle(item, i)">
|
|
247
|
+
<span v-if="statusOf(item, i) === 'current'" aria-hidden="true" class="pointer-events-none absolute inset-0 rounded-full bg-inherit opacity-40 motion-safe:animate-ping" />
|
|
248
|
+
<MIcon v-if="item.icon" :name="item.icon" :size="18" class="relative" />
|
|
249
|
+
</span>
|
|
250
|
+
</slot>
|
|
251
|
+
</span>
|
|
252
|
+
<span v-if="!isLast(i)" class="min-w-4 flex-1" :class="[dashed(i) ? 'h-0' : 'h-[2px]', lineClass(item, i, false)]" :style="lineStyle(item, i)" />
|
|
253
|
+
</div>
|
|
254
|
+
<!-- The gap to the next entry is the content's padding, so the line above runs all the way to its dot -->
|
|
255
|
+
<div class="mt-3 min-w-0" :class="dense ? 'pr-3' : 'pr-6'">
|
|
256
|
+
<template v-if="!bare">
|
|
257
|
+
<slot name="title" :item="item" :index="i">
|
|
258
|
+
<p class="text-body-large font-medium" :class="pending(item, i) ? 'text-on-surface-variant' : 'text-on-surface'">{{ item.title }}</p>
|
|
259
|
+
<span v-if="item.date" class="text-label-small text-on-surface-variant">{{ item.date }}</span>
|
|
260
|
+
</slot>
|
|
261
|
+
<p v-if="item.description" class="mt-1 text-body-medium text-on-surface-variant">{{ item.description }}</p>
|
|
262
|
+
</template>
|
|
263
|
+
<div v-if="itemSlot(i)" :class="{ 'mt-2': !bare }">
|
|
264
|
+
<slot :name="itemSlot(i)!" :item="item" :index="i" />
|
|
63
265
|
</div>
|
|
266
|
+
</div>
|
|
267
|
+
</li>
|
|
268
|
+
<!-- Past `limit`: the button, level with the dots -->
|
|
269
|
+
<li v-if="limited" data-timeline-row="more" class="flex shrink-0 flex-col pr-2">
|
|
270
|
+
<div v-if="hasGroups" class="mb-2 min-h-5" aria-hidden="true" />
|
|
271
|
+
<div class="flex items-center" :class="wide ? 'h-9' : 'h-3'">
|
|
272
|
+
<MButton variant="text" size="sm" :icon="isExpanded ? 'expand_less' : 'expand_more'" :aria-expanded="isExpanded" @click="toggleExpanded">
|
|
273
|
+
{{ toggleLabel }}
|
|
274
|
+
</MButton>
|
|
275
|
+
</div>
|
|
276
|
+
</li>
|
|
277
|
+
</ol>
|
|
278
|
+
|
|
279
|
+
<ol v-else-if="!alternating" ref="root" class="flex list-none flex-col p-0" role="list">
|
|
280
|
+
<!-- Vertical, single column (with an optional #opposite column before the line) -->
|
|
281
|
+
<template v-for="(item, i) in shown" :key="keyOf(item, i)">
|
|
282
|
+
<li v-if="startsGroup(i)" :data-timeline-row="`group:${item.group}`" class="pb-3" :class="{ 'pt-2': i > 0 }">
|
|
283
|
+
<slot name="group" :group="item.group!" :items="groupRun(i)">
|
|
284
|
+
<p class="text-title-small text-on-surface-variant">{{ item.group }}</p>
|
|
285
|
+
</slot>
|
|
286
|
+
</li>
|
|
287
|
+
<li
|
|
288
|
+
:data-timeline-row="rowKey(item, i)"
|
|
289
|
+
:aria-current="statusOf(item, i) === 'current' ? 'step' : undefined"
|
|
290
|
+
class="relative flex gap-4"
|
|
291
|
+
>
|
|
292
|
+
<!-- The gap to the next entry is padding on the text columns, not on the row: the line column stretches over
|
|
293
|
+
the whole row and reaches the next dot -->
|
|
294
|
+
<div v-if="$slots.opposite" class="w-24 shrink-0 text-right" :class="dense ? 'pb-4' : 'pb-8'">
|
|
295
|
+
<slot name="opposite" :item="item" :index="i" />
|
|
296
|
+
</div>
|
|
297
|
+
|
|
298
|
+
<!-- Line + dot -->
|
|
299
|
+
<div class="flex shrink-0 flex-col items-center" :class="{ 'w-9': wide }">
|
|
300
|
+
<slot name="dot" :item="item" :index="i">
|
|
301
|
+
<span class="z-1 flex shrink-0 items-center justify-center rounded-full" :class="dotClass(item, i)" :style="dotStyle(item, i)">
|
|
302
|
+
<span v-if="statusOf(item, i) === 'current'" aria-hidden="true" class="pointer-events-none absolute inset-0 rounded-full bg-inherit opacity-40 motion-safe:animate-ping" />
|
|
303
|
+
<MIcon v-if="item.icon" :name="item.icon" :size="18" class="relative" />
|
|
304
|
+
</span>
|
|
305
|
+
</slot>
|
|
306
|
+
<span v-if="!isLast(i)" class="flex-1" :class="[dashed(i) ? 'w-0' : 'w-[2px]', lineClass(item, i, true)]" :style="[{ minHeight: '16px' }, lineStyle(item, i)]" />
|
|
307
|
+
</div>
|
|
64
308
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
<
|
|
70
|
-
item.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
</div>
|
|
309
|
+
<!-- Content -->
|
|
310
|
+
<div class="-mt-0.5 min-w-0 flex-1" :class="dense ? 'pb-4' : 'pb-8'">
|
|
311
|
+
<template v-if="!bare">
|
|
312
|
+
<slot name="title" :item="item" :index="i">
|
|
313
|
+
<div class="flex items-baseline justify-between gap-2">
|
|
314
|
+
<p class="text-body-large font-medium" :class="pending(item, i) ? 'text-on-surface-variant' : 'text-on-surface'">{{ item.title }}</p>
|
|
315
|
+
<span v-if="item.date" class="shrink-0 text-label-small text-on-surface-variant">{{ item.date }}</span>
|
|
316
|
+
</div>
|
|
317
|
+
</slot>
|
|
318
|
+
<p v-if="item.description" class="mt-1 text-body-medium text-on-surface-variant">{{ item.description }}</p>
|
|
319
|
+
</template>
|
|
320
|
+
<div v-if="itemSlot(i)" :class="{ 'mt-2': !bare }">
|
|
321
|
+
<slot :name="itemSlot(i)!" :item="item" :index="i" />
|
|
79
322
|
</div>
|
|
80
323
|
</div>
|
|
324
|
+
</li>
|
|
81
325
|
</template>
|
|
326
|
+
<!-- Past `limit`: the button, its label lined up with the entries' text -->
|
|
327
|
+
<li v-if="limited" data-timeline-row="more" class="flex gap-4">
|
|
328
|
+
<div v-if="$slots.opposite" class="w-24 shrink-0" />
|
|
329
|
+
<div class="shrink-0" :class="wide ? 'w-9' : 'w-3'" />
|
|
330
|
+
<div class="-ml-3">
|
|
331
|
+
<MButton variant="text" size="sm" :icon="isExpanded ? 'expand_less' : 'expand_more'" :aria-expanded="isExpanded" @click="toggleExpanded">
|
|
332
|
+
{{ toggleLabel }}
|
|
333
|
+
</MButton>
|
|
334
|
+
</div>
|
|
335
|
+
</li>
|
|
336
|
+
</ol>
|
|
82
337
|
|
|
83
|
-
|
|
84
|
-
<template v-
|
|
338
|
+
<ol v-else ref="root" class="relative list-none p-0" :class="{ '@container': responsive }" role="list">
|
|
339
|
+
<template v-for="(item, i) in shown" :key="keyOf(item, i)">
|
|
340
|
+
<!-- A group's header: centered over the line, or at the start once folded -->
|
|
341
|
+
<li v-if="startsGroup(i)" :data-timeline-row="`group:${item.group}`" class="pb-3" :class="[{ 'pt-2': i > 0 }, responsive ? 'text-left @lg:text-center' : 'text-center']">
|
|
342
|
+
<slot name="group" :group="item.group!" :items="groupRun(i)">
|
|
343
|
+
<p class="text-title-small text-on-surface-variant">{{ item.group }}</p>
|
|
344
|
+
</slot>
|
|
345
|
+
</li>
|
|
346
|
+
<!-- Alternating: entries left and right of a central line. With `responsive`, below 32rem (the list's own width)
|
|
347
|
+
each entry is a grid instead: the line in the first column, the content and then #opposite in the second -->
|
|
348
|
+
<li
|
|
349
|
+
:data-timeline-row="rowKey(item, i)"
|
|
350
|
+
:aria-current="statusOf(item, i) === 'current' ? 'step' : undefined"
|
|
351
|
+
:class="responsive
|
|
352
|
+
? ['grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 @lg:flex @lg:items-stretch @lg:gap-x-0', i % 2 === 0 ? '@lg:flex-row' : '@lg:flex-row-reverse']
|
|
353
|
+
: ['flex items-stretch', i % 2 === 0 ? 'flex-row' : 'flex-row-reverse']"
|
|
354
|
+
>
|
|
355
|
+
<!-- Content side -->
|
|
85
356
|
<div
|
|
86
|
-
|
|
87
|
-
:
|
|
88
|
-
|
|
89
|
-
|
|
357
|
+
class="min-w-0"
|
|
358
|
+
:class="responsive
|
|
359
|
+
? ['col-start-2 row-start-1 text-left @lg:flex-1', i % 2 === 0 ? '@lg:text-right' : '', dense ? '@lg:pb-4' : '@lg:pb-8']
|
|
360
|
+
: ['flex-1', i % 2 === 0 ? 'text-right' : 'text-left', dense ? 'pb-4' : 'pb-8']"
|
|
90
361
|
>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
<span
|
|
101
|
-
v-if="item.date"
|
|
102
|
-
class="mt-1 inline-block text-label-small text-on-surface-variant"
|
|
103
|
-
>{{ item.date }}</span
|
|
104
|
-
>
|
|
362
|
+
<template v-if="!bare">
|
|
363
|
+
<slot name="title" :item="item" :index="i">
|
|
364
|
+
<p class="text-body-large font-medium" :class="pending(item, i) ? 'text-on-surface-variant' : 'text-on-surface'">{{ item.title }}</p>
|
|
365
|
+
</slot>
|
|
366
|
+
<p v-if="item.description" class="mt-1 text-body-medium text-on-surface-variant">{{ item.description }}</p>
|
|
367
|
+
<span v-if="item.date && !$slots.title" class="mt-1 inline-block text-label-small text-on-surface-variant">{{ item.date }}</span>
|
|
368
|
+
</template>
|
|
369
|
+
<div v-if="itemSlot(i)" :class="{ 'mt-2': !bare }">
|
|
370
|
+
<slot :name="itemSlot(i)!" :item="item" :index="i" />
|
|
105
371
|
</div>
|
|
372
|
+
</div>
|
|
106
373
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
374
|
+
<!-- Center column: dot + continuous line -->
|
|
375
|
+
<div
|
|
376
|
+
class="flex shrink-0 flex-col items-center"
|
|
377
|
+
:class="responsive ? 'col-start-1 row-span-2 row-start-1 w-9 @lg:w-14' : 'w-14'"
|
|
378
|
+
>
|
|
379
|
+
<slot name="dot" :item="item" :index="i">
|
|
380
|
+
<span
|
|
110
381
|
class="z-1 flex shrink-0 items-center justify-center rounded-full"
|
|
111
|
-
:class="
|
|
112
|
-
:style="item
|
|
382
|
+
:class="dotClass(item, i, item.icon ? 'h-9 w-9' : 'h-3.5 w-3.5')"
|
|
383
|
+
:style="dotStyle(item, i)"
|
|
113
384
|
>
|
|
114
|
-
<
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
</
|
|
385
|
+
<span v-if="statusOf(item, i) === 'current'" aria-hidden="true" class="pointer-events-none absolute inset-0 rounded-full bg-inherit opacity-40 motion-safe:animate-ping" />
|
|
386
|
+
<MIcon v-if="item.icon" :name="item.icon" :size="18" class="relative" />
|
|
387
|
+
</span>
|
|
388
|
+
</slot>
|
|
389
|
+
<span v-if="!isLast(i)" class="flex-1" :class="[dashed(i) ? 'w-0' : 'w-[2px]', lineClass(item, i, true)]" :style="lineStyle(item, i)" />
|
|
390
|
+
</div>
|
|
118
391
|
|
|
119
|
-
|
|
120
|
-
|
|
392
|
+
<!-- Opposite side (folded: under the content, carrying the gap to the next entry) -->
|
|
393
|
+
<div
|
|
394
|
+
class="min-w-0"
|
|
395
|
+
:class="[
|
|
396
|
+
responsive
|
|
397
|
+
? ['col-start-2 row-start-2 text-left @lg:flex-1', i % 2 === 0 ? '' : '@lg:text-right']
|
|
398
|
+
: ['flex-1', i % 2 === 0 ? 'text-left' : 'text-right'],
|
|
399
|
+
dense ? 'pb-4' : 'pb-8',
|
|
400
|
+
]"
|
|
401
|
+
>
|
|
402
|
+
<slot name="opposite" :item="item" :index="i" />
|
|
121
403
|
</div>
|
|
404
|
+
</li>
|
|
122
405
|
</template>
|
|
123
|
-
|
|
406
|
+
<!-- Past `limit`: the button, centered under the line (folded: lined up with the entries' text) -->
|
|
407
|
+
<li v-if="limited" data-timeline-row="more" class="flex" :class="responsive ? 'justify-start pl-9 @lg:justify-center @lg:pl-0' : 'justify-center'">
|
|
408
|
+
<MButton variant="text" size="sm" :icon="isExpanded ? 'expand_less' : 'expand_more'" :aria-expanded="isExpanded" @click="toggleExpanded">
|
|
409
|
+
{{ toggleLabel }}
|
|
410
|
+
</MButton>
|
|
411
|
+
</li>
|
|
412
|
+
</ol>
|
|
124
413
|
</template>
|