Code Monkey home page Code Monkey logo

elm-ui's Introduction

Check out the talk that goes with the library, Building a Better Design Toolkit

A New Language for Layout and Interface

CSS and HTML are actually quite difficult to use when you're trying to do the layout and styling of a web page.

This library is a complete alternative to HTML and CSS. Basically you can just write your app using this library and (mostly) never have to think about HTML and CSS again.

The high level goal of this library is to be a design toolkit that draws inspiration from the domains of design, layout, and typography, as opposed to drawing from the ideas as implemented in CSS and HTML.

This means:

  • Writing and designing your layout and view should be as simple and as fun as possible.
  • Many layout errors (like you'd run into using CSS) are just not possible to write in the first place!
  • Everything should just run fast.
  • Layout and style are explicit and easy to modify. CSS and HTML as tools for a layout language are hard to modify because there's no central place that represents your layout. You're generally forced to bounce back and forth between multiple definitions in multiple files in order to adjust layout, even though it's probably the most common thing you'll do.

Try this live example on Ellie!

module Main exposing (..)

import Element exposing (Element, el, text, row, alignRight, fill, width, rgb255, spacing, centerY, padding)
import Element.Background as Background
import Element.Border as Border
import Element.Font as Font


main = 
    Element.layout []
        myRowOfStuff

myRowOfStuff : Element msg
myRowOfStuff =
    row [ width fill, centerY, spacing 30 ]
        [ myElement
        , myElement
        , el [ alignRight ] myElement
        ]


myElement : Element msg
myElement =
    el
        [ Background.color (rgb255 240 0 245)
        , Font.color (rgb255 255 255 255)
        , Border.rounded 3
        , padding 30
        ]
        (text "stylish!")

Join the Elm UI Slack!

First, if you have a question about how to do something with the library, join #elm-ui on the Elm Slack! There are usually a number of people who are willing to help out, myself included.

History

The work is based off of a rewrite of the Style Elements library. A lot of that work was originally released under the Stylish Elephants project.

Community Cookbook

The community around elm-ui is maintaining a collection of examples called the elm-ui-cookbook. If you are just starting out with elm-ui, or get stuck on specific things, this can be a great resource.

Notes

Make sure to have <!DOCTYPE html> on top of your application; otherwise, things might get messed up in some browsers.

Contributing

Want to help out fixing bugs or reporting issues?

Please add issues you find, and if you want to verify code you want to contribute, please read how to run the tests here.

elm-ui's People

Contributors

adeschamps avatar alexandertrefz avatar alexkorban avatar bburdette avatar buinauskas avatar cameron avatar ceddlyburge avatar charlontank avatar cwhy avatar dela3499 avatar drola avatar escherlies avatar jyrodrigues avatar lucamug avatar mdgriffith avatar mgold avatar objarni avatar ollef avatar plaxdan avatar rjdellecese avatar rlefevre avatar roberto avatar rofrol avatar rosievers avatar rosuavio avatar sturgman avatar tomstejskal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elm-ui's Issues

Support for lists (and other flow content)

Hi,

I wondered if there were any plans to add more elements for laying out text. In my specific case, I was looking for equivalents of <ol>/<ul>/<li>, but it got me thinking about other elements that aid in accessibility and typography/text layout, such as dl, <time>, <abbr>, <address>, <em>, <strong> etc.

I can't find any mention of anything like this in these issues, sorry if I missed something.

Consider renaming `el` to `element`

There are various terms in design that start with el, e.g. the ellipse element in SVG, "elevation" in Material Design, etc. All the other functions and types in elm-ui are clear at the point of use. In the spirit of the "clarity over brevity" rule (borrowed from Swift API Guidelines), I suggest to rename the el element to element or something similar.

FillPortion ratio is not enforced when scrollbar is set and content overflows

SSCCE
https://ellie-app.com/3vqX29tHjjva1

Change line 60 from Long to Short to see the layout I was expecting.

Expected behavior
I was expecting that the height of el with fillPortion 10 would be 10x the height of el with fillPortion 1 on the same column., even though they both have contents that overflows but also both have scrollbarY set.

Versions

  • OS: OSX
  • Browser: Chrome
  • Browser Version: 69
  • Elm Version: 0.19
  • Elm UI Version: 1.0.0

Header region

There's a footer but no header region in the Element.Region module.

Is there any good reason for this omission, or can it be added?

Thanks for a great library!

How to split style and layout?

I'm not sure how I'm supposed to "separate" layout and style with elm-ui.

My initial idea was to create a Styles.elm file that exposes styles and do layout in my view.
I don't like the way I'm using List.append to add the alignRight. Any suggestions?
Or are there examples around that show a good way of separating code?

Styles.elm

title =
    [ Font.color (rgb255 0 255 0)
    , Font.size 20
    ]


body =
    [ Background.color (rgb255 40 40 40)
    ]

Main.elm

view : Model -> Browser.Document Msg
view model =
    { title = "gazet "
    , body =
        [ Element.layout Styles.body <|
            Element.row [ padding 10, spacing 7, width fill ]
                [ el Styles.title (text "hello!")
                , el Styles.title (text "hello!")
                , el (List.append [ alignRight ] Styles.title) (text "hello!")
                ]
        ]
    }

Element.modular returns Float but Font.size requires Int

There is a discrepancy between the docs and the implementation for use of Element.modular. The example in the docs is

scaled =
    Scale.modular 16 1.25

Font.size (scaled 4) -- 16 * 1.25 ^ (4 - 1) results in 31.25

But this fails as Font.size expects an Int rather than a Float.

external fonts can currently only use outdated file formats

To define a @font-face in CSS with a modern format like woff2, we not only need an url() but also an additional format('woff2') like so

/* roboto-regular - latin */
@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400;
  src: url('../fonts/roboto-v18-latin-regular.woff2') format('woff2');
}

