Spaces:
Sleeping

script / static /styles /_mixins.scss
Lara Monteagudo Tubau
Build CSS for Hugging Face deploy
ba2c0b3
Raw History Blame Contribute Delete
9.82 kB
// =============================================================================
// _mixins.scss β€” CollabCode Design System
// Reusable Sass mixins and utility functions
// =============================================================================
@import 'tokens';
// ─── RESPONSIVE BREAKPOINTS ──────────────────────────────────────────────────
@mixin respond-to($bp) {
@if $bp == 'sm' { @media (min-width: $breakpoint-sm) { @content; } }
@else if $bp == 'md' { @media (min-width: $breakpoint-md) { @content; } }
@else if $bp == 'lg' { @media (min-width: $breakpoint-lg) { @content; } }
@else if $bp == 'xl' { @media (min-width: $breakpoint-xl) { @content; } }
@else if $bp == '2xl' { @media (min-width: $breakpoint-2xl) { @content; } }
}
@mixin max-width($bp) {
@if $bp == 'sm' { @media (max-width: #{ $breakpoint-sm - 1 }) { @content; } }
@else if $bp == 'md' { @media (max-width: #{ $breakpoint-md - 1 }) { @content; } }
@else if $bp == 'lg' { @media (max-width: #{ $breakpoint-lg - 1 }) { @content; } }
}
// ─── REDUCED MOTION ──────────────────────────────────────────────────────────
// Always wrap animations in this mixin.
// "Vestibular disorders and photosensitive epilepsy affect β‰ˆ35% of people
// with disabilities." β€” WCAG 2.3 Understanding Document
@mixin motion-safe {
@media (prefers-reduced-motion: no-preference) { @content; }
}
@mixin motion-reduce {
@media (prefers-reduced-motion: reduce) { @content; }
}
// ─── ACCESSIBILITY ───────────────────────────────────────────────────────────
/// Visually hidden but readable by screen readers.
/// Use for icon-only buttons, skip links, etc.
@mixin visually-hidden {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
/// Revert visually-hidden when focused (skip-link pattern).
@mixin visually-hidden-focusable {
@include visually-hidden;
&:focus, &:focus-within {
position: static;
width: auto;
height: auto;
padding: inherit;
margin: inherit;
overflow: visible;
clip: auto;
white-space: normal;
}
}
/// WCAG 2.4.7 β€” visible focus indicator.
/// Uses :focus-visible so mouse clicks don't trigger the ring.
@mixin focus-ring($color: $color-border-focus, $offset: 2px) {
outline: 2px solid transparent; // always reserve space
&:focus-visible {
outline: 2px solid $color;
outline-offset: $offset;
box-shadow: $shadow-focus;
}
}
/// High-contrast mode support.
@mixin high-contrast {
@media (forced-colors: active) { @content; }
}
// ─── ELEVATION ───────────────────────────────────────────────────────────────
@mixin elevation($level: 'sm') {
@if $level == 'none' { box-shadow: $shadow-none; }
@else if $level == 'xs' { box-shadow: $shadow-xs; }
@else if $level == 'sm' { box-shadow: $shadow-sm; }
@else if $level == 'md' { box-shadow: $shadow-md; }
@else if $level == 'lg' { box-shadow: $shadow-lg; }
@else if $level == 'xl' { box-shadow: $shadow-xl; }
}
// ─── CARD ────────────────────────────────────────────────────────────────────
@mixin card($padding: $card-padding, $shadow: $card-shadow) {
background: $card-bg;
border: 1px solid $card-border;
border-radius: $card-radius;
padding: $padding;
box-shadow: $shadow;
}
@mixin card-interactive {
@include card;
cursor: pointer;
@include motion-safe {
transition: box-shadow $duration-fast $ease-out,
border-color $duration-fast $ease-out;
}
&:hover {
border-color: $color-border-strong;
box-shadow: $shadow-sm;
}
@include focus-ring;
}
// ─── BUTTON ──────────────────────────────────────────────────────────────────
@mixin button-base {
display: inline-flex;
align-items: center;
justify-content: center;
gap: $space-2;
padding: $btn-padding-y $btn-padding-x;
min-height: $btn-min-height;
border: 1px solid transparent;
border-radius: $btn-radius;
font-family: $font-family-sans;
font-size: $btn-font-size;
font-weight: $btn-font-weight;
line-height: $line-height-tight;
text-decoration: none;
cursor: pointer;
user-select: none;
white-space: nowrap;
@include focus-ring;
@include motion-safe {
transition: background-color $duration-fast $ease-in-out,
border-color $duration-fast $ease-in-out,
color $duration-fast $ease-in-out,
box-shadow $duration-fast $ease-in-out,
opacity $duration-fast $ease-in-out;
}
&:disabled,
&[aria-disabled='true'] {
opacity: 0.45;
cursor: not-allowed;
pointer-events: none;
}
}
@mixin button-primary {
@include button-base;
background: $color-interactive;
border-color: $color-interactive;
color: $color-text-on-emphasis;
&:hover:not(:disabled) {
background: $color-interactive-hover;
border-color: $color-interactive-hover;
}
&:active:not(:disabled) {
background: $color-interactive-active;
}
}
@mixin button-secondary {
@include button-base;
background: $color-bg-surface;
border-color: $color-border-strong;
color: $color-text-primary;
&:hover:not(:disabled) {
background: $color-bg-subtle;
border-color: $color-border-strong;
}
}
@mixin button-ghost {
@include button-base;
background: transparent;
border-color: transparent;
color: $color-interactive;
&:hover:not(:disabled) {
background: $color-interactive-muted;
}
}
@mixin button-danger {
@include button-base;
background: $color-error-bg;
border-color: $color-error-border;
color: $color-error-text;
&:hover:not(:disabled) {
background: $color-error-border;
color: $color-error-text;
}
}
// ─── STATUS BANNER ───────────────────────────────────────────────────────────
@mixin banner($bg, $border-color, $text-color) {
background: $bg;
border: 1px solid $border-color;
border-radius: $radius-md;
color: $text-color;
padding: $space-3 $space-4;
margin: $space-2 0;
font-size: $font-size-sm;
line-height: $line-height-relaxed;
}
@mixin banner-success { @include banner($color-success-bg, $color-success-border, $color-success-text); }
@mixin banner-warning { @include banner($color-warning-bg, $color-warning-border, $color-warning-text); }
@mixin banner-error { @include banner($color-error-bg, $color-error-border, $color-error-text); }
@mixin banner-info { @include banner($color-info-bg, $color-info-border, $color-info-text); }
// ─── PROGRESS BAR ────────────────────────────────────────────────────────────
@mixin progress-track($height: 8px) {
height: #{$height};
background: $color-bg-subtle;
border-radius: $radius-full;
overflow: hidden;
position: relative;
}
@mixin progress-fill($color: $color-interactive) {
position: absolute;
inset: 0 auto 0 0;
background: $color;
border-radius: inherit;
@include motion-safe {
transition: width $duration-slow $ease-out;
}
}
// ─── BADGE ───────────────────────────────────────────────────────────────────
@mixin badge($bg, $text-color) {
display: inline-block;
background: $bg;
color: $text-color;
border-radius: $badge-radius;
font-size: $badge-font-size;
font-weight: $badge-font-weight;
letter-spacing: 0.05em;
text-transform: uppercase;
padding: $badge-padding;
line-height: $line-height-tight;
white-space: nowrap;
}
// ─── TYPOGRAPHY HELPERS ───────────────────────────────────────────────────────
@mixin label-overline {
font-size: $font-size-2xs;
font-weight: $font-weight-bold;
letter-spacing: 0.1em;
text-transform: uppercase;
color: $color-text-tertiary;
}
@mixin body-sm {
font-size: $font-size-sm;
line-height: $line-height-normal;
color: $color-text-secondary;
}
@mixin mono-sm {
font-family: $font-family-mono;
font-size: $font-size-xs;
line-height: $line-height-normal;
}
// ─── LAYOUT ──────────────────────────────────────────────────────────────────
@mixin flex-row($gap: $space-3, $align: center) {
display: flex;
flex-direction: row;
align-items: $align;
gap: $gap;
}
@mixin flex-col($gap: $space-3) {
display: flex;
flex-direction: column;
gap: $gap;
}
@mixin truncate {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
@mixin divider($color: $color-border-default) {
border: none;
border-top: 1px solid $color;
margin: $space-5 0;
}