Here is where you an create your style sheet.
One of the first concepts of style-elements is that layout, position, and width/height all live in your view through the Element module.
Your style sheet handles everything else!
Check out the other Style modules for other properties.
Check out Basic.elm in the examples folder to see an example of a full style sheet.
style-elements does away with CSS selectors entirely. Every style gets one identifier, which is ultimately rendered as a class.
Here's a basic example of a style that sets a few colors.
import Style exposing (..)
import Style.Color as Color
import Color exposing (..)
type Styles
= Button
stylesheet =
Style.styleSheet
[ style Button
[ Color.background blue
, Color.text white
]
]
-- Which can be used in your view as:
el Button [ ] (text "A button!")Styles can have variations. Here's what it looks like to have a button style with a variation for Disabled
import Style exposing (..)
import Style.Color as Color
import Color exposing (..)
type Styles = Button
-- You need to create a new type to capture vartiations.
type Variations
= Large
stylesheet =
Style.styleSheet
[ style Button
[ Font.size 16
, variation Large
[ Font.size 20
]
]
]
-- which can be rendered in your view as
el Button [ vary Disabled True ] (text "A Disabled button!")Before you reach for a variation, consider just creating a subtype. So, something like:
import Style exposing (..)
import Style.Color as Color
import Color exposing (..)
type Styles
= Button ButtonStyles
type ButtonStyles
= Active
| Disabled
stylesheet =
Style.stylesheet
[ style (Button Active)
[ Color.background blue
]
, style (Button Disabled)
[ Color.background grey
]
]
-- which can be rendered in your view as
el (Button Active) [] (text "An Active button!")The main difference between these two is that variations can combine with other variations, while subtypes are mutually exclusive.
You can give a hint about what the padding should be for this element, but the layout can override it.
Check out the Style.Shadow module for more about shadows.
Check out the Style.Filter module for more about filters.
Apply a stack of filters. The actual filters are in Style.Filter.
import Style.Filter as Filter
import Style exposing (..)
style MyFitleredStyle
[ filters
[ Filter.blur 0.5
, Filter.invert 0.5
]
]Set the transform origin.
Units are always as pixels
Units always rendered as radians.
Use degrees or turns from the standard library if you want to use a different set of units.
Rotate around a vector.
Angle units always rendered as radians.
Use degrees or turns from the standard library if you want to use a different set of units.
Psuedo classes can be nested.
Example:
style Button
[ Color.background blue
, hover
[ Color.background red
]
]Stylesheet options
Remove style hash guards from style classes.
DEPRECATED, use styleSheet. This will be removed in the next major version
DEPRECATED, use styleSheetWith. This will be removed in the next major version