From d7d0f8e0e4c956e801b5da73f87d2765c41fbcc4 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Tue, 10 Dec 2019 17:46:00 +0000 Subject: [PATCH 01/50] examples/README.md to add context for the examples --- examples/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 examples/README.md diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..1c53abb --- /dev/null +++ b/examples/README.md @@ -0,0 +1,11 @@ +# _Examples_ + +This is a collection of _basic_ examples +collated from various sources including +https://elm-lang.org/examples +to give you a feel for Elm code. + +If you get stuck, please open an issue with a question: +https://github.com/dwyl/learn-elm/issues + +We are happy to help _anyone_ learning Elm to make progress! 😊 From 8ef6ce3ebc0ac375e990464af8784f284a59cb6b Mon Sep 17 00:00:00 2001 From: nelsonic Date: Tue, 10 Dec 2019 17:47:31 +0000 Subject: [PATCH 02/50] =?UTF-8?q?rename=20tutorials/lazy-loading/TUTORIAL.?= =?UTF-8?q?md=20to=20tutorials/lazy-loading/README.md=20so=20it=20is=20ins?= =?UTF-8?q?tantly=20viewable=20on=20GitHub=20instead=20of=20forcing=20peop?= =?UTF-8?q?le=20to=20have=20to=20*find*=20it=20and=20click=20another=20lin?= =?UTF-8?q?k=20=F0=9F=98=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutorials/lazy-loading/{TUTORIAL.md => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tutorials/lazy-loading/{TUTORIAL.md => README.md} (100%) diff --git a/tutorials/lazy-loading/TUTORIAL.md b/tutorials/lazy-loading/README.md similarity index 100% rename from tutorials/lazy-loading/TUTORIAL.md rename to tutorials/lazy-loading/README.md From 7774620a53a992bfe3182aa7e056edd8bf6ccfd6 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Tue, 10 Dec 2019 18:58:41 +0000 Subject: [PATCH 03/50] add elm.json after running elm init --- tutorials/elm-ui/elm.json | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tutorials/elm-ui/elm.json diff --git a/tutorials/elm-ui/elm.json b/tutorials/elm-ui/elm.json new file mode 100644 index 0000000..a8e90d9 --- /dev/null +++ b/tutorials/elm-ui/elm.json @@ -0,0 +1,24 @@ +{ + "type": "application", + "source-directories": [ + "src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/browser": "1.0.2", + "elm/core": "1.0.4", + "elm/html": "1.0.0" + }, + "indirect": { + "elm/json": "1.1.3", + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.2" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} From 2d1cb7ba9c81aa3bb247917dd3eb3ed3e86ebb6b Mon Sep 17 00:00:00 2001 From: nelsonic Date: Tue, 10 Dec 2019 21:06:02 +0000 Subject: [PATCH 04/50] add "Why?" section to explain why having a *system* is important! for #145 --- tutorials/elm-ui/README.md | 116 +++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 tutorials/elm-ui/README.md diff --git a/tutorials/elm-ui/README.md b/tutorials/elm-ui/README.md new file mode 100644 index 0000000..5d0619e --- /dev/null +++ b/tutorials/elm-ui/README.md @@ -0,0 +1,116 @@ +# `elm-ui` a Language for Layout and Interface + + +## _Why?_ 😢 `|>` 😍 + +People who are learning `CSS` +(_or those who are too impatient to learn and just want it to "work now"!_), +often end up feeling like `CSS` is a wild beast that cannot be tamed. + +
+ + Peter Griffen - Family Guy - CSS Trouble + +
+ + +In reality, CSS _can_ be learned/mastered reasonably quickly +and _amazing_ things can be made e.g: +http://www.csszengarden.com and https://www.cssdesignawards.com + +Sadly, it doesn't matter how well +_you_ - the conscientious developer/designer - learn CSS. +Unless you can ensure that _everyone_ in your team/company +has the same level of skill and care in their work, +it's _inevitable_ that over-time +duplicate and _conflicting_ styles will be added. + +
+ + dumpster fire + +
+ +Take any popular website and run it through CSS Stats https://cssstats.com +to see how many styles are being used. +A good example is [Twitter.com](https://twitter.com) +Their CSS is **632kb** + +![twitter-css-stats](https://user-images.githubusercontent.com/194400/70567485-f56b2580-1b8d-11ea-94c4-4e2ca8b5cd10.png) + +That might not sound like a lot, +but scroll down to the part that says **1024 total color declarations**: + +![twitter-css-stats-colors](https://user-images.githubusercontent.com/194400/70567583-1df31f80-1b8e-11ea-99d2-0c78a6f88a5d.png) + +Can you tell the difference between those shades of grey, blue and _white_?? +The point is that the developers/designers at Twitter - a tech company +with **billions** in revenue and some of the most talented people - +do not have _control_ over their CSS. + +> Twitter are the creators of Bootstrap +"_the most popular front-end framework in the world_". +**Bootstrap `v4`** is **123kb** (_uncompressed_) +and **23kb** (_compressed+gzipped_). +The _whole_ library including grid layout, +typography, colors, all compontents, forms and utilities. +Bootstrap is meant to be a _complete_ responsive grid-based design system +that _anyone_ can use to build their App/website. +And yet twitter, which has a _great_ in-house design team +with their own _system_ and component library, +have managed to build a + + + +The problem isn't you, the problem is the (_lack of a_) _system_. + + +@dwyl we _love_ the idea of having semantic and functional UIs +with no side-effects. Functional CSS allows you to change one style +without affecting any others. For the past few years +https://github.com/dwyl/learn-tachyons + + + +Design System for Building Semantic Compiled UI + ++ GitHub: +https://github.com/mdgriffith/elm-ui ++ Elm Package: +https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/ + +## _What?_ + +`elm-ui` is to `HTML` and `CSS` +what `elm` is to `JavaScript`. +`elm-ui` offers compile-time guarantees that your layout and styles. + + +## _How?_ + +In a new directory, initialise your `elm` workflow with the following command: +```sh +elm init +``` + +That will create an `elm.json` file similar to this one: +[`elm.json`]() + +Next we will add the dependency for `mdgriffith/elm-ui`: +```sh +elm install mdgriffith/elm-ui +``` +> **Note**: that command will only add an entry +in the `elm.json` `"dependencies"` section. +`elm install` does not actually _install_ anything. + + +### Debugging Layout with `Element.explain Debug.todo` + + +## References and Recommended Reading + ++ `elm-ui` _examples_: https://github.com/bburdette/elm-ui-examples ++ From 9be5d14c1258f46ba604218a4bb4f2800c8df330 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Tue, 10 Dec 2019 21:06:25 +0000 Subject: [PATCH 05/50] add initial elm-ui example code for #145 --- tutorials/elm-ui/src/Main.elm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tutorials/elm-ui/src/Main.elm diff --git a/tutorials/elm-ui/src/Main.elm b/tutorials/elm-ui/src/Main.elm new file mode 100644 index 0000000..58db2c7 --- /dev/null +++ b/tutorials/elm-ui/src/Main.elm @@ -0,0 +1,31 @@ +module Main exposing (main) + +import Element exposing (Element, alignRight, centerX, centerY, el, fill, padding, rgb255, row, spacing, text, width) +import Element.Background as Background +import Element.Border as Border +import Element.Font as Font + + +main = + Element.layout [] + myRowOfStuff + + +myRowOfStuff : Element msg +myRowOfStuff = + row [ width fill, centerY, spacing 30 ] + [ myElement + , el [ centerX ] myElement + , el [ alignRight, padding ] myElement -- align the element to the right + ] + + +myElement : Element msg +myElement = + el + [ Background.color (rgb255 240 0 245) + , Font.color (rgb255 255 255 255) + , Border.rounded 3 + , padding 30 + ] + (text "stylish!") From 1558527a270ca2fae2af44909641f4f0700f61e2 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Tue, 10 Dec 2019 21:07:33 +0000 Subject: [PATCH 06/50] create .gitignore file to avoid adding (generated) index.html file to GH --- tutorials/elm-ui/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 tutorials/elm-ui/.gitignore diff --git a/tutorials/elm-ui/.gitignore b/tutorials/elm-ui/.gitignore new file mode 100644 index 0000000..dcaf716 --- /dev/null +++ b/tutorials/elm-ui/.gitignore @@ -0,0 +1 @@ +index.html From 186af6b9dcf3a3bc858cd4482e9c89e7ef65eb3f Mon Sep 17 00:00:00 2001 From: nelsonic Date: Tue, 10 Dec 2019 21:08:05 +0000 Subject: [PATCH 07/50] add mdgriffith/elm-ui to elm.json for #145 --- tutorials/elm-ui/elm.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tutorials/elm-ui/elm.json b/tutorials/elm-ui/elm.json index a8e90d9..d8dd590 100644 --- a/tutorials/elm-ui/elm.json +++ b/tutorials/elm-ui/elm.json @@ -8,7 +8,8 @@ "direct": { "elm/browser": "1.0.2", "elm/core": "1.0.4", - "elm/html": "1.0.0" + "elm/html": "1.0.0", + "mdgriffith/elm-ui": "1.1.5" }, "indirect": { "elm/json": "1.1.3", From fd932d6ceeba02d99ce6407f3063e3b2e0b7caf1 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Tue, 10 Dec 2019 21:51:42 +0000 Subject: [PATCH 08/50] add link to "Building a Toolkit for Design" by Matthew Griffith video https://youtu.be/Ie-gqwSHQr0 #145 --- tutorials/elm-ui/README.md | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/tutorials/elm-ui/README.md b/tutorials/elm-ui/README.md index 5d0619e..9a7e089 100644 --- a/tutorials/elm-ui/README.md +++ b/tutorials/elm-ui/README.md @@ -3,6 +3,7 @@ ## _Why?_ 😢 `|>` 😍 + People who are learning `CSS` (_or those who are too impatient to learn and just want it to "work now"!_), often end up feeling like `CSS` is a wild beast that cannot be tamed. @@ -35,18 +36,18 @@ duplicate and _conflicting_ styles will be added. Take any popular website and run it through CSS Stats https://cssstats.com to see how many styles are being used. -A good example is [Twitter.com](https://twitter.com) -Their CSS is **632kb** +A good example is [Twitter.com](https://twitter.com). +Their CSS is **632KB** (_or **113KB** when compressed+gzipped_). ![twitter-css-stats](https://user-images.githubusercontent.com/194400/70567485-f56b2580-1b8d-11ea-94c4-4e2ca8b5cd10.png) That might not sound like a lot, -but scroll down to the part that says **1024 total color declarations**: +but scroll down to the section that says **1024 total color declarations**: ![twitter-css-stats-colors](https://user-images.githubusercontent.com/194400/70567583-1df31f80-1b8e-11ea-99d2-0c78a6f88a5d.png) Can you tell the difference between those shades of grey, blue and _white_?? -The point is that the developers/designers at Twitter - a tech company +The point is: developers/designers at Twitter - a tech company with **billions** in revenue and some of the most talented people - do not have _control_ over their CSS. @@ -62,15 +63,15 @@ And yet twitter, which has a _great_ in-house design team with their own _system_ and component library, have managed to build a - - The problem isn't you, the problem is the (_lack of a_) _system_. - @dwyl we _love_ the idea of having semantic and functional UIs with no side-effects. Functional CSS allows you to change one style -without affecting any others. For the past few years -https://github.com/dwyl/learn-tachyons +without affecting any others. +For the past few years we have been using Tachyons +see: https://github.com/dwyl/learn-tachyons +It's been _good_ in small-ish teams (_max 8 people_), + @@ -87,6 +88,13 @@ https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/ what `elm` is to `JavaScript`. `elm-ui` offers compile-time guarantees that your layout and styles. +> "_It's all right there. +There's no other place you have to go to modify this thing_." +> + +[![elm-ui-tookit-for-design](https://user-images.githubusercontent.com/194400/70571846-7c240080-1b96-11ea-9dd2-cacae7110b54.png)](https://youtu.be/Ie-gqwSHQr0) +https://youtu.be/Ie-gqwSHQr0 + ## _How?_ @@ -109,6 +117,9 @@ in the `elm.json` `"dependencies"` section. ### Debugging Layout with `Element.explain Debug.todo` +[Debug] +https://package.elm-lang.org/packages/elm-lang/core/3.0.0/Debug + ## References and Recommended Reading From e76afbb777beacb015101c10ccf432156edbc138 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Wed, 11 Dec 2019 14:22:35 +0000 Subject: [PATCH 09/50] re-org "Why Not" to end of page --- tutorials/elm-ui/README.md | 155 +++++++++++++++++++++---------------- 1 file changed, 87 insertions(+), 68 deletions(-) diff --git a/tutorials/elm-ui/README.md b/tutorials/elm-ui/README.md index 9a7e089..14481ee 100644 --- a/tutorials/elm-ui/README.md +++ b/tutorials/elm-ui/README.md @@ -3,72 +3,11 @@ ## _Why?_ 😢 `|>` 😍 - -People who are learning `CSS` -(_or those who are too impatient to learn and just want it to "work now"!_), -often end up feeling like `CSS` is a wild beast that cannot be tamed. - - - - -In reality, CSS _can_ be learned/mastered reasonably quickly -and _amazing_ things can be made e.g: -http://www.csszengarden.com and https://www.cssdesignawards.com - -Sadly, it doesn't matter how well -_you_ - the conscientious developer/designer - learn CSS. -Unless you can ensure that _everyone_ in your team/company -has the same level of skill and care in their work, -it's _inevitable_ that over-time -duplicate and _conflicting_ styles will be added. - - - -Take any popular website and run it through CSS Stats https://cssstats.com -to see how many styles are being used. -A good example is [Twitter.com](https://twitter.com). -Their CSS is **632KB** (_or **113KB** when compressed+gzipped_). - -![twitter-css-stats](https://user-images.githubusercontent.com/194400/70567485-f56b2580-1b8d-11ea-94c4-4e2ca8b5cd10.png) - -That might not sound like a lot, -but scroll down to the section that says **1024 total color declarations**: - -![twitter-css-stats-colors](https://user-images.githubusercontent.com/194400/70567583-1df31f80-1b8e-11ea-99d2-0c78a6f88a5d.png) - -Can you tell the difference between those shades of grey, blue and _white_?? -The point is: developers/designers at Twitter - a tech company -with **billions** in revenue and some of the most talented people - -do not have _control_ over their CSS. - -> Twitter are the creators of Bootstrap -"_the most popular front-end framework in the world_". -**Bootstrap `v4`** is **123kb** (_uncompressed_) -and **23kb** (_compressed+gzipped_). -The _whole_ library including grid layout, -typography, colors, all compontents, forms and utilities. -Bootstrap is meant to be a _complete_ responsive grid-based design system -that _anyone_ can use to build their App/website. -And yet twitter, which has a _great_ in-house design team -with their own _system_ and component library, -have managed to build a - -The problem isn't you, the problem is the (_lack of a_) _system_. - @dwyl we _love_ the idea of having semantic and functional UIs -with no side-effects. Functional CSS allows you to change one style +with no side-effects. Functional CSS allows anyone +to change _one_ style on a single element without affecting any others. -For the past few years we have been using Tachyons +For the past few years we have been using the Tachyons library see: https://github.com/dwyl/learn-tachyons It's been _good_ in small-ish teams (_max 8 people_), @@ -86,15 +25,18 @@ https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/ `elm-ui` is to `HTML` and `CSS` what `elm` is to `JavaScript`. -`elm-ui` offers compile-time guarantees that your layout and styles. +`elm-ui` offers compile-time guarantees +that your layout and styles work as expected. -> "_It's all right there. -There's no other place you have to go to modify this thing_." -> +Matthew Griffith described it eloquently in his Elm Conf talk +"Building a Toolkit for Design": [![elm-ui-tookit-for-design](https://user-images.githubusercontent.com/194400/70571846-7c240080-1b96-11ea-9dd2-cacae7110b54.png)](https://youtu.be/Ie-gqwSHQr0) https://youtu.be/Ie-gqwSHQr0 +> "_It's all right there. +There's no other place you have to go to modify this thing_." + ## _How?_ @@ -125,3 +67,80 @@ https://package.elm-lang.org/packages/elm-lang/core/3.0.0/Debug + `elm-ui` _examples_: https://github.com/bburdette/elm-ui-examples + + + +
+ +## _Why NOT Just Use CSS_? + + +People who are learning `CSS` +(_or those who are too impatient to learn and just want it to "work now"!_), +often end up feeling like `CSS` is a wild beast that cannot be tamed. +There's a _reason_ why searching for +["CSS gif"](https://www.google.com/search?q=css+gif&tbm=isch) +returns this mess as the top result: + + + +In reality, CSS _can_ be learned/mastered reasonably quickly +and _amazing_ things can be crafted.
+e.g: +http://www.csszengarden.com and https://www.cssdesignawards.com
+ +Sadly, it doesn't matter how well +_you_ - the conscientious developer/designer - learn CSS. +Unless you can ensure that _everyone_ in your team/company +has the same level of skill and care in their work, +it's _inevitable_ that over-time +duplicate and _conflicting_ styles will be added. + + + +Take any popular website and run it through CSS Stats https://cssstats.com +to see how many styles are being used. +A good example is +[Twitter.com](https://cssstats.com/stats?url=https%3A%2F%2Ftwitter.com). +Their CSS is **632KB** (_or **113KB** when compressed+gzipped_). +https://cssstats.com/stats?url=https%3A%2F%2Ftwitter.com + +![twitter-css-stats](https://user-images.githubusercontent.com/194400/70567485-f56b2580-1b8d-11ea-94c4-4e2ca8b5cd10.png) + +That might not sound like a lot, +but for context **632KB** is enough to write a 100k+ word novel. +The point is: the developers/designers at Twitter - a tech company +with **billions** in revenue and some of the most talented people - +have _lost control_ over their CSS. + +> **Twitter** created **Bootstrap** +"_the most popular front-end framework in the world_". +**Bootstrap `v4`** is **123kb** (_uncompressed_) +and **23kb** (_compressed+gzipped_); +the _whole_ library including grid layout, +typography, colors, all components, forms and utilities. +Bootstrap is meant to be a _complete_ responsive grid-based design system +that _anyone_ can use to build their App/website. +And yet twitter, which has a _great_ in-house design team +with their own _system_ and component library, +have managed to create a **CSS monster** +that is **5 times** the size of all of **Bootstrap**. +Even if they had **20kb** of colors, +that's enough for 256 colors, it would still be less than **150kb**. + + +The problem isn't you, +or "other people", +the problem is the (_lack of a_) _system_. +If the _system_ you are using to create your layout/styles +does not give you any consistency guarantees at compilation time, +then you don't _have_ a good enough system and chaos is _guaranteed_. From 1ed0390ee2874cbd3e643c35fe38591853bff174 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Wed, 11 Dec 2019 21:42:15 +0000 Subject: [PATCH 10/50] add examples of errors for elm-ui "What?" section #145 --- tutorials/elm-ui/README.md | 56 ++++++++++++++++++++++++++--------- tutorials/elm-ui/src/Main.elm | 4 +-- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/tutorials/elm-ui/README.md b/tutorials/elm-ui/README.md index 14481ee..ebd6e84 100644 --- a/tutorials/elm-ui/README.md +++ b/tutorials/elm-ui/README.md @@ -1,7 +1,7 @@ # `elm-ui` a Language for Layout and Interface -## _Why?_ 😢 `|>` 😍 +## _Why?_ 🤷 ... 😢 🌧 `|>` 😍🌈 @dwyl we _love_ the idea of having semantic and functional UIs with no side-effects. Functional CSS allows anyone @@ -9,24 +9,39 @@ to change _one_ style on a single element without affecting any others. For the past few years we have been using the Tachyons library see: https://github.com/dwyl/learn-tachyons -It's been _good_ in small-ish teams (_max 8 people_), +Using Tachyons in dosens of projects +has been _good_ in small teams (_max 8 people_). +However we have found that even with a functional CSS library +(_that greatly reduces the possibility of cascading side effects_), +we still see redundant and unnecessary styles +and occasionally visual bugs are introduced that go undetected. +No CSS library we know of offers compile-time guarantees +that the layout/styles applied to a given element are _correct_. +That's where `elm-ui` comes in and changes the game! +## _What?_ 💭 - -Design System for Building Semantic Compiled UI - -+ GitHub: -https://github.com/mdgriffith/elm-ui -+ Elm Package: -https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/ - -## _What?_ +`elm-ui` is a design system +for building semantic UI +with compile-time guarantees. `elm-ui` is to `HTML` and `CSS` -what `elm` is to `JavaScript`. +what `elm` is to `JavaScript`, +a way of making designing web applications fun again! `elm-ui` offers compile-time guarantees that your layout and styles work as expected. +You will see _helpful_ compiler errors/warnings +if you attempt to make a _breaking_ change to UI! +e.g: + +In this case I have attempted to apply a `Float` of 2.5 to the `Border.rounded` (`border-radius`) property: +![image](https://user-images.githubusercontent.com/194400/70662062-69283380-1c5d-11ea-8d90-1d4f72d67ec6.png) + +The same thing goes if I attempt to pass a `String` to `Border.rounded` e.g: `"2px"` +![image](https://user-images.githubusercontent.com/194400/70662334-ec498980-1c5d-11ea-9336-56f30db80270.png) +I get a type mismatch. + Matthew Griffith described it eloquently in his Elm Conf talk "Building a Toolkit for Design": @@ -38,6 +53,11 @@ https://youtu.be/Ie-gqwSHQr0 There's no other place you have to go to modify this thing_." ++ GitHub: +https://github.com/mdgriffith/elm-ui ++ Elm Package: +https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest + ## _How?_ In a new directory, initialise your `elm` workflow with the following command: @@ -57,6 +77,13 @@ in the `elm.json` `"dependencies"` section. `elm install` does not actually _install_ anything. + +### Drawbacks + + +`Colors` have to be specified + + ### Debugging Layout with `Element.explain Debug.todo` [Debug] @@ -66,10 +93,11 @@ https://package.elm-lang.org/packages/elm-lang/core/3.0.0/Debug ## References and Recommended Reading + `elm-ui` _examples_: https://github.com/bburdette/elm-ui-examples -+ ++ Style framework (_built on `elm-ui`_): +https://github.com/lucamug/style-framework -
+

