Hyperkit
I’ve been working on Hyperkit over the past fortnight, and the first release is now live on npm. It’s a collection of headless custom elements/web components designed to simplify building rich UIs with serverside frameworks like Rails or Revel.
It’s more like Headless UI than Shoelace: you bring your own styling.
Here’s an example of a styled sortable list:
<hyperkit-sortable class="bg-white rounded shadow-md w-64 overflow-hidden">
<hyperkit-sortable-item
class="flex items-center justify-between pr-4 pl-3 py-2 border-b border-b-stone-200 data-[before]:border-t-2 data-[before]:border-t-blue-400 data-[after]:border-b-2 data-[after]:border-b-blue-400 text-stone-800"
>
<hyperkit-sortable-handle>
<button
class="cursor-move mr-2 text-stone-400 select-none font-black px-1"
>
⋮
</button>
</hyperkit-sortable-handle>
<span class="text-xs font-medium flex-grow">Item 1</span>
</hyperkit-sortable-item>
<hyperkit-sortable-item
class="flex items-center justify-between pr-4 pl-3 py-2 border-b border-b-stone-200 data-[before]:border-t-2 data-[before]:border-t-blue-400 data-[after]:border-b-2 data-[after]:border-b-blue-400 text-stone-800"
>
<hyperkit-sortable-handle>
<button
class="cursor-move mr-2 text-stone-400 select-none font-black px-1"
>
⋮
</button>
</hyperkit-sortable-handle>
<span class="text-xs font-medium flex-grow">Item 2</span>
</hyperkit-sortable-item>
</hyperkit-sortable>
The pull of React, for me, has always been the clarity and DX that comes with colocating a component’s behaviour with it’s markup and styling. It makes a complex front-end way more intuitive/easy to reason with. The counterpart in Rails is Stimulus, which comparatively feels disconnected - relying on magic incantations of data attributes to apply behaviour. There’s a lack of traceability with Stimulus.
But for situations like a stylable select, or click to copy component, I don’t want to be reaching for React. Thus, Hyperkit - custom elements for UX patterns like sortable lists, repeating fieldsets and even calendars. Because Hyperkit uses custom elements, they’re just plain HTML tags, with all the behaviour encapsulated in the tag. No need to write a line of Javascript.
And if you use it with Phlex, you can build end-to-end frontends in pure ruby 🤌