Skip to content

Commit

Permalink
feat: Enable boostrap form validation styling for angular control states
Browse files Browse the repository at this point in the history
Added SCSS to apply bootstrap form validation styling for form controls.
  • Loading branch information
jrassa committed Aug 23, 2024
1 parent 83a5c5b commit e446f8e
Show file tree
Hide file tree
Showing 13 changed files with 134 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/app/common/flyout/flyout.component.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@import '../../../styles/shared';
@import '../../../styles/bootstrap/shared';

$flyout-border-top: 8px !default;
$flyout-box-shadow: 0 0.25rem 0.5rem rgba(var(--bs-body-bg-rgb), 0.2) !default;
Expand Down
1 change: 0 additions & 1 deletion src/app/common/system-alert/system-alert.component.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@use 'sass:map';
@import '../../../styles/shared';
@import '../../../styles/bootstrap/shared';

$system-alert-icons: () !default;
$system-alert-icons: map.merge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h2 skipTo>{{ mode() | titlecase }} Message</h2>
name="type"
bindLabel="display"
bindValue="value"
required
style="width: 350px"
[(ngModel)]="message().type"
[items]="typeOptions"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@import '../../../../styles/shared';
@import '../../../../styles/bootstrap/shared';

.feedback-form {
width: 550px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@use 'sass:map';
@import '../../../../styles/bootstrap/shared';
@import '../../../../styles/shared';
@import '../shared';

Expand Down
54 changes: 48 additions & 6 deletions src/styles/_bootstrap.scss
Original file line number Diff line number Diff line change
@@ -1,18 +1,60 @@
@import 'bootstrap/shared';

@import '../../node_modules/bootstrap/scss/bootstrap';

/**
* _bootstrap.scss
* This file is globally included in the Angular application.
* All bootstrap theme styles should be included in this file.
*/

//@import '../../node_modules/bootstrap/scss/bootstrap';

@import "bootstrap/shared";

// Layout & components
/**
* Individual components can be removed below to help reduce
* bundle size if not being used.
*/
@import "../../node_modules/bootstrap/scss/root";
@import "../../node_modules/bootstrap/scss/reboot";
@import "../../node_modules/bootstrap/scss/type";
@import "../../node_modules/bootstrap/scss/images";
@import "../../node_modules/bootstrap/scss/containers";
@import "../../node_modules/bootstrap/scss/grid";
@import "../../node_modules/bootstrap/scss/tables";
@import "../../node_modules/bootstrap/scss/forms";
@import "../../node_modules/bootstrap/scss/buttons";
@import "../../node_modules/bootstrap/scss/transitions";
@import "../../node_modules/bootstrap/scss/dropdown";
@import "../../node_modules/bootstrap/scss/button-group";
@import "../../node_modules/bootstrap/scss/nav";
@import "../../node_modules/bootstrap/scss/navbar";
@import "../../node_modules/bootstrap/scss/card";
@import "../../node_modules/bootstrap/scss/accordion";
@import "../../node_modules/bootstrap/scss/breadcrumb";
@import "../../node_modules/bootstrap/scss/pagination";
@import "../../node_modules/bootstrap/scss/badge";
@import "../../node_modules/bootstrap/scss/alert";
@import "../../node_modules/bootstrap/scss/progress";
@import "../../node_modules/bootstrap/scss/list-group";
@import "../../node_modules/bootstrap/scss/close";
@import "../../node_modules/bootstrap/scss/toasts";
@import "../../node_modules/bootstrap/scss/modal";
@import "../../node_modules/bootstrap/scss/tooltip";
@import "../../node_modules/bootstrap/scss/popover";
@import "../../node_modules/bootstrap/scss/carousel";
@import "../../node_modules/bootstrap/scss/spinners";
@import "../../node_modules/bootstrap/scss/offcanvas";
@import "../../node_modules/bootstrap/scss/placeholders";

// Helpers
@import "../../node_modules/bootstrap/scss/helpers";

// Utilities
@import "../../node_modules/bootstrap/scss/utilities/api";

// Additional styles
@import 'bootstrap/buttons';
@import 'bootstrap/cards';
@import 'bootstrap/dropdowns';
@import 'bootstrap/forms';
@import 'bootstrap/grid';
@import 'bootstrap/nav';
@import 'bootstrap/tables';
40 changes: 39 additions & 1 deletion src/styles/_ng-select.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@use 'sass:color';
@import 'shared';
@import 'bootstrap/shared';

@import '../../node_modules/@ng-select/ng-select/scss/mixins'; /* stylelint-disable-line no-invalid-position-at-import-rule */

Expand Down Expand Up @@ -35,6 +34,41 @@ $ng-select-dropdown-option-bg: $ng-select-dropdown-bg !default;
$ng-select-dropdown-option-text: var(--bs-body-color) !default;
$ng-select-dropdown-option-disabled: color.adjust($ng-select-primary-text-old, $lightness: 60%) !default;

@mixin ng-select-form-validation-state(
$state,
$color,
$icon,
$tooltip-color: color-contrast($color),
$tooltip-bg-color: rgba($color, $form-feedback-tooltip-opacity),
$focus-box-shadow: 0 0 $input-btn-focus-blur $input-focus-width rgba($color, $input-btn-focus-color-opacity),
$border-color: $color
) {
@include form-validation-state-selector($state) {
.ng-select-container {
border-color: $border-color;

@if $enable-validation-icons {
padding-right: $input-height-inner;
background-image: escape-svg($icon);
background-repeat: no-repeat;
background-position: right $input-height-inner-quarter center;
background-size: $input-height-inner-half $input-height-inner-half;
}
}
&.ng-select-focused {
&:not(.ng-select-opened) > .ng-select-container {
border-color: $border-color;
@if $enable-shadows {
@include box-shadow($input-box-shadow, $focus-box-shadow);
} @else {
// Avoid using mixin so we can pass custom focus shadow properly
box-shadow: $focus-box-shadow;
}
}
}
}
}

.ng-select {
&.ng-select-opened {
> .ng-select-container {
Expand Down Expand Up @@ -253,6 +287,10 @@ $ng-select-dropdown-option-disabled: color.adjust($ng-select-primary-text-old, $
border-width: 5px 5px 2.5px;
}
}

@each $state, $data in $form-validation-states {
@include ng-select-form-validation-state($state, $data...);
}
}

.ng-dropdown-panel {
Expand Down
1 change: 1 addition & 0 deletions src/styles/bootstrap/_buttons.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@use 'sass:math';
@import 'shared';

// Submit Button
$btn-submit-style: spinner !default;
Expand Down
13 changes: 13 additions & 0 deletions src/styles/bootstrap/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,16 @@ $form-inline-edit-label-col-width: 30% !default;
}
}
}

