Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

6.0 KB
Raw Blame
// ============================================
// BUTTON COMPONENTS
// ============================================
//
// Single source of truth for buttons. Designed so that:
//   - Height is controlled ONLY by the size class (no padding-y math)
//   - Horizontal padding is consistent regardless of icon presence
//   - Icon + text spacing uses `gap`, not padding tricks
//   - Variants set color/background/border only — never geometry
//
// Class API (kept stable for backwards compatibility):
//   Base:      .btn
//   Variants:  .btn-primary  .btn-secondary  .btn-soft
//              .btn-danger   .btn-ghost      .btn-link
//   Sizes:     (default)     .btn-sm         .btn-lg     .btn-icon
//   Modifiers: .btn-full     .btn-loading    .btn-expand
// ============================================

.btn {
    // Layout
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: $space-2;
    flex-shrink: 0;
    white-space: nowrap;
    text-align: center;
    vertical-align: middle;

    // Geometry: default (md) size
    height: $control-md;
    min-width: 64px;
    padding: 0 $space-3;
    border-radius: $radius-control;
    border: 1px solid transparent;

    // Typography
    font-family: inherit;
    font-size: $text-base; // 14px
    font-weight: $font-weight-medium;
    line-height: 1;

    // Behaviour
    cursor: pointer;
    user-select: none;
    background: none;
    color: inherit;
    @include transition();

    svg {
        width: 16px;
        height: 16px;
        flex-shrink: 0;
    }

    &:disabled,
    &[aria-disabled='true'] {
        opacity: 0.55;
        cursor: not-allowed;
        pointer-events: none;
    }

    &:focus-visible {
        outline: none;
        box-shadow: $focus-ring;
    }
}

// --------------------------------------------
// Variants
// --------------------------------------------

// Flat accent fill. No gradient, glow or inner highlight.
.btn-primary {
    background: var(--accent);
    color: #fff;

    &:hover:not(:disabled) {
        background: color-mix(in srgb, var(--accent) 88%, white);
    }
}

// Outlined neutral button (shadcn "outline")
.btn-secondary {
    background-color: transparent;
    border-color: $border-active;
    color: $text-primary;

    &:hover:not(:disabled) {
        background-color: $bg-hover;
    }
}

// Filled neutral / soft button (shadcn "secondary")
.btn-soft {
    background-color: $bg-secondary;
    color: $text-primary;

    &:hover:not(:disabled) {
        background-color: $bg-hover;
    }
}

.btn-danger {
    background: $danger;
    color: #fff;

    &:hover:not(:disabled) {
        background: $danger-hover;
    }
}

// --------------------------------------------
// Size variants
// --------------------------------------------

.btn-sm {
    height: $control-sm;
    min-width: 0;
    padding: 0 $space-2;
    font-size: $text-sm;
    gap: $space-tight;

    svg {
        width: 14px;
        height: 14px;
    }
}

.btn-lg {
    height: $control-lg;
    min-width: 96px;
    padding: 0 $space-4;
    font-size: $text-base;

    svg {
        width: 18px;
        height: 18px;
    }
}

.btn-link {
height: auto;
    min-width: 0;
    padding: 0;
    background: none;
    border: none;
    color: $accent-primary;
    cursor: pointer;
    font-size: $text-xs;
    text-decoration: none;

    // Named sizes retain their geometry while links keep zero padding.
    &.btn-sm { height: $control-sm; min-width: 0; }
    &.btn-lg { height: $control-lg; min-width: 0; }

    &:hover,
    &:hover:not(:disabled) { text-decoration: underline; }
}

// Icon-only square button — matches default height so it lines up
// next to regular buttons in toolbars.
.btn-icon {
display: flex;
    align-items: center;
    justify-content: center;
    width: $control-md;
    height: $control-md;
    min-width: auto !important;
    padding: 0 !important;
    background: transparent;
    border: none;
    border-radius: $radius-control;
    color: $text-tertiary;
    cursor: pointer;
    transition: all 0.2s;

    svg {
        width: 16px;
        height: 16px;
        margin: 0 !important;
    }

    &.btn-sm {
        width: $control-sm;
        height: $control-sm;

        svg { width: 14px; height: 14px; }
    }

    &.btn-lg {
        width: $control-lg;
        height: $control-lg;

        svg { width: 20px; height: 20px; }
    }

    &:hover {
        color: $text-primary;
        background: $bg-hover;
    }

    &.btn-danger:hover {
        background: fade($danger-raw, 20%);
        color: $danger;
    }

    &.success {
        color: $success;
        &:hover { background: $success-bg; }
    }

    &.danger {
        color: $danger;
        &:hover { background: $danger-bg; }
    }
}

// --------------------------------------------
// Modifiers
// --------------------------------------------

.btn-full {
    width: 100%;
}

.btn-expand {
    background: none;
    border: none;
    color: $text-tertiary;
    cursor: pointer;
    height: auto;
    min-width: 0;
    padding: $space-1 $space-2;
    font-size: $text-xs;
    @include flex-start();
    gap: $space-1;
    @include transition(color);

    &:hover {
        color: $text-primary;
    }
}

// Loading state styling lives in _spinner.scss alongside .spinner overrides.

.btn-xs {
    padding: $space-hair $space-tight;
    font-size: $text-xs;

    svg {
        stroke: currentColor;
        fill: none;
        stroke-width: 2;
    }
}

// Ghost takes precedence when combined with the icon size.
.btn-ghost {
background: transparent;
    border: 1px solid transparent;
    color: $text-secondary;

    &:hover {
        background: $bg-elevated;
        color: $text-primary;
    }

    &:hover:not(:disabled) {
        background-color: $bg-hover;
        color: $text-primary;
    }

    // Destructive row action: quiet like its neighbours, red only on hover.
    // A solid red button in every row shouts the one action nobody wants by
    // accident. A class, not a variant, so an older panel degrades to ghost.
    &.is-danger:hover:not(:disabled) {
        background-color: var(--red-bg);
        color: var(--red);
    }
}