dzuk-mutant/nice-screen-buckets/2.1.1

NOTE: the latest version is 6.0.1

Screen.Bucket

A module for creating sets of screen boundaries (here, called 'buckets') for comparing against the user's screen size.

Types

type alias Bucket =
{ min : Boundary
, max : Boundary
, axis : Axis
}

A single bucket. Can only be used for one dimension (as defined by it's axis).

= NoLimit
| Defined Int

The value that the minimum or a maximum of a Bucket can be at.

  • NoLimit: Represents either zero (if min) or infinity (if max).
  • Defined: A definite value (in px, represented as Ints).
type Axis
= Width
| Height

Defines what axis a bucket is for.

Creating buckets

create : Axis -> Boundary -> Boundary -> Bucket

A function that creates a Bucket using the normal values that Buckets contain.

Consider using stepBelow in conjunction with this function to create buckets that neatly slot next to each other.

mobile : Bucket
mobile = Bucket.create Width NoLimit (stepBelow tablet) 


tablet : Bucket
tablet = Bucket.create Width (Defined 412) (stepBelow desktop) 


desktop : Bucket
desktop = Bucket.create Width (Defined 1052) NoLimit
encompass : Axis -> Bucket -> Bucket -> Bucket

Creates a bucket that encompasses the minimum of the first bucket and the maximum of the second bucket.

Useful when you want to create buckets that are larger groupings of smaller buckets.

wide1 : Bucket
wide1 = Bucket.create Width (Defined 1056) (stepBelow wide2)


wide2 : Bucket
wide2 = Bucket.create Width (Defined 1440) NoLimit


wide : Bucket
wide = Bucket.encompass Width wide1 wide2
-- creates a bucket between 1056 and NoLimit
stepBelow : Bucket -> Boundary

Will produce a Boundary that is -1 of the minimum boundary of the given Bucket, if that Boundary is Definite.

If the minimum is NoLimit instead, then it will just return NoLimit.

Useful when you want to create buckets that neatly slot next to each other.

tablet : Bucket
tablet = Bucket.create Width (Defined 512) (stepBelow desktop) 


desktop : Bucket
desktop = Bucket.create Width (Defined 1052) NoLimit

Conversions

toMediaQuery : Bucket -> MediaQuery

A function that converts a Bucket into an elm-css MediaQuery that covers the boundaries given by the bucket at the correct axis.

These media queries can be stacked in a list wth functions such as withMedia, so you can cover larger areas with multiple contiguous buckets.

This function exists for possible edge cases that you might have. If you want to use buckets as media queries in a typical way, you'll probably want to look at Screen.withMedia instead.

tablet : Bucket
tablet = Bucket.create Width (Defined 512) (stepBelow desktop) 


tabletMq : MediaQuery
tabletMq = Bucket.toMediaQuery tablet
-- produces: only screen [ minWidth (px 512), maxWidth (px 1051) ]


desktop : Bucket
desktop = Bucket.create Width (Defined 1052) NoLimit


desktopMq : MediaQuery
desktopMq = Bucket.toMediaQuery desktop
-- produces: only screen [ minWidth (px 1052) ]