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

46025 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

type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
kip
I’ll shortly be launching Text, a nascent text analysis library. Current functionality In this early version (not ready for prime time) ...
New
kip
Following on from my CLDR lbraries I started work on Unicode transforms. But like everything related to CLDR there is a lot of yak-shavin...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews