Skip to content

Commit 9e363ff

Browse files
Mark Joneschrisdholt
authored andcommitted
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
1 parent a4c54c0 commit 9e363ff

File tree

17 files changed

+194
-2
lines changed

17 files changed

+194
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* The classname contract for the hypertext component
3+
*/
4+
export interface IHypertextClassNameContract {
5+
hypertext: string;
6+
}

packages/fast-components-class-name-contracts-base/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from "./button";
22
export * from "./divider";
3+
export * from "./hypertext";
34
export * from "./image";
45
export * from "./managed-classes";
56
export * from "./toggle";

packages/fast-components-react-base/app/examples.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import DividerExamples from "../src/divider/examples.data";
55
export { DividerExamples };
66

77
import ImageExamples from "../src/image/examples.data";
8-
export {ImageExamples};
8+
export { ImageExamples };
99

1010
import ToggleExamples from "../src/toggle/examples.data";
1111
export { ToggleExamples };
1212

1313
import TypographyExamples from "../src/typography/examples.data";
1414
export { TypographyExamples };
15+
16+
import HypertextExamples from "../src/hypertext/examples.data";
17+
export { HypertextExamples };
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Best practices
2+
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.
3+
4+
### Usage guidance
5+
*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.
6+
7+
### Style guidance
8+
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.
9+
10+
### Behavioral guidance
11+
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.
12+
13+
## Accessibility
14+
A *hypertext* is required to have two points of visual distinction when *inline*. The underline and visual state colors are both required for accessibility.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`hypertext hypertext: 0 1`] = `
4+
<a
5+
className="hypertext"
6+
href="https://msdn.microsoft.com/en-us/"
7+
>
8+
MSDN
9+
</a>
10+
`;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { ICategoryItemProps } from "@microsoft/fast-development-site-react";
2+
import { ISnapshotTestSuite } from "@microsoft/fast-jest-snapshots-react";
3+
import { IManagedClasses } from "@microsoft/fast-components-class-name-contracts-base";
4+
import Hypertext, { IHypertextHandledProps, IHypertextManagedClasses, IHypertextUnhandledProps } from "./hypertext";
5+
import * as React from "react";
6+
7+
const examples: ISnapshotTestSuite<IHypertextHandledProps & IHypertextManagedClasses> = {
8+
name: "hypertext",
9+
component: Hypertext,
10+
data: [
11+
{
12+
managedClasses: {
13+
hypertext: "hypertext"
14+
},
15+
href: "https://msdn.microsoft.com/en-us/",
16+
children: "MSDN"
17+
}
18+
]
19+
};
20+
21+
export default examples;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from "react";
2+
import { IHypertextClassNameContract, IManagedClasses } from "@microsoft/fast-components-class-name-contracts-base";
3+
4+
export interface IHypertextHandledProps {
5+
6+
/**
7+
* The HTML src attribute for the href attribute.
8+
*/
9+
href?: string;
10+
11+
/**
12+
* The option to set the content wrapped by hypertext.
13+
*/
14+
children?: React.ReactNode | React.ReactNode[];
15+
}
16+
17+
export interface IHypertextUnhandledProps extends React.AllHTMLAttributes<HTMLElement> {}
18+
export interface IHypertextManagedClasses extends IManagedClasses<IHypertextClassNameContract> {}
19+
export type HypertextProps = IHypertextHandledProps & IHypertextUnhandledProps & IHypertextManagedClasses;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import examples from "./examples.data";
2+
import { generateSnapshots } from "@microsoft/fast-jest-snapshots-react";
3+
4+
describe("hypertext", (): void => {
5+
generateSnapshots(examples);
6+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as React from "react";
2+
import * as ReactDOM from "react-dom";
3+
import Foundation, { HandledProps } from "../foundation";
4+
import { IHypertextHandledProps, IHypertextManagedClasses, IHypertextUnhandledProps } from "./hypertext.props";
5+
import { IHypertextClassNameContract, IManagedClasses } from "@microsoft/fast-components-class-name-contracts-base";
6+
import { get } from "lodash-es";
7+
8+
/* tslint:disable-next-line */
9+
class Hypertext extends Foundation<IHypertextHandledProps & IManagedClasses<IHypertextClassNameContract>, React.AnchorHTMLAttributes<HTMLAnchorElement>, {}> {
10+
protected handledProps: HandledProps<IHypertextHandledProps & IManagedClasses<IHypertextClassNameContract>> = {
11+
managedClasses: void 0,
12+
children: void 0
13+
};
14+
15+
/**
16+
* Renders the component
17+
*/
18+
public render(): React.ReactElement<HTMLAnchorElement> {
19+
return (
20+
<a
21+
{...this.unhandledProps()}
22+
className={this.generateClassNames()}
23+
>
24+
{this.props.children}
25+
</a>
26+
);
27+
}
28+
29+
/**
30+
* Generates class names
31+
*/
32+
protected generateClassNames(): string {
33+
return super.generateClassNames(get(this.props, "managedClasses.hypertext"));
34+
}
35+
}
36+
37+
export default Hypertext;
38+
export * from "./hypertext.props";
39+
export { IHypertextClassNameContract };
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Hypertext from "./hypertext";
2+
3+
export default Hypertext;
4+
export * from "./hypertext";

0 commit comments

Comments
 (0)