spotifyovercastrssapple-podcasts

elm-ui

We discuss the fundamentals of elm-ui, and how to decide if it's the right fit for your team.
July 27, 2020
#9

Previously called style-elements

Escape hatches

  • Element.html works at leaf nodes, but elm-ui in general doesn’t mix with plain html

  • Element.htmlAttribute

  • Refactoring is a huge asset for a team, so much easier than css refactoring

  • Doesn’t expose all the css tricks directly, sometimes you need escape hatches to access those

Responsiveness

  • Pass in window size from your Elm model
  • Doesn’t use media queries, so that approach doesn't play well with with pre-rendered html like in elm-pages
  • classifyDevice is an optional helper for responsiveness

Semantic html

  • Express layout with Element.row, column, el
  • Semantic HTML is independent from layout. Set with attributes using the Element.Region module.

Wrapping

  • Element.paragraph uses text wrapping

em/rem

  • elm-ui doesn't expose access to rem and em units to simplify the mental model and reduce overlapping ways to express something

Cookbooks/examples

Lucas Payr's elm-ui-widgets Alex Korban's elm-ui patterns )

Debugging elm-ui views

  • Element.explain gives you highlights around nested elements
  • Inspecting developer tools doesn't help much with elm-ui, but elm-ui is much more traceable because it doesn't have layout cascading like CSS

Resources

Transcript

