Code Monkey home page Code Monkey logo

elm-css-grid's Introduction

Elm Css Grid

This package provides a simple css grid system for Elm projects that use rtfeldman/elm-css.

The example in thie Ellie app is probably the best demonstration of what this package does: https://ellie-app.com/65Hb3tZTqDya1

elm css grid

Whats this all about?

Ive heard whats been referred to as 'the lie of css', which is that despite being an abbreviation for "style sheets" its not really about styling. If you didn't know anything about html or css, it would kind of seem like html is about laying out and css is about styling. Thats not really true. Both html and css are necessary for both laying out and styling. The different concepts dont neatly correspond to the different technologies. At this point in history html and css are just a big ugly accident with misleading names. Im sure if we started the internet from scratch we would make something better than html and css (something like the Elm package mdgriffith/elm-ui).

But in practice, it helps to think about positioning as a separate thing from styling. You should have separate blocks of html just for laying things out and other blocks of html just for being styled. If you dont do this, and instead try to make make one monster html element that both looks right and is well placed, you will not have a fun time. It will look funny, it will not be scalable, and it will break very easily. To make good maintainable html you can take the simple approach of dedicating some html elements to just positioning and other html elements to just styling.

Thats where css grids come in. Css grids just position stuff in a grid, then its up to you to style the stuff in the grid how you want.

Whats in this package

This package exposes a row function and a column function. A sequence of rows will naturally be organized vertically, and a sequence of columns in a row will naturally be organized horizontally. They are flex elements, so if you put only one column in a row, it will take up the whole row horizontally. If you have two unstyled column in a row they will naturally each take up 50% of the horizontal space.

This is an opinionated Api

This api is meant to be used in one way, and it wont let itself be used in another way:

  • The type signatures of row and column are very similar to that of html functions in elm/html, with the exception that their first parameter is a List Css.Style instead of List (Attribute msg). Layout html does not need attributes. You need attributes for things like event handlers, and data. Layout html shouldn't be used for that kind of thing.
  • The column function makes a Column msg and not an Html msg. The row function takes List (Column msg) and not List (Html msg). They only work with each other. A row with one column is fine, and preferable to a row with many non-column children.

You can however style the grid with your own List Css.Style, which will override the default styling of the grid components, such as in the case where a row or column needs needs a margin or padding.

Also

rows and columns show up in the DOM as <row></row> and <column></column>.

elm-css-grid's People

Contributors

2mol avatar chadtech avatar ubourdon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

elm-css-grid's Issues

Safari Issues

Out of the box, row does not work in Safari. It needs

flex-basis: auto;
flex-shrink: 0;

And then its good to go.

Clicking on columns

There should be a way to add event handlers to columns, otherwise you have to wrap everything in a div that only exists for that purpose.

    Grid.column
         []
         [ div [ Html.Events.onClick Clicked ] whatYouReallyWantedToRender ] ]

I am thinking an api like

    Grid.column [] []
        |> Grid.onClick Clicked
        |> Grid.on "mouseup" MousedUp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.