Skip to content

Add 'run' functions #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 71 additions & 3 deletions src/Element/WithContext.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Element.WithContext exposing
( with, withAttribute, withDecoration, layout, layoutWith, element, attribute, attr
( with, withAttribute, withDecoration, layout, layoutWith, element, attribute, attr, embed, embedAttr
, Element, none, text, el
, row, wrappedRow, column
, paragraph, textColumn
Expand All @@ -24,14 +24,15 @@ module Element.WithContext exposing
, map, mapAttribute
, html, htmlAttribute
, withContext, withContextAttribute, withContextDecoration
, attributes, run, runAttr, withAttr
)

{-|


# `elm-ui-with-context` specific functions

@docs with, withAttribute, withDecoration, layout, layoutWith, element, attribute, attr
@docs with, withAttribute, withDecoration, layout, layoutWith, element, attribute, attr, embed, embedAttr


# Basic Elements
Expand Down Expand Up @@ -227,10 +228,18 @@ Sometimes it's more convenient to just access the whole context while building y
-}

import Element
import Element.WithContext.Internal as Internal exposing (Attr(..), Attribute, Element(..), attr, attribute, attributes, run, runAttr, wrapAttrs, wrapContainer)
import Element.WithContext.Internal as Internal exposing (Attr(..), Attribute, Element(..), attr, attribute, wrapAttrs, wrapContainer)
import Html exposing (Html)


runAttr =
Internal.runAttr


attributes =
Internal.attributes


{-| -}
type alias Color =
Internal.Color
Expand Down Expand Up @@ -369,6 +378,50 @@ attr elem =
Attribute <| \_ -> elem


{-| Allow integration with external libraries that require elm-ui `Element`s to be passed in.
-}
embed :
({ unwrap : Element context msg -> Element.Element msg
, unwrapAttr : Attr context decorative msg -> Element.Attr decorative msg
}
-> Element context msg
)
-> Element context msg
embed ctor =
Element <|
\context ->
let
(Element result) =
ctor
{ unwrap = \(Element f) -> f context
, unwrapAttr = \(Attribute f) -> f context
}
in
result context


{-| Allow integration with external libraries that require elm-ui `Element`s to be passed in.
-}
embedAttr :
({ unwrap : Element context msg -> Element.Element msg
, unwrapAttr : Attr context decorative msg -> Element.Attr decorative msg
}
-> Attr context decorative msg
)
-> Attr context decorative msg
embedAttr ctor =
Attribute <|
\context ->
let
(Attribute result) =
ctor
{ unwrap = \(Element f) -> f context
, unwrapAttr = \(Attribute f) -> f context
}
in
result context


{-| -}
map : (msg -> msg1) -> Element context msg -> Element context msg1
map f (Element g) =
Expand Down Expand Up @@ -402,6 +455,13 @@ withDecoration selector f =
Attribute <| \context -> runAttr context <| f <| selector context


{-| Use a property from the context to build an `Attr`. Have a look at the README for examples.
-}
withAttr : (context -> property) -> (property -> Attr context decoration msg) -> Attr context decoration msg
withAttr selector f =
Attribute <| \context -> runAttr context <| f <| selector context


{-| Use the context to build an `Element`. Have a look at the README for examples.
-}
withContext : (context -> Element context msg) -> Element context msg
Expand All @@ -423,6 +483,14 @@ withContextDecoration f =
Attribute <| \context -> runAttr context <| f context


{-| Change a `Element context msg` into a `Element.Element msg`, which is
needed when wrapping a third-party view that takes non-WithContext elements
-}
run : context -> Element context msg -> Element.Element msg
run =
Internal.run


{-| -}
type alias Length =
Element.Length
Expand Down
4 changes: 2 additions & 2 deletions src/Element/WithContext/Input.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Element.WithContext.Input exposing
, button
, checkbox, defaultCheckbox
, text, multiline
, Placeholder, placeholder
, Placeholder, placeholder, runPlaceholder, runLabel
, username, newPassword, currentPassword, email, search, spellChecked
, slider, Thumb, thumb, defaultThumb
, radio, radioRow, Option, option, optionWith, OptionState(..)
Expand Down Expand Up @@ -66,7 +66,7 @@ This is also the first input element that has a [`required label`](#Label).

@docs text, multiline

@docs Placeholder, placeholder
@docs Placeholder, placeholder, runPlaceholder, runLabel


## Text with autofill
Expand Down