@stacksjs/components 0.2.921 → 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/SwipeRow-6myz9c27.stx +74 -0
- package/dist/index.js +14 -14
- 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/package.json +3 -3
- 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/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,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>
|