Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tricky-nails-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudfour/patterns': minor
---

Add light weight modifier to Heading component
13 changes: 13 additions & 0 deletions src/components/heading/heading.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@use "../../compiled/tokens/scss/opacity";
@use "../../compiled/tokens/scss/size";
@use "../../compiled/tokens/scss/transition";
@use "../../compiled/tokens/scss/font-weight";
@use '../../mixins/focus';
@use '../../mixins/headings';
@use '../../mixins/ms';
Expand Down Expand Up @@ -61,6 +62,18 @@ $max-width-permalink-shift: math.div($min-width-permalink-shift * 16 - 1, 16);
}
}

/**
* Weight modifier
*
* The default font weight for headings is normally defined by heading level.
* This modifier will change the heading to font-weight.$light. We do this to
* maintain the importance of headings without drowning out other content.
*/

.c-heading--light {
font-weight: font-weight.$light;
}

/**
* If `c-heading` is applied to a containing element, this class must be applied
* to the inner heading to avoid unintended font sizes.
Expand Down
18 changes: 18 additions & 0 deletions src/components/heading/heading.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Story, Canvas, Meta } from '@storybook/addon-docs/blocks';
import levelsDemo from './demo/levels.twig';
import template from './heading.twig';
import permalinksDemo from './demo/permalinks.twig';

<Meta title="Components/Heading" />
Expand Down Expand Up @@ -50,6 +51,23 @@ You can control the appearance of a `c-heading` component by including a `c-head
</Story>
</Canvas>

## Light Weight Modifier

The default font weight for headings is normally defined by heading level. This modifier will change the heading to `font-weight.$light`. We do this to maintain the importance of headings without drowning out other content.

<Canvas>
<Story
name="Light weight"
args={{
level: 1,
weight: 'light',
content: 'c-heading--light',
}}
>
{(args) => template(args)}
</Story>
</Canvas>

## Permalinks

The `c-heading` class may include a permalink using [a technique from Marcy Sutton ](http://codepen.io/marcysutton/pen/rLKvgZ). Three elements are required:
Expand Down
15 changes: 10 additions & 5 deletions src/components/heading/heading.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
Build the class name based on the level.
#}

{% set _level_class = 'c-heading' %}
{% set _heading_class = 'c-heading' %}
{% set _heading_class_prefix = 'c-heading' %}

{% if level is not empty %}
{% set _level_modifier = ('level-' ~ level)|replace({ '--': '-n' }) %}
{% set _level_class = _level_class ~ ' ' ~ _level_class ~ '--' ~ _level_modifier %}
{% set _heading_class = _heading_class ~ ' ' ~ _heading_class_prefix ~ '--' ~ _level_modifier %}
{% endif %}

{% if weight is not empty %}
{% set _heading_class = _heading_class ~ ' ' ~ _heading_class_prefix ~ '--' ~ weight %}
{% endif %}

{% if class %}
{% set _level_class = _level_class ~ ' ' ~ class %}
{% set _heading_class = _heading_class ~ ' ' ~ class %}
{% endif %}

{#
Expand Down Expand Up @@ -59,7 +64,7 @@
#}

{% if permalink and permalink_id %}
<div class="{{ _level_class }}">
<div class="{{ _heading_class }}">
<a class="c-heading__permalink" href="#{{ permalink_id }}">
{% include '@cloudfour/components/icon/icon.twig' with {
name: 'link',
Expand All @@ -72,7 +77,7 @@
</{{ tag_name }}>
</div>
{% else %}
<{{ tag_name }} class="{{ _level_class }}">
<{{ tag_name }} class="{{ _heading_class }}">
{{ _content }}
</{{ tag_name }}>
{% endif %}