@stacksjs/components 0.2.959 → 0.2.960

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.
@@ -17,6 +17,8 @@ export const minDate = $props.minDate || null
17
17
  export const maxDate = $props.maxDate || null
18
18
  export const disabledDates = $props.disabledDates || []
19
19
  export const locale = $props.locale || 'en-US'
20
+ export const previousMonthLabel = $props.previousMonthLabel || 'Previous month'
21
+ export const nextMonthLabel = $props.nextMonthLabel || 'Next month'
20
22
  export const firstDayOfWeek = $num($props.firstDayOfWeek) || 0
21
23
  export const showToday = $bool($props.showToday, true)
22
24
  export const className = $props.className || ''
@@ -45,6 +47,8 @@ export const disabledIsoList = disabledDates.map(d => new Date(d).toISOString())
45
47
  <script client>
46
48
  const emit = defineEmits()
47
49
  const locale = useReactiveProp('locale', {{ locale }})
50
+ const previousLabel = useReactiveProp('previousMonthLabel', {{ previousMonthLabel }})
51
+ const nextLabel = useReactiveProp('nextMonthLabel', {{ nextMonthLabel }})
48
52
  const firstDayOfWeek = {{ firstDayOfWeek }}
49
53
  const highlightToday = {{ highlightToday }}
