diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-08-11 20:42:27 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-08-11 20:42:27 +0530 |
| commit | e0cc82460c0fec4336037996c23947ab39ba4015 (patch) | |
| tree | ae5123e2d2f24ab519a9f6ddd2e800ca1b38134d /examples/form | |
| parent | 695365fa359fb98f14d06c205159739077f67fed (diff) | |
| download | css-everything-e0cc82460c0fec4336037996c23947ab39ba4015.tar.gz css-everything-e0cc82460c0fec4336037996c23947ab39ba4015.zip | |
refactor: renames form submit example
Diffstat (limited to 'examples/form')
| -rw-r--r-- | examples/form/index.html | 11 | ||||
| -rw-r--r-- | examples/form/signup.css | 77 | ||||
| -rw-r--r-- | examples/form/style.css | 38 |
3 files changed, 126 insertions, 0 deletions
diff --git a/examples/form/index.html b/examples/form/index.html new file mode 100644 index 0000000..158ee16 --- /dev/null +++ b/examples/form/index.html @@ -0,0 +1,11 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <title>Counter example</title> + <meta charset="UTF-8"> + <link href="./style.css" rel="stylesheet"> + </head> + <body> + <script async defer src="../../dist/index.js"></script> + </body> +</html> diff --git a/examples/form/signup.css b/examples/form/signup.css new file mode 100644 index 0000000..c5970c7 --- /dev/null +++ b/examples/form/signup.css @@ -0,0 +1,77 @@ + +#signup-page-content { + border: 1px solid #888; + padding: 1rem; + max-width: 700px; + margin: 1rem auto; + + --cssx-children: form#form; + --count: '0'; +} + +#signup-page-content::before { + content: "Sign-Up"; + display: block; + font-size: 2rem; + border-bottom: 1px solid gray; +} + +#form { + display: block; + + --cssx-on-submit: + prevent-default() + add-class(form, 'submitting') + request('https://httpbin.org/post', POST) + remove-class(form, 'submitting') + add-class(form, 'submitted') + ; + + --cssx-children: input#input-email input#input-password actions #message; +} +#form.submitted #message::after { + display: block; + content: "Form submitted successfully"; +} +#form.submitting #submit-btn { + pointer-events: none; + opacity: .5; +} + +#form input { + display: block; + width: 100%; + padding: 0.4rem 0.8rem; + margin-top: 1rem; +} + +#input-email { + --cssx-on-mount: + set-attr('type', 'email') + set-attr('name', 'email') + set-attr('required', 'true') + set-attr('placeholder', 'Email. Eg:- mail@postbox.com') + ; +} + +#input-password { + --cssx-on-mount: + set-attr('type', 'password') + set-attr('name', 'password') + set-attr('required', 'true') + set-attr('placeholder', 'Password. Eg:- password, password1, password2, password123') + ; +} + +#actions { + text-align: right; + padding-top: 1rem; + --cssx-children: button#submit-btn; +} + +#submit-btn { + padding: 0.4rem 0.7rem; + --cssx-on-mount: set-attr('type', 'submit'); +} +#submit-btn::after { content: "Sign-Up"; } + diff --git a/examples/form/style.css b/examples/form/style.css new file mode 100644 index 0000000..b79f265 --- /dev/null +++ b/examples/form/style.css @@ -0,0 +1,38 @@ +body { + --cssx-children: button#signup-btn signup-page; +} +body * { + box-sizing: border-box; +} + +#signup-btn { + display: inline-block; + background: #5180e9; + color: #000; + padding: 0.5rem 1rem; + cursor: pointer; + + --cssx-on-mount: set-attr('type', 'button'); + + --cssx-on-click: + add-class(signup-page, 'loading') + add-class(signup-btn, 'loading') + delay(0.5s) + load-cssx(signup-page-content, './signup.css') + remove-class(signup-page, 'loading') + remove-class(signup-btn, 'loading') + ; +} +#signup-btn::after { content: "Register now to start your free trail for $99"; } +#signup-btn.loading { + pointer-events: none; + opacity: 0.4; +} + +#signup-page { + --cssx-children: signup-page-content; +} +#signup-page.loading::after { + content: "Loading..."; +} + |
