Skip to content

Commit f97f5dc

Browse files
Deprecate govuk-grid-column generating class names
The class names generated by the mixin are not flexible enough, as the width is just appended to the class name. In spiking how we might add an extended grid we found the generated class names a little yoda-ish, for example `govuk-grid-column--at-desktop-one-quarter` (bonus points if you actually read that in Yoda’s voice). Moving the class naming out of the mixin and doing it within the objects layer is also more consistent with the rest of frontend, and means that users who do use the grid mixins directly don’t have to fit with the constraints of our class name structure. See: alphagov/govuk-frontend#1090 Co-authored-by: Oliver Byford <oliver.byford@digital.cabinet-office.gov.uk>
1 parent 97b034b commit f97f5dc

File tree

2 files changed

+52
-26
lines changed

2 files changed

+52
-26
lines changed

packages/core/objects/_grid.scss

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use "sass:map";
2+
13
////
24
/// Grid
35
///
@@ -11,10 +13,9 @@
1113
margin-left: -($nhsuk-gutter-half);
1214
}
1315

14-
@include govuk-grid-column(one-quarter);
15-
@include govuk-grid-column(one-third);
16-
@include govuk-grid-column(one-half);
17-
@include govuk-grid-column(two-thirds);
18-
@include govuk-grid-column(three-quarters);
19-
@include govuk-grid-column(full);
16+
@each $width in map.keys($nhsuk-grid-widths) {
17+
.nhsuk-grid-column-#{$width} {
18+
@include nhsuk-grid-column($width, $class: false);
19+
}
20+
}
2021
}

packages/core/tools/_grid.scss

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
///
3535
/// Creates a grid row class with a standardised margin.
3636
///
37-
/// @param {String} $class [govuk-grid-row] CSS class name
37+
/// @param {String} $class [nhsuk-grid-row] CSS class name
3838
///
3939
/// @example scss - Default
4040
/// @include govuk-grid-row;
@@ -47,8 +47,8 @@
4747
@mixin nhsuk-grid-row($class: "nhsuk-grid-row") {
4848
.#{$class} {
4949
@include clearfix;
50-
margin-left: -($nhsuk-gutter-half);
5150
margin-right: -($nhsuk-gutter-half);
51+
margin-left: -($nhsuk-gutter-half);
5252
}
5353
}
5454

@@ -63,42 +63,67 @@
6363

6464
/// Generate grid column styles
6565
///
66-
/// Creates a cross browser grid column with a class of '.govuk-grid-column' by
67-
/// default, and a standardised gutter between the columns.
66+
/// Creates a grid column with standard gutter between the columns.
6867
///
69-
/// Common widths are predefined above as keywords in the `$grid-widths` map.
68+
/// If a `$class` is provided (which is the default, but deprecated behaviour),
69+
/// the generated rules will be wrapped in a predefined selector in the format
70+
/// `$class-$width` (e.g. `nhsuk-grid-column-full`). This behaviour is
71+
/// deprecated and will be removed in v10.0
7072
///
71-
/// By default their width changes from 100% to specified width at the 'tablet'
72-
/// breakpoint, but that can be configured to be any other breakpoint by using
73-
/// the `$at` parameter.
73+
/// Grid widths are defined in the `$nhsuk-grid-widths` map.
7474
///
75-
/// @param {String} $class [govuk-grid-column] CSS class name
76-
/// @param {String} $width [full] one-quarter | one-third | one-half | two-third | three-quarters | full
75+
/// By default the column width changes from 100% to specified width at the
76+
/// 'tablet' breakpoint, but other breakpoints can be specified using the `$at`
77+
/// parameter.
78+
///
79+
/// @param {String} $width [full] name of a grid width from $nhsuk-grid-widths
7780
/// @param {String} $float [left] left | right
78-
/// @param {String} $at [tablet] - mobile | tablet | desktop | any custom breakpoint in px or em
81+
/// @param {String} $at [tablet] - mobile | tablet | desktop | any custom breakpoint
82+
/// @param {String} $class [nhsuk-grid-column] CSS class name (deprecated)
7983
///
8084
/// @example scss - Default
81-
/// @include govuk-grid-column(two-thirds)
82-
///
83-
/// @example scss - Customising the class name
84-
/// @include govuk-grid-column(one-half, $class: "test-column");
85+
/// .nhsuk-grid-column-two-thirds {
86+
/// @include nhsuk-grid-column(two-thirds, $class: false)
87+
/// }
8588
///
8689
/// @example scss - Customising the breakpoint where width percentage is applied
87-
/// @include govuk-grid-column(one-half, $at: desktop);
90+
/// .nhsuk-grid-column-one-half-at-desktop {
91+
/// @include nhsuk-grid-column(one-half, $at: desktop);
92+
/// }
8893
///
8994
/// @example scss - Customising the float direction
90-
/// @include govuk-grid-column(one-half, $float: right);
95+
/// .nhsuk-grid-column-one-half-right {
96+
/// @include nhsuk-grid-column(two-thirds, $float: right, $class: false);
97+
/// }
98+
///
99+
/// @example scss - Customising the class name (deprecated)
100+
/// @include nhsuk-grid-column(one-half, $class: "test-column");
101+
///
102+
/// @link https://github.com/alphagov/govuk-frontend Original code taken from GDS (Government Digital Service)
91103

92-
@mixin govuk-grid-column($width: full, $float: left, $at: desktop, $class: "nhsuk-grid-column") {
93-
.#{$class}-#{$width} {
104+
@mixin nhsuk-grid-column($width: full, $float: left, $at: tablet, $class: "nhsuk-grid-column") {
105+
@if $class {
106+
.#{$class}-#{$width} {
107+
@include nhsuk-grid-column($width, $float, $at, $class: false);
108+
}
109+
} @else {
94110
box-sizing: border-box;
95-
padding: 0 $nhsuk-gutter-half;
96111
@if $at != desktop {
97112
width: 100%;
98113
}
114+
padding: 0 $nhsuk-gutter-half;
99115
@include nhsuk-media-query($from: $at) {
100116
width: nhsuk-grid-width($width);
101117
float: $float;
102118
}
103119
}
104120
}
121+
122+
/// Generate grid column styles (deprecated)
123+
///
124+
/// @alias nhsuk-grid-column
125+
/// @deprecated To be removed in v10.0
126+
127+
@mixin govuk-grid-column($args...) {
128+
@include nhsuk-grid-column($args...);
129+
}

0 commit comments

Comments
 (0)