-
Notifications
You must be signed in to change notification settings - Fork 601
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
Conversation
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hypertext
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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"; | |||
|
|||
/** |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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}; |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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> = { |
There was a problem hiding this comment.
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.
import Hypertext from "./hypertext"; | ||
|
||
export default Hypertext; | ||
export * from "./hypertext"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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.
@@ -0,0 +1,10 @@ | |||
import * as React from "react"; | |||
|
|||
export interface IHypertextProps { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
d5fc108
to
735f70f
Compare
} | ||
|
||
|
||
export interface IHypertextUnhandledProps extends React.AllHTMLAttributes<HTMLElement> {} |
There was a problem hiding this comment.
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>, {}> { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
6bb7bf6
to
7543ec5
Compare
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(): {} { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this 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}`; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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}`; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(): {} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
578618e
to
766e84b
Compare
import { IHypertextClassNameContract, IManagedClasses } from "@microsoft/fast-components-class-name-contracts"; | ||
|
||
export interface IHypertextHandledProps { | ||
|
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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}; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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"));
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: spacing :)
17f9dd8
to
c5a16c6
Compare
c5a16c6
to
2159271
Compare
all comments addressed
|
||
export interface IHypertextHandledProps { | ||
|
||
href?: string; |
There was a problem hiding this comment.
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?
Adding hypertext component based on the existing button component.