-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12123 from bbc/WSTEAMA-1421-create-jumpto-skeleto…
…n-component Add JumpTo Component (Experiment - Hindi Service)
- Loading branch information
Showing
10 changed files
with
281 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## Description | ||
|
||
The JumpTo component serves as an in-page navigation menu, similar to a table of contents, allowing users to quickly jump to specific headings within an article. This component renders text as a `strong` element, a list of `anchor` links, and groups them within a `navigation` landmark. When a link is actioned, the page scrolls down to the relevant heading, identified by matching anchor `ids`. | ||
|
||
This component is typically used in articles with multiple headings, enhancing content findability by providing quick navigation options. | ||
|
||
## Props | ||
|
||
| Name | type | Description | | ||
| ----------------- | --------------------- | ----------------------------------------------- | | ||
| jumpToData | object | Contains article headings with titles and IDs | | ||
| eventTrackingData | eventTrackingMetadata | Contains click and view tracking data for Piano | |
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,84 @@ | ||
const pidginArticleFixtureWithJumpToBlock = { | ||
data: { | ||
article: { | ||
metadata: { | ||
atiAnalytics: { | ||
categoryName: 'US+election+2024', | ||
contentId: 'urn:bbc:optimo:asset:cn03je8kwpko', | ||
contentType: 'article', | ||
language: 'pcm', | ||
pageTitle: 'Kamala Harris Fox News interview in four short points', | ||
timePublished: '2024-10-17T09:27:26.770Z', | ||
timeUpdated: '2024-10-17T09:41:25.801Z', | ||
}, | ||
id: 'urn:bbc:ares::article:cn03je8kwpko', | ||
type: 'article', | ||
language: 'pcm', | ||
}, | ||
content: { | ||
model: { | ||
blocks: [ | ||
{ | ||
id: 'headline', | ||
type: 'headline', | ||
model: { | ||
text: 'Kamala Harris Fox interview in four short points', | ||
}, | ||
}, | ||
{ | ||
id: 'timestamp', | ||
type: 'timestamp', | ||
model: { | ||
firstPublished: 1729157246770, | ||
lastPublished: 1729158085801, | ||
}, | ||
}, | ||
{ | ||
id: 'text-intro', | ||
type: 'text', | ||
model: { | ||
blocks: [ | ||
{ | ||
type: 'paragraph', | ||
model: { | ||
text: 'Kamala Harris discusses her views in a Fox interview.', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: 'jumpTo', | ||
type: 'jumpTo', | ||
model: { | ||
jumpToHeadings: [ | ||
{ heading: 'Harris separates from Biden' }, | ||
{ heading: 'Prison gender surgery debate' }, | ||
{ heading: 'Apology challenge' }, | ||
{ heading: "Biden's mental state questioned" }, | ||
], | ||
}, | ||
}, | ||
{ | ||
id: 'text-main', | ||
type: 'text', | ||
model: { | ||
blocks: [ | ||
{ | ||
type: 'paragraph', | ||
model: { | ||
text: "Harris touched on several critical issues in the interview, including Biden's policy and her stance on prison reforms.", | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
contentType: 'application/json; charset=utf-8', | ||
}; | ||
|
||
export default pidginArticleFixtureWithJumpToBlock; |
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,27 @@ | ||
import React from 'react'; | ||
import pidginArticleFixtureWithJumpToBlock from './fixtureData'; | ||
import JumpTo, { JumpToProps } from '.'; | ||
import metadata from './metadata.json'; | ||
import readme from './README.md'; | ||
|
||
const Component = ({ jumpToHeadings = [] }: JumpToProps) => { | ||
return <JumpTo jumpToHeadings={jumpToHeadings} />; | ||
}; | ||
|
||
export default { | ||
title: 'Components/JumpTo', | ||
Component, | ||
parameters: { | ||
docs: { readme }, | ||
metadata, | ||
}, | ||
}; | ||
|
||
export const Example = () => { | ||
const jumpToHeadings = | ||
pidginArticleFixtureWithJumpToBlock.data.article.content.model.blocks.find( | ||
block => block.type === 'jumpTo', | ||
)?.model.jumpToHeadings; | ||
|
||
return <Component jumpToHeadings={jumpToHeadings} />; | ||
}; |
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,58 @@ | ||
/** @jsx jsx */ | ||
import { useContext } from 'react'; | ||
import { jsx } from '@emotion/react'; | ||
import { ServiceContext } from '#contexts/ServiceContext'; | ||
import useViewTracker from '#app/hooks/useViewTracker'; | ||
import useClickTrackerHandler from '#app/hooks/useClickTrackerHandler'; | ||
import { EventTrackingMetadata } from '#app/models/types/eventTracking'; | ||
import Text from '#app/components/Text'; | ||
import InlineLink from '#app/components/InlineLink'; | ||
import idSanitiser from '../../lib/utilities/idSanitiser'; | ||
|
||
export interface JumpToProps { | ||
jumpToHeadings?: Array<{ heading: string }>; | ||
eventTrackingData?: EventTrackingMetadata; | ||
} | ||
|
||
const JumpTo = ({ jumpToHeadings, eventTrackingData }: JumpToProps) => { | ||
const { translations } = useContext(ServiceContext); | ||
const { jumpTo = 'Jump to' } = translations?.articlePage || {}; | ||
|
||
const viewRef = useViewTracker(eventTrackingData); | ||
const clickTrackerHandler = useClickTrackerHandler({ | ||
...eventTrackingData, | ||
componentName: 'jumpto', | ||
}); | ||
|
||
const titleId = 'jump-to-heading'; | ||
|
||
return ( | ||
<nav | ||
ref={viewRef} | ||
role="navigation" | ||
aria-labelledby={titleId} | ||
data-testid="jump-to" | ||
> | ||
<Text as="strong" id={titleId}> | ||
{jumpTo} | ||
</Text> | ||
<ol role="list"> | ||
{jumpToHeadings?.map(({ heading }) => { | ||
const sanitisedId = idSanitiser(heading); | ||
return ( | ||
<li key={sanitisedId}> | ||
<InlineLink | ||
to={`#${sanitisedId}`} | ||
onClick={clickTrackerHandler} | ||
data-testid={`jump-to-link-${sanitisedId}`} | ||
text={heading} | ||
/> | ||
</li> | ||
); | ||
})} | ||
</ol> | ||
</nav> | ||
); | ||
}; | ||
|
||
export default JumpTo; |
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,29 @@ | ||
{ | ||
"alpha": false, | ||
"lastUpdated": { | ||
"day": 1, | ||
"month": "November", | ||
"year": 2024 | ||
}, | ||
"uxAccessibilityDoc": { | ||
"done": true, | ||
"reference": { | ||
"url": "https://www.figma.com/design/axYpw2KkNQAMjzdOYa677D/WS-OJ-experiment-handover?node-id=3506-3763&node-type=frame&t=djsGA5Y4x4ey3ar4-0", | ||
"label": "Screen Reader UX" | ||
} | ||
}, | ||
"acceptanceCriteria": { | ||
"done": true, | ||
"reference": { | ||
"url": "https://paper.dropbox.com/doc/Jump-to-menu-Accessibility-acceptance-criteria--CZuZGgB0eyva~6M50q_UCCQUAg-b5wF4xr9YMgITE0Ui9sWc", | ||
"label": "Accessibility Acceptance Criteria" | ||
} | ||
}, | ||
"swarm": { | ||
"done": false, | ||
"reference": { | ||
"url": "", | ||
"label": "Accessibility Swarm Notes" | ||
} | ||
} | ||
} |
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