## _Why NOT Just Use CSS_? diff --git a/tutorials/elm-ui/src/Main.elm b/tutorials/elm-ui/src/Main.elm index 58db2c7..1c19711 100644 --- a/tutorials/elm-ui/src/Main.elm +++ b/tutorials/elm-ui/src/Main.elm @@ -16,7 +16,7 @@ myRowOfStuff = row [ width fill, centerY, spacing 30 ] [ myElement , el [ centerX ] myElement - , el [ alignRight, padding ] myElement -- align the element to the right + , el [ alignRight ] myElement -- align the element to the right ] @@ -25,7 +25,7 @@ myElement = el [ Background.color (rgb255 240 0 245) , Font.color (rgb255 255 255 255) - , Border.rounded 3 + , Border.rounded 10 , padding 30 ] (text "stylish!") From aef3a97aaeb2c3992eeb5decc2c29b465563b402 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Wed, 11 Dec 2019 22:16:03 +0000 Subject: [PATCH 11/50] add sample code for elm-ui #145 --- tutorials/elm-ui/README.md | 79 +++++++++++++++++++++++++++++++---- tutorials/elm-ui/src/Main.elm | 10 ++--- 2 files changed, 77 insertions(+), 12 deletions(-) diff --git a/tutorials/elm-ui/README.md b/tutorials/elm-ui/README.md index ebd6e84..b1d9b43 100644 --- a/tutorials/elm-ui/README.md +++ b/tutorials/elm-ui/README.md @@ -26,6 +26,11 @@ That's where `elm-ui` comes in and changes the game! for building semantic UI with compile-time guarantees. ++ GitHub: +https://github.com/mdgriffith/elm-ui ++ Elm Package: +https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest + `elm-ui` is to `HTML` and `CSS` what `elm` is to `JavaScript`, a way of making designing web applications fun again! @@ -40,7 +45,8 @@ In this case I have attempted to apply a `Float` of 2.5 to the `Border.rounded` The same thing goes if I attempt to pass a `String` to `Border.rounded` e.g: `"2px"` ![image](https://user-images.githubusercontent.com/194400/70662334-ec498980-1c5d-11ea-9336-56f30db80270.png) -I get a type mismatch. +We get a type mismatch and know _exactly_ what needs to be fixed +in order for our view to compile. Matthew Griffith described it eloquently in his Elm Conf talk @@ -53,11 +59,6 @@ https://youtu.be/Ie-gqwSHQr0 There's no other place you have to go to modify this thing_." -+ GitHub: -https://github.com/mdgriffith/elm-ui -+ Elm Package: -https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest - ## _How?_ In a new directory, initialise your `elm` workflow with the following command: @@ -77,11 +78,75 @@ in the `elm.json` `"dependencies"` section. `elm install` does not actually _install_ anything. +Now create a directory called `src` +and a new file in the directory `src/Main.elm`. +Next _type_ (_or copy-paste_) the following code into the `src/Main.elm` file: + +```elm +module Main exposing (main) + +import Element exposing (Element, alignRight, centerX, centerY, el, fill, rgb255, row, spacing, text, width) +import Element.Background as Background +import Element.Border as Border +import Element.Font as Font + + +main = + Element.layout [] + rowOfStuff + + +rowOfStuff : Element msg +rowOfStuff = + row [ width fill, centerY, spacing 30 ] + [ myElement + , el [ centerX ] myElement + , el [ alignRight ] myElement -- align the element to the right + ] + + +myElement : Element msg +myElement = + el + [ Background.color (rgb255 75 192 169) + , Font.color (rgb255 255 255 255) + , Border.rounded 10 + , padding 30 + ] + (text "stylish!") + +``` + +In your terminal run: +``` +elm reactor +``` +Open the following page in your web browser: +http://localhost:8000/src/Main.elm + +You should expect to see: + +![elm-ui-basic-layout](https://user-images.githubusercontent.com/194400/70663573-90cccb00-1c60-11ea-8a1c-71d15d2b83ad.png) + + + + +
### Drawbacks +`Colors` have to be specified in terms of **rgb** values. +i.e. you need to supply the individual values for `Red` `Blue` `Green` as `Int`. + +If I attempt to invoke `rgb255 75, 192, 169` I will see the following error: + +![elm-ui-rgb-error](https://user-images.githubusercontent.com/194400/70663222-cfae5100-1c5f-11ea-8fa6-6d4437e3af14.png) + +This is a _small_ price to pay given that it allows us to _easily_ +implement a color picker allowing people to easily select _any_ color +when they are [_categorising_](https://github.com/dwyl/app/issues/235) -`Colors` have to be specified +![color-picker-dwyl-teal](https://user-images.githubusercontent.com/194400/70664979-72b49a00-1c63-11ea-80f4-fc533948f60f.png) ### Debugging Layout with `Element.explain Debug.todo` diff --git a/tutorials/elm-ui/src/Main.elm b/tutorials/elm-ui/src/Main.elm index 1c19711..77398e7 100644 --- a/tutorials/elm-ui/src/Main.elm +++ b/tutorials/elm-ui/src/Main.elm @@ -1,6 +1,6 @@ module Main exposing (main) -import Element exposing (Element, alignRight, centerX, centerY, el, fill, padding, rgb255, row, spacing, text, width) +import Element exposing (Element, alignRight, centerX, centerY, el, fill, rgb255, row, spacing, text, width) import Element.Background as Background import Element.Border as Border import Element.Font as Font @@ -8,11 +8,11 @@ import Element.Font as Font main = Element.layout [] - myRowOfStuff + rowOfStuff -myRowOfStuff : Element msg -myRowOfStuff = +rowOfStuff : Element msg +rowOfStuff = row [ width fill, centerY, spacing 30 ] [ myElement , el [ centerX ] myElement @@ -23,7 +23,7 @@ myRowOfStuff = myElement : Element msg myElement = el - [ Background.color (rgb255 240 0 245) + [ Background.color (rgb255 75 192 169) , Font.color (rgb255 255 255 255) , Border.rounded 10 , padding 30 From fd978f4bc4a8849ef3bbc33134cd8c8a4f146696 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Wed, 11 Dec 2019 22:26:14 +0000 Subject: [PATCH 12/50] add instructions for converting hex to rgb (required for elm-ui) #145 --- tutorials/elm-ui/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tutorials/elm-ui/README.md b/tutorials/elm-ui/README.md index b1d9b43..a313773 100644 --- a/tutorials/elm-ui/README.md +++ b/tutorials/elm-ui/README.md @@ -118,9 +118,11 @@ myElement = ``` In your terminal run: + ``` elm reactor ``` + Open the following page in your web browser: http://localhost:8000/src/Main.elm @@ -148,6 +150,14 @@ when they are [_categorising_](https://github.com/dwyl/app/issues/235) ![color-picker-dwyl-teal](https://user-images.githubusercontent.com/194400/70664979-72b49a00-1c63-11ea-80f4-fc533948f60f.png) +In the short-term if we have a _hex_ value e.g: `#4bc0a9` +that we need to convert to RGB, +~~simply use a free online tool: +https://www.rapidtables.com/convert/color/hex-to-rgb.html~~ +pasting the _hex_ into google returns the RGB conversion. +e.g: https://www.google.com/search?q=%234bc0a9 + + ### Debugging Layout with `Element.explain Debug.todo` From 03023b2d39010fa7540bc2f894959af9463c8667 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Wed, 11 Dec 2019 22:46:50 +0000 Subject: [PATCH 13/50] add more examples of compilation errors typo: paddign > padding #145 --- tutorials/elm-ui/README.md | 36 ++++++++++++++++++++++------------- tutorials/elm-ui/src/Main.elm | 4 ++-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/tutorials/elm-ui/README.md b/tutorials/elm-ui/README.md index a313773..0c2141d 100644 --- a/tutorials/elm-ui/README.md +++ b/tutorials/elm-ui/README.md @@ -1,4 +1,4 @@ -# `elm-ui` a Language for Layout and Interface +# `elm-ui` a Language for _Reliable_ Layout and Interface ## _Why?_ 🤷 ... 😢 🌧 `|>` 😍🌈 @@ -31,6 +31,16 @@ https://github.com/mdgriffith/elm-ui + Elm Package: https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest +Matthew Griffith described it eloquently in his Elm Conf talk +"Building a Toolkit for Design": + +[![elm-ui-tookit-for-design](https://user-images.githubusercontent.com/194400/70571846-7c240080-1b96-11ea-9dd2-cacae7110b54.png)](https://youtu.be/Ie-gqwSHQr0) +https://youtu.be/Ie-gqwSHQr0 + +> "_It's all right there. +There's no other place you have to go to modify this thing_." + + `elm-ui` is to `HTML` and `CSS` what `elm` is to `JavaScript`, a way of making designing web applications fun again! @@ -38,7 +48,8 @@ a way of making designing web applications fun again! that your layout and styles work as expected. You will see _helpful_ compiler errors/warnings if you attempt to make a _breaking_ change to UI! -e.g: + +Consider the following examples: In this case I have attempted to apply a `Float` of 2.5 to the `Border.rounded` (`border-radius`) property: ![image](https://user-images.githubusercontent.com/194400/70662062-69283380-1c5d-11ea-8d90-1d4f72d67ec6.png) @@ -48,18 +59,13 @@ The same thing goes if I attempt to pass a `String` to `Border.rounded` e.g: `"2 We get a type mismatch and know _exactly_ what needs to be fixed in order for our view to compile. +If you make a typo in your layout/style it's won't compile: -Matthew Griffith described it eloquently in his Elm Conf talk -"Building a Toolkit for Design": +![elm-ui-paddign-error](https://user-images.githubusercontent.com/194400/70667023-caed9b00-1c67-11ea-8396-0bf47d87a7d0.png) -[![elm-ui-tookit-for-design](https://user-images.githubusercontent.com/194400/70571846-7c240080-1b96-11ea-9dd2-cacae7110b54.png)](https://youtu.be/Ie-gqwSHQr0) -https://youtu.be/Ie-gqwSHQr0 - -> "_It's all right there. -There's no other place you have to go to modify this thing_." -## _How?_ +## _How?_ 📝 In a new directory, initialise your `elm` workflow with the following command: ```sh @@ -85,7 +91,7 @@ Next _type_ (_or copy-paste_) the following code into the `src/Main.elm` file: ```elm module Main exposing (main) -import Element exposing (Element, alignRight, centerX, centerY, el, fill, rgb255, row, spacing, text, width) +import Element exposing (Element, alignRight, centerX, centerY, el, fill, padding, rgb255, row, spacing, text, width) import Element.Background as Background import Element.Border as Border import Element.Font as Font @@ -114,9 +120,13 @@ myElement = , padding 30 ] (text "stylish!") - ``` +> This is the canonical example in the docs: +https://github.com/mdgriffith/elm-ui +If you are unable to run the code on your `localhost` +try the Ellie version: https://ellie-app.com/3f2n4J5RnT3a1 + In your terminal run: ``` @@ -174,7 +184,7 @@ https://github.com/lucamug/style-framework

