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
@@ -15,10 +15,9 @@
15
15
  },
16
16
  {
17
17
  name: 'placeholder',
18
- description: 'Placeholder shown when the input is empty. Defaults to `1h 30m 45s`.',
18
+ description: 'Placeholder shown when the input is empty. Defaults to `1h 30m` when\n`smallestUnit` is `minute`, and `1h 30m 45s` otherwise.',
19
19
  required: false,
20
- type: 'string',
21
- default: '"1h 30m 45s"'
20
+ type: 'string'
22
21
  },
23
22
  {
24
23
  name: 'format',
@@ -27,6 +26,20 @@
27
26
  type: 'DurationFormat',
28
27
  default: '"short"'
29
28
  },
29
+ {
30
+ name: 'largestUnit',
31
+ description: 'The biggest unit of the `short` and `long` presets and of the edit text.\n`day` shows 93784 as `1d 2h 3m 4s`. Defaults to `hour` (`26h 3m 4s`).',
32
+ required: false,
33
+ type: 'DurationLargestUnit',
34
+ default: '"hour"'
35
+ },
36
+ {
37
+ name: 'smallestUnit',
38
+ description: 'The smallest unit of the `short` and `long` presets and of the edit text.\n`minute` rounds to the nearest minute, and a typed value is saved rounded.\nIn a minute field, a bare number is minutes and `a:b` is hours and\nminutes: `15` is 15 minutes and `1:30` is 1h 30m. Defaults to `second`.',
39
+ required: false,
40
+ type: 'DurationSmallestUnit',
41
+ default: '"second"'
42
+ },
30
43
  {
31
44
  name: 'size',
32
45
  description: 'Visual size of the input. Forwarded to the underlying `TextInput`.',
@@ -32,6 +32,7 @@ in any order.
32
32
  | ------------ | -------------------------------------- | ------------------ |
33
33
  | Short units | `1h 30m 45s`, `1h30m45s`, `45s 1h 30m` | `5445` |
34
34
  | Long units | `1 hour 30 minutes`, `2hrs 15min` | `5400`, `8100` |
35
+ | Days | `1d 2h`, `2 days` | `93600`, `172800` |
35
36
  | Colon | `1:30:45`, `1:30`, `:45` | `5445`, `90`, `45` |
36
37
  | Bare integer | `90` | `90` |
37
38
 
@@ -69,6 +70,26 @@ as units.
69
70
  While the input has focus, it always shows the short notation (`2h 2m 3s`), so
70
71
  the text can be edited and read back the same way whatever the format.
71
72
 
73
+ ### Units
74
+
75
+ `largestUnit` and `smallestUnit` set which units the `short` and `long` presets
76
+ show. The edit text uses the same units. `colon` and templates name their own
77
+ units, so these props do not change them.
78
+
79
+ | Props | `93784` |
80
+ | ------------------------ | ------------- |
81
+ | _(default)_ | `26h 3m 4s` |
82
+ | `largest-unit="day"` | `1d 2h 3m 4s` |
83
+ | `smallest-unit="minute"` | `26h 3m` |
84
+
85
+ With `smallest-unit="minute"`, the value shows rounded to the nearest minute, so
86
+ `3599` shows `1h`. A typed value is saved rounded. A saved value that is not
87
+ edited keeps its seconds.
88
+
89
+ A minute field also reads a bare number as minutes and `a:b` as hours and
90
+ minutes, so `15` saves `900` and `1:30` saves `5400`. `1:30:45` and text with
91
+ units, such as `45s`, read the same as in a seconds field.
92
+
72
93
  ### Label, description and error
73
94
 
74
95
  `label` renders above the field and `description` below it. `error` renders
@@ -10,7 +10,7 @@
10
10
  :disabled="disabled"
11
11
  :size="size"
12
12
  :variant="variant"
13
- :placeholder="placeholder"
13
+ :placeholder="placeholderText"
14
14
  @focus="handleFocus"
15
15
  @blur="handleBlur"
16
16
  @input="handleInput"
@@ -30,12 +30,13 @@
30
30
  <script setup lang="ts">
31
31
  import { computed, nextTick, ref } from 'vue'
32
32
  import { TextInput } from '../TextInput'
33
- import { formatDuration, parseDuration } from './duration'
33
+ import { formatDuration, parseDuration, roundDuration } from './duration'
34
34
  import type { DurationProps, DurationExposed } from './types'
35
35
 
36
36
  const props = withDefaults(defineProps<DurationProps>(), {
37
- placeholder: '1h 30m 45s',
38
37
  format: 'short',
38
+ largestUnit: 'hour',
39
+ smallestUnit: 'second',
39
40
  })
40
41
 
41
42
  const model = defineModel<number | null>({ default: null })
@@ -50,13 +51,25 @@ defineSlots<{
50
51
  const inputRef = ref<InstanceType<typeof TextInput> | null>(null)
51
52
  const isFocused = ref(false)
52
53
  const editValue = ref('')
54
+ const focusValue = ref('')
53
55
  const internalError = ref('')
54
56
  const cancelled = ref(false)
55
57
 
58
+ const units = computed(() => ({
59
+ largestUnit: props.largestUnit,
60
+ smallestUnit: props.smallestUnit,
61
+ }))
62
+
63
+ const placeholderText = computed(
64
+ () =>
65
+ props.placeholder ??
66
+ (props.smallestUnit === 'minute' ? '1h 30m' : '1h 30m 45s'),
67
+ )
68
+
56
69
  const displayValue = computed(() =>
57
70
  isFocused.value || internalError.value
58
71
  ? editValue.value
59
- : formatDuration(model.value, props.format),
72
+ : formatDuration(model.value, props.format, units.value),
60
73
  )
61
74
 
62
75
  function handleFocus() {
@@ -67,7 +80,8 @@ function handleFocus() {
67
80
  isFocused.value = true
68
81
  // Always edit in the canonical "1h 30m 45s" notation so the typed value
69
82
  // round-trips through parseDuration regardless of the display `format`.
70
- editValue.value = formatDuration(model.value, 'short')
83
+ editValue.value = formatDuration(model.value, 'short', units.value)
84
+ focusValue.value = editValue.value
71
85
  internalError.value = ''
72
86
  nextTick(() => inputRef.value?.inputElement?.select())
73
87
  }
@@ -102,6 +116,13 @@ function handleKeydown(event: KeyboardEvent) {
102
116
  function commit() {
103
117
  const raw = editValue.value.trim()
104
118
 
119
+ // The edit text may be rounded, so committing it unchanged would rewrite the value.
120
+ if (raw === focusValue.value) {
121
+ internalError.value = ''
122
+ isFocused.value = false
123
+ return
124
+ }
125
+
105
126
  if (raw === '') {
106
127
  internalError.value = ''
107
128
  isFocused.value = false
@@ -109,10 +130,10 @@ function commit() {
109
130
  return
110
131
  }
111
132
 
112
- const seconds = parseDuration(raw)
133
+ const seconds = parseDuration(raw, units.value)
113
134
  if (seconds === null) {
114
135
  internalError.value =
115
- 'Invalid format. Try: 1h 30m 45s, 1 hour 30 minutes, 1:30:45, 90s'
136
+ 'Invalid format. Try: 1h 30m 45s, 1 hour 30 minutes, 1d 2h, 1:30:45, 90s'
116
137
  // Report the error and let focus leave. The rejected text stays visible
117
138
  // (displayValue tracks the error state) as a reminder, but they aren't
118
139
  // trapped in the field. Re-focusing restarts from the canonical saved
@@ -123,7 +144,7 @@ function commit() {
123
144
 
124
145
  internalError.value = ''
125
146
  isFocused.value = false
126
- model.value = seconds
147
+ model.value = roundDuration(seconds, props.smallestUnit)
127
148
  }
128
149
 
129
150
  defineExpose<DurationExposed>({
@@ -2,7 +2,12 @@
2
2
  // Duration helpers: convert between a seconds value and human-readable text.
3
3
  // ---------------------------------------------------------------------------
4
4
 
5
- import type { DurationFormat } from './types'
5
+ import type {
6
+ DurationFormat,
7
+ DurationLargestUnit,
8
+ DurationSmallestUnit,
9
+ DurationUnits,
10
+ } from './types'
6
11
 
7
12
  /**
8
13
  * Format a duration in seconds as text.
@@ -17,24 +22,41 @@ import type { DurationFormat } from './types'
17
22
  * formatDuration(5445, "h'h' m'm' s's'") // "1h 30m 45s" (template, all parts)
18
23
  * formatDuration(90, "h'h' m'm' s's'") // "0h 1m 30s"
19
24
  * formatDuration(7323, 'hh:mm:ss') // "02:02:03"
25
+ *
26
+ * `units` sets the unit range of the `short` and `long` presets:
27
+ *
28
+ * formatDuration(93784, 'short', { largestUnit: 'day' }) // "1d 2h 3m 4s"
29
+ * formatDuration(93784, 'short', { smallestUnit: 'minute' }) // "26h 3m"
20
30
  */
21
31
  export function formatDuration(
22
32
  totalSeconds: number | null | undefined,
23
33
  format: DurationFormat = 'short',
34
+ units: DurationUnits = {},
24
35
  ): string {
25
36
  if (totalSeconds === null || totalSeconds === undefined) return ''
26
37
 
27
38
  const seconds = Number(totalSeconds)
28
39
  if (Number.isNaN(seconds)) return ''
29
40
 
30
- const hours = Math.floor(seconds / 3600)
31
- const minutes = Math.floor((seconds % 3600) / 60)
32
- const secs = seconds % 60
41
+ const { largestUnit = 'hour', smallestUnit = 'second' } = units
42
+ const isPreset = format === 'short' || format === 'long'
43
+ // `colon` and templates have no day token and show the seconds unrounded.
44
+ const parts = isPreset
45
+ ? splitDuration(seconds, largestUnit, smallestUnit)
46
+ : splitDuration(seconds, 'hour', 'second')
47
+
48
+ if (format === 'short') return formatShort(parts, smallestUnit)
49
+ if (format === 'long') return formatLong(parts, smallestUnit)
50
+ if (format === 'colon') return formatColon(parts)
51
+ return renderTemplate(format, parts)
52
+ }
33
53
 
34
- if (format === 'short') return formatShort(hours, minutes, secs)
35
- if (format === 'long') return formatLong(hours, minutes, secs)
36
- if (format === 'colon') return formatColon(hours, minutes, secs)
37
- return renderTemplate(format, hours, minutes, secs)
54
+ /** Round seconds to the smallest unit, as the presets show them. */
55
+ export function roundDuration(
56
+ seconds: number,
57
+ smallestUnit: DurationSmallestUnit,
58
+ ): number {
59
+ return smallestUnit === 'minute' ? Math.round(seconds / 60) * 60 : seconds
38
60
  }
39
61
 
40
62
  // ---------------------------------------------------------------------------
@@ -48,12 +70,7 @@ export function formatDuration(
48
70
  // "h'h' m'm' s's'" → "1h 30m 45s"
49
71
  // "hh:mm:ss" → "01:30:45"
50
72
  // ---------------------------------------------------------------------------
51
- function renderTemplate(
52
- template: string,
53
- hours: number,
54
- minutes: number,
55
- secs: number,
56
- ): string {
73
+ function renderTemplate(template: string, parts: DurationParts): string {
57
74
  const pad = (value: number) => String(value).padStart(2, '0')
58
75
  let out = ''
59
76
  let i = 0
@@ -79,7 +96,8 @@ function renderTemplate(
79
96
  if (ch === 'h' || ch === 'm' || ch === 's') {
80
97
  let len = 1
81
98
  while (template[i + len] === ch) len++
82
- const value = ch === 'h' ? hours : ch === 'm' ? minutes : secs
99
+ const unit = ch === 'h' ? 'hour' : ch === 'm' ? 'minute' : 'second'
100
+ const value = parts[unit]
83
101
  out += len >= 2 ? pad(value) : String(value)
84
102
  i += len
85
103
  continue
@@ -92,53 +110,94 @@ function renderTemplate(
92
110
  return out
93
111
  }
94
112
 
95
- function formatShort(hours: number, minutes: number, secs: number): string {
96
- const parts: string[] = []
97
- if (hours) parts.push(`${hours}h`)
98
- if (minutes) parts.push(`${minutes}m`)
99
- if (secs) parts.push(`${secs}s`)
100
- return parts.length ? parts.join(' ') : '0s'
113
+ type DurationPartUnit = 'day' | 'hour' | 'minute' | 'second'
114
+ type DurationParts = Record<DurationPartUnit, number>
115
+
116
+ const PART_UNITS: DurationPartUnit[] = ['day', 'hour', 'minute', 'second']
117
+ const SHORT_LABELS: Record<DurationPartUnit, string> = {
118
+ day: 'd',
119
+ hour: 'h',
120
+ minute: 'm',
121
+ second: 's',
122
+ }
123
+
124
+ function splitDuration(
125
+ totalSeconds: number,
126
+ largestUnit: DurationLargestUnit,
127
+ smallestUnit: DurationSmallestUnit,
128
+ ): DurationParts {
129
+ const seconds = roundDuration(totalSeconds, smallestUnit)
130
+ const day = largestUnit === 'day' ? Math.floor(seconds / 86400) : 0
131
+ return {
132
+ day,
133
+ hour: Math.floor((seconds - day * 86400) / 3600),
134
+ minute: Math.floor((seconds % 3600) / 60),
135
+ second: seconds % 60,
136
+ }
101
137
  }
102
138
 
103
- function formatLong(hours: number, minutes: number, secs: number): string {
104
- const parts: string[] = []
105
- if (hours) parts.push(hours === 1 ? '1 hour' : `${hours} hours`)
106
- if (minutes) parts.push(minutes === 1 ? '1 minute' : `${minutes} minutes`)
107
- if (secs) parts.push(secs === 1 ? '1 second' : `${secs} seconds`)
108
- return parts.length ? parts.join(' ') : '0 seconds'
139
+ function formatShort(
140
+ parts: DurationParts,
141
+ smallestUnit: DurationPartUnit,
142
+ ): string {
143
+ const text = PART_UNITS.filter((unit) => parts[unit]).map(
144
+ (unit) => `${parts[unit]}${SHORT_LABELS[unit]}`,
145
+ )
146
+ return text.length ? text.join(' ') : `0${SHORT_LABELS[smallestUnit]}`
109
147
  }
110
148
 
111
- function formatColon(hours: number, minutes: number, secs: number): string {
149
+ function formatLong(
150
+ parts: DurationParts,
151
+ smallestUnit: DurationPartUnit,
152
+ ): string {
153
+ const text = PART_UNITS.filter((unit) => parts[unit]).map((unit) =>
154
+ parts[unit] === 1 ? `1 ${unit}` : `${parts[unit]} ${unit}s`,
155
+ )
156
+ return text.length ? text.join(' ') : `0 ${smallestUnit}s`
157
+ }
158
+
159
+ function formatColon({ hour, minute, second }: DurationParts): string {
112
160
  const pad = (value: number) => String(value).padStart(2, '0')
113
- if (hours) return `${hours}:${pad(minutes)}:${pad(secs)}`
114
- return `${minutes}:${pad(secs)}`
161
+ if (hour) return `${hour}:${pad(minute)}:${pad(second)}`
162
+ return `${minute}:${pad(second)}`
115
163
  }
116
164
 
117
165
  // ---------------------------------------------------------------------------
118
166
  // Parse: human-readable string → seconds (integer) or null if invalid.
119
167
  //
120
168
  // Supported formats (case-insensitive, spaces optional, any unit order):
121
- // 1h 30m 45s | 4m 3h 4s | 4sec 3hour 4min | 1h30m45s
169
+ // 1h 30m 45s | 4m 3h 4s | 4sec 3hour 4min | 1h30m45s | 1d 2h | 2 days
122
170
  // 1:30:45 | 1:30 | :45
123
- // 90 | 90s (bare integer treated as seconds)
171
+ // 90 | 90s
172
+ //
173
+ // A bare integer and the last colon group are read in the smallest unit:
174
+ // `90` is 90 seconds and `1:30` is 1m 30s by default, but with
175
+ // `smallestUnit: 'minute'` `90` is 90 minutes and `1:30` is 1h 30m.
176
+ // `1:30:45` is always h:m:s, and named units (`90s`) always keep their unit.
124
177
  // ---------------------------------------------------------------------------
125
- export function parseDuration(str: string): number | null {
178
+ export function parseDuration(
179
+ str: string,
180
+ units: DurationUnits = {},
181
+ ): number | null {
126
182
  const input = str.trim().toLowerCase()
127
183
  if (!input) return null
128
184
 
129
- const colonSeconds = parseColon(input)
185
+ const unitSeconds = units.smallestUnit === 'minute' ? 60 : 1
186
+
187
+ const colonSeconds = parseColon(input, unitSeconds)
130
188
  if (colonSeconds !== null) return colonSeconds
131
189
 
132
- // Bare integer: treated as seconds.
133
- if (/^\d+$/.test(input)) return parseInt(input, 10)
190
+ if (/^\d+$/.test(input)) return parseInt(input, 10) * unitSeconds
134
191
 
135
192
  return parseUnits(input)
136
193
  }
137
194
 
138
- // Colon-separated: h:m:s or m:s or :s. Groups are not bounded to 0-59:
139
- // out-of-range parts overflow by design, so "1:75" parses to 135s (1m + 75s)
140
- // and "5:99" to 399s. This mirrors stopwatch-style entry and is harmless.
141
- function parseColon(input: string): number | null {
195
+ // Colon-separated: h:m:s, or two groups ending in the smallest unit (m:s or
196
+ // h:m), or one such group (:s or :m). Groups are not bounded to 0-59:
197
+ // out-of-range parts overflow by design. In seconds mode "1:75" parses to 135s
198
+ // (1m + 75s) and "5:99" to 399s; in minute mode "1:75" is 8100s (1h + 75m).
199
+ // This mirrors stopwatch-style entry and is harmless.
200
+ function parseColon(input: string, unitSeconds: number): number | null {
142
201
  const match = input.match(/^(\d+):(\d+):(\d+)$|^(\d+):(\d+)$|^:(\d+)$/)
143
202
  if (!match) return null
144
203
 
@@ -150,15 +209,16 @@ function parseColon(input: string): number | null {
150
209
  )
151
210
  }
152
211
  if (match[4] !== undefined) {
153
- return parseInt(match[4], 10) * 60 + parseInt(match[5], 10)
212
+ return (parseInt(match[4], 10) * 60 + parseInt(match[5], 10)) * unitSeconds
154
213
  }
155
- return parseInt(match[6], 10)
214
+ return parseInt(match[6], 10) * unitSeconds
156
215
  }
157
216
 
158
217
  // Named units in any order: scan (number)(unit) tokens left-to-right and
159
218
  // verify no unexpected text exists between tokens. Rejects duplicate units.
160
219
  function parseUnits(input: string): number | null {
161
- const tokenRe = /(\d+)\s*(hours?|hrs?|h|minutes?|mins?|m|seconds?|secs?|s)/g
220
+ const tokenRe =
221
+ /(\d+)\s*(days?|d|hours?|hrs?|h|minutes?|mins?|m|seconds?|secs?|s)/g
162
222
  const tokens: { value: number; unit: string }[] = []
163
223
  let lastEnd = 0
164
224
  let match: RegExpExecArray | null
@@ -177,7 +237,8 @@ function parseUnits(input: string): number | null {
177
237
  for (const { value, unit } of tokens) {
178
238
  if (seen.has(unit)) return null
179
239
  seen.add(unit)
180
- if (unit === 'h') total += value * 3600
240
+ if (unit === 'd') total += value * 86400
241
+ else if (unit === 'h') total += value * 3600
181
242
  else if (unit === 'm') total += value * 60
182
243
  else total += value
183
244
  }
@@ -5,4 +5,5 @@ export type {
5
5
  DurationEmits,
6
6
  DurationExposed,
7
7
  DurationFormat,
8
+ DurationUnits,
8
9
  } from './types'
@@ -21,11 +21,26 @@ export type DurationFormatPreset = 'short' | 'long' | 'colon'
21
21
  // `string & {}` keeps preset autocomplete while still accepting any template.
22
22
  export type DurationFormat = DurationFormatPreset | (string & {})
23
23
 
24
+ /** The biggest unit the `short` and `long` presets use. `hour` folds days into hours. */
25
+ export type DurationLargestUnit = 'day' | 'hour'
26
+
27
+ /** The smallest unit the `short` and `long` presets use. `minute` rounds the seconds. */
28
+ export type DurationSmallestUnit = 'minute' | 'second'
29
+
30
+ /** The unit range of the `short` and `long` presets and of the edit text. */
31
+ export interface DurationUnits {
32
+ largestUnit?: DurationLargestUnit
33
+ smallestUnit?: DurationSmallestUnit
34
+ }
35
+
24
36
  export interface DurationProps extends InputLabelingProps {
25
37
  /** The duration value in seconds (two-way via `v-model`). */
26
38
  modelValue?: number | null
27
39
 
28
- /** Placeholder shown when the input is empty. Defaults to `1h 30m 45s`. */
40
+ /**
41
+ * Placeholder shown when the input is empty. Defaults to `1h 30m` when
42
+ * `smallestUnit` is `minute`, and `1h 30m 45s` otherwise.
43
+ */
29
44
  placeholder?: string
30
45
 
31
46
  /**
@@ -35,6 +50,20 @@ export interface DurationProps extends InputLabelingProps {
35
50
  */
36
51
  format?: DurationFormat
37
52
 
53
+ /**
54
+ * The biggest unit of the `short` and `long` presets and of the edit text.
55
+ * `day` shows 93784 as `1d 2h 3m 4s`. Defaults to `hour` (`26h 3m 4s`).
56
+ */
57
+ largestUnit?: DurationLargestUnit
58
+
59
+ /**
60
+ * The smallest unit of the `short` and `long` presets and of the edit text.
61
+ * `minute` rounds to the nearest minute, and a typed value is saved rounded.
62
+ * In a minute field, a bare number is minutes and `a:b` is hours and
63
+ * minutes: `15` is 15 minutes and `1:30` is 1h 30m. Defaults to `second`.
64
+ */
65
+ smallestUnit?: DurationSmallestUnit
66
+
38
67
  /** Visual size of the input. Forwarded to the underlying `TextInput`. */
39
68
  size?: InputSize
40
69
 
@@ -16,8 +16,9 @@ export type NormalizedMenuGroup = MenuGroupOption & {
16
16
 
17
17
  export const menuClasses = {
18
18
  content:
19
- 'menu-content z-[100] min-w-40 divide-y divide-outline-elevation-2 rounded-6 bg-surface-elevation-2 shadow-2xl ring-1 ring-black ring-opacity-5 focus:outline-none',
20
- group: 'p-1.5',
19
+ 'menu-content z-[100] min-w-40 max-h-[--reka-popper-available-height] overflow-y-auto divide-y divide-outline-elevation-2 rounded-6 bg-surface-elevation-2 shadow-2xl ring-1 ring-black ring-opacity-5 focus:outline-none',
20
+ // The 1px gap keeps a highlighted row and a selected row next to it visibly separate.
21
+ group: 'flex flex-col gap-px p-1.5',
21
22
  groupLabel:
22
23
  'flex h-7 items-center px-2 text-sm font-medium leading-tighter text-ink-gray-4',
23
24
  itemIcon: 'size-4 shrink-0',
@@ -247,6 +247,11 @@
247
247
  name: 'update:selectedOptions',
248
248
  description: 'Fired alongside `update:modelValue` with the original option objects\nresolved out of `options`, so custom fields on an option survive.',
249
249
  type: '[value: MultiSelectOption[]]'
250
+ },
251
+ {
252
+ name: 'highlight',
253
+ description: 'Fired when the highlighted row changes, by arrow keys or the pointer, with\nthe original option object. `null` once the popover closes.',
254
+ type: '[option: MultiSelectOption | null]'
250
255
  }
251
256
  ]
252
257
 
@@ -111,6 +111,22 @@ const {
111
111
  hasDescriptionSlot: () => Boolean(slots.description),
112
112
  })
113
113
 
114
+ const triggerAttrs = computed(() => {
115
+ const { class: _class, style: _style, ...rest } = attrs
116
+ return rest
117
+ })
118
+
119
+ // The list is named like the field: by its label, else by the name given to
120
+ // the component itself.
121
+ const listAttrs = computed(() =>
122
+ props.label || slots.label
123
+ ? { 'aria-labelledby': labelId.value }
124
+ : {
125
+ 'aria-label': attrs['aria-label'],
126
+ 'aria-labelledby': attrs['aria-labelledby'],
127
+ },
128
+ )
129
+
114
130
  const hasLabeling = computed(() => {
115
131
  return Boolean(
116
132
  props.label ||
@@ -307,6 +323,21 @@ function handleRootOpenChange(value: boolean) {
307
323
  open.value = value
308
324
  }
309
325
 
326
+ const highlightedValue = ref<unknown>()
327
+
328
+ const highlightedOption = computed<MultiSelectOption | null>(() => {
329
+ if (highlightedValue.value === undefined) return null
330
+ const value = toExternalValue(highlightedValue.value)
331
+ return rawOptions.value.find((option) => option.value === value) ?? null
332
+ })
333
+
334
+ watch(highlightedOption, (option) => emit('highlight', option))
335
+
336
+ // reka reports each new highlight but never its end, which comes with closing.
337
+ watch(open, (isOpen) => {
338
+ if (!isOpen) highlightedValue.value = undefined
339
+ })
340
+
310
341
  function handleInputChange(event: Event) {
311
342
  setQuery((event.target as HTMLInputElement).value)
312
343
  }
@@ -380,6 +411,7 @@ defineSlots<MultiSelectSlots>()
380
411
  :ignore-filter="true"
381
412
  @update:modelValue="handleRootModelValueChange"
382
413
  @update:open="handleRootOpenChange"
414
+ @highlight="highlightedValue = $event?.value"
383
415
  >
384
416
  <ComboboxAnchor as-child @click="handleTriggerClick">
385
417
  <slot v-if="$slots.trigger" name="trigger" v-bind="slotProps" />
@@ -394,6 +426,7 @@ defineSlots<MultiSelectSlots>()
394
426
  <button
395
427
  v-else
396
428
  ref="trigger"
429
+ v-bind="triggerAttrs"
397
430
  type="button"
398
431
  :class="[
399
432
  triggerClasses,
@@ -485,6 +518,7 @@ defineSlots<MultiSelectSlots>()
485
518
 
486
519
  <ComboboxPortal :to="portalTarget">
487
520
  <ComboboxContent
521
+ v-bind="listAttrs"
488
522
  data-slot="content"
489
523
  data-selection
490
524
  :data-variant="variant"
@@ -246,10 +246,9 @@ function getItemTextValue(item: NormalizedOption) {
246
246
 
247
247
  <style scoped>
248
248
  /*
249
- * The outer item row paints its own bg via data-[highlighted] /
250
- * data-[state=checked] utilities — including the combined hover+selected
251
- * state. Clear ItemListRow's own bg so the outer color always shows
252
- * through; text emphasis on selected stays.
249
+ * The outer item row paints its own bg via data-[highlighted]. Clear
250
+ * ItemListRow's own bg, so a checked row is not filled: the checkbox shows
251
+ * the state. Text emphasis on selected stays.
253
252
  */
254
253
  [data-slot='item'] [data-slot='item-list-row'] {
255
254
  background-color: transparent;
@@ -320,4 +320,10 @@ export interface MultiSelectEmits {
320
320
  * resolved out of `options`, so custom fields on an option survive.
321
321
  */
322
322
  'update:selectedOptions': [value: MultiSelectOption[]]
323
+
324
+ /**
325
+ * Fired when the highlighted row changes, by arrow keys or the pointer, with
326
+ * the original option object. `null` once the popover closes.
327
+ */
328
+ highlight: [option: MultiSelectOption | null]
323
329
  }
@@ -36,6 +36,7 @@ import OptionIcon from '../shared/selection/OptionIcon.vue'
36
36
  import PopoverPanel from '../shared/popover/PopoverPanel.vue'
37
37
  import {
38
38
  EMPTY_VALUE_PREFIX,
39
+ checkedItemClasses,
39
40
  inputFontSizeClasses,
40
41
  itemClasses,
41
42
  itemRootSizeClasses,
@@ -215,9 +216,8 @@ const internalModel = computed<SelectOptionValue | undefined>({
215
216
 
216
217
  const selectedOption = computed(() => {
217
218
  return (
218
- selectOptions.value.find(
219
- (option) => option.value === currentValue.value,
220
- ) ?? null
219
+ selectOptions.value.find((option) => option.value === currentValue.value) ??
220
+ null
221
221
  )
222
222
  })
223
223
 
@@ -467,7 +467,7 @@ defineExpose(exposed)
467
467
  :disabled="internalOption.option.disabled"
468
468
  :value="internalOption.internalValue"
469
469
  data-slot="item"
470
- :class="[itemClasses, itemRootClasses]"
470
+ :class="[itemClasses, checkedItemClasses, itemRootClasses]"
471
471
  >
472
472
  <!--
473
473
  Full-row takeover precedence:
@@ -2,6 +2,7 @@ import type { SelectionSize, SelectionVariant } from '../shared/selection/utils'
2
2
  import { resolvePropValue } from '../../utils/resolvePropValue'
3
3
 
4
4
  export {
5
+ checkedItemClasses,
5
6
  inputFontSizeClasses,
6
7
  itemClasses,
7
8
  itemRootSizeClasses,
@@ -139,10 +139,10 @@ const switchClasses = computed(() => {
139
139
  // The focus ring is applied globally via :focus-visible. In the padded
140
140
  // padded rows it is shown on the row instead, so suppress it on the control.
141
141
  props.padded ? 'focus:outline-none focus:ring-0' : '',
142
- 'disabled:cursor-not-allowed disabled:bg-surface-gray-3',
142
+ 'disabled:cursor-not-allowed',
143
143
  model.value
144
- ? 'bg-surface-gray-10 enabled:hover:bg-surface-gray-9 active:bg-surface-gray-8 group-hover:enabled:bg-surface-gray-9'
145
- : 'bg-surface-gray-4 enabled:hover:bg-surface-gray-5 active:bg-surface-gray-6 group-hover:enabled:bg-surface-gray-5',
144
+ ? 'bg-surface-gray-10 enabled:hover:bg-surface-gray-9 active:bg-surface-gray-8 group-hover:enabled:bg-surface-gray-9 disabled:bg-surface-gray-7'
145
+ : 'bg-surface-gray-4 enabled:hover:bg-surface-gray-5 active:bg-surface-gray-6 group-hover:enabled:bg-surface-gray-5 disabled:bg-surface-gray-3',
146
146
  props.size === 'md'
147
147
  ? 'h-5 w-8 border-[3px]'
148
148
  : props.size === 'sm'
@@ -119,7 +119,14 @@ export const triggerBaseClassesFocusWithin =
119
119
  'relative inline-flex items-center gap-2 text-left text-ink-gray-7 outline-none transition-[background-color,border-color,box-shadow] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] focus-within:focus-ring data-[state=open]:focus-ring'
120
120
 
121
121
  export const itemClasses =
122
- 'select-none rounded-4 border-0 text-base text-ink-gray-9 transition-colors duration-100 ease-out data-[disabled]:text-ink-gray-4 data-[highlighted]:bg-surface-alpha-gray-2 data-[state=checked]:bg-surface-gray-3 data-[highlighted]:data-[state=checked]:bg-surface-gray-4'
122
+ 'select-none rounded-4 border-0 text-base text-ink-gray-9 transition-colors duration-100 ease-out data-[disabled]:text-ink-gray-4 data-[highlighted]:bg-surface-alpha-gray-2'
123
+
124
+ /**
125
+ * Fill for the picked row of a single-pick list. A multi-pick list leaves it
126
+ * off: its checkbox already shows the state, and most of its rows are checked.
127
+ */
128
+ export const checkedItemClasses =
129
+ 'data-[state=checked]:bg-surface-gray-3 data-[highlighted]:data-[state=checked]:bg-surface-gray-4'
123
130
 
124
131
  /**
125
132
  * Case-insensitive substring match against an option's label and value.