Current behavior

external :
    { url : String
    , name : String
    }
    -> Font

Expected behavior

external :
    { url : String
    , format : Maybe String
    , name : String
    }
    -> Font

... and Font should be extended to handle this as well.

Versions

  • OS: Windows 8.1
  • Browsers: Chrome 64, Firefox 62
  • Elm Version: 0.19
  • Elm UI Version: 1.0.0

fillPortion and image not playing well together

Example
I've got an example here where 3 elements are sized using fillPortion 1, the middle element being an image. It works ok! But if you change the image fillportion to 2, the image displays at its full resolution.

https://ellie-app.com/3zztzKkg8X4a1

Expected behavior
I expected the image to still be in between the two other elements, but just a little larger - taking up 1/2 the width of the window rather than 1/3.

Versions

  • OS: nixos
  • Browser: firefox, chrome
  • Browser Version: ff62.0.03, chromium Version 69.0.3497.81 (Developer Build) (64-bit)
  • Elm Version 0.19.0
  • Elm UI Version 1.1.0

Combination of "width fill" and "centerX" on nested rows give unexpected width to paragraphs with line-breaks.

SSCCE: ellie

This code:

Element.row
        [ Element.width Element.fill ]
        [ Element.row [ Element.centerX ]
            [ Element.paragraph [ Element.width Element.shrink ] [ Element.text "Hello world" ]
            , Element.paragraph [ Element.width Element.shrink ] [ Element.text "Hello world" ]
            ]
        ]

produces a row which is unexpected wide. It seems that the width of the row correspond to the expected width in the case where the two paragraphs didn't have any line-breaks.
The row is only too wide when given the attribute Element.centerX.
This only seems to happend when the row with centerX is inside a row with width fill.
The following ellie compares the example with and without Element.centerX.

Versions

  • chromium version 69
  • elm 0.19
  • elm-ui 1.0

I have encountered this bug while upgrading an application from Elm 0.18 with stylish-elpehants 6.0.2 to Elm 0.19 with elm-ui 1.0.0.

Border shadow doesn't display when offsets are float values

When the border shadow offset property is a float that's value has any number after the "." that isn't zero, it doesn't display the shadow at all.

Example

Expected behavior
The expected behavior is for the shadow to display when a float value is given for the offset

Versions

  • OS: [macOS Mojave]
  • Browser [chrome]
  • Browser Version [Version 69.0.3497.100 (Official Build) (64-bit)]
  • Elm Version [0.19]
  • Elm UI Version [1.0.0]

SpaceEvenly and alignRight cancels eachother out

Ellie: https://ellie-app.com/3qQ5nSvWmHja1

I'm trying to create two columns that each space their contents evenly across the entire page. I want each column to be on opposite side of the screen. The right column can either be rightAligned, or space contents evenly, but not both. If one re-arranges the properties, it seems that whatever comes last takes precedence.

Expected behavior
That the right column is at the right side of the page, and that the contents are spaced evenly in the vertical direction.

Versions

  • OS: Mac OS X 10.11
  • Browser: Safari 12
  • Elm Version: 0.19
  • Elm UI Version: 1.0.0

