picocss/scss/forms/_basics.scss

444 lines
12 KiB
SCSS
Raw Normal View History

2022-10-23 10:47:50 +07:00
@use "sass:map";
2022-10-22 13:11:51 +07:00
@use "../settings" as *;
2022-10-22 11:44:10 +07:00
2022-10-23 10:47:50 +07:00
@if map.get($modules, "forms/basics") {
2023-04-09 11:54:55 +07:00
// Helper
$helper-previous-tags: "input, select, textarea";
2022-10-23 10:47:50 +07:00
/**
* Basics form elements
*/
// Reboot based on :
// - normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css
// - sanitize.css v13.0.0 | CC0 1.0 Universal | github.com/csstools/sanitize.css
//
// 1. Change the font styles in all browsers
// 2. Remove the margin in Firefox and Safari
input,
optgroup,
select,
textarea {
margin: 0; // 2
font-size: 1rem; // 1
line-height: var(#{$}line-height); // 1
font-family: inherit; // 1
letter-spacing: inherit; // 2
}
2019-11-27 15:31:49 +07:00
2022-10-23 10:47:50 +07:00
// Show the overflow in IE.
input {
overflow: visible;
}
2019-11-27 15:31:49 +07:00
2022-10-23 10:47:50 +07:00
// Remove the inheritance of text transform in Edge, Firefox, and IE
select {
text-transform: none;
}
2019-11-27 15:31:49 +07:00
2022-10-23 10:47:50 +07:00
// 1. Correct the text wrapping in Edge and IE
// 2. Correct the color inheritance from `fieldset` elements in IE
// 3. Remove the padding so developers are not caught out when they zero out
// `fieldset` elements in all browsers
legend {
max-width: 100%; // 1
padding: 0; // 3
color: inherit; // 2
white-space: normal; // 1
}
2019-11-27 15:31:49 +07:00
2022-10-23 10:47:50 +07:00
// 1. Remove the default vertical scrollbar in IE
textarea {
overflow: auto; // 1
}
2019-11-27 15:31:49 +07:00
2022-10-23 10:47:50 +07:00
// Remove the padding in IE 10
[type="checkbox"],
[type="radio"] {
padding: 0;
}
2019-11-27 15:31:49 +07:00
2022-10-23 10:47:50 +07:00
// Correct the cursor style of increment and decrement buttons in Safari
::-webkit-inner-spin-button,
::-webkit-outer-spin-button {
height: auto;
}
2022-10-23 10:47:50 +07:00
// 1. Correct the odd appearance in Chrome and Safari
// 2. Correct the outline style in Safari
[type="search"] {
-webkit-appearance: textfield; // 1
outline-offset: -2px; // 2
}
2022-10-23 10:47:50 +07:00
// Remove the inner padding in Chrome and Safari on macOS
[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
2022-10-23 10:47:50 +07:00
// 1. Correct the inability to style clickable types in iOS and Safari
// 2. Change font properties to `inherit` in Safari
::-webkit-file-upload-button {
-webkit-appearance: button; // 1
font: inherit; // 2
}
2022-10-23 10:47:50 +07:00
// Remove the inner border and padding of focus outlines in Firefox
::-moz-focus-inner {
padding: 0;
border-style: none;
}
2022-10-23 10:47:50 +07:00
// Remove the focus outline in Firefox
:-moz-focusring {
outline: none;
}
2019-11-27 15:31:49 +07:00
2022-10-23 10:47:50 +07:00
// Remove the additional :invalid styles in Firefox
:-moz-ui-invalid {
box-shadow: none;
}
2022-10-23 10:47:50 +07:00
// Change the inconsistent appearance in IE (opinionated)
::-ms-expand {
display: none;
}
2019-11-27 15:31:49 +07:00
2022-10-23 10:47:50 +07:00
// Remove the border and padding in all browsers (opinionated)
[type="file"],
[type="range"] {
padding: 0;
border-width: 0;
}
2022-10-23 10:47:50 +07:00
// Pico
//
2022-10-23 10:47:50 +07:00
// Force height for alternatives input types
input:not([type="checkbox"], [type="radio"], [type="range"]) {
height: calc(
(1rem * var(#{$}line-height)) +
(var(#{$}form-element-spacing-vertical) * 2) +
(var(#{$}border-width) * 2)
);
}
2022-10-23 10:47:50 +07:00
// Fieldset
fieldset {
margin: 0;
margin-bottom: var(#{$}spacing);
padding: 0;
border: 0;
}
2019-11-27 15:31:49 +07:00
2022-10-23 10:47:50 +07:00
// Label & legend
label,
fieldset legend {
display: block;
2023-03-15 22:15:25 +07:00
margin-bottom: calc(var(#{$}spacing) * 0.375);
2022-10-23 10:47:50 +07:00
font-weight: var(#{$}form-label-font-weight, var(#{$}font-weight));
2019-11-27 15:31:49 +07:00
}
2023-03-15 22:15:25 +07:00
fieldset legend {
margin-bottom: calc(var(#{$}spacing) * 0.5);
}
2022-10-23 10:47:50 +07:00
// Blocks, 100%
input:not([type="checkbox"], [type="radio"]),
select,
textarea {
width: 100%;
2021-07-02 16:54:41 +07:00
}
2022-10-23 10:47:50 +07:00
// Reset appearance (Not Checkboxes, Radios, Range and File)
input:not([type="checkbox"], [type="radio"], [type="range"], [type="file"]),
select,
textarea {
appearance: none;
padding: var(#{$}form-element-spacing-vertical) var(#{$}form-element-spacing-horizontal);
2019-11-27 15:31:49 +07:00
}
2022-10-23 10:47:50 +07:00
// Commons styles
input,
select,
textarea {
#{$✨}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);
outline: none;
background-color: var(#{$}background-color);
box-shadow: var(#{$}box-shadow);
color: var(#{$}color);
font-weight: var(#{$}font-weight);
@if $enable-transitions {
transition: background-color var(#{$}transition), border-color var(#{$}transition),
color var(#{$}transition), box-shadow var(#{$}transition);
}
}
2019-11-27 15:31:49 +07:00
2022-10-23 10:47:50 +07:00
// Active & Focus
2022-12-26 13:36:41 +07:00
input:not(
[type="submit"],
[type="button"],
[type="reset"],
[type="checkbox"],
[type="radio"],
[readonly]
),
2022-10-23 10:47:50 +07:00
:where(select, textarea) {
&:is(:active, :focus) {
#{$✨}background-color: var(#{$}form-element-active-background-color);
}
2022-10-23 10:47:50 +07:00
}
2022-10-23 10:47:50 +07:00
// Active & Focus
input:not([type="submit"], [type="button"], [type="reset"], [role="switch"], [readonly]),
:where(select, textarea) {
&:is(:active, :focus) {
#{$✨}border-color: var(#{$}form-element-active-border-color);
}
2022-10-23 10:47:50 +07:00
}
2022-03-06 10:53:20 +07:00
2022-10-23 10:47:50 +07:00
// Focus
2022-12-26 13:36:41 +07:00
input:not(
[type="submit"],
[type="button"],
[type="reset"],
[type="range"],
[type="file"],
[readonly]
),
2022-12-26 11:35:56 +07:00
:where(select, textarea) {
2022-10-23 10:47:50 +07:00
&:focus {
#{$✨}box-shadow: 0 0 0 var(#{$}outline-width) var(#{$}form-element-focus-color);
}
2021-07-02 16:54:41 +07:00
}
2022-10-23 10:47:50 +07:00
// Disabled
input:not([type="submit"], [type="button"], [type="reset"])[disabled],
select[disabled],
textarea[disabled],
label[aria-disabled="true"],
2022-10-23 10:47:50 +07:00
:where(fieldset[disabled])
:is(input:not([type="submit"], [type="button"], [type="reset"]), select, textarea) {
#{$✨}background-color: var(#{$}form-element-disabled-background-color);
#{$✨}border-color: var(#{$}form-element-disabled-border-color);
opacity: var(#{$}form-element-disabled-opacity);
pointer-events: none;
}
2020-09-29 08:38:35 +07:00
label[aria-disabled="true"] input[disabled] {
opacity: 1;
}
2022-10-23 10:47:50 +07:00
// Aria-invalid
:where(input, select, textarea) {
2022-12-26 13:36:41 +07:00
&:not(
[type="checkbox"],
[type="radio"],
[type="date"],
[type="datetime-local"],
[type="month"],
[type="time"],
2023-03-18 08:22:05 +07:00
[type="week"],
[type="range"]
2022-12-26 13:36:41 +07:00
) {
2022-10-23 10:47:50 +07:00
&[aria-invalid] {
@if $enable-important {
padding-right: calc(var(#{$}form-element-spacing-horizontal) + 1.5rem) !important;
padding-left: var(#{$}form-element-spacing-horizontal);
padding-inline-start: var(#{$}form-element-spacing-horizontal) !important;
padding-inline-end: calc(var(#{$}form-element-spacing-horizontal) + 1.5rem) !important;
} @else {
padding-right: calc(var(#{$}form-element-spacing-horizontal) + 1.5rem);
padding-left: var(#{$}form-element-spacing-horizontal);
padding-inline-start: var(#{$}form-element-spacing-horizontal);
padding-inline-end: calc(var(#{$}form-element-spacing-horizontal) + 1.5rem);
}
background-position: center right 0.75rem;
background-size: 1rem auto;
background-repeat: no-repeat;
}
&[aria-invalid="false"]:not(select) {
2022-10-23 10:47:50 +07:00
background-image: var(#{$}icon-valid);
}
&[aria-invalid="true"]:not(select) {
2022-10-23 10:47:50 +07:00
background-image: var(#{$}icon-invalid);
2020-09-29 08:38:35 +07:00
}
}
2019-11-27 15:31:49 +07:00
2022-10-23 10:47:50 +07:00
&[aria-invalid="false"] {
#{$✨}border-color: var(#{$}form-element-valid-border-color);
&:is(:active, :focus) {
@if $enable-important {
#{$✨}border-color: var(#{$}form-element-valid-active-border-color) !important;
2023-03-15 22:15:25 +07:00
&:not([type="checkbox"], [type="radio"]) {
#{$}box-shadow: 0
0
0
var(#{$}outline-width)
var(#{$}form-element-valid-focus-color) !important;
}
2022-10-23 10:47:50 +07:00
} @else {
#{$✨}border-color: var(#{$}form-element-valid-active-border-color);
2023-03-15 22:15:25 +07:00
&:not([type="checkbox"], [type="radio"]) {
#{$}box-shadow: 0
0
0
var(#{$}outline-width)
var(#{$}form-element-valid-focus-color);
}
2022-10-23 10:47:50 +07:00
}
}
}
2022-03-06 10:53:20 +07:00
2022-10-23 10:47:50 +07:00
&[aria-invalid="true"] {
#{$✨}border-color: var(#{$}form-element-invalid-border-color);
&:is(:active, :focus) {
@if $enable-important {
#{$✨}border-color: var(#{$}form-element-invalid-active-border-color) !important;
2023-03-15 22:15:25 +07:00
&:not([type="checkbox"], [type="radio"]) {
#{$}box-shadow: 0
0
0
var(#{$}outline-width)
var(#{$}form-element-invalid-focus-color) !important;
}
2022-10-23 10:47:50 +07:00
} @else {
#{$✨}border-color: var(#{$}form-element-invalid-active-border-color);
2023-03-15 22:15:25 +07:00
&:not([type="checkbox"], [type="radio"]) {
#{$}box-shadow: 0
0
0
var(#{$}outline-width)
var(#{$}form-element-invalid-focus-color);
}
2022-10-23 10:47:50 +07:00
}
2021-07-02 16:54:41 +07:00
}
}
2019-11-27 15:31:49 +07:00
}
2022-10-23 10:47:50 +07:00
[dir="rtl"] {
:where(input, select, textarea) {
&:not([type="checkbox"], [type="radio"]) {
&:is([aria-invalid], [aria-invalid="true"], [aria-invalid="false"]) {
background-position: center left 0.75rem;
}
}
2021-10-24 02:06:00 +07:00
}
}
2022-10-23 10:47:50 +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;
2019-11-27 15:31:49 +07:00
}
2022-10-23 10:47:50 +07:00
// Margin bottom (Not Checkboxes and Radios)
input:not([type="checkbox"], [type="radio"]),
select,
textarea {
margin-bottom: var(#{$}spacing);
2019-11-27 15:31:49 +07:00
}
2022-10-23 10:47:50 +07:00
// Select
2021-10-24 12:33:20 +07:00
select {
2022-10-23 10:47:50 +07:00
// Unstyle the caret on `<select>`s in IE10+.
&::-ms-expand {
border: 0;
background-color: transparent;
}
2022-09-11 18:30:49 +07:00
&:not([multiple], [size]) {
2022-10-23 10:47:50 +07:00
padding-right: calc(var(#{$}form-element-spacing-horizontal) + 1.5rem);
padding-left: var(#{$}form-element-spacing-horizontal);
padding-inline-start: var(#{$}form-element-spacing-horizontal);
padding-inline-end: calc(var(#{$}form-element-spacing-horizontal) + 1.5rem);
background-image: var(#{$}icon-chevron);
background-position: center right 0.75rem;
background-size: 1rem auto;
background-repeat: no-repeat;
2021-10-24 02:06:00 +07:00
}
&[multiple] {
option {
&:checked {
background: var(#{$}form-element-selected-background-color);
}
}
}
2021-10-24 02:06:00 +07:00
}
2022-10-23 10:47:50 +07:00
[dir="rtl"] {
select {
&:not([multiple], [size]) {
background-position: center left 0.75rem;
}
}
}
2023-03-13 01:38:56 +07:00
// Textarea
textarea {
display: block;
resize: vertical;
&[aria-invalid] {
@if $enable-important {
#{$}icon-height: calc(
(1rem * var(#{$}line-height)) +
(var(#{$}form-element-spacing-vertical) * 2) +
(var(#{$}border-width) * 2)
);
background-position: top right 0.75rem !important;
background-size: 1rem var(#{$}icon-height) !important;
}
}
}
2023-04-09 11:54:55 +07:00
@if map.get($modules, "layout/grid") and $enable-classes {
$helper-previous-tags: $helper-previous-tags + ", .grid";
}
2023-03-13 01:38:56 +07:00
2023-04-09 11:54:55 +07:00
:where(#{$helper-previous-tags}) {
2022-10-23 10:47:50 +07:00
+ small {
display: block;
width: 100%;
2023-03-13 01:38:56 +07:00
margin-top: calc(var(#{$}spacing) * -0.75);
2022-10-23 10:47:50 +07:00
margin-bottom: var(#{$}spacing);
color: var(#{$}muted-color);
}
&[aria-invalid="false"] {
+ small {
color: var(#{$}ins-color);
}
}
&[aria-invalid="true"] {
+ small {
color: var(#{$}del-color);
}
}
}
2019-11-27 15:31:49 +07:00
2022-10-23 10:47:50 +07:00
// Styles for Input inside a label
label {
> :where(input, select, textarea) {
margin-top: calc(var(#{$}spacing) * 0.25);
}
2019-11-27 15:31:49 +07:00
}
2022-10-15 23:22:12 +07:00
}