50
54
  /*
@@ -284,7 +288,8 @@ defineExpose({ selectedDate, currentMonth, selectDate, rangeStart, rangeEnd })
284
288
  type="button"
285
289
  class="{{ buttonClasses }}"
286
290
  @click="previousMonth()"
287
- aria-label="Previous month"
291
+ :aria-label="previousLabel()"
292
+ aria-label="{{ previousMonthLabel }}"
288
293
  >
289
294
  <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
290
295
  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
@@ -297,7 +302,8 @@ defineExpose({ selectedDate, currentMonth, selectDate, rangeStart, rangeEnd })
297
302
  type="button"
298
303
  class="{{ buttonClasses }}"
299
304
  @click="nextMonthFn()"
300
- aria-label="Next month"
305
+ :aria-label="nextLabel()"
306
+ aria-label="{{ nextMonthLabel }}"
301
307
  >
302
308
  <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
303
309
  <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
@@ -0,0 +1,156 @@
1
+ <script server>
2
+ export const nativeHost = $native
3
+ export const defaultLabel = $props.actionsLabel || 'More actions'
4
+ export const className = $props.className || $props.class || ''
5
+ export const testID = $props.testID || ''
6
+ export const initialActions = $props.actions || []
7
+ export const initialDisabled = $bool($props.disabled)
8
+ </script>
9
+
10
+ <script client>
11
+ import { closeSwipeRow, openSwipeRow, SWIPE_SLOP, swipeOffset, swipeSettlesOpen } from './swipe-row'
12
+
13
+ const emit = defineEmits(['action'])
14
+ const nativeHost = {{ nativeHost }}
15
+ // A host that pans the row with the finger and animates it (Craft's
16
+ // capabilities.interactiveSwipe): it owns the content's translation, and says
17
+ // where a swipe came to rest. Without it the row jumps open on a finished swipe.
18
+ const interactive = nativeHost && typeof craft !== 'undefined' && !!craft && !!craft.capabilities && craft.capabilities.interactiveSwipe === true
19
+ const actions = useReactiveProp('actions', {{ initialActions }})
20
+ const actionsLabel = useReactiveProp('actionsLabel', {{ defaultLabel }})
21
+ const disabled = useReactiveProp('disabled', {{ initialDisabled }})
22
+ const testId = useReactiveProp('testID', {{ testID }})
23
+ const opened = state(false)
24
+ const actionWidth = 88
25
+ const reveal = derived(() => actionWidth * actions().length)
26
+ const offset = derived(() => opened() ? reveal() : 0)
27
+ // Where a finger is holding the row on a web page, or null when nothing is.
28
+ const dragged = state(null)
29
+ const reduceMotion = !nativeHost && typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches
30
+ const webStyle = derived(() => {
31
+ const position = dragged() === null ? -offset() : dragged()
32
+ // pan-y: the browser keeps vertical scrolling and leaves the horizontal drag to us.
33
+ return { transform: 'translateX(' + position + 'px)', transition: dragged() !== null || reduceMotion ? 'none' : 'transform 250ms ease-out', touchAction: 'pan-y' }
34
+ })
35
+ const trayStyle = derived(() => nativeHost ? { right: -reveal(), width: reveal() } : { right: -reveal() + 'px', width: reveal() + 'px' })
36
+
37
+ function close() {
38
+ closeSwipeRow(close)
39
+ opened.set(false)
40
+ }
41
+
42
+ function open() {
43
+ if (disabled() || !actions().length) return
44
+ openSwipeRow(close)
45
+ opened.set(true)
46
+ }
47
+
48
+ function swipe(direction) {
49
+ if (direction === 'left') open()
50
+ else if (direction === 'right') close()
51
+ }
52
+
53
+ // An interactive swipe the user made came to rest.
54
+ function settle(isOpen) {
55
+ if (isOpen) open()
56
+ else close()
57
+ }
58
+
59
+ function activate(id) {
60
+ if (disabled() || !actions().some(action => action.id === id)) return
61
+ close()
62
+ emit('action', id)
63
+ }
64
+
65
+ // A finger dragging the row on a web page: it follows 1:1 once the drag is
66
+ // horizontal, and lets a vertical one scroll the page.
67
+ let drag = null
68
+ function dragStart(event) {
69
+ if (event.pointerType !== 'touch' || disabled() || !actions().length) return
70
+ drag = { x: event.clientX, y: event.clientY, from: -offset(), horizontal: null, at: event.timeStamp, last: event.clientX }
71
+ }
72
+ function dragMove(event) {
73
+ if (!drag) return
74
+ const dx = event.clientX - drag.x
75
+ if (drag.horizontal === null) {
76
+ const dy = event.clientY - drag.y
77
+ if (Math.abs(dx) < SWIPE_SLOP && Math.abs(dy) < SWIPE_SLOP) return
78
+ drag.horizontal = Math.abs(dx) > Math.abs(dy)
79
+ if (!drag.horizontal) {
80
+ drag = null
81
+ return
82
+ }
83
+ event.currentTarget.setPointerCapture?.(event.pointerId)
84
+ }
85
+ drag.velocity = (event.clientX - drag.last) / Math.max(1, event.timeStamp - drag.at)
86
+ drag.last = event.clientX
87
+ drag.at = event.timeStamp
88
+ dragged.set(swipeOffset(drag.from + dx, reveal()))
89
+ }
90
+ function dragEnd() {
91
+ const ended = drag
92
+ drag = null
93
+ if (!ended || dragged() === null) return
94
+ const position = dragged()
95
+ dragged.set(null)
96
+ if (swipeSettlesOpen(position, reveal(), ended.velocity || 0)) open()
97
+ else close()
98
+ }
99
+
100
+ effect(() => {
101
+ if (!actions().length || disabled()) close()
102
+ })
103
+ onMount(() => close)
104
+ </script>
105
+
106
+ <div class="relative overflow-hidden {{ className }}" :testID="testId()"
107
+ @if(nativeHost)
108
+ :swipeEnabled="!interactive && !disabled() && actions().length > 0"
109
+ :swipeDirection="opened() ? 'right' : 'left'"
110
+ @swipe="swipe($event.direction)"
111
+ @else
112
+ @keydown.escape="opened() && close()"
113
+ @endif
114
+ >
115
+ <div class="relative flex flex-row items-center"
116
+ @if(nativeHost)
117
+ :swipeReveal="interactive && !disabled() ? reveal() : 0"
118
+ :swipeOpen="opened()"
119
+ @swipe-settle="settle($event.open)"
120
+ :style="interactive ? {} : { transform: [{ translateX: -offset() }] }"
121
+ @else
122
+ :style="webStyle()"
123
+ @pointerdown="dragStart($event)"
124
+ @pointermove="dragMove($event)"
125
+ @pointerup="dragEnd()"
126
+ @pointercancel="dragEnd()"
127
+ @endif
128
+ >
129
+ <div class="flex flex-1 flex-col min-w-0"><slot /></div>
130
+ <button :if="actions().length" type="button" class="flex shrink-0 items-center justify-center h-11 w-11"
131
+ :disabled="disabled()" :aria-label="actionsLabel()" :aria-expanded="opened() ? 'true' : 'false'"
132
+ :testID="testId() && testId() + '-actions'" @click="opened() ? close() : open()">
133
+ <i class="h-5 w-5 text-[#636366] dark:text-[#aeaeb2] i-lucide-more-horizontal" aria-hidden="true"></i>
134
+ </button>
135
+ <!-- Just past the trailing edge, riding on the sliding content: the row
136
+ clips them while closed and the slide reveals them, so nothing pops
137
+ in. Hidden from assistive tech and from touch until open. -->
138
+ <div class="flex absolute inset-y-0 flex-row" :style="trayStyle()"
139
+ :aria-hidden="opened() ? 'false' : 'true'"
140
+ @if(nativeHost)
141
+ :pointerEvents="opened() ? 'auto' : 'none'"
142
+ @else
143
+ :class="opened() ? '' : 'pointer-events-none'"
144
+ @endif
145
+ >
146
+ <button :for="item in actions()" :key="item.id" type="button"
147
+ class="flex shrink-0 items-center justify-center px-1 min-h-11"
148
+ :class="item.destructive ? 'bg-[#b4232b] dark:bg-[#b4232b]' : 'bg-[#245fa9] dark:bg-[#245fa9]'"
149
+ :style="{ width: actionWidth + 'px' }" :disabled="disabled()" :tabindex="opened() ? 0 : -1"
150
+ :accessibilityLabel="item.accessibilityLabel || item.label" :aria-label="item.accessibilityLabel || item.label"
151
+ :testID="item.testID || (testId() && testId() + '-' + item.id)" @click="activate(item.id)">
152
+ <span class="text-xs font-semibold text-center text-white" :text="item.label"></span>
153
+ </button>
154
+ </div>
155
+ </div>
156
+ </div>
@@ -80,10 +80,12 @@ const isDisabled = useReactiveProp('disabled', {{ disabled }})
80
80
  const pressToToggle = useReactiveProp('pressToToggle', {{ pressToToggle }})
81
81
  // Reactive prop binding — parent can drive `show` via signals. See #1704.
82
82
  const isVisible = useReactiveProp('show', {{ show }})
83
- let timeoutId = null
84
- let pointerExitTimeout = null
85
83
  let positionGeneration = 0
86
84
  let destroyed = false
85
+ const showAfterDelay = useDebounce(() => {
86
+ if (!destroyed && !isDisabled() && !pressToToggle()) isVisible.set(true)
87
+ }, delay)
88
+ const hideAfterExit = useDebounce(hideTooltip, 160)
87
89
 
88
90
  // Use the actual offset parent, so a tooltip inside a modal or a transformed
89
91
  // container still gets viewport bounds rather than assuming document origin.
@@ -117,31 +119,20 @@ function showTooltip() {
117
119
  if (isDisabled() || pressToToggle()) return
118
120
  cancelPointerExit()
119
121
  if (isVisible()) return
120
- if (timeoutId) clearTimeout(timeoutId)
121
- if (delay > 0) {
122
- timeoutId = setTimeout(() => {
123
- timeoutId = null
124
- if (!destroyed && !isDisabled() && !pressToToggle()) isVisible.set(true)
125
- }, delay)
126
- }
127
- else {
128
- isVisible.set(true)
129
- }
122
+ if (delay > 0) showAfterDelay()
123
+ else isVisible.set(true)
130
124
  }
131
125
 
132
126
  function cancelPointerExit() {
133
- if (pointerExitTimeout === null) return
134
- clearTimeout(pointerExitTimeout)
135
- pointerExitTimeout = null
127
+ hideAfterExit.cancel()
136
128
  }
137
129
 
138
130
  function leaveTooltip() {
139
131
  if (pressToToggle()) return
140
132
  if (!isVisible()) { hideTooltip(); return }
141
- cancelPointerExit()
142
133
  // A portaled panel has an eight-pixel gap from its trigger. Let a pointer
143
134
  // cross that gap without losing the text it was approaching to read.
144
- pointerExitTimeout = setTimeout(hideTooltip, 160)
135
+ hideAfterExit()
145
136
  }
146
137
 
147
138
  function toggleTouch(event) {
@@ -159,10 +150,7 @@ function toggleTouch(event) {
159
150
  function hideTooltip() {
160
151
  ++positionGeneration
161
152
  cancelPointerExit()
162
- if (timeoutId) {
163
- clearTimeout(timeoutId)
164
- timeoutId = null
165
- }
153
+ showAfterDelay.cancel()
166
154
  isVisible.set(false)
167
155
  }
168
156
 
@@ -198,8 +186,6 @@ effect(() => {
198
186
  onDestroy(() => {
199
187
  destroyed = true
200
188
  ++positionGeneration
201
- cancelPointerExit()
202
- if (timeoutId) clearTimeout(timeoutId)
203
189
  if (stopPositioning) stopPositioning()
204
190
  window.stx.overlays.close(activeTooltipId)
205
191
  })