1
1
mirror of https://github.com/primer/css.git synced 2024-12-02 07:53:06 +03:00

Merge pull request #132 from primer/error-states

Inline error state styling
This commit is contained in:
Aaron Shekey 2015-06-24 17:00:26 -05:00
commit 75b83df435
3 changed files with 101 additions and 50 deletions

View File

@ -296,6 +296,14 @@ body {
dl.form { dl.form {
margin: 15px 0; margin: 15px 0;
&:first-child {
margin-top: 0;
}
&:last-child {
margin-bottom: 0;
}
> dt { > dt {
margin: 0 0 6px; margin: 0 0 6px;
font-style: normal; font-style: normal;
@ -303,6 +311,7 @@ body {
> dd { > dd {
padding: 0; padding: 0;
margin-bottom: 0;
} }
} }

View File

@ -175,6 +175,26 @@ Use the `.select-sm` class to resize both default and custom `<select>`s to matc
</form> </form>
{% endexample %} {% endexample %}
## Form group validation
Convey errors and warnings for form groups. Add the appropriate class—either `.errored` or `.warn`—to the `<dl class="form">` to start. Then, house your error messaging in an additional `<dd>` with either `.error` or `.warning`.
{% example html %}
<form>
<dl class="form errored">
<dt><label>Example Text</label></dt>
<dd><input type="text" value="Example Value"></dd>
<dd class="error">This example input has an error.</dd>
</dl>
<br>
<dl class="form warn">
<dt><label>Example Text</label></dt>
<dd><input type="text" value="Example Value"></dd>
<dd class="warning">This example input has a warning.</dd>
</dl>
</form>
{% endexample %}
## Checkboxes and radios ## Checkboxes and radios
Utilities to spice up the alignment and styling of checkbox and radio controls. Utilities to spice up the alignment and styling of checkbox and radio controls.

View File

@ -29,7 +29,7 @@ textarea {
vertical-align: middle; vertical-align: middle;
background-color: #fff; background-color: #fff;
background-repeat: no-repeat; // Repeat and position set for form states (success, error, etc) background-repeat: no-repeat; // Repeat and position set for form states (success, error, etc)
background-position: right center; background-position: right 8px center; // For form validation. This keeps images 8px from right and centered vertically.
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 3px; border-radius: 3px;
outline: none; outline: none;
@ -140,7 +140,6 @@ dl.form {
width: 440px; width: 440px;
max-width: 100%; max-width: 100%;
margin-right: 5px; margin-right: 5px;
background-position-x: 98%;
} }
input { input {
@ -220,64 +219,87 @@ dl.form {
} }
} }
// Form validation
//
// Our inline errors
&.warn,
&.errored { &.errored {
> dt label { dd.warning,
color: #900; dd.error {
}
// General text next to the field
.error {
display: inline;
color: #900;
}
// Specific error explanations from the server
dd.error,
dd.warning {
display: inline-block; display: inline-block;
padding: 5px; position: absolute;
font-size: 11px; max-width: 450px; // Keep our long errors readable
color: #494620; z-index: 10;
background: #f7ea57; margin: 2px 0 0;
border: 1px solid #c0b536; padding: 5px 8px;
border-top-color: #fff; font-size: 13px;
border-bottom-right-radius: 3px; font-weight: normal;
border-bottom-left-radius: 3px; border-radius: 3px;
}
dd.warning:after,
dd.warning:before,
dd.error:after,
dd.error:before {
bottom: 100%;
z-index: 15;
left: 10px;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
dd.warning:after,
dd.error:after {
border-width: 5px;
}
dd.warning:before,
dd.error:before {
border-width: 6px;
margin-left: -1px;
} }
} }
&.warn { &.warn {
// General text next to the field
.warning {
display: inline;
color: #900;
}
// Specific warning explanations from the server
dd.warning { dd.warning {
display: inline-block; color: #4e401e;
padding: 5px; background-color: #ffe5a7;
font-size: 11px; border: 1px solid #e7ce94;
color: #494620;
background: #f7ea57; &:after {
border: 1px solid #c0b536; border-bottom-color: #ffe5a7;
border-top-color: #fff; }
border-bottom-right-radius: 3px;
border-bottom-left-radius: 3px; &:before {
border-bottom-color: #cdb683;
}
} }
} }
.form-note { &.errored {
display: inline-block; > dt label {
padding: 5px; color: $brand-red;
margin-top: -1px; }
font-size: 11px;
color: #494620; dd.error {
background: #f7ea57; color: #fff;
border: 1px solid #c0b536; background-color: #bf1515;
border-top-color: #fff; border-color: #911;
border-bottom-right-radius: 3px; font-size: 13px;
border-bottom-left-radius: 3px;
&:after {
border-bottom-color: #bf1515;
}
&:before {
border-bottom-color: #911;
}
}
} }
} }