diff --git a/src/Element/WithContext.elm b/src/Element/WithContext.elm index c4b38b6..0453289 100644 --- a/src/Element/WithContext.elm +++ b/src/Element/WithContext.elm @@ -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 @@ -24,6 +24,7 @@ module Element.WithContext exposing , map, mapAttribute , html, htmlAttribute , withContext, withContextAttribute, withContextDecoration + , attributes, run, runAttr, withAttr ) {-| @@ -31,7 +32,7 @@ module Element.WithContext exposing # `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 @@ -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 @@ -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) = @@ -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 @@ -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 diff --git a/src/Element/WithContext/Input.elm b/src/Element/WithContext/Input.elm index 45b24e4..0b15a64 100644 --- a/src/Element/WithContext/Input.elm +++ b/src/Element/WithContext/Input.elm @@ -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(..) @@ -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