frappe-ui 1.0.2 → 1.1.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.
Files changed (96) hide show
  1. package/experimental/Calendar/calendarUtils.ts +33 -21
  2. package/experimental/MultiEmailInput/MultiEmailInput.vue +64 -12
  3. package/experimental/MultiEmailInput/types.ts +12 -3
  4. package/experimental/Stepper/StepIndicator.vue +129 -0
  5. package/experimental/Stepper/Stepper.api.md +117 -0
  6. package/experimental/Stepper/Stepper.md +95 -0
  7. package/experimental/Stepper/Stepper.vue +82 -0
  8. package/experimental/Stepper/StepperHorizontal.vue +93 -0
  9. package/experimental/Stepper/StepperVertical.vue +291 -0
  10. package/experimental/Stepper/index.ts +11 -0
  11. package/experimental/Stepper/resolve.ts +87 -0
  12. package/experimental/Stepper/types.ts +89 -0
  13. package/experimental.ts +2 -0
  14. package/package.json +1 -1
  15. package/src/charts/CalendarHeatmapChart.vue +353 -0
  16. package/src/charts/DonutChart.vue +34 -58
  17. package/src/charts/HeatmapChart.vue +26 -64
  18. package/src/charts/NumberCard.vue +62 -7
  19. package/src/charts/PercentageBarChart.vue +243 -0
  20. package/src/charts/SankeyChart.vue +14 -11
  21. package/src/charts/ScatterChart.vue +24 -20
  22. package/src/charts/axisChartCommon.ts +182 -18
  23. package/src/charts/axisFormat.ts +8 -3
  24. package/src/charts/calendarHeatmapOptions.ts +604 -0
  25. package/src/charts/colorMath.ts +26 -0
  26. package/src/charts/components/ChartContainer.vue +63 -53
  27. package/src/charts/components/ChartLegend.vue +216 -24
  28. package/src/charts/components/ChartScale.vue +85 -0
  29. package/src/charts/core/dataLabelFit.ts +45 -6
  30. package/src/charts/core/useAxisChart.ts +36 -19
  31. package/src/charts/core/useChart.ts +6 -1
  32. package/src/charts/core/usePlotKeyboard.ts +13 -2
  33. package/src/charts/docs/BarChart.md +11 -3
  34. package/src/charts/docs/CalendarHeatmapChart.api.md +165 -0
  35. package/src/charts/docs/CalendarHeatmapChart.md +33 -0
  36. package/src/charts/docs/ChartContainer.api.md +6 -0
  37. package/src/charts/docs/ChartLegend.api.md +1 -1
  38. package/src/charts/docs/ChartLegend.md +25 -3
  39. package/src/charts/docs/DonutChart.api.md +12 -0
  40. package/src/charts/docs/DonutChart.md +17 -0
  41. package/src/charts/docs/HeatmapChart.api.md +1 -1
  42. package/src/charts/docs/LineChart.md +5 -3
  43. package/src/charts/docs/NumberCard.api.md +6 -0
  44. package/src/charts/docs/NumberCard.md +6 -0
  45. package/src/charts/docs/Overview.md +13 -6
  46. package/src/charts/docs/PercentageBarChart.api.md +148 -0
  47. package/src/charts/docs/PercentageBarChart.md +42 -0
  48. package/src/charts/docs/ScatterChart.md +2 -3
  49. package/src/charts/donutChartOptions.ts +22 -130
  50. package/src/charts/format.ts +4 -1
  51. package/src/charts/heatmapOptions.ts +17 -12
  52. package/src/charts/hiddenSeries.ts +8 -3
  53. package/src/charts/index.ts +12 -0
  54. package/src/charts/legendOverflow.ts +40 -0
  55. package/src/charts/numberCardFormat.ts +19 -13
  56. package/src/charts/referenceLines.ts +2 -1
  57. package/src/charts/scatterOptions.ts +16 -3
  58. package/src/charts/seriesData.ts +8 -3
  59. package/src/charts/slices.ts +228 -0
  60. package/src/charts/tokens.ts +99 -0
  61. package/src/charts/types.ts +318 -9
  62. package/src/components/Avatar/Avatar.md +27 -2
  63. package/src/components/Avatar/Avatar.vue +29 -12
  64. package/src/components/Combobox/Combobox.vue +9 -2
  65. package/src/components/Combobox/ComboboxResults.vue +6 -1
  66. package/src/components/Combobox/utils.ts +2 -1
  67. package/src/components/Dialog/Dialog.md +3 -1
  68. package/src/components/Duration/Duration.api.md +16 -3
  69. package/src/components/Duration/Duration.md +21 -0
  70. package/src/components/Duration/Duration.vue +29 -8
  71. package/src/components/Duration/duration.ts +105 -44
  72. package/src/components/Duration/index.ts +1 -0
  73. package/src/components/Duration/types.ts +30 -1
  74. package/src/components/Menu/utils.ts +3 -2
  75. package/src/components/MultiSelect/MultiSelect.api.md +5 -0
  76. package/src/components/MultiSelect/MultiSelect.vue +34 -0
  77. package/src/components/MultiSelect/MultiSelectResults.vue +3 -4
  78. package/src/components/MultiSelect/types.ts +6 -0
  79. package/src/components/Select/Select.vue +4 -4
  80. package/src/components/Select/utils.ts +1 -0
  81. package/src/components/Switch/Switch.vue +3 -3
  82. package/src/components/shared/selection/utils.ts +8 -1
  83. package/src/data-fetching/useCall/useCall.ts +25 -26
  84. package/src/data-fetching/useFrappeFetch.ts +48 -2
  85. package/src/data-fetching/useList/useList.ts +11 -3
  86. package/src/data-fetching/utils.ts +15 -1
  87. package/src/molecules/editor/components/MediaNodeView.vue +10 -1
  88. package/src/molecules/editor/components/MediaResizeGuide.vue +71 -0
  89. package/src/molecules/editor/components/media-node-view-utils.ts +7 -0
  90. package/src/molecules/editor/composables/useNodeViewResize.ts +142 -10
  91. package/src/molecules/editor/extensions/iframe/IframeNodeView.vue +3 -1
  92. package/src/molecules/editor/useEditor.ts +12 -6
  93. package/src/utils/dialog.ts +37 -14
  94. package/tailwind/content.js +1 -0
  95. package/vite/README.md +5 -3
  96. package/vite/codeLanguages.js +41 -17