transparent button still issues onPress message

Un-expected behavior is that a transparent button still issues an event if you click on it. Easy enough to work around, but not what's indicated in the docs.

https://ellie-app.com/3CFndNgGLWya1

Expected behavior

According to the docs transparent elements ought to ignore mouse events.

Versions

  • OS: nixos
  • Browser: firefox
  • Browser Version: 62.0.03
  • Elm Version 0.19.0
  • Elm UI Version 1.1.0

prop escape hatch?

Really missing the prop function from style-elements. Has this been replaced by anything else? Very many things become impossible without it!

Allow `download` element to have file name.

Elm 0.19 has special way of handeling links. This makes it so that if you want a [ href "download", download "" ] [ Html.text "Will download" ] to work, it should have file name set for its download attribute.

It's would be nice if Elm-ui would also support setting name for it's Element.download element.

Related to ELM issue - elm/html#175

Missing Feature: Font Variants

There is currently no way to set the variant of a font.

This is important to make content look right for the specific situation it is in (tabular numbers, proper small caps, slashed 0s etc).

Sidenote: There is also a lower level implementation that allows more features to be used, but is a lot more cryptic called font-feature-settings

I would be happy to try my hand on a PR, if you want me to.

Using centerX in a column with scrollbars causes the column to overflow its container

I have a column with centerX and scrollbars. It overflows. If I take away centerX, it doesn’t overflow.

Here's an example in Ellie. You can see the scrollbar/overflow behavior change when you click the Toggle button at the top of the column of numbers, which controls whether centerX is applied or not.

https://ellie-app.com/3sm9w3pJFhja1

  • OS: Mac OS X
  • Browser: Chrome, Safari
  • Browser Version: Chrome 69.0.3497.100, Safari Version 12.0 (13606.2.11)
  • Elm Version: 0.19
  • Elm UI Version: 1.0.0

Missing old `screen` function

I believe it is impossible without the old screen function to create a fixed overlay over a page that extends beyond the viewport.

Ex: say you are making a news feed with a scrollable list of posts. When a user clicks on an image, you want to create a light box modal displaying a larger view of that image.

Afaik, your options are either to

  1. fill height above the posts element, which will create a gigantic overlay with a probably incorrect center
  2. subscribe to the height of the screen, store that value in your model, and set the height of the modal to that value. This is also problematic, as the user can scroll around the modal.

Proposed solution: bring back the screen function

How to avoid triggering a Msg with Input.checkbox

Hey,

This might be a dumb question, but is there a way to not define onChange (or disable it) for a checkbox ?
I have a row with a few things, including a checkbox. When the user clicks anywhere on the row it toggles the checkbox, for that I have an onClick on the row that works just fine, the issue is that it's triggering both the onClick for the row and the onChange for the checkbox when the user clicks on the checkbox directly. It's not a huge issue, but it does end up saving the status twice with the server, which is a bit silly.

Thanks

Documentation refers to style-elements

Hello, browsing the current package documentation (1.0.0) we still see several references to style-elements instead of elm-ui. Very minor, but it could be confusing for new folks!

wrappedRow with centerX does not render centered when wrapped

Originally brought up in the Slack channel.

SSCCE

https://ellie-app.com/3Fsk9QQ9D6za1

module Main exposing (main)

import Element as E
import Element.Background as BG

myelement num =
    E.el [ E.centerX
         , E.width (E.px 100)
         , E.height (E.px 100)
         , BG.color (E.rgb 0 0.5 0.5)
        -- , E.explain Debug.todo
         ] (E.text (String.fromInt num))


view =
    E.wrappedRow [ E.spacing 10
                 , E.width E.fill
                -- , E.explain Debug.todo
                 , E.centerX]
        [ myelement 1
        , myelement 2
        , myelement 3
        , myelement 4
        , myelement 5
        , myelement 6
        ]

main =
    E.layout [] view

Expected behavior

Expected that both the first and second row remain centered when wrapping occurs. What actually happens is that the first row becomes right aligned and the second row becomes left aligned.

Versions

  • OS: Windows 7
  • Browser Firefox Dev Edition
  • Browser Version 63.0b14
  • Elm Version 0.19
  • Elm UI Version 0.1.1

Diagnosis

Currently the way horizontal centering is achieved on the wrapped row is by adding property flex-grow: 1 to the first and last elements of the row. This strategy breaks down when the row is wrapped since the first element of the second row does not in general have flex-grow: 1

Temporary workarounds

