mastodon.ar.al is one of the many independent Mastodon servers you can use to participate in the fediverse.
This is my personal fediverse server.

Administered by:

Server stats:

1
active users

🍞 Kitten toast, anyone?

A fifteen-second demo of how you can create a toast message in 42 lines of code¹ without writing any client-side JavaScript using Streaming HTML² in Kitten³.

Video:

vimeo.com/925828491

Source code:

codeberg.org/kitten/app/src/br

Enjoy!

:kitten: 💕

¹ Almost half of which is CSS.
² ar.al/2024/03/08/streaming-htm
³ codeberg.org/kitten/app

Notice how:

- A 2 second settle duration is set. Coupled with the 0.7 second transition set in CSS, this makes toast messages fade + slide in for 0.7 seconds, remain displayed for 1.3 seconds, then fade + slide out in 0.7 seconds.

- We first stream a new Toast fragment followed by a MessageInput fragment to clear the message input.

- The message input doesn’t lose focus. This is due to the morph attribute on it making Kitten surgically replace changed attributes instead of the whole element.

Aral Balkan

PS. Those 42 lines are all the source code.

That’s it.

No scaffolding. No npm create this-or-that.

1. Create a folder called toast.
2. Add those 42 lines of code to a file called index.page.js in that folder.
3. Run kitten¹.

Now hit https://localhost in your browser and you will see the example running just like in the video in the first post.

:kitten: 💕

¹ codeberg.org/kitten/app

# Kitten

Summary card of repository kitten/app
Codeberg.orgappA web development kit that’s small, purrs, and loves you.

@aral I can imagine how things relate to each other by looking for symbol names but this really looks like black magic :)

@ctietze TL; DR: element names on form elements, as well as any other element wired up via the `connect` attribute, get mapped to event handlers on the server where the event name matches the element name.

If you want to learn the intricacies of the wiring, you’ll have to read the post :) (Or else, I’d have to rewrite the post here.) It involves htmx and a little Kitten magic with an automatically-created WebSocket route and event routing logic.

@aral thanks! I was thinking that from the code in the video, it looks similar to the triggers and emplacement rules that HTMX uses.

Now that you clarify that HTMX is actually used under the hood, that clarifies things :)