-
Notifications
You must be signed in to change notification settings - Fork 15
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 #185 from rsksmart/feat/news-line
News announcement bar
- Loading branch information
Showing
4 changed files
with
108 additions
and
5 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,60 @@ | ||
import React, { useState, useEffect, useLayoutEffect } from 'react' | ||
import clsx from 'clsx' | ||
import styles from './styles.module.scss' | ||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext' | ||
import Link from '/src/components/Link' | ||
|
||
export default function NewsLine () { | ||
const { siteConfig } = useDocusaurusContext() | ||
const news = siteConfig?.customFields?.newsHighlight || [] | ||
const [isClosed, setIsClosed] = useState(false) | ||
const [isVisible, setIsVisible] = useState(true) | ||
let lastScrollTop = 0 | ||
|
||
const handleClose = () => { | ||
setIsClosed(true) | ||
sessionStorage.setItem('DevportalNewsLineClosed', 'true') | ||
} | ||
const truncateTitle = (title, maxLength) => { | ||
return title.length > maxLength ? `${title.substring(0, maxLength)}...` : title | ||
} | ||
useLayoutEffect(() => { | ||
if (!window) return; | ||
setIsClosed(sessionStorage.getItem('DevportalNewsLineClosed') === 'true') | ||
const handleScroll = () => { | ||
const scrollTop = window.pageYOffset || document.documentElement.scrollTop | ||
if (scrollTop > lastScrollTop) { | ||
setIsVisible(false) | ||
} else { | ||
setIsVisible(true) | ||
} | ||
lastScrollTop = scrollTop <= 0 ? 0 : scrollTop | ||
} | ||
|
||
window.addEventListener('scroll', handleScroll) | ||
return () => { | ||
window.removeEventListener('scroll', handleScroll) | ||
} | ||
}, [isClosed]) | ||
|
||
return (news?.length > 0 && !isClosed) && ( | ||
<div className={clsx(styles.NewsLineWrap, { [styles.hidden]: !isVisible })}> | ||
<div className={clsx(`py-10`, styles.NewsLine)}> | ||
<div className="container d-flex align-self-start align-items-md-center gap-8"> | ||
<div className="d-flex flex-column flex-wrap flex-md-row align-items-md-center justify-content-md-center gap-8 column-gap-lg-16 flex-grow-1"> | ||
{news.slice(0, 4).map((item, index) => ( | ||
<Link key={index} href={item.url} className={clsx(`d-flex fs-14 gap-16 align-items-center link-base`)}> | ||
{truncateTitle(item.title, 150)} | ||
</Link> | ||
))} | ||
</div> | ||
<button className="btn-blank d-flex" onClick={handleClose} aria-label="Close"> | ||
<svg width="16" height="16"> | ||
<use xlinkHref="#icon-close-circle"/> | ||
</svg> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} |
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,38 @@ | ||
.NewsLine { | ||
background: var(--bs-body-bg); | ||
border: 1px solid var(--bs-body-color); | ||
border-width: 1px 0; | ||
|
||
@media (max-width: 996.98px) { | ||
border-width: 0 0 1px; | ||
} | ||
} | ||
|
||
.NewsLineWrap { | ||
position: sticky; | ||
top: 88px; | ||
z-index: calc(var(--ifm-z-index-fixed) - 1); | ||
transition: transform 0.3s cubic-bezier(0.65, 0, 0.35, 1); | ||
|
||
@media (max-width: 996.98px) { | ||
top: 73px; | ||
margin-top: -24px; | ||
margin-bottom: 24px; | ||
padding-left: 16px; | ||
padding-right: 16px; | ||
|
||
[class*="container"] { | ||
padding-left: 0; | ||
padding-right: 0; | ||
} | ||
} | ||
@media (max-width: 767.98px) { | ||
top: 54px; | ||
margin-top: -16px; | ||
margin-bottom: 24px; | ||
} | ||
|
||
&.hidden { | ||
transform: translateY(-102%); | ||
} | ||
} |
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