Skip to content

Commit cb75223

Browse files
Merge pull request #1163 from nhsuk/static-spacing
Add static spacing override classes
2 parents fcfad93 + 0d08138 commit cb75223

File tree

2 files changed

+66
-15
lines changed

2 files changed

+66
-15
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
## Unreleased
44

5+
:new: **New features**
6+
7+
#### Use new override classes to apply static spacing
8+
9+
You can now use static spacing override classes to apply spacing from [the static spacing scale](https://service-manual.nhs.uk/design-system/styles/spacing#static-spacing) to elements of your design.
10+
11+
The new classes start with: `nhsuk-u-static` followed by either `margin-` or `padding-`, and then a spacing unit number.
12+
13+
To apply spacing in a single direction, include `left-`, `right-`, `top-`, or `bottom-` just before the spacing unit.
14+
15+
For example:
16+
17+
- `nhsuk-u-static-margin-9` will apply a 64px margin to all sides of the element at all screen sizes
18+
- `nhsuk-u-static-padding-right-5` will apply 32px of padding to the right side of the element at all screen sizes
19+
- `nhsuk-u-static-margin-0` will remove all margins at all screen sizes
20+
21+
This was added in [pull request #1163: Add static spacing override classes](https://github.com/nhsuk/nhsuk-frontend/pull/1163).
22+
523
:wastebasket: **Deprecated features**
624

725
#### Add nhsuk namespace to Sass mixins and functions

packages/core/utilities/_spacing.scss

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
// stylelint-disable declaration-no-important
2+
13
@use "../settings" as *;
24
@use "../tools" as *;
5+
@use "sass:map";
36

47
////
58
/// Spacing
@@ -13,34 +16,34 @@
1316

1417
$_spacing-directions: ("top", "right", "bottom", "left") !default;
1518

16-
/// Spacing override classes
19+
/// Generate responsive spacing override classes
1720
///
1821
/// Generate spacing override classes for the given property (e.g. margin)
19-
/// for each point in the spacing scale.
22+
/// for each point in the responsive spacing scale.
2023
///
2124
/// @param {String} $property - Property to add spacing to (e.g. 'margin')
2225
///
23-
/// @example scss
24-
/// .nhsuk-u-margin-0 {
25-
/// margin: 0;
26+
/// @example css
27+
/// .nhsuk-u-margin-4 {
28+
/// margin: 16px !important;
2629
/// }
2730
///
28-
/// .nhsuk-u-margin-top-1 {
29-
/// margin-top: [whatever spacing point 1 is...]
31+
/// @media (min-width: 40.0625em) {
32+
/// .nhsuk-u-margin-4 {
33+
/// margin: 24px !important;
34+
/// }
3035
/// }
3136
///
32-
/// 1. For each point in the spacing scale (defined in settings), create an
33-
/// override that affects all directions...
34-
/// 2. ... and then an override for each individual direction
3537

36-
@mixin _nhsuk-generate-spacing-overrides($property) {
37-
// [1]
38+
@mixin _nhsuk-generate-responsive-spacing-overrides($property) {
39+
// For each point in the spacing scale (defined in settings), create an
40+
// override that affects all directions...
3841
@each $scale-point, $scale-map in $nhsuk-spacing-responsive-scale {
3942
.nhsuk-u-#{$property}-#{$scale-point} {
4043
@include nhsuk-responsive-spacing($scale-point, $property, "all", true);
4144
}
4245

43-
// [2]
46+
// ... and then an override for each individual direction
4447
@each $direction in $_spacing-directions {
4548
.nhsuk-u-#{$property}-#{$direction}-#{$scale-point} {
4649
@include nhsuk-responsive-spacing($scale-point, $property, $direction, true);
@@ -49,7 +52,37 @@ $_spacing-directions: ("top", "right", "bottom", "left") !default;
4952
}
5053
}
5154

55+
/// Generate static spacing override classes
56+
///
57+
/// Generate spacing override classes for the given property (e.g. margin)
58+
/// for each point in the non-responsive spacing scale.
59+
///
60+
/// @param {String} $property - Property to add spacing to (e.g. 'margin')
61+
///
62+
/// @example css
63+
/// .nhsuk-u-static-margin-4 {
64+
/// margin: 24px !important;
65+
/// }
66+
///
67+
68+
@mixin _nhsuk-generate-static-spacing-overrides($property) {
69+
@each $spacing-point in map.keys($nhsuk-spacing-points) {
70+
.nhsuk-u-static-#{$property}-#{$spacing-point} {
71+
#{$property}: nhsuk-spacing($spacing-point) !important;
72+
}
73+
74+
@each $direction in $_spacing-directions {
75+
.nhsuk-u-static-#{$property}-#{$direction}-#{$spacing-point} {
76+
#{$property}-#{$direction}: nhsuk-spacing($spacing-point) !important;
77+
}
78+
}
79+
}
80+
}
81+
5282
@include nhsuk-exports("nhsuk/core/utilities/spacing") {
53-
@include _nhsuk-generate-spacing-overrides("margin");
54-
@include _nhsuk-generate-spacing-overrides("padding");
83+
@include _nhsuk-generate-responsive-spacing-overrides("margin");
84+
@include _nhsuk-generate-responsive-spacing-overrides("padding");
85+
86+
@include _nhsuk-generate-static-spacing-overrides("margin");
87+
@include _nhsuk-generate-static-spacing-overrides("padding");
5588
}

0 commit comments

Comments
 (0)