UNPKG

2.16 kBSCSSView Raw
1// Foundation for Sites by ZURB
2// foundation.zurb.com
3// Licensed under MIT Open Source
4
5////
6/// @group abide
7////
8
9/// Sets if error styles should be added to inputs.
10/// @type Boolean
11$abide-inputs: true !default;
12
13/// Sets if error styles should be added to labels.
14/// @type Boolean
15$abide-labels: true !default;
16
17/// Background color to use for invalid text inputs.
18/// @type Color
19$input-background-invalid: get-color(alert) !default;
20
21/// Color to use for labels of invalid inputs.
22/// @type Color
23$form-label-color-invalid: get-color(alert) !default;
24
25/// Default font color for form error text.
26/// @type Color
27$input-error-color: get-color(alert) !default;
28
29/// Default font size for form error text.
30/// @type Number
31$input-error-font-size: rem-calc(12) !default;
32
33/// Default font weight for form error text.
34/// @type Keyword
35$input-error-font-weight: $global-weight-bold !default;
36
37/// Styles the background and border of an input field to have an error state.
38///
39/// @param {Color} $background [$alert-color] - Color to use for the background and border.
40/// @param {Number} $background-lighten [10%] - Lightness level of the background color.
41@mixin form-input-error(
42 $background: $input-background-invalid,
43 $background-lighten: 10%
44) {
45 &:not(:focus) {
46 border-color: $background;
47 background-color: mix($background, $white, $background-lighten);
48 &::placeholder {
49 color: $background;
50 }
51 }
52}
53
54/// Adds error styles to a form element, using the values in the settings file.
55@mixin form-error {
56 display: none;
57 margin-top: $form-spacing * -0.5;
58 margin-bottom: $form-spacing;
59
60 font-size: $input-error-font-size;
61 font-weight: $input-error-font-weight;
62 color: $input-error-color;
63}
64
65@mixin foundation-form-error {
66 @if $abide-inputs {
67 // Error class for invalid inputs
68 .is-invalid-input {
69 @include form-input-error;
70 }
71 }
72
73 @if $abide-labels {
74 // Error class for labels of invalid outputs
75 .is-invalid-label {
76 color: $form-label-color-invalid;
77 }
78 }
79
80 // Form error element
81 .form-error {
82 @include form-error;
83
84 &.is-visible {
85 display: block;
86 }
87 }
88}