picocss/scss/content/_button.scss

234 lines
5.5 KiB
SCSS
Raw Normal View History

2019-11-27 15:31:49 +07:00
/**
* Button
*/
// 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
2019-11-27 15:31:49 +07:00
// 2. Remove the margin in Firefox and Safari
// 3. Show the overflow in Edge
button {
margin: 0; // 2
overflow: visible; // 3
font-family: inherit; // 1
text-transform: none; // 1
}
// Correct the inability to style clickable types in iOS and Safari
2019-11-27 15:31:49 +07:00
button,
[type="button"],
[type="reset"],
[type="submit"] {
-webkit-appearance: button;
}
// Remove the inner border and padding in Firefox
2019-11-27 15:31:49 +07:00
button::-moz-focus-inner,
[type="button"]::-moz-focus-inner,
[type="reset"]::-moz-focus-inner,
[type="submit"]::-moz-focus-inner {
2021-07-02 16:54:41 +07:00
padding: 0;
border-style: none;
2019-11-27 15:31:49 +07:00
}
// Pico
//
button {
display: block;
width: 100%;
2021-07-02 16:54:41 +07:00
margin-bottom: var(--spacing);
2019-11-27 15:31:49 +07:00
}
2022-01-16 11:41:50 +07:00
[role="button"] {
2019-11-27 15:31:49 +07:00
display: inline-block;
text-decoration: none;
}
button,
input[type="submit"],
input[type="button"],
2020-09-29 08:38:35 +07:00
input[type="reset"],
2022-01-16 11:41:50 +07:00
[role="button"] {
2021-07-02 16:54:41 +07:00
--background-color: var(--primary);
--border-color: var(--primary);
--color: var(--primary-inverse);
--box-shadow: var(--button-box-shadow, 0 0 0 rgba(0, 0, 0, 0));
2021-10-24 12:33:20 +07:00
padding: var(--form-element-spacing-vertical)
var(--form-element-spacing-horizontal);
2021-07-02 16:54:41 +07:00
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);
2021-11-08 00:12:34 +07:00
font-weight: var(--font-weight);
font-size: 1rem;
2020-09-29 08:38:35 +07:00
line-height: var(--line-height);
2019-11-27 15:31:49 +07:00
text-align: center;
cursor: pointer;
@if $enable-transitions {
2021-10-24 12:33:20 +07:00
transition: background-color var(--transition),
border-color var(--transition), color var(--transition),
2020-09-29 08:38:35 +07:00
box-shadow var(--transition);
}
2019-11-27 15:31:49 +07:00
2022-02-27 16:12:53 +07:00
&[aria-current],
2019-11-27 15:31:49 +07:00
&:hover,
&:active,
&:focus {
2021-07-02 16:54:41 +07:00
--background-color: var(--primary-hover);
--border-color: var(--primary-hover);
--box-shadow: var(--button-hover-box-shadow, 0 0 0 rgba(0, 0, 0, 0));
2022-01-16 11:49:08 +07:00
--color: var(--primary-inverse);
2019-11-27 15:31:49 +07:00
}
&:focus {
2021-10-24 12:33:20 +07:00
--box-shadow: var(--button-hover-box-shadow, 0 0 0 rgba(0, 0, 0, 0)),
0 0 0 var(--outline-width) var(--primary-focus);
2019-11-27 15:31:49 +07:00
}
}
2021-07-02 16:54:41 +07:00
// .secondary, .contrast & .outline
@if $enable-classes {
// Secondary
button.secondary,
input[type="submit"].secondary,
input[type="button"].secondary,
2021-07-02 16:54:41 +07:00
input[type="reset"],
[role="button"].secondary {
--background-color: var(--secondary);
--border-color: var(--secondary);
--color: var(--secondary-inverse);
cursor: pointer;
2022-02-27 16:12:53 +07:00
&[aria-current],
&:hover,
&:active,
&:focus {
--background-color: var(--secondary-hover);
--border-color: var(--secondary-hover);
2021-07-02 16:54:41 +07:00
--color: var(--secondary-inverse);
}
&:focus {
--box-shadow: var(--button-hover-box-shadow, 0 0 0 rgba(0, 0, 0, 0)),
0 0 0 var(--outline-width) var(--secondary-focus);
}
}
// Contrast
button.contrast,
input[type="submit"].contrast,
input[type="button"].contrast,
input[type="reset"].contrast,
[role="button"].contrast {
--background-color: var(--contrast);
--border-color: var(--contrast);
--color: var(--contrast-inverse);
2022-02-27 16:12:53 +07:00
&[aria-current],
&:hover,
&:active,
&:focus {
--background-color: var(--contrast-hover);
--border-color: var(--contrast-hover);
2021-07-02 16:54:41 +07:00
--color: var(--contrast-inverse);
}
2021-07-02 16:54:41 +07:00
&:focus {
--box-shadow: var(--button-hover-box-shadow, 0 0 0 rgba(0, 0, 0, 0)),
0 0 0 var(--outline-width) var(--contrast-focus);
2021-07-02 16:54:41 +07:00
}
}
2021-07-02 16:54:41 +07:00
// Outline (primary)
button.outline,
input[type="submit"].outline,
input[type="button"].outline,
input[type="reset"].outline,
[role="button"].outline {
--background-color: transparent;
--color: var(--primary);
2022-02-27 16:12:53 +07:00
&[aria-current],
&:hover,
&:active,
&:focus {
2021-07-02 16:54:41 +07:00
--background-color: transparent;
--color: var(--primary-hover);
2021-07-02 16:54:41 +07:00
}
}
2021-07-02 16:54:41 +07:00
// Outline (secondary)
button.outline.secondary,
input[type="submit"].outline.secondary,
input[type="button"].outline.secondary,
input[type="reset"].outline.secondary,
[role="button"].outline.secondary {
--color: var(--secondary);
2022-02-27 16:12:53 +07:00
&[aria-current],
&:hover,
&:active,
&:focus {
--color: var(--secondary-hover);
}
}
2021-07-02 16:54:41 +07:00
// Outline (contrast)
button.outline.contrast,
input[type="submit"].outline.contrast,
input[type="button"].outline.contrast,
input[type="reset"].outline.contrast,
[role="button"].outline.contrast {
--color: var(--contrast);
2022-02-27 16:12:53 +07:00
&[aria-current],
&:hover,
&:active,
&:focus {
--color: var(--contrast-hover);
2021-07-02 16:54:41 +07:00
}
}
}
2021-07-02 16:54:41 +07:00
@else {
// Secondary button without .class
input[type="reset"] {
--background-color: var(--secondary);
--border-color: var(--secondary);
--color: var(--secondary-inverse);
cursor: pointer;
2022-02-27 16:12:53 +07:00
&[aria-current],
&:hover,
&:active,
&:focus {
--background-color: var(--secondary-hover);
--border-color: var(--secondary-hover);
}
2021-07-02 16:54:41 +07:00
&:focus {
--box-shadow: var(--button-hover-box-shadow, 0 0 0 rgba(0, 0, 0, 0)),
0 0 0 var(--outline-width) var(--secondary-focus);
2021-07-02 16:54:41 +07:00
}
}
2019-11-27 15:31:49 +07:00
}
// Button [disabled]
2022-01-16 11:41:50 +07:00
// 1. Links without href are disabled by default
button[disabled],
input[type="submit"][disabled],
input[type="button"][disabled],
input[type="reset"][disabled],
2022-01-16 11:41:50 +07:00
a[role="button"]:not([href]), // 1
[role="button"][disabled] {
opacity: 0.5;
pointer-events: none;
}