@stacksjs/components 0.2.959 → 0.2.961

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -57,7 +57,7 @@ yarn add @stacksjs/components
57
57
  - **Tabs** - Tabbed content with horizontal/vertical layouts and multiple variants
58
58
  - **Tooltip** - Contextual tooltips with positioning options
59
59
  - **Video** - Video player with aspect ratio support
60
- - **SwipeRow** - Reveal row actions with a native swipe or the accessible More actions button
60
+ - **SwipeRow** - Reveal row actions with a swipe or the accessible More actions button. Set `nativeSwipeOnly` when a native row already exposes equivalent VoiceOver and TalkBack actions. The web keeps its button.
61
61
  - **VirtualList** - Windowed list for rendering large datasets efficiently
62
62
  - **VirtualTable** - Windowed table with columns for large datasets
63
63
  - **Dropdown** - Menu dropdown component with keyboard navigation
@@ -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,158 @@
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
+ export const initialNativeSwipeOnly = $bool($props.nativeSwipeOnly)
9
+ </script>
10
+
11
+ <script client>
12
+ import { closeSwipeRow, openSwipeRow, SWIPE_SLOP, swipeOffset, swipeSettlesOpen } from './swipe-row'
13
+
14
+ const emit = defineEmits(['action'])
15
+ const nativeHost = {{ nativeHost }}
16
+ // A host that pans the row with the finger and animates it (Craft's
17
+ // capabilities.interactiveSwipe): it owns the content's translation, and says
18
+ // where a swipe came to rest. Without it the row jumps open on a finished swipe.
19
+ const interactive = nativeHost && typeof craft !== 'undefined' && !!craft && !!craft.capabilities && craft.capabilities.interactiveSwipe === true
20
+ const actions = useReactiveProp('actions', {{ initialActions }})
21
+ const actionsLabel = useReactiveProp('actionsLabel', {{ defaultLabel }})
22
+ const disabled = useReactiveProp('disabled', {{ initialDisabled }})
23
+ const nativeSwipeOnly = useReactiveProp('nativeSwipeOnly', {{ initialNativeSwipeOnly }})
24
+ const testId = useReactiveProp('testID', {{ testID }})
25
+ const opened = state(false)
26
+ const actionWidth = 88
27
+ const reveal = derived(() => actionWidth * actions().length)
28
+ const offset = derived(() => opened() ? reveal() : 0)
29
+ // Where a finger is holding the row on a web page, or null when nothing is.
30
+ const dragged = state(null)
31
+ const reduceMotion = !nativeHost && typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches
32
+ const webStyle = derived(() => {
33
+ const position = dragged() === null ? -offset() : dragged()
34
+ // pan-y: the browser keeps vertical scrolling and leaves the horizontal drag to us.
35
+ return { transform: 'translateX(' + position + 'px)', transition: dragged() !== null || reduceMotion ? 'none' : 'transform 250ms ease-out', touchAction: 'pan-y' }
36
+ })
37
+ const trayStyle = derived(() => nativeHost ? { right: -reveal(), width: reveal() } : { right: -reveal() + 'px', width: reveal() + 'px' })
38
+
39
+ function close() {
40
+ closeSwipeRow(close)
41
+ opened.set(false)
42
+ }
43
+
44
+ function open() {
45
+ if (disabled() || !actions().length) return
46
+ openSwipeRow(close)
47
+ opened.set(true)
48
+ }
49
+
50
+ function swipe(direction) {
51
+ if (direction === 'left') open()
52
+ else if (direction === 'right') close()
53
+ }
54
+
55
+ // An interactive swipe the user made came to rest.
56
+ function settle(isOpen) {
57
+ if (isOpen) open()
58
+ else close()
59
+ }
60
+
61
+ function activate(id) {
62
+ if (disabled() || !actions().some(action => action.id === id)) return
63
+ close()
64
+ emit('action', id)
65
+ }
66
+
67
+ // A finger dragging the row on a web page: it follows 1:1 once the drag is
68
+ // horizontal, and lets a vertical one scroll the page.
69
+ let drag = null
70
+ function dragStart(event) {
71
+ if (event.pointerType !== 'touch' || disabled() || !actions().length) return
72
+ drag = { x: event.clientX, y: event.clientY, from: -offset(), horizontal: null, at: event.timeStamp, last: event.clientX }
73
+ }
74
+ function dragMove(event) {
75
+ if (!drag) return
76
+ const dx = event.clientX - drag.x
77
+ if (drag.horizontal === null) {
78
+ const dy = event.clientY - drag.y
79
+ if (Math.abs(dx) < SWIPE_SLOP && Math.abs(dy) < SWIPE_SLOP) return
80
+ drag.horizontal = Math.abs(dx) > Math.abs(dy)
81
+ if (!drag.horizontal) {
82
+ drag = null
83
+ return
84
+ }
85
+ event.currentTarget.setPointerCapture?.(event.pointerId)
86
+ }
87
+ drag.velocity = (event.clientX - drag.last) / Math.max(1, event.timeStamp - drag.at)
88
+ drag.last = event.clientX
89
+ drag.at = event.timeStamp
90
+ dragged.set(swipeOffset(drag.from + dx, reveal()))
91
+ }
92
+ function dragEnd() {
93
+ const ended = drag
94
+ drag = null
95
+ if (!ended || dragged() === null) return
96
+ const position = dragged()
97
+ dragged.set(null)
98
+ if (swipeSettlesOpen(position, reveal(), ended.velocity || 0)) open()
99
+ else close()
100
+ }
101
+
102
+ effect(() => {
103
+ if (!actions().length || disabled()) close()
104
+ })
105
+ onMount(() => close)
106
+ </script>
107
+
108
+ <div class="relative overflow-hidden {{ className }}" :testID="testId()"
109
+ @if(nativeHost)
110
+ :swipeEnabled="!interactive && !disabled() && actions().length > 0"
111
+ :swipeDirection="opened() ? 'right' : 'left'"
112
+ @swipe="swipe($event.direction)"
113
+ @else
114
+ @keydown.escape="opened() && close()"
115
+ @endif
116
+ >
117
+ <div class="relative flex flex-row items-center"
118
+ @if(nativeHost)
119
+ :swipeReveal="interactive && !disabled() ? reveal() : 0"
120
+ :swipeOpen="opened()"
121
+ @swipe-settle="settle($event.open)"
122
+ :style="interactive ? {} : { transform: [{ translateX: -offset() }] }"
123
+ @else
124
+ :style="webStyle()"
125
+ @pointerdown="dragStart($event)"
126
+ @pointermove="dragMove($event)"
127
+ @pointerup="dragEnd()"
128
+ @pointercancel="dragEnd()"
129
+ @endif
130
+ >
131
+ <div class="flex flex-1 flex-col min-w-0"><slot /></div>
132
+ <button :if="actions().length && (!nativeHost || !nativeSwipeOnly())" type="button" class="flex shrink-0 items-center justify-center h-11 w-11"
133
+ :disabled="disabled()" :aria-label="actionsLabel()" :aria-expanded="opened() ? 'true' : 'false'"
134
+ :testID="testId() && testId() + '-actions'" @click="opened() ? close() : open()">
135
+ <i class="h-5 w-5 text-[#636366] dark:text-[#aeaeb2] i-lucide-more-horizontal" aria-hidden="true"></i>
136
+ </button>
137
+ <!-- Just past the trailing edge, riding on the sliding content: the row
138
+ clips them while closed and the slide reveals them, so nothing pops
139
+ in. Hidden from assistive tech and from touch until open. -->
140
+ <div class="flex absolute inset-y-0 flex-row" :style="trayStyle()"
141
+ :aria-hidden="opened() ? 'false' : 'true'"
142
+ @if(nativeHost)
143
+ :pointerEvents="opened() ? 'auto' : 'none'"
144
+ @else
145
+ :class="opened() ? '' : 'pointer-events-none'"
146
+ @endif
147
+ >
148
+ <button :for="item in actions()" :key="item.id" type="button"
149
+ class="flex shrink-0 items-center justify-center px-1 min-h-11"
150
+ :class="item.destructive ? 'bg-[#b4232b] dark:bg-[#b4232b]' : 'bg-[#245fa9] dark:bg-[#245fa9]'"
151
+ :style="{ width: actionWidth + 'px' }" :disabled="disabled()" :tabindex="opened() ? 0 : -1"
152
+ :accessibilityLabel="item.accessibilityLabel || item.label" :aria-label="item.accessibilityLabel || item.label"
153
+ :testID="item.testID || (testId() && testId() + '-' + item.id)" @click="activate(item.id)">
154
+ <span class="text-xs font-semibold text-center text-white" :text="item.label"></span>
155
+ </button>
156
+ </div>
157
+ </div>
158
+ </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
  })