From 954fe36ee6b5a96cdaa402f8a8aa7e5b5ccb4f6f Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Fri, 24 Feb 2023 10:31:58 -0600 Subject: [PATCH 1/3] make the label required on a link. however, it can be an empty string if the desire is to only show an icon --- src/components/Link/Link.jsx | 37 +++++++++++++++++----------- src/components/Link/Link.stories.jsx | 13 +++++++++- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/components/Link/Link.jsx b/src/components/Link/Link.jsx index 0b49f2c9..76bdeb92 100644 --- a/src/components/Link/Link.jsx +++ b/src/components/Link/Link.jsx @@ -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 }) => ( - - {icon && ( - 0 && 'me-2'}`} /> - )} - {label} - -) +const Link = ({ addClass, href, icon, label, style, ...props }) => { + return ( + + {icon && ( + + )} + {label && label} + + ) +} +/** + * 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. +*/ 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: {}, } diff --git a/src/components/Link/Link.stories.jsx b/src/components/Link/Link.stories.jsx index 4a4078b0..1e152bb2 100644 --- a/src/components/Link/Link.stories.jsx +++ b/src/components/Link/Link.stories.jsx @@ -21,10 +21,21 @@ Default.args = { export const Alternate = Template.bind({}) Alternate.args = { 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: { + textDecoration: 'none', + color: '#AS8908', + }, } From b9f46219ae694ec0ca7cb656f79b08ba971028ad Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Fri, 24 Feb 2023 10:32:31 -0600 Subject: [PATCH 2/3] update the link in the FilesTable component to have required props --- src/components/FilesTable/FilesTable.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/FilesTable/FilesTable.jsx b/src/components/FilesTable/FilesTable.jsx index 2c5c55b3..874e3bd0 100644 --- a/src/components/FilesTable/FilesTable.jsx +++ b/src/components/FilesTable/FilesTable.jsx @@ -34,6 +34,7 @@ const FilesTable = ({ addClass, files }) => { From 00ba8aad3743a680327b782c65e151b142da988e Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Fri, 24 Feb 2023 10:37:51 -0600 Subject: [PATCH 3/3] add href value --- src/components/Link/Link.stories.jsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/components/Link/Link.stories.jsx b/src/components/Link/Link.stories.jsx index 1e152bb2..182070da 100644 --- a/src/components/Link/Link.stories.jsx +++ b/src/components/Link/Link.stories.jsx @@ -13,14 +13,14 @@ const Template = (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: { @@ -31,11 +31,8 @@ Alternate.args = { export const NoLabel = Template.bind({}) NoLabel.args = { - href: '', + href: '/', icon: 'fa-download', label: '', - style: { - textDecoration: 'none', - color: '#AS8908', - }, + style: {}, }