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

feat: Link Component #161 #309

Merged
merged 13 commits into from
Jul 15, 2020
Merged

feat: Link Component #161 #309

merged 13 commits into from
Jul 15, 2020

Conversation

ahobson
Copy link
Contributor

@ahobson ahobson commented Jul 7, 2020

Summary

Adds new Link component. Includes handling for asCustom prop.

Related Issues or PRs

relates to #161

How To Test

  • check new Link examples on Storybook

@haworku haworku mentioned this pull request Jul 7, 2020
@haworku haworku changed the title [WIP] link component with createElement feat: Link Component #161 Jul 9, 2020

type LinkProps = {
href: string
children: React.ReactNode
Copy link
Contributor

Choose a reason for hiding this comment

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

Added these back. Trying to follow the pattern of requiring props that are fundamental to the element.

Without these props <Link className="usa-button" variant="unstyled" /> is valid code. It compiles without warning ... and a regular anchor tag in our app would warn about this for missing href and children (since we use jsx-a11y to check valid anchor tags).

)
}

export function Link<FCProps = LinkProps>(
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we still need overloads to get accurate intellisense and type suggestions. What I notice is right now when the asCustom is not present and Link has invalid props, it only warns about not including asCustom, maybe because it has the broadest types. It doesn't warn for anchor tag.

Here's what an overload before line 46 could look (I think):

// Overloads
export function Link<T>(asCustomProps: AsCustomProps<T>): React.ReactElement
export function Link(linkProps: LinkProps): React.ReactElement

Lmk if you want to pair on this or if I'm off base.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for this suggestion. I'll have to look into this. I think I will have time on Friday

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! I think I've simplified the type signatures and added the overloads. It seems to do what we expect in VSCode now.

Copy link
Contributor

@haworku haworku left a comment

Choose a reason for hiding this comment

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

LGTM - made a couple comments more for documentation reasons.

I would still love to see us get the typescript intellisense actually working. This could be a model for other components in the future of how to use these flexible types but still have decent type safety.

But if it feels to others like overloads aren't a good idea -- let's set this aside for now and move on! Thanks for figuring out the generic types at least that's a win!

@ahobson ahobson requested a review from haworku July 10, 2020 19:14
suzubara
suzubara previously approved these changes Jul 13, 2020
Copy link
Contributor

@suzubara suzubara left a comment

Choose a reason for hiding this comment

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

the amount of code here does not reflect all of the time and thoughtfulness that went into this component! 💯 I am real excited about this one

/*
* TODO: sort out how to test visited links in storybook
*
* export const Visited = (): React.ReactElement => (
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the USWDS source (https://designsystem.digital.gov/components/typography/#links) I think they just added the usa-color-text-visited class to their docs theme for demonstration purposes. We probably could do the same in a Storybook-only CSS file (these can be added in ./storybook):

.usa-color-text-visited {
  color: color($theme-link-visited-color);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

we may also want to do something similar to the Default story so that it never gets the :visited style applied. IMO adding CSS to Storybook to enforce the intended styles for demonstration purposes is a 💯 valid thing to do.

Copy link
Contributor

@haworku haworku Jul 13, 2020

Choose a reason for hiding this comment

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

@suzubara is 813c393 workable for this??

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah that looks great!


export const StyledAsButton = (): React.ReactElement => (
<p>
<Link className="usa-button" variant="unstyled" href={'#'}>
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion for future iteration: I have a feeling the usa-button and all of its variations will be a common use-case for Link components, so adding the possible button style/className props to the Link component might be a good idea.

@haworku haworku changed the base branch from develop to main July 13, 2020 20:05
@haworku haworku dismissed suzubara’s stale review July 13, 2020 20:05

The base branch was changed.

@haworku haworku requested a review from suzubara July 14, 2020 17:00
@haworku haworku merged commit 2879bec into main Jul 15, 2020
@haworku haworku mentioned this pull request Jul 15, 2020
@haworku haworku deleted the adh-link-component-ideas branch July 15, 2020 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants