Skip to content

Commit

Permalink
Rework .form-control generator
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlaki committed Mar 15, 2022
1 parent a6845e4 commit 362116c
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 71 deletions.
24 changes: 12 additions & 12 deletions css/spruce.css
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,18 @@ html[dir=rtl] .form-control--valid, html[dir=rtl] .form-control--invalid {
padding: 0.75em 1em;
}

select.form-control:not([multiple]):not([size]) {
background-image: url('data:image/svg+xml,%3csvg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"%3e%3cpath d="M12,12.692l-5.203,-5.203c-0.234,-0.234 -0.614,-0.234 -0.849,0l-1.272,1.273c-0.235,0.234 -0.235,0.614 -0,0.849l6.9,6.9c0.234,0.234 0.614,0.234 0.848,-0l6.9,-6.9c0.235,-0.235 0.235,-0.615 0,-0.849l-1.272,-1.273c-0.235,-0.234 -0.615,-0.234 -0.849,0l-5.203,5.203Z" style="fill:%238660cd;"/%3e%3c/svg%3e');
background-position: center right 0.5em;
background-repeat: no-repeat;
background-size: 1.25em auto;
-webkit-padding-end: 2em;
padding-inline-end: 2em;
}
html[dir=rtl] select.form-control:not([multiple]):not([size]) {
background-position: center left 0.5em;
}

.form-description {
color: var(--spruce-form-color-text);
display: block;
Expand Down Expand Up @@ -1033,18 +1045,6 @@ legend {
flex: 1 1 var(--col-width);
}

select.form-control:not([multiple]):not([size]) {
background-image: url('data:image/svg+xml,%3csvg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"%3e%3cpath d="M12,12.692l-5.203,-5.203c-0.234,-0.234 -0.614,-0.234 -0.849,0l-1.272,1.273c-0.235,0.234 -0.235,0.614 -0,0.849l6.9,6.9c0.234,0.234 0.614,0.234 0.848,-0l6.9,-6.9c0.235,-0.235 0.235,-0.615 0,-0.849l-1.272,-1.273c-0.235,-0.234 -0.615,-0.234 -0.849,0l-5.203,5.203Z" style="fill:%238660cd;"/%3e%3c/svg%3e');
background-position: center right 0.5em;
background-repeat: no-repeat;
background-size: 1.25em auto;
-webkit-padding-end: 2em;
padding-inline-end: 2em;
}
html[dir=rtl] select.form-control:not([multiple]):not([size]) {
background-position: center left 0.5em;
}

.field-feedback {
display: block;
}
Expand Down
2 changes: 1 addition & 1 deletion css/spruce.min.css

Large diffs are not rendered by default.

99 changes: 64 additions & 35 deletions scss/form/_control.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
@use '../mixin' as *;
@use '../config' as *;

@mixin generate-form-control {
.form-control {
@mixin generate-form-control(
$input,
$has-states: false,
$has-sizes: false,
$has-select: true
) {
#{$input} {
$this: &;

appearance: none;
background-color: color(background, form);
border: $form-control-border-width solid color(border, form);
Expand Down Expand Up @@ -38,51 +45,73 @@
);
}

&--valid,
&--invalid {
background-position: center right $select-icon-right-offset;
background-repeat: no-repeat;
background-size: $select-icon-width auto;
padding-inline-end: $select-padding-right;
// Validation states
@if ($has-states) {
&--valid,
&--invalid {
background-position: center right $select-icon-right-offset;
background-repeat: no-repeat;
background-size: $select-icon-width auto;
padding-inline-end: $select-padding-right;

html[dir='rtl'] & {
background-position: center left $select-icon-right-offset;
html[dir='rtl'] & {
background-position: center left $select-icon-right-offset;
}
}
}

&--valid {
@include field-icon($form-valid-image, map.get($colors, alert, success));
border-color: color(success, alert);
&--valid {
@include field-icon($form-valid-image, map.get($colors, alert, success));
border-color: color(success, alert);

&:focus {
@include field-focus(
$border: color(valid, form),
$box-shadow: color(valid-shadow, form)
);
&:focus {
@include field-focus(
$border: color(valid, form),
$box-shadow: color(valid-shadow, form)
);
}
}
}

&--invalid {
@include field-icon($form-invalid-image, map.get($colors, alert, danger));
border-color: color(danger, alert);
&--invalid {
@include field-icon($form-invalid-image, map.get($colors, alert, danger));
border-color: color(danger, alert);

&:focus {
@include field-focus(
$border: color(invalid, form),
$box-shadow: color(invalid-shadow, form)
);
&:focus {
@include field-focus(
$border: color(invalid, form),
$box-shadow: color(invalid-shadow, form)
);
}
}
}

//Sizes
&--sm {
font-size: $form-control-font-size-sm;
padding: $form-control-padding-sm;
// Sizes
@if ($has-sizes) {
&--sm {
font-size: $form-control-font-size-sm;
padding: $form-control-padding-sm;
}

&--lg {
font-size: $form-control-font-size-lg;
padding: $form-control-padding-lg;
}
}
}

&--lg {
font-size: $form-control-font-size-lg;
padding: $form-control-padding-lg;
// Generate select styling
@if ($has-select) {
select#{$input} {
&:not([multiple]):not([size]) {
@include field-icon($select-image, map.get($colors, form, select-foreground));
background-position: center right $select-icon-right-offset;
background-repeat: no-repeat;
background-size: $select-icon-width auto;
padding-inline-end: $select-padding-right;

html[dir='rtl'] & {
background-position: center left $select-icon-right-offset;
}
}
}
}
}
1 change: 0 additions & 1 deletion scss/form/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
@forward 'group';
@forward 'row';
@forward 'check';
@forward 'select';
@forward 'validation';
20 changes: 0 additions & 20 deletions scss/form/_select.scss

This file was deleted.

8 changes: 6 additions & 2 deletions scss/mixin/_generator.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
'.form-check__label',
true
);
@include generate-form-control;
@include generate-form-control(
'.form-control',
true,
true,
true
);
@include generate-form-description;
@include generate-fieldset;
@include generate-form-group;
@include generate-form-label;
@include generate-form-row;
@include generate-form-select;
@include generate-field-feedback;
}

0 comments on commit 362116c

Please sign in to comment.