frappe-ui 1.0.2 → 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/experimental/Calendar/CalendarEventRow.vue +0 -4
- package/experimental/Calendar/calendarUtils.ts +33 -21
- package/experimental/CommandPalette/CommandPaletteItem.vue +9 -1
- package/experimental/MultiEmailInput/MultiEmailInput.vue +64 -12
- package/experimental/MultiEmailInput/types.ts +12 -3
- package/experimental/SpriteIcons/IconPicker.vue +2 -1
- package/experimental/Stepper/StepIndicator.vue +129 -0
- package/experimental/Stepper/Stepper.api.md +117 -0
- package/experimental/Stepper/Stepper.md +95 -0
- package/experimental/Stepper/Stepper.vue +82 -0
- package/experimental/Stepper/StepperHorizontal.vue +93 -0
- package/experimental/Stepper/StepperVertical.vue +291 -0
- package/experimental/Stepper/index.ts +11 -0
- package/experimental/Stepper/resolve.ts +87 -0
- package/experimental/Stepper/types.ts +89 -0
- package/experimental.ts +2 -21
- package/package.json +1 -3
- package/src/charts/CalendarHeatmapChart.vue +353 -0
- package/src/charts/DonutChart.vue +34 -58
- package/src/charts/HeatmapChart.vue +26 -64
- package/src/charts/NumberCard.vue +62 -7
- package/src/charts/PercentageBarChart.vue +243 -0
- package/src/charts/SankeyChart.vue +14 -11
- package/src/charts/ScatterChart.vue +24 -20
- package/src/charts/axisChartCommon.ts +182 -18
- package/src/charts/axisFormat.ts +8 -3
- package/src/charts/calendarHeatmapOptions.ts +604 -0
- package/src/charts/colorMath.ts +26 -0
- package/src/charts/components/ChartContainer.vue +63 -53
- package/src/charts/components/ChartLegend.vue +216 -24
- package/src/charts/components/ChartScale.vue +85 -0
- package/src/charts/core/dataLabelFit.ts +45 -6
- package/src/charts/core/useAxisChart.ts +36 -19
- package/src/charts/core/useChart.ts +6 -1
- package/src/charts/core/usePlotKeyboard.ts +13 -2
- package/src/charts/docs/BarChart.md +11 -3
- package/src/charts/docs/CalendarHeatmapChart.api.md +165 -0
- package/src/charts/docs/CalendarHeatmapChart.md +33 -0
- package/src/charts/docs/ChartContainer.api.md +6 -0
- package/src/charts/docs/ChartLegend.api.md +1 -1
- package/src/charts/docs/ChartLegend.md +25 -3
- package/src/charts/docs/DonutChart.api.md +12 -0
- package/src/charts/docs/DonutChart.md +17 -0
- package/src/charts/docs/HeatmapChart.api.md +1 -1
- package/src/charts/docs/LineChart.md +5 -3
- package/src/charts/docs/NumberCard.api.md +6 -0
- package/src/charts/docs/NumberCard.md +6 -0
- package/src/charts/docs/Overview.md +13 -6
- package/src/charts/docs/PercentageBarChart.api.md +148 -0
- package/src/charts/docs/PercentageBarChart.md +42 -0
- package/src/charts/docs/ScatterChart.md +2 -3
- package/src/charts/donutChartOptions.ts +22 -130
- package/src/charts/format.ts +4 -1
- package/src/charts/heatmapOptions.ts +17 -12
- package/src/charts/hiddenSeries.ts +8 -3
- package/src/charts/index.ts +12 -0
- package/src/charts/legendOverflow.ts +40 -0
- package/src/charts/numberCardFormat.ts +19 -13
- package/src/charts/referenceLines.ts +2 -1
- package/src/charts/scatterOptions.ts +16 -3
- package/src/charts/seriesData.ts +8 -3
- package/src/charts/slices.ts +228 -0
- package/src/charts/tokens.ts +99 -0
- package/src/charts/types.ts +318 -9
- package/src/components/Avatar/Avatar.md +27 -2
- package/src/components/Avatar/Avatar.vue +29 -12
- package/src/components/Breadcrumbs/Breadcrumbs.vue +2 -1
- package/src/components/Combobox/Combobox.vue +9 -2
- package/src/components/Combobox/ComboboxResults.vue +6 -1
- package/src/components/Combobox/utils.ts +2 -1
- package/src/components/DatePicker/DatePicker.md +7 -0
- package/src/components/DatePicker/DatePicker.vue +6 -0
- package/src/components/DatePicker/DateTimePicker.vue +6 -0
- package/src/components/DatePicker/composables.ts +18 -1
- package/src/components/DatePicker/utils.ts +53 -0
- package/src/components/Dialog/Dialog.md +3 -1
- package/src/components/Duration/Duration.api.md +16 -3
- package/src/components/Duration/Duration.md +21 -0
- package/src/components/Duration/Duration.vue +29 -8
- package/src/components/Duration/duration.ts +105 -44
- package/src/components/Duration/index.ts +1 -0
- package/src/components/Duration/types.ts +30 -1
- package/src/components/HoverCard/HoverCard.vue +21 -5
- package/src/components/Menu/utils.ts +3 -2
- package/src/components/MobileNav/MobileNavItem.vue +3 -22
- package/src/components/MultiSelect/MultiSelect.api.md +5 -0
- package/src/components/MultiSelect/MultiSelect.vue +34 -0
- package/src/components/MultiSelect/MultiSelectResults.vue +3 -4
- package/src/components/MultiSelect/types.ts +6 -0
- package/src/components/Select/Select.vue +4 -4
- package/src/components/Select/utils.ts +1 -0
- package/src/components/SettingsDialog/SettingsDialog.api.md +7 -2
- package/src/components/SettingsDialog/SettingsDialog.md +2 -1
- package/src/components/SettingsDialog/SettingsRow.vue +12 -2
- package/src/components/Sidebar/SidebarItem.vue +3 -33
- package/src/components/SidebarRail/SidebarRailItem.vue +4 -17
- package/src/components/Switch/Switch.vue +3 -3
- package/src/components/Tooltip/Tooltip.vue +8 -0
- package/src/components/shared/deferredTrigger.ts +174 -0
- package/src/components/shared/navLink.ts +45 -0
- package/src/components/shared/selection/utils.ts +8 -1
- package/src/data-fetching/useCall/useCall.ts +25 -26
- package/src/data-fetching/useFrappeFetch.ts +48 -2
- package/src/data-fetching/useList/useList.ts +11 -3
- package/src/data-fetching/utils.ts +15 -1
- package/src/molecules/editor/components/MediaNodeView.vue +10 -1
- package/src/molecules/editor/components/MediaResizeGuide.vue +71 -0
- package/src/molecules/editor/components/media-node-view-utils.ts +7 -0
- package/src/molecules/editor/composables/useNodeViewResize.ts +142 -10
- package/src/molecules/editor/extensions/attachment/attachment-engine.ts +1 -1
- package/src/molecules/editor/extensions/content-paste/paste-html-utils.ts +16 -6
- package/src/molecules/editor/extensions/iframe/IframeNodeView.vue +29 -10
- package/src/molecules/editor/extensions/iframe/iframe-allowlist.ts +35 -16
- package/src/molecules/editor/extensions/iframe/iframe-embed-utils.ts +1 -1
- package/src/molecules/editor/extensions/iframe/iframe-extension.ts +30 -30
- package/src/molecules/editor/extensions/link/LinkEditorPopup.vue +1 -1
- package/src/molecules/editor/extensions/link/link-paste-plugin.ts +1 -1
- package/src/molecules/editor/extensions/shared/media-upload-engine.ts +1 -1
- package/src/molecules/editor/useEditor.ts +12 -6
- package/src/molecules/list/ListRow.vue +8 -1
- package/src/utils/dialog.ts +57 -16
- package/src/{molecules/editor/extensions/shared → utils}/url-safety.ts +28 -16
- package/tailwind/content.js +1 -1
- package/tailwind/plugin.js +22 -0
- package/vite/README.md +5 -3
- package/vite/codeLanguages.js +41 -17
- package/vite/doctypeInterfaceGenerator.js +52 -39
- package/vitepress/index.node.ts +0 -2
- package/experimental/TextEditor/TextEditor.api.md +0 -161
- package/experimental/TextEditor/TextEditor.vue +0 -298
- package/experimental/TextEditor/classIcon.ts +0 -21
- package/experimental/TextEditor/commands.js +0 -344
- package/experimental/TextEditor/components/CodeBlockComponent.vue +0 -103
- package/experimental/TextEditor/components/FontColor.vue +0 -153
- package/experimental/TextEditor/components/ImageViewerModal.vue +0 -463
- package/experimental/TextEditor/components/InsertImage.vue +0 -54
- package/experimental/TextEditor/components/InsertLink.vue +0 -13
- package/experimental/TextEditor/components/InsertVideo.vue +0 -14
- package/experimental/TextEditor/components/LinkPopup.vue +0 -99
- package/experimental/TextEditor/components/MediaNodeView.vue +0 -398
- package/experimental/TextEditor/components/MentionList.vue +0 -95
- package/experimental/TextEditor/components/TextEditorBubbleMenu.vue +0 -78
- package/experimental/TextEditor/components/TextEditorFixedMenu.vue +0 -78
- package/experimental/TextEditor/components/TextEditorFloatingMenu.vue +0 -61
- package/experimental/TextEditor/components/TextEditorMenu.vue +0 -218
- package/experimental/TextEditor/components/index.js +0 -0
- package/experimental/TextEditor/extensions/code-block.ts +0 -119
- package/experimental/TextEditor/extensions/color/color-extension.ts +0 -140
- package/experimental/TextEditor/extensions/color/color-styles.css +0 -25
- package/experimental/TextEditor/extensions/color/index.ts +0 -2
- package/experimental/TextEditor/extensions/content-paste-extension.ts +0 -160
- package/experimental/TextEditor/extensions/copy-styles.ts +0 -160
- package/experimental/TextEditor/extensions/emoji/EmojiList.vue +0 -55
- package/experimental/TextEditor/extensions/emoji/emoji-extension.ts +0 -55
- package/experimental/TextEditor/extensions/emoji/emojis.json +0 -7422
- package/experimental/TextEditor/extensions/heading/heading.ts +0 -20
- package/experimental/TextEditor/extensions/highlight/highlight-extension.ts +0 -241
- package/experimental/TextEditor/extensions/highlight/highlight-styles.css +0 -31
- package/experimental/TextEditor/extensions/highlight/index.ts +0 -2
- package/experimental/TextEditor/extensions/iframe/IframeNodeView.vue +0 -308
- package/experimental/TextEditor/extensions/iframe/InsertIframe.vue +0 -209
- package/experimental/TextEditor/extensions/iframe/iframe-extension.ts +0 -404
- package/experimental/TextEditor/extensions/iframe/index.ts +0 -11
- package/experimental/TextEditor/extensions/iframe/utils.ts +0 -283
- package/experimental/TextEditor/extensions/image/image-extension.ts +0 -661
- package/experimental/TextEditor/extensions/image/index.ts +0 -5
- package/experimental/TextEditor/extensions/image-group/ImageGroupNodeView.vue +0 -182
- package/experimental/TextEditor/extensions/image-group/ImageGroupUploadDialog.vue +0 -740
- package/experimental/TextEditor/extensions/image-group/image-group-extension.ts +0 -187
- package/experimental/TextEditor/extensions/image-viewer-extension.ts +0 -162
- package/experimental/TextEditor/extensions/link/index.ts +0 -1
- package/experimental/TextEditor/extensions/link/link-extension.ts +0 -323
- package/experimental/TextEditor/extensions/link/linkPasteHandler.ts +0 -51
- package/experimental/TextEditor/extensions/mention/index.ts +0 -1
- package/experimental/TextEditor/extensions/mention/mention-extension.ts +0 -204
- package/experimental/TextEditor/extensions/mention/style.css +0 -11
- package/experimental/TextEditor/extensions/shared/color-utils.ts +0 -236
- package/experimental/TextEditor/extensions/slash-commands/SlashCommandsList.vue +0 -59
- package/experimental/TextEditor/extensions/slash-commands/slash-commands-extension.ts +0 -184
- package/experimental/TextEditor/extensions/suggestion/SuggestionList.vue +0 -130
- package/experimental/TextEditor/extensions/suggestion/createSuggestionExtension.ts +0 -151
- package/experimental/TextEditor/extensions/suggestion/index.ts +0 -5
- package/experimental/TextEditor/extensions/tag/index.ts +0 -1
- package/experimental/TextEditor/extensions/tag/tag-extension.ts +0 -170
- package/experimental/TextEditor/extensions/toc-node/TocNodeView.vue +0 -439
- package/experimental/TextEditor/extensions/toc-node/index.ts +0 -3
- package/experimental/TextEditor/extensions/toc-node/toc-node-extension.ts +0 -167
- package/experimental/TextEditor/extensions/video-extension.ts +0 -653
- package/experimental/TextEditor/hljs-github.css +0 -197
- package/experimental/TextEditor/index.ts +0 -21
- package/experimental/TextEditor/style.css +0 -190
- package/experimental/TextEditor/types.ts +0 -72
- package/experimental/TextEditor/utils.js +0 -11
- package/src/utils/url-validation.ts +0 -39
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Stepper
|
|
2
|
+
|
|
3
|
+
Shows where a person or a process is in an ordered sequence of steps.
|
|
4
|
+
|
|
5
|
+
> **Experimental** — `Stepper` ships from
|
|
6
|
+
> [`frappe-ui/experimental`](/docs/experimental) while its API is reviewed and
|
|
7
|
+
> refined, so it is exempt from the usual deprecation policy and can change
|
|
8
|
+
> shape or disappear in any release.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { Stepper } from 'frappe-ui/experimental'
|
|
12
|
+
import type { StepItem, StepperProps } from 'frappe-ui/experimental'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
<ComponentPlayground name="Stepper" />
|
|
16
|
+
|
|
17
|
+
## Examples
|
|
18
|
+
|
|
19
|
+
### Setup wizard
|
|
20
|
+
|
|
21
|
+
`clickable` turns finished steps into buttons, so a person can go back. A step
|
|
22
|
+
marked `skipped` shows as passed, without a check.
|
|
23
|
+
|
|
24
|
+
<ComponentPreview name="Stepper-Wizard" />
|
|
25
|
+
|
|
26
|
+
### Plain
|
|
27
|
+
|
|
28
|
+
`vertical` with nothing else: the step number sits inside every step that is not
|
|
29
|
+
finished yet.
|
|
30
|
+
|
|
31
|
+
<ComponentPreview name="Stepper-Plain" />
|
|
32
|
+
|
|
33
|
+
### Run progress with sub-steps
|
|
34
|
+
|
|
35
|
+
A step with `children` gets its own line of sub-steps. `loading` spins the
|
|
36
|
+
outline of the current step's circle; `failed` marks it failed. `edge="end"`
|
|
37
|
+
puts the indicators after the labels.
|
|
38
|
+
|
|
39
|
+
<ComponentPreview name="Stepper-RunProgress" />
|
|
40
|
+
|
|
41
|
+
### Compact
|
|
42
|
+
|
|
43
|
+
`size="sm"` for a sidebar or a run log. `meta` shows trailing text such as a
|
|
44
|
+
duration.
|
|
45
|
+
|
|
46
|
+
<ComponentPreview name="Stepper-Compact" />
|
|
47
|
+
|
|
48
|
+
### Segmented
|
|
49
|
+
|
|
50
|
+
Without `vertical`, the stepper is the stock `Progress` with one interval per
|
|
51
|
+
step, and the labels underneath. Sub-steps are not shown.
|
|
52
|
+
|
|
53
|
+
<ComponentPreview name="Stepper-Segmented" />
|
|
54
|
+
|
|
55
|
+
## Behavior
|
|
56
|
+
|
|
57
|
+
### Current step
|
|
58
|
+
|
|
59
|
+
`v-model` holds the current step's value, which can be a sub-step's value. Every
|
|
60
|
+
step before it shows as done and every step after it as upcoming. An empty
|
|
61
|
+
value, or one that matches no step, shows every step as upcoming. `completed`
|
|
62
|
+
shows every step as done.
|
|
63
|
+
|
|
64
|
+
A step with sub-steps follows them: done once every sub-step is done or skipped,
|
|
65
|
+
current while it holds the current sub-step. Naming the parent itself makes its
|
|
66
|
+
first sub-step current.
|
|
67
|
+
|
|
68
|
+
### Skipped steps
|
|
69
|
+
|
|
70
|
+
Set `skipped` on a step the flow passed without doing. It shows as skipped once
|
|
71
|
+
the current step is past it, and as upcoming before that. The line through a
|
|
72
|
+
skipped step fills like a finished one.
|
|
73
|
+
|
|
74
|
+
### Running and failed
|
|
75
|
+
|
|
76
|
+
`loading` and `failed` describe the current step. `loading` keeps the circle and
|
|
77
|
+
its number still and moves a short arc around the outline. It stops under
|
|
78
|
+
reduced motion.
|
|
79
|
+
|
|
80
|
+
### Going back
|
|
81
|
+
|
|
82
|
+
With `clickable`, finished and skipped steps are buttons. Clicking one emits
|
|
83
|
+
`update:modelValue` with its value. While `completed` is set, no step is a
|
|
84
|
+
button, because `completed` overrides the value a click would set. The stepper
|
|
85
|
+
never moves on its own: the caller decides what the next step is.
|
|
86
|
+
|
|
87
|
+
## Accessibility
|
|
88
|
+
|
|
89
|
+
The steps are an ordered list, and sub-steps a nested list. The current step has
|
|
90
|
+
`aria-current="step"`. Each indicator carries a hidden word for its state
|
|
91
|
+
("completed", "running", "skipped", …), so the list reads without the icons.
|
|
92
|
+
With `clickable`, finished steps are buttons you can reach with Tab and press
|
|
93
|
+
with Enter or Space.
|
|
94
|
+
|
|
95
|
+
<!-- @include: ./Stepper.api.md -->
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
data-slot="stepper"
|
|
4
|
+
:data-orientation="vertical ? 'vertical' : 'horizontal'"
|
|
5
|
+
:data-size="size"
|
|
6
|
+
:data-edge="vertical ? edge : undefined"
|
|
7
|
+
:data-loading="loading || undefined"
|
|
8
|
+
>
|
|
9
|
+
<component
|
|
10
|
+
:is="vertical ? StepperVertical : StepperHorizontal"
|
|
11
|
+
:steps="resolved"
|
|
12
|
+
:size="size"
|
|
13
|
+
:loading="loading"
|
|
14
|
+
:clickable="clickable && !completed"
|
|
15
|
+
v-bind="vertical ? { edge, substeps } : {}"
|
|
16
|
+
@select="select"
|
|
17
|
+
>
|
|
18
|
+
<template v-if="$slots['step-prefix']" #step-prefix="slotProps">
|
|
19
|
+
<slot name="step-prefix" v-bind="slotProps" />
|
|
20
|
+
</template>
|
|
21
|
+
<template v-if="$slots['step-label']" #step-label="slotProps">
|
|
22
|
+
<slot name="step-label" v-bind="slotProps" />
|
|
23
|
+
</template>
|
|
24
|
+
<template v-if="$slots['step-description']" #step-description="slotProps">
|
|
25
|
+
<slot name="step-description" v-bind="slotProps" />
|
|
26
|
+
</template>
|
|
27
|
+
<template v-if="$slots['step-suffix']" #step-suffix="slotProps">
|
|
28
|
+
<slot name="step-suffix" v-bind="slotProps" />
|
|
29
|
+
</template>
|
|
30
|
+
</component>
|
|
31
|
+
</div>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<script setup lang="ts">
|
|
35
|
+
import { computed } from 'vue'
|
|
36
|
+
import StepperHorizontal from './StepperHorizontal.vue'
|
|
37
|
+
import StepperVertical from './StepperVertical.vue'
|
|
38
|
+
import { resolveSteps } from './resolve'
|
|
39
|
+
import type {
|
|
40
|
+
StepSlotProps,
|
|
41
|
+
StepValue,
|
|
42
|
+
StepperEmits,
|
|
43
|
+
StepperProps,
|
|
44
|
+
} from './types'
|
|
45
|
+
|
|
46
|
+
const props = withDefaults(defineProps<StepperProps>(), {
|
|
47
|
+
modelValue: null,
|
|
48
|
+
completed: false,
|
|
49
|
+
loading: false,
|
|
50
|
+
failed: false,
|
|
51
|
+
vertical: false,
|
|
52
|
+
edge: 'start',
|
|
53
|
+
size: 'md',
|
|
54
|
+
substeps: 'all',
|
|
55
|
+
clickable: false,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const emit = defineEmits<StepperEmits>()
|
|
59
|
+
|
|
60
|
+
defineSlots<{
|
|
61
|
+
/** Replaces a step's indicator. */
|
|
62
|
+
'step-prefix'?: (props: StepSlotProps) => any
|
|
63
|
+
/** Replaces a step's label. */
|
|
64
|
+
'step-label'?: (props: StepSlotProps) => any
|
|
65
|
+
/** Replaces a step's description (vertical only). */
|
|
66
|
+
'step-description'?: (props: StepSlotProps) => any
|
|
67
|
+
/** Replaces a step's trailing meta text (vertical only). */
|
|
68
|
+
'step-suffix'?: (props: StepSlotProps) => any
|
|
69
|
+
}>()
|
|
70
|
+
|
|
71
|
+
const resolved = computed(() =>
|
|
72
|
+
resolveSteps(props.steps, {
|
|
73
|
+
current: props.modelValue,
|
|
74
|
+
completed: props.completed,
|
|
75
|
+
failed: props.failed,
|
|
76
|
+
}),
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
function select(value: StepValue) {
|
|
80
|
+
if (value !== props.modelValue) emit('update:modelValue', value)
|
|
81
|
+
}
|
|
82
|
+
</script>
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<!-- The stock Progress, used as it ships: one interval per step. -->
|
|
4
|
+
<Progress :value="value" :intervals="steps.length" />
|
|
5
|
+
<ol class="mt-2.5 grid auto-cols-fr grid-flow-col gap-x-1">
|
|
6
|
+
<li
|
|
7
|
+
v-for="(step, i) in steps"
|
|
8
|
+
:key="step.item.value"
|
|
9
|
+
data-slot="step"
|
|
10
|
+
:data-state="step.state"
|
|
11
|
+
:aria-current="isCurrent(step) ? 'step' : undefined"
|
|
12
|
+
class="min-w-0"
|
|
13
|
+
>
|
|
14
|
+
<component
|
|
15
|
+
:is="isButton(step) ? 'button' : 'div'"
|
|
16
|
+
:type="isButton(step) ? 'button' : undefined"
|
|
17
|
+
class="flex w-full min-w-0 items-center gap-1.5 text-start"
|
|
18
|
+
:class="isButton(step) && BUTTON"
|
|
19
|
+
@click="isButton(step) && emit('select', step.item.value)"
|
|
20
|
+
>
|
|
21
|
+
<slot name="step-prefix" v-bind="slotProps(step)">
|
|
22
|
+
<StepIndicator
|
|
23
|
+
:state="step.state"
|
|
24
|
+
:size="indicator"
|
|
25
|
+
:loading="loading"
|
|
26
|
+
:index="i"
|
|
27
|
+
/>
|
|
28
|
+
</slot>
|
|
29
|
+
<slot name="step-label" v-bind="slotProps(step)">
|
|
30
|
+
<span
|
|
31
|
+
class="truncate transition-colors group-hover:text-ink-gray-9 motion-reduce:transition-none"
|
|
32
|
+
:class="[title, TITLE[step.state]]"
|
|
33
|
+
:title="step.item.label"
|
|
34
|
+
>
|
|
35
|
+
{{ step.item.label }}
|
|
36
|
+
</span>
|
|
37
|
+
</slot>
|
|
38
|
+
</component>
|
|
39
|
+
</li>
|
|
40
|
+
</ol>
|
|
41
|
+
</div>
|
|
42
|
+
</template>
|
|
43
|
+
|
|
44
|
+
<script setup lang="ts">
|
|
45
|
+
import { computed } from 'vue'
|
|
46
|
+
import { Progress } from '../../src/components/Progress'
|
|
47
|
+
import StepIndicator from './StepIndicator.vue'
|
|
48
|
+
import { isPassed } from './resolve'
|
|
49
|
+
import type { ResolvedStep, StepState, StepValue, StepperSize } from './types'
|
|
50
|
+
|
|
51
|
+
const props = defineProps<{
|
|
52
|
+
steps: ResolvedStep[]
|
|
53
|
+
size: StepperSize
|
|
54
|
+
loading: boolean
|
|
55
|
+
clickable: boolean
|
|
56
|
+
}>()
|
|
57
|
+
|
|
58
|
+
const emit = defineEmits<{ select: [value: StepValue] }>()
|
|
59
|
+
|
|
60
|
+
const TITLE: Record<StepState, string> = {
|
|
61
|
+
complete: 'text-ink-gray-7',
|
|
62
|
+
current: 'text-ink-gray-9',
|
|
63
|
+
failed: 'text-ink-gray-9',
|
|
64
|
+
upcoming: 'text-ink-gray-5',
|
|
65
|
+
skipped: 'text-ink-gray-5',
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const BUTTON = [
|
|
69
|
+
// Hover darkens the label, no fill; the inset gives the focus ring room.
|
|
70
|
+
'group -mx-1 w-[calc(100%+0.5rem)] px-1 rounded-4 cursor-pointer',
|
|
71
|
+
'focus-visible:focus-ring',
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
const indicator = computed(() => (props.size === 'sm' ? 'xs' : 'sm'))
|
|
75
|
+
const title = computed(() =>
|
|
76
|
+
props.size === 'sm' ? 'text-sm' : 'text-sm-medium',
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
/** An interval fills once its step is done or skipped. */
|
|
80
|
+
const value = computed(() => {
|
|
81
|
+
const passed = props.steps.filter((s) => isPassed(s.state)).length
|
|
82
|
+
return props.steps.length ? (passed / props.steps.length) * 100 : 0
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const isCurrent = (step: ResolvedStep) =>
|
|
86
|
+
step.state === 'current' || step.state === 'failed'
|
|
87
|
+
const isButton = (step: ResolvedStep) => props.clickable && isPassed(step.state)
|
|
88
|
+
const slotProps = (step: ResolvedStep) => ({
|
|
89
|
+
item: step.item,
|
|
90
|
+
index: step.index,
|
|
91
|
+
state: step.state,
|
|
92
|
+
})
|
|
93
|
+
</script>
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ol class="flex flex-col" :data-edge="edge">
|
|
3
|
+
<li
|
|
4
|
+
v-for="(step, i) in steps"
|
|
5
|
+
:key="step.item.value"
|
|
6
|
+
data-slot="step"
|
|
7
|
+
:data-state="step.state"
|
|
8
|
+
:aria-current="isCurrent(step) ? 'step' : undefined"
|
|
9
|
+
>
|
|
10
|
+
<!-- Only phrasing content inside, so the row is valid as a <button>. -->
|
|
11
|
+
<component
|
|
12
|
+
:is="isButton(step) ? 'button' : 'div'"
|
|
13
|
+
:type="isButton(step) ? 'button' : undefined"
|
|
14
|
+
class="flex items-stretch text-start"
|
|
15
|
+
:class="[rowDirection, headClass(step)]"
|
|
16
|
+
@click="isButton(step) && emit('select', step.item.value)"
|
|
17
|
+
>
|
|
18
|
+
<span
|
|
19
|
+
class="flex min-w-0 flex-1 flex-col justify-center"
|
|
20
|
+
:class="[textAlign, ui.headPad]"
|
|
21
|
+
>
|
|
22
|
+
<slot name="step-label" v-bind="slotProps(step)">
|
|
23
|
+
<span
|
|
24
|
+
class="break-words transition-colors group-hover:text-ink-gray-9 motion-reduce:transition-none"
|
|
25
|
+
:class="[ui.title, TITLE[step.state]]"
|
|
26
|
+
>{{ step.item.label }}</span
|
|
27
|
+
>
|
|
28
|
+
</slot>
|
|
29
|
+
<slot name="step-description" v-bind="slotProps(step)">
|
|
30
|
+
<span
|
|
31
|
+
v-if="step.item.description"
|
|
32
|
+
class="mt-px text-sm transition-colors group-hover:text-ink-gray-6 motion-reduce:transition-none"
|
|
33
|
+
:class="CAPTION[step.state]"
|
|
34
|
+
>
|
|
35
|
+
{{ step.item.description }}
|
|
36
|
+
</span>
|
|
37
|
+
</slot>
|
|
38
|
+
</span>
|
|
39
|
+
<span
|
|
40
|
+
v-if="step.item.meta || $slots['step-suffix']"
|
|
41
|
+
class="order-first self-center text-sm tabular-nums text-ink-gray-5"
|
|
42
|
+
:class="metaGap"
|
|
43
|
+
>
|
|
44
|
+
<slot name="step-suffix" v-bind="slotProps(step)">{{
|
|
45
|
+
step.item.meta
|
|
46
|
+
}}</slot>
|
|
47
|
+
</span>
|
|
48
|
+
<span
|
|
49
|
+
class="flex shrink-0 flex-col items-center"
|
|
50
|
+
:class="[ui.railWidth, railGap]"
|
|
51
|
+
>
|
|
52
|
+
<span
|
|
53
|
+
class="fui-stepper-seg"
|
|
54
|
+
:class="ui.segTop"
|
|
55
|
+
v-bind="segAttrs(i, 'top')"
|
|
56
|
+
/>
|
|
57
|
+
<slot name="step-prefix" v-bind="slotProps(step)">
|
|
58
|
+
<StepIndicator
|
|
59
|
+
:state="step.state"
|
|
60
|
+
:size="ui.indicator"
|
|
61
|
+
:loading="loading"
|
|
62
|
+
:index="i"
|
|
63
|
+
/>
|
|
64
|
+
</slot>
|
|
65
|
+
<span
|
|
66
|
+
class="fui-stepper-seg"
|
|
67
|
+
:class="ui.segBottom"
|
|
68
|
+
v-bind="segAttrs(i, 'bottom')"
|
|
69
|
+
/>
|
|
70
|
+
</span>
|
|
71
|
+
</component>
|
|
72
|
+
|
|
73
|
+
<div
|
|
74
|
+
v-if="showChildren(step)"
|
|
75
|
+
class="flex items-stretch"
|
|
76
|
+
:class="[rowDirection, bleed]"
|
|
77
|
+
>
|
|
78
|
+
<ol class="min-w-0 flex-1" :class="[textAlign, ui.subGap]">
|
|
79
|
+
<li
|
|
80
|
+
v-for="(child, j) in step.children"
|
|
81
|
+
:key="child.item.value"
|
|
82
|
+
data-slot="step"
|
|
83
|
+
:data-state="child.state"
|
|
84
|
+
:aria-current="isCurrent(child) ? 'step' : undefined"
|
|
85
|
+
class="flex items-center gap-2.5"
|
|
86
|
+
:class="rowDirection"
|
|
87
|
+
>
|
|
88
|
+
<span class="min-w-0 flex-1" :class="ui.subPad">
|
|
89
|
+
<slot name="step-label" v-bind="slotProps(child)">
|
|
90
|
+
<span
|
|
91
|
+
class="break-words"
|
|
92
|
+
:class="[ui.sub, SUB_TITLE[child.state]]"
|
|
93
|
+
>{{ child.item.label }}</span
|
|
94
|
+
>
|
|
95
|
+
</slot>
|
|
96
|
+
</span>
|
|
97
|
+
<span
|
|
98
|
+
class="flex shrink-0 flex-col items-center self-stretch"
|
|
99
|
+
:class="ui.subRailWidth"
|
|
100
|
+
>
|
|
101
|
+
<span
|
|
102
|
+
class="fui-stepper-seg mb-px"
|
|
103
|
+
v-bind="subSegAttrs(step, j, 'top')"
|
|
104
|
+
/>
|
|
105
|
+
<slot name="step-prefix" v-bind="slotProps(child)">
|
|
106
|
+
<StepIndicator
|
|
107
|
+
:state="child.state"
|
|
108
|
+
:size="ui.subIndicator"
|
|
109
|
+
:loading="loading"
|
|
110
|
+
/>
|
|
111
|
+
</slot>
|
|
112
|
+
<span
|
|
113
|
+
class="fui-stepper-seg mt-px"
|
|
114
|
+
v-bind="subSegAttrs(step, j, 'bottom')"
|
|
115
|
+
/>
|
|
116
|
+
</span>
|
|
117
|
+
</li>
|
|
118
|
+
</ol>
|
|
119
|
+
<div
|
|
120
|
+
class="flex shrink-0 flex-col items-center"
|
|
121
|
+
:class="[ui.railWidth, railGap]"
|
|
122
|
+
>
|
|
123
|
+
<span class="fui-stepper-seg" v-bind="segAttrs(i, 'through')" />
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
</li>
|
|
127
|
+
</ol>
|
|
128
|
+
</template>
|
|
129
|
+
|
|
130
|
+
<script setup lang="ts">
|
|
131
|
+
import { computed } from 'vue'
|
|
132
|
+
import StepIndicator from './StepIndicator.vue'
|
|
133
|
+
import { isPassed } from './resolve'
|
|
134
|
+
import type {
|
|
135
|
+
ResolvedStep,
|
|
136
|
+
StepState,
|
|
137
|
+
StepValue,
|
|
138
|
+
StepperEdge,
|
|
139
|
+
StepperSize,
|
|
140
|
+
} from './types'
|
|
141
|
+
|
|
142
|
+
const props = defineProps<{
|
|
143
|
+
steps: ResolvedStep[]
|
|
144
|
+
edge: StepperEdge
|
|
145
|
+
size: StepperSize
|
|
146
|
+
loading: boolean
|
|
147
|
+
clickable: boolean
|
|
148
|
+
substeps: 'all' | 'current'
|
|
149
|
+
}>()
|
|
150
|
+
|
|
151
|
+
const emit = defineEmits<{ select: [value: StepValue] }>()
|
|
152
|
+
|
|
153
|
+
const TITLE: Record<StepState, string> = {
|
|
154
|
+
complete: 'text-ink-gray-7',
|
|
155
|
+
current: 'text-ink-gray-9',
|
|
156
|
+
failed: 'text-ink-gray-9',
|
|
157
|
+
upcoming: 'text-ink-gray-5',
|
|
158
|
+
skipped: 'text-ink-gray-5',
|
|
159
|
+
}
|
|
160
|
+
const SUB_TITLE: Record<StepState, string> = {
|
|
161
|
+
complete: 'text-ink-gray-6',
|
|
162
|
+
current: 'text-ink-gray-9',
|
|
163
|
+
failed: 'text-ink-gray-9',
|
|
164
|
+
upcoming: 'text-ink-gray-4',
|
|
165
|
+
skipped: 'text-ink-gray-4',
|
|
166
|
+
}
|
|
167
|
+
const CAPTION: Record<StepState, string> = {
|
|
168
|
+
complete: 'text-ink-gray-5',
|
|
169
|
+
current: 'text-ink-gray-5',
|
|
170
|
+
failed: 'text-ink-red-7',
|
|
171
|
+
upcoming: 'text-ink-gray-4',
|
|
172
|
+
skipped: 'text-ink-gray-4',
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const SIZES = {
|
|
176
|
+
md: {
|
|
177
|
+
indicator: 'md',
|
|
178
|
+
subIndicator: 'sm',
|
|
179
|
+
title: 'text-base-medium',
|
|
180
|
+
sub: 'text-base',
|
|
181
|
+
headPad: 'py-3',
|
|
182
|
+
subPad: 'py-1.5',
|
|
183
|
+
subGap: 'pb-2.5',
|
|
184
|
+
railWidth: 'w-5',
|
|
185
|
+
subRailWidth: 'w-4',
|
|
186
|
+
segTop: 'mb-0.5',
|
|
187
|
+
segBottom: 'mt-0.5',
|
|
188
|
+
},
|
|
189
|
+
sm: {
|
|
190
|
+
indicator: 'sm',
|
|
191
|
+
subIndicator: 'xs',
|
|
192
|
+
title: 'text-base',
|
|
193
|
+
sub: 'text-sm',
|
|
194
|
+
headPad: 'py-1.5',
|
|
195
|
+
subPad: 'py-1',
|
|
196
|
+
subGap: 'pb-0.5',
|
|
197
|
+
railWidth: 'w-4',
|
|
198
|
+
subRailWidth: 'w-3.5',
|
|
199
|
+
segTop: 'mb-px',
|
|
200
|
+
segBottom: 'mt-px',
|
|
201
|
+
},
|
|
202
|
+
} as const
|
|
203
|
+
|
|
204
|
+
const ui = computed(() => SIZES[props.size])
|
|
205
|
+
// Label first in the DOM so it reads before the indicator's state word;
|
|
206
|
+
// `start` puts the indicator on the leading side visually.
|
|
207
|
+
const rowDirection = computed(() =>
|
|
208
|
+
props.edge === 'start' ? 'flex-row-reverse' : 'flex-row',
|
|
209
|
+
)
|
|
210
|
+
const textAlign = computed(() =>
|
|
211
|
+
props.edge === 'end' ? 'text-end' : 'text-start',
|
|
212
|
+
)
|
|
213
|
+
// Literal classes so Tailwind's scanner generates them.
|
|
214
|
+
const RAIL_GAP = {
|
|
215
|
+
start: { md: 'me-3', sm: 'me-2.5' },
|
|
216
|
+
end: { md: 'ms-3', sm: 'ms-2.5' },
|
|
217
|
+
} as const
|
|
218
|
+
const railGap = computed(() => RAIL_GAP[props.edge][props.size])
|
|
219
|
+
// Meta sits on the far side from the indicators: `order-first` lands it at the
|
|
220
|
+
// row's main start, which `flex-row-reverse` turns into the trailing edge.
|
|
221
|
+
const metaGap = computed(() => (props.edge === 'start' ? 'ms-2' : 'me-2'))
|
|
222
|
+
// With `clickable`, rows bleed 8px each side so the focus ring has room;
|
|
223
|
+
// every row does it, so the lines stay aligned.
|
|
224
|
+
const bleed = computed(() =>
|
|
225
|
+
props.clickable ? '-mx-2 w-[calc(100%+1rem)] px-2' : '',
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
const isCurrent = (step: ResolvedStep) =>
|
|
229
|
+
step.state === 'current' || step.state === 'failed'
|
|
230
|
+
const isButton = (step: ResolvedStep) => props.clickable && isPassed(step.state)
|
|
231
|
+
const slotProps = (step: ResolvedStep) => ({
|
|
232
|
+
item: step.item,
|
|
233
|
+
index: step.index,
|
|
234
|
+
state: step.state,
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
function showChildren(step: ResolvedStep) {
|
|
238
|
+
if (!step.children.length) return false
|
|
239
|
+
return props.substeps === 'all' || isCurrent(step)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function headClass(step: ResolvedStep) {
|
|
243
|
+
if (!isButton(step)) return bleed.value
|
|
244
|
+
return [
|
|
245
|
+
bleed.value,
|
|
246
|
+
// Hover darkens the text (see the label and description), no fill.
|
|
247
|
+
'group rounded-5 cursor-pointer focus-visible:focus-ring',
|
|
248
|
+
]
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** The line before step `i` fills once the step before it is passed. */
|
|
252
|
+
function segAttrs(i: number, part: 'top' | 'bottom' | 'through') {
|
|
253
|
+
const last = i === props.steps.length - 1
|
|
254
|
+
const hidden = part === 'top' ? i === 0 : last
|
|
255
|
+
const owner = part === 'top' ? props.steps[i - 1] : props.steps[i]
|
|
256
|
+
return {
|
|
257
|
+
'data-hidden': hidden || undefined,
|
|
258
|
+
'data-passed': (owner && isPassed(owner.state)) || undefined,
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function subSegAttrs(step: ResolvedStep, j: number, part: 'top' | 'bottom') {
|
|
263
|
+
const hidden = part === 'top' ? j === 0 : j === step.children.length - 1
|
|
264
|
+
const owner = part === 'top' ? step.children[j - 1] : step.children[j]
|
|
265
|
+
return {
|
|
266
|
+
'data-hidden': hidden || undefined,
|
|
267
|
+
'data-passed': (owner && isPassed(owner.state)) || undefined,
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
</script>
|
|
271
|
+
|
|
272
|
+
<style scoped>
|
|
273
|
+
.fui-stepper-seg {
|
|
274
|
+
flex: 1 1 0;
|
|
275
|
+
width: 1px;
|
|
276
|
+
min-height: 0;
|
|
277
|
+
background: var(--outline-gray-2);
|
|
278
|
+
transition: background-color 300ms ease;
|
|
279
|
+
}
|
|
280
|
+
.fui-stepper-seg[data-passed] {
|
|
281
|
+
background: var(--surface-gray-10);
|
|
282
|
+
}
|
|
283
|
+
.fui-stepper-seg[data-hidden] {
|
|
284
|
+
visibility: hidden;
|
|
285
|
+
}
|
|
286
|
+
@media (prefers-reduced-motion: reduce) {
|
|
287
|
+
.fui-stepper-seg {
|
|
288
|
+
transition: none;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
</style>
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { ResolvedStep, StepItem, StepState, StepValue } from './types'
|
|
2
|
+
|
|
3
|
+
interface ResolveOptions {
|
|
4
|
+
current?: StepValue | null
|
|
5
|
+
completed?: boolean
|
|
6
|
+
failed?: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type Position = 'before' | 'at' | 'after'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Walks the steps depth-first (a step, then its sub-steps) and returns the
|
|
13
|
+
* order-sensitive list of leaves: steps without sub-steps, and sub-steps.
|
|
14
|
+
* Only the first level of `children` counts.
|
|
15
|
+
*/
|
|
16
|
+
function leavesOf(steps: StepItem[]): StepItem[] {
|
|
17
|
+
return steps.flatMap((step) =>
|
|
18
|
+
step.children?.length ? step.children : [step],
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Index of the current leaf. Naming a parent makes its first sub-step current.
|
|
24
|
+
* Returns -1 when nothing matches, `leaves.length` when everything is done.
|
|
25
|
+
*/
|
|
26
|
+
function currentIndex(steps: StepItem[], opts: ResolveOptions): number {
|
|
27
|
+
const leaves = leavesOf(steps)
|
|
28
|
+
if (opts.completed) return leaves.length
|
|
29
|
+
if (opts.current == null) return -1
|
|
30
|
+
const parent = steps.find(
|
|
31
|
+
(s) => s.value === opts.current && s.children?.length,
|
|
32
|
+
)
|
|
33
|
+
const target = parent ? parent.children![0].value : opts.current
|
|
34
|
+
return leaves.findIndex((leaf) => leaf.value === target)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function leafState(
|
|
38
|
+
item: StepItem,
|
|
39
|
+
position: Position,
|
|
40
|
+
failed?: boolean,
|
|
41
|
+
): StepState {
|
|
42
|
+
if (position === 'at') return failed ? 'failed' : 'current'
|
|
43
|
+
if (position === 'after') return 'upcoming'
|
|
44
|
+
return item.skipped ? 'skipped' : 'complete'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A parent's state follows its sub-steps. */
|
|
48
|
+
function parentState(item: StepItem, children: ResolvedStep[]): StepState {
|
|
49
|
+
const states = children.map((c) => c.state)
|
|
50
|
+
if (states.some((s) => s === 'current' || s === 'failed')) {
|
|
51
|
+
return states.includes('failed') ? 'failed' : 'current'
|
|
52
|
+
}
|
|
53
|
+
if (states.every((s) => s === 'complete' || s === 'skipped')) {
|
|
54
|
+
return item.skipped ? 'skipped' : 'complete'
|
|
55
|
+
}
|
|
56
|
+
return 'upcoming'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Derives every step's state from the current value. Never mutates `steps`. */
|
|
60
|
+
export function resolveSteps(
|
|
61
|
+
steps: StepItem[],
|
|
62
|
+
opts: ResolveOptions,
|
|
63
|
+
): ResolvedStep[] {
|
|
64
|
+
const current = currentIndex(steps, opts)
|
|
65
|
+
let cursor = 0
|
|
66
|
+
const positionOf = (): Position => {
|
|
67
|
+
const i = cursor++
|
|
68
|
+
if (current === -1 || i > current) return 'after'
|
|
69
|
+
return i === current ? 'at' : 'before'
|
|
70
|
+
}
|
|
71
|
+
const leaf = (item: StepItem, index: number): ResolvedStep => ({
|
|
72
|
+
item,
|
|
73
|
+
index,
|
|
74
|
+
state: leafState(item, positionOf(), opts.failed),
|
|
75
|
+
children: [],
|
|
76
|
+
})
|
|
77
|
+
return steps.map((item, index) => {
|
|
78
|
+
if (!item.children?.length) return leaf(item, index)
|
|
79
|
+
const children = item.children.map(leaf)
|
|
80
|
+
return { item, index, state: parentState(item, children), children }
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Done or skipped: progress has moved past it. */
|
|
85
|
+
export function isPassed(state: StepState): boolean {
|
|
86
|
+
return state === 'complete' || state === 'skipped'
|
|
87
|
+
}
|