-## _Why NOT Just Use CSS_? +## _Why NOT Just Use CSS_? 🤷 People who are learning `CSS` diff --git a/tutorials/elm-ui/src/Main.elm b/tutorials/elm-ui/src/Main.elm index 77398e7..f096357 100644 --- a/tutorials/elm-ui/src/Main.elm +++ b/tutorials/elm-ui/src/Main.elm @@ -1,6 +1,6 @@ module Main exposing (main) -import Element exposing (Element, alignRight, centerX, centerY, el, fill, rgb255, row, spacing, text, width) +import Element exposing (Element, alignRight, centerX, centerY, el, fill, padding, rgb255, row, spacing, text, width) import Element.Background as Background import Element.Border as Border import Element.Font as Font @@ -26,6 +26,6 @@ myElement = [ Background.color (rgb255 75 192 169) , Font.color (rgb255 255 255 255) , Border.rounded 10 - , padding 30 + , paddign 30 ] (text "stylish!") From d754300961c7a8f8020eca1029a56d292286240f Mon Sep 17 00:00:00 2001 From: nelsonic Date: Wed, 11 Dec 2019 23:43:59 +0000 Subject: [PATCH 14/50] suggest an alternative scoped import to reduce line length for elm-ui #145 --- tutorials/elm-ui/README.md | 109 +++++++++++++++++++++++++++++++++- tutorials/elm-ui/src/Main.elm | 18 +++--- 2 files changed, 116 insertions(+), 11 deletions(-) diff --git a/tutorials/elm-ui/README.md b/tutorials/elm-ui/README.md index 0c2141d..552e5af 100644 --- a/tutorials/elm-ui/README.md +++ b/tutorials/elm-ui/README.md @@ -107,7 +107,7 @@ rowOfStuff = row [ width fill, centerY, spacing 30 ] [ myElement , el [ centerX ] myElement - , el [ alignRight ] myElement -- align the element to the right + , el [ alignRight ] myElement ] @@ -140,15 +140,120 @@ You should expect to see: ![elm-ui-basic-layout](https://user-images.githubusercontent.com/194400/70663573-90cccb00-1c60-11ea-8a1c-71d15d2b83ad.png) +Let's break down this code section by section: + +The first line is the standard `Elm` module (export) directive. +```elm +module Main exposing (main) +``` + +The next section are the imports: +```elm +import Element exposing (Element, alignRight, centerX, centerY, el, fill, padding, rgb255, row, spacing, text, width) +import Element.Background as Background +import Element.Border as Border +import Element.Font as Font +``` +These are fairly standard scoped `elm` import statements. + +We are covering 4 out of 9 of the available `elm-ui` modules. +The one with the most features/functions is +[`Elemenent`](https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/Element) +which contains everything you need for creating standard HTML elements +including their layout and positioning. +[`Background`](https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/Element-Background), +[`Border`](https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/Element-Border) +and +[`Font`](https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/Element-Font) +are _exactly_ what you would expect them to be. + + + + +A note on long import lines: +if you attempt to split the `import Element` declaration into two lines: +```elm +import Element exposing (Element, alignRight, centerX, centerY, el, fill) +import Element exposing (padding, rgb255, row, spacing, text, width) +``` +`elm-format` will re-format the two lines into one again ... we tried ... 🙄 + +The way to get around this is to follow the +[`elm` guide modules](https://guide.elm-lang.org/webapps/modules.html) +advice and avoid using `exposing` unless it's absolutely necessary. +So we can convert the super-long import +(_which will only get longer as your view expands to include more style_): + +From: + +```elm +import Element exposing (Element, alignRight, centerX, centerY, el, fill, padding, rgb255, row, spacing, text, width) +``` + +To: + +```elm +import Element as E exposing (Element, el, row) +``` +This only makes the top level elements `el` and `row` available +for use in our view functions. The rest of the `elm-ui` functions +need to be prefixed with `E` e.g: `E.functionName` + + +The _full_ revised code would be: + +```elm +module Main exposing (main) + +import Element exposing (Element, alignRight, centerX, centerY, el, fill, padding, rgb255, row, spacing, text, width) +import Element.Background as Background +import Element.Border as Border +import Element.Font as Font + + +main = + Element.layout [] + rowOfStuff + + +rowOfStuff : Element msg +rowOfStuff = + row [ width fill, centerY, spacing 30 ] + [ myElement + , el [ centerX ] myElement + , el [ alignRight ] myElement -- align the element to the right + ] + + +myElement : Element msg +myElement = + el + [ Background.color (rgb255 75 192 169) + , Font.color (rgb255 255 255 255) + , Border.rounded 10 + , paddign 30 + ] + (E.text "stylish!") +``` + +Some people might feel that this is more to type. +However it's _immediately_ clear where a given function "comes from" +and there is a much lower risk of naming conflicts. +E.g. you might have a _dynamic_ (_or "responsive"_) view function +that changes depending on the `width` of the viewport (_screen_). -
+

