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

165 link proptypes #170

Merged
merged 3 commits into from
Feb 24, 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
1 change: 1 addition & 0 deletions src/components/FilesTable/FilesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const FilesTable = ({ addClass, files }) => {
<td className='text-center'>
<Link
icon='fa-download'
label=''
href={href}
aria-label='download'
/>
Expand Down
37 changes: 22 additions & 15 deletions src/components/Link/Link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,39 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import PropTypes from 'prop-types'
import './link.css'

const Link = ({ addClass, href, icon, label, style, ...props }) => (
<a
href={href}
className={`link ${addClass}`}
style={style}
{...props}
>
{icon && (
<FontAwesomeIcon icon={icon} className={`small ${label.length > 0 && 'me-2'}`} />
)}
{label}
</a>
)
const Link = ({ addClass, href, icon, label, style, ...props }) => {
return (
<a
href={href}
className={`link ${addClass}`}
style={style}
{...props}
>
Comment on lines +7 to +13
Copy link
Member Author

Choose a reason for hiding this comment

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

the majority of this is indention.

{icon && (
<FontAwesomeIcon icon={icon} className={`small ${label.length && 'me-2'}`} />
)}
{label && label}
Copy link
Member Author

Choose a reason for hiding this comment

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

only show the label if it isn't an empty string.

</a>
)
}

/**
* there isn't an easy way to require either the icon OR the label. there are additional packages we could install that have the
* capability, but that would bloat the package unnecessarily. instead, we're requiring that the label be passed. the overwhelming
* majority of instances where a link is used, will want a label anyway. however, in the event a label isn't desired, passing the
* value as an empty string will satisfy prop types, while still only showing an icon.
Comment on lines +23 to +26
Copy link
Member Author

Choose a reason for hiding this comment

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

I tried this suggestion, but it felt like overkill.

*/
Link.propTypes = {
addClass: PropTypes.string,
href: PropTypes.string.isRequired,
icon: PropTypes.string,
label: PropTypes.string,
label: PropTypes.string.isRequired,
style: PropTypes.shape({}),
}

Link.defaultProps = {
addClass: '',
icon: '',
label: '',
style: {},
}

Expand Down
14 changes: 11 additions & 3 deletions src/components/Link/Link.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,26 @@ const Template = (args) => <Link {...args} />

export const Default = Template.bind({})
Default.args = {
href: '',
href: '/',
label: 'I am a link',
style: {},
}

export const Alternate = Template.bind({})
Alternate.args = {
href: '',
href: '/',
icon: 'fa-envelope',
label: 'No underline!',
style: {
textDecoration: 'none',
color: '#AB1289',
},
icon: 'fa-envelope',
}

export const NoLabel = Template.bind({})
NoLabel.args = {
href: '/',
icon: 'fa-download',
label: '',
style: {},
}