[v10] Add code and monospace font utilities#1962
Conversation
colinrotherham
left a comment
There was a problem hiding this comment.
Looks great, thanks Ed
I'd forgotten GOV use govuk-!-font-tabular-numbers
i.e. There's no -family- in there
Wondering whether "monospace" fits better in terms of fonts?
- .nhsuk-u-font-family-code {
+ .nhsuk-u-font-monospace {|
Amusingly I'm the one who first added tabular numbers on GOV.UK. Happy to try a different name and would prefer something shorter anyway. I guess for us to decide whether to frame it about monospace fonts, or to frame it about the end usage - for codes. |
|
Thanks for opening this @edwardhorsford I did the input-code spacing and I think I went with the increased spacing as a balance – on different devices the monospace font renders with different fonts. But I need to check this. Agree on my Mac that it looks OK with less spacing. In terms of a modifier and/or input-code styling: I think it'd be useful to have both. The input-code having extra letter spacing and the general-purpose monospace having default spacing. |
|
@anandamaryon1 we don't have to reduce the letter-spacing like I've done - or indeed could pick a number half way between. But I'd be very keen on reducing the word-spacing so that spaces are not so large / the groups of digits aren't so separated. |
|
@edwardhorsford I've pushed an update to meet in the middle with the For example (letter-spacing: 0.075em; word-spacing: -0.5ch;): |
|
I'm going to rebase this against |
|
@anandamaryon1 I'll make one tiny tweak though Let's keep the font mixin API the same and only support i.e. We can set the custom spacing like GOV.UK Frontend, only where necessary .nhsuk-input--code {
- @include nhsuk-font-monospace($letter-spacing: 0.075em, $word-spacing: -0.5ch);
+ @include nhsuk-font-monospace;
+ letter-spacing: 0.075em;
+ word-spacing: -0.5ch;
} |
|
@anandamaryon1 Sounds good, happy with this compromise. |
ea8aa43 to
fddcceb
Compare
fddcceb to
0677e07
Compare
|
@anandamaryon1 @edwardhorsford Can you check the new changelog edit please? Noting that "monospace" text should have spaces and characters at the same width I've split out:
Aligning "code" with
|
Ah, I was expecting the |
…pacing parameters and remove it's default spacing
0677e07 to
80e8498
Compare
7496f17 to
2d510be
Compare
|
Updated the PR (see description) to include some Sass deprecations We'll get this released in v10.5.2 |
2d510be to
2dd57bb
Compare




Description
My service displays NHS number and something called an accession number, and I wanted to display these in a fixed width font. We tried using
.nhsuk-input--codebut this is meant for text inputs and excessively spaces letters, especially spaces.Chatting with @colinrotherham it felt like it could be helpful to have a general purpose modifier for this.
I've set it to to:
.nhsuk-input--code)Screenshot:

I also took the opportunity to update the example NHS numbers in the frontend app to the same example from the design system, and one explicitly starting with 9, which is a reserved range.
At the suggestion of @colinrotherham I've made an internal@mixin nhsuk-font-monospace()mixin and used it in this new modifier and.nhsuk-input--code.Update: We've split out two new sets of utilities:
nhsuk-u-font-codewith Sass mixinnhsuk-font-codenhsuk-u-font-monospacewith Sass mixinnhsuk-font-monospaceWith changes to the
nhsuk-input--codemodifier limited to tighter letter and word spacingSass deprecations
I've updated this PR to include Sass deprecations to prefer
nhsuk-typography-*nhsuk-font-*