-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add hypertext component (#210)
* renamed all to hypertext from hyperlink * renamed hyperlink to hypertext * microsoft appropriate test link used * added hypertext references in react-msft and styles-msft * added md file for hypertext * missed hyperlink reference, and updated md doc to use hypertext * added more style to hypertext, fixed some possible build issues * chris helped added a couple good style things, fixed example text * addressing PR comments * rebased * changes to account for testing examples update * applied more PR comments * removed the text property on hypertext, will only use children * added newline to file so it builds? * updates to fix server build rules * more tslint errors fixed * more tslint errors fixed * updated snapshots * refactoring based on PR comments * merge issue resolved * tslint stuff again * PR comments applied * rebased again * PR comments applied * spacing on export fixed * added comments to handled props for hypertext * changes to accomodate contract interface update
- Loading branch information
1 parent
a4c54c0
commit 9e363ff
Showing
17 changed files
with
194 additions
and
2 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
packages/fast-components-class-name-contracts-base/src/hypertext/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* The classname contract for the hypertext component | ||
*/ | ||
export interface IHypertextClassNameContract { | ||
hypertext: string; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/fast-components-class-name-contracts-base/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## Best practices | ||
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 inline elements. 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. | ||
|
||
### Style guidance | ||
Two *hypertexts* can appear consecutively on separate lines of text and wrap. *Hypertext* text must be clear and unique. Multiple *hypertext* to same location should have identical link text. | ||
|
||
### Behavioral guidance | ||
If you need to initiate actions (e.g. download a file), consider using *action trigger* instead. For calls to action (e.g. "buy"), consider using *call to action*, and for the final action in a workflow (e.g. "save"), consider using *button*. Keep *hypertexts* to just a few words, 4-5 max, not entire sentences. Don't include the period if *hypertext* is at the end of a sentence. | ||
|
||
## Accessibility | ||
A *hypertext* is required to have two points of visual distinction when *inline*. The underline and visual state colors are both required for accessibility. |
10 changes: 10 additions & 0 deletions
10
packages/fast-components-react-base/src/hypertext/__snapshots__/hypertext.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`hypertext hypertext: 0 1`] = ` | ||
<a | ||
className="hypertext" | ||
href="https://msdn.microsoft.com/en-us/" | ||
> | ||
MSDN | ||
</a> | ||
`; |
21 changes: 21 additions & 0 deletions
21
packages/fast-components-react-base/src/hypertext/examples.data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ICategoryItemProps } from "@microsoft/fast-development-site-react"; | ||
import { ISnapshotTestSuite } from "@microsoft/fast-jest-snapshots-react"; | ||
import { IManagedClasses } from "@microsoft/fast-components-class-name-contracts-base"; | ||
import Hypertext, { IHypertextHandledProps, IHypertextManagedClasses, IHypertextUnhandledProps } from "./hypertext"; | ||
import * as React from "react"; | ||
|
||
const examples: ISnapshotTestSuite<IHypertextHandledProps & IHypertextManagedClasses> = { | ||
name: "hypertext", | ||
component: Hypertext, | ||
data: [ | ||
{ | ||
managedClasses: { | ||
hypertext: "hypertext" | ||
}, | ||
href: "https://msdn.microsoft.com/en-us/", | ||
children: "MSDN" | ||
} | ||
] | ||
}; | ||
|
||
export default examples; |
19 changes: 19 additions & 0 deletions
19
packages/fast-components-react-base/src/hypertext/hypertext.props.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as React from "react"; | ||
import { IHypertextClassNameContract, IManagedClasses } from "@microsoft/fast-components-class-name-contracts-base"; | ||
|
||
export interface IHypertextHandledProps { | ||
|
||
/** | ||
* The HTML src attribute for the href attribute. | ||
*/ | ||
href?: string; | ||
|
||
/** | ||
* The option to set the content wrapped by hypertext. | ||
*/ | ||
children?: React.ReactNode | React.ReactNode[]; | ||
} | ||
|
||
export interface IHypertextUnhandledProps extends React.AllHTMLAttributes<HTMLElement> {} | ||
export interface IHypertextManagedClasses extends IManagedClasses<IHypertextClassNameContract> {} | ||
export type HypertextProps = IHypertextHandledProps & IHypertextUnhandledProps & IHypertextManagedClasses; |
6 changes: 6 additions & 0 deletions
6
packages/fast-components-react-base/src/hypertext/hypertext.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import examples from "./examples.data"; | ||
import { generateSnapshots } from "@microsoft/fast-jest-snapshots-react"; | ||
|
||
describe("hypertext", (): void => { | ||
generateSnapshots(examples); | ||
}); |
39 changes: 39 additions & 0 deletions
39
packages/fast-components-react-base/src/hypertext/hypertext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as React from "react"; | ||
import * as ReactDOM from "react-dom"; | ||
import Foundation, { HandledProps } from "../foundation"; | ||
import { IHypertextHandledProps, IHypertextManagedClasses, IHypertextUnhandledProps } from "./hypertext.props"; | ||
import { IHypertextClassNameContract, IManagedClasses } from "@microsoft/fast-components-class-name-contracts-base"; | ||
import { get } from "lodash-es"; | ||
|
||
/* tslint:disable-next-line */ | ||
class Hypertext extends Foundation<IHypertextHandledProps & IManagedClasses<IHypertextClassNameContract>, React.AnchorHTMLAttributes<HTMLAnchorElement>, {}> { | ||
protected handledProps: HandledProps<IHypertextHandledProps & IManagedClasses<IHypertextClassNameContract>> = { | ||
managedClasses: void 0, | ||
children: void 0 | ||
}; | ||
|
||
/** | ||
* Renders the component | ||
*/ | ||
public render(): React.ReactElement<HTMLAnchorElement> { | ||
return ( | ||
<a | ||
{...this.unhandledProps()} | ||
className={this.generateClassNames()} | ||
> | ||
{this.props.children} | ||
</a> | ||
); | ||
} | ||
|
||
/** | ||
* Generates class names | ||
*/ | ||
protected generateClassNames(): string { | ||
return super.generateClassNames(get(this.props, "managedClasses.hypertext")); | ||
} | ||
} | ||
|
||
export default Hypertext; | ||
export * from "./hypertext.props"; | ||
export { IHypertextClassNameContract }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Hypertext from "./hypertext"; | ||
|
||
export default Hypertext; | ||
export * from "./hypertext"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/fast-components-react-msft/src/hypertext/examples.data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ICategoryItemProps } from "@microsoft/fast-development-site-react"; | ||
import { ISnapshotTestSuite } from "@microsoft/fast-jest-snapshots-react"; | ||
import { IManagedClasses } from "@microsoft/fast-jss-manager-react"; | ||
import Hypertext from "./index"; | ||
import { IHypertextHandledProps } from "@microsoft/fast-components-react-base"; | ||
import * as React from "react"; | ||
|
||
export default { | ||
name: "hypertext", | ||
component: Hypertext, | ||
data: [ | ||
{ | ||
href: "https://msdn.microsoft.com", | ||
children: "Hypertext" | ||
}, | ||
{ | ||
children: "Hypertext" | ||
} | ||
] | ||
} as ISnapshotTestSuite<IHypertextHandledProps>; |
12 changes: 12 additions & 0 deletions
12
packages/fast-components-react-msft/src/hypertext/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as React from "react"; | ||
import { | ||
Hypertext, | ||
IFoundationProps, | ||
IHypertextClassNameContract, | ||
IHypertextHandledProps, | ||
IHypertextUnhandledProps | ||
} from "@microsoft/fast-components-react-base"; | ||
import manageJss from "@microsoft/fast-jss-manager-react"; | ||
import { HypertextStyles } from "@microsoft/fast-components-styles-msft"; | ||
|
||
export default manageJss(HypertextStyles)(Hypertext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/fast-components-styles-msft/src/hypertext/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { IDesignSystem } from "../design-system"; | ||
import { ComponentStyles } from "@microsoft/fast-jss-manager"; | ||
import { IHypertextClassNameContract } from "@microsoft/fast-components-class-name-contracts-base"; | ||
import { toPx } from "../utilities/units"; | ||
|
||
const styles: ComponentStyles<IHypertextClassNameContract, IDesignSystem> = { | ||
hypertext: { | ||
borderBottom: (config: IDesignSystem): string => { | ||
return `${toPx(1)} solid ${config.brandColor}`; | ||
}, | ||
color: (config: IDesignSystem): string => { | ||
return config.brandColor; | ||
}, | ||
outline: toPx(0), | ||
textDecoration: "none", | ||
"&:hover, &:focus": { | ||
borderBottom: (config: IDesignSystem): string => { | ||
return `${toPx(2)} solid ${config.brandColor}`; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export default styles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters