-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update line-height behavior to respect token value, size headings rel…
…ative to body text (#291) * Normalize heading line-heights **Why**: - So that assigned line-heights match expectations based upon [the available token options](https://github.com/uswds/uswds/blob/61a0d99f0e6b36c3758948ba6ac46140abc5e585/src/stylesheets/theme/_uswds-theme-typography.scss#L363-L371), not influenced by either font family or scale - So that heading line-heights can be smaller than body content, but only in the case that the actual value would be greater than that of body text (and in all other cases, using the body line-height for headings) * Update CHANGELOG.md
- Loading branch information
Showing
5 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import 'typography'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
---------------------------------------- | ||
typeset() | ||
---------------------------------------- | ||
Replaces USWDS typeset to set heading | ||
line-height as the maximum between the | ||
default heading line-height and the body | ||
line-height when considering font-size | ||
---------------------------------------- | ||
*/ | ||
|
||
@mixin typeset( | ||
$family: $theme-body-font-family, | ||
$scale: $theme-body-font-size, | ||
$line-height-scale: $theme-body-line-height | ||
) { | ||
@if type-of($family) == 'list' { | ||
$list: $family; | ||
$family: if(nth($list, 1), nth($list, 1), null); | ||
$scale: if(nth($list, 2), nth($list, 2), null); | ||
$line-height: if(nth($list, 3), nth($list, 3), null); | ||
} | ||
$family: if($family == null, $theme-body-font-family, $family); | ||
$scale: if($scale == null, $theme-body-font-size, $scale); | ||
$line-height-scale: if($line-height-scale == null, $theme-body-line-height, $line-height-scale); | ||
|
||
$font-size: font-size($family, $scale); | ||
$line-height: lh($family, $line-height-scale); | ||
|
||
font-family: ff($family); | ||
font-size: $font-size; | ||
@if ( | ||
$family == 'heading' and $font-size * $line-height < 1rem * lh('body', $theme-body-line-height) | ||
) { | ||
$line-height: lh($family, $theme-body-line-height); | ||
} | ||
line-height: $line-height; | ||
} | ||
|
||
/* | ||
---------------------------------------- | ||
h6() | ||
---------------------------------------- | ||
Replaces USWDS h6 to set heading family | ||
---------------------------------------- | ||
*/ | ||
|
||
@mixin h6 { | ||
@include typeset('heading', $theme-h6-font-size, $theme-heading-line-height); | ||
|
||
font-weight: fw('normal'); | ||
letter-spacing: ls('ls-1'); | ||
text-transform: uppercase; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
---------------------------------------- | ||
line-height() | ||
lh() | ||
---------------------------------------- | ||
Replaces USWDS lh to remove line-height | ||
normalization behavior | ||
---------------------------------------- | ||
*/ | ||
|
||
@function lh($props...) { | ||
$props: unpack($props); | ||
|
||
@if not(length($props) == 2) { | ||
@error 'lh() needs both a valid face and line height token ' | ||
+ 'in the format `lh(FACE, HEIGHT)`.'; | ||
} | ||
|
||
$scale: smart-quote(nth($props, 2)); | ||
|
||
@if not map-get($system-line-height, $scale) { | ||
@return error-not-token($scale, 'line-height', $system-line-height); | ||
} | ||
|
||
@return map-get($system-line-height, $scale); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters