mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 03:06:31 -05:00
Restructure Link Components and fix internal link children error (#106)
* Restructure Link Components and fix internal link children error
This commit is contained in:
parent
177f639492
commit
5c716bd314
7 changed files with 42 additions and 50 deletions
|
@ -1,5 +1,5 @@
|
|||
import React from 'react'
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import React from 'react'
|
||||
import { Alert } from 'react-bootstrap'
|
||||
|
||||
export interface LoadingScreenProps {
|
||||
|
|
|
@ -18,7 +18,7 @@ export const PoweredByLinks: React.FC = () => {
|
|||
<ExternalLink href="https://codimd.org" text="CodiMD"/>
|
||||
</Trans>
|
||||
|
|
||||
<TranslatedInternalLink path='/n/release-notes' i18nKey='landing.footer.releases'/>
|
||||
<TranslatedInternalLink href='/n/release-notes' i18nKey='landing.footer.releases'/>
|
||||
{
|
||||
Object.entries({ ...config.specialLinks }).map(([i18nKey, href]) =>
|
||||
<Fragment key={i18nKey}>
|
||||
|
|
|
@ -1,18 +1,8 @@
|
|||
import React, { Fragment } from 'react'
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import { IconProp } from '../../utils/iconProp'
|
||||
import React, { Fragment } from 'react'
|
||||
import { LinkWithTextProps } from './types'
|
||||
|
||||
export interface ExternalLinkProp {
|
||||
href: string;
|
||||
icon?: IconProp;
|
||||
className?: string
|
||||
}
|
||||
|
||||
export interface ExternalLinkTextProp {
|
||||
text: string;
|
||||
}
|
||||
|
||||
export const ExternalLink: React.FC<ExternalLinkProp & ExternalLinkTextProp> = ({ href, text, icon, className = 'text-light' }) => {
|
||||
export const ExternalLink: React.FC<LinkWithTextProps> = ({ href, text, icon, className = 'text-light' }) => {
|
||||
return (
|
||||
<a href={href}
|
||||
target="_blank"
|
||||
|
|
|
@ -1,30 +1,22 @@
|
|||
import React, { Fragment } from 'react'
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import React, { Fragment } from 'react'
|
||||
import { LinkContainer } from 'react-router-bootstrap'
|
||||
import { IconProp } from '../../utils/iconProp'
|
||||
import { LinkWithTextProps } from './types'
|
||||
|
||||
export interface InternalLinkProp {
|
||||
path: string;
|
||||
icon?: IconProp;
|
||||
className?: string
|
||||
}
|
||||
|
||||
export interface InternalLinkTextProp {
|
||||
text: string;
|
||||
}
|
||||
|
||||
export const InternalLink: React.FC<InternalLinkProp & InternalLinkTextProp> = ({ path, text, icon, className = 'text-light' }) => {
|
||||
export const InternalLink: React.FC<LinkWithTextProps> = ({ href, text, icon, className = 'text-light' }) => {
|
||||
return (
|
||||
<LinkContainer to={path}
|
||||
<LinkContainer to={href}
|
||||
className={className}>
|
||||
{
|
||||
icon
|
||||
? <Fragment>
|
||||
<FontAwesomeIcon icon={icon} fixedWidth={true}/>
|
||||
</Fragment>
|
||||
: null
|
||||
}
|
||||
{text}
|
||||
<Fragment>
|
||||
{
|
||||
icon
|
||||
? <Fragment>
|
||||
<FontAwesomeIcon icon={icon} fixedWidth={true}/>
|
||||
</Fragment>
|
||||
: null
|
||||
}
|
||||
{text}
|
||||
</Fragment>
|
||||
</LinkContainer>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,18 +1,11 @@
|
|||
import { StringMap, TOptionsBase } from 'i18next'
|
||||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { ExternalLink, ExternalLinkProp } from './external-link'
|
||||
import { ExternalLink } from './external-link'
|
||||
import { TranslatedLinkProps } from './types'
|
||||
|
||||
export interface TranslatedLinkProps {
|
||||
i18nKey: string;
|
||||
i18nOption?: (TOptionsBase & StringMap) | string
|
||||
}
|
||||
|
||||
const TranslatedExternalLink: React.FC<TranslatedLinkProps & ExternalLinkProp> = ({ i18nKey, i18nOption, ...props }) => {
|
||||
export const TranslatedExternalLink: React.FC<TranslatedLinkProps> = ({ i18nKey, i18nOption, ...props }) => {
|
||||
const { t } = useTranslation()
|
||||
return (
|
||||
<ExternalLink text={t(i18nKey, i18nOption)} {...props}/>
|
||||
)
|
||||
}
|
||||
|
||||
export { TranslatedExternalLink }
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { InternalLink, InternalLinkProp } from './internal-link'
|
||||
import { TranslatedLinkProps } from './translated-external-link'
|
||||
import { InternalLink } from './internal-link'
|
||||
import { TranslatedLinkProps } from './types'
|
||||
|
||||
export const TranslatedInternalLink: React.FC<TranslatedLinkProps & InternalLinkProp> = ({ i18nKey, i18nOption, ...props }) => {
|
||||
export const TranslatedInternalLink: React.FC<TranslatedLinkProps> = ({ i18nKey, i18nOption, ...props }) => {
|
||||
const { t } = useTranslation()
|
||||
return (
|
||||
<InternalLink text={t(i18nKey, i18nOption)} {...props}/>
|
||||
|
|
17
src/components/links/types.ts
Normal file
17
src/components/links/types.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { StringMap, TOptionsBase } from 'i18next'
|
||||
import { IconProp } from '../../utils/iconProp'
|
||||
|
||||
export interface GeneralLinkProp {
|
||||
href: string;
|
||||
icon?: IconProp;
|
||||
className?: string
|
||||
}
|
||||
|
||||
export interface LinkWithTextProps extends GeneralLinkProp {
|
||||
text: string;
|
||||
}
|
||||
|
||||
export interface TranslatedLinkProps extends GeneralLinkProp{
|
||||
i18nKey: string;
|
||||
i18nOption?: (TOptionsBase & StringMap) | string
|
||||
}
|
Loading…
Reference in a new issue