Mixins
SCSS mixins and utility classes cm-admin provides for layout, typography and truncation. They live in helpers/_mixins.scss and helpers/_typography.scss β import both with:
@import "../helpers/index.scss";
flexβ
Shorthand for flexbox layouts.
@mixin flex($direction: row, $justify: normal, $align: normal, $wrap: nowrap);
.my-container {
@include flex($justify: center, $align: center);
}
.my-column {
@include flex($direction: column, $justify: space-between);
}
fontβ
Apply font size, weight and colour in one call.
@mixin font($size: $t3-text, $color: $primary-text-clr, $weight: normal);
.my-label {
@include font($size: $t4-text, $color: $ink-lighter-clr, $weight: bold);
}
typographyβ
The full typography mixin β size (a unitless number, rendered as px), named weight, colour, line height and family.
@mixin typography(
$size: 14,
$weight: "regular",
$color: $primary-text-clr,
$line-height: 1.5,
$family: $primary-font
);
.field-label {
@include typography(14, "bold", $primary-text-clr);
}
.section-heading {
@include typography(16, "bold");
}
$weight is a key from the $font-weight map: "regular", "medium", "bold" or "bolder".
text-truncateβ
Truncate text with an ellipsis β one line, or a fixed number of lines.
@mixin text-truncate($lines: 1);
.truncate-single {
@include text-truncate(1);
}
.truncate-multi {
@include text-truncate(3);
}
transition-linearβ
Standard all 0.2s linear transition for hover effects.
.my-button {
@include transition-linear;
&:hover {
background: $brand-hover-color;
}
}
white-rgbaβ
White background with adjustable opacity β used for overlay-style panels.
@mixin white-rgba($opacity: 0.3);
shade-colorβ
A Sass function (not a mixin) that darkens a colour by mixing in black β kept for compatibility because Bootstrap 6 removed it.
border-color: shade-color($brand-color, 20%);
Utility classesβ
Generated in helpers/_typography.scss, all !important.
| Group | Classes |
|---|---|
| Font size | .fs-12 β¦ .fs-24 and .f12 β¦ .f24 (12, 14, 16, 18, 20, 24px) |
| Font weight | .fw-regular .fw-medium .fw-bold .fw-bolder, legacy .bold .bolder |
| Line height | .lh-tight (1.2) .lh-normal (1.5) .lh-relaxed (1.75) .lh-loose (2) |
| Text alignment | .text-left .text-center .text-right .text-justify |
| Text transform | .text-uppercase .text-lowercase .text-capitalize .text-none |
| Text decoration | .text-underline .text-overline .text-line-through .text-none |
| Truncation | .text-truncate .text-truncate-2 .text-truncate-3 |
Creating new componentsβ
When adding new components, follow this pattern:
// 1. Import helpers
@import "../helpers/index.scss";
// 2. Scope under .cm-admin
.cm-admin .my-component {
// 3. Extend Bootstrap classes
@extend .d-flex, .align-items-center;
// 4. Use cm-admin variables
background: $grey-lightest-clr;
border-radius: $radius-4;
// 5. Use mixins for common patterns
@include font($size: $t4-text, $color: $primary-text-clr);
padding: 16px;
&:hover {
@include transition-linear;
background: $grey-lighter-clr;
}
}
Example: custom alertβ
@import "../helpers/index";
.cm-admin .alert {
@extend .alert-dismissible, .d-flex, .align-items-center;
}
.flag-alert {
max-width: 752px;
padding: 24px;
background: $red-lightest-clr;
border-radius: $radius-4;
.alert-header {
@include font($size: $t6-text, $color: $red-regular-clr, $weight: bold);
text-transform: uppercase;
}
.alert-body {
margin-top: 16px;
.body-title {
@include font($size: $t4-text, $color: $primary-text-clr, $weight: bold);
}
}
}
Best practicesβ
- Always scope under
.cm-adminβ prevents style leakage into the host app - Use
@extendfor Bootstrap classes β keeps markup clean - Prefer variables over hardcoded values β ensures consistency
- Use mixins for repeated patterns β reduces code duplication