• Stars
    star
    1,239
  • Rank 37,913 (Top 0.8 %)
  • Language
    Elm
  • License
    BSD 3-Clause "New...
  • Created over 9 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Typed CSS in Elm.

elm-css

elm-css lets you define CSS in Elm. (For an Elm styling system that is a complete departure from CSS, check out Elm-UI.)

Here's an example of how to define some elm-css styles:

module MyCss exposing (main)

import Css exposing (..)
import Html
import Html.Styled exposing (..)
import Html.Styled.Attributes exposing (css, href, src)
import Html.Styled.Events exposing (onClick)


{-| A logo image, with inline styles that change on hover.
-}
logo : Html msg
logo =
    img
        [ src "logo.png"
        , css
            [ display inlineBlock
            , padding (px 20)
            , border3 (px 5) solid (rgb 120 120 120)
            , hover
                [ borderColor theme.primary
                , borderRadius (px 10)
                ]
            ]
        ]
        []


{-| A plain old record holding a couple of theme colors.
-}
theme : { secondary : Color, primary : Color }
theme =
    { primary = hex "55af6a"
    , secondary = rgb 250 240 230
    }


{-| A reusable button which has some styles pre-applied to it.
-}
btn : List (Attribute msg) -> List (Html msg) -> Html msg
btn =
    styled button
        [ margin (px 12)
        , color (rgb 250 250 250)
        , hover
            [ backgroundColor theme.primary
            , textDecoration underline
            ]
        ]


{-| A reusable style. Css.batch combines multiple styles into one, much
like mixins in CSS preprocessors.
-}
paragraphFont : Style
paragraphFont =
    Css.batch
        [ fontFamilies [ "Palatino Linotype", "Georgia", "serif" ]
        , fontSize (px 16)
        , fontWeight normal
        ]


{-| Css.property lets you define custom properties, using strings as their values.
-}
legacyBorderRadius : String -> Style
legacyBorderRadius amount =
    Css.batch
        [ property "-moz-border-radius" amount
        , property "-webkit-border-top-left-radius" amount
        , property "-webkit-border-top-right-radius" amount
        , property "-webkit-border-bottom-right-radius" amount
        , property "-webkit-border-bottom-left-radius" amount
        , property "border-radius" amount
        ]


view : Model -> Html Msg
view model =
    nav []
        [ img [ src "assets/backdrop.jpg", css [ width (pct 100) ] ] []
        , btn [ onClick DoSomething ] [ text "Click me!" ]
        ]


main : Program Never Model Msg
main =
    Html.beginnerProgram
        { view = view >> toUnstyled
        , update = update
        , model = initialModel
        }

See the Css module documentation for an explanation of how this code works.

elm-css draws inspiration from the excellent Sass, Stylus, CSS Modules, and styled-components libraries. It includes features like:

Examples

Related Projects

More Repositories

1

seamless-immutable

Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.
JavaScript
5,363
star
2

elm-spa-example

A Single Page Application written in Elm
Elm
3,251
star
3

dreamwriter

(NOTE! This has not been updated since Elm 0.15.1.) Streamlined long-form writing software. Written in Elm.
JavaScript
459
star
4

elm-workshop

An introductory Elm workshop. Video available on Frontend Masters!
Elm
438
star
5

elm-0.19-workshop

Elm 0.19 workshops. Includes Intro and Advanced courses.
Elm
212
star
6

rust-1.51-workshop

Richard Feldman's Rust workshop
Rust
192
star
7

node-elm-compiler

A Node.js interface to the Elm compiler binaries.
TypeScript
170
star
8

elm-in-action

Resources for the Elm In Action book.
JavaScript
160
star
9

elm-validate

Convenience functions for validating Elm data.
Elm
144
star
10

node-test-runner

Runs elm-test suites from Node.js. Get it with npm install -g elm-test
JavaScript
133
star
11

elm-google-maps

Using Google Maps in Elm by way of Polymer
Elm
56
star
12

elm-use

Switch between Elm versions
JavaScript
38
star
13

elm-iso8601-date-strings

Convert between ISO-8601 date strings and Time.Posix
Elm
30
star
14

elm-web-workers

Write Elm code that talks to Web Workers.
Elm
28
star
15

selectlist

A nonempty list in which exactly one element is always selected.
Elm
27
star
16

elm-json-experiment

Experimental API for building JSON decoders
Elm
20
star
17

lambdaconf-2015-elm-workshop

Materials for the Elm Workshop at LambdaConf 2015
Elm
20
star
18

grunt-elm

Grunt plugin that compiles Elm files to JavaScript.
JavaScript
19
star
19

elm-codify

A tool to generate Elm decoders, encoders, and type aliases from JSON.
Elm
16
star
20

elm-0.18-workshop

An introductory Elm 0.18 workshop.
Elm
14
star
21

elm-node-app

Communication layer so Elm code can talk to Node.js code.
Elm
13
star
22

elm-css-helpers

Helpers for using elm-css with elm-html
Elm
11
star
23

dotfiles

Configuration files I use.
Shell
11
star
24

style-elements-demo

style-elements demo for ReactiveConf 2017 talk, "CSS as Bytecode"
Elm
8
star
25

elm-sorter-experiment

Experimental Sorter/Dict/Set API
Elm
8
star
26

elm-hex

Work with Hexadecimal numbers in Elm.
Elm
6
star
27

dreamwriter-coffee

Streamlined writing software. Written in React and CoffeeScript.
CoffeeScript
6
star
28

vector

List where head & tail don't return Maybe and still can't crash
Elm
6
star
29

count

Call record constructors with increasing integers. Surprisingly useful!
Elm
5
star
30

elm-signup-form

JavaScript
5
star
31

test-update

Convenience functions for testing update functions
Elm
5
star
32

mloc-2015-elm-workshop

Materials for the Elm Workshop at mloc.js 2015
Elm
5
star
33

hashed-class

Generate CSS classnames by hashing their styles.
Elm
5
star
34

hex

Work with Hexadecimal numbers in Elm.
Elm
4
star
35

roc-decimal-draft

Rust
3
star
36

quicksort-benchmarks

quicksort-benchmarks
Swift
3
star
37

csrf-xhr

Automatically add Rails CSRF tokens into XMLHttpRequest headers.
JavaScript
3
star
38

elm-in-action.com

Website for the book Elm in Action, from Manning Publications
3
star
39

console-print

Print special characters to the console, in Elm
Elm
3
star
40

ziplist

DEPRECATED in favor of rtfeldman/selectlist (better name!)
Elm
3
star
41

path

Elm
2
star
42

operation-pterodactyl

πŸ¦‰
Elm
2
star
43

elm-css-util

Utility functions shared by elm-css and elm-css-helpers
Elm
2
star
44

elm-dropbox

Elm API for integrating with Dropbox
JavaScript
2
star
45

legacy-elm-test

An implementation of the legacy ElmTest module for backwards compatibility.
Elm
2
star
46

openresty-postgres-example

RealWorld example backend using OpenResty, Postgres, and nothing else
JavaScript
1
star
47

binstall

JavaScript
1
star
48

sweetvalidation

CoffeeScript
1
star
49

promises-done-polyfill

Polyfills Promise.done()
JavaScript
1
star