Skip to content

Commit

Permalink
Add static spacing override classes to overrides
Browse files Browse the repository at this point in the history
New spacing override classes which use the static spacing at all
viewports. The existing spacing override classes use the
responsive spacing helper, and so have different spacing at
different viewports. These helper classes are used in components in
govuk_publishing_components and the option to use static spacing
would be useful in specific areas of GOV.UK and as an option for
components.
  • Loading branch information
patrickpatrickpatrick committed Jul 25, 2022
1 parent 80b9974 commit cf42944
Showing 1 changed file with 47 additions and 12 deletions.
59 changes: 47 additions & 12 deletions src/govuk/overrides/_spacing.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/// @group overrides
////

// stylelint-disable declaration-no-important

/// Directions for spacing
///
/// @type Map
Expand All @@ -14,25 +16,27 @@ $_spacing-directions: (
"left"
) !default;

/// Spacing override classes
/// Generate responsive spacing override classes
///
/// Generate spacing override classes for the given property (e.g. margin)
/// for each point in the spacing scale.
/// for each point in the responsive spacing scale.
///
/// @param {String} $property - Property to add spacing to (e.g. 'margin')
///
/// @example scss
/// .govuk-\!-margin-0 {
/// margin: 0;
/// }
/// @example css
/// .govuk-\!-margin-4 {
/// margin: 15px !important;
/// }
///
/// .govuk-\!-margin-top-1 {
/// margin-top: [whatever spacing point 1 is...]
/// }
/// @media (min-width: 40.0625em) {
/// .govuk-\!-margin-4 {
/// margin: 20px !important;
/// }
/// }
///
/// @access private

@mixin _govuk-generate-spacing-overrides($property) {
@mixin _govuk-generate-responsive-spacing-overrides($property) {
// For each point in the spacing scale (defined in settings), create an
// override that affects all directions...
@each $scale-point, $scale-map in $govuk-spacing-responsive-scale {
Expand All @@ -52,7 +56,38 @@ $_spacing-directions: (
}
}

/// Generate static spacing override classes
///
/// Generate spacing override classes for the given property (e.g. margin)
/// for each point in the non-responsive spacing scale.
///
/// @param {String} $property - Property to add spacing to (e.g. 'margin')
///
/// @example css
/// .govuk-\!-margin-static-4 {
/// margin: 20px !important;
/// }
///
/// @access private
@mixin _govuk-generate-static-spacing-overrides($property) {
@each $spacing-point in map-keys($govuk-spacing-points) {
.govuk-\!-static-#{$property}-#{$spacing-point} {
#{$property}: govuk-spacing($spacing-point) !important;
}

@each $direction in $_spacing-directions {

.govuk-\!-static-#{$property}-#{$direction}-#{$spacing-point} {
#{$property}-#{$direction}: govuk-spacing($spacing-point) !important;
}
}
}
}

@include govuk-exports("govuk/overrides/spacing") {
@include _govuk-generate-spacing-overrides("margin");
@include _govuk-generate-spacing-overrides("padding");
@include _govuk-generate-responsive-spacing-overrides("margin");
@include _govuk-generate-responsive-spacing-overrides("padding");

@include _govuk-generate-static-spacing-overrides("margin");
@include _govuk-generate-static-spacing-overrides("padding");
}

0 comments on commit cf42944

Please sign in to comment.