Skip to content

Add a Embed module #10

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"exposed-modules": [
"Element.WithContext",
"Element.WithContext.Input",
"Element.WithContext.Embed",
"Element.WithContext.Events",
"Element.WithContext.Background",
"Element.WithContext.Border",
Expand Down
103 changes: 103 additions & 0 deletions src/Element/WithContext/Embed.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
module Element.WithContext.Embed exposing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's better to call it Embed or Interop? Probably Embed is better

( el, attr
, unwrap, unwrapAttr, unwrapLabel, unwrapOption, unwrapPlaceholder, unwrapThumb
)

{-|

@docs el, attr

-}

import Element
import Element.Input
import Element.WithContext.Input.Internal as Internal exposing (Label(..), Option(..), Placeholder(..), Thumb(..), runLabel, runOption, runPlaceholder, runThumb)
import Element.WithContext.Internal as Internal exposing (Attr(..), Element(..), run, runAttr)


unwrap =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing documentation

Internal.run


unwrapAttr =
Internal.runAttr


unwrapLabel =
Internal.runLabel


unwrapOption =
Internal.runOption


unwrapPlaceholder =
Internal.runPlaceholder


unwrapThumb =
Internal.runThumb


{-| Allow integration with external libraries that require elm-ui `Element`s to be passed in.
-}
el :
({ context : context
, unwrap : Element context msg -> Element.Element msg
, unwrapAttr : Attr context decorative msg -> Element.Attr decorative msg
, unwrapPlaceholder : Placeholder context msg -> Element.Input.Placeholder msg
, unwrapLabel : Label context msg -> Element.Input.Label msg
, unwrapThumb : Thumb context -> Element.Input.Thumb
, unwrapOption : Option context value msg -> Element.Input.Option value msg
}
-> Element context msg
)
-> Element context msg
el ctor =
Element <|
\context ->
let
(Element result) =
ctor
{ context = context
, unwrap = \(Element f) -> f context
, unwrapAttr = \(Attribute f) -> f context
, unwrapPlaceholder = \(Placeholder f) -> f context
, unwrapLabel = \(Label f) -> f context
, unwrapThumb = \(Thumb f) -> f context
, unwrapOption = \(Option f) -> f context
}
in
result context


{-| Allow integration with external libraries that require elm-ui `Element`s to be passed in.
-}
attr :
({ context : context
, unwrap : Element context msg -> Element.Element msg
, unwrapAttr : Attr context decorative msg -> Element.Attr decorative msg
, unwrapPlaceholder : Placeholder context msg -> Element.Input.Placeholder msg
, unwrapLabel : Label context msg -> Element.Input.Label msg
, unwrapThumb : Thumb context -> Element.Input.Thumb
, unwrapOption : Option context value msg -> Element.Input.Option value msg
}
-> Attr context decorative msg
)
-> Attr context decorative msg
attr ctor =
Attribute <|
\context ->
let
(Attribute result) =
ctor
{ context = context
, unwrap = \(Element f) -> f context
, unwrapAttr = \(Attribute f) -> f context
, unwrapPlaceholder = \(Placeholder f) -> f context
, unwrapLabel = \(Label f) -> f context
, unwrapThumb = \(Thumb f) -> f context
, unwrapOption = \(Option f) -> f context
}
in
result context
38 changes: 9 additions & 29 deletions src/Element/WithContext/Input.elm
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,13 @@ Alternatively, see if it's reasonable to _not_ display an input if you'd normall
import Element as Vanilla
import Element.Input as Input
import Element.WithContext exposing (Attribute, Element, element)
import Element.WithContext.Input.Internal as InputInternal exposing (Label(..), Option(..), Placeholder(..), Thumb(..), runLabel, runOption, runPlaceholder, runThumb)
import Element.WithContext.Internal exposing (attribute, attributes, run, wrapAttrs)


{-| -}
type Placeholder context msg
= Placeholder (context -> Input.Placeholder msg)
type alias Placeholder context msg =
InputInternal.Placeholder context msg
Comment on lines +195 to +196
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you doing this? [not saying it's wrong, just curious about the reason]



{-| -}
Expand All @@ -205,8 +206,8 @@ placeholder attrs child =


{-| -}
type Label context msg
= Label (context -> Input.Label msg)
type alias Label context msg =
InputInternal.Label context msg


buildLabel :
Expand Down Expand Up @@ -333,9 +334,8 @@ checkbox =
)


{-| -}
type Thumb context
= Thumb (context -> Input.Thumb)
type alias Thumb context =
InputInternal.Thumb context


{-| -}
Expand All @@ -344,11 +344,6 @@ thumb attrs =
Thumb <| \context -> Input.thumb <| attributes context attrs


runThumb : a -> Thumb a -> Input.Thumb
runThumb context (Thumb f) =
f context


{-| -}
defaultThumb : Thumb context
defaultThumb =
Expand Down Expand Up @@ -454,16 +449,6 @@ textHelper f =
)


runPlaceholder : context -> Placeholder context msg -> Input.Placeholder msg
runPlaceholder context (Placeholder f) =
f context


runLabel : context -> Label context msg -> Input.Label msg
runLabel context (Label f) =
f context


{-| -}
text :
List (Attribute context msg)
Expand Down Expand Up @@ -615,13 +600,8 @@ multiline =


{-| -}
type Option context value msg
= Option (context -> Input.Option value msg)


runOption : a -> Option a value msg -> Input.Option value msg
runOption context (Option f) =
f context
type alias Option context value msg =
InputInternal.Option context value msg


{-| -}
Expand Down
40 changes: 40 additions & 0 deletions src/Element/WithContext/Input/Internal.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module Element.WithContext.Input.Internal exposing (Label(..), Option(..), Placeholder(..), Thumb(..), runLabel, runOption, runPlaceholder, runThumb)

import Element.Input as Input


type Placeholder context msg
= Placeholder (context -> Input.Placeholder msg)


runPlaceholder : context -> Placeholder context msg -> Input.Placeholder msg
runPlaceholder context (Placeholder f) =
f context


type Label context msg
= Label (context -> Input.Label msg)


runLabel : context -> Label context msg -> Input.Label msg
runLabel context (Label f) =
f context


type Option context value msg
= Option (context -> Input.Option value msg)


runOption : a -> Option a value msg -> Input.Option value msg
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be nitpicky, but can you s/a/context/

runOption context (Option f) =
f context


{-| -}
type Thumb context
= Thumb (context -> Input.Thumb)


runThumb : a -> Thumb a -> Input.Thumb
runThumb context (Thumb f) =
f context