From aefacb0a07a9ef66172dfccb24714717585f86b1 Mon Sep 17 00:00:00 2001
From: Volpeon <git@volpeon.ink>
Date: Sun, 6 Feb 2022 11:08:53 +0100
Subject: Added form

---
 src/index.scss             |  2 ++
 src/layouts/_form.scss     | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 src/objects/_checkbox.scss |  1 +
 src/objects/_radio.scss    |  1 +
 src/objects/_switch.scss   |  1 +
 tpl/index.pug              | 34 ++++++++++++++++++++++++++++++++++
 tpl/objects/form.pug       | 13 +++++++++++++
 yarn.lock                  |  2 +-
 8 files changed, 99 insertions(+), 1 deletion(-)
 create mode 100644 src/layouts/_form.scss
 create mode 100644 tpl/objects/form.pug

diff --git a/src/index.scss b/src/index.scss
index c945321..9f7f85e 100644
--- a/src/index.scss
+++ b/src/index.scss
@@ -16,6 +16,8 @@
 @import 'objects/checkbox';
 @import 'objects/switch';
 
+@import 'layouts/form';
+
 :root {
     @include iro.props-assign;
     @include iro.props-assign('light-palette');
diff --git a/src/layouts/_form.scss b/src/layouts/_form.scss
new file mode 100644
index 0000000..9e6520f
--- /dev/null
+++ b/src/layouts/_form.scss
@@ -0,0 +1,46 @@
+@use 'iro-sass/src/index' as iro;
+
+@include iro.props-namespace('form') {
+    @include iro.props-store((
+        --dims: (
+            --item-spacing-y:  iro.props-get(--dims --spacing --y --md, $global: true),
+            --label-spacing-x: iro.props-get(--dims --spacing --x --md, $global: true),
+            --hint-font-size:  iro.props-get(--dims --font-size --sm, $global: true),
+        ),
+    ));
+
+    @include iro.bem-layout(iro.props-namespace()) {
+        display:               grid;
+        grid-template-columns: auto 1fr;
+        grid-template-rows:    auto;
+        align-items:           baseline;
+        gap:                   iro.props-get(--dims --item-spacing-y) iro.props-get(--dims --label-spacing-x);
+    
+        @include iro.bem-elem('item') {
+            display: contents;
+        }
+    
+        @include iro.bem-elem('item-label') {
+            grid-column: 1;
+        }
+    
+        @include iro.bem-elem('item-content') {
+            grid-column: 2;
+        }
+    
+        @include iro.bem-modifier('labels-right') {
+            @include iro.bem-elem('item-label') {
+                text-align: right;
+            }
+        }
+    
+        @include iro.bem-modifier('labels-above') {
+            display:        flex;
+            flex-direction: column;
+    
+            @include iro.bem-elem('item') {
+                display: block;
+            }
+        }
+    }
+}
diff --git a/src/objects/_checkbox.scss b/src/objects/_checkbox.scss
index 606b717..587321b 100644
--- a/src/objects/_checkbox.scss
+++ b/src/objects/_checkbox.scss
@@ -105,6 +105,7 @@
         }
     
         @include iro.bem-elem('label') {
+            align-self:  baseline;
             margin-left: iro.props-get(--dims --label-gap);
         }
     
diff --git a/src/objects/_radio.scss b/src/objects/_radio.scss
index bb32cdf..213b7c4 100644
--- a/src/objects/_radio.scss
+++ b/src/objects/_radio.scss
@@ -74,6 +74,7 @@
         }
     
         @include iro.bem-elem('label') {
+            align-self:  baseline;
             margin-left: iro.props-get(--dims --label-gap);
         }
     
diff --git a/src/objects/_switch.scss b/src/objects/_switch.scss
index 25125da..7d5d16d 100644
--- a/src/objects/_switch.scss
+++ b/src/objects/_switch.scss
@@ -80,6 +80,7 @@
         }
     
         @include iro.bem-elem('label') {
+            align-self:  baseline;
             margin-left: iro.props-get(--dims --label-gap);
         }
     
diff --git a/tpl/index.pug b/tpl/index.pug
index 8595be0..2ebb625 100644
--- a/tpl/index.pug
+++ b/tpl/index.pug
@@ -11,6 +11,7 @@ include objects/field-label.pug
 include objects/radio.pug
 include objects/checkbox.pug
 include objects/switch.pug
+include objects/form.pug
 
 mixin box 
     +container(padX=true padY=true inPage=true theme="raised")
@@ -268,3 +269,36 @@ html
                 +switch(accent=true disabled=true)= 'Cats'
                 +switch(accent=true disabled=true)= 'Dogs'
                 +switch(accent=true checked=true disabled=true)= 'Foxes'
+
+            //-----------------------------------------
+
+            +h1-heading(level='xl')= 'Form'
+            +rule(level='medium')
+
+            +box
+                +form
+                    +form-item('Username')
+                        +text-field(placeholder='Example: Volpeon')
+
+                    +form-item('Password', 'At least 6 characters, all characters allowed')
+                        +text-field(placeholder='Example: hunter2', type='password')
+
+                    +form-item('Bio')
+                        +text-field(placeholder='Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam...')
+
+                    +form-item('Favorite animal')
+                        +radio(name="form-demo-1" checked=true)= 'Foxes'
+                        +radio(name="form-demo-1")= 'Other'
+
+                    +form-item('Notification settings')
+                        +switch= 'In-app notifications'
+                        br
+                        +switch= 'Desktop notifications'
+                        br
+                        +switch= 'Email notifications'
+
+                    +form-item('')
+                        +checkbox= 'I\'ve read and accept the terms and conditions'
+
+                    +form-item('')
+                        +a-button(variant='primary')= 'Register'
diff --git a/tpl/objects/form.pug b/tpl/objects/form.pug
new file mode 100644
index 0000000..496ed48
--- /dev/null
+++ b/tpl/objects/form.pug
@@ -0,0 +1,13 @@
+include field-label.pug
+
+mixin form
+    form(class={
+        'l-form':               true,
+        'l-form--labels-right': attributes.labelsAlign === 'right',
+        'l-form--labels-above': attributes.labelsAlign === 'above'
+        })
+        block
+
+mixin form-item(label, hint=null)
+    +field-label(label, hint)(class='l-form__item' labelClass='l-form__item-label' contentClass='l-form__item-content')
+        block
diff --git a/yarn.lock b/yarn.lock
index b5d2cce..9653150 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1260,7 +1260,7 @@ internal-slot@^1.0.3:
 
 "iro-sass@git+https://git.vulpes.one/git/iro-sass.git":
   version "1.0.2"
-  resolved "git+https://git.vulpes.one/git/iro-sass.git#bab633f8a6faf4be7cd4ebd16b1b5c270d95320a"
+  resolved "git+https://git.vulpes.one/git/iro-sass.git#9f1653f2ab64ef8cb4c545416da4241baa481557"
 
 is-arrayish@^0.2.1:
   version "0.2.1"
-- 
cgit v1.2.3-70-g09d2