pico/scss/content/_button.scss

208 lines
4.8 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
&:hover,
&:active,
&:focus {
2022-01-16 11:41:50 +07:00
--color: var(--primary-inverse);
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));
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 button without .class
2019-11-27 15:31:49 +07:00
input[type="reset"] {
2021-07-02 16:54:41 +07:00
--background-color: var(--secondary);
--border-color: var(--secondary);
--color: var(--secondary-inverse);
2019-11-27 15:31:49 +07:00
cursor: pointer;
2021-07-02 16:54:41 +07:00
&:hover,
&:active,
&:focus {
--background-color: var(--secondary-hover);
--border-color: var(--secondary-hover);
}
&: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(--secondary-focus);
2021-07-02 16:54:41 +07:00
}
}
// .secondary, .contrast & .outline
@if $enable-classes {
button,
input[type="submit"],
input[type="button"],
input[type="reset"],
2022-01-16 11:41:50 +07:00
[role="button"] {
2021-07-02 16:54:41 +07:00
// Secondary
&.secondary {
--background-color: var(--secondary);
--border-color: var(--secondary);
--color: var(--secondary-inverse);
cursor: pointer;
&:hover,
&:active,
&:focus {
--background-color: var(--secondary-hover);
--border-color: var(--secondary-hover);
}
&: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(--secondary-focus);
2021-07-02 16:54:41 +07:00
}
}
// Contrast
&.contrast {
--background-color: var(--contrast);
--border-color: var(--contrast);
--color: var(--contrast-inverse);
&:hover,
&:active,
&:focus {
--background-color: var(--contrast-hover);
--border-color: var(--contrast-hover);
}
&: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(--contrast-focus);
2021-07-02 16:54:41 +07:00
}
}
// Outline (primary)
&.outline {
--background-color: transparent;
--color: var(--primary);
&:hover,
&:active,
&:focus {
--background-color: transparent;
--color: var(--primary-hover);
}
}
// Outline (secondary)
&.outline.secondary {
--color: var(--secondary);
&:hover,
&:active,
&:focus {
--color: var(--secondary-hover);
}
}
// Outline (contrast)
&.outline.contrast {
--color: var(--contrast);
&:hover,
&:active,
&:focus {
--color: var(--contrast-hover);
}
}
}
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;
}