elcritch

elcritch

Bulma Widgets - LiveComponent wrappers using Bulma

Update Aug 2024:

I’ve been working on re-writing my previous bulma widgets library to modernize it. There’s basic components for most of the basic bulma elements. There are also a few initial stateful live components for dropdowns and menus.

The library also includes the necessary Bulma CSS files for easy setup.

A big part of the re-write focuses on changing how the state of widgets is handled. There’s an event system which provides out-of-the-box support for updating shared values from a parent liveview in child live components. There’s also support for cached values and broadcasting values. I’m still working on documenting the design, but the api’s in what I think is a useable state.

The goal is easy development for small scale app style UIs for Nerves devices.

Here’s the examples I’ve been developing with:


Original (Mar 2020):

BulmaWidgets – LiveComponent wrappers around Bulma CSS “widgets” for Phoenix LiveView. This library is intended to wrap the Bulma elements/components into mostly self-contained components. These components help make developing interactive UI’s in LiveView simpler.

Code is on Github at Bulma Widgets. An example server is running at http://lacritch.xyz/.

This is an early release being porting from an earlier internal pre-live-component UI library. I’d appreciate any feedback, ideas on implementing the component interactions with the parent LiveView. There is a little bit of interaction between the parent LiveView and the components, but it’s very minimal.

Currently only two elements have been ported, but show the overall usage. Future elements will be mostly focused on inputs / user selections useful for allowing users to select options or user components (such as tabs). Providing wrappers for elements like Cards requires a lot of API options, and so may not fit well into this library.

While this library is similar to Surface it’s much less ambitious in scope… I’d recommend Surface for those who want a full featured component library. This library focus’s on providing basic LiveView-only UI components without needing a separate template engine or tooling.

Most Liked

elcritch

elcritch

Oh yes, that’s correct. Nerves builds a firmware image with the system and code that can be uploaded via an Upload script by ./upload.sh lacritch.xyz. Easy as can be. The code for this server is on my GitHub at Cloud Server. I should probably fix the Phoenix signing keys so they’re not in the config.exs but this is a throw-away server so I made it public so you could see it. The whole process is programmable in a few dozen lines of Elixir as well. Bootstrapping the initial VPS image is a little fiddly but not too bad. I used a Knoppix image to write the initial Nerves firmware to a VPS disk and it worked like a charm.

Another note is that I don’t see why one couldn’t take a Nerves firmware image and create a container image by dumping the squashfs filesystem to a tarball. Then you don’t need to worry about library version compatibility since it’s all cross-compiled. :slight_smile: There’s more discussion on the topic Can you use nerves to deploy a cloud-based server? - #12 by axelson and Running Nerves on Amazon EC2

Honestly, when/if my company needs to deploy web services I’m going to use Nerves images. I don’t see the need for K8s unless you’re doing microservices and I plan to do everything in Elixir. Maybe make a nice LiveView dashboard, insta k8s alternative. :wink:

elcritch

elcritch

An interesting note on the lacritch.xyz server is that it’s using Nerves to build and deploy to a small Linux VPS. It currently takes ~5 seconds to come back up after rebooting. It doesn’t have a proxy in front, so if anyone any security issues I’d love to know!

elcritch

elcritch

I find making a library out of my internal widgets helps keep me a bit more disciplined in documenting them. Plus maybe others find them useful. :slight_smile: Not currently planning on adding Bulma extensions as I don’t use them currently, but I’d be willing to accept PR’s.

Great! I used yours to see how I could model something like a card component. I tried a few variations and ended up liking a pattern of using a case statement in a do block with the LiveComponents as the Source-of-Truth. Though I also provide a “default” setup using proplist options for cases where you would want standard buttons, like this:

    <%= live_component @socket, CardComponent, 
                   id: :card1, 
                   footers: ["Save Item": "card-1-save"] do %>
      <%= case @item do %>
        <% :content_item -> %>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit.
          Phasellus nec iaculis mauris. <a>@bulmaio</a>.
          <a href="#">#css</a> <a href="#">#responsive</a>
          <br>
          <time datetime="2016-1-1">11:09 PM - 1 Jan 2016</time>
        <% _other -> %>
      <% end %>
    <% end %>