@@ -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,11 @@
1
+ export { default as Stepper } from './Stepper.vue'
2
+ export type {
3
+ StepItem,
4
+ StepState,
5
+ StepValue,
6
+ StepperEdge,
7
+ StepperEmits,
8
+ StepperProps,
9
+ StepperSize,
10
+ StepSlotProps,
11
+ } from './types'
@@ -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
+ }
@@ -0,0 +1,89 @@
1
+ export type StepValue = string | number
2
+
3
+ /** A step's state, derived from its position relative to the current step. */
4
+ export type StepState =
5
+ | 'complete'
6
+ | 'current'
7
+ | 'upcoming'
8
+ | 'failed'
9
+ | 'skipped'
10
+
11
+ export type StepperSize = 'sm' | 'md'
12
+ export type StepperEdge = 'start' | 'end'
13
+
14
+ /** A step to render. Holds data only; the stepper never writes to it. */
15
+ export interface StepItem {
16
+ /** Unique across the whole tree, sub-steps included. */
17
+ value: StepValue
18
+
19
+ /** Text shown for the step. */
20
+ label: string
21
+
22
+ /** Second line under the label. */
23
+ description?: string
24
+
25
+ /** Trailing text, such as a duration. */
26
+ meta?: string
27
+
28
+ /** The flow passed this step without doing it. */
29
+ skipped?: boolean
30
+
31
+ /** One level of sub-steps. Deeper nesting is ignored. */
32
+ children?: StepItem[]
33
+ }
34
+
35
+ export interface StepperProps {
36
+ /** Steps in order. */
37
+ steps: StepItem[]
38
+
39
+ /** Value of the current step; may be a sub-step's value. */
40
+ modelValue?: StepValue | null
41
+
42
+ /** Every step is done. Wins over `modelValue`. */
43
+ completed?: boolean
44
+
45
+ /** The current step is running: its indicator's outline spins. */
46
+ loading?: boolean
47
+
48
+ /** The current step failed. */
49
+ failed?: boolean
50
+
51
+ /** Lays the steps out as a vertical list instead of a segmented bar. */
52
+ vertical?: boolean
53
+
54
+ /** Vertical only: the side the indicators sit on. */
55
+ edge?: StepperEdge
56
+
57
+ /** Size of the indicators and text. */
58
+ size?: StepperSize
59
+
60
+ /** Vertical only: show sub-steps for every step, or only the current one. */
61
+ substeps?: 'all' | 'current'
62
+
63
+ /**
64
+ * Finished steps become buttons that set `v-model`. Off while `completed`
65
+ * is set, since `completed` would override the value a click sets.
66
+ */
67
+ clickable?: boolean
68
+ }
69
+
70
+ export interface StepperEmits {
71
+ /** Fired when a finished step is clicked (`clickable` only). */
72
+ 'update:modelValue': [value: StepValue]
73
+ }
74
+
75
+ /** Props every `#step-*` slot receives. */
76
+ export interface StepSlotProps {
77
+ item: StepItem
78
+ /** Position among its siblings. */
79
+ index: number
80
+ state: StepState
81
+ }
82
+
83
+ /** A step with its derived state, as rendered. */
84
+ export interface ResolvedStep {
85
+ item: StepItem
86
+ index: number
87
+ state: StepState
88
+ children: ResolvedStep[]
89
+ }
package/experimental.ts CHANGED
@@ -3,6 +3,8 @@
3
3
  export * from './experimental/Accordion'
4
4
  export * from './experimental/FloatingWindow'
5
5
  export * from './experimental/MultiEmailInput'
6
+ // Stepper. Incubating while its API is reviewed and refined before freezing.
7
+ export * from './experimental/Stepper'
6
8
  export { inputFontSizeClasses } from './src/components/Combobox/utils'
7
9
  export {
8
10
  InputLabel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "frappe-ui",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "A set of components and utilities for rapid UI development",
5
5
  "engines": {
6
6
  "node": ">=20.19.0"