|
81 | 81 | @return $line-height;
|
82 | 82 | }
|
83 | 83 |
|
84 |
| -/// Responsive typography |
| 84 | +/// Font size and line height helper |
85 | 85 | ///
|
86 |
| -/// Takes a 'font map' as an argument and uses it to create font-size and |
87 |
| -/// line-height declarations for different breakpoints, and for print. |
| 86 | +/// Takes a point from the responsive 'font map' as an argument (the size as it |
| 87 | +/// would appear on tablet and above), and uses it to create font-size and |
| 88 | +/// line-height declarations for different breakpoints, and print. |
88 | 89 | ///
|
89 | 90 | /// Example font map:
|
90 | 91 | ///
|
91 |
| -/// $my-font-map: ( |
| 92 | +/// 19: ( |
92 | 93 | /// null: (
|
93 | 94 | /// font-size: 16px,
|
94 | 95 | /// line-height: 20px
|
|
101 | 102 | /// font-size: 14pt,
|
102 | 103 | /// line-height: 1.15
|
103 | 104 | /// )
|
104 |
| -/// );\ |
| 105 | +/// ); |
105 | 106 | ///
|
106 | 107 | /// @example scss
|
107 | 108 | /// .foo {
|
108 |
| -/// @include nhsuk-typography-responsive(19); |
| 109 | +/// @include nhsuk-font-size(19); |
109 | 110 | /// }
|
110 | 111 | ///
|
111 | 112 | /// .foo {
|
112 |
| -/// @include nhsuk-typography-responsive(36, $important: true); |
| 113 | +/// @include nhsuk-font-size(36, $important: true); |
113 | 114 | /// }
|
114 | 115 | ///
|
115 |
| -/// @param {Map} $font-map - Font map |
| 116 | +/// @param {Number} $size - Point from the spacing scale (the size as it would |
| 117 | +/// appear on tablet and above) |
116 | 118 | /// @param {Number} $override-line-height [false] - Non responsive custom line
|
117 | 119 | /// height. Omit to use the line height from the font map.
|
118 | 120 | /// @param {Boolean} $important [false] - Whether to mark declarations as
|
119 | 121 | /// `!important`.
|
120 | 122 | ///
|
121 |
| -/// 1. Mark rules as !important if $important is true - this will result in |
122 |
| -/// these variables becoming strings, so this needs to happen *after* they |
123 |
| -/// are used in calculations |
| 123 | +/// @throw if `$size` is not a valid point from the spacing scale |
124 | 124 | ///
|
| 125 | +/// @link https://github.com/alphagov/govuk-frontend Original code taken from GDS (Government Digital Service) |
125 | 126 |
|
126 |
| -@mixin nhsuk-typography-responsive($size, $override-line-height: false, $important: false) { |
| 127 | +@mixin nhsuk-font-size($size, $override-line-height: false, $important: false) { |
127 | 128 | @if not map.has-key($nhsuk-typography-scale, $size) {
|
128 | 129 | @error "Unknown font size `#{$size}` - expected a point from the typography scale.";
|
129 | 130 | }
|
|
139 | 140 | $font-size: $font-size
|
140 | 141 | );
|
141 | 142 |
|
142 |
| - // [1] |
| 143 | + // Mark rules as !important if $important is true - this will result in |
| 144 | + // these variables becoming strings, so this needs to happen *after* they |
| 145 | + // are used in calculations |
143 | 146 | $font-size: $font-size if($important, !important, null);
|
144 | 147 | $font-size-rem: $font-size-rem if($important, !important, null);
|
145 | 148 | $line-height: $line-height if($important, !important, null);
|
|
165 | 168 | }
|
166 | 169 | }
|
167 | 170 |
|
| 171 | +/// Font size and line height helper (deprecated) |
| 172 | +/// |
| 173 | +/// @param {Number} $size - Point from the spacing scale (the size as it would |
| 174 | +/// appear on tablet and above) |
| 175 | +/// @param {Number} $override-line-height [false] - Non responsive custom line |
| 176 | +/// height. Omit to use the line height from the font map. |
| 177 | +/// @param {Boolean} $important [false] - Whether to mark declarations as |
| 178 | +/// `!important`. |
| 179 | +/// |
| 180 | +/// @throw if `$size` is not a valid point from the spacing scale |
| 181 | +/// |
| 182 | +/// @alias nhsuk-font-size |
| 183 | +/// @deprecated Use `nhsuk-font-size` instead |
| 184 | + |
| 185 | +@mixin nhsuk-typography-responsive($size, $override-line-height: false, $important: false) { |
| 186 | + @include nhsuk-font-size($size, $override-line-height, $important); |
| 187 | +} |
| 188 | + |
168 | 189 | /// Font
|
169 | 190 | ///
|
170 | 191 | /// @example scss
|
|
191 | 212 | }
|
192 | 213 |
|
193 | 214 | @if $size {
|
194 |
| - @include nhsuk-typography-responsive($size, $override-line-height: $line-height); |
| 215 | + @include nhsuk-font-size($size, $override-line-height: $line-height); |
195 | 216 | }
|
196 | 217 | }
|
0 commit comments