Compare commits
103 Commits
568ff3c1ee
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0af0129054 | ||
|
|
8ff2ec3766 | ||
|
|
843c71946f | ||
|
|
51e3629fa5 | ||
|
|
ddc003eb13 | ||
|
|
e81a22dd10 | ||
|
|
269cb2967c | ||
|
|
6b764ae61b | ||
|
|
44c89e6559 | ||
|
|
a541a2dac2 | ||
|
|
ff7baa0a24 | ||
|
|
623d05da91 | ||
|
|
8601288230 | ||
|
|
fa11926642 | ||
|
|
9c8ec7fb0d | ||
|
|
78c9bd1d61 | ||
|
|
9c19bd7b6b | ||
|
|
de2fd2bdc0 | ||
|
|
81235e3ce6 | ||
|
|
4f7b2fcd17 | ||
|
|
e13fa186e1 | ||
|
|
f238940622 | ||
|
|
7f4b8cab8a | ||
|
|
b0dd8cded1 | ||
|
|
f48d958a2c | ||
|
|
2cb3cc7c35 | ||
|
|
f4ab1ac7ec | ||
|
|
2769f5e8dc | ||
|
|
d7dce88751 | ||
|
|
b036002ca8 | ||
|
|
70ab1e59c4 | ||
|
|
133fa0df2b | ||
|
|
58ca4ecafa | ||
|
|
843e55841b | ||
|
|
cfe3994bc9 | ||
|
|
8b95d963fe | ||
|
|
83d8cd07d2 | ||
|
|
6b323ba746 | ||
|
|
e834ff06ab | ||
|
|
f30d9dad94 | ||
|
|
ee914c8014 | ||
|
|
b8d0dc96fd | ||
|
|
faedb21808 | ||
|
|
9bdf180f97 | ||
|
|
f383085910 | ||
|
|
2070bbebb0 | ||
|
|
9edf7f0196 | ||
|
|
d7d5ac63ac | ||
|
|
841543e984 | ||
|
|
b1c128738f | ||
|
|
51319b036b | ||
|
|
0f30e1fc41 | ||
|
|
11d5d6254a | ||
|
|
ae33d7e72a | ||
|
|
aca8599d6e | ||
|
|
43daef0455 | ||
|
|
ff296f84eb | ||
|
|
ae2b3d1327 | ||
|
|
433ff827b7 | ||
|
|
b776000cf0 | ||
|
|
c260d348d7 | ||
|
|
153f5ef9ce | ||
|
|
256df8d2aa | ||
|
|
d300d5c16b | ||
|
|
73804a0ed4 | ||
|
|
4b2c6e4f62 | ||
|
|
7382680fc5 | ||
|
|
cee8159c69 | ||
|
|
6d5077159b | ||
|
|
d74df846f2 | ||
|
|
7a8dba19ee | ||
|
|
fe8b54346a | ||
|
|
fbeced6eb2 | ||
|
|
e17b45d2ec | ||
|
|
d7bcb418d4 | ||
|
|
77bcf87cd1 | ||
|
|
8c0318c4e2 | ||
|
|
080b47a9a6 | ||
|
|
01ec722ea0 | ||
|
|
e6f36dc0bd | ||
|
|
27e19d4494 | ||
|
|
5d0f58edc1 | ||
|
|
0e7d53b582 | ||
|
|
96edd50450 | ||
|
|
dd590e1530 | ||
|
|
3133a9aa8c | ||
|
|
a52ab42c61 | ||
|
|
77e70c3536 | ||
|
|
4d9a7c3e12 | ||
|
|
6d827365ac | ||
|
|
f9c32fd7dc | ||
|
|
998cc778e6 | ||
|
|
076dc76ca4 | ||
|
|
5f260455cb | ||
|
|
bf33858e41 | ||
|
|
6ed489835f | ||
|
|
febc77032b | ||
|
|
65bfe3077f | ||
|
|
f8f1580fc7 | ||
|
|
aca7ae8ecf | ||
|
|
03aa9f8b94 | ||
|
|
2d514e9258 | ||
|
|
3c51273cc3 |
0
.go/pkg/mod/cache/lock
vendored
Normal file
@@ -128,8 +128,8 @@ object Page {
|
||||
target := "_blank",
|
||||
"Frontend Mentor. "
|
||||
),
|
||||
"Coded by ",
|
||||
a(href := "#", "Your Name Here")
|
||||
"Source code at",
|
||||
a(href := "https://github.com/efim/Learning-HTMX", "Your Name Here")
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
Challenge by
|
||||
<a href="https://www.frontendmentor.io?ref=challenge" target="_blank"
|
||||
>Frontend Mentor</a
|
||||
>. Coded by <a href="#">Your Name Here</a>.
|
||||
>. Source code at <a href="https://github.com/efim/Learning-HTMX">Your Name Here</a>.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -189,7 +189,7 @@
|
||||
Challenge by
|
||||
<a href="https://www.frontendmentor.io?ref=challenge" target="_blank"
|
||||
>Frontend Mentor</a
|
||||
>. Coded by <a href="#">Your Name Here</a>.
|
||||
>. Source code at <a href="https://github.com/efim/Learning-HTMX">Your Name Here</a>.
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -228,7 +228,7 @@
|
||||
Challenge by
|
||||
<a href="https://www.frontendmentor.io?ref=challenge" target="_blank"
|
||||
>Frontend Mentor</a
|
||||
>. Coded by <a href="#">Your Name Here</a>.
|
||||
>. Source code at <a href="https://github.com/efim/Learning-HTMX">Your Name Here</a>.
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
1
15-multi-step-form/.envrc
Normal file
@@ -0,0 +1 @@
|
||||
use flake
|
||||
161
15-multi-step-form/README.org
Normal file
@@ -0,0 +1,161 @@
|
||||
* Frontend Mentor - Multi-step form solution
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: frontend-mentor---multi-step-form-solution
|
||||
:END:
|
||||
This is a solution to the
|
||||
[[https://www.frontendmentor.io/challenges/multistep-form-YVAnSdqQBJ][Multi-step
|
||||
form challenge on Frontend Mentor]]. Frontend Mentor challenges help you
|
||||
improve your coding skills by building realistic projects.
|
||||
|
||||
** Overview
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: overview
|
||||
:END:
|
||||
*** The challenge
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: the-challenge
|
||||
:END:
|
||||
Users should be able to:
|
||||
|
||||
- Complete each step of the sequence
|
||||
- Go back to a previous step to update their selections
|
||||
- See a summary of their selections on the final step and confirm their
|
||||
order
|
||||
- View the optimal layout for the interface depending on their device's
|
||||
screen size
|
||||
- See hover and focus states for all interactive elements on the page
|
||||
- Receive form validation messages if:
|
||||
- A field has been missed
|
||||
- The email address is not formatted correctly
|
||||
- A step is submitted, but no selection has been made
|
||||
|
||||
*** Screenshot
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: screenshot
|
||||
:END:
|
||||
[[screenshot-desktop.png]]
|
||||
[[screenshot-mobile.png]]
|
||||
|
||||
*** Links
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: links
|
||||
:END:
|
||||
- [[https://www.frontendmentor.io/solutions/responsive-ssr-on-scala-interactivity-by-htmx-thymeleaf-templates-QIGkOSgRa4][Solution URL]]
|
||||
- [[https://efim-frontentmentor-multi-step-form.onrender.com][Live Site URL]]
|
||||
|
||||
** My process
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: my-process
|
||||
:END:
|
||||
*** Built with
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: built-with
|
||||
:END:
|
||||
- Semantic HTML5 markup
|
||||
well, i tried, but yeah
|
||||
- TailwinCSS
|
||||
- Mobile-first workflow
|
||||
- Server-side rendering, in Scala and Cask
|
||||
- htmx
|
||||
- Thymeleaf html templates
|
||||
|
||||
|
||||
*** What I learned
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: what-i-learned
|
||||
:END:
|
||||
**** hx-get and hx-post
|
||||
***** How i show correct form stage for each user on same URL
|
||||
on 'index.html' i use "initial loading" element
|
||||
#+begin_src html
|
||||
<section hx-get="/get-form" hx-trigger="load" hx-swap="outerHTML">
|
||||
<!-- here be immediate hx-get for the form. to subscitute the body -->
|
||||
<img class="w-14 text-green-500 fill-current" src="../public/images/tail-spin.svg" alt="loading..." />
|
||||
</section>
|
||||
#+end_src
|
||||
|
||||
This element will do single GET request to server to /get-form
|
||||
And user already has cookie with sessionId set from visiting the root enpoint, which returned 'index.html'
|
||||
|
||||
So request to /get-form already includes 'sessionId' cookie, and server can find \ initialize Answers data for this particular session,
|
||||
and 'currentStep' is part of the Answers
|
||||
|
||||
so reloading 'index.html' would trigger /get-form, which would render correct step.
|
||||
***** hx-post
|
||||
This will make POST request.
|
||||
If we do GET request from <input> only current input value is included, as query para.
|
||||
POST request from <input> or from <form> would include all filelds of the form.
|
||||
|
||||
So form submittion on "Next" and "Back" done via htmx POST requests, which parse and save passed attributes, but also server selects required next form step, renders it and returns for the 'hx-swap="outerHTML"'
|
||||
|
||||
hx-post on <input> allows for 'inline validation' (see useful resources)
|
||||
this allows for validating field value - in isolation or together with all other form field values.
|
||||
|
||||
**** Learned format in which browser sends POST attributes to the server
|
||||
Request payload as text:
|
||||
name=e&email=emails%40la.la&phone=%2B7%20(911)%2084-35644%20ext%20155
|
||||
|
||||
I chose this exercise also because i wanted more experience in working with forms.
|
||||
Single form would still be much nicer, even with htmx, but yeah.
|
||||
Current exercise felt like full-fledged application.
|
||||
|
||||
**** Styling of the checkbox and radiobuttons as big selectable areas
|
||||
This was first time I attempted something like this.
|
||||
Insight was to use <label> as overall container for the input and other data - descriptions and icons.
|
||||
|
||||
Because user clicking on label automatically translates into toggling of the input, no js needed.
|
||||
|
||||
Either hide (for radio button part on step 2) or keep (for checkboxes on step 3) the input, and put descriptions and icons as next element.
|
||||
|
||||
So that =peer-= styling can be used.
|
||||
|
||||
**** htmx inline validation of the phone number field
|
||||
Almost exactly as in example.
|
||||
Separate rest endpoint for the input field, which returns new rendered state.
|
||||
|
||||
hx-post is triggered on input field default trigger = "changed",
|
||||
and i guess only on focus leaving field. So this seems quite efficient.
|
||||
|
||||
This way validation can be done with very heavy libraries and access to DB and such. Over single field, or over all of them at once.
|
||||
Seems unusual, but cool
|
||||
*** Continued development
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: continued-development
|
||||
:END:
|
||||
I want to learn more about Thymeleaf - how to use files for efficient fragment
|
||||
storage. Currently it feels that i have separate files, and it's nice, but some
|
||||
files have several fragments, and maybe need more documentation or markings.
|
||||
|
||||
Look for other templating solutions for java \ scala, maybe there are others
|
||||
with 'fragment' functionality
|
||||
|
||||
Would be nice to refactor the code, to have smaller and more directed files.
|
||||
|
||||
I am also getting better at doing flex \ grid layouts without specific
|
||||
paddings\margins on the lements, but feel that i'm still abusing that, and that
|
||||
future tinkering with layouts could be painful due to free space being
|
||||
constructed from manual paddings\margings
|
||||
|
||||
For htmx - would be nice to learn transition animations, and try to use it in a bigger exercise already.
|
||||
|
||||
*** Useful resources
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: useful-resources
|
||||
:END:
|
||||
- htmx inline validation
|
||||
https://htmx.org/examples/inline-validation/
|
||||
- htmx control of parameters sent with response
|
||||
https://htmx.org/docs/#parameters
|
||||
** Acknowledgments
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: acknowledgments
|
||||
:END:
|
||||
- svg animated spinner - from SamHerbert
|
||||
https://github.com/SamHerbert/SVG-Loaders/tree/master
|
||||
http://samherbert.net/svg-loaders/
|
||||
- tailwind elements - for their example of 'switch styled' checkbox
|
||||
which I used as inspiration for my styling
|
||||
https://tailwind-elements.com/docs/standard/forms/switch/
|
||||
- to render.com for allowing DockerImage deployments on a free tier
|
||||
they get shut down after 15 minutes of inactivity, and image has to be < 10Gb
|
||||
but this is great! no credit card needed
|
||||
@@ -11,6 +11,7 @@ lazy val multiStepForm = (project in file("."))
|
||||
libraryDependencies ++= Seq(
|
||||
"com.lihaoyi" %% "cask" % "0.9.1",
|
||||
"com.lihaoyi" %% "mainargs" % "0.5.0",
|
||||
"org.thymeleaf" % "thymeleaf" % "3.1.1.RELEASE"
|
||||
"org.thymeleaf" % "thymeleaf" % "3.1.1.RELEASE",
|
||||
"com.googlecode.libphonenumber" % "libphonenumber" % "8.13.16"
|
||||
)
|
||||
)
|
||||
|
||||
101
15-multi-step-form/default.nix
Normal file
@@ -0,0 +1,101 @@
|
||||
{ pkgs, lib, sbt-derivation }:
|
||||
|
||||
let
|
||||
pname = "multi-step-form";
|
||||
package = sbt-derivation.lib.mkSbtDerivation {
|
||||
inherit pkgs pname;
|
||||
# ...and the rest of the arguments
|
||||
version = "0.0.1";
|
||||
src = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
|
||||
nativeBuildInputs = [ pkgs.nodePackages.tailwindcss ];
|
||||
buildPhase = ''
|
||||
tailwindcss -i ./src/input.css -o ./src/main/resources/public/output.css
|
||||
sbt assembly
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp target/scala-*/${pname}-assembly-*.jar $out/bin/${pname}.jar
|
||||
'';
|
||||
|
||||
depsSha256 = "sha256-zG4e7ERdi/WxzACymaYUQ0x8v4/peGARuqPAK8xvBmE=";
|
||||
};
|
||||
|
||||
module = { config, pkgs, ... }:
|
||||
let cfg = config.services.${pname};
|
||||
in {
|
||||
options.services.${pname} = {
|
||||
enable = lib.mkEnableOption "My frontendmentor exercise ${pname}";
|
||||
|
||||
port = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 8080;
|
||||
description = "Port to listen on.";
|
||||
};
|
||||
|
||||
host = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "localhost";
|
||||
description = "Host to bind to.";
|
||||
};
|
||||
|
||||
useNginx = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = "Whether to use Nginx to proxy requests.";
|
||||
};
|
||||
};
|
||||
config = lib.mkIf cfg.enable {
|
||||
users.groups."${pname}-group" = { };
|
||||
users.users."${pname}-user" = {
|
||||
isSystemUser = true;
|
||||
group = "${pname}-group";
|
||||
};
|
||||
|
||||
systemd.services.${pname} =
|
||||
let serverHost = if cfg.useNginx then "localhost" else cfg.host;
|
||||
in {
|
||||
description = "Exercise app ${pname}";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
startLimitIntervalSec = 30;
|
||||
startLimitBurst = 10;
|
||||
serviceConfig = {
|
||||
ExecStart =
|
||||
"${pkgs.jdk}/bin/java -jar ${package}/bin/${pname}.jar -p ${
|
||||
toString cfg.port
|
||||
} --host ${serverHost}";
|
||||
WorkingDirectory = "${package}/bin";
|
||||
Restart = "on-failure";
|
||||
User = "${pname}-user";
|
||||
Group = "${pname}-group";
|
||||
};
|
||||
};
|
||||
|
||||
services.nginx = lib.mkIf cfg.useNginx {
|
||||
virtualHosts.${cfg.host} = {
|
||||
locations."/".proxyPass = "http://127.0.0.1:${toString cfg.port}";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
image = pkgs.dockerTools.buildLayeredImage {
|
||||
name = pname;
|
||||
tag = "latest";
|
||||
created = "now";
|
||||
config = {
|
||||
Cmd = [ "${pkgs.jdk}/bin/java" "-jar" "${package}/bin/${pname}.jar" "--host" "0.0.0.0" ];
|
||||
ExposedPorts = {
|
||||
"8080/tcp" = {};
|
||||
};
|
||||
};
|
||||
};
|
||||
# image = pkgs.dockerTools.buildLayeredImage { # so, wow, this works
|
||||
# name = "hello2";
|
||||
# tag = "latest";
|
||||
# config.Cmd = [ "${pkgs.hello}/bin/hello" ];
|
||||
# };
|
||||
in {
|
||||
package = package;
|
||||
module = module;
|
||||
image = image;
|
||||
}
|
||||
BIN
15-multi-step-form/screenshot-desktop.png
Normal file
|
After Width: | Height: | Size: 112 KiB |
BIN
15-multi-step-form/screenshot-mobile.png
Normal file
|
After Width: | Height: | Size: 45 KiB |
1
15-multi-step-form/src/main/resources/public/htmx.min.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<!-- By Sam Herbert (@sherb), for everyone. More @ http://goo.gl/7AJzbL -->
|
||||
<svg width="38" height="38" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient x1="8.042%" y1="0%" x2="65.682%" y2="23.865%" id="a">
|
||||
<stop stop-color="hsl(228, 100%, 84%)" stop-opacity="0" offset="0%"/>
|
||||
<stop stop-color="hsl(228, 100%, 84%)" stop-opacity=".631" offset="63.146%"/>
|
||||
<stop stop-color="hsl(228, 100%, 84%)" offset="100%"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g fill="none" fill-rule="evenodd">
|
||||
<g transform="translate(1 1)">
|
||||
<path d="M36 18c0-9.94-8.06-18-18-18" id="Oval-2" stroke="url(#a)" stroke-width="2">
|
||||
<animateTransform
|
||||
attributeName="transform"
|
||||
type="rotate"
|
||||
from="0 18 18"
|
||||
to="360 18 18"
|
||||
dur="0.9s"
|
||||
repeatCount="indefinite" />
|
||||
</path>
|
||||
<circle fill="#fff" cx="36" cy="18" r="1">
|
||||
<animateTransform
|
||||
attributeName="transform"
|
||||
type="rotate"
|
||||
from="0 18 18"
|
||||
to="360 18 18"
|
||||
dur="0.9s"
|
||||
repeatCount="indefinite" />
|
||||
</circle>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -1 +0,0 @@
|
||||
hello from the resource file!
|
||||
@@ -548,30 +548,26 @@ video {
|
||||
bottom: 0px;
|
||||
}
|
||||
|
||||
.z-0 {
|
||||
z-index: 0;
|
||||
.end-0 {
|
||||
inset-inline-end: 0px;
|
||||
}
|
||||
|
||||
.z-10 {
|
||||
z-index: 10;
|
||||
.top-0 {
|
||||
top: 0px;
|
||||
}
|
||||
|
||||
.z-20 {
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
.z-40 {
|
||||
z-index: 40;
|
||||
}
|
||||
|
||||
.z-50 {
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.col-start-2 {
|
||||
grid-column-start: 2;
|
||||
}
|
||||
|
||||
.row-span-full {
|
||||
grid-row: 1 / -1;
|
||||
}
|
||||
|
||||
.row-span-2 {
|
||||
grid-row: span 2 / span 2;
|
||||
}
|
||||
@@ -580,26 +576,14 @@ video {
|
||||
grid-row-start: 1;
|
||||
}
|
||||
|
||||
.m-8 {
|
||||
margin: 2rem;
|
||||
.my-3 {
|
||||
margin-top: 0.75rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.m-4 {
|
||||
margin: 1rem;
|
||||
}
|
||||
|
||||
.m-6 {
|
||||
margin: 1.5rem;
|
||||
}
|
||||
|
||||
.my-10 {
|
||||
margin-top: 2.5rem;
|
||||
margin-bottom: 2.5rem;
|
||||
}
|
||||
|
||||
.my-8 {
|
||||
margin-top: 2rem;
|
||||
margin-bottom: 2rem;
|
||||
.my-5 {
|
||||
margin-top: 1.25rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.my-7 {
|
||||
@@ -611,10 +595,26 @@ video {
|
||||
margin-top: -5rem;
|
||||
}
|
||||
|
||||
.mb-2 {
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.mb-4 {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.ml-16 {
|
||||
margin-left: 4rem;
|
||||
}
|
||||
|
||||
.ml-2 {
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
.ml-20 {
|
||||
margin-left: 5rem;
|
||||
}
|
||||
|
||||
.ml-6 {
|
||||
margin-left: 1.5rem;
|
||||
}
|
||||
@@ -627,26 +627,18 @@ video {
|
||||
margin-right: 0.75rem;
|
||||
}
|
||||
|
||||
.mt-3 {
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.mt-5 {
|
||||
margin-top: 1.25rem;
|
||||
}
|
||||
|
||||
.mt-\[0\.3rem\] {
|
||||
margin-top: 0.3rem;
|
||||
}
|
||||
|
||||
.ml-\[200px\] {
|
||||
margin-left: 200px;
|
||||
}
|
||||
|
||||
.ml-\[100px\] {
|
||||
margin-left: 100px;
|
||||
}
|
||||
|
||||
.ml-\[70px\] {
|
||||
margin-left: 70px;
|
||||
}
|
||||
|
||||
.ml-20 {
|
||||
margin-left: 5rem;
|
||||
}
|
||||
|
||||
.flex {
|
||||
display: flex;
|
||||
}
|
||||
@@ -659,6 +651,10 @@ video {
|
||||
display: inline-grid;
|
||||
}
|
||||
|
||||
.contents {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
@@ -671,6 +667,14 @@ video {
|
||||
height: 3rem;
|
||||
}
|
||||
|
||||
.h-14 {
|
||||
height: 3.5rem;
|
||||
}
|
||||
|
||||
.h-16 {
|
||||
height: 4rem;
|
||||
}
|
||||
|
||||
.h-20 {
|
||||
height: 5rem;
|
||||
}
|
||||
@@ -687,34 +691,38 @@ video {
|
||||
height: 1.25rem;
|
||||
}
|
||||
|
||||
.h-8 {
|
||||
height: 2rem;
|
||||
.h-6 {
|
||||
height: 1.5rem;
|
||||
}
|
||||
|
||||
.h-screen {
|
||||
height: 100vh;
|
||||
.h-8 {
|
||||
height: 2rem;
|
||||
}
|
||||
|
||||
.h-full {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.h-6 {
|
||||
height: 1.5rem;
|
||||
}
|
||||
|
||||
.h-4 {
|
||||
height: 1rem;
|
||||
.h-screen {
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.w-11\/12 {
|
||||
width: 91.666667%;
|
||||
}
|
||||
|
||||
.w-14 {
|
||||
width: 3.5rem;
|
||||
}
|
||||
|
||||
.w-24 {
|
||||
width: 6rem;
|
||||
}
|
||||
|
||||
.w-6 {
|
||||
width: 1.5rem;
|
||||
}
|
||||
|
||||
.w-8 {
|
||||
width: 2rem;
|
||||
}
|
||||
@@ -731,14 +739,6 @@ video {
|
||||
width: 100vw;
|
||||
}
|
||||
|
||||
.w-6 {
|
||||
width: 1.5rem;
|
||||
}
|
||||
|
||||
.w-4 {
|
||||
width: 1rem;
|
||||
}
|
||||
|
||||
.grow {
|
||||
flex-grow: 1;
|
||||
}
|
||||
@@ -757,14 +757,26 @@ video {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.grid-cols-\[repeat\(4\2c _auto\)\] {
|
||||
grid-template-columns: repeat(4, auto);
|
||||
}
|
||||
|
||||
.grid-cols-\[1fr_100px\] {
|
||||
grid-template-columns: 1fr 100px;
|
||||
}
|
||||
|
||||
.grid-cols-\[1fr_70px\] {
|
||||
grid-template-columns: 1fr 70px;
|
||||
}
|
||||
|
||||
.grid-cols-\[1fr_auto\] {
|
||||
grid-template-columns: 1fr auto;
|
||||
}
|
||||
|
||||
.grid-cols-\[auto_1fr\] {
|
||||
grid-template-columns: auto 1fr;
|
||||
}
|
||||
|
||||
.grid-cols-\[repeat\(4\2c _auto\)\] {
|
||||
grid-template-columns: repeat(4, auto);
|
||||
}
|
||||
|
||||
.flex-row {
|
||||
flex-direction: row;
|
||||
}
|
||||
@@ -785,6 +797,10 @@ video {
|
||||
align-content: center;
|
||||
}
|
||||
|
||||
.items-start {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.items-center {
|
||||
align-items: center;
|
||||
}
|
||||
@@ -794,6 +810,10 @@ video {
|
||||
column-gap: 1.25rem;
|
||||
}
|
||||
|
||||
.gap-y-3 {
|
||||
row-gap: 0.75rem;
|
||||
}
|
||||
|
||||
.gap-y-4 {
|
||||
row-gap: 1rem;
|
||||
}
|
||||
@@ -804,12 +824,16 @@ video {
|
||||
border-bottom-width: calc(1px * var(--tw-divide-y-reverse));
|
||||
}
|
||||
|
||||
.self-center {
|
||||
align-self: center;
|
||||
.place-self-center {
|
||||
place-self: center;
|
||||
}
|
||||
|
||||
.justify-self-center {
|
||||
justify-self: center;
|
||||
.self-end {
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.self-center {
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.rounded {
|
||||
@@ -837,19 +861,33 @@ video {
|
||||
border-color: hsl(231 11% 63% / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.border-light-gray {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: hsl(229 24% 87% / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.border-white {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: rgb(255 255 255 / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.border-strawberry-red {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: hsl(354 84% 57% / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.\!bg-light-blue {
|
||||
--tw-bg-opacity: 1 !important;
|
||||
background-color: hsl(206 94% 87% / var(--tw-bg-opacity)) !important;
|
||||
}
|
||||
|
||||
.bg-green-200 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(187 247 208 / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.bg-light-gray {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: hsl(229 24% 87% / var(--tw-bg-opacity));
|
||||
.bg-light-gray\/25 {
|
||||
background-color: hsl(229 24% 87% / 0.25);
|
||||
}
|
||||
|
||||
.bg-magnolia {
|
||||
@@ -857,53 +895,49 @@ video {
|
||||
background-color: hsl(217 100% 97% / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.bg-magnolia\/75 {
|
||||
background-color: hsl(217 100% 97% / 0.75);
|
||||
}
|
||||
|
||||
.bg-marine-blue {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: hsl(213 96% 18% / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.bg-white {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.bg-yellow-500 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(234 179 8 / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.bg-cool-gray {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: hsl(231 11% 63% / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.bg-light-blue {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: hsl(206 94% 87% / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.bg-pastel-blue {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: hsl(228 100% 84% / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.bg-purplish-blue {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: hsl(243 100% 62% / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.bg-white {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
|
||||
}
|
||||
|
||||
.bg-sidebar-mobile {
|
||||
background-image: url("images/bg-sidebar-mobile.svg");
|
||||
}
|
||||
|
||||
.bg-cover {
|
||||
background-size: cover;
|
||||
}
|
||||
|
||||
.bg-no-repeat {
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.fill-current {
|
||||
fill: currentColor;
|
||||
}
|
||||
|
||||
.p-1 {
|
||||
padding: 0.25rem;
|
||||
}
|
||||
|
||||
.p-3 {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
.px-4 {
|
||||
padding-left: 1rem;
|
||||
padding-right: 1rem;
|
||||
@@ -914,6 +948,16 @@ video {
|
||||
padding-right: 1.5rem;
|
||||
}
|
||||
|
||||
.px-8 {
|
||||
padding-left: 2rem;
|
||||
padding-right: 2rem;
|
||||
}
|
||||
|
||||
.py-20 {
|
||||
padding-top: 5rem;
|
||||
padding-bottom: 5rem;
|
||||
}
|
||||
|
||||
.py-3 {
|
||||
padding-top: 0.75rem;
|
||||
padding-bottom: 0.75rem;
|
||||
@@ -929,12 +973,8 @@ video {
|
||||
padding-bottom: 2rem;
|
||||
}
|
||||
|
||||
.pt-3 {
|
||||
padding-top: 0.75rem;
|
||||
}
|
||||
|
||||
.pl-8 {
|
||||
padding-left: 2rem;
|
||||
.pb-5 {
|
||||
padding-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.pl-5 {
|
||||
@@ -945,6 +985,14 @@ video {
|
||||
padding-left: 1.5rem;
|
||||
}
|
||||
|
||||
.pt-3 {
|
||||
padding-top: 0.75rem;
|
||||
}
|
||||
|
||||
.text-center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.text-2xl {
|
||||
font-size: 1.5rem;
|
||||
line-height: 2rem;
|
||||
@@ -960,6 +1008,11 @@ video {
|
||||
line-height: 1.25rem;
|
||||
}
|
||||
|
||||
.text-xs {
|
||||
font-size: 0.75rem;
|
||||
line-height: 1rem;
|
||||
}
|
||||
|
||||
.font-bold {
|
||||
font-weight: 700;
|
||||
}
|
||||
@@ -972,11 +1025,21 @@ video {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.\!text-marine-blue {
|
||||
--tw-text-opacity: 1 !important;
|
||||
color: hsl(213 96% 18% / var(--tw-text-opacity)) !important;
|
||||
}
|
||||
|
||||
.text-cool-gray {
|
||||
--tw-text-opacity: 1;
|
||||
color: hsl(231 11% 63% / var(--tw-text-opacity));
|
||||
}
|
||||
|
||||
.text-green-500 {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(34 197 94 / var(--tw-text-opacity));
|
||||
}
|
||||
|
||||
.text-light-gray {
|
||||
--tw-text-opacity: 1;
|
||||
color: hsl(229 24% 87% / var(--tw-text-opacity));
|
||||
@@ -987,11 +1050,29 @@ video {
|
||||
color: hsl(213 96% 18% / var(--tw-text-opacity));
|
||||
}
|
||||
|
||||
.text-purplish-blue {
|
||||
--tw-text-opacity: 1;
|
||||
color: hsl(243 100% 62% / var(--tw-text-opacity));
|
||||
}
|
||||
|
||||
.text-white {
|
||||
--tw-text-opacity: 1;
|
||||
color: rgb(255 255 255 / var(--tw-text-opacity));
|
||||
}
|
||||
|
||||
.text-strawberry-red {
|
||||
--tw-text-opacity: 1;
|
||||
color: hsl(354 84% 57% / var(--tw-text-opacity));
|
||||
}
|
||||
|
||||
.underline {
|
||||
text-decoration-line: underline;
|
||||
}
|
||||
|
||||
.accent-purplish-blue {
|
||||
accent-color: hsl(243, 100%, 62%);
|
||||
}
|
||||
|
||||
.drop-shadow-xl {
|
||||
--tw-drop-shadow: drop-shadow(0 20px 13px rgb(0 0 0 / 0.03)) drop-shadow(0 8px 5px rgb(0 0 0 / 0.08));
|
||||
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
|
||||
@@ -1116,10 +1197,34 @@ html {
|
||||
margin-left: 1.2rem;
|
||||
}
|
||||
|
||||
.invalid\:border-strawberry-red:invalid {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: hsl(354 84% 57% / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.hover\:cursor-pointer:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.hover\:border-purplish-blue:hover {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: hsl(243 100% 62% / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.hover\:bg-magnolia\/\[\.1\]:hover {
|
||||
background-color: hsl(217 100% 97% / .1);
|
||||
}
|
||||
|
||||
.focus\:border-marine-blue:focus {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: hsl(213 96% 18% / var(--tw-border-opacity));
|
||||
}
|
||||
|
||||
.focus\:outline-none:focus {
|
||||
outline: 2px solid transparent;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.peer:checked ~ .peer-checked\:border-purplish-blue {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: hsl(243 100% 62% / var(--tw-border-opacity));
|
||||
@@ -1134,8 +1239,8 @@ html {
|
||||
background-color: hsl(217 100% 97% / 0.5);
|
||||
}
|
||||
|
||||
.peer:checked ~ .peer-checked\:bg-magnolia\/20 {
|
||||
background-color: hsl(217 100% 97% / 0.2);
|
||||
.peer:checked ~ .peer-checked\:bg-magnolia\/75 {
|
||||
background-color: hsl(217 100% 97% / 0.75);
|
||||
}
|
||||
|
||||
.peer:checked ~ .peer-checked\:text-cool-gray {
|
||||
@@ -1149,12 +1254,26 @@ html {
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.md\:row-span-1 {
|
||||
grid-row: span 1 / span 1;
|
||||
}
|
||||
|
||||
.md\:row-span-2 {
|
||||
grid-row: span 2 / span 2;
|
||||
}
|
||||
|
||||
.md\:ml-20 {
|
||||
margin-left: 5rem;
|
||||
.md\:mx-4 {
|
||||
margin-left: 1rem;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
.md\:my-7 {
|
||||
margin-top: 1.75rem;
|
||||
margin-bottom: 1.75rem;
|
||||
}
|
||||
|
||||
.md\:ml-24 {
|
||||
margin-left: 6rem;
|
||||
}
|
||||
|
||||
.md\:mr-24 {
|
||||
@@ -1165,6 +1284,14 @@ html {
|
||||
margin-top: 0px;
|
||||
}
|
||||
|
||||
.md\:mt-2 {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.md\:mt-5 {
|
||||
margin-top: 1.25rem;
|
||||
}
|
||||
|
||||
.md\:flex {
|
||||
display: flex;
|
||||
}
|
||||
@@ -1181,6 +1308,14 @@ html {
|
||||
height: 3rem;
|
||||
}
|
||||
|
||||
.md\:h-20 {
|
||||
height: 5rem;
|
||||
}
|
||||
|
||||
.md\:h-40 {
|
||||
height: 10rem;
|
||||
}
|
||||
|
||||
.md\:h-\[568px\] {
|
||||
height: 568px;
|
||||
}
|
||||
@@ -1193,6 +1328,10 @@ html {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.md\:w-20 {
|
||||
width: 5rem;
|
||||
}
|
||||
|
||||
.md\:w-32 {
|
||||
width: 8rem;
|
||||
}
|
||||
@@ -1209,8 +1348,8 @@ html {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.md\:w-20 {
|
||||
width: 5rem;
|
||||
.md\:grow {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.md\:grid-cols-1 {
|
||||
@@ -1221,6 +1360,10 @@ html {
|
||||
grid-template-columns: auto 1fr;
|
||||
}
|
||||
|
||||
.md\:grid-rows-\[1fr_auto_auto\] {
|
||||
grid-template-rows: 1fr auto auto;
|
||||
}
|
||||
|
||||
.md\:grid-rows-\[repeat\(4\2c _auto\)\] {
|
||||
grid-template-rows: repeat(4, auto);
|
||||
}
|
||||
@@ -1245,6 +1388,10 @@ html {
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.md\:justify-center {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.md\:gap-x-4 {
|
||||
-moz-column-gap: 1rem;
|
||||
column-gap: 1rem;
|
||||
@@ -1254,6 +1401,10 @@ html {
|
||||
row-gap: 1.75rem;
|
||||
}
|
||||
|
||||
.md\:place-self-start {
|
||||
place-self: start;
|
||||
}
|
||||
|
||||
.md\:rounded-2xl {
|
||||
border-radius: 1rem;
|
||||
}
|
||||
@@ -1275,6 +1426,10 @@ html {
|
||||
padding: 2.5rem;
|
||||
}
|
||||
|
||||
.md\:p-4 {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.md\:p-5 {
|
||||
padding: 1.25rem;
|
||||
}
|
||||
@@ -1283,6 +1438,11 @@ html {
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.md\:px-0 {
|
||||
padding-left: 0px;
|
||||
padding-right: 0px;
|
||||
}
|
||||
|
||||
.md\:px-24 {
|
||||
padding-left: 6rem;
|
||||
padding-right: 6rem;
|
||||
@@ -1293,6 +1453,15 @@ html {
|
||||
padding-right: 1rem;
|
||||
}
|
||||
|
||||
.md\:px-6 {
|
||||
padding-left: 1.5rem;
|
||||
padding-right: 1.5rem;
|
||||
}
|
||||
|
||||
.md\:pb-10 {
|
||||
padding-bottom: 2.5rem;
|
||||
}
|
||||
|
||||
.md\:pb-2 {
|
||||
padding-bottom: 0.5rem;
|
||||
}
|
||||
@@ -1301,6 +1470,10 @@ html {
|
||||
padding-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.md\:pb-8 {
|
||||
padding-bottom: 2rem;
|
||||
}
|
||||
|
||||
.md\:pt-5 {
|
||||
padding-top: 1.25rem;
|
||||
}
|
||||
@@ -1315,6 +1488,15 @@ html {
|
||||
line-height: 1.5rem;
|
||||
}
|
||||
|
||||
.md\:text-lg {
|
||||
font-size: 1.125rem;
|
||||
line-height: 1.75rem;
|
||||
}
|
||||
|
||||
.md\:tracking-widest {
|
||||
letter-spacing: 0.1em;
|
||||
}
|
||||
|
||||
.md\:drop-shadow-2xl {
|
||||
--tw-drop-shadow: drop-shadow(0 25px 25px rgb(0 0 0 / 0.15));
|
||||
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
|
||||
|
||||
@@ -9,10 +9,15 @@
|
||||
rel="icon"
|
||||
type="image/png"
|
||||
sizes="32x32"
|
||||
href="./assets/images/favicon-32x32.png"
|
||||
th:href="'public/images/favicon-32x32.png'"
|
||||
href="../public/images/favicon-32x32.png"
|
||||
/>
|
||||
<link href="../public/out.css" rel="stylesheet" />
|
||||
|
||||
<link
|
||||
th:href="'public/out.css'"
|
||||
href="../public/out.css"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<script th:src="'public/htmx.min.js'" src="../public/htmx.min.js"></script>
|
||||
<title>Frontend Mentor | Multi-step form</title>
|
||||
|
||||
<!-- Feel free to remove these styles or customise in your own stylesheet 👍 -->
|
||||
@@ -27,7 +32,27 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main class="bg-light-gray h-screen w-screen">
|
||||
<!-- here be immediate hx-get for the form. to subscitute the body -->
|
||||
<main class="grid place-content-center w-screen h-screen bg-magnolia">
|
||||
<section hx-get="/get-form" hx-trigger="load" hx-swap="outerHTML">
|
||||
<!-- here be immediate hx-get for the form. to subscitute the body -->
|
||||
<img
|
||||
class="w-14 text-green-500 fill-current"
|
||||
th:src="'public/images/tail-spin.svg'"
|
||||
src="../public/images/tail-spin.svg"
|
||||
alt="loading..."
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section class="absolute top-0 end-0" id="new-session-control">
|
||||
<button hx-get="/force-new-session">Request new session</button>
|
||||
</section>
|
||||
<div class="fixed inset-x-0 bottom-0 attribution">
|
||||
Challenge by
|
||||
<a href="https://www.frontendmentor.io?ref=challenge" target="_blank"
|
||||
>Frontend Mentor</a
|
||||
>. Source code at
|
||||
<a href="https://github.com/efim/Learning-HTMX">Your Name Here</a>.
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -35,55 +35,82 @@
|
||||
</p>
|
||||
<![endif]-->
|
||||
|
||||
<article
|
||||
<form
|
||||
class="flex flex-col items-center w-screen h-screen md:grid md:items-start md:p-5 md:bg-white md:rounded-2xl md:grid-cols-[auto_1fr] md:w-desktop-form md:h-desktop-form md:drop-shadow-2xl"
|
||||
id="form-step"
|
||||
th:fragment="formFragment(formData)"
|
||||
hx-post="/submit-step/1/2"
|
||||
hx-swap="outerHTML"
|
||||
action="/submit-step/1/2"
|
||||
method="post"
|
||||
>
|
||||
<summary
|
||||
class="w-full h-44 bg-no-repeat md:row-span-2 bg-sidebar-mobile marker:text-white md:bg-sidebar-desktop md:h-[568px] md:w-[274px]"
|
||||
class="w-full h-44 bg-no-repeat bg-cover md:row-span-2 md:tracking-widest bg-sidebar-mobile marker:text-white md:bg-sidebar-desktop md:h-[568px] md:w-[274px]"
|
||||
id="sidebar"
|
||||
th:fragment="stepsSummary(formData)"
|
||||
>
|
||||
<ol
|
||||
class="grid grid-cols-[repeat(4,_auto)] gap-x-5 content-center items-center place-content-center h-24 md:flex-col md:h-full md:grid-rows-[repeat(4,_auto)] md:grid-cols-1 md:content-start md:p-10 md:gap-y-7 text-white text-sm uppercase"
|
||||
>
|
||||
<li class="items-center md:grid md:gap-x-4 md:grid-cols-[auto_1fr]">
|
||||
<li
|
||||
class="items-center md:grid md:gap-x-4 md:grid-cols-[auto_1fr]"
|
||||
th:each="stepNum: ${formData.stepsAmount}"
|
||||
>
|
||||
<div
|
||||
class="grid place-content-center w-8 h-8 text-white rounded-full border border-white"
|
||||
class="grid place-content-center w-8 h-8 font-bold text-white rounded-full border border-white"
|
||||
th:classappend="${stepNum.index} == ${formData.userAnswers.currentStep} ? '!bg-light-blue !text-marine-blue'"
|
||||
th:text="${stepNum.index}"
|
||||
>
|
||||
1
|
||||
</div>
|
||||
<p class="hidden md:flex md:flex-col">
|
||||
<span class="text-light-gray">Step 1</span><span class="font-bold">Your info</span>
|
||||
<span class="text-light-gray"
|
||||
>Step <span th:text="${stepNum.index}">1</span></span
|
||||
><span class="font-bold" th:text="${stepNum.name}"
|
||||
>Your info</span
|
||||
>
|
||||
</p>
|
||||
</li>
|
||||
<li class="items-center md:grid md:gap-x-4 md:grid-cols-[auto_1fr]">
|
||||
<li
|
||||
class="items-center md:grid md:gap-x-4 md:grid-cols-[auto_1fr]"
|
||||
th:remove="all"
|
||||
>
|
||||
<div
|
||||
class="grid place-content-center w-8 h-8 text-white rounded-full border border-white"
|
||||
>
|
||||
2
|
||||
</div>
|
||||
<p class="hidden md:flex md:flex-col">
|
||||
<span class="text-light-gray">Step 2</span><span class="font-bold">Select plan</span>
|
||||
<span class="text-light-gray">Step 2</span
|
||||
><span class="font-bold">Select plan</span>
|
||||
</p>
|
||||
</li>
|
||||
<li class="items-center md:grid md:gap-x-4 md:grid-cols-[auto_1fr]">
|
||||
<li
|
||||
class="items-center md:grid md:gap-x-4 md:grid-cols-[auto_1fr]"
|
||||
th:remove="all"
|
||||
>
|
||||
<div
|
||||
class="grid place-content-center w-8 h-8 text-white rounded-full border border-white"
|
||||
>
|
||||
3
|
||||
</div>
|
||||
<p class="hidden md:flex md:flex-col">
|
||||
<span class="text-light-gray">Step 3</span><span class="font-bold">Add-ons</span>
|
||||
<span class="text-light-gray">Step 3</span
|
||||
><span class="font-bold">Add-ons</span>
|
||||
</p>
|
||||
</li>
|
||||
<li class="items-center md:grid md:gap-x-4 md:grid-cols-[auto_1fr]">
|
||||
<li
|
||||
class="items-center md:grid md:gap-x-4 md:grid-cols-[auto_1fr]"
|
||||
th:remove="all"
|
||||
>
|
||||
<div
|
||||
class="grid place-content-center w-8 h-8 text-white rounded-full border border-white"
|
||||
>
|
||||
4
|
||||
</div>
|
||||
<p class="hidden md:flex md:flex-col">
|
||||
<span class="text-light-gray">Step 4</span><span class="font-bold">summary</span>
|
||||
<span class="text-light-gray">Step 4</span
|
||||
><span class="font-bold">summary</span>
|
||||
</p>
|
||||
</li>
|
||||
</ol>
|
||||
@@ -93,35 +120,87 @@
|
||||
class="flex flex-col py-8 px-6 -mt-20 w-11/12 bg-white rounded-xl md:px-24 md:mt-0 md:w-full drop-shadow-xl md:drop-shadow-none"
|
||||
>
|
||||
<!-- Step 1 start -->
|
||||
<h1 class="text-2xl font-bold md:text-4xl text-marine-blue">Personal info</h1>
|
||||
<h1 class="text-2xl font-bold md:text-4xl text-marine-blue">
|
||||
Personal info
|
||||
</h1>
|
||||
<p class="py-3 text-cool-gray">
|
||||
Please provide your name, email address, and phone number.
|
||||
</p>
|
||||
<label for="name" class="pt-3 text-sm md:pt-5 md:pb-2 text-marine-blue">Name</label>
|
||||
<input
|
||||
id="name"
|
||||
type="text"
|
||||
placeholder="e.g. Stephen King"
|
||||
class="p-1 px-4 h-10 text-sm font-semibold rounded border md:p-6 md:px-4 md:text-base md:rounded-lg placeholder:text-cool-gray"
|
||||
/>
|
||||
<label for="email" class="pt-3 text-sm md:pt-5 md:pb-2 text-marine-blue"
|
||||
>Email Address</label
|
||||
<div class="contents">
|
||||
<label
|
||||
for="name"
|
||||
class="pt-3 text-sm md:pt-5 md:pb-2 text-marine-blue"
|
||||
>Name</label
|
||||
>
|
||||
<input
|
||||
id="name"
|
||||
th:value="${formData.userAnswers.step1.name}"
|
||||
name="name"
|
||||
type="text"
|
||||
required
|
||||
placeholder="e.g. Stephen King"
|
||||
class="p-1 px-4 h-10 text-sm font-semibold rounded border md:p-6 md:px-4 md:text-base md:rounded-lg focus:outline-none placeholder:text-cool-gray invalid:border-strawberry-red focus:border-marine-blue"
|
||||
/>
|
||||
</div>
|
||||
<div class="contents">
|
||||
<label
|
||||
for="email"
|
||||
class="pt-3 text-sm md:pt-5 md:pb-2 text-marine-blue"
|
||||
>Email Address</label
|
||||
>
|
||||
<input
|
||||
id="email"
|
||||
th:value="${formData.userAnswers.step1.email}"
|
||||
name="email"
|
||||
type="email"
|
||||
required
|
||||
placeholder="e.g. stephenking@lorem.com"
|
||||
class="p-1 px-4 h-10 text-sm font-semibold rounded border md:p-6 md:px-4 md:text-base md:rounded-lg focus:outline-none placeholder:text-cool-gray invalid:border-strawberry-red focus:border-marine-blue"
|
||||
/>
|
||||
</div>
|
||||
<!-- Following is email input field
|
||||
it has outer div that sets separate 'value' variable
|
||||
and innder div which denotes fragment, parametrized by this only variable
|
||||
now i should be able to render only this input field as fragment -->
|
||||
<div
|
||||
th:with="value=${formData.userAnswers.step1.phone},error=''"
|
||||
class="contents relative"
|
||||
>
|
||||
<input
|
||||
id="email"
|
||||
type="email"
|
||||
placeholder="e.g. stephenking@lorem.com"
|
||||
class="p-1 px-4 h-10 text-sm font-semibold rounded border md:p-6 md:px-4 md:text-base md:rounded-lg placeholder:text-cool-gray"
|
||||
/>
|
||||
<label for="phone" class="pt-3 text-sm md:pt-5 md:pb-2 text-marine-blue"
|
||||
>Phone Number</label
|
||||
>
|
||||
<input
|
||||
id="phone"
|
||||
type="tel"
|
||||
placeholder="e.g. +1 234 567 890"
|
||||
class="p-1 px-4 h-10 text-sm font-semibold rounded border md:p-6 md:px-4 md:text-base md:rounded-lg placeholder:text-cool-gray"
|
||||
/>
|
||||
<div
|
||||
class="contents"
|
||||
hx-target="this"
|
||||
hx-swap="outerHTML"
|
||||
th:fragment="email-input (value,error)"
|
||||
>
|
||||
<label
|
||||
for="phone"
|
||||
class="pt-3 text-sm md:pt-5 md:pb-2 text-marine-blue"
|
||||
>Phone Number</label
|
||||
>
|
||||
<input
|
||||
id="phone"
|
||||
th:value="${value}"
|
||||
name="phone"
|
||||
type="tel"
|
||||
required
|
||||
placeholder="e.g. +1 234 567 890"
|
||||
class="p-1 px-4 h-10 text-sm font-semibold rounded border md:p-6 md:px-4 md:text-base md:rounded-lg focus:outline-none placeholder:text-cool-gray invalid:border-strawberry-red focus:border-marine-blue"
|
||||
th:classappend="${!error.isEmpty} ? 'border-strawberry-red' : ''"
|
||||
hx-post="/step1/phonenumber"
|
||||
hx-indicator="#ind"
|
||||
/>
|
||||
<div
|
||||
th:if="${error} != null"
|
||||
th:text="${error}"
|
||||
class="text-sm text-strawberry-red">Please enter valid phone number</div>
|
||||
<img
|
||||
id="ind"
|
||||
src="../public/images/tail-spin.svg"
|
||||
th:src="'public/images/tail-spin.svg'"
|
||||
class="absolute w-14 h-14 htmx-indicator"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Step 1 end -->
|
||||
</section>
|
||||
@@ -131,13 +210,19 @@
|
||||
class="flex flex-row items-center py-4 w-full bg-white md:items-end md:h-full"
|
||||
>
|
||||
<div class="grow"></div>
|
||||
<input
|
||||
type="submit"
|
||||
class="grid place-content-center mr-3 w-24 h-10 text-sm font-semibold text-white rounded md:mr-24 md:w-32 md:h-12 md:text-base md:rounded-lg bg-marine-blue"
|
||||
value="Next Step"
|
||||
/>
|
||||
<a
|
||||
th:remove="all"
|
||||
href="step2.html"
|
||||
class="grid place-content-center mr-3 w-24 h-10 text-sm font-semibold text-white rounded md:mr-24 md:w-32 md:h-12 md:text-base md:rounded-lg bg-marine-blue"
|
||||
>Next Step</a
|
||||
>
|
||||
</section>
|
||||
</article>
|
||||
</form>
|
||||
<div class="fixed inset-x-0 bottom-0 attribution">
|
||||
Challenge by
|
||||
<a href="https://www.frontendmentor.io?ref=challenge" target="_blank"
|
||||
|
||||
@@ -36,13 +36,19 @@
|
||||
<![endif]-->
|
||||
|
||||
<main class="grid place-content-center h-screen">
|
||||
<article
|
||||
<form
|
||||
class="flex flex-col items-center w-screen h-screen md:grid md:items-start md:p-5 md:bg-white md:rounded-2xl md:grid-cols-[auto_1fr] md:w-desktop-form md:h-desktop-form md:drop-shadow-2xl"
|
||||
id="form-step"
|
||||
hx-post="/submit-step/2/3"
|
||||
hx-swap="outerHTML"
|
||||
action="/submit-step/2/3"
|
||||
method="post"
|
||||
th:fragment="formFragment(formData)"
|
||||
>
|
||||
<summary
|
||||
class="w-full h-44 bg-no-repeat md:row-span-2 bg-sidebar-mobile marker:text-white md:bg-sidebar-desktop md:h-[568px] md:w-[274px]"
|
||||
id="sidebar"
|
||||
th:replace="~{step1::stepsSummary (${formData})}"
|
||||
>
|
||||
<ol
|
||||
class="grid grid-cols-[repeat(4,_auto)] gap-x-5 content-center items-center place-content-center h-24 md:flex-col md:h-full md:grid-rows-[repeat(4,_auto)] md:grid-cols-1 md:content-start md:p-10 md:gap-y-7 text-white text-sm uppercase"
|
||||
@@ -101,71 +107,122 @@
|
||||
<h1 class="text-2xl font-bold md:text-4xl text-marine-blue">
|
||||
Select your plan
|
||||
</h1>
|
||||
<p class="py-3 text-cool-gray">
|
||||
<p class="py-3 mb-4 text-cool-gray">
|
||||
You have the option of monthly or yearly billing.
|
||||
</p>
|
||||
<div
|
||||
class="flex flex-col w-full md:flex-row"
|
||||
class="flex flex-col gap-y-3 my-3 w-full md:flex-row md:gap-x-4"
|
||||
id="plan-type-inputs"
|
||||
th:fragment="planTypesInputs(formData)"
|
||||
>
|
||||
<label for="ArcadePlanType" class="relative h-20 md:w-32">
|
||||
<label
|
||||
for="ArcadePlanType"
|
||||
class="relative h-20 md:h-40 md:grow"
|
||||
th:each="planType: ${formData.availablePlans}"
|
||||
th:for="${planType}"
|
||||
>
|
||||
<input
|
||||
id="ArcadePlanType"
|
||||
th:id="${planType}"
|
||||
type="radio"
|
||||
name="plan-type"
|
||||
value="Arcade"
|
||||
th:value="${planType}"
|
||||
class="hidden peer"
|
||||
th:checked="${formData.userAnswers.step2.planType.toString()} == ${planType.toString()}"
|
||||
checked
|
||||
/>
|
||||
<div
|
||||
class="absolute inset-y-0 inset-x-0 rounded-lg border border-cool-gray peer-checked:border-purplish-blue peer-checked:bg-magnolia"
|
||||
class="grid absolute inset-y-0 inset-x-0 place-content-center h-full rounded-lg border md:grid-cols-1 md:p-4 grid-cols-[auto_1fr] border-light-gray peer-checked:border-purplish-blue peer-checked:bg-magnolia/50 md:grid-rows-[1fr_auto_auto] hover:bg-magnolia/[.1] hover:border-purplish-blue"
|
||||
>
|
||||
<span class="">Arcade</span>
|
||||
<img
|
||||
class="place-self-center px-4 md:row-span-1 md:place-self-start md:px-0"
|
||||
th:src="${planType.iconPath}" src="../public/images/icon-arcade.svg" alt="" />
|
||||
<div class="flex flex-col items-start">
|
||||
<h2 th:text="${planType}" class="font-semibold text-marine-blue">Arcade</h2>
|
||||
<p
|
||||
th:text="|$${formData.planCost(planType)}/${formData.periodCostLabel}|"
|
||||
class="text-sm text-cool-gray"
|
||||
>
|
||||
$9/mo
|
||||
</p>
|
||||
<p th:if="${formData.userAnswers.step2.isYearly}" class="text-xs text-marine-blue">
|
||||
2 months free
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label for="AdvancedPlanType" class="relative h-20 md:w-32">
|
||||
<label
|
||||
for="AdvancedPlanType"
|
||||
class="relative h-20 md:w-32"
|
||||
th:remove="all"
|
||||
>
|
||||
<input
|
||||
id="AdvancedPlanType"
|
||||
type="radio"
|
||||
name="plan-type"
|
||||
value="Advanced"
|
||||
class="hidden peer"
|
||||
th:checked="${formData.userAnswers.step2.planType.toString()} == 'Advanced'"
|
||||
/>
|
||||
<div
|
||||
class="absolute inset-y-0 inset-x-0 rounded-lg border border-cool-gray peer-checked:border-purplish-blue peer-checked:bg-magnolia"
|
||||
>
|
||||
<span>Advanced</span>
|
||||
<img src="../public/images/icon-advanced.svg" alt="" />
|
||||
<h2>Advanced</h2>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label for="ProPlanType" class="relative h-20 md:w-32">
|
||||
<label
|
||||
for="ProPlanType"
|
||||
class="relative h-20 md:w-32"
|
||||
th:remove="all"
|
||||
>
|
||||
<input
|
||||
id="ProPlanType"
|
||||
type="radio"
|
||||
name="plan-type"
|
||||
value="Pro"
|
||||
class="hidden peer"
|
||||
th:checked="${formData.userAnswers.step2.planType.toString()} == 'Pro'"
|
||||
/>
|
||||
<div
|
||||
class="absolute inset-y-0 inset-x-0 rounded-lg border border-cool-gray peer-checked:border-purplish-blue peer-checked:bg-magnolia"
|
||||
>
|
||||
<span>Pro</span>
|
||||
<img src="../public/images/icon-pro.svg" alt="" />
|
||||
<h2>Pro</h2>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-flow-col-dense place-content-center w-full rounded-lg bg-magnolia">
|
||||
<div
|
||||
class="grid grid-flow-col-dense place-content-center mt-3 w-full rounded-lg md:mt-5 bg-light-gray/25"
|
||||
>
|
||||
<div
|
||||
class="inline-grid grid-cols-3 place-items-center h-12 text-sm font-bold"
|
||||
>
|
||||
<input
|
||||
class="mr-2 w-9 h-5 ml-2 rounded-full appearance-none mt-[0.3rem] bg-marine-blue after:absolute after:h-3 after:w-3 after:rounded-full after:border-none after:bg-neutral-100 after:transition-[background-color_0.2s,transform_0.2s] checked:after:ml-[1.2rem] after:ml-[0.25rem] after:mt-[0.25rem] hover:cursor-pointer col-start-2 row-start-1 peer"
|
||||
class="mr-2 w-9 h-5 ml-2 rounded-full appearance-none mt-[0.3rem] bg-marine-blue after:absolute after:h-3 after:w-3 after:rounded-full after:border-none after:bg-neutral-100 after:transition-[background-color_0.2s,transform_0.2s] checked:after:ml-[1.2rem] after:ml-[0.25rem] after:mt-[0.25rem] hover:cursor-pointer col-start-2 row-start-1 peer md:mx-4"
|
||||
type="checkbox"
|
||||
name="isPackageYearly"
|
||||
role="switch"
|
||||
id="packageDuration"
|
||||
th:checked="${formData.userAnswers.step2.isYearly}"
|
||||
hx-post="/step2/planTypeInputs"
|
||||
hx-target="#plan-type-inputs"
|
||||
hx-swap="outerHTML"
|
||||
/>
|
||||
<span class="row-start-1 text-marine-blue peer-checked:text-cool-gray">Monthly</span>
|
||||
<span class="row-start-1 text-cool-gray peer-checked:text-marine-blue">Yearly</span>
|
||||
<p
|
||||
class="row-start-1 text-marine-blue peer-checked:text-cool-gray"
|
||||
>
|
||||
Monthly
|
||||
</p>
|
||||
<p
|
||||
class="row-start-1 text-cool-gray peer-checked:text-marine-blue"
|
||||
>
|
||||
Yearly
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -177,18 +234,27 @@
|
||||
class="flex flex-row items-center py-4 w-full bg-white md:items-end md:h-full"
|
||||
>
|
||||
<a
|
||||
hx-post="/submit-step/2/1"
|
||||
hx-swap="outerHTML"
|
||||
hx-target="#form-step"
|
||||
href="step1.html"
|
||||
class="ml-6 text-sm font-semibold md:pb-3 md:ml-20 md:text-base text-cool-gray"
|
||||
class="ml-6 text-sm font-semibold md:pb-3 md:ml-24 md:text-base text-cool-gray"
|
||||
>Go Back</a
|
||||
>
|
||||
<div class="grow"></div>
|
||||
<input
|
||||
type="submit"
|
||||
class="grid place-content-center mr-3 w-24 h-10 text-sm font-semibold text-white rounded md:mr-24 md:w-32 md:h-12 md:text-base md:rounded-lg bg-marine-blue"
|
||||
value="Next Step"
|
||||
/>
|
||||
<a
|
||||
th:remove="all"
|
||||
href="step3.html"
|
||||
class="grid place-content-center mr-3 w-24 h-10 text-sm font-semibold text-white rounded md:mr-24 md:w-32 md:h-12 md:text-base md:rounded-lg bg-marine-blue"
|
||||
>Next Step</a
|
||||
>
|
||||
</section>
|
||||
</article>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -36,13 +36,19 @@
|
||||
<![endif]-->
|
||||
|
||||
<main class="grid place-content-center h-screen">
|
||||
<article
|
||||
<form
|
||||
class="flex flex-col items-center w-screen h-screen md:grid md:items-start md:p-5 md:bg-white md:rounded-2xl md:grid-cols-[auto_1fr] md:w-desktop-form md:h-desktop-form md:drop-shadow-2xl"
|
||||
id="form-step"
|
||||
hx-post="/submit-step/3/4"
|
||||
hx-swap="outerHTML"
|
||||
action="/submit-step/3/4"
|
||||
method="post"
|
||||
th:fragment="formFragment(formData)"
|
||||
>
|
||||
<summary
|
||||
class="w-full h-44 bg-no-repeat md:row-span-2 bg-sidebar-mobile marker:text-white md:bg-sidebar-desktop md:h-[568px] md:w-[274px]"
|
||||
id="sidebar"
|
||||
th:replace="~{step1::stepsSummary (${formData})}"
|
||||
>
|
||||
<ol
|
||||
class="grid grid-cols-[repeat(4,_auto)] gap-x-5 content-center items-center place-content-center h-24 md:flex-col md:h-full md:grid-rows-[repeat(4,_auto)] md:grid-cols-1 md:content-start md:p-10 md:gap-y-7 text-white text-sm uppercase"
|
||||
@@ -101,62 +107,100 @@
|
||||
<h1 class="text-2xl font-bold md:text-4xl text-marine-blue">
|
||||
Pick add-ons
|
||||
</h1>
|
||||
<p class="py-3 text-cool-gray">
|
||||
<p class="py-3 md:pb-10 text-cool-gray">
|
||||
Add-ons help enhance your gaming experience.
|
||||
</p>
|
||||
<div
|
||||
class="flex flex-col w-full text-sm md:text-base"
|
||||
>
|
||||
<label for="multiplayer-games" class="relative pl-6 h-20 md:w-full">
|
||||
<div class="flex flex-col gap-y-3 w-full text-sm md:text-base">
|
||||
<label
|
||||
th:each="addon: ${formData.availableAddons}"
|
||||
for="multiplayer-games"
|
||||
th:for="${addon}"
|
||||
class="relative pl-5 h-16 md:w-full md:h-20"
|
||||
>
|
||||
<input
|
||||
id="multiplayer-games"
|
||||
th:id="${addon}"
|
||||
type="checkbox"
|
||||
value="OnlineService"
|
||||
th:value="${addon}"
|
||||
name="addon-services"
|
||||
class="my-7 w-6 h-6 peer"
|
||||
class="absolute z-40 my-5 w-6 h-6 text-white rounded-lg border md:my-7 accent-purplish-blue border-light-gray peer"
|
||||
th:checked="${formData.userAnswers.step3.containsAddon(addon)}"
|
||||
/>
|
||||
<div
|
||||
class="absolute inset-y-0 inset-x-0 rounded-lg border border-cool-gray peer-checked:border-purplish-blue peer-checked:bg-magnolia/50"
|
||||
class="absolute inset-y-0 inset-x-0 z-20 rounded-lg border border-cool-gray peer-checked:border-purplish-blue peer-checked:bg-magnolia/75 hover:bg-magnolia/[.1] hover:border-purplish-blue"
|
||||
>
|
||||
<div class="grid place-content-center ml-20 h-full grid-cols-[1fr_100px]">
|
||||
<h1>Online Service</h1>
|
||||
<p>Access to multiplayer games</p>
|
||||
<p class="col-start-2 row-span-2 row-start-1 self-center">+$1/mo</p>
|
||||
<div
|
||||
class="grid place-content-center ml-16 h-full grid-cols-[1fr_70px]"
|
||||
>
|
||||
<h1 th:text="${addon.name}"
|
||||
class="font-bold text-marine-blue"
|
||||
>Online Service</h1>
|
||||
<p th:text="${addon.description}"
|
||||
class="text-xs text-cool-gray"
|
||||
>
|
||||
Access to multiplayer games
|
||||
</p>
|
||||
<p
|
||||
class="col-start-2 row-span-2 row-start-1 self-center text-purplish-blue"
|
||||
th:text="|+$${formData.addonCost(addon)}/${formData.periodCostLabel}|"
|
||||
>
|
||||
+$1/mo
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label for="larger-storage" class="relative pl-6 h-20 md:w-full">
|
||||
<label
|
||||
for="larger-storage"
|
||||
class="relative pl-6 h-20 md:w-full"
|
||||
th:remove="all"
|
||||
>
|
||||
<input
|
||||
id="larger-storage"
|
||||
type="checkbox"
|
||||
name="addon-services"
|
||||
value="LargerStorage"
|
||||
class="my-7 w-6 h-6 peer"
|
||||
th:checked="${formData.userAnswers.step3.containsAddon('LargerStorage')}"
|
||||
/>
|
||||
<div
|
||||
class="absolute inset-y-0 inset-x-0 rounded-lg border border-cool-gray peer-checked:border-purplish-blue peer-checked:bg-magnolia/50"
|
||||
>
|
||||
<div class="grid place-content-center ml-20 h-full grid-cols-[1fr_100px]">
|
||||
<div
|
||||
class="grid place-content-center ml-20 h-full grid-cols-[1fr_100px]"
|
||||
>
|
||||
<h1>Larger storage</h1>
|
||||
<p>Extra 1TB of cloud save</p>
|
||||
<p class="col-start-2 row-span-2 row-start-1 self-center">+$2/mo</p>
|
||||
<p class="col-start-2 row-span-2 row-start-1 self-center">
|
||||
+$2/mo
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<label for="custom-profile" class="relative pl-6 h-20 md:w-full">
|
||||
<label
|
||||
for="custom-profile"
|
||||
class="relative pl-6 h-20 md:w-full"
|
||||
th:remove="all"
|
||||
>
|
||||
<input
|
||||
id="custom-profile"
|
||||
type="checkbox"
|
||||
name="addon-services"
|
||||
value="CustomProfile"
|
||||
class="my-7 w-6 h-6 peer"
|
||||
th:checked="${formData.userAnswers.step3.containsAddon('CustomProfile')}"
|
||||
/>
|
||||
<div
|
||||
class="absolute inset-y-0 inset-x-0 rounded-lg border border-cool-gray peer-checked:border-purplish-blue peer-checked:bg-magnolia/50"
|
||||
>
|
||||
<div class="grid place-content-center ml-20 h-full grid-cols-[1fr_100px]">
|
||||
<div
|
||||
class="grid place-content-center ml-20 h-full grid-cols-[1fr_100px]"
|
||||
>
|
||||
<h1>Customizable Profile</h1>
|
||||
<p>Custom theme on your profile</p>
|
||||
<p class="col-start-2 row-span-2 row-start-1 self-center">+$2/mo</p>
|
||||
<p class="col-start-2 row-span-2 row-start-1 self-center">
|
||||
+$2/mo
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
@@ -170,18 +214,28 @@
|
||||
class="flex flex-row items-center py-4 w-full bg-white md:items-end md:h-full"
|
||||
>
|
||||
<a
|
||||
hx-post="/submit-step/3/2"
|
||||
hx-swap="outerHTML"
|
||||
hx-target="#form-step"
|
||||
href="step2.html"
|
||||
class="ml-6 text-sm font-semibold md:pb-3 md:ml-20 md:text-base text-cool-gray"
|
||||
class="ml-6 text-sm font-semibold md:pb-3 md:ml-24 md:text-base text-cool-gray"
|
||||
>Go Back</a
|
||||
>
|
||||
<div class="grow"></div>
|
||||
<input
|
||||
type="submit"
|
||||
href="step4.html"
|
||||
class="grid place-content-center mr-3 w-24 h-10 text-sm font-semibold text-white rounded md:mr-24 md:w-32 md:h-12 md:text-base md:rounded-lg bg-marine-blue"
|
||||
value="Next Step"
|
||||
/>
|
||||
<a
|
||||
th:remove="all"
|
||||
href="step4.html"
|
||||
class="grid place-content-center mr-3 w-24 h-10 text-sm font-semibold text-white rounded md:mr-24 md:w-32 md:h-12 md:text-base md:rounded-lg bg-marine-blue"
|
||||
>Next Step</a
|
||||
>
|
||||
</section>
|
||||
</article>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -36,13 +36,19 @@
|
||||
<![endif]-->
|
||||
|
||||
<main class="grid place-content-center h-screen">
|
||||
<article
|
||||
<form
|
||||
class="flex flex-col items-center w-screen h-screen md:grid md:items-start md:p-5 md:bg-white md:rounded-2xl md:grid-cols-[auto_1fr] md:w-desktop-form md:h-desktop-form md:drop-shadow-2xl"
|
||||
id="form-step"
|
||||
hx-post="/submit-step/4/5"
|
||||
action="/submit-step/4/5"
|
||||
hx-swap="outerHTML"
|
||||
method="post"
|
||||
th:fragment="formFragment(formData)"
|
||||
>
|
||||
<summary
|
||||
class="w-full h-44 bg-no-repeat md:row-span-2 bg-sidebar-mobile marker:text-white md:bg-sidebar-desktop md:h-[568px] md:w-[274px]"
|
||||
id="sidebar"
|
||||
th:replace="~{step1::stepsSummary (${formData})}"
|
||||
>
|
||||
<ol
|
||||
class="grid grid-cols-[repeat(4,_auto)] gap-x-5 content-center items-center place-content-center h-24 md:flex-col md:h-full md:grid-rows-[repeat(4,_auto)] md:grid-cols-1 md:content-start md:p-10 md:gap-y-7 text-white text-sm uppercase"
|
||||
@@ -98,28 +104,69 @@
|
||||
class="flex flex-col py-8 px-6 -mt-20 w-11/12 bg-white rounded-xl md:px-24 md:mt-0 md:w-full drop-shadow-xl md:drop-shadow-none"
|
||||
>
|
||||
<!-- Step 3 start -->
|
||||
<h1 class="text-2xl font-bold md:text-4xl text-marine-blue">Finishing up</h1>
|
||||
<p class="py-3 text-cool-gray">Double-check everything looks OK before confirming.</p>
|
||||
<h1 class="text-2xl font-bold md:text-4xl text-marine-blue">
|
||||
Finishing up
|
||||
</h1>
|
||||
<p class="pt-3 pb-5 md:pb-8 text-cool-gray">
|
||||
Double-check everything looks OK before confirming.
|
||||
</p>
|
||||
<div
|
||||
class="flex flex-col w-full text-sm rounded-lg divide-y md:text-base bg-magnolia"
|
||||
class="flex flex-col w-full text-sm rounded-lg divide-y md:text-base bg-magnolia/75"
|
||||
id="selection-overview"
|
||||
>
|
||||
<div id="selected-plan">
|
||||
Arcade (Monthly) Change $90/y
|
||||
<div id="selected-plan" class="grid p-3 md:p-6 grid-cols-[1fr_auto]">
|
||||
<h2 th:text="${formData.fullPlanName}"
|
||||
class="font-bold text-marine-blue"
|
||||
>Arcade (Monthly)</h2>
|
||||
<p
|
||||
th:text="|$${formData.selectedPlanCost}/${formData.periodCostLabel}|"
|
||||
class="row-span-2 self-end font-bold text-marine-blue"
|
||||
>
|
||||
$90/y
|
||||
</p>
|
||||
<a
|
||||
hx-post="/submit-step/4/2"
|
||||
hx-swap="outerHTML"
|
||||
hx-target="#form-step"
|
||||
href="step3.html"
|
||||
hx-params="not form-confirmed"
|
||||
class="underline text-cool-gray"
|
||||
>Change</a
|
||||
>
|
||||
</div>
|
||||
<div id="selected-addons"
|
||||
class="flex flex-col"
|
||||
<div id="selected-addons" class="flex flex-col gap-y-4 p-3 md:p-6 mp-10"
|
||||
th:if="not ${formData.userAnswers.step3.addonsAsJava.isEmpty}"
|
||||
>
|
||||
<div>
|
||||
Online service +$10/yr
|
||||
</div>
|
||||
<div>
|
||||
Larger storage +$20/yr
|
||||
<div
|
||||
th:each="addon: ${formData.userAnswers.step3.addonsAsJava}"
|
||||
class="flex flex-row"
|
||||
>
|
||||
<p th:text="${addon.name}" class="grow text-cool-gray">Online service</p>
|
||||
<p
|
||||
th:text="|+$${formData.addonCost(addon)}/${formData.periodCostLabel}|"
|
||||
>
|
||||
+$10/yr
|
||||
</p>
|
||||
</div>
|
||||
<div th:remove="all">Larger storage +$20/yr</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>Total (per year) $120</p>
|
||||
<section class="flex flex-row p-3 mt-5 md:px-6">
|
||||
<p class="grow text-cool-gray">
|
||||
Total (per
|
||||
<span
|
||||
th:text="${formData.userAnswers.step2.isYearly} ? 'year' : 'month'"
|
||||
>year</span
|
||||
>)
|
||||
</p>
|
||||
<p
|
||||
th:text="|+$${formData.fullOrderPrice}/${formData.periodCostLabel}|"
|
||||
class="font-bold md:text-lg text-purplish-blue"
|
||||
>
|
||||
$120
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<!-- Step 3 end -->
|
||||
</section>
|
||||
@@ -129,18 +176,29 @@
|
||||
class="flex flex-row items-center py-4 w-full bg-white md:items-end md:h-full"
|
||||
>
|
||||
<a
|
||||
hx-post="/submit-step/4/3"
|
||||
hx-swap="outerHTML"
|
||||
hx-target="#form-step"
|
||||
href="step3.html"
|
||||
class="ml-6 text-sm font-semibold md:pb-3 md:ml-20 md:text-base text-cool-gray"
|
||||
class="ml-6 text-sm font-semibold md:pb-3 md:ml-24 md:text-base text-cool-gray"
|
||||
hx-params="not form-confirmed"
|
||||
>Go Back</a
|
||||
>
|
||||
<div class="grow"></div>
|
||||
<input type="hidden" name="form-confirmed" value="true" />
|
||||
<input
|
||||
type="submit"
|
||||
class="grid place-content-center mr-3 w-24 h-10 text-sm font-semibold text-white rounded md:mr-24 md:w-32 md:h-12 md:text-base md:rounded-lg bg-purplish-blue"
|
||||
value="Confirm"
|
||||
/>
|
||||
<a
|
||||
href="step4.html"
|
||||
th:remove="all"
|
||||
href="step5.html"
|
||||
class="grid place-content-center mr-3 w-24 h-10 text-sm font-semibold text-white rounded md:mr-24 md:w-32 md:h-12 md:text-base md:rounded-lg bg-purplish-blue"
|
||||
>Confirm</a
|
||||
>
|
||||
</section>
|
||||
</article>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -35,16 +35,85 @@
|
||||
</p>
|
||||
<![endif]-->
|
||||
|
||||
<main class="bg-green-200">
|
||||
<!-- Step 5 start -->
|
||||
<main class="grid place-content-center h-screen">
|
||||
<article
|
||||
class="flex flex-col items-center w-screen h-screen md:grid md:items-start md:p-5 md:bg-white md:rounded-2xl md:grid-cols-[auto_1fr] md:w-desktop-form md:h-desktop-form md:drop-shadow-2xl"
|
||||
id="form-step"
|
||||
th:fragment="formFragment(formData)"
|
||||
>
|
||||
<summary
|
||||
class="w-full h-44 bg-no-repeat md:row-span-2 bg-sidebar-mobile marker:text-white md:bg-sidebar-desktop md:h-[568px] md:w-[274px]"
|
||||
id="sidebar"
|
||||
th:replace="~{step1::stepsSummary (${formData})}"
|
||||
>
|
||||
<ol
|
||||
class="grid grid-cols-[repeat(4,_auto)] gap-x-5 content-center items-center place-content-center h-24 md:flex-col md:h-full md:grid-rows-[repeat(4,_auto)] md:grid-cols-1 md:content-start md:p-10 md:gap-y-7 text-white text-sm uppercase"
|
||||
>
|
||||
<li class="items-center md:grid md:gap-x-4 md:grid-cols-[auto_1fr]">
|
||||
<div
|
||||
class="grid place-content-center w-8 h-8 text-white rounded-full border border-white"
|
||||
>
|
||||
1
|
||||
</div>
|
||||
<p class="hidden md:flex md:flex-col">
|
||||
<span class="text-light-gray">Step 1</span
|
||||
><span class="font-bold">Your info</span>
|
||||
</p>
|
||||
</li>
|
||||
<li class="items-center md:grid md:gap-x-4 md:grid-cols-[auto_1fr]">
|
||||
<div
|
||||
class="grid place-content-center w-8 h-8 text-white rounded-full border border-white"
|
||||
>
|
||||
2
|
||||
</div>
|
||||
<p class="hidden md:flex md:flex-col">
|
||||
<span class="text-light-gray">Step 2</span
|
||||
><span class="font-bold">Select plan</span>
|
||||
</p>
|
||||
</li>
|
||||
<li class="items-center md:grid md:gap-x-4 md:grid-cols-[auto_1fr]">
|
||||
<div
|
||||
class="grid place-content-center w-8 h-8 text-white rounded-full border border-white"
|
||||
>
|
||||
3
|
||||
</div>
|
||||
<p class="hidden md:flex md:flex-col">
|
||||
<span class="text-light-gray">Step 3</span
|
||||
><span class="font-bold">Add-ons</span>
|
||||
</p>
|
||||
</li>
|
||||
<li class="items-center md:grid md:gap-x-4 md:grid-cols-[auto_1fr]">
|
||||
<div
|
||||
class="grid place-content-center w-8 h-8 text-white rounded-full border border-white"
|
||||
>
|
||||
4
|
||||
</div>
|
||||
<p class="hidden md:flex md:flex-col">
|
||||
<span class="text-light-gray">Step 4</span
|
||||
><span class="font-bold">summary</span>
|
||||
</p>
|
||||
</li>
|
||||
</ol>
|
||||
</summary>
|
||||
<section
|
||||
id="multipage-form-container"
|
||||
class="flex flex-col gap-y-4 items-center py-20 px-8 -mt-20 w-11/12 bg-white rounded-xl md:row-span-2 md:justify-center md:px-24 md:mt-0 md:w-full md:h-full drop-shadow-xl md:drop-shadow-none"
|
||||
>
|
||||
<!-- Step 5 start -->
|
||||
|
||||
Thank you!
|
||||
|
||||
Thanks for confirming your subscription! We hope you have fun
|
||||
using our platform. If you ever need support, please feel free
|
||||
to email us at support@loremgaming.com.
|
||||
<img src="../public/images/icon-thank-you.svg" alt="" class="mb-2 w-14 h-14 md:w-20 md:h-20" />
|
||||
<h2 class="text-2xl font-bold md:mt-2 md:text-4xl text-marine-blue">Thank you!</h2>
|
||||
<p class="text-center text-cool-gray">
|
||||
Thanks for confirming your subscription! We hope you have fun
|
||||
using our platform. If you ever need support, please feel free
|
||||
to email us at support@loremgaming.com.
|
||||
</p>
|
||||
|
||||
<!-- Step 5 end -->
|
||||
|
||||
</section>
|
||||
<div class="md:hidden grow"></div>
|
||||
</article>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,10 +1,219 @@
|
||||
package multistepform
|
||||
|
||||
import java.util.UUID
|
||||
import scala.jdk.CollectionConverters._
|
||||
|
||||
object Models {
|
||||
|
||||
/** Labels and form info which dynamically depend on user answers e.g plan
|
||||
* name 'Arcade (Yearly)' vs 'Pro (Monthly)'
|
||||
*/
|
||||
final case class FormData(
|
||||
userAnswers: Answers
|
||||
) {
|
||||
val stepsAmount = Steps.values.toList.asJava
|
||||
|
||||
// yeah, in real world it will not be this simple
|
||||
def yearlyCost(monthlyCost: Int): Int = 10 * monthlyCost
|
||||
|
||||
def periodCostLabel: String = {
|
||||
if (userAnswers.step2.isYearly) "yr" else "mo"
|
||||
}
|
||||
|
||||
def selectedPlanCost: Int = planCost(userAnswers.step2.planType)
|
||||
|
||||
def planCost(plan: PlanType): Int = {
|
||||
val monthlyPlanCost = plan.monthlyCost
|
||||
if (userAnswers.step2.isYearly) yearlyCost(monthlyPlanCost)
|
||||
else monthlyPlanCost
|
||||
}
|
||||
|
||||
def addonCost(addon: Addons): Int = {
|
||||
val monthCost = addon.monthlyCost
|
||||
if (userAnswers.step2.isYearly) yearlyCost(monthCost) else monthCost
|
||||
}
|
||||
|
||||
def fullPlanName: String = {
|
||||
val period = if (userAnswers.step2.isYearly) "Yearly" else "Monthly"
|
||||
s"${userAnswers.step2.planType} (${period})"
|
||||
}
|
||||
|
||||
def fullOrderPrice: Int = {
|
||||
selectedPlanCost + userAnswers.step3.addons.toList.map(addonCost).sum
|
||||
}
|
||||
|
||||
def availablePlans = PlanType.values.toList.asJava
|
||||
|
||||
def availableAddons = Addons.values.toList.asJava
|
||||
}
|
||||
|
||||
final case class Answers(
|
||||
sessionId: String = "id1",
|
||||
currentStep: Int = 1,
|
||||
)
|
||||
sessionId: String = "",
|
||||
currentStep: Int = 1,
|
||||
step1: StepAnswers.Step1 = StepAnswers.Step1(),
|
||||
step2: StepAnswers.Step2 = StepAnswers.Step2(),
|
||||
step3: StepAnswers.Step3 = StepAnswers.Step3(),
|
||||
step4: StepAnswers.Step4 = StepAnswers.Step4()
|
||||
) {
|
||||
// this is not enforced by compiler, sad, maintain by hand in html template files
|
||||
def fragmentName: String = s"step${currentStep}"
|
||||
|
||||
def updateStep(stepNum: Int, rawData: String, nextStep: Int): Answers = {
|
||||
stepNum match {
|
||||
case 1 =>
|
||||
this.copy(
|
||||
step1 = this.step1.fromFormData(rawData),
|
||||
currentStep = nextStep
|
||||
)
|
||||
case 2 =>
|
||||
this.copy(
|
||||
step2 = this.step2.fromFormData(rawData),
|
||||
currentStep = nextStep
|
||||
)
|
||||
case 3 =>
|
||||
this.copy(
|
||||
step3 = this.step3.fromFormData(rawData),
|
||||
currentStep = nextStep
|
||||
)
|
||||
case 4 =>
|
||||
this.copy(
|
||||
step4 = this.step4.fromFormData(rawData),
|
||||
currentStep = nextStep
|
||||
)
|
||||
case _ => this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** TODO would be nice to connect answers to the steps enum in some helpful
|
||||
* way.
|
||||
*/
|
||||
enum Steps(val index: Int, val name: String):
|
||||
case Step1 extends Steps(1, "Your info")
|
||||
case Step2 extends Steps(2, "Select plan")
|
||||
case Step3 extends Steps(3, "Add-ons")
|
||||
case Step4 extends Steps(4, "Summary")
|
||||
|
||||
enum PlanType(val monthlyCost: Int, val iconPath: String):
|
||||
case Arcade extends PlanType(9, "public/images/icon-arcade.svg")
|
||||
case Advanced extends PlanType(12, "public/images/icon-advanced.svg")
|
||||
case Pro extends PlanType(15, "public/images/icon-pro.svg")
|
||||
def name(): String = {
|
||||
this.toString().replaceAll("([a-z])([A-Z])", "$1 $2")
|
||||
}
|
||||
|
||||
enum Addons(val monthlyCost: Int, val description: String):
|
||||
case OnlineService extends Addons(1, "Access to multiplayer games")
|
||||
case LargerStorage extends Addons(2, "Extra 1TB of cloud storage")
|
||||
case CustomProfile extends Addons(2, "Custom theme on your profile")
|
||||
|
||||
/** Change camel case into human readable. Adding single space before each
|
||||
* uppercase
|
||||
*/
|
||||
def name(): String = {
|
||||
this.toString().replaceAll("([a-z])([A-Z])", "$1 $2")
|
||||
}
|
||||
|
||||
sealed trait StepAnswers {
|
||||
def fromFormData(rawData: String): StepAnswers
|
||||
def submitted: Boolean
|
||||
}
|
||||
object StepAnswers {
|
||||
final case class Step1(
|
||||
name: String = "",
|
||||
email: String = "",
|
||||
phone: String = "",
|
||||
override val submitted: Boolean = false
|
||||
) extends StepAnswers {
|
||||
override def fromFormData(rawData: String): Step1 = {
|
||||
println(s"parsing step 1 data $rawData")
|
||||
val fieldValues = rawData
|
||||
.split("&")
|
||||
.filterNot(_.isEmpty())
|
||||
.map { field =>
|
||||
val Array(name, value) = field.split("=")
|
||||
name -> value
|
||||
}
|
||||
.toMap
|
||||
|
||||
val name = fieldValues.getOrElse("name", "")
|
||||
val email = fieldValues.getOrElse("email", "")
|
||||
val phone = fieldValues.getOrElse("phone", "")
|
||||
|
||||
Step1(name, email, phone, submitted = true)
|
||||
}
|
||||
}
|
||||
final case class Step2(
|
||||
planType: PlanType = PlanType.Arcade,
|
||||
isYearly: Boolean = false,
|
||||
override val submitted: Boolean = false
|
||||
) extends StepAnswers {
|
||||
override def fromFormData(rawData: String): Step2 = {
|
||||
println(s"parsing step 2 data $rawData")
|
||||
val fieldValues = rawData
|
||||
.split("&")
|
||||
.filterNot(_.isEmpty())
|
||||
.map { field =>
|
||||
val Array(name, value) = field.split("=")
|
||||
name -> value
|
||||
}
|
||||
.toMap
|
||||
|
||||
val planType =
|
||||
PlanType.valueOf(fieldValues.getOrElse("plan-type", "Arcade"))
|
||||
val isYearly = fieldValues.get("isPackageYearly").contains("on")
|
||||
|
||||
Step2(planType, isYearly, submitted = true)
|
||||
}
|
||||
}
|
||||
final case class Step3(
|
||||
addons: Set[Addons] = Set.empty,
|
||||
override val submitted: Boolean = false
|
||||
) extends StepAnswers {
|
||||
def addonsAsJava = addons.asJava
|
||||
|
||||
def containsAddon(addonName: String): Boolean = {
|
||||
addons.contains(Addons.valueOf(addonName))
|
||||
}
|
||||
|
||||
override def fromFormData(rawData: String): Step3 = {
|
||||
println(s"parsing step 3 data $rawData")
|
||||
// for multiple checkboxes data comes in form of
|
||||
// addon-services=OnlineService&addon-services=CustomProfile
|
||||
val fieldValues = rawData
|
||||
.split("&")
|
||||
.filterNot(_.isEmpty())
|
||||
.map { field =>
|
||||
val Array(name, value) = field.split("=")
|
||||
name -> value
|
||||
}
|
||||
|
||||
val addonsStrings = fieldValues
|
||||
.groupMap(_._1)(_._2)
|
||||
.getOrElse("addon-services", Array.empty[String])
|
||||
println(s"in step 3 got strings ${addonsStrings.mkString(", ")}")
|
||||
val addons = addonsStrings.map(Addons.valueOf(_)).toSet
|
||||
|
||||
Step3(addons, submitted = true)
|
||||
}
|
||||
}
|
||||
final case class Step4(
|
||||
override val submitted: Boolean = false
|
||||
) extends StepAnswers {
|
||||
override def fromFormData(rawData: String): Step4 = {
|
||||
val fieldValues = rawData
|
||||
.split("&")
|
||||
.filterNot(_.isEmpty())
|
||||
.map { field =>
|
||||
println(s"working with field $field")
|
||||
val Array(name, value) = field.split("=")
|
||||
name -> value
|
||||
}
|
||||
.toMap
|
||||
|
||||
val isConfirmed = fieldValues.contains("form-confirmed")
|
||||
Step4(isConfirmed)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,16 @@ package multistepform
|
||||
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver
|
||||
import org.thymeleaf.TemplateEngine
|
||||
import org.thymeleaf.context.Context
|
||||
import cask.endpoints.ParamReader
|
||||
import java.util.UUID
|
||||
import scala.jdk.CollectionConverters._
|
||||
import multistepform.Models.Answers
|
||||
import scala.annotation.internal.requiresCapability
|
||||
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber.CountryCodeSource
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil
|
||||
|
||||
import java.net.URLDecoder
|
||||
import scala.util.Try
|
||||
|
||||
case class Routes()(implicit cc: castor.Context, log: cask.Logger)
|
||||
extends cask.Routes {
|
||||
@@ -14,16 +24,197 @@ case class Routes()(implicit cc: castor.Context, log: cask.Logger)
|
||||
val templateEngine = new TemplateEngine()
|
||||
templateEngine.setTemplateResolver(templateResolver)
|
||||
|
||||
val sessoinCookieName = "sessionId"
|
||||
|
||||
/** This route works with and without 'sessionId' cookie present set's this
|
||||
* cookie if not present, and returns initial 'index.html' where the form is
|
||||
* not yet initialized, and will be requested for the session
|
||||
*/
|
||||
@cask.get("/")
|
||||
def getIndex() = {
|
||||
def getIndex(ctx: cask.Request) = {
|
||||
val sessionCookie = ctx.cookies.get(sessoinCookieName)
|
||||
lazy val newSessionCookies = sessionCookie match {
|
||||
case None =>
|
||||
Seq(
|
||||
cask.Cookie(
|
||||
sessoinCookieName,
|
||||
UUID.randomUUID().toString(),
|
||||
path = "/"
|
||||
)
|
||||
)
|
||||
case Some(_) => Seq.empty // don't set new cookies
|
||||
}
|
||||
|
||||
println(s"getting cookie $sessionCookie will set new? ${newSessionCookies}")
|
||||
|
||||
val context = new Context()
|
||||
val indexPage = templateEngine.process("index", context)
|
||||
cask.Response(
|
||||
indexPage,
|
||||
headers = Seq("Content-Type" -> "text/html;charset=UTF-8"),
|
||||
cookies = newSessionCookies
|
||||
)
|
||||
}
|
||||
|
||||
@cask.get("/force-new-session")
|
||||
def forceNewSession() = {
|
||||
val newSessionCookie =
|
||||
cask.Cookie(sessoinCookieName, UUID.randomUUID().toString(), path = "/")
|
||||
println(s"setting new session ${newSessionCookie.value}")
|
||||
cask.Response(
|
||||
s"New session forced. Force new session",
|
||||
headers = Seq("Content-Type" -> "text/html;charset=UTF-8"),
|
||||
cookies = Seq(newSessionCookie)
|
||||
)
|
||||
}
|
||||
|
||||
val formDataContextVarName = "formData"
|
||||
|
||||
/** This method only works when cookie 'sessionId' is present will get or init
|
||||
* Form State for the session, and return last unsubmitted form step fragment
|
||||
*/
|
||||
@cask.get("/get-form")
|
||||
def getForm(sessionId: cask.Cookie) = {
|
||||
val id = sessionId.value
|
||||
val state = Sessions.sessionReplies.getOrElse(id, Answers(id))
|
||||
println(s"starting form for $state")
|
||||
val context = new Context()
|
||||
val formData = Models.FormData(state)
|
||||
context.setVariable(formDataContextVarName, formData)
|
||||
val formFragment = templateEngine.process(
|
||||
state.fragmentName,
|
||||
Set("formFragment").asJava,
|
||||
context
|
||||
)
|
||||
cask.Response(
|
||||
formFragment,
|
||||
headers = Seq("Content-Type" -> "text/html;charset=UTF-8")
|
||||
)
|
||||
}
|
||||
|
||||
@cask.post("/submit-step/:stepNum/:nextStep")
|
||||
def submitStep(
|
||||
sessionId: cask.Cookie,
|
||||
stepNum: Int,
|
||||
nextStep: Int,
|
||||
request: cask.Request
|
||||
) = {
|
||||
val id = sessionId.value
|
||||
println(s"got $request for $id. it's data is ${request.text()}")
|
||||
|
||||
// note: this is nice at step #1 because not storing anything before first submission
|
||||
// but on followup steps, if data lost - new default object is created
|
||||
// and that is not nice
|
||||
val userAnswers = Sessions.sessionReplies.getOrElse(id, Answers(id))
|
||||
|
||||
val submittedData = URLDecoder.decode(request.text(), "UTF-8")
|
||||
|
||||
val updatedAnswers =
|
||||
userAnswers.updateStep(stepNum, submittedData, nextStep)
|
||||
|
||||
Sessions.sessionReplies.update(id, updatedAnswers)
|
||||
|
||||
val context = new Context()
|
||||
val formData = Models.FormData(updatedAnswers)
|
||||
context.setVariable(formDataContextVarName, formData)
|
||||
val nextFormFragment = templateEngine.process(
|
||||
updatedAnswers.fragmentName,
|
||||
Set("formFragment").asJava,
|
||||
context
|
||||
)
|
||||
println(s"the state now is $updatedAnswers")
|
||||
cask.Response(
|
||||
nextFormFragment,
|
||||
headers = Seq("Content-Type" -> "text/html;charset=UTF-8")
|
||||
)
|
||||
}
|
||||
|
||||
@cask.post("/step1/phonenumber")
|
||||
def validateStep1PhoneNumber(request: cask.Request) = {
|
||||
val submittedData = URLDecoder.decode(request.text(), "UTF-8")
|
||||
println(
|
||||
s"getting data ${request.data} or ${request.text()} or $submittedData"
|
||||
)
|
||||
val fieldValues = submittedData
|
||||
.split("&")
|
||||
.filterNot(_.isEmpty())
|
||||
.map { field =>
|
||||
println(s"looking at field $field")
|
||||
val (name, value) = field.split("=").toList match {
|
||||
case List(name, value) => name -> value
|
||||
case name :: tail => name -> tail.headOption.getOrElse("")
|
||||
case Nil => ???
|
||||
}
|
||||
name -> value
|
||||
}
|
||||
.toMap
|
||||
|
||||
val name = fieldValues.getOrElse("name", "")
|
||||
val email = fieldValues.getOrElse("email", "")
|
||||
val phone = fieldValues.getOrElse("phone", "")
|
||||
|
||||
println(s"after parsing name=$name | email=$email | phone=$phone")
|
||||
|
||||
val phoneUtils = PhoneNumberUtil.getInstance()
|
||||
val phoneNum = Try(
|
||||
phoneUtils.parse(phone, CountryCodeSource.UNSPECIFIED.name())
|
||||
).toOption
|
||||
val isPhoneValid = phoneNum.map(phoneUtils.isValidNumber(_)).getOrElse(false)
|
||||
|
||||
val error = if (isPhoneValid) "" else "Please input valid phone number"
|
||||
|
||||
val context = new Context()
|
||||
context.setVariable("value", phone)
|
||||
context.setVariable("error", error)
|
||||
val inputDiv =
|
||||
templateEngine.process("step1", Set("email-input").asJava, context)
|
||||
|
||||
cask.Response(
|
||||
inputDiv,
|
||||
headers = Seq("Content-Type" -> "text/html;charset=UTF-8")
|
||||
)
|
||||
}
|
||||
|
||||
/** This endpoint re-renders 'plan type inputs' so that togglng monthly\yearly
|
||||
* could redraw their html
|
||||
*/
|
||||
@cask.post("/step2/planTypeInputs")
|
||||
def getPlanTypeInputs(sessionId: cask.Cookie, request: cask.Request) = {
|
||||
val id = sessionId.value
|
||||
val submittedData = URLDecoder.decode(request.text(), "UTF-8")
|
||||
println(s"requesting plan type inputs for $id and $request")
|
||||
Sessions.sessionReplies.get(id) match {
|
||||
case None =>
|
||||
cask.Response(
|
||||
"Can't find answers for your session, please reload the page",
|
||||
404
|
||||
)
|
||||
case Some(answers) => {
|
||||
// here changing yearly/monthly part of state based on passed checkbox value
|
||||
// and selected plan
|
||||
// only for purposes of rendering the fragment
|
||||
// not persisting, unless next or previous buttons are pressed
|
||||
val withYearlyParamSetAndSelectedPlan =
|
||||
answers.step2.fromFormData(submittedData)
|
||||
val updatedState =
|
||||
answers.copy(step2 = withYearlyParamSetAndSelectedPlan)
|
||||
val formData = Models.FormData(updatedState)
|
||||
val context = new Context()
|
||||
context.setVariable(formDataContextVarName, formData)
|
||||
val planTypesInputsHtml = templateEngine.process(
|
||||
"step2",
|
||||
Set("planTypesInputs").asJava,
|
||||
context
|
||||
)
|
||||
println(s"updating plan type inputs for $answers")
|
||||
cask.Response(
|
||||
planTypesInputsHtml,
|
||||
headers = Seq("Content-Type" -> "text/html;charset=UTF-8")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@cask.staticResources("/public")
|
||||
def publicFiles() = "public"
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package multistepform
|
||||
|
||||
import multistepform.Models.Answers
|
||||
|
||||
object Sessions {
|
||||
// the simplest form of storing data
|
||||
// i'll be relying on Render.com killing my app after 15 minutes of inactivity for GC
|
||||
// no need to manage concurrency really, because requests for same session are really far apart
|
||||
// and load will average to be 10req/day :shrug:
|
||||
val sessionReplies = scala.collection.mutable.Map.empty[String, Answers]
|
||||
}
|
||||
16
16-countries-page-from-api/.gitignore
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
.bsp/
|
||||
.scala-build/
|
||||
.metals/
|
||||
.direnv
|
||||
*/dist/
|
||||
/11-single-price-grid-component/.bloop/
|
||||
|
||||
**/.bloop
|
||||
**/project/project/
|
||||
**/project/metals.sbt
|
||||
**/project/.bloop
|
||||
**/project/target/
|
||||
**/target/
|
||||
|
||||
*/result
|
||||
result
|
||||
0
16-countries-page-from-api/.project
Normal file
2
16-countries-page-from-api/.scalafmt.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
version = "3.7.10"
|
||||
runner.dialect = scala3
|
||||
136
16-countries-page-from-api/README.org
Normal file
@@ -0,0 +1,136 @@
|
||||
* Frontend Mentor - REST Countries API with color theme switcher solution
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: frontend-mentor---rest-countries-api-with-color-theme-switcher-solution
|
||||
:END:
|
||||
This is a solution to the
|
||||
[[https://www.frontendmentor.io/challenges/rest-countries-api-with-color-theme-switcher-5cacc469fec04111f7b848ca][REST
|
||||
Countries API with color theme switcher challenge on Frontend Mentor]].
|
||||
Frontend Mentor challenges help you improve your coding skills by
|
||||
building realistic projects.
|
||||
|
||||
** Overview
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: overview
|
||||
:END:
|
||||
*** The challenge
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: the-challenge
|
||||
:END:
|
||||
Users should be able to:
|
||||
|
||||
- See all countries from the API on the homepage
|
||||
- Search for a country using an =input= field
|
||||
- Filter countries by region
|
||||
- Click on a country to see more detailed information on a separate page
|
||||
- Click through to the border countries on the detail page
|
||||
- Toggle the color scheme between light and dark mode /(optional)/
|
||||
|
||||
*** Screenshot
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: screenshot
|
||||
:END:
|
||||
[[mobile-main.png]]
|
||||
[[mobile-single.png]]
|
||||
[[desktop-main.png]]
|
||||
[[desktop-single.png]]
|
||||
|
||||
|
||||
*** Links
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: links
|
||||
:END:
|
||||
- Solution URL: https://github.com/efim/Learning-HTMX/tree/master/16-countries-page-from-api
|
||||
- Live Site URL: https://efim-frontentmentor-countries-page.onrender.com/
|
||||
|
||||
** My process
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: my-process
|
||||
:END:
|
||||
*** Built with
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: built-with
|
||||
:END:
|
||||
- Scala Server Side Rendering
|
||||
- Htmx
|
||||
- TailwindCSS
|
||||
- Flexbox
|
||||
- CSS Grid
|
||||
- Mobile-first workflow
|
||||
|
||||
|
||||
*** What I learned
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: what-i-learned
|
||||
:END:
|
||||
**** polling download for 'infinite scroll'
|
||||
https://htmx.org/examples/infinite-scroll/
|
||||
|
||||
I've done almost same thing as example,
|
||||
but i'm appending additional empty div, that inserts responses instead of itself
|
||||
|
||||
this way i have one template fragment with repeater,
|
||||
and don't have to add hx attributes to the last one,
|
||||
|
||||
i just have separate fragment that i append to response which will trigger new
|
||||
load on enter view.
|
||||
**** having html 5 native autocomplete with <datalist> tag
|
||||
just server side rendering it with all country names is yay
|
||||
**** inserting thymeleaf templates by css selector
|
||||
https://www.thymeleaf.org/doc/tutorials/3.1/usingthymeleaf.html#appendix-c-markup-selector-syntax
|
||||
|
||||
this way i can insert <script> tag from index page, without declaring it as a fragment,
|
||||
because i'll want is static anyway.
|
||||
|
||||
and can share 'dark mode' js code between pages
|
||||
**** building docker image
|
||||
First off: using nix docker tools, and sbt assembly to create 'uber jar'
|
||||
now 'nix build .#countries-page-image' builds an image and symlinks it to ./result
|
||||
|
||||
$ docker load < result
|
||||
loads the image
|
||||
|
||||
and it can be started
|
||||
$ docker image list
|
||||
$ docker run -d -p 9090:8080 <image-id>
|
||||
**** deploying to render.com
|
||||
need to auth the docker cli, then tag an image with my repository name
|
||||
$ docker login
|
||||
$ docker tag 141 efim1234/rock-paper-scissors:latest
|
||||
$ podman push localhost/efim1234/countries-page:latest docker.io/efim1234/countries-page:latest
|
||||
|
||||
and now render.com, when creating "new service"
|
||||
can find "efim1234/countries-page:latest" as public image and use it
|
||||
**** using browser history
|
||||
with either server side
|
||||
HX-Push -> "some-url"
|
||||
or
|
||||
hx-push-url="true" in the html side
|
||||
|
||||
so that url is put into address bar,
|
||||
and browser save the body into history
|
||||
|
||||
and now my website has forward and backward navigation
|
||||
|
||||
only bug - the 'filter by region' for some reason doesn't maintain the selected value
|
||||
|
||||
*** Continued development
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: continued-development
|
||||
:END:
|
||||
In future project i'll probably want to lean and use go.
|
||||
For smaller binaries of the server, using PocketBase as embedded backend functions,
|
||||
and maybe having a better chances of just doing some real world small projects.
|
||||
|
||||
*** Useful resources
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: useful-resources
|
||||
:END:
|
||||
- htmx documentation and examples
|
||||
https://htmx.org/docs/#introduction
|
||||
- thymeleaf documentation
|
||||
https://www.thymeleaf.org/doc/tutorials/3.1/usingthymeleaf.html#introducing-thymeleaf
|
||||
- TailwindCSS documentation
|
||||
https://tailwindcss.com/docs/installation
|
||||
- heroicons: MIT licensed svg icons
|
||||
https://github.com/tailwindlabs/heroicons
|
||||
- render.com for providing free hosting for services from docker images
|
||||
17
16-countries-page-from-api/build.sbt
Normal file
@@ -0,0 +1,17 @@
|
||||
name := "countries-page"
|
||||
|
||||
val toolkitV = "0.1.7"
|
||||
val toolkit = "org.scala-lang" %% "toolkit" % toolkitV
|
||||
val toolkitTest = "org.scala-lang" %% "toolkit-test" % toolkitV
|
||||
|
||||
val cask = "com.lihaoyi" %% "cask" % "0.9.1"
|
||||
val mainargs = "com.lihaoyi" %% "mainargs" % "0.5.4"
|
||||
val requests = "com.lihaoyi" %% "requests" % "0.8.0"
|
||||
|
||||
ThisBuild / scalaVersion := "3.2.2"
|
||||
libraryDependencies ++= Seq(cask, mainargs, requests)
|
||||
libraryDependencies += toolkit
|
||||
libraryDependencies += (toolkitTest % Test)
|
||||
|
||||
// https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf
|
||||
libraryDependencies += "org.thymeleaf" % "thymeleaf" % "3.1.2.RELEASE"
|
||||
37
16-countries-page-from-api/default.nix
Normal file
@@ -0,0 +1,37 @@
|
||||
{ pkgs, lib, sbt-derivation }:
|
||||
let pname = "countries-page";
|
||||
in rec {
|
||||
package = sbt-derivation.lib.mkSbtDerivation {
|
||||
inherit pkgs pname;
|
||||
# ...and the rest of the arguments
|
||||
version = "0.0.1";
|
||||
src = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
|
||||
nativeBuildInputs = [ pkgs.nodePackages.tailwindcss ];
|
||||
buildPhase = ''
|
||||
tailwindcss -i ./src/input.css -o ./src/main/resources/public/output.css
|
||||
sbt assembly
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp target/scala-*/${pname}-assembly-*.jar $out/bin/${pname}.jar
|
||||
'';
|
||||
|
||||
depsSha256 = "sha256-PZYt1xvT8BKkFedA8nQvjvuE6JtmxNh0aSManAe4DpY=";
|
||||
};
|
||||
image = pkgs.dockerTools.buildLayeredImage {
|
||||
name = pname;
|
||||
tag = "latest";
|
||||
created = "now";
|
||||
config = {
|
||||
Cmd = [
|
||||
"${pkgs.jdk}/bin/java"
|
||||
"-jar"
|
||||
"${package}/bin/${pname}.jar"
|
||||
"--host"
|
||||
"0.0.0.0"
|
||||
];
|
||||
ExposedPorts = { "8080/tcp" = { }; };
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
BIN
16-countries-page-from-api/design/desktop-design-detail-dark.jpg
Normal file
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 26 KiB |
BIN
16-countries-page-from-api/design/desktop-design-home-dark.jpg
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
16-countries-page-from-api/design/desktop-design-home-light.jpg
Normal file
|
After Width: | Height: | Size: 96 KiB |
BIN
16-countries-page-from-api/design/desktop-preview.jpg
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
16-countries-page-from-api/design/mobile-design-detail-dark.jpg
Normal file
|
After Width: | Height: | Size: 38 KiB |
BIN
16-countries-page-from-api/design/mobile-design-detail-light.jpg
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
16-countries-page-from-api/design/mobile-design-home-dark.jpg
Normal file
|
After Width: | Height: | Size: 203 KiB |
BIN
16-countries-page-from-api/design/mobile-design-home-light.jpg
Normal file
|
After Width: | Height: | Size: 216 KiB |
BIN
16-countries-page-from-api/desktop-main.png
Normal file
|
After Width: | Height: | Size: 194 KiB |
BIN
16-countries-page-from-api/desktop-single.png
Normal file
|
After Width: | Height: | Size: 83 KiB |
BIN
16-countries-page-from-api/mobile-main.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
16-countries-page-from-api/mobile-single.png
Normal file
|
After Width: | Height: | Size: 41 KiB |
1
16-countries-page-from-api/project/build.properties
Normal file
@@ -0,0 +1 @@
|
||||
sbt.version=1.9.0
|
||||
3
16-countries-page-from-api/project/plugins.sbt
Normal file
@@ -0,0 +1,3 @@
|
||||
addSbtPlugin("io.spray" % "sbt-revolver" % "0.10.0")
|
||||
|
||||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.1")
|
||||
28
16-countries-page-from-api/src/input.css
Normal file
@@ -0,0 +1,28 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
html {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'NunitoSans';
|
||||
src: url('/public/fonts/nunito-sans/NunitoSans-Regular.ttf') format('truetype');
|
||||
font-weight: 400; /* Regular */
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'NunitoSans';
|
||||
src: url('/public/fonts/nunito-sans/NunitoSans-Bold.ttf') format('truetype');
|
||||
font-weight: 700; /* Bold */
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'NunitoSans';
|
||||
src: url('/public/fonts/nunito-sans/NunitoSans-ExtraBold.ttf') format('truetype');
|
||||
font-weight: 800; /* ExtraBold */
|
||||
font-style: normal;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
Copyright 2016 The Nunito Project Authors (contact@sansoxygen.com),
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
<svg fill="#000000" height="800px" width="800px" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
viewBox="0 0 386.242 386.242" xml:space="preserve">
|
||||
<g>
|
||||
<path id="Arrow_Back" d="M374.212,182.3H39.432l100.152-99.767c4.704-4.704,4.704-12.319,0-17.011
|
||||
c-4.704-4.704-12.319-4.704-17.011,0L3.474,184.61c-4.632,4.632-4.632,12.379,0,17.011l119.1,119.1
|
||||
c4.704,4.704,12.319,4.704,17.011,0c4.704-4.704,4.704-12.319,0-17.011L39.432,206.36h334.779c6.641,0,12.03-5.39,12.03-12.03
|
||||
S380.852,182.3,374.212,182.3z"/>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
<g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 790 B |
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg fill="#000000" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
width="800px" height="800px" viewBox="0 0 81.289 81.289"
|
||||
xml:space="preserve">
|
||||
<g>
|
||||
<path d="M79.248,38.668c-1.246-0.464-2.669-0.088-3.518,0.95c-4.791,5.84-11.858,9.192-19.403,9.192
|
||||
c-13.833,0-25.083-11.255-25.083-25.083c0-6.963,2.808-13.441,7.908-18.242c0.977-0.918,1.26-2.357,0.705-3.579
|
||||
c-0.552-1.222-1.818-1.959-3.157-1.826C15.778,2.112,0,19.511,0,40.555c0,22.424,18.245,40.669,40.672,40.669
|
||||
c22.16,0,40.002-17.363,40.616-39.528C81.324,40.355,80.508,39.136,79.248,38.668z M40.671,74.953
|
||||
c-18.971,0-34.402-15.43-34.402-34.4c0-14.93,9.389-27.69,22.859-32.43c-2.714,4.689-4.156,10.022-4.156,15.605
|
||||
c0,17.292,14.065,31.355,31.357,31.355c6.317,0,12.373-1.882,17.479-5.322C69.82,64.399,56.557,74.953,40.671,74.953z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M15.7955 15.8111L21 21M18 10.5C18 14.6421 14.6421 18 10.5 18C6.35786 18 3 14.6421 3 10.5C3 6.35786 6.35786 3 10.5 3C14.6421 3 18 6.35786 18 10.5Z" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 469 B |
1065
16-countries-page-from-api/src/main/resources/public/output.css
Normal file
@@ -0,0 +1,194 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge" />
|
||||
<title>Exploring countries</title>
|
||||
<meta name="description" content="" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link href="../public/output.css" th:href=@{~/public/output.css}
|
||||
rel="stylesheet" />
|
||||
<script src="https://unpkg.com/htmx.org@1.9.6"></script>
|
||||
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
||||
<!-- Place favicon.ico in the root directory -->
|
||||
</head>
|
||||
<body
|
||||
class="bg-very-light-gray h-screen flex flex-col dark:bg-very-dark-blue dark:text-white"
|
||||
hx-boost="true"
|
||||
>
|
||||
<!--[if lt IE 8]>
|
||||
<p class="browserupgrade">
|
||||
You are using an <strong>outdated</strong> browser. Please
|
||||
<a href="http://browsehappy.com/">upgrade your browser</a> to improve
|
||||
your experience.
|
||||
</p>
|
||||
<![endif]-->
|
||||
<header th:replace="~{index :: header}">
|
||||
<div
|
||||
class="flex-1 max-w-screen-xl h-20 flex flex-row justify-between items-center px-4"
|
||||
>
|
||||
<a th:href="@{~/}" href="index.html"
|
||||
><h1 class="grow font-bold md:text-2xl">Where in the world?</h1>
|
||||
</a>
|
||||
<button id="toggleDarkMode" class="flex flex-row gap-x-2">
|
||||
<svg
|
||||
class="text-black dark:text-white h-6"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M21.7519 15.0019C20.597 15.4839 19.3296 15.75 18 15.75C12.6152 15.75 8.25 11.3848 8.25 5.99999C8.25 4.67039 8.51614 3.40296 8.99806 2.24805C5.47566 3.71785 3 7.19481 3 11.25C3 16.6348 7.36522 21 12.75 21C16.8052 21 20.2821 18.5243 21.7519 15.0019Z"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
<p>Dark Mode</p>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
<nav
|
||||
class="flex flex-none h-32 px-8 py-10 max-w-screen-xl place-self-center w-full md:h-48 items-center"
|
||||
>
|
||||
<a href="index.html" th:href="@{~/}" class="h-fit">
|
||||
<div
|
||||
class="h-9 w-28 bg-white drop-shadow-[0_0_3px_rgba(0,0,0,0.5)] text-md rounded px-5 py-2 flex flex-row gap-x-3 place-content-center dark:bg-dark-blue"
|
||||
>
|
||||
<!-- Back icon -->
|
||||
<svg
|
||||
class="text-black dark:text-white h-full"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M10.5 19.5L3 12M3 12L10.5 4.5M3 12H21"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
<!-- <img
|
||||
src="../public/icons/back-svgrepo-com.svg"
|
||||
class="w-4 h-5"
|
||||
alt=""
|
||||
/> -->
|
||||
<p>Back</p>
|
||||
</div>
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
<main
|
||||
class="px-8 pb-10 flex flex-col gap-y-10 md:grid md:grid-cols-2 md:h-max md:place-self-center w-full max-w-screen-xl"
|
||||
>
|
||||
<img
|
||||
src="https://flagcdn.com/de.svg"
|
||||
th:src="${country.flag}"
|
||||
th:alt="|flag of ${country.nameView}|"
|
||||
class="w-full md:w-10/12"
|
||||
/>
|
||||
<section
|
||||
id="stat-block"
|
||||
class="contents md:grid md:grid-cols-2 md:gap-y-10 md:py-10"
|
||||
>
|
||||
<h1
|
||||
class="text-2xl font-bold pt-2 -mb-4 md:col-span-full md:text-3xl"
|
||||
th:text="${country.nameView}"
|
||||
>
|
||||
Germany
|
||||
</h1>
|
||||
<dl class="space-y-2" id="main-stats">
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Native name:</dt>
|
||||
<dd th:text="${country.nativeName}">Belgie</dd>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Population:</dt>
|
||||
<dd
|
||||
th:text="${#numbers.formatInteger(country.population, 3, 'COMMA')}"
|
||||
>
|
||||
81,771,900
|
||||
</dd>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Region:</dt>
|
||||
<dd th:text="${country.region}">Europe</dd>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Sub Region:</dt>
|
||||
<dd th:text="${country.subregion}">Western Europe</dd>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Capital:</dt>
|
||||
<dd th:text="${country.capitalView}">Berlin</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
<dl class="space-y-2" id="additional-stats">
|
||||
<div th:if="${country.topLevelDomain.nonEmpty()}" class="flex">
|
||||
<dt class="font-bold mr-2">Top Level Domain:</dt>
|
||||
<dd th:text="${country.topLevelDomain.get()}">.be</dd>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Currencies:</dt>
|
||||
<!-- <dd th:text="${#strings.listJoin(country.currencies.map(_.name),',')}">Euro</dd> -->
|
||||
<dd th:text="${#strings.listJoin(country.currenciesView, ',')}">
|
||||
Euro
|
||||
</dd>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Languages:</dt>
|
||||
<dd th:text="${#strings.listJoin(country.languagesView, ', ')}">
|
||||
Dutch, French, German
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<section
|
||||
id="neighboring-countries"
|
||||
class="md:col-span-full md:flex md:flex-row md:items-center md:gap-x-2"
|
||||
>
|
||||
<h2 class="font-bold text-lg md:pr-2">Border Countries:</h2>
|
||||
<div class="grid grid-cols-3 gap-2">
|
||||
<a
|
||||
href="/"
|
||||
class="text-center min-h-9 bg-white drop-shadow text-md rounded px-5 py-2 md:w-32 md:py-1 dark:bg-dark-blue"
|
||||
th:each="border : ${borderCountries}"
|
||||
th:text="${border}"
|
||||
th:href="@{~/country(countryName=${border})}"
|
||||
>France</a
|
||||
>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
</main>
|
||||
<script
|
||||
th:replace="~{index :: script#dark-mode-scripts}"
|
||||
type="text/javascript"
|
||||
>
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const darkMode = localStorage.getItem("darkMode");
|
||||
console.log("yoyo");
|
||||
if (darkMode === "true") {
|
||||
document.documentElement.classList.add("dark");
|
||||
} else {
|
||||
document.documentElement.classList.remove("dark");
|
||||
}
|
||||
});
|
||||
document
|
||||
.getElementById("toggleDarkMode")
|
||||
.addEventListener("click", function () {
|
||||
document.documentElement.classList.toggle("dark");
|
||||
localStorage.setItem(
|
||||
"darkMode",
|
||||
document.documentElement.classList.contains("dark")
|
||||
);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,266 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge" />
|
||||
<title>Exploring countries</title>
|
||||
<meta name="description" content="" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link href="../public/output.css" th:href=@{~/public/output.css}
|
||||
rel="stylesheet" />
|
||||
<script src="https://unpkg.com/htmx.org@1.9.6"></script>
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
||||
<!-- Place favicon.ico in the root directory -->
|
||||
</head>
|
||||
<body
|
||||
class="bg-very-light-gray h-screen flex flex-col dark:bg-very-dark-blue dark:text-white"
|
||||
hx-boost="true"
|
||||
>
|
||||
<!--[if lt IE 8]>
|
||||
<p class="browserupgrade">
|
||||
You are using an <strong>outdated</strong> browser. Please
|
||||
<a href="http://browsehappy.com/">upgrade your browser</a> to improve
|
||||
your experience.
|
||||
</p>
|
||||
<![endif]-->
|
||||
<header
|
||||
class="w-screen bg-white h-20 flex flex-row shadow-md place-content-center flex-none dark:bg-dark-blue"
|
||||
>
|
||||
<div
|
||||
class="flex-1 max-w-screen-xl h-20 flex flex-row justify-between items-center px-4"
|
||||
>
|
||||
<a th:href="@{~/}" href="index.html"
|
||||
><h1 class="grow font-bold md:text-2xl">Where in the world?</h1>
|
||||
</a>
|
||||
<button id="toggleDarkMode" class="flex flex-row gap-x-2">
|
||||
<svg
|
||||
class="text-black dark:text-white h-6"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M21.7519 15.0019C20.597 15.4839 19.3296 15.75 18 15.75C12.6152 15.75 8.25 11.3848 8.25 5.99999C8.25 4.67039 8.51614 3.40296 8.99806 2.24805C5.47566 3.71785 3 7.19481 3 11.25C3 16.6348 7.36522 21 12.75 21C16.8052 21 20.2821 18.5243 21.7519 15.0019Z"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
<p>Dark Mode</p>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
<nav
|
||||
class="flex flex-col flex-none md:flex-row px-6 my-4 justify-around h-48 md:h-32 md:items-center"
|
||||
>
|
||||
<form
|
||||
method="get"
|
||||
id="search-country"
|
||||
action=""
|
||||
hx-get="/country"
|
||||
hx-target="body"
|
||||
hx-push-url="true"
|
||||
class="contents"
|
||||
>
|
||||
<div
|
||||
class="md:w-1/4 md:min-w-max flex flex-row items-center bg-white shadow-md h-14 md:h-16 rounded-lg dark:bg-dark-blue"
|
||||
>
|
||||
<!-- <p class="w-16 grid place-content-center">IC</p> -->
|
||||
<svg
|
||||
class="text-black dark:text-white h-6 px-7"
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M9 3.5C5.96243 3.5 3.5 5.96243 3.5 9C3.5 12.0376 5.96243 14.5 9 14.5C10.519 14.5 11.893 13.8852 12.8891 12.8891C13.8852 11.893 14.5 10.519 14.5 9C14.5 5.96243 12.0376 3.5 9 3.5ZM2 9C2 5.13401 5.13401 2 9 2C12.866 2 16 5.13401 16 9C16 10.6625 15.4197 12.1906 14.4517 13.3911L17.7803 16.7197C18.0732 17.0126 18.0732 17.4874 17.7803 17.7803C17.4874 18.0732 17.0126 18.0732 16.7197 17.7803L13.3911 14.4517C12.1906 15.4197 10.6625 16 9 16C5.13401 16 2 12.866 2 9Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
</svg>
|
||||
<input
|
||||
class="appearance-none flex-grow focus:outline-none mr-2 dark:bg-dark-blue dark:placeholder:text-white"
|
||||
type="text"
|
||||
id="country.nameView-input"
|
||||
name="countryName"
|
||||
list="country.nameViews-list"
|
||||
placeholder="Search for a country..."
|
||||
hx-post="/countries-cards"
|
||||
hx-target="#countries-main-list"
|
||||
hx-trigger="keyup changed delay:500ms"
|
||||
/>
|
||||
</div>
|
||||
<datalist id="country.nameViews-list">
|
||||
<option
|
||||
th:each="country : ${allCountriesList}"
|
||||
th:value="${country.nameView}"
|
||||
value=""
|
||||
></option>
|
||||
</datalist>
|
||||
<select
|
||||
name="region"
|
||||
class="block w-62 mt-1 h-14 md:h-16 w-64 bg-white shadow-lg rounded-md shadow-sm focus:outline-none px-7 dark:bg-dark-blue"
|
||||
hx-post="/countries-cards"
|
||||
hx-target="#countries-main-list"
|
||||
>
|
||||
<option
|
||||
value=""
|
||||
selected
|
||||
disabled
|
||||
th:selected="${#strings.isEmpty(selectedRegion)}"
|
||||
>
|
||||
Filter by Region
|
||||
</option>
|
||||
<option
|
||||
th:each="region: ${regionsSet}"
|
||||
th:value="${region}"
|
||||
th:text="${region}"
|
||||
th:selected="${selectedRegion == region}"
|
||||
value="Africa"
|
||||
>
|
||||
Africa
|
||||
</option>
|
||||
<option th:remove="all" value="Americas">Americas</option>
|
||||
<option th:remove="all" value="Asia">Asia</option>
|
||||
<option th:remove="all" value="Europe">Europe</option>
|
||||
<option th:remove="all" value="Oceania">Oceania</option>
|
||||
</select>
|
||||
</form>
|
||||
</nav>
|
||||
<main
|
||||
class="flex flex-col items-center gap-10 pb-8 md:grid md:grid-cols-[repeat(auto-fill,_275px)] md:px-20 md:justify-around"
|
||||
id="countries-main-list"
|
||||
>
|
||||
<article
|
||||
th:fragment="cards-of-countries (countriesList)"
|
||||
th:each="country : ${countriesList}"
|
||||
id="germany"
|
||||
th:id="${country.alpha3Code}"
|
||||
class="bg-white min-h-[350px] w-[275px] flex flex-col rounded-lg shadow-lg dark:bg-dark-blue"
|
||||
>
|
||||
<a
|
||||
href="country.html"
|
||||
th:href="@{~/country(countryName=${country.nameView})}"
|
||||
>
|
||||
<img
|
||||
src="https://flagcdn.com/de.svg"
|
||||
th:src="${country.flag}"
|
||||
alt="flag of Germany"
|
||||
th:alt="|flag of ${country.nameView}|"
|
||||
class="rounded-t-lg max-h-56 w-full"
|
||||
/>
|
||||
<section class="p-8 space-y-3 min-h-fit">
|
||||
<h2 class="text-2xl font-bold" th:text="${country.nameView}">
|
||||
Germany
|
||||
</h2>
|
||||
<dl class="space-y-1">
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Population:</dt>
|
||||
<dd
|
||||
th:text="${#numbers.formatInteger(country.population, 3, 'COMMA')}"
|
||||
>
|
||||
81,771,900
|
||||
</dd>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Region:</dt>
|
||||
<dd th:text="${country.region}">Europe</dd>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Capital:</dt>
|
||||
<dd th:text="${country.capitalView}">Berlin</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</section>
|
||||
</a>
|
||||
</article>
|
||||
<div
|
||||
th:fragment="infiniteScrollAnchor (nextPage, selectedRegion)"
|
||||
th:if="${nextPage != -1}"
|
||||
id="next-page-anchor"
|
||||
hx-trigger="revealed"
|
||||
th:hx-get="@{~/countries-cards(region=${selectedRegion},page=${nextPage},countryName=${countryName})}"
|
||||
hx-swap="outerHTML"
|
||||
></div>
|
||||
|
||||
<article
|
||||
id="usa"
|
||||
class="bg-white h-[350px] w-[275px] flex flex-col rounded-lg shadow-lg dark:bg-dark-blue"
|
||||
th:remove="all"
|
||||
>
|
||||
<img
|
||||
src="https://flagcdn.com/us.svg"
|
||||
alt="flag of the USA"
|
||||
class="rounded-t-lg"
|
||||
/>
|
||||
<section class="p-8 space-y-3">
|
||||
<h2 class="text-2xl font-bold">United States of America</h2>
|
||||
<dl class="space-y-1">
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Population:</dt>
|
||||
<dd>329,484,123</dd>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Region:</dt>
|
||||
<dd>Americas</dd>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Capital:</dt>
|
||||
<dd>Washington, D.C.</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</section>
|
||||
</article>
|
||||
|
||||
<article
|
||||
id="Brazil"
|
||||
class="bg-white h-[350px] w-[275px] flex flex-col rounded-lg shadow-lg dark:bg-dark-blue"
|
||||
th:remove="all"
|
||||
>
|
||||
<img
|
||||
src="https://flagcdn.com/br.svg"
|
||||
alt="flag of Germany"
|
||||
class="rounded-t-lg"
|
||||
/>
|
||||
<section class="p-8 space-y-3">
|
||||
<h2 class="text-2xl font-bold">Brazil</h2>
|
||||
<dl class="space-y-1">
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Population:</dt>
|
||||
<dd>212,559,409</dd>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Region:</dt>
|
||||
<dd>Americas</dd>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<dt class="font-bold mr-2">Capital:</dt>
|
||||
<dd>Brasília</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</section>
|
||||
</article>
|
||||
</main>
|
||||
<script id="dark-mode-scripts" type="text/javascript">
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const darkMode = localStorage.getItem("darkMode");
|
||||
if (darkMode === "true") {
|
||||
document.documentElement.classList.add("dark");
|
||||
} else {
|
||||
document.documentElement.classList.remove("dark");
|
||||
}
|
||||
});
|
||||
document
|
||||
.getElementById("toggleDarkMode")
|
||||
.addEventListener("click", function () {
|
||||
document.documentElement.classList.toggle("dark");
|
||||
localStorage.setItem(
|
||||
"darkMode",
|
||||
document.documentElement.classList.contains("dark")
|
||||
);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,48 @@
|
||||
package example
|
||||
|
||||
import upickle.default._
|
||||
import scala.jdk.CollectionConverters._
|
||||
|
||||
final case class Country(
|
||||
name: Name,
|
||||
cca3: String,
|
||||
population: Int,
|
||||
region: String,
|
||||
subregion: String = "",
|
||||
flags: Flags,
|
||||
capital: List[String] = List.empty,
|
||||
tld: Option[String] = None, // maybe optional?
|
||||
currencies: Map[String, Currency] = Map.empty,
|
||||
languages: Map[String, String] = Map.empty,
|
||||
borders: List[String] = List.empty
|
||||
) derives ReadWriter {
|
||||
def currenciesView = currencies.values.map(_.name).toList.asJava
|
||||
def languagesView = languages.values.toList.asJava
|
||||
def nameView = name.common
|
||||
def capitalView = capital.headOption.getOrElse("")
|
||||
def nativeName = name.nativeName.headOption.map(_._2.common).getOrElse("")
|
||||
def topLevelDomain = tld
|
||||
def alpha3Code = cca3
|
||||
def flag = flags.svg
|
||||
}
|
||||
|
||||
final case class Name(
|
||||
common: String,
|
||||
nativeName: Map[String, Name.Native] = Map.empty
|
||||
) derives ReadWriter
|
||||
object Name {
|
||||
final case class Native(
|
||||
common: String
|
||||
) derives ReadWriter
|
||||
}
|
||||
|
||||
final case class Currency(
|
||||
name: String,
|
||||
symbol: String = ""
|
||||
) derives ReadWriter
|
||||
|
||||
final case class Flags(
|
||||
png: String,
|
||||
svg: String,
|
||||
alt: String = ""
|
||||
) derives ReadWriter
|
||||
55
16-countries-page-from-api/src/main/scala/example/Main.scala
Normal file
@@ -0,0 +1,55 @@
|
||||
package example
|
||||
|
||||
import org.thymeleaf.templatemode.TemplateMode
|
||||
import org.thymeleaf.TemplateEngine
|
||||
import org.thymeleaf.context.Context
|
||||
import cask.model.Response
|
||||
import mainargs.{main, arg, ParserForMethods, Flag}
|
||||
import scala.util.Try
|
||||
|
||||
object MinimalApplication extends cask.Routes {
|
||||
|
||||
@main
|
||||
def run(
|
||||
@arg(
|
||||
name = "port",
|
||||
short = 'p',
|
||||
doc = "Port on which server will start service"
|
||||
)
|
||||
portArg: Int = 8080,
|
||||
@arg(name = "host", doc = "Host on which server will start serving")
|
||||
hostArg: String = "localhost"
|
||||
) = {
|
||||
println(s"Will start server on ${hostArg}:${portArg}")
|
||||
val countriesDb = loadCountries()
|
||||
val server = new cask.Main {
|
||||
override def allRoutes: Seq[cask.main.Routes] = Seq(
|
||||
Routes(countries = countriesDb)
|
||||
)
|
||||
override def port: Int = portArg
|
||||
override def host: String = hostArg
|
||||
}
|
||||
server.main(Array.empty)
|
||||
}
|
||||
|
||||
def loadCountries() = {
|
||||
val defaultCountriesData: List[Country] =
|
||||
upickle.default.read[List[Country]](
|
||||
scala.io.Source.fromResource("temporary/all.json").getLines().mkString,
|
||||
true
|
||||
)
|
||||
val apiDataRequest = requests.get("https://restcountries.com/v3.1/all")
|
||||
val apiData = Try(
|
||||
upickle.default.read[List[Country]](apiDataRequest.text(), true)
|
||||
)
|
||||
if (apiData.isFailure)
|
||||
println(s"> data load failed ${apiData}")
|
||||
else
|
||||
println(s"> api data load is successful")
|
||||
|
||||
apiData.toOption.getOrElse(defaultCountriesData)
|
||||
}
|
||||
|
||||
def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)
|
||||
|
||||
}
|
||||
184
16-countries-page-from-api/src/main/scala/example/Routes.scala
Normal file
@@ -0,0 +1,184 @@
|
||||
package example
|
||||
|
||||
import cask.model.Response
|
||||
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver
|
||||
import org.thymeleaf.TemplateEngine
|
||||
import org.thymeleaf.context.Context
|
||||
import org.thymeleaf.templatemode.TemplateMode
|
||||
import scala.jdk.CollectionConverters._
|
||||
import cask.model.Request
|
||||
|
||||
case class Routes(countries: List[Country])(implicit
|
||||
cc: castor.Context,
|
||||
log: cask.Logger
|
||||
) extends cask.Routes {
|
||||
|
||||
/** initializing thymeleaf template engine which finds and renders html
|
||||
* templates by name
|
||||
*/
|
||||
def buildTemplateEngine(): TemplateEngine = {
|
||||
val templateResolver = new ClassLoaderTemplateResolver()
|
||||
templateResolver.setTemplateMode(TemplateMode.HTML)
|
||||
templateResolver.setPrefix("/templates/")
|
||||
templateResolver.setSuffix(".html")
|
||||
templateResolver.setCacheTTLMs(3600000L);
|
||||
|
||||
val templateEngine = new TemplateEngine()
|
||||
templateEngine.setTemplateResolver(templateResolver)
|
||||
|
||||
templateEngine
|
||||
}
|
||||
val engine: TemplateEngine = buildTemplateEngine()
|
||||
|
||||
private val pageSize = 12
|
||||
|
||||
@cask.get("/")
|
||||
def indexPage(
|
||||
region: Option[String] = None,
|
||||
page: Int = 0,
|
||||
countryName: Option[String] = None
|
||||
) = {
|
||||
val context = new Context()
|
||||
|
||||
val regions = countries.map(_.region).distinct.sorted.asJava
|
||||
val selectedCountries = getSelectedCountries(region, countryName)
|
||||
|
||||
val startIndex = page * pageSize
|
||||
val countriesPage =
|
||||
selectedCountries.slice(startIndex, startIndex + pageSize)
|
||||
// if current page is not full - there will be no next page
|
||||
val nextPage = if (countriesPage.length == pageSize) page + 1 else -1
|
||||
context.setVariable("nextPage", nextPage)
|
||||
|
||||
context.setVariable("regionsSet", regions)
|
||||
context.setVariable("countriesList", countriesPage.asJava)
|
||||
context.setVariable("allCountriesList", countries.asJava)
|
||||
// for anchor to request next pages from same countries
|
||||
context.setVariable("selectedRegion", region.getOrElse(""))
|
||||
context.setVariable("countryName", countryName.getOrElse(""))
|
||||
|
||||
val indexPage = engine.process("index", context)
|
||||
Response(
|
||||
indexPage,
|
||||
headers = Seq("Content-Type" -> "text/html; charset=utf-8")
|
||||
)
|
||||
}
|
||||
|
||||
@cask.postForm("/countries-cards")
|
||||
def postPageOfCountriesCards(
|
||||
region: cask.FormValue,
|
||||
countryName: cask.FormValue
|
||||
) = {
|
||||
println(s"in get for countries cards with $region and $countryName")
|
||||
getPageOfCountriesCards(Some(region.value), 0, Some(countryName.value))
|
||||
}
|
||||
|
||||
/** this method returns directly set of cards and new anchor for loading next
|
||||
* page of cards
|
||||
*
|
||||
* intended to be called from "next-page-anchor" with htmx
|
||||
*/
|
||||
@cask.get("/countries-cards")
|
||||
def getPageOfCountriesCards(
|
||||
region: Option[String] = None,
|
||||
page: Int = 0,
|
||||
countryName: Option[String] = None
|
||||
) = {
|
||||
val context = new Context()
|
||||
|
||||
val selectedCountries = getSelectedCountries(region, countryName)
|
||||
|
||||
val startIndex = page * pageSize
|
||||
val countriesPage =
|
||||
selectedCountries.slice(startIndex, startIndex + pageSize)
|
||||
context.setVariable("countriesList", countriesPage.asJava)
|
||||
|
||||
// for anchor to request next pages from same countries
|
||||
context.setVariable("selectedRegion", region.getOrElse(""))
|
||||
context.setVariable("countryName", countryName.getOrElse(""))
|
||||
|
||||
// if current page is not full - there will be no next page
|
||||
val nextPage = if (countriesPage.length == pageSize) page + 1 else -1
|
||||
context.setVariable("nextPage", nextPage)
|
||||
|
||||
val cards = engine.process(
|
||||
"index",
|
||||
Set("cards-of-countries", "infiniteScrollAnchor").asJava,
|
||||
context
|
||||
)
|
||||
// this is to store switch to another region in the history
|
||||
val newUrl = s"/?region=${region.getOrElse("")}&countryName=${countryName.getOrElse("")}"
|
||||
// only save url when new region is requested, not on addtional card loads
|
||||
val urlHeaderOpt = if (page == 0) Seq("HX-Push" -> newUrl) else Seq.empty
|
||||
Response(
|
||||
cards,
|
||||
headers = Seq(
|
||||
"Content-Type" -> "text/html; charset=utf-8"
|
||||
) ++ urlHeaderOpt
|
||||
)
|
||||
}
|
||||
|
||||
private def getSelectedCountries(
|
||||
region: Option[String] = None,
|
||||
countryName: Option[String] = None
|
||||
) = {
|
||||
val countriesFromSelectedRegion = region match {
|
||||
case None => countries
|
||||
case Some("") => countries
|
||||
case Some(selectedRegion) => countries.filter(_.region == selectedRegion)
|
||||
}
|
||||
// applying country name filtering, can be partial name
|
||||
val selectedCountries = countryName match {
|
||||
case None => countriesFromSelectedRegion
|
||||
case Some("") => countriesFromSelectedRegion
|
||||
case Some(partialSearchString) =>
|
||||
val lowerSearch = partialSearchString.toLowerCase()
|
||||
countriesFromSelectedRegion
|
||||
.filter(country => {
|
||||
val nameContainsPartialMatch =
|
||||
country.name.common.toLowerCase().contains(lowerSearch) ||
|
||||
country.name.nativeName.values.foldLeft(false) {
|
||||
(acc, nativeName) =>
|
||||
acc || nativeName.common.toLowerCase().contains(lowerSearch)
|
||||
}
|
||||
|
||||
nameContainsPartialMatch
|
||||
})
|
||||
}
|
||||
selectedCountries
|
||||
}
|
||||
|
||||
@cask.get("/country")
|
||||
def getCountryPage(countryName: String, region: Option[String] = None) = {
|
||||
val context = new Context()
|
||||
countries.find(_.name.common == countryName) match {
|
||||
case Some(selectedCountry) =>
|
||||
context.setVariable("country", selectedCountry)
|
||||
val borderCountries = countries
|
||||
.filter(c => selectedCountry.borders.contains(c.alpha3Code))
|
||||
.map(_.name.common)
|
||||
.sortBy(_.length())
|
||||
.asJava
|
||||
|
||||
context.setVariable("borderCountries", borderCountries)
|
||||
|
||||
val countryPage = engine.process("country", context)
|
||||
Response(
|
||||
countryPage,
|
||||
headers = Seq("Content-Type" -> "text/html; charset=utf-8")
|
||||
)
|
||||
case None => Response("", 400)
|
||||
}
|
||||
}
|
||||
|
||||
@cask.post("/do-thing")
|
||||
def doThing(request: cask.Request) = {
|
||||
request.text().reverse
|
||||
}
|
||||
|
||||
@cask.staticResources("public")
|
||||
def giveStaticResources() = "public"
|
||||
|
||||
initialize()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package example
|
||||
|
||||
class ExampleSuite extends munit.FunSuite:
|
||||
|
||||
test("addition") {
|
||||
assert(1 + 1 == 2)
|
||||
}
|
||||
end ExampleSuite
|
||||
41
16-countries-page-from-api/style-guide.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# Front-end Style Guide
|
||||
|
||||
## Layout
|
||||
|
||||
The designs were created to the following widths:
|
||||
|
||||
- Mobile: 375px
|
||||
- Desktop: 1440px
|
||||
|
||||
## Colors
|
||||
|
||||
### Neutral
|
||||
|
||||
- Dark Blue (Dark Mode Elements): hsl(209, 23%, 22%)
|
||||
- Very Dark Blue (Dark Mode Background): hsl(207, 26%, 17%)
|
||||
- Very Dark Blue (Light Mode Text): hsl(200, 15%, 8%)
|
||||
- Dark Gray (Light Mode Input): hsl(0, 0%, 52%)
|
||||
- Very Light Gray (Light Mode Background): hsl(0, 0%, 98%)
|
||||
- White (Dark Mode Text & Light Mode Elements): hsl(0, 0%, 100%)
|
||||
|
||||
## Typography
|
||||
|
||||
### Body Copy
|
||||
|
||||
- Homepage Items: 14px
|
||||
- Detail Page: 16px
|
||||
|
||||
### Fonts
|
||||
|
||||
- Family: [Nunito Sans](https://fonts.google.com/specimen/Nunito+Sans)
|
||||
- Weights: 300, 600, 800
|
||||
|
||||
## Icons
|
||||
|
||||
For the icons, you can use a font icon library. Don't worry if the icons that you choose don't look exactly like they do on the design.
|
||||
|
||||
Some suggestions can be found below:
|
||||
|
||||
- [Font Awesome](https://fontawesome.com)
|
||||
- [IcoMoon](https://icomoon.io)
|
||||
- [Ionicons](https://ionicons.com)
|
||||
20
16-countries-page-from-api/tailwind.config.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: ["./src/main/resources/**/*.html"],
|
||||
darkMode: 'class',
|
||||
theme: {
|
||||
extend: {
|
||||
colors: {
|
||||
'dark-gray': 'hsl(0, 0%, 52%)', // light mode input
|
||||
'very-light-gray': 'hsl(0, 0%, 98%)', // light mode bg
|
||||
'dark-blue': 'hsl(209, 23%, 22%)', // dark mode elements
|
||||
'very-dark-blue': 'hsl(207, 26%, 17%)', // dark mode bg
|
||||
},
|
||||
fontFamily: {
|
||||
'sans': ['NunitoSans', 'sans-serif'],
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
|
||||
18
17-results-summary-component-go/.gitignore
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
# Avoid accidental upload of the Sketch and Figma design files
|
||||
#####################################################
|
||||
## Please do not remove lines 5 and 6 - thanks! 🙂 ##
|
||||
#####################################################
|
||||
*.sketch
|
||||
*.fig
|
||||
|
||||
# Avoid accidental XD upload if you convert the design file
|
||||
###############################################
|
||||
## Please do not remove line 12 - thanks! 🙂 ##
|
||||
###############################################
|
||||
*.xd
|
||||
|
||||
# Avoid your project being littered with annoying .DS_Store files!
|
||||
.DS_Store
|
||||
.prettierignore
|
||||
|
||||
public/out.css
|
||||
0
17-results-summary-component-go/.project
Normal file
96
17-results-summary-component-go/README.org
Normal file
@@ -0,0 +1,96 @@
|
||||
* Frontend Mentor - Results summary component solution
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: frontend-mentor---results-summary-component-solution
|
||||
:END:
|
||||
This is a solution to the
|
||||
[[https://www.frontendmentor.io/challenges/results-summary-component-CE_K6s0maV][Results
|
||||
summary component challenge on Frontend Mentor]]. Frontend Mentor
|
||||
challenges help you improve your coding skills by building realistic
|
||||
projects.
|
||||
|
||||
** Overview
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: overview
|
||||
:END:
|
||||
*** The challenge
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: the-challenge
|
||||
:END:
|
||||
Users should be able to:
|
||||
|
||||
- View the optimal layout for the interface depending on their device's
|
||||
screen size
|
||||
- See hover and focus states for all interactive elements on the page
|
||||
- *Bonus*: Use the local JSON data to dynamically populate the content
|
||||
|
||||
*** Screenshot
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: screenshot
|
||||
:END:
|
||||
[[screenshot-mobile.png]]
|
||||
[[screenshot-desktop.png]]
|
||||
|
||||
*** Links
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: links
|
||||
:END:
|
||||
- Solution URL: https://github.com/efim/Learning-HTMX/tree/master/17-results-summary-component-go
|
||||
- Live Site URL: https://efim-frontentmentor-results-summary-go.onrender.com/
|
||||
|
||||
** My process
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: my-process
|
||||
:END:
|
||||
*** Built with
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: built-with
|
||||
:END:
|
||||
- Semantic HTML5 markup
|
||||
- TailwindCSS
|
||||
- Flexbox
|
||||
- CSS Grid
|
||||
- Mobile-first workflow
|
||||
- Go Server Side Rendering
|
||||
- Nix for building and docker image creation
|
||||
|
||||
*** What I learned
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: what-i-learned
|
||||
:END:
|
||||
**** restarting server of file watch
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: restarting-server-of-file-watch
|
||||
:END:
|
||||
go doesn't have built in restart on file watch, and there are separate programs that do that
|
||||
|
||||
#+begin_src bash
|
||||
wgo -verbose -file .go -file .gohtml -file tailwind.config.js tailwindcss -i ./input.css -o public/out.css :: go run main.go -p 1234
|
||||
#+end_src
|
||||
|
||||
and doing tailwind first, because server embeds the output css file, so
|
||||
it's needed for the build step
|
||||
**** setting up static routes with default go web server
|
||||
**** generating template and returning it as response of go route
|
||||
**** embedding files into the binary for portability
|
||||
**** using css variables to set custom colors in TailwindCSS
|
||||
**** getting cli arguments in the go program
|
||||
|
||||
*** Continued development
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: continued-development
|
||||
:END:
|
||||
Further things to learn: getting data from forms, general go things - coroutines, utilizing sqlite, embedding PocketBase
|
||||
|
||||
*** Useful resources
|
||||
:PROPERTIES:
|
||||
:CUSTOM_ID: useful-resources
|
||||
:END:
|
||||
- https://pkg.go.dev/text/template#example-Template-Block
|
||||
main go templating documentation
|
||||
- https://pkg.go.dev/net/http
|
||||
main default server documentation
|
||||
- https://nixos.wiki/wiki/Go - packaging Go
|
||||
- https://golangdocs.com/command-line-arguments-in-golang
|
||||
command line arguments
|
||||
|
||||
|
||||
22
17-results-summary-component-go/data.json
Normal file
@@ -0,0 +1,22 @@
|
||||
[
|
||||
{
|
||||
"category": "Reaction",
|
||||
"score": 80,
|
||||
"icon": "./assets/images/icon-reaction.svg"
|
||||
},
|
||||
{
|
||||
"category": "Memory",
|
||||
"score": 92,
|
||||
"icon": "./assets/images/icon-memory.svg"
|
||||
},
|
||||
{
|
||||
"category": "Verbal",
|
||||
"score": 61,
|
||||
"icon": "./assets/images/icon-verbal.svg"
|
||||
},
|
||||
{
|
||||
"category": "Visual",
|
||||
"score": 72,
|
||||
"icon": "./assets/images/icon-visual.svg"
|
||||
}
|
||||
]
|
||||
32
17-results-summary-component-go/default.nix
Normal file
@@ -0,0 +1,32 @@
|
||||
{ lib, pkgs, ... }:
|
||||
let
|
||||
pname = "results-summary-component";
|
||||
version = "0.0.1";
|
||||
in rec {
|
||||
package = pkgs.buildGoModule {
|
||||
inherit pname version;
|
||||
src = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
|
||||
vendorHash = null; # set to "" when get dependencies in go.mod
|
||||
|
||||
# Adding the Tailwind build step to preBuild
|
||||
preBuild = ''
|
||||
${pkgs.nodePackages.tailwindcss}/bin/tailwindcss -i ./input.css -o public/out.css
|
||||
'';
|
||||
};
|
||||
image = pkgs.dockerTools.buildLayeredImage {
|
||||
name = pname;
|
||||
tag = "latest";
|
||||
created = "now";
|
||||
config = {
|
||||
Cmd = [
|
||||
"${package}/bin/results-summary-component-go"
|
||||
"-p"
|
||||
"8080"
|
||||
"-h"
|
||||
"0.0.0.0"
|
||||
];
|
||||
ExposedPorts = { "8080/tcp" = { }; };
|
||||
};
|
||||
};
|
||||
# nixos module
|
||||
}
|
||||
BIN
17-results-summary-component-go/design/active-states.jpg
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
17-results-summary-component-go/design/desktop-design.jpg
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
17-results-summary-component-go/design/desktop-preview.jpg
Normal file
|
After Width: | Height: | Size: 37 KiB |
BIN
17-results-summary-component-go/design/mobile-design.jpg
Normal file
|
After Width: | Height: | Size: 19 KiB |
3
17-results-summary-component-go/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module sunshine.industries/results-summary-component-go
|
||||
|
||||
go 1.20
|
||||
34
17-results-summary-component-go/input.css
Normal file
@@ -0,0 +1,34 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
@layer base {
|
||||
:root {
|
||||
--summary-item-color-var: 0deg 100% 67%
|
||||
}
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'HankenGrotesk';
|
||||
src: url('/static/public/fonts/static/HankenGrotesk-Medium.ttf') format('truetype');
|
||||
font-weight: 400; /* Regular */
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'HankenGrotesk';
|
||||
src: url('/static/public/fonts/static/HankenGrotesk-Bold.ttf') format('truetype');
|
||||
font-weight: 700; /* Bold */
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'HankenGrotesk';
|
||||
src: url('/static/public/fonts/static/HankenGrotesk-ExtraBold.ttf') format('truetype');
|
||||
font-weight: 800; /* ExtraBold */
|
||||
font-style: normal;
|
||||
}
|
||||
79
17-results-summary-component-go/main.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"flag"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed public
|
||||
var publicContent embed.FS
|
||||
|
||||
//go:embed templates
|
||||
var templates embed.FS
|
||||
|
||||
type Category struct {
|
||||
Name string
|
||||
ColorHsl string
|
||||
Score int
|
||||
IconPath string
|
||||
}
|
||||
|
||||
func iconPath(categoryName string) string {
|
||||
return fmt.Sprintf("/static/public/images/icon-%s.svg", categoryName)
|
||||
}
|
||||
|
||||
type ResultsSummaryData struct {
|
||||
Categories []Category
|
||||
TotalScore int
|
||||
UpperPercent int
|
||||
}
|
||||
|
||||
// starts webserver that serves html page for exercise
|
||||
func main() {
|
||||
// serves public static resources: bundled images, fonts, css
|
||||
// visible on http://localhost:8080/static/public/some-text.txt
|
||||
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(publicContent))))
|
||||
|
||||
http.HandleFunc("/hello", func(w http.ResponseWriter, req *http.Request) {
|
||||
io.WriteString(w, "This is temporary here, hello")
|
||||
})
|
||||
|
||||
resultsData := ResultsSummaryData{
|
||||
Categories: []Category{
|
||||
{Name: "Reaction", ColorHsl: "0deg 100% 67%",
|
||||
Score: 80, IconPath: iconPath("reaction")},
|
||||
{Name: "Memory", ColorHsl: "39deg 100% 56%",
|
||||
Score: 92, IconPath: iconPath("memory")},
|
||||
{Name: "Verbal", ColorHsl: "166deg 100% 37%",
|
||||
Score: 61, IconPath: iconPath("verbal")},
|
||||
{Name: "Visual", ColorHsl: "234deg 85% 45%",
|
||||
Score: 72, IconPath: iconPath("visual")},
|
||||
},
|
||||
TotalScore: 76,
|
||||
UpperPercent: 65,
|
||||
}
|
||||
|
||||
// main page with results summary
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
||||
templateName := "templates/summary-component.gohtml"
|
||||
tmpl := template.Must(template.ParseFS(templates, "templates/index.gohtml", templateName))
|
||||
if err := tmpl.Execute(w, resultsData); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
|
||||
var port int
|
||||
var host string
|
||||
flag.IntVar(&port, "p", 8080, "Specify port for server to start on")
|
||||
flag.StringVar(&host, "h", "localhost", "Specify host for server to start on")
|
||||
flag.Parse()
|
||||
|
||||
address := fmt.Sprintf("%s:%d", host, port)
|
||||
log.Printf("starting server on %s", address)
|
||||
log.Fatal(http.ListenAndServe(address, nil))
|
||||
}
|
||||
54
17-results-summary-component-go/public/fonts/README.txt
Normal file
@@ -0,0 +1,54 @@
|
||||
Hanken Grotesk Variable Font
|
||||
============================
|
||||
|
||||
This download contains Hanken Grotesk as both variable fonts and static fonts.
|
||||
|
||||
Hanken Grotesk is a variable font with this axis:
|
||||
wght
|
||||
|
||||
This means all the styles are contained in these files:
|
||||
HankenGrotesk-VariableFont_wght.ttf
|
||||
|
||||
If your app fully supports variable fonts, you can now pick intermediate styles
|
||||
that aren’t available as static fonts. Not all apps support variable fonts, and
|
||||
in those cases you can use the static font files for Hanken Grotesk:
|
||||
static/HankenGrotesk-Medium.ttf
|
||||
static/HankenGrotesk-Bold.ttf
|
||||
static/HankenGrotesk-ExtraBold.ttf
|
||||
|
||||
Get started
|
||||
-----------
|
||||
|
||||
1. Install the font files you want to use
|
||||
|
||||
2. Use your app's font picker to view the font family and all the
|
||||
available styles
|
||||
|
||||
Learn more about variable fonts
|
||||
-------------------------------
|
||||
|
||||
https://developers.google.com/web/fundamentals/design-and-ux/typography/variable-fonts
|
||||
https://variablefonts.typenetwork.com
|
||||
https://medium.com/variable-fonts
|
||||
|
||||
In desktop apps
|
||||
|
||||
https://theblog.adobe.com/can-variable-fonts-illustrator-cc
|
||||
https://helpx.adobe.com/nz/photoshop/using/fonts.html#variable_fonts
|
||||
|
||||
Online
|
||||
|
||||
https://developers.google.com/fonts/docs/getting_started
|
||||
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide
|
||||
https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/variable-fonts
|
||||
|
||||
Installing fonts
|
||||
|
||||
MacOS: https://support.apple.com/en-us/HT201749
|
||||
Linux: https://www.google.com/search?q=how+to+install+a+font+on+gnu%2Blinux
|
||||
Windows: https://support.microsoft.com/en-us/help/314960/how-to-install-or-remove-a-font-in-windows
|
||||
|
||||
Android Apps
|
||||
|
||||
https://developers.google.com/fonts/docs/android
|
||||
https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts
|
||||
BIN
17-results-summary-component-go/public/images/favicon-32x32.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 20 20"><path stroke="#FFB21E" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.25" d="M5.833 11.667a2.5 2.5 0 1 0 .834 4.858"/><path stroke="#FFB21E" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.25" d="M3.553 13.004a3.333 3.333 0 0 1-.728-5.53m.025-.067a2.083 2.083 0 0 1 2.983-2.824m.199.054A2.083 2.083 0 1 1 10 3.75v12.917a1.667 1.667 0 0 1-3.333 0M10 5.833a2.5 2.5 0 0 0 2.5 2.5m1.667 3.334a2.5 2.5 0 1 1-.834 4.858"/><path stroke="#FFB21E" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.25" d="M16.447 13.004a3.334 3.334 0 0 0 .728-5.53m-.025-.067a2.083 2.083 0 0 0-2.983-2.824M10 3.75a2.085 2.085 0 0 1 2.538-2.033 2.084 2.084 0 0 1 1.43 2.92m-.635 12.03a1.667 1.667 0 0 1-3.333 0"/></svg>
|
||||
|
After Width: | Height: | Size: 831 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 20 20"><path stroke="#F55" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.25" d="M10.833 8.333V2.5l-6.666 9.167h5V17.5l6.666-9.167h-5Z"/></svg>
|
||||
|
After Width: | Height: | Size: 247 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 20 20"><path stroke="#00BB8F" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.25" d="M7.5 10h5M10 18.333A8.333 8.333 0 1 0 1.667 10c0 1.518.406 2.942 1.115 4.167l-.699 3.75 3.75-.699A8.295 8.295 0 0 0 10 18.333Z"/></svg>
|
||||
|
After Width: | Height: | Size: 323 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 20 20"><path stroke="#1125D6" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.25" d="M10 11.667a1.667 1.667 0 1 0 0-3.334 1.667 1.667 0 0 0 0 3.334Z"/><path stroke="#1125D6" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.25" d="M17.5 10c-1.574 2.492-4.402 5-7.5 5s-5.926-2.508-7.5-5C4.416 7.632 6.66 5 10 5s5.584 2.632 7.5 5Z"/></svg>
|
||||
|
After Width: | Height: | Size: 453 B |
2
17-results-summary-component-go/public/some-text.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
hello!
|
||||
yoyo
|
||||
BIN
17-results-summary-component-go/results-summary-component-go
Executable file
BIN
17-results-summary-component-go/screenshot-desktop.png
Normal file
|
After Width: | Height: | Size: 99 KiB |
BIN
17-results-summary-component-go/screenshot-mobile.png
Normal file
|
After Width: | Height: | Size: 47 KiB |