Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextLink component #109

Merged
merged 6 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions ui/src/components/TextLink/TextLink.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react'
import classes from './TextLink.module.scss'
import { FiExternalLink } from 'react-icons/fi'
import PropTypes from 'prop-types'

const TextLink = ({ url, text, external }) => {
const handleClick = () => {
external ? window.open(url, '_blank') : window.location.href = url
}

return (
<a
href={url}
target={external ? '_blank' : '_self'}
rel={external ? 'noopener noreferrer' : ''}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, świetnie użyłeś noopener noreferrer 😀 Fajny use-case

onClick={handleClick}
className={`${classes.textLink} ${external ? 'external' : ''}`}
>
{text}
{external && <FiExternalLink className={classes.externalIcon}/>}
</a>
)
}

TextLink.propTypes = {
/** destination URL that the link you want to navigate to */
url: PropTypes.string.isRequired,
/** content that will be displayed in the link */
text: PropTypes.string.isRequired,
/** boolean that indicates whether the link is external or internal */
external: PropTypes.bool
}

export default TextLink
26 changes: 26 additions & 0 deletions ui/src/components/TextLink/TextLink.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@import '../../assets/styles/abstracts/variables';

.textLink {
text-decoration: underline;
color: $alternative-a500;
padding: 0.625em 0.25em 0em 0.25em;
border-radius: 2px;
transition: background-color 0.3s;

&:hover {
background-color: $base-white;
}

&:focus {
outline: none;
background-color: $primary-p100;
}

}

.externalIcon {
top: -3.2px;
margin-left: 4.8px;
vertical-align: text-bottom;
position: relative;
}
28 changes: 28 additions & 0 deletions ui/src/components/TextLink/TextLink.stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'
import TextLink from './TextLink'

export default {
title: 'Components/TextLink',
component: TextLink,
argTypes: {
external: {
control: 'boolean'
}
}
}

const Template = (args) => <TextLink {...args} />

export const InternalLink = Template.bind({})
InternalLink.args = {
url: '/page',
text: 'Internal Link',
external: false
}

export const ExternalLink = Template.bind({})
ExternalLink.args = {
url: 'https://www.put.poznan.pl',
text: 'External Link',
external: true
}
Loading