It turns out that using the do-block actually makes composability pretty straightforward, even using the parent LiveView assigns (@modal_va is set in the parent LiveView) works! I’m pretty happy with the composability, even though you have to write a case statement. A macro would be nice to handle that but broke when I tried it.

You can also mix and match from default event handlers or custom ones like in this example. Note the save-button targets the parent LiveView while the cancel-button uses the default cancel handler:

    <%= live_component @socket, ModalComponent, id: :modal2 do %>
      <%= case @item do %>
        <% :header -> %>
          <p class="modal-card-title">Second Modal</p>
          <button class="delete" phx-click="delete" phx-target="<%= @target %>" aria-label="close">
        <% :footer -> %>
          <button class="button is-success" phx-click="modal-2-save" >
            Save changes
          </button>
          <button class="button" phx-click="cancel" phx-target="<%= @target %>">
            Cancel
          </button>
        <% _other -> %>
      <% end %>
    <% end %>

Originally I tried using the parent LiveView as the Source-of-Truth, but it seems you can’t define handle_event’s without providing an id and state in the LiveComponent (in LiveView v0.9.0). Between that and having two spots to define/configure the widgets felt confusing and a bit cumbersome. So having the widgets send events to the parent LiveView allows a pretty simple interaction between widgets that seems pretty simple and robust so far. Though documenting it well is the tricky part.

Also there are helper functions to do things like open/close/update a widget like:

  def handle_event("modal-1-save", _params, socket) do
    {:noreply, socket |> widget_close(:modal1)}
  end
elcritch

elcritch

I’ve been working on re-writing my previous bulma widgets library to modernize it. There’s basic components for most of the basic bulma elements. There are also a few initial stateful live components for dropdowns and menus.

The library also includes the necessary Bulma CSS files for easy setup.

A big part of the re-write focuses on changing how the state of widgets is handled. There’s an event system which provides out-of-the-box support for updating shared values from a parent liveview in child live components. There’s also support for cached values and broadcasting values. I’m still working on documenting the design, but the api’s in what I think is a useable state.

The goal is easy development for small scale app style UIs for Nerves devices.

Here’s the examples I’ve been developing with:

ondrej-tucek

ondrej-tucek

Hey @elcritch this is very cool project :slight_smile: We also like and use Bulma for our projects, for example see our app (still WIP). It’s all written in LiveView.

Did you consider about how change a css style or a html content in your components for different using? I mean, e.g. a few modal window, one for showing danger action (see our modal in app), one for showing warning (different style and data), etc. But it’s only one component (as you can see in our component modal).

Where Next?

Popular in Libraries Top

tmbb
I’ve decided to create this topic to discuss optimization possibilities for something like Phoenix LiveView. I’ve created this topic unde...
New
markmark206
simple_feature_flags is a tiny package that lets you turn features on or off based on which environment (e.g. localhost, staging, product...
New
Qqwy
TypeCheck: Fast and flexible runtime type-checking for your Elixir projects. Core ideas Type- and function specifications are const...
336 13801 100
New
dbern
I’m excited to announce that TaxJar has developed and open-sourced DateTimeParser. We developed it because we found a need to parse user ...
New
praveenperera
FastRSS Parse RSS feeds very quickly: This is rust NIF built using rustler Uses the RSS rust crate to do the actual RSS parsing Speed...
New
michalmuskala
Another small library today. PersistentEts Hex: persistent_ets | Hex GitHub: GitHub - michalmuskala/persistent_ets Ets table backed by...
New
benlime
LiveMotion enables high performance animations declared on the server and run on the client. As a follow up to my previous thread A libr...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
bryanjos
Hi, I wanted share a small library we at Revelry Labs made for rendering react components from the server side. There are instructions fo...
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Sub Categories:

We're in Beta

About us Mission Statement