forked from diplodoc-platform/components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67ccb12
commit 050f137
Showing
11 changed files
with
128 additions
and
54 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,12 @@ | ||
.dc-vcs-link { | ||
display: flex; | ||
align-items: center; | ||
|
||
&__icon { | ||
margin-right: 6px; | ||
|
||
&_type_github { | ||
fill: var(--yc-color-github); | ||
} | ||
} | ||
} |
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,88 @@ | ||
import React from 'react'; | ||
import block from 'bem-cn-lite'; | ||
import {withTranslation, WithTranslation, WithTranslationProps} from 'react-i18next'; | ||
|
||
import GithubIcon from '../../../assets/icons/github.svg'; | ||
import ArcanumIcon from '../../../assets/icons/arcanum.svg'; | ||
|
||
import {Vcs, Lang} from '../../models'; | ||
|
||
import './VcsLink.scss'; | ||
|
||
const b = block('dc-vcs-link'); | ||
|
||
export interface VcsLinkProps { | ||
vcsUrl: string; | ||
vcsType: Vcs; | ||
lang: Lang; | ||
className?: string; | ||
} | ||
|
||
type VcsLinkInnerProps = | ||
& VcsLinkProps | ||
& WithTranslation | ||
& WithTranslationProps; | ||
|
||
export interface IconProps { | ||
className: string; | ||
width: number; | ||
height: number; | ||
} | ||
|
||
class VcsLink extends React.Component<VcsLinkInnerProps> { | ||
componentDidUpdate(prevProps: VcsLinkProps) { | ||
const {i18n, lang} = this.props; | ||
if (prevProps.lang !== lang) { | ||
i18n.changeLanguage(lang); | ||
} | ||
} | ||
|
||
render() { | ||
const {vcsUrl, className} = this.props; | ||
|
||
return ( | ||
<a | ||
href={vcsUrl} | ||
target="_blank" | ||
rel="noreferrer noopener" | ||
className={b(null, className)} | ||
> | ||
{this.renderIcon()} | ||
{this.renderText()} | ||
</a> | ||
); | ||
} | ||
|
||
private renderIcon() { | ||
const {vcsType} = this.props; | ||
|
||
const iconSize = 24; | ||
const iconClassName = b('icon', {type: vcsType}); | ||
const iconProps: IconProps = { | ||
className: iconClassName, | ||
width: iconSize, | ||
height: iconSize, | ||
}; | ||
|
||
switch (vcsType) { | ||
case Vcs.Github: | ||
return <GithubIcon {...iconProps}/>; | ||
case Vcs.Arcanum: | ||
return <ArcanumIcon {...iconProps}/>; | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
private renderText() { | ||
const {vcsType, lang, i18n, t} = this.props; | ||
|
||
if (i18n.language !== lang) { | ||
i18n.changeLanguage(lang); | ||
} | ||
|
||
return t(`label_link-${vcsType}`); | ||
} | ||
} | ||
|
||
export default withTranslation('vcsLink')(VcsLink); |
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,2 @@ | ||
export {default as VcsLink} from './VcsLink'; | ||
export * from './VcsLink'; |
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