A module for storing and interpreting screen dimensions using buckets.
Depending on the situation you need, you can either implement screen size-based functionality in the form of:
All methods use the same core set of display buckets, but doing anything with data in Elm is slower because it relies on JavaScript. So when doing presentation-related things, always use the Media Queries wherever possible.
Use this array of tools when you need to store and update the screen size in your model, so you can change your app's functionality based on screen size.
The record for the width portion of Metrics.
Widths are generally more important than height for determining screen layout so there's both broad and fine buckets.
The record for the height portion of Metrics.
Heights are generally less important than height for determining screen layout so there's only broad buckets.
Makes a starting metrics structure where all the values are 0.
Use this in your initial model, but the model must be properly initialised afterwards.
Takes the width and height values that you'd get from functions like
Browser.Events.onResize and updates the screen metrics structure based
on those values.
Because bucket boundaries are in Ints while functions like
Browser.Events.onResize produce Floats, the function rounds those
values up when comparing against buckets.
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
ScreenResize w h ->
( { model | screen = Screen.set w h model.screen }, Cmd.none )These are stored in Screen.Metrics and can also be converted to from raw
Ints from functions in the raw numbers section.
These are ideal for using buckets for changing the basic functionality and elements of your app based on screen size. If you want to change your app's presentation, you should use CSS Media Queries instead.
Html.div
[]
-- show mobile menu if screen width is Handset
[ ( if model.screen.width.broad == Handset then
Html.div [] [Html.text "menu"]
else
[]
)
]Custom type representing broad width buckets.
Check this package's readme for summaries of all the buckets.
Custom type representing fine width buckets.
Check this package's readme for summaries of all the buckets.
Custom type representing height buckets.
Check this package's readme for summaries of all the buckets.
Use these to create Media Queries to change your app's presentation in elm-css.
This is the most responsive way to change stuff based on screen size in the browser, so you should use it wherever you can.
You can stack these media queries in a list like below:
css [ withMedia [ Screen.handset, Screen.portable1, Screen.portable2 ]
[ height (px 32)
, overflow hidden
]
, withMedia [ Screen.portable3, Screen.wide ]
[ width (px 192)
, padding4 (px 64) (blc 32) (px 32) (px 48)
]
]CSS Media query covering all handset width buckets (handset1 - handset3).
CSS Media query covering all portable width buckets (portable1 - portable3).
CSS Media query covering all wide width buckets (wide1 - wide2).
CSS Media query for the handset1 width bucket.
CSS Media query for the handset2 width bucket.
CSS Media query for the handset3 width bucket.
CSS Media query for the portable1 width bucket.
CSS Media query for the portable2 width bucket.
CSS Media query for the portable3 width bucket.
CSS Media query for the wide1 width bucket.
CSS Media query for the wide2 width bucket.
CSS Media query covering the limited height bucket.
CSS Media query covering the medium height bucket.
CSS Media query covering the tall height bucket.
Should you need access to the base metric numbers these buckets are made of.
A single screen dimension bucket.
The value that the minimum or a maximum of a bucket can be at.
Defines what axis a bucket is for.
Takes an int representing screen width in pixels and converts it into a broad screen width bucket.
Takes a Int representing screen width and and converts it into a fine screen width bucket.
Takes an int representing a screen height in pixels and converts it into a screen height bucket.
Buckets boundaries are Ints, so this function rounds the screen width Int up.
https://github.com/dzuk-mutant/Helium/blob/master/docs/display.md#display-height-groups
Raw values for the handset width bucket.
Raw values for the portable width bucket.
Raw values for the wide width bucket.
Raw values for the handset1 width bucket.
Raw values for the handset2 width bucket.
Raw values for the handset3 width bucket.
Raw values for the portable1 width bucket.
Raw values for the portable2 width bucket.
Raw values for the portable3 width bucket.
Raw values for the wide1 width bucket.
Raw values for the wide2 width bucket.
Raw values for the limited height bucket.
Raw values for the medium height bucket.
Raw values for the tall height bucket.
The type for storing all screen information.
Widths are generally more important than height for determining screen layout so there's both broad and fine buckets for width.