Media queries in Elm

Lucamug
2 min readMar 6, 2018

--

Demo with editor and Time Traveling Debugger and without

Demo stand-alone

Code

The use of Elm combined with Style-elements allow us to be creative with media queries. This app, a simple html page editor, can generate a mobile preview that is quite accurate without using iframes or browser tools.

CSS media queries can only react to the viewport size but if our media query are in the code, we have the flexibility to have them reacting to any type of parameter.

For example, the page is rendering properly inside a narrow div and at the same time is also rendering correctly in full screen mode.

Even though I am using them for a while. I am still impressed by the level of sophistication that can be reached by using Elm+SE(v5).

This is an example of something that I could not have done without Elm, SE (and the Elm Slack community).

Unbreakable Json

A by-product of Loved/Hated Elm Json decoders is that the application is very robust. The App store the data in a Json file (that is also then stringified and saved into the browser Local Store.

This Json structure is editable both from a form, field by field, or directly inside a textarea. Because the Json is decoded/encoded at each keystroke, it is impossible to break it.

You can only do editing that

  1. Are not breaking the Json structure.
  2. Are not breaking certain fields such as logo or color. To edit these fields you need to select the entire content and paste at once the now value because just typing you need to go through a series of invalid Json data.

This is not a very useful feature but it was nice to see how it played out.

More about Unbreakable Json: https://medium.com/@l.mugnaini/unbreakable-json-95637300176c

Resources

Inspired by/Made with

Related Posts

CSS Nirvana
Do you remember when I told you that separating layout from style was a good thing? Well, forget about it!medium.com

Single Page Application Boilerplate for Elm
Demo → Codemedium.com

Zero-maintenance Always-up-to-date Living Style Guide in Elm!
Demo → Codemedium.com

Forms in Elm — Validation, Tutorial and Examples — Part 1
Sometime Elm’s newcomers complain about the complexity and the large amount of boilerplate needed to create forms.medium.com

--

--

Responses (1)