• This repository has been archived on 06/Sep/2019
  • Stars
    star
    180
  • Rank 205,735 (Top 5 %)
  • Language
    Elm
  • License
    MIT License
  • Created about 7 years ago
  • Updated almost 6 years ago

Reviews

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

Repository Details

Styling your Html Elements with typed Css πŸ’…

Unreleased! At the moment I can't release this package to the elm package manager because it is using Native code. If you still want to expirement with it you can install it directly from GitHub. ❀️

elm-styled logo

Use typed CSS inside your Elm files to style your Html elements.

elm-package install styled-components/elm-styled

Usage

Basic

This creates two Elm functions, title and wrapper.

import Html exposing (..)
import Styled exposing (..)
import Styled.Colors exposing (pink, lightYellow)


title =
    styled h1
        [ fontSize (Styled.em 1.5)
        , textAlign center
        , color pink
        , fontFamily monospace
        ]


wrapper =
    styled div
        [ padding (Styled.em 4)
        , backgroundColor lightYellow
        ]

You render them like every other Elm node.

main =
    wrapper []
        [ title []
            [ text "Hello World, this is my first styled function πŸ’…" ]
        ]
Screenshot of the above code ran in a browser πŸ’…

Overriding Styles

We can create a simple button function and using this function to create a new styled function. The new styled function will have all of the styles from both styled functions.

import Html exposing (div, text)
import Styled exposing (..)
import Styled.Colors exposing (white, pink)


button =
    styled Html.button
        [ backgroundColor white
        , color pink
        , fontSize (Styled.em 1)
        , margin (Styled.em 1)
        , padding2 (Styled.em 0.25) (Styled.em 1)
        , border (px 2) solid pink
        , borderRadius (px 3)
        ]


primaryButton =
    styled button
        [ backgroundColor pink
        , color white
        ]


main =
    div
        []
        [ button [] [ text "Normal" ]
        , primaryButton [] [ text "Primary" ]
        ]
Screenshot of the above code ran in a browser πŸ’…

Dynamic Styles

If you want to have dynamic styles you can create a function which will return a styled function.

import Html exposing (..)
import Styled exposing (..)
import Styled.Colors exposing (red, yellow, green)


light paint =
    styled div
        [ backgroundColor paint
        , borderRadius (percent 50)
        , display inlineBlock
        , height (px 60)
        , width (px 60)
        , margin (px 20)
        ]


trafficLight =
    div []
        [ light red [] []
        , light yellow [] []
        , light green [] []
        ]


main =
    trafficLight
Screenshot of the above code ran in a browser πŸ’…

Animations

CSS animations with @keyframes aren't scoped to a single function but you still don't want them to be global. This is why we export a keyframes helper which will generate a unique name for your keyframes. You can then use that unique name throughout your app.

import Html exposing (..)
import Styled exposing (..)
import Styled.Keyframes exposing (keyframes)
import Styled.Transforms exposing (rotate)
import Styled.Timings exposing (linear)


spin =
    keyframes
        [ ( 0
          , [ transform (rotate (deg 0))
            ]
          )
        , ( 100
          , [ transform (rotate (deg 360))
            ]
          )
        ]


loader =
    styled div
        [ display inlineBlock
        , animationName spin
        , animationDuration (Styled.s 2)
        , animationTimingFunction linear
        , animationIterationCount infinite
        ]


main =
    loader [] [ text "[ πŸ’… ]" ]
Screenshot of the above code ran in a browser πŸ’…

More Repositories

1

styled-components

Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress πŸ’…
TypeScript
39,930
star
2

polished

A lightweight toolset for writing styles in JavaScript ✨
JavaScript
7,562
star
3

awesome-styled-components

A curated list of awesome styled-components resources πŸ’…
3,283
star
4

xstyled

A utility-first CSS-in-JS framework built for React. πŸ’…πŸ‘©β€πŸŽ€βš‘οΈ
MDX
2,254
star
5

jest-styled-components

πŸ”§ πŸ’… Jest utilities for Styled Components
JavaScript
1,577
star
6

vue-styled-components

Visual primitives for the component age. A simple port for Vue of styled-components πŸ’…
JavaScript
1,362
star
7

styled-theming

Create themes for your app using styled-components
JavaScript
1,168
star
8

css-to-react-native

Convert CSS text to a React Native stylesheet object
JavaScript
1,117
star
9

babel-plugin-styled-components

Improve the debugging experience and add server-side rendering support to styled-components
JavaScript
1,063
star
10

vscode-styled-components

Syntax highlighting for styled-components
JavaScript
911
star
11

stylelint-processor-styled-components

Lint your styled components with stylelint!
JavaScript
657
star
12

styled-components-website

The styled-components website and documentation
MDX
607
star
13

webstorm-styled-components

styled-components highlighting support in IntelliJ editors
Kotlin
377
star
14

vim-styled-components

Vim bundle for http://styled-components.com based javascript files.
Vim Script
300
star
15

comparison

Comparing different ways to style components
JavaScript
183
star
16

babel-plugin-polished

Compile polished helper functions at build time
JavaScript
138
star
17

styled-elements

Styled components for the DOM.
JavaScript
87
star
18

stylelint-config-styled-components

The shareable stylelint config for stylelint-processor-styled-components
JavaScript
71
star
19

spec

Design Requirements and Spec for a Component-oriented CSS Solution
61
star
20

color-schemer

A React app to help you select a color scheme, built with styled-components and polished
JavaScript
55
star
21

styled-components-codemods

Automatic codemods to upgrade your styled-components code to newer versions.
JavaScript
52
star
22

styled-components-experimentation

A place to play with things that shouldn't be in core
JavaScript
31
star
23

s-c.sh

The styled-components URL shortener!
30
star
24

styled-components-native-code-mod

JavaScript
28
star
25

styled-components.github.io

The styled-components homepage
JavaScript
22
star
26

brand

Logo and brand related materials
11
star
27

benchmark

JavaScript
9
star
28

todomvc

The Speedometer 2.0 React TodoMVC example rebuilt with styled-components
JavaScript
6
star
29

babel-plugin-styled-components-ssr

[EXPERIMENTAL]
JavaScript
2
star
30

use-styled-hook

tbd
1
star