@stacksjs/components 0.2.919 → 0.2.922
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 +1 -0
- package/dist/{ChatInbox-3cz5tt0d.stx → ChatInbox-swjc2p6x.stx} +24 -10
- package/dist/RenderSurface-z9zr4d75.stx +137 -0
- package/dist/SwipeRow-6myz9c27.stx +74 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +24 -24
- package/dist/render-surface/render-surface.js +145 -0
- package/dist/ui/list/SwipeRow.d.ts +13 -0
- package/dist/ui/list/index.d.ts +2 -0
- package/dist/ui/list/swipe-row.d.ts +16 -0
- package/dist/ui/render-surface/RenderSurface.d.ts +45 -0
- package/dist/ui/render-surface/index.d.ts +17 -0
- package/dist/ui/render-surface/render-surface.d.ts +94 -0
- package/package.json +8 -3
- package/src/index.ts +1 -0
- package/src/ui/chat/ChatInbox.stx +24 -10
- package/src/ui/list/SwipeRow.stx +74 -0
- package/src/ui/list/index.ts +3 -0
- package/src/ui/list/swipe-row.ts +29 -0
- package/src/ui/render-surface/README.md +69 -0
- package/src/ui/render-surface/RenderSurface.stx +137 -0
- package/src/ui/render-surface/index.ts +27 -0
- package/src/ui/render-surface/render-surface.ts +244 -0
package/README.md
CHANGED
|
@@ -56,6 +56,7 @@ yarn add @stacksjs/components
|
|
|
56
56
|
- **Tabs** - Tabbed content with horizontal/vertical layouts and multiple variants
|
|
57
57
|
- **Tooltip** - Contextual tooltips with positioning options
|
|
58
58
|
- **Video** - Video player with aspect ratio support
|
|
59
|
+
- **SwipeRow** - Reveal row actions with a native swipe or the accessible More actions button
|
|
59
60
|
- **VirtualList** - Windowed list for rendering large datasets efficiently
|
|
60
61
|
- **VirtualTable** - Windowed table with columns for large datasets
|
|
61
62
|
- **Dropdown** - Menu dropdown component with keyboard navigation
|
|
@@ -50,7 +50,7 @@ effect(() => {
|
|
|
50
50
|
if (element && (changedThread || newMessage && (nearBottom || last.sender_id === selfId()))) {
|
|
51
51
|
nextTick(() => { element.scrollTop = element.scrollHeight })
|
|
52
52
|
}
|
|
53
|
-
if (changedThread && id) nextTick(() => composer()?.focus())
|
|
53
|
+
if (changedThread && id) nextTick(() => composer()?.focus({ preventScroll: true }))
|
|
54
54
|
lastThread = id
|
|
55
55
|
lastMessage = last?.id || 0
|
|
56
56
|
})
|
|
@@ -58,6 +58,12 @@ const hasSelection = derived(() => !!selected())
|
|
|
58
58
|
const noSelection = derived(() => !selected() && !compact)
|
|
59
59
|
const emptyRows = derived(() => !loading() && rows().length === 0)
|
|
60
60
|
const emptyThread = derived(() => hasSelection() && !threadLoading() && messages().length === 0)
|
|
61
|
+
const messageRows = derived(() => messages().map((message, index, thread) => {
|
|
62
|
+
const next = thread[index + 1]
|
|
63
|
+
const gap = next && Number(new Date(next.created_at)) - Number(new Date(message.created_at))
|
|
64
|
+
const end = !next || message.sender_id !== next.sender_id || !(gap >= 0 && gap < 300_000)
|
|
65
|
+
return { message, end, mine: message.sender_id === selfId() }
|
|
66
|
+
}))
|
|
61
67
|
const selectedName = derived(() => selected()?.name || '')
|
|
62
68
|
const selectedRole = derived(() => selected()?.role || '')
|
|
63
69
|
const selectedAvatar = derived(() => selected()?.avatar || '')
|
|
@@ -71,7 +77,7 @@ watch(() => active() && visibility() === 'visible' ? chat.scopeKey() : null, (sc
|
|
|
71
77
|
if (scope !== null) void chat.refresh(true)
|
|
72
78
|
}, { immediate: true })
|
|
73
79
|
</script>
|
|
74
|
-
<section aria-label="Messages" data-compact="{{ compact }}" class="stx-chat-inbox flex flex-col {{ sizeClasses }} max-h-[900px] overflow-hidden bg-panel
|
|
80
|
+
<section aria-label="Messages" data-compact="{{ compact }}" class="stx-chat-inbox flex flex-col {{ sizeClasses }} max-h-[900px] overflow-hidden bg-panel rounded-2xl {{ className }}">
|
|
75
81
|
<div :if="error" role="alert" class="flex gap-3 items-center justify-between px-4 py-3 text-sm text-rose-800 dark:text-rose-200 bg-danger-soft">
|
|
76
82
|
<span :text="error"></span><button type="button" @click="chat.refresh(true)" class="font-semibold underline">Try again</button>
|
|
77
83
|
</div>
|
|
@@ -84,7 +90,7 @@ watch(() => active() && visibility() === 'visible' ? chat.scopeKey() : null, (sc
|
|
|
84
90
|
</div>
|
|
85
91
|
<p :if="loading" role="status" class="px-5 pb-2 text-xs text-fg-muted">Updating messages...</p>
|
|
86
92
|
<div class="flex-1 overflow-y-auto px-2 pb-2">
|
|
87
|
-
<button :for="person in rows" type="button" @click="chat.open(person)" :aria-pressed="selected && selected.id === person.id" :class="selected && selected.id === person.id ? 'bg-accent-soft' : 'hover:bg-panel-hover'" class="flex gap-3 items-start w-full p-3 text-left rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent">
|
|
93
|
+
<button :for="person in rows" :key="person.id" type="button" @click="chat.open(person)" :data-chat-contact="person.id" :aria-pressed="selected && selected.id === person.id" :class="selected && selected.id === person.id ? 'bg-accent-soft' : 'hover:bg-panel-hover'" class="flex gap-3 items-start w-full p-3 text-left rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent">
|
|
88
94
|
<Avatar :src="person.avatar || ''" :alt="person.name" size="md" className="shrink-0" />
|
|
89
95
|
<span class="flex-1 min-w-0"><span class="flex items-center justify-between gap-2"><span class="font-semibold text-sm text-fg-strong truncate" :text="person.name"></span><span :if="person.conversation && person.conversation.unread" class="px-1.5 min-w-5 text-center text-xs font-semibold text-accent-ink bg-accent-solid rounded-full" :text="person.conversation.unread"></span></span><span class="block mt-0.5 text-xs text-fg-muted" :text="person.role"></span><span class="block mt-1 text-sm text-fg truncate" :text="person.conversation && person.conversation.last_message ? person.conversation.last_message.body : 'Start a conversation'"></span></span>
|
|
90
96
|
</button>
|
|
@@ -94,20 +100,22 @@ watch(() => active() && visibility() === 'visible' ? chat.scopeKey() : null, (sc
|
|
|
94
100
|
<div :if="noSelection" class="stx-chat-empty hidden flex-1 flex-col items-center justify-center px-8 text-center bg-surface/50">
|
|
95
101
|
<span class="i-lucide-messages-square text-3xl text-accent" aria-hidden="true"></span><h2 class="mt-4 text-lg font-semibold text-fg-strong">A place for the conversation</h2><p class="mt-2 max-w-xs text-sm leading-6 text-fg-muted">Training questions, session feedback, or a quick check-in. Choose someone from your inbox to get started.</p>
|
|
96
102
|
</div>
|
|
97
|
-
<div :if="hasSelection" class="flex flex-1 flex-col min-w-0">
|
|
103
|
+
<div :if="hasSelection" data-chat-thread class="flex flex-1 flex-col min-w-0">
|
|
98
104
|
<header class="flex items-center gap-3 px-4 py-4 border-b border-line">
|
|
99
105
|
<button type="button" @click="chat.back()" aria-label="Back to inbox" class="stx-chat-back {{ backButtonClass }} p-2 rounded-lg hover:bg-surface-hover"><span class="i-lucide-arrow-left" aria-hidden="true"></span></button><StxLink :if="selectedHref" :to="selectedHref" className="stx-chat-person flex flex-1 gap-3 items-center min-w-0 rounded-lg hover:opacity-80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent"><Avatar :src="selectedAvatar" :alt="selectedName" size="md" className="shrink-0" /><div class="min-w-0"><h2 class="font-semibold text-fg-strong truncate" :text="selectedName"></h2><p class="mt-0.5 text-xs text-fg-muted" :text="selectedRole"></p></div></StxLink><div :if="!selectedHref" class="stx-chat-person flex flex-1 gap-3 items-center min-w-0"><Avatar :src="selectedAvatar" :alt="selectedName" size="md" className="shrink-0" /><div class="min-w-0"><h2 class="font-semibold text-fg-strong truncate" :text="selectedName"></h2><p class="mt-0.5 text-xs text-fg-muted" :text="selectedRole"></p></div></div><button type="button" @click="chat.refresh(true)" aria-label="Refresh conversation" class="p-2 text-fg-muted rounded-lg hover:bg-surface-hover"><span class="i-lucide-refresh-cw" aria-hidden="true"></span></button>
|
|
100
106
|
</header>
|
|
101
|
-
<div ref="chat-history" role="log" aria-label="Conversation history" aria-live="polite" aria-relevant="additions" :aria-busy="threadLoading" class="flex flex-col flex-1 min-h-0 overflow-y-auto px-4 py-5
|
|
107
|
+
<div ref="chat-history" role="log" aria-label="Conversation history" aria-live="polite" aria-relevant="additions" :aria-busy="threadLoading" class="flex flex-col flex-1 min-h-0 overflow-y-auto px-4 py-5">
|
|
102
108
|
<button :if="hasMore" type="button" @click="chat.older()" :disabled="threadLoading" class="self-center text-sm text-accent-soft-ink font-medium underline">Load earlier messages</button>
|
|
103
109
|
<p :if="threadLoading" role="status" class="text-center text-sm text-fg-muted">Loading conversation...</p>
|
|
104
110
|
<div :if="emptyThread" class="my-auto text-center"><p class="font-semibold text-fg-strong">Start with a question or a check-in</p><p class="mt-2 text-sm text-fg-muted">Messages stay here so you can pick up where you left off.</p></div>
|
|
105
|
-
<article :for="
|
|
106
|
-
<p :class="
|
|
111
|
+
<article :for="row in messageRows" :key="row.message.id" :data-chat-message="row.message.id" :class="(row.mine ? 'items-end' : 'items-start') + (row.end ? ' mb-3' : ' mb-0.5')" class="flex flex-col gap-1">
|
|
112
|
+
<p :class="(row.mine ? 'bg-accent-solid text-accent-ink' : 'bg-surface-sunken text-fg-strong') + (row.end ? (row.mine ? ' rounded-br-md' : ' rounded-bl-md') : '')" class="stx-chat-message max-w-[88%] whitespace-pre-wrap break-words px-3.5 py-2 rounded-[18px] text-sm leading-5" :text="row.message.body"></p>
|
|
113
|
+
<span :class="row.end ? '' : 'sr-only'" class="px-1 text-[11px] text-fg-muted"><time :datetime="row.message.created_at" :text="timestamp(row.message.created_at)"></time><span :if="row.mine" :text="row.message.read_at ? ' · Read' : ' · Sent'"></span></span>
|
|
107
114
|
</article>
|
|
108
115
|
</div>
|
|
109
|
-
<form @submit.prevent="submit()" class="
|
|
110
|
-
<label class="
|
|
116
|
+
<form @submit.prevent="submit()" class="m-3 flex items-end gap-2 p-1.5 rounded-3xl bg-field focus-within:ring-2 focus-within:ring-accent">
|
|
117
|
+
<label class="flex-1 min-w-0"><span class="sr-only">Write a message</span><textarea ref="chat-composer" x-model="draft" @keydown="keyboard($event)" :maxlength="maxLength" :disabled="sending" rows="1" placeholder="Write a message…" class="stx-chat-composer block w-full resize-none px-2.5 py-2 text-sm leading-6 text-fg-strong placeholder:text-fg-soft bg-transparent focus:outline-none"></textarea></label>
|
|
118
|
+
<button type="submit" :aria-label="sendLabel" :disabled="!canSend" class="flex shrink-0 items-center justify-center h-10 w-10 text-accent-ink bg-accent-solid hover:bg-accent-solid-hover disabled:opacity-50 disabled:cursor-not-allowed rounded-full focus-visible:ring-2 focus-visible:ring-accent"><span class="h-5 w-5 i-lucide-arrow-up" aria-hidden="true"></span></button>
|
|
111
119
|
</form>
|
|
112
120
|
</div>
|
|
113
121
|
</div>
|
|
@@ -115,11 +123,17 @@ watch(() => active() && visibility() === 'visible' ? chat.scopeKey() : null, (sc
|
|
|
115
123
|
|
|
116
124
|
<style>
|
|
117
125
|
.stx-chat-inbox { container: stx-chat / inline-size; }
|
|
126
|
+
.stx-chat-composer { field-sizing: content; max-height: 7rem; }
|
|
127
|
+
@media (width < 768px) {
|
|
128
|
+
.stx-chat-inbox[data-compact="false"]:has([data-chat-thread]) {
|
|
129
|
+
height: max(340px, calc(100dvh - 210px));
|
|
130
|
+
min-height: 0;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
118
133
|
@container stx-chat (min-width: 48rem) {
|
|
119
134
|
.stx-chat-inbox[data-compact="false"] .stx-chat-sidebar { display: flex; width: 20rem; }
|
|
120
135
|
.stx-chat-inbox[data-compact="false"] .stx-chat-back { display: none; }
|
|
121
136
|
.stx-chat-inbox[data-compact="false"] .stx-chat-empty { display: flex; }
|
|
122
137
|
.stx-chat-inbox[data-compact="false"] .stx-chat-message { max-width: 75%; }
|
|
123
|
-
.stx-chat-inbox[data-compact="false"] .stx-chat-shortcut { display: inline; }
|
|
124
138
|
}
|
|
125
139
|
</style>
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
/*
|
|
3
|
+
* <RenderSurface>: a box shared TypeScript draws into, frame by frame, with
|
|
4
|
+
* no WebView (stacksjs/stx#2108, craft-native/craft#578).
|
|
5
|
+
*
|
|
6
|
+
* <RenderSurface class="flex-1" filter="nearest"
|
|
7
|
+
* @ready="loop = startRenderLoop($event.surface, paint)"
|
|
8
|
+
* @restored="loop.wake()" @error="report($event)" />
|
|
9
|
+
*
|
|
10
|
+
* On a native screen it is the host's RenderSurface, drawn with Metal; in a
|
|
11
|
+
* browser it is a <canvas>. Frames go in through `presentFrame` or
|
|
12
|
+
* `startRenderLoop` from `@stacksjs/components/render-surface`, by the name
|
|
13
|
+
* `ready` carries.
|
|
14
|
+
*
|
|
15
|
+
* Props:
|
|
16
|
+
* - `surface`: the name frames are given to. Unique on the screen; when it is
|
|
17
|
+
* left out each instance gets its own. A second live surface of a name
|
|
18
|
+
* already taken stays blank and reports `DUPLICATE`.
|
|
19
|
+
* - `filter`: `nearest` (the default, for pixel art) or `linear`, used when a
|
|
20
|
+
* frame's size differs from the box's pixels.
|
|
21
|
+
* - `opaque`: true by default. A surface that is not opaque takes
|
|
22
|
+
* premultiplied alpha.
|
|
23
|
+
* - `label`: what a screen reader says for it.
|
|
24
|
+
* - `unavailableText`: what shows in its place where nothing can draw one.
|
|
25
|
+
*
|
|
26
|
+
* Events:
|
|
27
|
+
* - `ready` the first time it has a size, then `resize` on each change, both
|
|
28
|
+
* `{ surface, width, height, scale, pixelWidth, pixelHeight }`;
|
|
29
|
+
* - `lost` (`{ surface, reason }`) when the app goes to the background on a
|
|
30
|
+
* phone, and `restored` (the metrics again) when it returns: nothing is
|
|
31
|
+
* kept across a loss, so draw a whole frame again;
|
|
32
|
+
* - `error` with `{ surface, code, message }`: `UNAVAILABLE` where this device
|
|
33
|
+
* cannot draw one (the box then says so rather than staying blank), or
|
|
34
|
+
* `DUPLICATE`.
|
|
35
|
+
*/
|
|
36
|
+
export const surface = $props.surface || `surface-${$uid}`
|
|
37
|
+
export const filter = $props.filter === 'linear' ? 'linear' : 'nearest'
|
|
38
|
+
export const opaque = $bool($props.opaque, true)
|
|
39
|
+
export const className = $props.className || $props.class || ''
|
|
40
|
+
export const label = $props.label || ''
|
|
41
|
+
export const unavailableText = $props.unavailableText || 'This device cannot draw this view.'
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<script client>
|
|
45
|
+
import { claimCanvasSurface, renderSurfaceHost } from './render-surface'
|
|
46
|
+
|
|
47
|
+
const emit = defineEmits(['ready', 'resize', 'lost', 'restored', 'error'])
|
|
48
|
+
const name = {{ surface }}
|
|
49
|
+
const filter = {{ filter }}
|
|
50
|
+
const opaque = {{ opaque }}
|
|
51
|
+
const nativeHost = !!window.stx._host.isNative
|
|
52
|
+
const canvasRef = useRef('canvasRef')
|
|
53
|
+
const unavailable = state(false)
|
|
54
|
+
let claim = null
|
|
55
|
+
let observer = null
|
|
56
|
+
let sized = false
|
|
57
|
+
|
|
58
|
+
// A host event carries its payload as nativeEvent; the shared runtime may
|
|
59
|
+
// also hand it over as it is.
|
|
60
|
+
function payload(event) {
|
|
61
|
+
return (event && event.nativeEvent) || event || {}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function metrics(event) {
|
|
65
|
+
const m = payload(event)
|
|
66
|
+
return { surface: name, width: m.width, height: m.height, scale: m.scale, pixelWidth: m.pixelWidth, pixelHeight: m.pixelHeight }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function fail(error) {
|
|
70
|
+
if (error.code === 'UNAVAILABLE') unavailable.set(true)
|
|
71
|
+
// Reported, never swallowed: a DUPLICATE is a page mistake, and the box
|
|
72
|
+
// stays blank until it is fixed.
|
|
73
|
+
emit('error', { surface: name, code: String(error.code || 'ERROR'), message: String(error.message || '') })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function hostReady(event) { emit('ready', metrics(event)) }
|
|
77
|
+
function hostResize(event) { emit('resize', metrics(event)) }
|
|
78
|
+
function hostLost(event) { emit('lost', { surface: name, reason: String(payload(event).reason || 'background') }) }
|
|
79
|
+
function hostRestored(event) { emit('restored', metrics(event)) }
|
|
80
|
+
function hostError(event) { fail(payload(event)) }
|
|
81
|
+
|
|
82
|
+
// A browser has no surface events of its own. The canvas's size stands in
|
|
83
|
+
// for them: its first size is `ready`, each change after it `resize`.
|
|
84
|
+
function measure() {
|
|
85
|
+
const canvas = canvasRef.value
|
|
86
|
+
if (!canvas || !claim || claim.error) return
|
|
87
|
+
const box = canvas.getBoundingClientRect()
|
|
88
|
+
if (box.width <= 0 || box.height <= 0) return
|
|
89
|
+
const scale = window.devicePixelRatio || 1
|
|
90
|
+
const detail = { surface: name, width: box.width, height: box.height, scale, pixelWidth: Math.round(box.width * scale), pixelHeight: Math.round(box.height * scale) }
|
|
91
|
+
emit(sized ? 'resize' : 'ready', detail)
|
|
92
|
+
sized = true
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
onMount(() => {
|
|
96
|
+
// Per mount: an :if can take the surface away and bring it back with the
|
|
97
|
+
// same setup, and coming back is a new surface with a ready of its own.
|
|
98
|
+
sized = false
|
|
99
|
+
if (nativeHost) {
|
|
100
|
+
// The host also says UNAVAILABLE once at mount; knowing it here shows the
|
|
101
|
+
// fallback without waiting for that.
|
|
102
|
+
if (renderSurfaceHost() === 'none') unavailable.set(true)
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
const canvas = canvasRef.value
|
|
106
|
+
if (!canvas) return
|
|
107
|
+
canvas.style.imageRendering = filter === 'nearest' ? 'pixelated' : 'auto'
|
|
108
|
+
claim = claimCanvasSurface(name, canvas, { opaque })
|
|
109
|
+
if (claim.error) { fail(claim.error); return }
|
|
110
|
+
// The observer's first answer, after layout, is the ready. Measured here
|
|
111
|
+
// instead, a surface mounted again under an :if said ready before the
|
|
112
|
+
// page's listener was back on it, and the page never heard.
|
|
113
|
+
if (typeof ResizeObserver === 'function') {
|
|
114
|
+
observer = new ResizeObserver(() => measure())
|
|
115
|
+
observer.observe(canvas)
|
|
116
|
+
}
|
|
117
|
+
else setTimeout(measure, 0)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
onDestroy(() => {
|
|
121
|
+
sized = false
|
|
122
|
+
if (observer) observer.disconnect()
|
|
123
|
+
observer = null
|
|
124
|
+
if (claim && claim.release) claim.release()
|
|
125
|
+
claim = null
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
defineExpose({ surface: name, unavailable })
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
{{-- data-stx-layout-root: a phone has no display:contents, so the scope around
|
|
132
|
+
this root is a real box there, and an unsized one left the surface 0
|
|
133
|
+
points wide in a row: the host never said ready. --}}
|
|
134
|
+
<div class="relative flex flex-col min-h-0 min-w-0 {{ className }}" data-render-surface data-stx-layout-root>
|
|
135
|
+
<canvas data-native="RenderSurface" ref="canvasRef" surface="{{ surface }}" filter="{{ filter }}" :opaque="{{ opaque }}" role="img" @if(label) aria-label="{{ label }}" @endif class="flex-1 block w-full min-h-0 min-w-0" @ready="hostReady($event)" @resize="hostResize($event)" @lost="hostLost($event)" @restored="hostRestored($event)" @error="hostError($event)"></canvas>
|
|
136
|
+
<div :show="unavailable()" role="status" class="absolute inset-0 flex items-center justify-center p-4 text-center text-sm text-fg-muted">{{ unavailableText }}</div>
|
|
137
|
+
</div>
|
|
@@ -0,0 +1,74 @@
|
|
|
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 } from './swipe-row'
|
|
12
|
+
|
|
13
|
+
const emit = defineEmits(['action'])
|
|
14
|
+
const nativeHost = {{ nativeHost }}
|
|
15
|
+
const actions = useReactiveProp('actions', {{ initialActions }})
|
|
16
|
+
const actionsLabel = useReactiveProp('actionsLabel', {{ defaultLabel }})
|
|
17
|
+
const disabled = useReactiveProp('disabled', {{ initialDisabled }})
|
|
18
|
+
const testId = useReactiveProp('testID', {{ testID }})
|
|
19
|
+
const opened = state(false)
|
|
20
|
+
const actionWidth = 88
|
|
21
|
+
const offset = derived(() => opened() ? actionWidth * actions().length : 0)
|
|
22
|
+
|
|
23
|
+
function close() {
|
|
24
|
+
closeSwipeRow(close)
|
|
25
|
+
opened.set(false)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function open() {
|
|
29
|
+
if (disabled() || !actions().length) return
|
|
30
|
+
openSwipeRow(close)
|
|
31
|
+
opened.set(true)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function swipe(direction) {
|
|
35
|
+
if (direction === 'left') open()
|
|
36
|
+
else if (direction === 'right') close()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function activate(id) {
|
|
40
|
+
if (disabled() || !actions().some(action => action.id === id)) return
|
|
41
|
+
close()
|
|
42
|
+
emit('action', id)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
effect(() => {
|
|
46
|
+
if (!actions().length || disabled()) close()
|
|
47
|
+
})
|
|
48
|
+
onMount(() => close)
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<div class="relative overflow-hidden {{ className }}" :testID="testId()"
|
|
52
|
+
:swipeEnabled="nativeHost && !disabled() && actions().length > 0"
|
|
53
|
+
:swipeDirection="opened() ? 'right' : 'left'"
|
|
54
|
+
@swipe="swipe($event.direction)" @keydown.escape="opened() && close()">
|
|
55
|
+
<div class="flex flex-row items-center"
|
|
56
|
+
:style="nativeHost ? { transform: [{ translateX: -offset() }] } : { transform: 'translateX(' + -offset() + 'px)' }">
|
|
57
|
+
<div class="flex flex-1 flex-col min-w-0"><slot /></div>
|
|
58
|
+
<button :if="actions().length" type="button" class="flex shrink-0 items-center justify-center h-11 w-11"
|
|
59
|
+
:disabled="disabled()" :aria-label="actionsLabel()" :aria-expanded="opened() ? 'true' : 'false'"
|
|
60
|
+
:testID="testId() && testId() + '-actions'" @click="opened() ? close() : open()">
|
|
61
|
+
<i class="h-5 w-5 text-[#636366] dark:text-[#aeaeb2] i-lucide-more-horizontal" aria-hidden="true"></i>
|
|
62
|
+
</button>
|
|
63
|
+
</div>
|
|
64
|
+
<div :if="opened()" class="flex absolute inset-y-0 right-0 flex-row">
|
|
65
|
+
<button :for="item in actions()" :key="item.id" type="button"
|
|
66
|
+
class="flex shrink-0 items-center justify-center px-1 min-h-11"
|
|
67
|
+
:class="item.destructive ? 'bg-[#b4232b] dark:bg-[#b4232b]' : 'bg-[#245fa9] dark:bg-[#245fa9]'"
|
|
68
|
+
:style="{ width: actionWidth + 'px' }" :disabled="disabled()"
|
|
69
|
+
:accessibilityLabel="item.accessibilityLabel || item.label" :aria-label="item.accessibilityLabel || item.label"
|
|
70
|
+
:testID="item.testID || (testId() && testId() + '-' + item.id)" @click="activate(item.id)">
|
|
71
|
+
<span class="text-xs font-semibold text-center text-white" :text="item.label"></span>
|
|
72
|
+
</button>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
package/dist/index.d.ts
CHANGED
|
@@ -86,6 +86,7 @@ export * from './ui/preview-frame/index';
|
|
|
86
86
|
export * from './ui/progress/index';
|
|
87
87
|
export * from './ui/radio/index';
|
|
88
88
|
export * from './ui/radio-group/index';
|
|
89
|
+
export * from './ui/render-surface/index';
|
|
89
90
|
export * from './ui/segmented-control/index';
|
|
90
91
|
export * from './ui/select/index';
|
|
91
92
|
export * from './ui/settings/index';
|