-
Notifications
You must be signed in to change notification settings - Fork 2
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
Task solution from happy-luna #16
Closed
Closed
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
c6013f8
COMMIT-1 Implement data structure and decoders
9dfedd6
add font
4cffab6
implement an email field
1a14a65
implement phone input
b9c2c52
implement company name input
12bc714
implement address fields
ceb705b
implement buttons
87d0c60
add email validation and error message
2b7cbbd
add phone validation
b481d96
adjust styling
4222e9f
validate address
3447b18
make form more responsive
9d4204e
extract form
3da57e2
add data retention settings section
fcd67a2
implement data retention policy form
4596085
extract contact form into separate module
37708c4
adjust contact form init
f74da3e
extract setting to module
d1b874d
focus on policy field after add
92c29d1
add tags view
7400295
add tags module & extract data structures into modules
ea1ebd2
implement tags form view
0fa0d4a
add 'remove' button
460c0fa
add functionality to tags form
03c4eb5
adjust input logic
367dadb
add tags validation
2abad14
add submit/close functionality to tags form
5465f0c
adjust code style
6e02a14
reset tags form on cancel/close
660610f
fix forms states
677c7c6
add value field to new tag, let it be submitted by enter
dcceca1
add remove button to settings
40b8115
check whole contact form for validity on sumbit
98590c2
fix inheritance logic
8b9a12b
expose only required stuff
26290d6
adjust tags validation logic/ remove duplication
39022b4
remove unnecessary styles module
21f7e31
extract big views into functions
1fe9912
use string approach for errors
c0f3c36
adjsut inheritance logic
cf6c48b
use simple approach for nonZero
f307431
improve input build readability
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
elm-stuff | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
module Components.Input exposing | ||
( disabled | ||
, error | ||
, id | ||
, label | ||
, onBlur | ||
, onChange | ||
, type_ | ||
, value | ||
, viewTextOrNumber | ||
) | ||
|
||
import Html exposing (Html) | ||
import Html.Attributes as Attrs | ||
import Html.Events as Events | ||
|
||
|
||
type alias Config msg = | ||
{ label : String | ||
, disabled : Bool | ||
, type_ : String | ||
, onChange : Maybe (String -> msg) | ||
, onBlur : Maybe msg | ||
, value : String | ||
, error : String | ||
, id : String | ||
} | ||
|
||
|
||
defaultConfig : Config msg | ||
defaultConfig = | ||
{ label = "" | ||
, disabled = False | ||
, type_ = "text" | ||
, onChange = Nothing | ||
, onBlur = Nothing | ||
, value = "" | ||
, error = "" | ||
, id = "" | ||
} | ||
|
||
|
||
id : String -> Config msg -> Config msg | ||
id id_ config = | ||
{ config | id = id_ } | ||
|
||
|
||
onBlur : Maybe msg -> Config msg -> Config msg | ||
onBlur onBlur_ config = | ||
{ config | onBlur = onBlur_ } | ||
|
||
|
||
label : String -> Config msg -> Config msg | ||
label label_ config = | ||
{ config | label = label_ } | ||
|
||
|
||
disabled : Bool -> Config msg -> Config msg | ||
disabled disabled_ config = | ||
{ config | disabled = disabled_ } | ||
|
||
|
||
type_ : String -> Config msg -> Config msg | ||
type_ type__ config = | ||
{ config | type_ = type__ } | ||
|
||
|
||
onChange : Maybe (String -> msg) -> Config msg -> Config msg | ||
onChange onChange_ config = | ||
{ config | onChange = onChange_ } | ||
|
||
|
||
value : String -> Config msg -> Config msg | ||
value value_ config = | ||
{ config | value = value_ } | ||
|
||
|
||
error : String -> Config msg -> Config msg | ||
error error_ config = | ||
{ config | error = error_ } | ||
|
||
|
||
viewTextOrNumber : List (Config msg -> Config msg) -> Html msg | ||
viewTextOrNumber customConfigurations = | ||
let | ||
config : Config msg | ||
config = | ||
customConfigurations | ||
|> List.foldl | ||
(\customConfiguration config_ -> customConfiguration config_) | ||
defaultConfig | ||
|
||
hasError : Bool | ||
hasError = | ||
not (String.isEmpty config.error) | ||
in | ||
Html.span | ||
[ Attrs.class "flex flex-col rounded px-2 py-1" | ||
, Attrs.classList [ ( "bg-[#e8f3fc]", config.disabled ) ] | ||
] | ||
[ Html.label [ Attrs.class "text-sm pl-1", Attrs.classList [ ( "text-red-500", hasError ) ] ] | ||
[ Html.text | ||
(if hasError then | ||
config.error | ||
|
||
else | ||
config.label | ||
) | ||
] | ||
, Html.input | ||
([ Attrs.type_ config.type_ | ||
, Attrs.id config.id | ||
, Attrs.class "focus:outline-none w-full" | ||
, Attrs.class "border rounded px-2 py-1" | ||
, Attrs.classList | ||
[ ( "bg-[#e8f3fc]", config.disabled ) | ||
, ( "border-red-500", hasError ) | ||
, ( "border-stone-400", not hasError ) | ||
] | ||
, Attrs.disabled config.disabled | ||
, Attrs.value config.value | ||
] | ||
++ (config.onChange | ||
|> Maybe.map (Events.onInput >> List.singleton) | ||
|> Maybe.withDefault [] | ||
) | ||
++ (config.onBlur | ||
|> Maybe.map (Events.onBlur >> List.singleton) | ||
|> Maybe.withDefault [] | ||
) | ||
) | ||
[] | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I like the usage of this library, I feel we should use it more often 💯
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.
It's a bit dangerous, because it relies on the order that attributes are declared in a record.
Change the order, you get a very nasty and very silent bug.
Bit us a couple of times at a previous job of mine.