### Drawbacks `Colors` have to be specified in terms of **rgb** values. i.e. you need to supply the individual values for `Red` `Blue` `Green` as `Int`. +e.g: +```elm +Background.color (rgb255 75 192 169) +``` If I attempt to invoke `rgb255 75, 192, 169` I will see the following error: diff --git a/tutorials/elm-ui/src/Main.elm b/tutorials/elm-ui/src/Main.elm index f096357..f104197 100644 --- a/tutorials/elm-ui/src/Main.elm +++ b/tutorials/elm-ui/src/Main.elm @@ -1,31 +1,31 @@ module Main exposing (main) -import Element exposing (Element, alignRight, centerX, centerY, el, fill, padding, rgb255, row, spacing, text, width) +import Element as E exposing (Element, el, row) import Element.Background as Background import Element.Border as Border import Element.Font as Font main = - Element.layout [] + E.layout [] rowOfStuff rowOfStuff : Element msg rowOfStuff = - row [ width fill, centerY, spacing 30 ] + row [ E.width E.fill, E.centerY, E.spacing 30 ] [ myElement - , el [ centerX ] myElement - , el [ alignRight ] myElement -- align the element to the right + , el [ E.centerX ] myElement + , el [ E.alignRight ] myElement ] myElement : Element msg myElement = el - [ Background.color (rgb255 75 192 169) - , Font.color (rgb255 255 255 255) + [ Background.color (E.rgb255 75 192 169) + , Font.color (E.rgb255 255 255 255) , Border.rounded 10 - , paddign 30 + , E.padding 30 ] - (text "stylish!") + (E.text "stylish!") From 31065a1e58124fddc8c38cf51312b26a9a04d53c Mon Sep 17 00:00:00 2001 From: nelsonic Date: Wed, 11 Dec 2019 23:55:04 +0000 Subject: [PATCH 15/50] update example of scoped import for elm-ui example/tutorial #145 --- tutorials/elm-ui/README.md | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/tutorials/elm-ui/README.md b/tutorials/elm-ui/README.md index 552e5af..7a67b41 100644 --- a/tutorials/elm-ui/README.md +++ b/tutorials/elm-ui/README.md @@ -198,6 +198,10 @@ import Element as E exposing (Element, el, row) This only makes the top level elements `el` and `row` available for use in our view functions. The rest of the `elm-ui` functions need to be prefixed with `E` e.g: `E.functionName` +Avoid using uncontrolled import statements +e.g: `import Element exposing (..)` at all cost. +They might be tempting in the short-run, +but they rapidly become an unmaintainable headache. The _full_ revised code would be: @@ -205,42 +209,56 @@ The _full_ revised code would be: ```elm module Main exposing (main) -import Element exposing (Element, alignRight, centerX, centerY, el, fill, padding, rgb255, row, spacing, text, width) +import Element as E exposing (Element, el, row) import Element.Background as Background import Element.Border as Border import Element.Font as Font main = - Element.layout [] + E.layout [] rowOfStuff rowOfStuff : Element msg rowOfStuff = - row [ width fill, centerY, spacing 30 ] + row [ E.width E.fill, E.centerY, E.spacing 30 ] [ myElement - , el [ centerX ] myElement - , el [ alignRight ] myElement -- align the element to the right + , el [ E.centerX ] myElement + , el [ E.alignRight ] myElement ] myElement : Element msg myElement = el - [ Background.color (rgb255 75 192 169) - , Font.color (rgb255 255 255 255) + [ Background.color (E.rgb255 75 192 169) + , Font.color (E.rgb255 255 255 255) , Border.rounded 10 - , paddign 30 + , E.padding 30 ] (E.text "stylish!") ``` -Some people might feel that this is more to type. +Some people might feel that this tedious because it's more to type. However it's _immediately_ clear where a given function "comes from" and there is a much lower risk of naming conflicts. -E.g. you might have a _dynamic_ (_or "responsive"_) view function + +Consider the following scenario: +Your App has a _dynamic_ (_or "responsive"_) navigation view function that changes depending on the `width` of the viewport (_screen_). +The signature of the function might be something like this: + +```elm +nav : Int -> Html Msg +nav width = + if width > 600 then + E.row [ E.] + else + + + +``` From c372a1ef404058b86cea0cf1836ef009392ad798 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Wed, 11 Dec 2019 23:59:40 +0000 Subject: [PATCH 16/50] must return to view width example after constructing sample App layout --- tutorials/elm-ui/README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tutorials/elm-ui/README.md b/tutorials/elm-ui/README.md index 7a67b41..ac0a17b 100644 --- a/tutorials/elm-ui/README.md +++ b/tutorials/elm-ui/README.md @@ -253,11 +253,9 @@ The signature of the function might be something like this: nav : Int -> Html Msg nav width = if width > 600 then - E.row [ E.] + E.row [ E.width E.fill] else - - - + -- something else ``` From 856c68c99494b409efdd0ea8de18c002e31fddfe Mon Sep 17 00:00:00 2001 From: nelsonic Date: Thu, 12 Dec 2019 19:50:27 +0000 Subject: [PATCH 17/50] add padding and background to row element in elm-ui tutorial #145 --- tutorials/elm-ui/src/Main.elm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tutorials/elm-ui/src/Main.elm b/tutorials/elm-ui/src/Main.elm index f104197..abd61ba 100644 --- a/tutorials/elm-ui/src/Main.elm +++ b/tutorials/elm-ui/src/Main.elm @@ -13,7 +13,12 @@ main = rowOfStuff : Element msg rowOfStuff = - row [ E.width E.fill, E.centerY, E.spacing 30 ] + row + [ E.width E.fill + , E.centerY + , E.paddingXY 42 10 + , Background.color (E.rgb255 215 219 218) + ] [ myElement , el [ E.centerX ] myElement , el [ E.alignRight ] myElement From 8440a1f2dc695c809c5fa3775f062abbe2556bb6 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Thu, 12 Dec 2019 19:50:50 +0000 Subject: [PATCH 18/50] comment out nav example in elm-ui #145 --- tutorials/elm-ui/README.md | 51 +++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/tutorials/elm-ui/README.md b/tutorials/elm-ui/README.md index ac0a17b..32c504d 100644 --- a/tutorials/elm-ui/README.md +++ b/tutorials/elm-ui/README.md @@ -38,7 +38,7 @@ Matthew Griffith described it eloquently in his Elm Conf talk https://youtu.be/Ie-gqwSHQr0 > "_It's all right there. -There's no other place you have to go to modify this thing_." +There's no other place you have to go to modify this_." `elm-ui` is to `HTML` and `CSS` @@ -49,7 +49,7 @@ that your layout and styles work as expected. You will see _helpful_ compiler errors/warnings if you attempt to make a _breaking_ change to UI! -Consider the following examples: +### Example Compile Time Warnings In this case I have attempted to apply a `Float` of 2.5 to the `Border.rounded` (`border-radius`) property: ![image](https://user-images.githubusercontent.com/194400/70662062-69283380-1c5d-11ea-8d90-1d4f72d67ec6.png) @@ -63,6 +63,10 @@ If you make a typo in your layout/style it's won't compile: ![elm-ui-paddign-error](https://user-images.githubusercontent.com/194400/70667023-caed9b00-1c67-11ea-8396-0bf47d87a7d0.png) +Hopefully that gives you a _taste_ +for the compiler warnings provided by `elm-ui`. +The best way to experience this further +is to start ## _How?_ 📝 @@ -80,13 +84,15 @@ Next we will add the dependency for `mdgriffith/elm-ui`: elm install mdgriffith/elm-ui ``` > **Note**: that command will only add an entry -in the `elm.json` `"dependencies"` section. -`elm install` does not actually _install_ anything. +in the `elm.json` `"dependencies"` section.
+`elm install` does not actually _install_ anything +until you attempt to compile the app. Now create a directory called `src` and a new file in the directory `src/Main.elm`. -Next _type_ (_or copy-paste_) the following code into the `src/Main.elm` file: +Next _type_ (_or copy-paste_) the following code +into the `src/Main.elm` file: ```elm module Main exposing (main) @@ -197,10 +203,12 @@ import Element as E exposing (Element, el, row) ``` This only makes the top level elements `el` and `row` available for use in our view functions. The rest of the `elm-ui` functions -need to be prefixed with `E` e.g: `E.functionName` -Avoid using uncontrolled import statements -e.g: `import Element exposing (..)` at all cost. -They might be tempting in the short-run, +need to be prefixed with `E` e.g: `E.functionName`. +The advice from the creator of Elm +and other experienced Elm devs is: +avoid using uncontrolled import statements +e.g: `import Element exposing (..)`. +It might be tempting in the short-run to just "import everything", but they rapidly become an unmaintainable headache. @@ -244,6 +252,7 @@ Some people might feel that this tedious because it's more to type. However it's _immediately_ clear where a given function "comes from" and there is a much lower risk of naming conflicts. + + + + + + + + + + @@ -286,21 +306,24 @@ that we need to convert to RGB, ~~simply use a free online tool: https://www.rapidtables.com/convert/color/hex-to-rgb.html~~ pasting the _hex_ into google returns the RGB conversion. -e.g: https://www.google.com/search?q=%234bc0a9 - +e.g: https://www.google.com/search?q=%234bc0a9
+A color explorer site like Color Hexa has even more detail. +e.g: https://color-hex.org/color/4bc0a9 ### Debugging Layout with `Element.explain Debug.todo` -[Debug] -https://package.elm-lang.org/packages/elm-lang/core/3.0.0/Debug +[Debug](https://package.elm-lang.org/packages/elm-lang/core/3.0.0/Debug) +

## References and Recommended Reading + `elm-ui` _examples_: https://github.com/bburdette/elm-ui-examples + Style framework (_built on `elm-ui`_): https://github.com/lucamug/style-framework ++ Elm UI Explorer (Style Guide): +https://package.elm-lang.org/packages/kalutheo/elm-ui-explorer/4.0.0/

@@ -309,7 +332,7 @@ https://github.com/lucamug/style-framework People who are learning `CSS` -(_or those who are too impatient to learn and just want it to "work now"!_), +(_or those who are too impatient to learn and just want it to "work now!"_), often end up feeling like `CSS` is a wild beast that cannot be tamed. There's a _reason_ why searching for ["CSS gif"](https://www.google.com/search?q=css+gif&tbm=isch) From c836e28ea46532510068ad27ea7cac571199dd12 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Thu, 12 Dec 2019 23:16:53 +0000 Subject: [PATCH 19/50] add explanation of main function requirement in elm programs with screenshots --- tutorials/elm-ui/README.md | 143 +++++++++++++++++++++++++++++++--- tutorials/elm-ui/src/Main.elm | 23 +++--- 2 files changed, 140 insertions(+), 26 deletions(-) diff --git a/tutorials/elm-ui/README.md b/tutorials/elm-ui/README.md index 32c504d..eccc00b 100644 --- a/tutorials/elm-ui/README.md +++ b/tutorials/elm-ui/README.md @@ -146,6 +146,27 @@ You should expect to see: ![elm-ui-basic-layout](https://user-images.githubusercontent.com/194400/70663573-90cccb00-1c60-11ea-8a1c-71d15d2b83ad.png) +If you open the elements tab of Dev Tools in your browser +you will see the resulting HTML code: + +![generated-html](https://user-images.githubusercontent.com/194400/70760326-30fa2100-1d41-11ea-913d-d42fff663637.png) + +As far as generated HTML goes this is not too bad. + + + + Let's break down this code section by section: The first line is the standard `Elm` module (export) directive. @@ -160,9 +181,10 @@ import Element.Background as Background import Element.Border as Border import Element.Font as Font ``` -These are fairly standard scoped `elm` import statements. +These are fairly standard scoped `elm` `import` statements. -We are covering 4 out of 9 of the available `elm-ui` modules. +In this simple example we are using +4 out of 9 of the available `elm-ui` modules. The one with the most features/functions is [`Elemenent`](https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/Element) which contains everything you need for creating standard HTML elements @@ -171,12 +193,86 @@ including their layout and positioning. [`Border`](https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/Element-Border) and [`Font`](https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/Element-Font) -are _exactly_ what you would expect them to be. +are _exactly_ what you would expect them to be, +a collection functions related to styling those properties. +We will cover each of these in more detail later on as needed, +however I encourage you to click the links +and scroll through available functions +to get an idea for what they can do. + +#### The `main` function + +Let's continue looking at the 3 sections of code. +`main` assembles the rest of the code so it can be exposed +to the `elm` compiler. + + +```elm +main = + Element.layout [] + rowOfStuff +``` +This function creates an `Element.layout` + +#### Side Note on Naming Conventions + +Naming the entry point function `main` is not just a _convention_, +it's a compiler requirement. +If you try renaming `main` to something else in both places it appears, +your code won't compile. +You will see the following error message +in your browser (_running `elm reactor`_): + +![main-not-defined](https://user-images.githubusercontent.com/194400/70759502-8123b400-1d3e-11ea-8ee9-2c1751455a6d.png) + +And the following compiler warning if you attempt to compile it: + +![compiler-warning-no-main](https://user-images.githubusercontent.com/194400/70759831-8df4d780-1d3f-11ea-8369-b12108062f16.png) + +This is a _good_ thing, because it means all `elm` programs are consistent. +You won't see the `main` function of a program being named `app` or `myfunc` +which means there are fewer changes of confusion for beginners. + + + +#### + + +```elm +rowOfStuff : Element msg +rowOfStuff = + row [ width fill, centerY, spacing 30 ] + [ myElement + , el [ centerX ] myElement + , el [ alignRight ] myElement + ] +``` + -A note on long import lines: +```elm +myElement : Element msg +myElement = + el + [ Background.color (rgb255 75 192 169) + , Font.color (rgb255 255 255 255) + , Border.rounded 10 + , padding 30 + ] + (text "stylish!") +``` + + + + + + +



+ + +A quick note on long import lines: if you attempt to split the `import Element` declaration into two lines: ```elm import Element exposing (Element, alignRight, centerX, centerY, el, fill) @@ -201,12 +297,12 @@ To: ```elm import Element as E exposing (Element, el, row) ``` -This only makes the top level elements `el` and `row` available +This only makes the top level elements `el`, `layout` and `row` available for use in our view functions. The rest of the `elm-ui` functions need to be prefixed with `E` e.g: `E.functionName`. The advice from the creator of Elm and other experienced Elm devs is: -avoid using uncontrolled import statements +avoid using unqualified import statements e.g: `import Element exposing (..)`. It might be tempting in the short-run to just "import everything", but they rapidly become an unmaintainable headache. @@ -217,14 +313,14 @@ The _full_ revised code would be: ```elm module Main exposing (main) -import Element as E exposing (Element, el, row) +import Element as E exposing (Element, el, layout, row) import Element.Background as Background import Element.Border as Border import Element.Font as Font main = - E.layout [] + layout [] rowOfStuff @@ -252,6 +348,13 @@ Some people might feel that this tedious because it's more to type. However it's _immediately_ clear where a given function "comes from" and there is a much lower risk of naming conflicts. +We will be adopting this `E.` prefix approach +for the remainder of this tutorial +because it's the method recommended/used by Evan. + +> See "Using Modules" section at the end of: +https://guide.elm-lang.org/webapps/modules.html + +```elm +rowOfStuff : Element msg +rowOfStuff = + row + [ E.width E.fill + , E.centerY + , E.paddingXY 42 10 + , Background.color (E.rgb255 215 219 218) + ] + [ myElement + , el [ E.centerX ] myElement + , el [ E.alignRight ] myElement + ] +``` + + @@ -277,6 +396,10 @@ nav width = +### Debugging Layout with `Element.explain Debug.todo` + +[Debug](https://package.elm-lang.org/packages/elm-lang/core/3.0.0/Debug) + @@ -311,10 +434,6 @@ A color explorer site like Color Hexa has even more detail. e.g: https://color-hex.org/color/4bc0a9 -### Debugging Layout with `Element.explain Debug.todo` - -[Debug](https://package.elm-lang.org/packages/elm-lang/core/3.0.0/Debug) -

