-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added temporary fix for focus of sign out link in gov.uk banner * Added timeline component * updated version number * updated check-compatibility * added leading 0 * Update src/components/timeline/_timeline.scss Co-authored-by: Matthew Mascord <[email protected]> * changing import * Added info to the readme Co-authored-by: Matthew Mascord <[email protected]>
- Loading branch information
1 parent
450b9d9
commit 4ff2d88
Showing
10 changed files
with
254 additions
and
15 deletions.
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
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
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,5 @@ | ||
# Timeline | ||
This pattern helps users understand what has happened and when. For example, the history of a tax repayment claim. | ||
|
||
## License | ||
This code is open source software licensed under the [Apache 2.0 License]("http://www.apache.org/licenses/LICENSE-2.0.html"). |
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,46 @@ | ||
@import "../../../../govuk-frontend/govuk/core/typography"; | ||
|
||
.hmrc-timeline { | ||
$border-width: 5px; | ||
|
||
border-left: $border-width solid govuk-colour("blue"); | ||
margin: 0; | ||
margin-bottom: govuk-spacing(6); | ||
padding: 0; | ||
|
||
&__event { | ||
@include govuk-responsive-padding(6, "bottom"); | ||
|
||
padding-left: govuk-spacing(4) - $border-width; | ||
position: relative; | ||
list-style: none; | ||
|
||
&:last-child { | ||
padding-bottom: 0; | ||
} | ||
} | ||
|
||
&__event-title { | ||
@include govuk-responsive-margin(1, "bottom"); | ||
|
||
@extend %govuk-heading-m; | ||
|
||
&::before { | ||
background-color: govuk-colour("blue"); | ||
content: ""; | ||
height: $border-width; | ||
position: absolute; | ||
left: 0; | ||
top: 0.5em; | ||
width: (govuk-spacing(4) * 0.6) - $border-width; | ||
} | ||
} | ||
|
||
&__event-meta { | ||
@include govuk-font($size: 19); | ||
@include govuk-text-colour; | ||
@include govuk-responsive-margin(3, "bottom"); | ||
|
||
display: block; | ||
} | ||
} |
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,3 @@ | ||
{% macro hmrcTimeline(params) %} | ||
{%- include "./template.njk" -%} | ||
{% endmacro %} |
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,13 @@ | ||
{% if params.events | length !== 0 %} | ||
<ol class="hmrc-timeline"> | ||
{% for event in params.events -%} | ||
<li class="hmrc-timeline__event"> | ||
<{% if params.headingLevel %}h{{- params.headingLevel | string | trim -}}{% else %}h2{% endif %} class="hmrc-timeline__event-title">{{ event.title }}</{% if params.headingLevel %}h{{- params.headingLevel | string | trim -}}{% else %}h2{% endif %}> | ||
<time class="hmrc-timeline__event-meta" {% if event.datetime %}datetime="{{event.datetime}}"{% endif %}>{{ event.time }}</time> | ||
<div class="hmrc-timeline__event-content"> | ||
{{ event.content | safe }} | ||
</div> | ||
</li> | ||
{%- endfor %} | ||
</ol> | ||
{% endif %} |
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,90 @@ | ||
/* eslint-env jest */ | ||
|
||
const { render, getExamples } = require('../../../lib/jest-helpers'); | ||
|
||
const examples = getExamples('timeline'); | ||
|
||
describe('Timeline', () => { | ||
describe('by default', () => { | ||
const $ = render('timeline', examples.default); | ||
const $timeline = $('.hmrc-timeline'); | ||
|
||
it('should not show the timeline if there are no parameters given', () => { | ||
expect($timeline.length).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('with one item', () => { | ||
const $ = render('timeline', examples['single-event']); | ||
const $orderedList = $('ol.hmrc-timeline'); | ||
const $listItems = $('li.hmrc-timeline__event'); | ||
const $heading = $('.hmrc-timeline__event-title'); | ||
const $time = $('.hmrc-timeline__event-meta'); | ||
|
||
it('has the correct text', () => { | ||
expect($listItems.text()).toContain('singleExampleContent1'); | ||
}); | ||
|
||
it('has an ordered list', () => { | ||
expect($orderedList.length).toBe(1); | ||
}); | ||
|
||
it('has a list of 1 item', () => { | ||
expect($listItems.length).toBe(1); | ||
}); | ||
|
||
it('has the default heading level', () => { | ||
expect($heading.get(0).tagName).toBe('h2'); | ||
}); | ||
|
||
it('has the title content', () => { | ||
expect($heading.text()).toBe('event one'); | ||
}); | ||
|
||
it('has the correct time text and datetime attribute', () => { | ||
expect($time.text()).toBe('15 July 2020'); | ||
expect($time.attr('datetime')).toBe('2020-07-15'); | ||
}); | ||
}); | ||
|
||
describe('with a custom heading level', () => { | ||
const $ = render('timeline', examples['custom-header-level']); | ||
const $heading = $('.hmrc-timeline__event-title'); | ||
|
||
it('should have a different tag', () => { | ||
expect($heading.get(0).tagName).toBe('h3'); | ||
}); | ||
}); | ||
|
||
describe('with no datetime parameter', () => { | ||
const $ = render('timeline', examples['no-datetime-event']); | ||
const $time = $('.hmrc-timeline__event-meta'); | ||
|
||
it('should not have the datetime attribute', () => { | ||
expect($time.attr('datetime')).toBe(undefined); | ||
}); | ||
}); | ||
|
||
describe('with two items', () => { | ||
const $ = render('timeline', examples['multiple-events']); | ||
const $listItems = $('li.hmrc-timeline__event'); | ||
const $headings = $('.hmrc-timeline__event-title'); | ||
const $times = $('.hmrc-timeline__event-meta'); | ||
|
||
it('Contains a list of 2 items', () => { | ||
expect($listItems.length).toBe(2); | ||
}); | ||
|
||
it('has the correct title, text, time and datetime for each list item', () => { | ||
expect($headings.eq(0).text()).toBe('event one'); | ||
expect($times.eq(0).text()).toBe('20 July 2020'); | ||
expect($times.eq(0).attr('datetime')).toBe('2020-07-20'); | ||
expect($listItems.eq(0).text()).toContain('exampleContent1'); | ||
|
||
expect($headings.eq(1).text()).toBe('event two'); | ||
expect($times.eq(1).text()).toBe('21 July 2020'); | ||
expect($times.eq(1).attr('datetime')).toBe('2020-07-21'); | ||
expect($listItems.eq(1).text()).toContain('exampleContent2'); | ||
}); | ||
}); | ||
}); |
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,75 @@ | ||
params: | ||
- events: | ||
type: array | ||
required: true | ||
description: the list of events in the timeline | ||
params: | ||
- title: | ||
type: string | ||
required: true | ||
description: the name of the event | ||
|
||
- datetime: | ||
type: string | ||
required: false | ||
description: the machine readable date added to the datetime attribute in the time element | ||
|
||
- time: | ||
type: string | ||
required: true | ||
description: the human readable date | ||
|
||
- content: | ||
type: string | ||
required: true | ||
description: the description of the timeline event | ||
- headingLevel: | ||
type: integer | ||
required: false | ||
description: allows customisation of the heading level. | ||
|
||
examples: | ||
- name: default | ||
description: A default example. | ||
data: | ||
events: [] | ||
|
||
- name: custom-header-level | ||
description: Events with custom header levels. | ||
data: | ||
headingLevel: 3 | ||
events: | ||
- title: 'event one' | ||
datetime: '2020-07-14' | ||
time: '14 July 2020' | ||
content: '<p class="govuk-body">exampleContent1</p>' | ||
|
||
- name: no-datetime-event | ||
description: An example with no datetime. | ||
data: | ||
events: | ||
- title: 'event one' | ||
time: '15 July 2020' | ||
content: '<p class="govuk-body">singleExampleContent1</p>' | ||
|
||
- name: single-event | ||
description: An example with a single event. | ||
data: | ||
events: | ||
- title: 'event one' | ||
datetime: '2020-07-15' | ||
time: '15 July 2020' | ||
content: '<p class="govuk-body">singleExampleContent1</p>' | ||
|
||
- name: multiple-events | ||
description: An example with multiple events. | ||
data: | ||
events: | ||
- title: 'event one' | ||
datetime: '2020-07-20' | ||
time: '20 July 2020' | ||
content: '<p class="govuk-body">exampleContent1</p>' | ||
- title: 'event two' | ||
datetime: '2020-07-21' | ||
time: '21 July 2020' | ||
content: '<p class="govuk-body">exampleContent2</p>' |