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: add hypertext component #210

Merged
merged 27 commits into from
Apr 13, 2018
Merged

feat: add hypertext component #210

merged 27 commits into from
Apr 13, 2018

Conversation

marjonlynch
Copy link
Contributor

Adding hypertext component based on the existing button component.

@@ -0,0 +1,14 @@
## Best practices
Use *hyperlink* when you need to navigate the user to more information about the text that was selected. *Hyperlinks* are best used for tertiary actions outside the main work flow.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hypertext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it, thanks

Use *hypertext* when you need to navigate the user to more information about the text that was selected. *Hypertexts* are best used for tertiary actions outside the main work flow.

### Usage guidance
*Hypertexts* may appear as standalone elements, on a line by themselves, or inline elements, in the middle of regular text. Use inline *hypertext* within the context of a sentence or a paragraph. Within a paragraph, *hypertext* should inherit the same formatting as the neighboring text as far as font size and font weight. Inline links will appear underlined.
Copy link
Member

Choose a reason for hiding this comment

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

I think we'll want to change our guidance to use these inline only

@@ -0,0 +1,23 @@
import * as React from "react";

/**
Copy link
Member

Choose a reason for hiding this comment

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

we can pull this enum as we aren't supporting non-anchor elements and this isn't configurable


export interface IHypertextProps {

id?: string;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this needs to be a first class prop for this component. I think we can pull this


id?: string;

text?: string;
Copy link
Member

Choose a reason for hiding this comment

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

Since we're passing children here, text is unnecessary unless we are going to draw a clear distinction


href?: string;

ariaLabel?: string;
Copy link
Member

Choose a reason for hiding this comment

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

based on our conversation yesterday with Mat, I think this is the exception here and likely wouldn't expect this as a first-class prop

}

export default Hypertext;
export {IHypertextProps, IHypertextClassNameContract, HypertextHTMLTags};
Copy link
Member

Choose a reason for hiding this comment

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

you can pull this as it won't exist

};

protected defaultProps: IHypertextProps = {
ariaLabel: void(0),
Copy link
Member

Choose a reason for hiding this comment

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

looks like there are no default props. These would go within handled I believe.

import Hypertext from "./hypertext";

export default Hypertext;
export * from "./hypertext";
Copy link
Member

Choose a reason for hiding this comment

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

I think we need a newline here

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we saying that we should have new lines before export statements? If so, should this be a new rule on tslint package?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I sort of liked grouping by component name.

Copy link
Member

Choose a reason for hiding this comment

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

There should be a .ts check for newline at the end of the file. I'm trying to hook up ordering alphabetically in tslint for these import/exports.

let attributes = {};

if (this.props.href) {
attributes['href'] = this.props.href;
Copy link
Member

Choose a reason for hiding this comment

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

these should be double quotes

import {ComponentStyles} from "@microsoft/fast-jss-manager";
import {IHypertextClassNameContract} from "@microsoft/fast-components-class-name-contracts";

const styles: ComponentStyles<IHypertextClassNameContract, IDesignSystem> = {
Copy link
Member

Choose a reason for hiding this comment

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

let me know if you, kham, and Jeff want to jump on a session to do one of these.

@awentzel awentzel changed the title Adding hypertext component, minimal styles and md file feat: add hypertext component Apr 5, 2018
@awentzel awentzel added feature A new feature type : feat labels Apr 5, 2018
import Hypertext from "./hypertext";

export default Hypertext;
export * from "./hypertext";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we saying that we should have new lines before export statements? If so, should this be a new rule on tslint package?

import Hypertext from "./hypertext";

export default Hypertext;
export * from "./hypertext";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I sort of liked grouping by component name.

@@ -0,0 +1,16 @@
import {ICategoryItemProps} from "@microsoft/fast-development-site-react";
import {IGenericExample} from "../examples";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you'll want to do a rebase and replace IGenericExample with ISnapshots.... Little bit of a refactor, unfortunately.

nicholasrice
nicholasrice previously approved these changes Apr 5, 2018
@@ -0,0 +1,10 @@
import * as React from "react";

export interface IHypertextProps {
Copy link
Contributor

Choose a reason for hiding this comment

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

We've changed the naming convention slightly for props objects - can you align to button.props.ts?

managedClasses: void 0,
};

private generateAttributes() {
Copy link
Contributor

@nicholasrice nicholasrice Apr 5, 2018

Choose a reason for hiding this comment

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

You'll see this approach to applying attributes a lot in the previous repo - the reason we did it this way is we didn't have accurate typescript typings for components.

In this project, we made sure to set things up more accurately - you can just add href={this.props.href} in the render method itself and remove this method - that will reduce the code clutter of having an extra method

Copy link
Member

Choose a reason for hiding this comment

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

@nicholasrice question - if a disabled href is just an anchor without an href, do we want to check for it like this rather than passing straight into the render function?

}


export interface IHypertextUnhandledProps extends React.AllHTMLAttributes<HTMLElement> {}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we want all html attributes here as this is just an anchor. We likely want:
React.HTMLAnchorAttributes<HTMLAnchorElement>

import {IHypertextClassNameContract, IManagedClasses} from "@microsoft/fast-components-class-name-contracts";

/* tslint:disable-next-line */
class Hypertext extends Foundation<IHypertextHandledProps & IManagedClasses<IHypertextClassNameContract>, React.AllHTMLAttributes<HTMLAnchorElement>, {}> {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of AllHTMLAttributes we'll want HTMLAnchorAttributes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also done? probably

/* tslint:disable-next-line */
class Hypertext extends Foundation<IHypertextHandledProps & IManagedClasses<IHypertextClassNameContract>, React.AllHTMLAttributes<HTMLAnchorElement>, {}> {
protected handledProps: HandledProps<IHypertextHandledProps & IManagedClasses<IHypertextClassNameContract>> = {
managedClasses: void 0,
Copy link
Member

Choose a reason for hiding this comment

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

We'll need to enumerate any of the props here that are handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think, done and done

const HREF_INDEX = "href";

if (this.props.href) {
attributes[HREF_INDEX] = this.props.href;
Copy link
Member

Choose a reason for hiding this comment

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

does dot notation not work here? I know that you're likely getting an error, but if we can access via dot notation, let's do that instead.

Copy link
Collaborator

@awentzel awentzel left a comment

Choose a reason for hiding this comment

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

You'll also want to resolve your Travis CI build errors (lint errors). https://travis-ci.org/Microsoft/fast-dna/builds/363248660?utm_source=github_status&utm_medium=notification

@marjonlynch marjonlynch force-pushed the users/marjon/add-hyperlink branch from 6bb7bf6 to 7543ec5 Compare April 6, 2018 21:09
@janechu
Copy link
Collaborator

janechu commented Apr 7, 2018

You'll want to check the body of the PR message and use something like "Closes #181" this will automatically link your PR to the open ticket and close it when the PR is merged in.

return super.generateClassNames(this.props.managedClasses.hypertext);
}

private generateAttributes(): {} {
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 should remove this function. Because we're not manipulating this data, it can be safely applied with the this.unhandledProps() call.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

class Hypertext extends Foundation<IHypertextHandledProps & IManagedClasses<IHypertextClassNameContract>, React.AnchorHTMLAttributes<HTMLAnchorElement>, {}> {
protected handledProps: HandledProps<IHypertextHandledProps & IManagedClasses<IHypertextClassNameContract>> = {
managedClasses: void 0,
href: void 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

We really don't need to enumerate href as a prop either - it is included by the React.AnchorHTMLAttributes interface accurately for this component

Copy link
Contributor

@nalogiudice nalogiudice left a comment

Choose a reason for hiding this comment

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

A few JSS nits

const styles: ComponentStyles<IHypertextClassNameContract, IDesignSystem> = {
hypertext: {
borderBottom: (config: IDesignSystem): string => {
return `1px solid ${config.brandColor}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

should use ${toPx(1)} here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

textDecoration: "none",
"&:hover, &:focus": {
borderBottom: (config: IDesignSystem): string => {
return `2px solid ${config.brandColor}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should use ${toPx(2)} here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and done

return super.generateClassNames(this.props.managedClasses.hypertext);
}

private generateAttributes(): {} {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@marjonlynch marjonlynch force-pushed the users/marjon/add-hyperlink branch from 578618e to 766e84b Compare April 13, 2018 18:55
import { IHypertextClassNameContract, IManagedClasses } from "@microsoft/fast-components-class-name-contracts";

export interface IHypertextHandledProps {

Copy link
Member

Choose a reason for hiding this comment

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

can you add comments for the prop definitions

import * as React from "react";

export default {
name: "hypertext",
Copy link
Member

Choose a reason for hiding this comment

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

can you add an example that does not include an href?

@@ -4,6 +4,9 @@
import ButtonStyles from "./button";
export { ButtonStyles };

import HypertextStyles from "./hypertext";
export {HypertextStyles};
Copy link
Member

Choose a reason for hiding this comment

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

I know it's not barking from a tslint standpoint, but can you follow the convention of including spaces on export statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, I knew about that just missed this one. Doh!

* Generates class names
*/
protected generateClassNames(): string {
return super.generateClassNames(this.props.managedClasses.hypertext);
Copy link
Member

Choose a reason for hiding this comment

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

this is new within the last day, but we'll want to use lodash's "get" method to access here. It will check that this prop actually exists.

@import { get } from "lodash-es";
super.generateClassNames(get(this.props, "managedClasses.hypertext"));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it in, learning about lodash today

@@ -1,6 +1,7 @@
export * from "./button";
export * from "./divider";
export * from "./image";
export * from "./hypertext";
Copy link
Member

@chrisdholt chrisdholt Apr 13, 2018

Choose a reason for hiding this comment

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

I mean - we can correct this later if need be, but technically "h" would be before "i" :)

@@ -12,3 +12,6 @@ export { ToggleExamples };

import TypographyExamples from "../src/typography/examples.data";
export { TypographyExamples };

import HypertextExamples from "../src/hypertext/examples.data";
export {HypertextExamples};
Copy link
Member

Choose a reason for hiding this comment

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

nit: spacing :)

@marjonlynch marjonlynch force-pushed the users/marjon/add-hyperlink branch from 17f9dd8 to c5a16c6 Compare April 13, 2018 20:25
@marjonlynch marjonlynch force-pushed the users/marjon/add-hyperlink branch from c5a16c6 to 2159271 Compare April 13, 2018 21:36
@marjonlynch marjonlynch dismissed stale reviews from chrisdholt, nalogiudice, nicholasrice, and awentzel April 13, 2018 21:39

all comments addressed


export interface IHypertextHandledProps {

href?: string;
Copy link
Member

Choose a reason for hiding this comment

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

@marjonlynch - maybe it isn't showing the changes...but did you add comments here?

@chrisdholt chrisdholt merged commit 9e363ff into master Apr 13, 2018
@marjonlynch marjonlynch deleted the users/marjon/add-hyperlink branch April 16, 2018 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants