Compare commits

...

5 commits

Author SHA1 Message Date
be8d93e946
Style tweak: make all but selected list icons rounded
In our case, "list icons" usually means "avatars" so think
"rounded avatars, except the currently selected one which remains
square". This makes things look a bit more polished, but still
allow you to properly see the full avatar when you actually need
to.
2024-03-24 23:12:50 +05:30
4379de12df
Catch back button keypress in options menu
By default, the back button exits the entire chat, which is an
overkill if we're just in the menu. This commit makes the options
menu catch the backspace event and simply close the menu instead
of letting it go all the way to closing the conversation.

Along the way, the function was also neatened a bit to use breaks
instead of returns.
2024-03-24 23:11:14 +05:30
073176a9c9
Allow the options menu to toggle itself
Earlier, the toggle was only happening from the outside, but now
we can toggle the options menu from the menu itself. This is
useful when we want to close the menu from inside, for example
when an option has been selected or the back button has been
pressed.
2024-03-24 23:10:22 +05:30
d36fd1afe8
Bugfix: options menu nav broken with new ListItem classes
The autofocus and nav functions were still using the old class
name .list-item-indicator instead of .list-item which it actually
is now.
2024-03-24 23:09:45 +05:30
c4cd385cfe
Make ListItem image optional
It was supposed to be optional anyway, but setting it as undefined
to begin with makes it explicitly optional so Svelte doesn't start
giving warnings and stuff.
2024-03-24 23:06:37 +05:30
3 changed files with 36 additions and 10 deletions

View file

@ -2,7 +2,7 @@
export let text = 'List Item'
export let subtext = ''
export let indicator = false
export let image
export let image = undefined
export let tabindex = -1
export let autofocus = false
export let fullheight = false
@ -88,4 +88,13 @@
.list-item-indicator__subtext::first-letter {
text-transform: none;
}
/* Make all but the selected icon rounded */
.list-item-icon__icon {
border-radius: 0.6rem;
}
.list-item-icon:focus .list-item-icon__icon {
border-radius: 0;
}
</style>

View file

@ -2,12 +2,19 @@
import { onMount } from 'svelte'
export let title = "Options"
// Function to call in order to close the menu.
// This is triggerd either with the "back" button
// or when one of the options is selected.
export let toggler = function() {
console.error("You didn't provide a toggler function to close the options menu!")
}
// Special navigation for the options menu
function optionNav(move) {
let currentIndex = Number(document.activeElement.dataset.index || 0)
let next = currentIndex + move
let items = document
.querySelectorAll('.options .list-item-indicator')
.querySelectorAll('.options .list-item')
// Loop around if at end
if (next < 0) next = items.length - 1
@ -23,15 +30,21 @@
case 'ArrowUp':
optionNav(-1)
e.stopPropagation()
return
break
case 'ArrowDown':
optionNav(1)
e.stopPropagation()
return
break
case 'Enter':
toggler()
document.activeElement.click()
e.stopPropagation()
return
break
case 'Backspace':
toggler()
e.stopPropagation()
e.preventDefault()
break
}
}
@ -42,7 +55,7 @@
// Focus the first option item
let optionItems = document
.querySelectorAll('.options .list-item-indicator');
.querySelectorAll('.options .list-item');
// Set the index attributes (We assume this won't
// change too often/until the next time the menu

View file

@ -26,6 +26,9 @@
// Whether the options menu is visible or not
let optionsMenuVisible = false
function toggleOptionsMenu() {
optionsMenuVisible = !optionsMenuVisible
}
$: title = chatbox?.attributes?.nickname || chatbox?.attributes?.id || params.chatID || 'Convo'
@ -96,9 +99,7 @@
}
k.right.label = 'Options'
k.right.callback = () => {
optionsMenuVisible = !optionsMenuVisible
}
k.right.callback = toggleOptionsMenu
return k
})
@ -244,7 +245,10 @@
</div>
{#if optionsMenuVisible}
<OptionsMenu title="Options">
<OptionsMenu
title="Options"
toggler={toggleOptionsMenu}
>
<ListItem
text="Close conversation"
onclick={closeChat}