## References and Recommended Reading diff --git a/tutorials/elm-ui/src/Main.elm b/tutorials/elm-ui/src/Main.elm index abd61ba..bc7320b 100644 --- a/tutorials/elm-ui/src/Main.elm +++ b/tutorials/elm-ui/src/Main.elm @@ -1,36 +1,31 @@ module Main exposing (main) -import Element as E exposing (Element, el, row) +import Element exposing (Element, alignRight, centerX, centerY, el, fill, padding, rgb255, row, spacing, text, width) import Element.Background as Background import Element.Border as Border import Element.Font as Font main = - E.layout [] + Element.layout [] rowOfStuff rowOfStuff : Element msg rowOfStuff = - row - [ E.width E.fill - , E.centerY - , E.paddingXY 42 10 - , Background.color (E.rgb255 215 219 218) - ] + row [ width fill, centerY, spacing 30 ] [ myElement - , el [ E.centerX ] myElement - , el [ E.alignRight ] myElement + , el [ centerX ] myElement + , el [ alignRight ] myElement ] myElement : Element msg myElement = el - [ Background.color (E.rgb255 75 192 169) - , Font.color (E.rgb255 255 255 255) + [ Background.color (rgb255 75 192 169) + , Font.color (rgb255 255 255 255) , Border.rounded 10 - , E.padding 30 + , padding 30 ] - (E.text "stylish!") + (text "stylish!") From 01ede3b4b5749c5ddc05280809bc6f38b5d77cc8 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Fri, 13 Dec 2019 10:33:56 +0000 Subject: [PATCH 20/50] add explanation of row for #145 --- tutorials/elm-ui/README.md | 107 +++++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 10 deletions(-) diff --git a/tutorials/elm-ui/README.md b/tutorials/elm-ui/README.md index eccc00b..fd4bc4f 100644 --- a/tutorials/elm-ui/README.md +++ b/tutorials/elm-ui/README.md @@ -30,6 +30,8 @@ with compile-time guarantees. https://github.com/mdgriffith/elm-ui + Elm Package: https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest ++ Examples: +https://github.com/mdgriffith/elm-ui/tree/master/examples Matthew Griffith described it eloquently in his Elm Conf talk "Building a Toolkit for Design": @@ -149,9 +151,18 @@ You should expect to see: If you open the elements tab of Dev Tools in your browser you will see the resulting HTML code: -![generated-html](https://user-images.githubusercontent.com/194400/70760326-30fa2100-1d41-11ea-913d-d42fff663637.png) +![generated-html](https://user-images.githubusercontent.com/194400/70762204-b08aee80-1d47-11ea-9d5f-bd8e121a42d8.png) -As far as generated HTML goes this is not too bad. +As far as generated HTML goes this is not _too_ bad. +The in-line CSS classes are generated at compile time +and included in `