[00:00:00]
Hello, Jeroen.
[00:00:02]
Hello, Dillon.
[00:00:03]
So what are we talking about today?
[00:00:05]
Today, we are pulling out some UI knowledge
[00:00:11]
and talking about Elm UI.
[00:00:13]
I think it's the first time we talk about UI, actually.
[00:00:16]
That's true.
[00:00:17]
I do tend to, as an Elm developer,
[00:00:20]
you think so much about types, business logic.
[00:00:23]
It almost feels like this backend developer mindset
[00:00:28]
focused on sort of modeling the domain and things like that
[00:00:31]
and refactoring and testing.
[00:00:33]
But UI is an important skill.
[00:00:36]
It's not necessarily my strong suit,
[00:00:38]
but I think it's important,
[00:00:39]
and I think Elm UI is a super cool way to do it in Elm.
[00:00:42]
Yeah, it's not my strong suit either.
[00:00:44]
I'm more of a tooling guy.
[00:00:47]
But Elm is a frontend language,
[00:00:50]
or language for web apps.
[00:00:52]
So it is kind of a big point.
[00:00:57]
Essentially, what we're doing with Elm, for the most part,
[00:01:00]
is trying to put things on a web page.
[00:01:02]
So if we can do that nicely, elegantly,
[00:01:05]
in a maintainable way, it's a really important skill.
[00:01:09]
So I think the first question to answer is,
[00:01:11]
what is Elm UI?
[00:01:13]
Yep, what is Elm UI?
[00:01:15]
Well, first of all, it is a way to get something
[00:01:18]
of the type HTML in your Elm application, ultimately.
[00:01:23]
That's what it does.
[00:01:25]
But it does that in a way that's got a very Elm sort of philosophy.
[00:01:29]
That's really the way I think of it,
[00:01:31]
is if you take the philosophical ideas of Elm,
[00:01:33]
the simplicity, predictability,
[00:01:36]
the focus on making a really nice experience
[00:01:41]
without prioritizing being backwards compatible
[00:01:45]
with every script and library that's been written before,
[00:01:50]
and instead trying to create a nice little space
[00:01:53]
where you can express things in a very nice and safe way.
[00:01:56]
That's how I think of Elm UI, ultimately.
[00:01:59]
If you didn't have to worry about being backwards compatible
[00:02:02]
with every CSS decision ever,
[00:02:05]
how would you create a new way of expressing views and layouts
[00:02:09]
that would be really easy to understand,
[00:02:11]
and that's speaking in the language of a human,
[00:02:13]
not in a standard body that sort of evolved
[00:02:18]
into all these past decisions.
[00:02:20]
Since 1995 or something, yeah.
[00:02:23]
I don't know how old CSS is, actually.
[00:02:25]
I don't know the history there.
[00:02:27]
So Matt Griffith, the author of Elm UI,
[00:02:30]
he's quite knowledgeable about all those trivial things and stuff.
[00:02:34]
It's really fun to talk to him about that stuff.
[00:02:36]
But I think that's one of the really cool things,
[00:02:38]
is that Elm UI,
[00:02:40]
CSS has a lot of overlapping ways to do things,
[00:02:42]
and you see this happening a lot
[00:02:47]
in the system that you introduce let and const in ES6,
[00:02:53]
but you don't take away var.
[00:02:54]
Var is still there because the old stuff has to work.
[00:02:57]
And arrow functions are an even better example
[00:03:00]
because people can sort of agree that,
[00:03:03]
for the most part, let's not use var.
[00:03:06]
Now, var does have hoisting,
[00:03:08]
which let and const don't have,
[00:03:10]
so some people might still deliberately choose to use var
[00:03:15]
as a JavaScript style syntax code base.
[00:03:18]
But arrow functions have certain properties
[00:03:22]
of lexical scoping that are more predictable and nice,
[00:03:26]
and they're nicer for certain things,
[00:03:28]
but then they don't have hoisting,
[00:03:30]
and the syntax feels a little awkward to use
[00:03:33]
because you have to bind it to a constant.
[00:03:35]
You have to say const function name equals arrow function.
[00:03:39]
So that's sort of the same feeling with CSS,
[00:03:44]
but you can still float left and float right
[00:03:46]
and do clear fix and all these CSS hacks, right?
[00:03:49]
These things that, like, more old school CSS
[00:03:52]
didn't have native built in support
[00:03:54]
for a lot of things that we have primitives for now
[00:03:57]
with things like Flexbox.
[00:03:59]
But CSS still has all these overlapping ways
[00:04:02]
to express things,
[00:04:03]
and so it becomes really difficult
[00:04:06]
to figure out what are the good parts of CSS.
[00:04:08]
Maybe there are the parts that you are using
[00:04:13]
that you understand all these other things
[00:04:14]
and how they interact with the good parts of it,
[00:04:16]
and LMI doesn't have those problems.
[00:04:18]
Yeah, the biggest problems I find with CSS
[00:04:21]
is that a lot of things are incompatible.
[00:04:23]
Like, you can't use this property
[00:04:25]
if you are also using this one,
[00:04:27]
or if you use this one,
[00:04:29]
you also need to use this one.
[00:04:32]
So if you do flex dash direction,
[00:04:35]
you'd necessarily need to do display flex.
[00:04:37]
You can't forget it.
[00:04:42]
It's pretty simple,
[00:04:45]
but other ones can be pretty complicated.
[00:04:46]
And some of them, like,
[00:04:48]
you really need to know about
[00:04:50]
several browsers implementations.
[00:04:52]
Like, if you do position absolutes,
[00:04:55]
I think you need to set at least top and left
[00:04:58]
or bottom and right.
[00:05:02]
Otherwise, on Internet Explorer 11,
[00:05:06]
it will not show up as expected.
[00:05:11]
Which I have not had the luck to learn about
[00:05:15]
through some great teaching.
[00:05:17]
I had to learn on the stack,
[00:05:19]
and well, my skills are what they are now.
[00:05:21]
Yeah, right.
[00:05:22]
But yeah, when you learn LMI,
[00:05:24]
you learn something from scratch
[00:05:26]
which is well designed, as far as I can tell.
[00:05:30]
Good job, Matt.
[00:05:32]
And yeah, it feels much simpler, much smaller,
[00:05:37]
simply quite nice to use.
[00:05:39]
Yes.
[00:05:40]
Yeah, and exactly as you say,
[00:05:42]
there aren't as many caveats
[00:05:43]
where it's like,
[00:05:44]
okay, here's this feature,
[00:05:46]
but you have to be sure
[00:05:48]
that you use it only in this context,
[00:05:50]
and if you use this one thing,
[00:05:51]
you have to use it with this other thing,
[00:05:53]
with these other conditions,
[00:05:55]
and it's going to conflict with this other thing.
[00:05:58]
And then with CSS,
[00:06:01]
it always feels like there are two ways to do it.
[00:06:06]
And the best practice is to just
[00:06:08]
maybe pick one and stick to it,
[00:06:10]
but then there are certain places
[00:06:11]
where margin and padding behaves differently,
[00:06:14]
like margin around a button
[00:06:16]
is going to have certain behavior
[00:06:19]
versus padding is inside the button.
[00:06:22]
And LMI just says like,
[00:06:24]
hey, you've got padding.
[00:06:26]
That's the tool you use
[00:06:28]
to put space around things.
[00:06:29]
And if you want space around a button,
[00:06:34]
you can use the parent container thing
[00:06:36]
and have that have padding
[00:06:38]
and then have the button inside of that,
[00:06:40]
and that's how you get like,
[00:06:42]
you don't need like these two different ways
[00:06:44]
to express the same idea.
[00:06:46]
And if you think about that
[00:06:47]
from a debugging point of view,
[00:06:49]
if you're looking at a particular page
[00:06:52]
and you know it's written with CSS,
[00:06:54]
where do you even begin
[00:06:55]
to go looking for the problem?
[00:06:57]
It could come from one style sheet.
[00:07:02]
Yeah, when you've got a UI problem,
[00:07:05]
somebody's pointed out that the padding
[00:07:07]
is off on something.
[00:07:09]
In one specific browser.
[00:07:11]
Right, maybe.
[00:07:13]
Well, that's another matter,
[00:07:15]
but there's that too.
[00:07:16]
And actually, LMI,
[00:07:18]
it is kind of cool because LMI
[00:07:20]
can have a way of expressing things
[00:07:22]
and it's more high level
[00:07:23]
than just plain CSS,
[00:07:25]
so it can encapsulate
[00:07:30]
across browser, which is true.
[00:07:32]
That's a nice feature.
[00:07:33]
But even just like a more basic,
[00:07:36]
this needs more padding.
[00:07:37]
Well, where's the padding coming from?
[00:07:38]
Is it defined in this style sheet
[00:07:40]
or in this other style sheet?
[00:07:41]
Is it being overridden?
[00:07:42]
Is there an exclamation point important somewhere
[00:07:45]
that's causing it to happen
[00:07:47]
or a more specific CSS selector somewhere
[00:07:49]
where that padding is coming from?
[00:07:51]
Is it coming from padding or from margin?
[00:07:54]
So there are so many things to think about.
[00:07:59]
So the padding is defined by the parent, period.
[00:08:03]
There's no margin.
[00:08:04]
It's just padding.
[00:08:06]
There's no cascading.
[00:08:08]
It's all just inline styles.
[00:08:11]
That style may be defined,
[00:08:13]
that layout rule may be defined in another module.
[00:08:17]
It may be defined in a function
[00:08:19]
which takes a parameter.
[00:08:21]
So you have to figure that out
[00:08:23]
just like debugging any Elm code,
[00:08:28]
and the debugging is the same as figuring out
[00:08:31]
where a particular value came from in your Elm code.
[00:08:35]
I think we need to address some other basics
[00:08:37]
that we have skipped over.
[00:08:39]
So we're talking about an Elm package
[00:08:42]
which is called md Griffith slash Elm UI,
[00:08:46]
Elm dash UI,
[00:08:47]
because there are several others Elm UI,
[00:08:50]
and this is the one we were talking about.
[00:08:52]
I think everyone in the community
[00:08:57]
is probably authors of other Elm UIs.
[00:08:59]
When they say Elm UI,
[00:09:00]
they talk about their own, maybe.
[00:09:02]
Right, and it was formerly called style elements.
[00:09:06]
So if you ever see that word floating around,
[00:09:10]
there are some really good talks
[00:09:12]
about style elements, unfortunately,
[00:09:14]
but that's sort of the 1.0 version
[00:09:17]
of those ideas of Elm UI.
[00:09:19]
Yeah, I think it doesn't change all that much
[00:09:24]
in this one, the basic ideas.
[00:09:26]
No, the basic ideas are similar.
[00:09:28]
So one of the really big changes is
[00:09:30]
there was a notion of these sort of classes
[00:09:33]
where you built them using Elm types,
[00:09:38]
so you usually would just have one big union type
[00:09:41]
or custom type that defined all the different classes
[00:09:44]
you could have, like your button class
[00:09:46]
and your, maybe the button class has variance to it
[00:09:51]
that it can be like button,
[00:09:53]
primary and button, secondary and things like that.
[00:09:56]
Yeah.
[00:09:57]
And it could have maybe a bool
[00:09:59]
of whether it's enabled or disabled or whatever,
[00:10:01]
but you would apply different styles
[00:10:04]
based on that class, and you would,
[00:10:05]
so instead of having just inline styles
[00:10:08]
that you put, and then it's up to you
[00:10:11]
to choose how you want to abstract those away,
[00:10:13]
you had to have a sort of single place
[00:10:18]
for possible styles and how to display them,
[00:10:21]
and then you would say,
[00:10:24]
I want an element, and it's a button primary.
[00:10:28]
Okay, yeah, that looks pretty different
[00:10:30]
from what is in Elm UI now.
[00:10:32]
And it feels very different,
[00:10:34]
and that was probably the biggest change,
[00:10:37]
and that I think was a very nice change.
[00:10:39]
A lot of the guiding philosophy I think behind Elm UI
[00:10:42]
is like, if we have a way to do it in Elm,
[00:10:47]
let's construct in this library for it.
[00:10:49]
Let's use Elm abstractions
[00:10:51]
like abstracting things to a different module.
[00:10:54]
Yeah, I think it's worth pointing out again
[00:10:57]
that Elm UI is a replacement for Elm HTML.
[00:11:01]
Yes.
[00:11:02]
So it's not like Elm CSS where you use Elm slash HTML
[00:11:06]
and set style properties on it.
[00:11:10]
It is a very different paradigm meant to do the same thing.
[00:11:15]
But as we said several times,
[00:11:18]
in a simpler way, in a nicer way, in a fresher way.
[00:11:22]
Yeah.
[00:11:22]
Right.
[00:11:23]
Ultimately, at some point in your Elm UI based app,
[00:11:27]
you're going to have a function called element.layout
[00:11:29]
or element.layoutwith which you can provide some options,
[00:11:33]
and that's going to be like the top level thing.
[00:11:36]
So your view function,
[00:11:37]
instead of just being a view function
[00:11:39]
that takes in a bunch of HTML,
[00:11:44]
and you're going to use the other Elm view function,
[00:11:46]
you're going to need to give it a type called element
[00:11:48]
from Elm UI, that's its equivalent of HTML,
[00:11:51]
and you just take those elements
[00:11:53]
and you call the element.layout function
[00:11:56]
with all of your elements
[00:11:58]
that represent your entire page's view,
[00:12:00]
and that turns it into HTML,
[00:12:02]
which is something that Elm itself can present in your view.
[00:12:05]
And then otherwise, it feels very similar
[00:12:07]
to the way that we write HTML in Elm,
[00:12:12]
you know, HTML.div list list,
[00:12:15]
where there's like the list of attributes
[00:12:18]
and the list of the children of that div.
[00:12:20]
It's element.row or element.column,
[00:12:25]
and then those also take a list of attributes
[00:12:28]
and a list of children,
[00:12:29]
but the children are of type element,
[00:12:32]
not of type HTML now.
[00:12:34]
So it feels generally very similar in a lot of ways.
[00:12:39]
So I have not had the pleasure to use it professionally.
[00:12:43]
I've used it for a side project, which I've abandoned now.
[00:12:46]
In my previous job, we used Elm CSS,
[00:12:49]
and in my current one at Humia, we use regular CSS.
[00:12:53]
It's working well also,
[00:12:55]
though I'm not very familiar with CSS,
[00:12:58]
or at least not enough.
[00:13:00]
So I think I would have an easier time working with Elm UI,
[00:13:03]
but that's not what we use at the moment.
[00:13:08]
So you've played with it more than I have.
[00:13:12]
So yeah, I was thinking of asking you questions today.
[00:13:15]
Yes, please do.
[00:13:17]
Yeah, you know, to be honest,
[00:13:19]
I haven't used it in a paid professional setting,
[00:13:22]
but I've used it for some pretty substantial...
[00:13:25]
I built a project called Mobster,
[00:13:27]
which is like an electron app that's built with Elm.
[00:13:31]
That actually uses Elm style elements,
[00:13:36]
a few years back.
[00:13:38]
Well, if you have no experience with Elm UI,
[00:13:40]
then this is finished.
[00:13:42]
We're done talking about it.
[00:13:45]
No, I use Elm UI quite a bit in side projects,
[00:13:48]
and I really like it, but yeah.
[00:13:51]
I have the basics, but just the basics.
[00:13:56]
So when would you choose to use Elm UI
[00:13:59]
instead of CSS or Elm CSS
[00:14:04]
or is it all there?
[00:14:06]
Yeah, that is a really good question
[00:14:08]
because it's tempting to always jump on the new shiny thing.
[00:14:12]
And so you have to ask yourself,
[00:14:14]
what business problem does this solve?
[00:14:16]
And then what risks are associated with it?
[00:14:21]
Exactly.
[00:14:22]
What potential dead ends might we run into?
[00:14:25]
And so, I think the first thing to talk about
[00:14:28]
is how does it...
[00:14:33]
design toolkits and frameworks?
[00:14:35]
And that's not what Elm UI is.
[00:14:37]
So if you want to use Bootstrap or Material Design
[00:14:42]
or InDesign, Tailwind, right.
[00:14:45]
Now Tailwind is interesting
[00:14:46]
because Tailwind is a set of utility classes.
[00:14:49]
So Tailwind CSS is actually...
[00:14:52]
You can look at a site and you know it's built with Bootstrap.
[00:14:55]
Even if it's using a sort of custom theme with Bootstrap,
[00:15:00]
it's pretty clear,
[00:15:02]
that's a Bootstrap primary button,
[00:15:05]
that's a Bootstrap secondary button,
[00:15:07]
that's a Bootstrap outline button, whatever.
[00:15:09]
And with Tailwind CSS,
[00:15:12]
often people are going to be sort of copy pasting
[00:15:15]
certain recipes from the Tailwind docs and stuff,
[00:15:19]
which they do quite a nice job.
[00:15:20]
But really you can build a view
[00:15:23]
that looks like whatever you want it to using Tailwind.
[00:15:28]
Organizing that and building that out.
[00:15:31]
So Elm UI is more like that,
[00:15:33]
where it's not going to be a total design framework
[00:15:36]
that's made all these decisions for you
[00:15:38]
and it has a look and feel baked into it, right.
[00:15:41]
Which for a lot of professionally designed
[00:15:44]
custom applications, that's what you want.
[00:15:46]
Because I think you do hit up against a wall eventually
[00:15:48]
if you're limited to the decisions that Bootstrap has made
[00:15:52]
or that Material Design has made.
[00:15:57]
But if you consider, you know, Elm UI is not,
[00:16:00]
it's not designed to play well
[00:16:03]
by just sprinkling in a little bit of CSS.
[00:16:06]
So if you want to look up some CSS
[00:16:09]
for some custom thing, there are escape patches.
[00:16:13]
There is a function called element.html
[00:16:16]
which takes an actual HTML thing
[00:16:19]
and it lets you sneak in an Elm HTML element
[00:16:24]
for Elm UI code.
[00:16:26]
Which is nice because then you can gradually add Elm UI
[00:16:30]
to your project or back out of it also if you don't like it.
[00:16:34]
Yes, definitely.
[00:16:36]
And it doesn't always play nicely
[00:16:38]
and you shouldn't expect it to.
[00:16:42]
But when you're adding something at a leaf node,
[00:16:45]
it might be okay because you're just saying
[00:16:48]
like I have a select, you know, like drop down
[00:16:53]
and it works exactly the way I want.
[00:16:54]
I just want to render that with my regular styles
[00:16:56]
and you call out to it
[00:16:58]
and that's probably going to work pretty well.
[00:17:00]
The reason why you say that it doesn't always work well
[00:17:04]
with normal CSS is because under the hood
[00:17:07]
it uses CSS classes.
[00:17:09]
So ones are very, very small class names,
[00:17:13]
but it does have CSS classes.
[00:17:16]
So potentially they could conflict
[00:17:21]
and it inherits properties from Elm UI elements
[00:17:24]
that are above your HTML elements.
[00:17:28]
Exactly.
[00:17:29]
And there are also escape patches.
[00:17:31]
There's what is it called element.attribute.
[00:17:34]
HTML Attribute.
[00:17:35]
Yeah, exactly.
[00:17:36]
element.html attribute is the escape patch for,
[00:17:40]
you know, you could even add a CSS class
[00:17:44]
to an Elm UI element.
[00:17:49]
And I've found occasions to use it
[00:17:51]
that we can get into more details,
[00:17:53]
like some stuff around like responsive elements
[00:17:56]
with media queries.
[00:17:57]
But, you know, generally if you want to sprinkle in
[00:18:00]
a lot of CSS for whatever reason, you know,
[00:18:03]
you have some really complicated CSS tricks
[00:18:06]
that you're using for things.
[00:18:08]
It's something to be aware of that like Elm UI
[00:18:10]
works really nicely if you're just sort of
[00:18:13]
presenting some core things.
[00:18:18]
But yes, Elm UI is not attempting to expose
[00:18:21]
every single thing you could possibly do with CSS.
[00:18:25]
And it gives you escape patches
[00:18:27]
in case you need to do that.
[00:18:29]
And, you know, if you want a tool that, you know,
[00:18:31]
lets you use the same mental model as using CSS
[00:18:34]
and that lets you just do anything
[00:18:36]
you could possibly do with CSS,
[00:18:38]
but in a way that's more type safe,
[00:18:40]
then that's basically what Richard Feldman's
[00:18:45]
doing.
[00:18:46]
So I often see the advice that if you don't know CSS well,
[00:18:50]
like for instance, if you are a backend developer originally,
[00:18:53]
and you're new to frontend and Elm,
[00:18:57]
then Elm UI is a good recommendation
[00:19:01]
that it will help you out
[00:19:03]
to get things looking nicely in an easy way.
[00:19:06]
So I don't question that that is a good advice.
[00:19:11]
What do you think about using Elm UI
[00:19:13]
when you are someone who knows CSS very well?
[00:19:16]
And also, how does it work with teams?
[00:19:20]
Like when, for instance, you don't know CSS well,
[00:19:23]
but your colleagues do, do you need to win them over?
[00:19:26]
Or is it a bad idea to use Elm UI?
[00:19:29]
Right. Here's my bottom line.
[00:19:31]
Like if the client was asking me,
[00:19:33]
we're considering using Elm UI or something else,
[00:19:38]
I would go with...
[00:19:39]
Yes, go with Elm UI. Go.
[00:19:41]
Yeah, I mean, I think there are a lot of reasons to go with Elm UI.
[00:19:45]
Here's how I would frame that decision.
[00:19:47]
I'd be thinking about, let's start with the pros.
[00:19:50]
We've talked about a lot of them.
[00:19:51]
I think the number one pro in my mind,
[00:19:55]
well, I think the best way to summarize
[00:19:58]
what will work really well for using Elm UI
[00:20:02]
in a company setting for a team
[00:20:07]
is that Elm UI feels way more like refactoring
[00:20:10]
plain Elm code than it does refactoring CSS style sheets.
[00:20:16]
Which if you've ever done both of those things,
[00:20:19]
then I think you know exactly what I mean by that, right?
[00:20:22]
It's very scary.
[00:20:24]
If you're changing CSS,
[00:20:26]
it feels like a huge risk to tweak something
[00:20:29]
because you're like, well, what other things
[00:20:31]
is that going to affect?
[00:20:36]
Just start from scratch.
[00:20:38]
Just start the whole page from scratch.
[00:20:40]
That's what I do.
[00:20:42]
Exactly.
[00:20:43]
And when you're talking about a code base
[00:20:45]
that over time is really going to grow
[00:20:48]
into a large code base and a large team maintaining it,
[00:20:51]
that's huge.
[00:20:52]
Because ultimately, things just can slow down so much
[00:20:56]
as a code base and a team gets large, right?
[00:21:00]
So I would say that that is the number one consideration,
[00:21:05]
how maintainable is it going to be?
[00:21:06]
And that's going to outweigh any cost of,
[00:21:10]
whatever cost there is for learning a new thing.
[00:21:14]
Honestly, learning it isn't that hard.
[00:21:16]
I wouldn't be concerned about learning Elm UI.
[00:21:19]
It does look very simple, yeah.
[00:21:21]
It's quite simple.
[00:21:23]
And it's not the kind of thing that you're like,
[00:21:26]
okay, this is how we use Elm UI
[00:21:28]
and don't use these parts of it
[00:21:33]
as one way to express things for the most part.
[00:21:36]
And then you can organize your code nicely,
[00:21:38]
and that's important.
[00:21:39]
But for the most part, you express things one way.
[00:21:42]
It kind of looks like the same arguments
[00:21:44]
as for Elm, basically.
[00:21:46]
I think that's a really good way to put it, yes.
[00:21:48]
Yeah, if you're willing to make the jump to Elm,
[00:21:51]
then you can make the jump to Elm UI in a way.
[00:21:54]
I think that's probably a pretty fair statement.
[00:21:59]
But yeah, the refactoring experience is second to none
[00:22:04]
as far as view code goes.
[00:22:07]
Because if you're saying,
[00:22:09]
hey, is it going to break anything
[00:22:11]
if I change this style in this one place?
[00:22:14]
You can literally just,
[00:22:16]
if you're using IntelliJ,
[00:22:18]
you can say find usages of the definition
[00:22:22]
of some style thing you're looking at.
[00:22:27]
It's a function for how wide a button is going to be.
[00:22:31]
You can literally say find usages, and that's it.
[00:22:34]
You know every place it's used, which is amazing.
[00:22:37]
So you know that it's not going to have
[00:22:40]
some hidden spooky effects that when you change
[00:22:42]
this one thing, it's going to alter the way
[00:22:44]
these other things are working.
[00:22:46]
You can do a refactoring.
[00:22:48]
If you do a series of steps where I extract this code
[00:22:51]
to this place, I move this here,
[00:22:56]
I know it's going to work the same way.
[00:22:58]
Whereas with CSS, I wouldn't feel that way.
[00:23:00]
Have you ever had a case where you did get a surprise?
[00:23:04]
Not in that way at all, no.
[00:23:06]
Those things aren't surprising.
[00:23:08]
So those are the pros.
[00:23:10]
I think those are the big things that I would be
[00:23:12]
focused on in evaluating that decision for a team.
[00:23:16]
It's like, okay, this is going to be amazing
[00:23:18]
for maintainability and bringing new team members
[00:23:23]
and changing the view code, which is awesome.
[00:23:25]
That's huge.
[00:23:26]
Especially for a web app.
[00:23:28]
Yeah, exactly.
[00:23:30]
Yeah, it's going to be quite nice for adding new things
[00:23:34]
in a really easy way and creating nice abstractions
[00:23:37]
in Elm code.
[00:23:38]
So that part is amazing.
[00:23:40]
The cons I would be considering would be
[00:23:43]
responsiveness is something that, well,
[00:23:45]
I've been talking to Matt about responsiveness
[00:23:50]
like working with Elm pages.
[00:23:52]
So when you talk about responsiveness, it's about
[00:23:55]
making it look good on all window sizes or tablets, mobile.
[00:24:01]
Exactly.
[00:24:02]
And if you change the window size, then things get
[00:24:06]
rearranged automatically.
[00:24:08]
That is something that Elm UI does not do on its own.
[00:24:12]
Does it?
[00:24:13]
It does.
[00:24:14]
But the way it does it is it's just,
[00:24:19]
the recommendation is have a flag that passes in
[00:24:22]
the initial window size and then have a subscription
[00:24:26]
to listen to a resize event in the window.
[00:24:29]
And then store the window size in your model
[00:24:33]
and pass that around any places that need to be responsive.
[00:24:37]
That certainly works.
[00:24:39]
But it's not as smooth as media queries,
[00:24:41]
although it does solve a lot of problems, I think.
[00:24:46]
I mean, I've seen very nice responsive designs built with that.
[00:24:50]
And you can definitely do nice things with it.
[00:24:52]
For me, the problem is if you're pre rendering your pages,
[00:24:56]
then you don't have access to the user's initial window size
[00:25:01]
at the time that you're pre rendering your entire site.
[00:25:04]
Because you just pre render everything to HTML files.
[00:25:07]
And then you just serve up static HTML files.
[00:25:10]
Go listen to episode one about Elm pages if you want to know
[00:25:15]
how to do that.
[00:25:16]
That's right.
[00:25:17]
Media queries play a lot nicer than responsiveness
[00:25:20]
that's in pure Elm code because it doesn't require
[00:25:24]
a JavaScript runtime in order to display correctly.
[00:25:28]
Yeah, it doesn't slow down your page.
[00:25:30]
Yeah.
[00:25:31]
And I wouldn't say that speed is such a problem.
[00:25:34]
It's just that you don't need to wait for the JavaScript
[00:25:37]
to load for the app to be hydrated.
[00:25:42]
But for me, building static sites,
[00:25:45]
I find it to be quite important.
[00:25:47]
And I know it's on Matt's radar,
[00:25:50]
and it's something that we've been talking about.
[00:25:53]
Is there a possible nice design that could support that?
[00:25:56]
So it's possible that there might be support for that.
[00:25:59]
And it's possible that you don't care about that at all.
[00:26:02]
If you're building a big SaaS product,
[00:26:05]
then maybe you don't even pre render your pages
[00:26:10]
and you don't care.
[00:26:11]
I also tend to prefer just saying,
[00:26:14]
okay, here's this view,
[00:26:16]
and I want the width to be whatever.
[00:26:21]
I want it to fill a portion of this size
[00:26:25]
if it's on a larger device.
[00:26:27]
And if it's on mobile,
[00:26:29]
then I want it to fill the full width of the page.
[00:26:32]
Or you want to display some other text, for instance.
[00:26:37]
And I tend to not want to pass around something
[00:26:40]
from my model to do that.
[00:26:42]
Again, maybe that's being finicky,
[00:26:45]
and that's just my own personal preference.
[00:26:47]
So you might totally disagree and say,
[00:26:49]
I really don't care about that,
[00:26:51]
and that works fine for me.
[00:26:53]
That's just my own personal thing.
[00:26:55]
And I find that one of the hardest things to do
[00:26:57]
in order to make a site look really professional
[00:27:00]
is making it responsive.
[00:27:05]
Making things responsive with Tailwind CSS
[00:27:07]
is a really nice experience from what I've worked with.
[00:27:11]
So the way that LMI does it is using a device type
[00:27:16]
or device class information,
[00:27:19]
which is stored in the model,
[00:27:20]
and then you have to pass it around
[00:27:22]
to every child element
[00:27:23]
until you don't need to pass it to any children anymore.
[00:27:26]
Yeah, I mean, that's one helper it gives you.
[00:27:28]
The device is just like a custom type
[00:27:33]
for whatever, like mobile, tablet, browser,
[00:27:35]
whatever it is.
[00:27:36]
You could build your own.
[00:27:38]
You could pass it around.
[00:27:40]
You could pass it as a Boolean, like isMobile,
[00:27:42]
or whatever.
[00:27:43]
It's totally up to you.
[00:27:45]
But ultimately, you have to pass state,
[00:27:47]
and you use pure Elm to say,
[00:27:50]
if I'm on mobile, then render it like this,
[00:27:53]
then include this attribute
[00:27:55]
or use this value for this attribute,
[00:27:56]
else do this.
[00:27:57]
I actually quite like that design.
[00:28:02]
I actually, with LMI,
[00:28:03]
the first time a few years ago,
[00:28:06]
I actually copied that to my work project,
[00:28:09]
which uses Elm CSS,
[00:28:11]
but we still use that version.
[00:28:14]
Because the really nice part I found was,
[00:28:17]
when you want to display different things,
[00:28:20]
like I want to display this text when I'm on desktop,
[00:28:24]
and this text if I'm on mobile.
[00:28:29]
What I see people do in CSS is display both.
[00:28:32]
Well, have both in the HTML tree,
[00:28:35]
and then have a display none
[00:28:37]
in one media query case,
[00:28:40]
and display in the other one.
[00:28:43]
And you switch depending on the device that you're on.
[00:28:48]
So I found that to be much simpler.
[00:28:51]
So I really like that idea.
[00:28:53]
There are also a few other things
[00:28:58]
that I found really easy to use.
[00:29:02]
Oh yeah, definitely.
[00:29:03]
Yeah, right, because you can sort of
[00:29:05]
put the appropriate parent child relationship
[00:29:08]
for the display flex
[00:29:09]
and the flex direction and all that.
[00:29:12]
Yeah, you preset that it's going to be
[00:29:15]
in column or in a row,
[00:29:16]
and it reads better, I think, also.
[00:29:19]
It doesn't read div class something,
[00:29:23]
which doesn't give you much information.
[00:29:28]
It just tells you what it does,
[00:29:30]
which I think is what LMUI's philosophy is about.
[00:29:33]
You explain what it should look like,
[00:29:36]
not what it should represent,
[00:29:39]
which is, I don't know if it's a good idea design wise,
[00:29:43]
but for me it worked well.
[00:29:45]
No, I think that makes a lot of sense.
[00:29:47]
I think it's, LMUI is very declarative, right?
[00:29:50]
And of course that's a very positive thing.
[00:29:52]
Yeah, and I think what you're talking about
[00:29:57]
through pure LMUI stuff,
[00:29:58]
obviously that philosophy has a lot of advantages,
[00:30:01]
and it's a matter of personal preference
[00:30:04]
as much as anything, right?
[00:30:06]
To me it sometimes feels more declarative
[00:30:08]
to say whatever, if a view is going to be displaying
[00:30:12]
in column or row,
[00:30:14]
if I say, like in Tailwind CSS,
[00:30:18]
like if I say whatever it is,
[00:30:20]
like lg colon flex dash row,
[00:30:25]
greater than large device,
[00:30:27]
then it's flex row,
[00:30:29]
and otherwise it's flex column.
[00:30:31]
To me that feels more declarative
[00:30:33]
to just say, this is the rule for displaying this,
[00:30:36]
rather than a stateful thing where I check
[00:30:38]
what is the state of this window.
[00:30:41]
That's my personal preference,
[00:30:42]
but if you're doing things like you're talking about
[00:30:44]
where you're showing different text or things like that,
[00:30:47]
based on the window size,
[00:30:49]
then it's a lot more elegant to do that
[00:30:54]
with personal preference as much as anything.
[00:30:56]
When it comes to pre rendered sites,
[00:30:58]
then it really becomes a pain point.
[00:31:01]
But if you don't have a pre rendered site,
[00:31:03]
and it works for your taste to check something in your model
[00:31:06]
to see how to render something responsively,
[00:31:09]
then that's great.
[00:31:10]
Then it might be a really good fit for you.
[00:31:12]
Those are really my own personal experiences with it
[00:31:15]
based on the types of problems that I work on
[00:31:20]
and the ways that I think about things.
[00:31:22]
But for a lot of people, I don't think that is a problem.
[00:31:25]
So don't let that stop you.
[00:31:28]
You're the only one who talks about that as far as I know.
[00:31:32]
I mean, I spend a lot of time thinking about
[00:31:34]
making the hydration of a static site really nice
[00:31:39]
when I'm working on Elm pages.
[00:31:41]
So I'm not necessarily the best representation
[00:31:45]
of a typical Elm user there.
[00:31:50]
I think other cons...
[00:31:52]
Did we talk about integrating it into teams?
[00:31:55]
We talked about the ease of refactoring
[00:31:59]
and the ability to create nice abstractions and stuff.
[00:32:02]
So I think overall, it's a very strong choice.
[00:32:05]
I think it's worth just understanding the philosophy of Elm UI.
[00:32:10]
And if you find yourself wanting to do
[00:32:13]
very nuanced, detailed CSS tricks all over the place,
[00:32:18]
then it may be that you feel like Elm UI gets in the way of that
[00:32:22]
because it creates a simpler abstraction
[00:32:25]
that doesn't expose every detailed thing that CSS gives you.
[00:32:30]
And it gives you escape patches to do that,
[00:32:32]
so you can do whatever you want to for the most part.
[00:32:35]
But I think it's just worth understanding the philosophy
[00:32:39]
more than anything to consider
[00:32:41]
whether it's the right fit for your team.
[00:32:46]
And create nice abstractions so it's easier to create new code.
[00:32:50]
It's unbeatable. It's amazing.
[00:32:53]
Yeah. Do you actually know of people who tried out Elm
[00:32:56]
because of Elm UI?
[00:32:58]
I know it's a big name in the Elm community.
[00:33:02]
People say,
[00:33:04]
Oh, if you try out Elm, try out Elm UI, it's amazing.
[00:33:07]
But do you know people who actually went
[00:33:10]
and tried Elm because of Elm UI?
[00:33:15]
I actually have a coaching client
[00:33:17]
that initially had me come in and help them
[00:33:20]
because they wanted to build their SaaS product using Elm UI.
[00:33:26]
That was sort of the main thing.
[00:33:27]
They wanted to use Elm UI and Elm GraphQL.
[00:33:30]
And they've told me that the experience
[00:33:33]
of maintaining a complex SaaS product
[00:33:36]
that's the core of their business
[00:33:38]
has been absurdly easy using those two things.
[00:33:43]
So infrequently that it's laughable.
[00:33:46]
Okay, awesome.
[00:33:48]
So you need a different mindset sometimes
[00:33:52]
when you're working with Elm UI.
[00:33:55]
For instance, the one thing that comes to mind
[00:33:57]
which I haven't had the chance to play with
[00:34:00]
is for instance, menus.
[00:34:03]
So menus, they appear above other elements in Elm UI.
[00:34:08]
Whereas in CSS, you would use a z index.
[00:34:13]
So you apply an attribute which is display above.
[00:34:19]
Is that?
[00:34:20]
Okay, good.
[00:34:22]
Yes.
[00:34:22]
Right.
[00:34:24]
I remember things from two years ago.
[00:34:28]
Yeah, I think there's in front and behind content.
[00:34:33]
And so like, for example, if you wanted to display a modal,
[00:34:37]
then in front gives you an attribute
[00:34:41]
that lets you put an element in front of another element.
[00:34:44]
And so you could take like the very uppermost parent
[00:34:49]
of your entire view, of your entire page.
[00:34:53]
And you could, so let's say that your entire page
[00:34:56]
is like a column.
[00:34:57]
You could say like element.column
[00:34:59]
and that would be your whole page, right?
[00:35:04]
And then the child in that column would be like your nav bar.
[00:35:07]
And that would be like a row.
[00:35:09]
That child would be a row element
[00:35:11]
which has its own children laid out, however it's laid out.
[00:35:15]
And then the next thing in the top level column of your page
[00:35:20]
would be the body of the page.
[00:35:22]
And then the last thing would be the footer, let's say.
[00:35:26]
And that might be a row as well.
[00:35:28]
So that very topmost container,
[00:35:33]
that's how you would display a modal in front of your main view.
[00:35:36]
So you say element.column
[00:35:39]
and then you give a list of attributes
[00:35:41]
and then you give a list of children.
[00:35:43]
The list of attributes,
[00:35:44]
if you wanted to be displaying a modal,
[00:35:46]
then that list of attributes would include element.infront
[00:35:50]
and then you'd give the modal view to that function.
[00:35:54]
And now you're displaying,
[00:35:56]
which it's a little hard to wrap your head around at first,
[00:36:01]
but you're displaying a modal in front of your main view.
[00:36:03]
What kind of problems did you run into
[00:36:05]
when working with LMI?
[00:36:07]
Things where you need to think differently,
[00:36:10]
just like that case of in front and behind or below?
[00:36:15]
I think the thing that is probably most difficult
[00:36:19]
to wrap your head around
[00:36:21]
is the way that wrapping works.
[00:36:23]
So maybe, no pun intended there, but...
[00:36:28]
You intended it.
[00:36:30]
You scammer.
[00:36:31]
Secretly, I intended it.
[00:36:34]
I wanted to say this joke for years.
[00:36:39]
Now is my chance.
[00:36:41]
Yeah, so essentially,
[00:36:44]
the way that wrapping works is you have...
[00:36:47]
Do you mean about text wrapping?
[00:36:49]
Yeah, text wrapping...
[00:36:51]
Like if you wanted to do a heading,
[00:36:56]
like a column that's got three top level elements
[00:37:00]
of the nav bar, the body, the footer.
[00:37:02]
Inside of the body,
[00:37:04]
the first thing we want to have there would be a title,
[00:37:07]
like a heading.
[00:37:08]
Then the way you would do that is,
[00:37:11]
let's say you can do what's called an EL, like an element.
[00:37:15]
And that would be...
[00:37:16]
It's not like a layout container
[00:37:19]
that has multiple children, like a row or a column.
[00:37:24]
There's a style to it.
[00:37:25]
It's kind of like a DOM node.
[00:37:27]
Like span or an A or a div.
[00:37:32]
Right.
[00:37:33]
In a way.
[00:37:34]
It doesn't have children, so it's...
[00:37:36]
EL does have children.
[00:37:38]
Well, it has one child.
[00:37:40]
What I meant to say is it doesn't have multiple children.
[00:37:42]
So it's like a container for a single element,
[00:37:45]
not a bigger container.
[00:37:48]
Otherwise, you need row or column.
[00:37:53]
That's an interesting mental model.
[00:37:54]
You could think of it as...
[00:37:57]
I believe you could just define L yourself as EL, that is.
[00:38:03]
As just passing a single element to a row.
[00:38:07]
Because it doesn't matter if you're displaying it
[00:38:09]
as a row or a column if there's one element.
[00:38:12]
In practice, the CSS under the hood
[00:38:14]
might be a little different,
[00:38:15]
but it's effectively going to be displayed the same way.
[00:38:20]
You just do element.EL
[00:38:22]
in your main body area there.
[00:38:25]
You say, okay, I want to...
[00:38:27]
There are a lot of things that are going to work really nicely.
[00:38:29]
Let's say that you just have a title that says,
[00:38:32]
Hello, it's a nice short title.
[00:38:34]
Then you're not going to run into any text wrapping issues.
[00:38:36]
Then maybe you're going to want to center it.
[00:38:38]
That's going to work in a very intuitive way.
[00:38:40]
Way more intuitive than you're used to
[00:38:43]
because you're just going to say,
[00:38:44]
you're going to do element.EL
[00:38:49]
and then it takes the child,
[00:38:52]
which would be element.text of Hello.
[00:38:54]
The element attributes,
[00:38:56]
you're just going to say element.centerX.
[00:38:58]
Now it's going to be centered.
[00:39:01]
It's going to be centered horizontally.
[00:39:04]
You can also use the heading attributes in this case.
[00:39:09]
Or is it different?
[00:39:10]
You can do element.region.heading.
[00:39:15]
For accessibility purposes,
[00:39:17]
there's this module element.region.
[00:39:21]
That gives you a way to use semantic HTML.
[00:39:24]
But semantic HTML is not used for styling in Elm UI.
[00:39:29]
It's used for accessibility purposes.
[00:39:32]
It's a best practice,
[00:39:35]
like Lighthouse will complain
[00:39:37]
if you don't have something marked as main
[00:39:42]
if you have navbar and things like that.
[00:39:46]
You can set those types of things with element.region.
[00:39:50]
But otherwise, listeners may notice
[00:39:53]
from our conversation that we've been talking about
[00:39:55]
element.row, element.column, element.EL,
[00:39:58]
but we haven't been talking about H1, H2, article, span.
[00:40:03]
It's a smaller palette of functions
[00:40:06]
because you express layout with one thing
[00:40:11]
with element.region.
[00:40:12]
With that module, it gives you helpers
[00:40:14]
for saying this is a heading,
[00:40:16]
this is the main element.
[00:40:18]
We can center our header very intuitively.
[00:40:21]
We can add element.region to add a heading
[00:40:25]
with some semantic UI,
[00:40:27]
but that's not going to come with any built in style.
[00:40:29]
Like in vanilla HTML, if you say H1 or H2,
[00:40:33]
they come with built in styles.
[00:40:34]
With Elm UI, they don't.
[00:40:39]
element.region.heading1,
[00:40:42]
because you need to pass an argument
[00:40:44]
which is a number or an integer,
[00:40:46]
it won't be big as just like when you do H1.
[00:40:51]
Okay.
[00:40:52]
Exactly.
[00:40:53]
What makes it big is when you say
[00:40:56]
element.font.size.
[00:40:58]
You add that attribute and it doesn't care
[00:41:01]
what its region is.
[00:41:06]
It's just a possibility.
[00:41:08]
All of those things, there are a few things to learn,
[00:41:11]
but there's not much of a learning curve.
[00:41:13]
They're very intuitive and it's like a small set of concepts.
[00:41:16]
But then instead of having our heading say hello,
[00:41:20]
if we wanted to say a very long message,
[00:41:24]
maybe on a small device,
[00:41:26]
suddenly our heading isn't wrapping.
[00:41:30]
Oh no.
[00:41:35]
It's not going to wrap.
[00:41:39]
If you use element.el,
[00:41:42]
by default, it's not going to wrap the contents of it.
[00:41:45]
But if you put it in an element.paragraph,
[00:41:47]
it's going to wrap.
[00:41:48]
That's one of the concepts in Elm UI
[00:41:51]
that takes a little getting used to,
[00:41:53]
but once you get used to it,
[00:41:54]
you see that something isn't wrapping.
[00:41:56]
You wrap it in an element.paragraph.
[00:41:58]
I know that that's something that Matt has a few ideas
[00:42:03]
that the model might be more intuitive for that,
[00:42:05]
but it's not like a problem.
[00:42:07]
It's just that it doesn't necessarily do the thing
[00:42:10]
you would intuitively think it's going to do
[00:42:12]
the first time around.
[00:42:13]
Yeah, gotcha.
[00:42:15]
So that's wrapping,
[00:42:16]
and that's one of the few things
[00:42:19]
that's a little bit counterintuitive sometimes.
[00:42:21]
Okay.
[00:42:22]
So there are different modules to set the attributes,
[00:42:25]
unlike in Elm HTML where you have HTML.attributes.
[00:42:30]
You have elements.background,
[00:42:32]
that border, events,
[00:42:33]
font, inputs, and region.
[00:42:37]
And I kind of like that
[00:42:39]
just because when you have that list of attributes,
[00:42:43]
I always prepend those with border.solid,
[00:42:48]
border.width1 or whatever,
[00:42:51]
and it allows me to group things visually,
[00:42:54]
like border, border, border, events, border.
[00:42:59]
should be next to the border because they're grouped.
[00:43:01]
And I always find that a bit irritating in CSS.
[00:43:06]
When I have a CSS class and I set the properties,
[00:43:10]
I don't know in which order I'm supposed to have them.
[00:43:13]
Not that it matters, but just team wise,
[00:43:16]
like how do you group them together?
[00:43:20]
Right.
[00:43:21]
So I know that at my company,
[00:43:26]
we had actually, because it was annoying we disabled it,
[00:43:29]
we had an auto formatter that reordered those
[00:43:33]
to be consistent, which I really like.
[00:43:35]
I like that kind of thing, just like Elm formats.
[00:43:39]
But yeah, if you don't have that,
[00:43:41]
I don't know which order things should be.
[00:43:44]
Like do you have the position first,
[00:43:46]
then the font siding?
[00:43:48]
I don't know.
[00:43:49]
Just with these names,
[00:43:54]
how do you get to group those together?
[00:43:56]
It is nice.
[00:43:57]
I think that one of the reasons why that isn't the case
[00:44:01]
in the Elm HTML package,
[00:44:03]
I mean, besides just it's a different package,
[00:44:06]
so maybe it wasn't a different design vision or whatever.
[00:44:10]
But if you imagine doing that with HTML attributes,
[00:44:14]
there are so many,
[00:44:15]
and they can be used to do so many different types of things.
[00:44:20]
Organize those concepts into like 10 different groups.
[00:44:25]
It would be hard to do that precisely.
[00:44:28]
But with Elm UI, there really is like a very nice toolkit
[00:44:34]
of concepts to pull from.
[00:44:37]
Yeah, Elm HTML is just not opinionated.
[00:44:40]
So it aims to be able to do all the things
[00:44:43]
that you can do with an HTML and CSS,
[00:44:48]
not necessarily CSS.
[00:44:50]
But because Elm UI is a fresh start,
[00:44:53]
it can be a bit more opinionated,
[00:44:55]
and it does it well.
[00:44:57]
Right.
[00:44:58]
One other thing that maybe might be surprising
[00:45:02]
coming to Elm UI is there are some opinions around sizing
[00:45:08]
that a lot of people are used to using EM and REM
[00:45:13]
sizing in CSS.
[00:45:15]
And Elm UI has a lot of functions where you say like...
[00:45:20]
You just pass it to an integer,
[00:45:22]
and it's expected to be a number of pixels,
[00:45:25]
which I find weird.
[00:45:27]
I was going to ask that.
[00:45:29]
Why?
[00:45:31]
That's part of the vision.
[00:45:32]
So just to give a quick example,
[00:45:34]
you could say like element.width
[00:45:39]
of the particular element,
[00:45:41]
and it takes an int,
[00:45:43]
and it's going to set the width in pixels.
[00:45:47]
You can do element.fillPortion,
[00:45:49]
and that's going to be,
[00:45:51]
if you give three different elements
[00:45:53]
a portion of one each,
[00:45:54]
then each of them will get one third of the width.
[00:45:57]
Yeah, so that's how you do percentages in a way.
[00:46:00]
Yes.
[00:46:01]
Of the parent size.
[00:46:02]
That's right. Yep.
[00:46:07]
And then you can just distribute it.
[00:46:09]
But yeah, when you say element.width,
[00:46:11]
it takes an int which represents pixels,
[00:46:14]
and that's a little counterintuitive at first.
[00:46:16]
I know that the first time I encountered that,
[00:46:18]
I was used to using things like EM
[00:46:21]
for responsive font sizes and things like that.
[00:46:25]
But the rationale behind it, I believe,
[00:46:27]
is just sort of an opinion that,
[00:46:30]
I don't know, if somebody's on a 4K display,
[00:46:35]
it's going to look smaller
[00:46:40]
than if it's on an iPhone.
[00:46:44]
But that's what you want it to look like.
[00:46:48]
You're on a larger screen with more pixels,
[00:46:53]
but it's okay for it to look smaller,
[00:46:55]
and then you fit more things in,
[00:46:56]
and that's okay.
[00:46:58]
Just use pixels.
[00:47:03]
Is that what you're saying?
[00:47:05]
I believe those are going to be proportionate
[00:47:07]
to the actual pixels,
[00:47:09]
like to the actual display.
[00:47:12]
Do you want to check that?
[00:47:13]
If he's wrong, edit this out.
[00:47:15]
I'm trying to protect you, Dillon.
[00:47:19]
m is relative to the font size
[00:47:22]
of its direct or nearest parent.
[00:47:25]
You're right.
[00:47:26]
Clearly, my mental model around m and rem
[00:47:31]
is rusty and inaccurate
[00:47:33]
because I have been so spoiled by Elm UI.
[00:47:37]
But essentially, I guess it's,
[00:47:41]
I mean, it's one of those things,
[00:47:42]
like many things in Elm UI,
[00:47:43]
that it's trying to create
[00:47:46]
a cleaner mental model
[00:47:47]
that doesn't have as many special cases and rules
[00:47:50]
that you have to think about,
[00:47:52]
and probably will have to look up
[00:47:54]
something on Stack Overflow to explain it
[00:47:59]
and use it,
[00:48:01]
because they're kind of confusing concepts.
[00:48:03]
So ems are relative to the font size
[00:48:07]
of its direct or nearest parent,
[00:48:10]
and rem is relative to the root font size.
[00:48:14]
And so I guess the idea is that
[00:48:16]
sometimes people use em or rem sizing
[00:48:22]
to set all their font sizes
[00:48:27]
and they'll set the font size in the body
[00:48:30]
based on a media query.
[00:48:32]
So if you're on an iPhone or a 4K monitor,
[00:48:35]
then there will be a media query
[00:48:37]
in a single point that sets the main body font size.
[00:48:41]
So that complexity is just,
[00:48:44]
I mean, it seems pretty sensible,
[00:48:46]
even more so when we look at the actual definition,
[00:48:49]
that, I mean, like, when you're using em or rem,
[00:48:54]
you can see what it does.
[00:48:56]
My learning has been always use rem.
[00:49:00]
And then I read some articles that say always use em.
[00:49:04]
And yeah, well, opinions diverge on this, clearly.
[00:49:09]
Clearly one way is better than the other,
[00:49:11]
but not everyone agrees on which one.
[00:49:15]
So one thing that I noticed is that
[00:49:18]
it is quite easy to reuse elements
[00:49:23]
so have you had the chance to create style guides
[00:49:27]
or design systems with Elm UI?
[00:49:31]
Is that something that people tend to do more often with it
[00:49:35]
or no relation?
[00:49:38]
I know that there was a talk at Elm Europe
[00:49:41]
where there was a project that's like storybook
[00:49:45]
in the React ecosystem, but using Elm UI
[00:49:48]
as a way of presenting different layout components.
[00:49:53]
And I was doing some projects where they...
[00:49:55]
Is that Elm UI Explorer, maybe?
[00:49:58]
I think it was Elm UI Explorer,
[00:50:00]
which actually does not about Elm UI I learned after that.
[00:50:05]
Oh, okay. I wasn't fully clear.
[00:50:07]
Yeah.
[00:50:09]
It's a storybook like project.
[00:50:12]
Interesting.
[00:50:13]
Yeah, I think it is easier to encapsulate nice interfaces
[00:50:17]
for displaying different things,
[00:50:22]
design systems and that sort of thing as a result.
[00:50:25]
But people are starting to come out
[00:50:27]
with more sort of community tools
[00:50:29]
and sort of like, I know some people are working
[00:50:32]
on like recipe sites for it and that sort of thing.
[00:50:35]
Yeah, we saw that.
[00:50:37]
Elm UI Storybook, for instance, I think by Lucas Pair.
[00:50:43]
We'll correct myself if that was wrong.
[00:50:46]
Yeah, we'll have to find a few resources like that
[00:50:51]
but there's a pretty large user base
[00:50:53]
and a very active group of people discussing these things
[00:50:56]
in the Elm UI channel in Slack.
[00:50:58]
So it's definitely worth asking for opinions on things
[00:51:03]
and how to...
[00:51:05]
Or help, by the way.
[00:51:07]
...tile drop downs.
[00:51:08]
Yeah, getting help, getting clarity on a mental model,
[00:51:11]
things like that.
[00:51:12]
But I think regarding creating nice abstractions for things,
[00:51:17]
with Elm UI, it's very easy to refactor things
[00:51:20]
into nice abstractions.
[00:51:22]
I would just give a public service announcement
[00:51:25]
to remind people to actually do that step
[00:51:28]
to abstract things nicely because it's tempting,
[00:51:31]
like everything in Elm UI is inline.
[00:51:34]
It's not something you write in like a style sheet
[00:51:37]
and you have to have a class for things.
[00:51:39]
So it doesn't force you to abstract things away
[00:51:44]
but abstracting things when you do is awesome.
[00:51:46]
But I would encourage people to actually do that step.
[00:51:50]
Yeah.
[00:51:51]
So I've worked with people who were very good at CSS
[00:51:54]
and when they were on a project with Elm CSS,
[00:51:59]
they had a lot more trouble finding the code associated
[00:52:04]
with the classes they saw
[00:52:06]
because the classes are hashed
[00:52:11]
anymore.
[00:52:12]
You can't look for button dash item in your source code
[00:52:17]
and find the file that contains that class.
[00:52:20]
And you have the same problem with Elm UI.
[00:52:23]
When you need to change an element that you see on a page,
[00:52:26]
how do you go from visually seeing that item on the page
[00:52:30]
to finding it in the project in your source code?
[00:52:34]
So there is one tool at your disposal called element.explain
[00:52:39]
and it's quite handy.
[00:52:40]
And what you do is you set element.explain,
[00:52:43]
you have to pass it debug.to do for internal purposes
[00:52:47]
but you get used to it.
[00:52:48]
It's not a big deal.
[00:52:49]
So as not to forget to remove it.
[00:52:52]
So you don't forget to remove it.
[00:52:53]
Exactly.
[00:52:54]
Right.
[00:52:55]
So you're not going to compile it
[00:52:56]
with the optimize flag on for production.
[00:52:58]
And then it gives you a nice little highlight
[00:53:01]
around the area you're looking at.
[00:53:03]
So if you're finding that something is like wrapping strangely
[00:53:08]
I use that pretty often.
[00:53:09]
And it's a very nice way to debug.
[00:53:11]
Beyond that, as you say,
[00:53:14]
even more so than like with Elm CSS,
[00:53:17]
there's not even a direct mapping to CSS
[00:53:19]
like there is with Elm CSS.
[00:53:22]
Elm CSS is an abstraction
[00:53:24]
but it's a pretty direct one on CSS
[00:53:27]
and Elm UI is a much more high level abstraction.
[00:53:30]
And so there's not a direct mapping
[00:53:35]
and so the going in your browser's developer tools
[00:53:38]
is not going to give you that much help.
[00:53:42]
So what usually ends up happening is
[00:53:45]
you just kind of trace back
[00:53:47]
where things are coming from.
[00:53:49]
Like I was saying earlier,
[00:53:51]
why is the padding like this on this element?
[00:53:54]
Well, what's rendering this element?
[00:53:58]
If you can find the parent,
[00:54:03]
that's all there is to it.
[00:54:04]
It's not going to cascade from anything.
[00:54:06]
It's not going to get overridden by bang important.
[00:54:09]
It's not going to be,
[00:54:11]
is it coming from a margin or from this?
[00:54:13]
And is part of it coming from margin?
[00:54:15]
Is part of it coming from the parent's padding?
[00:54:19]
It just comes from one place.
[00:54:21]
It's the parent's padding.
[00:54:22]
It's the only place it could be.
[00:54:23]
So it's much more traceable.
[00:54:25]
Okay, but yeah, if you need to find one element
[00:54:30]
or then you have to go through the whole code.
[00:54:34]
You can be a bit smarter than that, but obviously,
[00:54:37]
but that's kind of what it pulls down to.
[00:54:39]
It's true.
[00:54:40]
I would say that overall,
[00:54:42]
my experience figuring out
[00:54:43]
where a certain view issue is coming from
[00:54:46]
has been easier in Elm UI than it is with CSS.
[00:54:50]
Okay.
[00:54:52]
For what it's worth, yeah.
[00:54:53]
No surprise here.
[00:54:58]
Is there anything that people can use as resources
[00:55:00]
getting started with Elm UI?
[00:55:01]
Yeah, definitely.
[00:55:03]
So first of all, I would mention Matt's conference talk
[00:55:08]
at Elm Europe 2017.
[00:55:11]
I was in the audience
[00:55:12]
and I didn't realize how good it was at that time.
[00:55:18]
I watched it again a few years later
[00:55:21]
and I thought, man, that was actually genius.
[00:55:26]
I was stunned by that talk initially.
[00:55:28]
It inspired me in my approach to API design quite a bit,
[00:55:34]
just that vision of that clarity of the API
[00:55:38]
and the design goals
[00:55:40]
and just rethinking things from the ground up,
[00:55:43]
which really is very much the Elm approach.
[00:55:46]
Yes, definitely.
[00:55:47]
It feels like if you love the philosophy behind Elm,
[00:55:50]
you're probably going to love the philosophy behind Elm UI.
[00:55:55]
It's incredibly insightful.
[00:55:57]
Yeah, I agree.
[00:55:58]
Even though that talk is about style elements,
[00:56:01]
the older incantation of it,
[00:56:03]
or the older incarnation of Elm UI,
[00:56:07]
CSS is more like an incantation.
[00:56:12]
Elm UI is more like an incarnation.
[00:56:14]
But it is still relevant in terms of the design philosophy.
[00:56:17]
But Matt's given a few talks about Elm UI
[00:56:22]
and I think they're all worthwhile to watch.
[00:56:25]
And Richard Feldman gave,
[00:56:27]
even though he's the author of Elm CSS,
[00:56:30]
he gave a really cool talk about Elm UI
[00:56:32]
back when it was still style elements as well.
[00:56:35]
I thought that was a nice talk
[00:56:37]
that gives some motivation of some of the ideas
[00:56:39]
and why it's a nice tool.
[00:56:41]
I know Richard is definitely a fan of Elm UI as well,
[00:56:44]
but he's got some great resources on that.
[00:56:49]
I think that's it for this channel on the Elm Slack.
[00:56:52]
Definitely go there if you want to know more
[00:56:54]
about what's going on and if you want to ask for help.
[00:56:58]
I think that is probably one of the most visited channels
[00:57:02]
in the Elm Slack that is not general,
[00:57:05]
or general purpose, I mean.
[00:57:08]
Sometimes it feels like it's even more active
[00:57:10]
than the general channel.
[00:57:13]
Actually, since I don't use Elm UI,
[00:57:18]
it's just too many people talking over there
[00:57:21]
for things that I'm not that interested in.
[00:57:24]
Yeah, there are almost 1800 people over there.
[00:57:28]
That's a lot.
[00:57:31]
And if you have a question,
[00:57:32]
there's a very good chance
[00:57:34]
that you'll get a good answer.
[00:57:36]
So it's definitely a good idea
[00:57:37]
to jump in that channel as you're getting started.
[00:57:39]
Yeah. Other resources?
[00:57:41]
Go to package.elmlang.org
[00:57:46]
too, that's a great way to get started.
[00:57:48]
And there's some examples in the examples folder.
[00:57:50]
Yeah, and take the one from MD Griffith.
[00:57:54]
Oh yes, that's right.
[00:57:56]
I think that's a pretty good summary.
[00:57:58]
Yeah. Actually, there's no other Elm UI.
[00:58:01]
There used to be.
[00:58:02]
There used to be, but...
[00:58:04]
pdog design, but I think it didn't get moved over
[00:58:07]
to Elm 19 maybe.
[00:58:09]
Okay, well, then if you find Elm UI, use Elm UI.
[00:58:14]
No confusion there.
[00:58:16]
Yep.
[00:58:17]
Now there is thanks to us,
[00:58:18]
but that's okay.
[00:58:20]
Thanks to me.
[00:58:21]
You're welcome, community.
[00:58:25]
Well, thanks for the discussion,
[00:58:26]
Jeroen, I'll talk to you next time.
[00:58:28]
See you next time.
[00:58:33]
.