-
Notifications
You must be signed in to change notification settings - Fork 30
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 #12496 from guardian/rm/add-multi-byline
Add multi byline element
- Loading branch information
Showing
22 changed files
with
1,077 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { css } from '@emotion/react'; | ||
import { space, textSans14 } from '@guardian/source/foundations'; | ||
import sanitise from 'sanitize-html'; | ||
import { palette } from '../palette'; | ||
|
||
/** Nesting is necessary in the bio styles because we receive a string of html from the | ||
* field. This can contain the following tags: | ||
* Blocks: p, ul, li | ||
* Inline: strong, em, a | ||
*/ | ||
const bioStyles = css` | ||
${textSans14}; | ||
padding: ${space[1]}px 0; | ||
color: ${palette('--bio-text-subdued')}; | ||
p { | ||
margin-bottom: ${space[2]}px; | ||
} | ||
a { | ||
color: ${palette('--link-kicker-text')}; | ||
text-underline-offset: 3px; | ||
} | ||
a:not(:hover) { | ||
text-decoration-color: ${palette('--bio-link-underline')}; | ||
} | ||
a:hover { | ||
text-decoration: underline; | ||
} | ||
ul { | ||
list-style: none; | ||
margin: 0 0 ${space[2]}px; | ||
padding: 0; | ||
} | ||
ul li { | ||
padding-left: ${space[5]}px; | ||
} | ||
ul li p { | ||
display: inline-block; | ||
margin-bottom: 0; | ||
} | ||
ul li:before { | ||
display: inline-block; | ||
content: ''; | ||
border-radius: 0.375rem; | ||
height: 10px; | ||
width: 10px; | ||
margin: 0 ${space[2]}px 0 -${space[5]}px; | ||
background-color: ${palette('--bullet-fill')}; | ||
} | ||
strong { | ||
font-weight: bold; | ||
} | ||
`; | ||
|
||
const bottomBorderStyles = css` | ||
border-top: 1px solid ${palette('--article-border')}; | ||
margin-bottom: ${space[2]}px; | ||
`; | ||
|
||
const containsText = (html: string) => { | ||
const htmlWithoutTags = sanitise(html, { | ||
allowedTags: [], | ||
allowedAttributes: {}, | ||
}); | ||
return htmlWithoutTags.length > 0; | ||
}; | ||
|
||
export const Bio = ({ html }: { html?: string }) => { | ||
if (!html || !containsText(html)) return null; | ||
const sanitizedHtml = sanitise(html, {}); | ||
return ( | ||
<> | ||
<div | ||
css={bioStyles} | ||
dangerouslySetInnerHTML={{ __html: sanitizedHtml }} | ||
/> | ||
<div css={bottomBorderStyles} /> | ||
</> | ||
); | ||
}; |
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,18 @@ | ||
import { css } from '@emotion/react'; | ||
import { space, textSans14 } from '@guardian/source/foundations'; | ||
import { palette } from '../palette'; | ||
|
||
const endNoteStyles = css` | ||
${textSans14}; | ||
color: ${palette('--end-note-text-subdued')}; | ||
margin-bottom: ${space[3]}px; | ||
`; | ||
|
||
export const EndNote = ({ text }: { text?: string }) => { | ||
if (!text) return null; | ||
return ( | ||
<p css={endNoteStyles}> | ||
<em>{text}</em> | ||
</p> | ||
); | ||
}; |
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
Oops, something went wrong.