msaraiva

msaraiva

Broadway Core Team

Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative way to express and use components in Phoenix. Some of the main features include:

  • Components as modules - they can be stateless, stateful, data-only or compile-time
  • Declarative properties - explicitly declare the inputs (properties) of each component (like React)
  • An HTML-centric templating language with built-in directives (:for, :if, …) and syntactic sugar for attributes (inspired by Vue.js)
  • Contexts - allows parent components to share data with its children without passing them as properties
  • Compile-time checking of components and their properties
  • Integration with editor/tools for warnings, syntax highlighting, jump-to-definition, auto-completion and more

A work-in-progress live demo with more details is available at surface-demo.msaraiva.io.

Installation instructions and other useful information can be found at github.com/msaraiva/surface.

And finally, a VS Code extension that adds support for syntax highlighting is also available at
marketplace.visualstudio.com.

There’s still a lot of work to do and I hope some of you out there might be willing to help me in this journey. Bear in mind that the LiveView Component API has not reached a stable version yet and it’s currently under development, so although we try to keep track of the latest changes as much as possible, there might be temporary incompatibilities between Surface and Phoenix LiveView until a final version is released.

I’d like to thank @chrismccord and the Phoenix Core Team for buying the idea of reusable components and bringing the necessary basic concepts to the core API.

I also want to thank @josevalim, not only for the many valuable insights during development but also for his inestimable help with the main parser.

Happy coding!

-marlus

45389 214

Showing Posts 1 to 10

msaraiva

msaraiva OP

Broadway Core Team
mindok

mindok

Nice work Marlus! Many gems in there. It sounds silly, but the biggest immediate win for me is likely the css-twiddling - visual indicators of state changes make for lots of messy code currently.

Quick question - is it possible to have a Surface Component embedded in a “traditional” LiveView?

haubie

haubie

Nice! I wondered how you did it when I saw your preview in Twitter!

imartinat

imartinat

That’s awesome! Thank you very much Marlus for this great library and great documentation.

msaraiva

msaraiva OP

Broadway Core Team

the biggest immediate win for me is likely the css-twiddling - visual indicators of state changes make for lots of messy code currently.

Indeed. This was one of the first things I implemented. It’s quite a simple concept but it turned out to be extremely useful :slight_smile:

is it possible to have a Surface Component embedded in a “traditional” LiveView?

Definitely! After translation, which is done at compile-time, the code becomes just an ordinary phoenix template, not different from any code written using the built-in ~L. Just make sure you import Surface so you have ~H available or add it to your lib/my_app_web.ex. Like:

...

  def view do
    quote do
      ...
      import Surface
    end
  end

This way you’ll have it available in any view!

eaverdeja

eaverdeja

That’s awesome!! I think React and other JS frameworks have very nice mental models (despite the problems that surround actually using these tools in practice).

I’m glad Phoenix (& ecosystem) is a late mover in this space and that there is will to learn and borrow from these mental models. Much love Marlus :heart:

msaraiva

msaraiva OP

Broadway Core Team

In case you’re giving Surface a try, please update it to the latest version on master. Updates include:

  • A new parser that provides much more accurate messages on parsing/translation errors (thanks to José Valim)
  • Handle void HTML elements like <br> and <hr> without need to self close the tag
  • Append property info to components’ documentation
  • More bug fixes

Example - showing component docs on hover with appended property info:

13
Post #7
niccolox

niccolox

have you thought about using something like Liquid templates for your syntax?

cnck1387

cnck1387

Call me stupid but can someone explain the value in having such an abstraction in practice?

In the Grid example it looks like you could have put the <table> inside of a template in the render function and it would work the same and be more similar to how templates work with EEx.

What wins are there for setting things up like this instead?

eaverdeja

eaverdeja

Wouldn’t it enable us to build component libraries with thought out APIs and standalone tests? Similar to what material-ui does on the React world. That would be a big win in my book :relieved_face:

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
rodloboz
I’ve started working on a new library to run SQL queries and do basic business intelligence. Think “Blazer for Elixir.” Currently it fe...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews