Skip to content

Commit

Permalink
Add ability to change the default heading level of care cards
Browse files Browse the repository at this point in the history
  • Loading branch information
the-nathan-smith authored and mikemonteith committed Aug 18, 2021
1 parent f890d95 commit 139a954
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## v1.1.0
- Add optional default heading level setting for care cards

## v1.0.0

### Upgrade Considerations
Expand Down
6 changes: 6 additions & 0 deletions docs/components/care_card.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class MyPage(Page):
])
```

# Default Heading Level

The default heading level for care cards is 3 but this can be overwritten using a Django setting.
See testapp/testapp/settings/base.py as an example.
If no setting is supplied the default will remain 3.

## Reference

* [Service Manual](https://service-manual.nhs.uk/design-system/components/care-cards)
Expand Down
4 changes: 4 additions & 0 deletions testapp/testapp/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,7 @@

# Default field for primary keys
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

# Default heading level for care cards
# Uncomment the line below and change the value to what you want (min=2 max=6)
# DEFAULT_CARE_CARD_HEADING_LEVEL = 3
9 changes: 8 additions & 1 deletion wagtailnhsukfrontend/blocks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.core.exceptions import ValidationError
from django.conf import settings
from django.forms.utils import ErrorList
from wagtail.core.blocks import (
BooleanBlock,
Expand Down Expand Up @@ -328,14 +329,20 @@ class Meta:
template = 'wagtailnhsukfrontend/expander_group.html'


if hasattr(settings, 'DEFAULT_CARE_CARD_HEADING_LEVEL'):
CARE_CARD_HEADING_LEVEL = settings.DEFAULT_CARE_CARD_HEADING_LEVEL
else:
CARE_CARD_HEADING_LEVEL = 3


class CareCardBlock(FlattenValueContext, StructBlock):

type = ChoiceBlock([
('primary', 'Non-urgent'),
('urgent', 'Urgent'),
('immediate', 'Immediate'),
], required=True, default='primary',)
heading_level = IntegerBlock(required=True, min_value=2, max_value=6, default=3, help_text='The heading level affects users with screen readers. Default=3, Min=2, Max=4.')
heading_level = IntegerBlock(required=True, min_value=2, max_value=6, default=CARE_CARD_HEADING_LEVEL, help_text='The heading level affects users with screen readers. Default=' + str(CARE_CARD_HEADING_LEVEL) + ', Min=2, Max=4.')
title = CharBlock(required=True)

class BodyStreamBlock(StreamBlock):
Expand Down

0 comments on commit 139a954

Please sign in to comment.