Files
metabuilder/scss/components/buttons.scss
2026-03-09 22:30:41 +00:00

515 lines
12 KiB
SCSS

// Button Components - MD3 BEM SCSS
// =========================================================
// Semantic BEM classes for all button variants.
// Uses MD3 CSS custom properties (var(--mat-sys-*)).
// No Tailwind. No inline styles.
// ─── Base button ────────────────────────────────────────────────────────────
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 0 16px;
height: 40px;
min-width: 64px;
border: none;
border-radius: 20px;
font-size: 14px;
font-weight: 500;
letter-spacing: 0.01em;
cursor: pointer;
user-select: none;
text-decoration: none;
transition: background 0.2s ease, box-shadow 0.2s ease, opacity 0.15s ease;
position: relative;
overflow: hidden;
white-space: nowrap;
background: var(--mat-sys-primary);
color: var(--mat-sys-on-primary);
&:hover {
opacity: 0.92;
}
&:focus-visible {
outline: 2px solid var(--mat-sys-primary);
outline-offset: 2px;
}
&:disabled,
&--disabled {
opacity: 0.38;
cursor: not-allowed;
pointer-events: none;
}
// ─── Width modifiers ──────────────────────────────────────────────────────
&--full-width {
width: 100%;
}
// ─── Size modifiers ───────────────────────────────────────────────────────
&--sm {
height: 32px;
padding: 0 12px;
font-size: 12px;
border-radius: 16px;
gap: 6px;
}
&--lg {
height: 48px;
padding: 0 24px;
font-size: 15px;
border-radius: 24px;
gap: 10px;
}
&--icon-only {
width: 40px;
min-width: 40px;
height: 40px;
padding: 0;
border-radius: 50%;
gap: 0;
}
&--icon-only#{&}--sm {
width: 32px;
min-width: 32px;
height: 32px;
border-radius: 50%;
}
&--icon-only#{&}--lg {
width: 48px;
min-width: 48px;
height: 48px;
border-radius: 50%;
}
// ─── Variant: filled (default) ────────────────────────────────────────────
&--filled {
background: var(--mat-sys-primary);
color: var(--mat-sys-on-primary);
&:hover {
background: color-mix(in srgb, var(--mat-sys-primary) 92%, black);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
}
// ─── Variant: outlined ────────────────────────────────────────────────────
&--outlined {
background: transparent;
color: var(--mat-sys-primary);
border: 1px solid var(--mat-sys-outline);
&:hover {
background: color-mix(in srgb, var(--mat-sys-primary) 8%, transparent);
}
&:focus-visible {
border-color: var(--mat-sys-primary);
}
}
// ─── Variant: ghost / text ────────────────────────────────────────────────
&--ghost {
background: transparent;
color: var(--mat-sys-primary);
&:hover {
background: color-mix(in srgb, var(--mat-sys-primary) 8%, transparent);
}
}
// ─── Variant: surface / tonal ─────────────────────────────────────────────
&--tonal {
background: var(--mat-sys-surface-container);
color: var(--mat-sys-on-surface);
&:hover {
background: color-mix(in srgb, var(--mat-sys-surface-container) 85%, var(--mat-sys-on-surface));
}
}
// ─── Variant: error / destructive ─────────────────────────────────────────
&--error {
background: var(--mat-sys-error);
color: var(--mat-sys-on-error, #fff);
&:hover {
opacity: 0.9;
}
}
&--error-outlined {
background: transparent;
color: var(--mat-sys-error);
border: 1px solid var(--mat-sys-error);
&:hover {
background: color-mix(in srgb, var(--mat-sys-error) 8%, transparent);
}
}
// ─── Variant: secondary ───────────────────────────────────────────────────
&--secondary {
background: var(--mat-sys-secondary);
color: var(--mat-sys-on-secondary, #fff);
&:hover {
opacity: 0.9;
}
}
// ─── Content layout: icon + text ─────────────────────────────────────────
&__content {
display: inline-flex;
align-items: center;
gap: 8px;
}
&__icon {
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
&__icon--leading {
margin-left: -4px;
}
&__icon--trailing {
margin-right: -4px;
}
&__spinner {
display: inline-block;
width: 16px;
height: 16px;
border: 2px solid currentColor;
border-top-color: transparent;
border-radius: 50%;
animation: btn-spin 0.8s linear infinite;
flex-shrink: 0;
}
&__text {
// text node wrapper — no styles needed by default
}
// ─── Loading state ────────────────────────────────────────────────────────
&--loading {
cursor: wait;
pointer-events: none;
.btn__spinner {
display: inline-block;
}
}
}
// ─── Floating Action Button (FAB) ────────────────────────────────────────────
.fab {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
height: 56px;
min-width: 56px;
padding: 0 16px;
border: none;
border-radius: 16px;
background: var(--mat-sys-primary);
color: var(--mat-sys-on-primary);
font-size: 14px;
font-weight: 500;
cursor: pointer;
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.24);
transition: box-shadow 0.2s ease, opacity 0.15s ease;
&:hover {
box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28);
opacity: 0.92;
}
&:focus-visible {
outline: 2px solid var(--mat-sys-primary);
outline-offset: 2px;
}
&:disabled {
opacity: 0.38;
cursor: not-allowed;
box-shadow: none;
}
// ─── FAB sizes ────────────────────────────────────────────────────────────
&--small {
height: 40px;
min-width: 40px;
border-radius: 12px;
padding: 0 12px;
}
&--large {
height: 96px;
min-width: 96px;
border-radius: 28px;
font-size: 16px;
}
// FAB icon-only (no label)
&--icon-only {
padding: 0;
width: 56px;
}
&--icon-only#{&}--small {
width: 40px;
}
&--icon-only#{&}--large {
width: 96px;
}
&__icon {
display: inline-flex;
align-items: center;
justify-content: center;
}
&__label {
// text label inside extended FAB
}
}
// ─── Icon Button ──────────────────────────────────────────────────────────────
.icon-btn {
display: inline-flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
padding: 0;
border: none;
border-radius: 50%;
background: transparent;
color: var(--mat-sys-on-surface);
cursor: pointer;
transition: background 0.15s ease, opacity 0.15s ease;
&:hover {
background: color-mix(in srgb, var(--mat-sys-on-surface) 8%, transparent);
}
&:focus-visible {
outline: 2px solid var(--mat-sys-primary);
outline-offset: 2px;
}
&:disabled {
opacity: 0.38;
cursor: not-allowed;
pointer-events: none;
}
&--filled {
background: var(--mat-sys-primary);
color: var(--mat-sys-on-primary);
&:hover {
opacity: 0.92;
}
}
&--outlined {
border: 1px solid var(--mat-sys-outline);
&:hover {
background: color-mix(in srgb, var(--mat-sys-primary) 8%, transparent);
}
}
&--sm {
width: 32px;
height: 32px;
}
&--lg {
width: 48px;
height: 48px;
}
}
// ─── Toggle (checkbox-label pattern) ─────────────────────────────────────────
.toggle {
display: inline-flex;
align-items: center;
gap: 8px;
cursor: pointer;
&__input {
// visually hidden native checkbox
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
&__track {
display: inline-flex;
align-items: center;
width: 36px;
height: 20px;
border-radius: 10px;
background: var(--mat-sys-outline);
transition: background 0.2s ease;
position: relative;
}
&__thumb {
width: 16px;
height: 16px;
border-radius: 50%;
background: var(--mat-sys-surface);
position: absolute;
left: 2px;
transition: transform 0.2s ease;
}
&__input:checked ~ &__track {
background: var(--mat-sys-primary);
}
&__input:checked ~ &__track &__thumb {
transform: translateX(16px);
}
&__label {
font-size: 14px;
color: var(--mat-sys-on-surface);
user-select: none;
}
&--disabled {
opacity: 0.38;
cursor: not-allowed;
}
}
// ─── Action Button wrapper ────────────────────────────────────────────────────
.action-btn {
display: inline-flex;
&__icon {
display: inline-flex;
align-items: center;
margin-right: 8px;
flex-shrink: 0;
}
&__label {
// label text - no extra styles
}
}
// ─── Toolbar button ───────────────────────────────────────────────────────────
.toolbar-btn {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 0 12px;
height: 36px;
border: none;
border-radius: 18px;
background: transparent;
color: var(--mat-sys-on-surface);
font-size: 13px;
font-weight: 500;
cursor: pointer;
white-space: nowrap;
transition: background 0.15s ease;
&:hover {
background: color-mix(in srgb, var(--mat-sys-on-surface) 8%, transparent);
}
&:focus-visible {
outline: 2px solid var(--mat-sys-primary);
outline-offset: 2px;
}
&--outline {
border: 1px solid var(--mat-sys-outline);
&:hover {
background: color-mix(in srgb, var(--mat-sys-primary) 8%, transparent);
}
}
&--outline-error {
border: 1px solid var(--mat-sys-error);
color: var(--mat-sys-error);
&:hover {
background: color-mix(in srgb, var(--mat-sys-error) 8%, transparent);
color: var(--mat-sys-on-error, #fff);
}
}
&--default {
background: var(--mat-sys-primary);
color: var(--mat-sys-on-primary);
&:hover {
opacity: 0.92;
}
}
&--hidden-sm {
@media (max-width: 640px) {
display: none;
}
}
&--visible-sm {
@media (min-width: 641px) {
display: inline-flex;
}
}
}
// ─── Spinner keyframes ────────────────────────────────────────────────────────
@keyframes btn-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}