The following Ellie has an attempt to add styles via Element.htmlAttribute but it fails because the css is added to the wrong elements: https://ellie-app.com/3FvRsWjVqrJa1

module Main exposing (main)

import Element as E
import Element.Background as BG
import Html.Attributes as HA

myelement attr num =
    E.el (attr ++ [ E.centerX
         , E.width (E.px 100)
         , E.height (E.px 100)
         , BG.color (E.rgb 0 0.5 0.5)
        -- , E.explain Debug.todo
         ]) (E.text (String.fromInt num))


view =
    E.wrappedRow [ E.spacing 10
                 , E.width E.fill
                -- , E.explain Debug.todo
                 , E.centerX
                 , E.htmlAttribute (HA.style "justify-content" "center")]
        [ myelement [E.htmlAttribute (HA.style "flex-grow" "0")] 1
        , myelement [] 2
        , myelement [] 3
        , myelement [] 4
        , myelement [] 5
        , myelement [E.htmlAttribute (HA.style "flex-grow" "0")] 6
        ]

main =
    E.layout [] view

The following is a workaround that works by adding css manually: https://ellie-app.com/3Fw9nkQX29ya1
It is the same as the SSCCE but with the following styles added manually (untested):

    .s.r > s:first-of-type.accx { flex-grow: 0 !important; }
    .s.r > s:last-of-type.accx { flex-grow: 0 !important; }
    .cx > .wrp { justify-content: center !important; }

I haven't tested how this would affect other content rendered by elm-ui

`height fill` on Element.layout

Hi! Newbie here. I was wondering how can I get the height of the layout to fill the entire space of the body. This works in Ellie, of course, but how can I get the same behaviour for the root element of my site?

main =
    Element.layout [ height fill ] -- this only doesn't work :(
        myRowOfStuff

Thanks!

Border.glow and Border.innerGlow are mutually exclusive

SSCCE: https://ellie-app.com/3gtX5yDcg8La1

Specifying both Border.Glow and Border.innerGlow yields only the glow listed second. I would expect both glows to be present.

If there are any expected mutually exclusive attributes (e.g. dashed and dotted borders), they should be documented. A dashed glow doesn't seem to work, not that it's well-defined anyway.

macOS High Sierra, Safari 11.1.2, Elm 0.19, Elm UI 1.0.0

Input.Slider is rendered in front of InFront elements

This is an issue reported by Leif Battermann in the Slack channel. SSCCE:

https://ellie-app.com/3DytzyCwXvga1

Expected behavior
The slider should render below the modal and not be accessible while the modal is present.

Versions

  • OS: Windows 7
  • Firefox Developer Edition
  • Browser Version: 63.0b14
  • Elm Version 0.19
  • Elm UI Version 1.1.0

Workaround
The following ellie shows how to work around the issue:

https://ellie-app.com/3DBC5vydSxxa1

It involves rendering an Element.column with the modal as an Element.inFront and rendering the slider as a Element.row within. The z-index of the modal is manually set to 20.

Additional Research
Removing the z-index:10 from the input[type=range] reset does not work because it makes the slider non-functional in all cases.

The text in a multiline input doesn't always match the value set in its `text` field.

The text option of a multiline input has unintuitive behavior. It can set the initial value of the input, but changing it doesn't update the input text. I use Element.Keyed as in the case below to update multiline input text. (Changing the key creates a new element with the provided text value.)

In this example, there are two inputs, each of which has its text field set by the same value - the model's text field. The left input is a multiline and the right is a multiline wrapped in a keyed element.

I'd expect the displayed text in each input to match it's text field, but an input only updates as long as it hasn't yet been typed into.

If you type into each input, then click the Update text and key button, the left input will not update, and the right input will update, since it is keyed and the key has just changed.

multiline

module Main exposing (main)

import Browser
import Debug
import Element exposing (..)
import Element.Background as Background
import Element.Input as Input
import Element.Keyed as Keyed


main =
    Browser.sandbox
        { init = init
        , view = view
        , update = update
        }


init =
    { text = "initial text"
    , key = "initial key"
    }


type Msg
    = SetText String
    | UpdateInput


update msg model =
    case msg of
        SetText string ->
            { model | text = string }

        UpdateInput ->
            { model
                | text = "updated text"
                , key = "updated key"
            }


options string =
    { onChange = SetText
    , text = string
    , placeholder = Just (Input.placeholder [] (text ""))
    , label = Input.labelAbove [] none
    , spellcheck = False
    }