@mixin form-validation-state-selector($state) {
@if ($state == "valid" or $state == "invalid") {
.was-validated #{if(&, "&", "")}:#{$state},
#{if(&, "&", "")}.is-#{$state} {
@content;
}
} @else {
#{if(&, "&", "")}.is-#{$state} {
@content;
}
}
}
21 changes: 21 additions & 0 deletions src/styles/bootstrap/_mixins_override.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Mixins defined here will override mixins of the same name provided by bootstrap

@mixin form-validation-state-selector($state) {
@if ($state == "valid" or $state == "invalid") {
.was-validated #{if(&, "&", "")}:#{$state},
#{if(&, "&", "")}.is-#{$state} {
@content;
}
} @else {
#{if(&, "&", "")}.is-#{$state} {
@content;
}
}
// Add bootstrap validation styling based on ng-invalid
@if ($state == "invalid") {
#{if(&, "&", "")}.ng-#{$state}.ng-dirty,
#{if(&, "&", "")}.ng-#{$state}.ng-touched {
@content;
}
}
}
1 change: 0 additions & 1 deletion src/styles/bootstrap/_nav.scss

This file was deleted.

16 changes: 11 additions & 5 deletions src/styles/bootstrap/_shared.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// Imports non-rendering bootstrap SASS (i.e. variables, functions, mixins) for easy import into other files.
// Variable overrides must be imported before the variables are defined
@import 'variables_overrides';

@import 'variables';
// Configuration
@import "../../../node_modules/bootstrap/scss/functions";
@import "../../../node_modules/bootstrap/scss/variables";
@import "../../../node_modules/bootstrap/scss/variables-dark";
@import "../../../node_modules/bootstrap/scss/maps";
@import "../../../node_modules/bootstrap/scss/mixins";
@import "../../../node_modules/bootstrap/scss/utilities";

@import '../../../node_modules/bootstrap/scss/functions';
@import '../../../node_modules/bootstrap/scss/variables';
@import '../../../node_modules/bootstrap/scss/mixins';
// Mixin overrides must be imported before the mixins are used.
@import "mixins_override";
File renamed without changes.

0 comments on commit e446f8e

Please sign in to comment.