This repository was archived by the owner on Apr 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add linkTarget to <RelatedComponents> (#125)
- Loading branch information
1 parent
c526246
commit 260d782
Showing
5 changed files
with
77 additions
and
22 deletions.
There are no files selected for viewing
14 changes: 10 additions & 4 deletions
14
src/components/information-box-title/information-box-title.tsx
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 |
---|---|---|
@@ -1,22 +1,28 @@ | ||
import { FC } from 'react'; | ||
import cx from 'classnames'; | ||
import { ElementContent } from '../../types'; | ||
import { ElementContent, withStaticProps } from '../../types'; | ||
import Link from '../link/link'; | ||
import { LinkTarget } from '../link/LinkConstants'; | ||
import styles from './information-box-title.module.scss'; | ||
|
||
type InformationBoxTitleProps = { | ||
children: ElementContent; | ||
href?: string; | ||
linkTarget?: LinkTarget; | ||
}; | ||
|
||
const InformationBoxTitle: FC<InformationBoxTitleProps> = ({ children, href }) => { | ||
const InformationBoxTitle: FC<InformationBoxTitleProps> & { linkTargets?: typeof LinkTarget } = ({ | ||
children, | ||
href, | ||
linkTarget, | ||
}) => { | ||
return href && typeof children === 'string' ? ( | ||
<Link className={cx(styles.informationBoxTitle)} href={href} withoutSpacing> | ||
<Link className={cx(styles.informationBoxTitle)} href={href} withoutSpacing target={linkTarget}> | ||
{children} | ||
</Link> | ||
) : ( | ||
<h4 className={cx(styles.informationBoxTitle, { [styles.titleLink]: href })}>{children}</h4> | ||
); | ||
}; | ||
|
||
export default InformationBoxTitle; | ||
export default withStaticProps(InformationBoxTitle, { linkTargets: LinkTarget }); |
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 |
---|---|---|
@@ -1,22 +1,35 @@ | ||
import React from 'react'; | ||
import React, { useContext } from 'react'; | ||
import InformationBox from '../information-box/information-box'; | ||
import { ElementContent } from '../../types'; | ||
import { LinkTarget } from '../link/LinkConstants'; | ||
import { ElementContent, withStaticProps } from '../../types'; | ||
import { RelatedComponentsContext } from '../related-components/related-components-context'; | ||
import styles from './related-component.module.scss'; | ||
|
||
interface RelatedComponentProps { | ||
component?: ElementContent; | ||
title?: string; | ||
description?: string; | ||
href: string; | ||
linkTarget?: LinkTarget; | ||
} | ||
|
||
const RelatedComponent: React.FC<RelatedComponentProps> = ({ component, title = '', description = '', href }) => ( | ||
<InformationBox | ||
component={<div className={styles.relatedComponentComponent}>{component}</div>} | ||
title={title} | ||
description={description} | ||
href={href} | ||
/> | ||
); | ||
const RelatedComponent: React.FC<RelatedComponentProps> & { linkTargets?: typeof LinkTarget } = ({ | ||
component, | ||
title = '', | ||
description = '', | ||
href, | ||
linkTarget, | ||
}) => { | ||
const overrideLinkTarget = linkTarget || useContext(RelatedComponentsContext).linkTarget; | ||
return ( | ||
<InformationBox | ||
component={<div className={styles.relatedComponentComponent}>{component}</div>} | ||
title={title} | ||
description={description} | ||
href={href} | ||
linkTarget={overrideLinkTarget} | ||
/> | ||
); | ||
}; | ||
|
||
export default RelatedComponent; | ||
export default withStaticProps(RelatedComponent, { linkTargets: LinkTarget }); |
10 changes: 10 additions & 0 deletions
10
src/components/related-components/related-components-context.ts
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,10 @@ | ||
import React from 'react'; | ||
import { LinkTarget } from '../link/LinkConstants'; | ||
|
||
type RelatedComponentsContextType = { | ||
linkTarget?: LinkTarget; | ||
}; | ||
|
||
export const RelatedComponentsContext = React.createContext<RelatedComponentsContextType>({ | ||
linkTarget: LinkTarget.NEW_WINDOW, | ||
}); |
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