pico/scss/content/_form.scss

326 lines
7.3 KiB
SCSS
Raw Normal View History

2019-11-27 15:31:49 +07:00
/**
* Form elements
*/
// Reboot based on :
// - normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css
// - sanitize.css v12.0.1 | CC0 1.0 Universal | github.com/csstools/sanitize.css
2019-11-27 15:31:49 +07:00
//
// 1. Change the font styles in all browsers
// 2. Remove the margin in Firefox and Safari
2019-11-27 15:31:49 +07:00
input,
optgroup,
select,
textarea {
margin: 0; // 2
font-family: inherit; // 1
font-size: 1rem; // 1
letter-spacing: inherit; // 2
2020-09-29 08:38:35 +07:00
line-height: var(--line-height); // 1
2019-11-27 15:31:49 +07:00
}
// Show the overflow in IE.
input {
overflow: visible;
}
// Remove the inheritance of text transform in Edge, Firefox, and IE
2019-11-27 15:31:49 +07:00
select {
text-transform: none;
}
// 1. Correct the text wrapping in Edge and IE
// 2. Correct the color inheritance from `fieldset` elements in IE
2019-11-27 15:31:49 +07:00
// 3. Remove the padding so developers are not caught out when they zero out
// `fieldset` elements in all browsers
2019-11-27 15:31:49 +07:00
legend {
max-width: 100%; // 1
padding: 0; // 3
color: inherit; // 2
white-space: normal; // 1
}
// 1. Remove the margin in Firefox and Safari
// 2. Remove the default vertical scrollbar in IE
// 3. Change the resize direction in all browsers (opinionated)
2019-11-27 15:31:49 +07:00
textarea {
margin: 0; // 1
overflow: auto; // 2
resize: vertical; // 3
resize: block; // 3
2019-11-27 15:31:49 +07:00
}
// Remove the padding in IE 10
2019-11-27 15:31:49 +07:00
[type="checkbox"],
[type="radio"] {
padding: 0;
}
// Correct the cursor style of increment and decrement buttons in Safari
::-webkit-inner-spin-button,
::-webkit-outer-spin-button {
2019-11-27 15:31:49 +07:00
height: auto;
}
// 1. Correct the odd appearance in Chrome and Safari
// 2. Correct the outline style in Safari
2019-11-27 15:31:49 +07:00
[type="search"] {
-webkit-appearance: textfield; // 1
outline-offset: -2px; // 2
}
// Remove the inner padding in Chrome and Safari on macOS
2019-11-27 15:31:49 +07:00
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
// 1. Correct the inability to style clickable types in iOS and Safari
// 2. Change font properties to `inherit` in Safari
2019-11-27 15:31:49 +07:00
::-webkit-file-upload-button {
-webkit-appearance: button; // 1
font: inherit; // 2
}
// Remove the inner border and padding of focus outlines in Firefox
::-moz-focus-inner {
padding: 0;
border-style: none;
}
2021-07-02 16:54:41 +07:00
// Remove the focus outline in Firefox
:-moz-focusring {
2021-07-02 16:54:41 +07:00
outline: none;
}
// Remove the additional :invalid styles in Firefox
:-moz-ui-invalid {
box-shadow: none;
}
// Change the inconsistent appearance in IE (opinionated)
::-ms-expand {
display: none;
}
// Remove the border and padding in all browsers (opinionated)
[type="file"],
[type="range"] {
padding: 0;
border-width: 0;
}
2019-11-27 15:31:49 +07:00
// Pico
//
// Force height for alternatives input types
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]) {
2020-09-29 08:38:35 +07:00
height: calc(
(1rem * var(--line-height)) +
(var(--form-element-spacing-vertical) * 2) +
2021-07-02 16:54:41 +07:00
(var(--border-width) * 2)
2020-09-29 08:38:35 +07:00
);
}
2019-11-27 15:31:49 +07:00
// Fieldset
fieldset {
margin: 0;
2021-07-02 16:54:41 +07:00
margin-bottom: var(--spacing);
2019-11-27 15:31:49 +07:00
padding: 0;
border: 0;
}
// Label & legend
label,
fieldset legend {
display: block;
2021-07-02 16:54:41 +07:00
margin-bottom: calc(var(--spacing) / 4);
2019-11-27 15:31:49 +07:00
vertical-align: middle;
}
2021-07-02 16:54:41 +07:00
// Blocks, 100%
input:not([type="checkbox"]):not([type="radio"]),
select,
2021-07-02 16:54:41 +07:00
textarea {
display: block;
width: 100%;
}
// Reset appearance (Not Checkboxes, Radios, Range and File)
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
2019-11-27 15:31:49 +07:00
select,
textarea {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
2020-09-29 08:38:35 +07:00
padding: var(--form-element-spacing-vertical) var(--form-element-spacing-horizontal);
vertical-align: middle;
}
// Commons styles
input,
select,
textarea {
2021-07-02 16:54:41 +07:00
--background-color: var(--form-element-background-color);
--border-color: var(--form-element-border-color);
--color: var(--form-element-color);
--box-shadow: none;
border: var(--border-width) solid var(--border-color);
border-radius: var(--border-radius);
2019-11-27 15:31:49 +07:00
outline: none;
2021-07-02 16:54:41 +07:00
background-color: var(--background-color);
box-shadow: var(--box-shadow);
color: var(--color);
font-weight: var(--font-weight);
@if $enable-transitions {
transition:
2020-09-29 08:38:35 +07:00
background-color var(--transition),
border-color var(--transition),
color var(--transition),
box-shadow var(--transition);
}
2021-07-02 16:54:41 +07:00
}
2019-11-27 15:31:49 +07:00
2021-07-02 16:54:41 +07:00
// Active & Focus
input:not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([readonly]),
select,
textarea {
&:active,
&:focus {
--background-color: var(--form-element-active-background-color);
2019-11-27 15:31:49 +07:00
}
2021-07-02 16:54:41 +07:00
}
2019-11-27 15:31:49 +07:00
2021-07-02 16:54:41 +07:00
// Active & Focus
input:not([type="submit"]):not([type="button"]):not([type="reset"]):not([role="switch"]):not([readonly]),
select,
textarea {
2019-11-27 15:31:49 +07:00
&:active,
&:focus {
2021-07-02 16:54:41 +07:00
--border-color: var(--form-element-active-border-color);
}
}
// Focus
input:not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="range"]):not([type="file"]):not([readonly]),
select,
textarea {
&:focus {
--box-shadow: 0 0 0 var(--outline-width) var(--form-element-focus-color);
2019-11-27 15:31:49 +07:00
}
2021-07-02 16:54:41 +07:00
}
2019-11-27 15:31:49 +07:00
2021-07-02 16:54:41 +07:00
// Disabled
input:not([type="submit"]):not([type="button"]):not([type="reset"]),
select,
textarea {
2019-11-27 15:31:49 +07:00
&[disabled] {
2021-07-02 16:54:41 +07:00
--background-color: var(--form-element-disabled-background-color);
--border-color: var(--form-element-disabled-border-color);
opacity: var(--form-element-disabled-opacity);
2021-07-02 16:54:41 +07:00
}
}
2019-11-27 15:31:49 +07:00
2021-07-02 16:54:41 +07:00
// Aria-valid
input,
select,
textarea {
&[aria-invalid] {
padding-right: 2rem;
background-position: center right .75rem;
background-repeat: no-repeat;
background-size: 1rem auto;
}
&[aria-invalid="false"] {
--border-color: var(--form-element-valid-border-color);
background-image: var(--icon-valid);
2020-09-29 08:38:35 +07:00
&:active,
&:focus {
@if $enable-important {
2021-07-02 16:54:41 +07:00
--border-color: var(--form-element-valid-active-border-color) !important;
2020-09-29 08:38:35 +07:00
}
@else {
2021-07-02 16:54:41 +07:00
--border-color: var(--form-element-valid-active-border-color);
2020-09-29 08:38:35 +07:00
}
}
2019-11-27 15:31:49 +07:00
}
2021-07-02 16:54:41 +07:00
&[aria-invalid="true"] {
--border-color: var(--form-element-invalid-border-color);
background-image: var(--icon-invalid);
2021-07-02 16:54:41 +07:00
&:active,
&:focus {
@if $enable-important {
--border-color: var(--form-element-invalid-active-border-color) !important;
}
@else {
--border-color: var(--form-element-invalid-active-border-color);
}
}
2019-11-27 15:31:49 +07:00
}
}
2021-07-02 16:54:41 +07:00
// Placeholder
input::placeholder,
input::-webkit-input-placeholder,
textarea::placeholder,
textarea::-webkit-input-placeholder,
select:invalid {
color: var(--form-element-placeholder-color);
opacity: 1;
}
2021-07-02 16:54:41 +07:00
// Margin bottom (Not Checkboxes and Radios)
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
2021-07-02 16:54:41 +07:00
margin-bottom: var(--spacing);
}
2019-11-27 15:31:49 +07:00
// Select
select {
2019-11-27 15:31:49 +07:00
// Unstyle the caret on `<select>`s in IE10+.
&::-ms-expand {
border: 0;
background-color: transparent;
}
&:not([multiple]):not([size]) {
2020-09-29 08:38:35 +07:00
padding-right: calc(var(--form-element-spacing-horizontal) + 1.5rem);
background-image: var(--icon-chevron);
2019-11-27 15:31:49 +07:00
background-position: center right .75rem;
background-repeat: no-repeat;
background-size: 1rem auto;
}
}
// Helper
input,
select,
textarea {
+ small {
2021-07-02 16:54:41 +07:00
display: block;
width: 100%;
margin-top: calc(var(--spacing) * -0.75);
margin-bottom: var(--spacing);
color: var(--muted-color);
}
2019-11-27 15:31:49 +07:00
}
// Styles for Input inside a label
label {
& > input,
2019-11-27 15:31:49 +07:00
& > select,
& > textarea {
2021-07-02 16:54:41 +07:00
margin-top: calc(var(--spacing) / 4);
2019-11-27 15:31:49 +07:00
}
}