view model =
    Element.layout [ width fill, height fill ] <|
        column [ width fill ]
            [ row [ width fill, height fill ]
                [ el [ width fill ]
                    (Input.multiline [] (options model.text))
                , Keyed.el [ width fill ]
                    ( model.key, Input.multiline [] (options model.text) )
                ]
            , Input.button
                [ width fill
                , paddingXY 10 10
                , Background.color (rgba 0 0 0 0.1)
                ]
                { onPress = Just UpdateInput
                , label = text "Update text and key"
                }
            , el [ centerX, padding 50 ] (text (Debug.toString model))
            ]

Multiple elements simultaneously render with Element.focused attributes

SSCCE: https://ellie-app.com/3zyY5PfnbG8a1

Expected behavior

Only one element can have focus at a time. So only one element should be decorated with Element.focused decorations at a time.

Actual behaviour

Clicking (focusing) a button will render that button and all following buttons as focused.

Versions

  • OS: OSX 10.13.6
  • Browser : verified in Safari 12.0 and Firefox 62.0.3, not yet tested elsewere
  • Elm Version 19
  • Elm UI Version 1.1.0

Supporting right-to-left languages

I just saw the excellent presentation you did at elm-conf, and I noted you were using alignLeft. I've worked on projects that had to support both left-to-right languages (english, etc.) and right-to-left (RTL) languages (hebrew, etc.), with CSS rules that could be generated to match either type of locale and would mirror the layout depending on the language. But for doing that, names like "left" and "right" are misleading, because they're only true for one type of locale. (For reference, Apple uses the names "leading" and "trailing" instead when making apps on iOS)

Do you think that elm-ui could support mirroring like this in the future, to make it easy to support both LTR and RTL locales with the same application?

And just to be clear, I'm merely curious right now; I'm not in the process of deciding to use elm-ui based on RTL support or anything like that.

Use new Color type

To help with consistency, we created a new color package.

https://package.elm-lang.org/packages/avh4/elm-color/latest/Color

Elm-UI is a good candidate to use that new package.

There are two solutions:

  1. Use the new Color type and the remove custom Color type from elm-ui.
  2. Keep the elm-ui own Color type and create constructors that accept the new Color type.

I know 2. is needed to help elm-ui optimize (by keeping css string maybe) but I think the drawback of having multiple color type is too high and that 1. should be preferred.

Reason behind the elm-ui name?

There's already a library for elm called elm-ui that has over 700 stars, this makes it very confusing as google picks up that library over yours. Why would you use a name that's already taken?

textColumn width

Element.textColumn appears to have a minimum width of 500px and maximum width of 750px that can't be overridden. Is there a reason for this as it prevents use for a Phone? Thanks.

`height fill` doesn't work on multiline input

Here's a minimal example showing a multiline element and an el, both using the same attributes. Both are set to height fill, but the multiline on the left doesn't fill the height of the parent, while the el on the right does.

elm-ui-issue

module Main exposing (Msg(..), attributes, main, myText, options)

import Element exposing (..)
import Element.Input as Input



-- Attributes are used for both el and multiline input.


attributes =
    [ width fill, height fill, explain Debug.todo ]


myText =
    "Line 1\n\n\n\nLine 5"


options =
    { onChange = \string -> NoMsg
    , text = myText
    , placeholder = Just (Input.placeholder [] (text ""))
    , label = Input.labelAbove [] none
    , spellcheck = False
    }


main =
    Element.layout [ width fill, height fill ] <|
        row [ width fill, height fill ]
            [ Input.multiline attributes options
            , el attributes (text myText)
            ]


type Msg
    = NoMsg

Newline not respected in contents of Element.paragraph with (style "white-space" "pre-wrap")

SSCCE: https://ellie-app.com/3B4HGWdB2gqa1

Expected behavior

Preformatted texts in Element.paragraph should be rendered as is, when style "white-space" "pre-wrap" is given.
I'm using this for (obviously) showing preformatted texts given by end users as is, respecting newlines and other whitespaces.

I recon this was working in elm-ui 1.0.0 (probably), but not working in 1.1.0.

Currently texts presented via Element.text are wrapped in <div>s which have display: inline; white-space: normal; style attached. This should be the culprit.
Although I suspect this is introduced for some other purposes, thus I cannot tell just removing this solves the problem or not.

As an alternative path, adding some special attribute so that preformatted texts can be rendered in paragraph would be cool, too.

Versions

  • OS: Windows 10
  • Chrome 69.0.3497.100
  • Elm 0.19
  • Elm UI Version 1.1.0

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.