-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
module Element.WithContext.Embed exposing | ||
( 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 = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] |
||
|
||
|
||
{-| -} | ||
|
@@ -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 : | ||
|
@@ -333,9 +334,8 @@ checkbox = | |
) | ||
|
||
|
||
{-| -} | ||
type Thumb context | ||
= Thumb (context -> Input.Thumb) | ||
type alias Thumb context = | ||
InputInternal.Thumb context | ||
|
||
|
||
{-| -} | ||
|
@@ -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 = | ||
|
@@ -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) | ||
|
@@ -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 | ||
|
||
|
||
{-| -} | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry to be nitpicky, but can you |
||
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 |
There was a problem hiding this comment.
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
orInterop
? ProbablyEmbed
is better