-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added ArticleNavigation component, which provides next/prev nav…
…igation between articles (#169) * feat: Added ArticleNavigation component, which provides next/prev navigation between articles (#159) * fix: fixed section links and mdx rendered margin * fix: a little refactoring * fix: removed unuseful functions --------- Co-authored-by: Aleksei <[email protected]>
- Loading branch information
1 parent
6d49ddf
commit 27b836b
Showing
11 changed files
with
339 additions
and
47 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,66 @@ | ||
@use '~@gravity-ui/page-constructor/styles/variables.scss' as pcVariables; | ||
@use '../../variables.scss'; | ||
|
||
$block: '.#{variables.$ns}article-navigation'; | ||
|
||
#{$block} { | ||
display: flex; | ||
gap: var(--g-spacing-6); | ||
@media (max-width: map-get(pcVariables.$gridBreakpoints, 'md') - 1) { | ||
gap: var(--g-spacing-5); | ||
} | ||
&__content { | ||
padding: var(--g-spacing-2) 0; | ||
overflow: hidden; | ||
width: 100%; | ||
@media (max-width: map-get(pcVariables.$gridBreakpoints, 'md') - 1) { | ||
padding: var(--g-spacing-3) 0; | ||
} | ||
@media (max-width: map-get(pcVariables.$gridBreakpoints, 'sm') - 1) { | ||
display: none; | ||
} | ||
&-title { | ||
@media (max-width: map-get(pcVariables.$gridBreakpoints, 'md') - 1) { | ||
display: none; | ||
} | ||
} | ||
} | ||
&__button { | ||
cursor: pointer; | ||
text-decoration: none; | ||
display: flex; | ||
gap: var(--g-spacing-3); | ||
width: 50%; | ||
border-radius: 16px; | ||
border: 1px solid var(--g-color-sfx-fade); | ||
padding: var(--g-spacing-1); | ||
justify-content: space-between; | ||
@media (max-width: map-get(pcVariables.$gridBreakpoints, 'sm') - 1) { | ||
width: unset; | ||
} | ||
&_reverse { | ||
flex-direction: row-reverse; | ||
margin-left: auto; | ||
padding-left: var(--g-spacing-5); | ||
@media (max-width: map-get(pcVariables.$gridBreakpoints, 'sm') - 1) { | ||
padding-left: var(--g-spacing-1); | ||
} | ||
} | ||
&-icon { | ||
flex: none; | ||
border-radius: 12px; | ||
background: var(--g-color-base-generic); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
color: var(--g-color-text-primary); | ||
padding: 0 var(--g-spacing-5); | ||
@media (max-width: map-get(pcVariables.$gridBreakpoints, 'md') - 1) { | ||
padding: 0 var(--g-spacing-3); | ||
} | ||
@media (max-width: map-get(pcVariables.$gridBreakpoints, 'sm') - 1) { | ||
padding: var(--g-spacing-3); | ||
} | ||
} | ||
} | ||
} |
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,78 @@ | ||
import {ArrowLeft, ArrowRight} from '@gravity-ui/icons'; | ||
import {Flex, Icon, Text} from '@gravity-ui/uikit'; | ||
import Link from 'next/link'; | ||
import {useCallback} from 'react'; | ||
import {CONTENT_WRAPPER_ID} from 'src/constants'; | ||
import {block} from 'src/utils'; | ||
|
||
import {SubSection} from '../NavigationLayout/types'; | ||
|
||
const b = block('article-navigation'); | ||
|
||
import './ArticleNavigation.scss'; | ||
|
||
interface ArticleNavigationProps { | ||
prevSection: SubSection | null; | ||
nextSection: SubSection | null; | ||
} | ||
|
||
export const ArticleNavigation: React.FC<ArticleNavigationProps> = ({prevSection, nextSection}) => { | ||
const scrollTop = useCallback(() => { | ||
const content = document.getElementById(CONTENT_WRAPPER_ID); | ||
if (content) { | ||
content.scrollTo({ | ||
top: 0, | ||
behavior: 'smooth', | ||
}); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<div className={b()}> | ||
{prevSection && ( | ||
<Link href={prevSection.url}> | ||
<a className={b('button')} onClick={scrollTop}> | ||
<div className={b('button-icon')}> | ||
<Icon data={ArrowLeft} size={16} /> | ||
</div> | ||
<Flex direction="column" gap="1" className={b('content')}> | ||
<Text variant="body-short" color="light-complementary"> | ||
Previous | ||
</Text> | ||
<Text | ||
className={b('content-title')} | ||
ellipsis={true} | ||
variant="body-2" | ||
color="primary" | ||
> | ||
{prevSection.title} | ||
</Text> | ||
</Flex> | ||
</a> | ||
</Link> | ||
)} | ||
{nextSection && ( | ||
<Link href={nextSection.url}> | ||
<a className={b('button', {reverse: true})} onClick={scrollTop}> | ||
<div className={b('button-icon')}> | ||
<Icon data={ArrowRight} size={16} /> | ||
</div> | ||
<Flex direction="column" gap="1" className={b('content')}> | ||
<Text variant="body-short" color="light-complementary"> | ||
Next | ||
</Text> | ||
<Text | ||
className={b('content-title')} | ||
ellipsis={true} | ||
variant="body-2" | ||
color="primary" | ||
> | ||
{nextSection.title} | ||
</Text> | ||
</Flex> | ||
</a> | ||
</Link> | ||
)} | ||
</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 @@ | ||
export {ArticleNavigation} from './ArticleNavigation'; |
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
Oops, something went wrong.