Skip to content
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
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
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
Jan 15, 2025
9dfedd6
add font
Jan 15, 2025
4cffab6
implement an email field
Jan 15, 2025
1a14a65
implement phone input
Jan 15, 2025
b9c2c52
implement company name input
Jan 15, 2025
12bc714
implement address fields
Jan 15, 2025
ceb705b
implement buttons
Jan 15, 2025
87d0c60
add email validation and error message
Jan 15, 2025
2b7cbbd
add phone validation
Jan 15, 2025
b481d96
adjust styling
Jan 15, 2025
4222e9f
validate address
Jan 15, 2025
3447b18
make form more responsive
Jan 15, 2025
9d4204e
extract form
Jan 15, 2025
3da57e2
add data retention settings section
Jan 15, 2025
fcd67a2
implement data retention policy form
Jan 15, 2025
4596085
extract contact form into separate module
Jan 16, 2025
37708c4
adjust contact form init
Jan 16, 2025
f74da3e
extract setting to module
Jan 16, 2025
d1b874d
focus on policy field after add
Jan 16, 2025
92c29d1
add tags view
Jan 16, 2025
7400295
add tags module & extract data structures into modules
Jan 16, 2025
ea1ebd2
implement tags form view
Jan 16, 2025
0fa0d4a
add 'remove' button
Jan 16, 2025
460c0fa
add functionality to tags form
Jan 16, 2025
03c4eb5
adjust input logic
Jan 16, 2025
367dadb
add tags validation
Jan 16, 2025
2abad14
add submit/close functionality to tags form
Jan 16, 2025
5465f0c
adjust code style
Jan 16, 2025
6e02a14
reset tags form on cancel/close
Jan 16, 2025
660610f
fix forms states
Jan 16, 2025
677c7c6
add value field to new tag, let it be submitted by enter
Jan 16, 2025
dcceca1
add remove button to settings
Jan 16, 2025
40b8115
check whole contact form for validity on sumbit
Jan 16, 2025
98590c2
fix inheritance logic
Jan 16, 2025
8b9a12b
expose only required stuff
Jan 16, 2025
26290d6
adjust tags validation logic/ remove duplication
Jan 17, 2025
39022b4
remove unnecessary styles module
Jan 17, 2025
21f7e31
extract big views into functions
Jan 17, 2025
1fe9912
use string approach for errors
Jan 17, 2025
c0f3c36
adjsut inheritance logic
Jan 17, 2025
cf6c48b
use simple approach for nonZero
Jan 17, 2025
f307431
improve input build readability
Jan 17, 2025
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
elm-stuff
.idea/
4 changes: 3 additions & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"NoRedInk/elm-json-decode-pipeline": "1.0.1",
Copy link
Member

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 💯

Copy link

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.

"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/json": "1.1.3"
"elm/json": "1.1.3",
"elm/regex": "1.0.0"
},
"indirect": {
"elm/time": "1.0.0",
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap" rel="stylesheet">
<link media="all" rel="stylesheet" href="src/styles.css">
<title>Elm challenge</title>
<script type="module" src="src/app.js"></script>
Expand Down
133 changes: 133 additions & 0 deletions src/Components/Input.elm
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 []
)
)
[]
]
Loading