Skip to content

Commit b988ade

Browse files
author
Mark Jones
authored
feat(subheading): add subheading component (#828)
* feat(subheading) create subheading * based on Typography component * defaults to type level 3 * subheading level 1-6 maps to type level 3-8 * applied italics to component names in readme
1 parent 1f0f337 commit b988ade

File tree

14 files changed

+418
-0
lines changed

14 files changed

+418
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from "./flipper";
33
export * from "./heading";
44
export * from "./managed-classes";
55
export * from "./paragraph";
6+
export * from "./subheading";
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* The class name contract for the subheading component
3+
*/
4+
export interface ISubheadingClassNameContract {
5+
subheading: string;
6+
subheading_1: string;
7+
subheading_2: string;
8+
subheading_3: string;
9+
subheading_4: string;
10+
subheading_5: string;
11+
subheading_6: string;
12+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export { LabelExamples };
2828
import ParagraphExamples from "../src/paragraph/examples.data";
2929
export { ParagraphExamples };
3030

31+
import SubheadingExamples from "../src/subheading/examples.data";
32+
export { SubheadingExamples };
33+
3134
import ToggleExamples from "../src/toggle/examples.data";
3235
export { ToggleExamples };
3336

packages/fast-components-react-msft/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export { Image } ;
2323
import Label from "./label";
2424
export { Label } ;
2525

26+
import Subheading from "./subheading";
27+
export { Subheading };
28+
2629
import TextField from "./text-field";
2730
export { TextField };
2831

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Subheading
2+
Use various *subheading* sizes to create a clear hierarchy within your page. Subheadings are paired with the Heading component.
3+
4+
## Usage
5+
Use the appropriate numbered tag for the relative importance of each *subheading* compared to other *subheadings* on the page. Subheadings should be descriptive summaries of the content below them. Choose a *subheading* level that best organizes your page content. Then choose the *subheading* tag and level to meet your design needs. For example, an `<h2>` element does not absolutely require level 2, it could be any of the other levels as well.
6+
7+
## Style guide
8+
Subheadings are a great way to break up your writing. They improve the layout of a page and draw attention to important points.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`generate snapshots Subheading: 0 1`] = `
4+
<h3
5+
className="typography_3-0-1-31 subheading-0-1-22 subheading_1-0-1-23"
6+
>
7+
Subheading test string
8+
</h3>
9+
`;
10+
11+
exports[`generate snapshots Subheading: 1 1`] = `
12+
<h1
13+
className="typography_3-0-1-47 subheading-0-1-38 subheading_1-0-1-39"
14+
data-sketch-symbol="Subheading 1"
15+
>
16+
Subheading test string
17+
</h1>
18+
`;
19+
20+
exports[`generate snapshots Subheading: 2 1`] = `
21+
<h1
22+
className="typography_3-0-1-63 subheading-0-1-54 subheading_1-0-1-55"
23+
data-sketch-symbol="Subheading 1"
24+
>
25+
Subheading test string
26+
</h1>
27+
`;
28+
29+
exports[`generate snapshots Subheading: 3 1`] = `
30+
<h2
31+
className="typography_4-0-1-80 subheading-0-1-70 subheading_2-0-1-72"
32+
data-sketch-symbol="Subheading 2"
33+
>
34+
Subheading test string
35+
</h2>
36+
`;
37+
38+
exports[`generate snapshots Subheading: 4 1`] = `
39+
<h3
40+
className="typography_5-0-1-97 subheading-0-1-86 subheading_3-0-1-89"
41+
data-sketch-symbol="Subheading 3"
42+
>
43+
Subheading test string
44+
</h3>
45+
`;
46+
47+
exports[`generate snapshots Subheading: 5 1`] = `
48+
<h4
49+
className="typography_6-0-1-114 subheading-0-1-102 subheading_4-0-1-106"
50+
data-sketch-symbol="Subheading 4"
51+
>
52+
Subheading test string
53+
</h4>
54+
`;
55+
56+
exports[`generate snapshots Subheading: 6 1`] = `
57+
<h5
58+
className="typography_7-0-1-131 subheading-0-1-118 subheading_5-0-1-123"
59+
data-sketch-symbol="Subheading 5"
60+
>
61+
Subheading test string
62+
</h5>
63+
`;
64+
65+
exports[`generate snapshots Subheading: 7 1`] = `
66+
<h6
67+
className="typography_8-0-1-148 subheading-0-1-134 subheading_6-0-1-140"
68+
data-sketch-symbol="Subheading 6"
69+
>
70+
Subheading test string
71+
</h6>
72+
`;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import * as React from "react";
2+
import { IComponentFactoryExample } from "@microsoft/fast-development-site-react";
3+
import Subheading from "./index";
4+
import {
5+
ISubheadingHandledProps,
6+
ISubheadingUnhandledProps,
7+
SubheadingLevel,
8+
SubheadingTag
9+
} from "./subheading.props";
10+
import Schema from "./subheading.schema.json";
11+
import Documentation from "./.tmp/documentation";
12+
13+
const testString: string = "Subheading test string";
14+
15+
export default {
16+
name: "Subheading",
17+
component: Subheading,
18+
schema: Schema as any,
19+
documentation: <Documentation />,
20+
detailData: {
21+
children: "Subheading"
22+
},
23+
data: [
24+
{
25+
children: testString
26+
},
27+
{
28+
tag: SubheadingTag.h1,
29+
children: testString,
30+
"data-sketch-symbol": "Subheading 1"
31+
},
32+
{
33+
tag: SubheadingTag.h1,
34+
level: SubheadingLevel._1,
35+
children: testString,
36+
"data-sketch-symbol": "Subheading 1"
37+
},
38+
{
39+
tag: SubheadingTag.h2,
40+
level: SubheadingLevel._2,
41+
children: testString,
42+
"data-sketch-symbol" : "Subheading 2"
43+
},
44+
{
45+
tag: SubheadingTag.h3,
46+
level: SubheadingLevel._3,
47+
children: testString,
48+
"data-sketch-symbol": "Subheading 3"
49+
},
50+
{
51+
tag: SubheadingTag.h4,
52+
level: SubheadingLevel._4,
53+
children: testString,
54+
"data-sketch-symbol": "Subheading 4"
55+
},
56+
{
57+
tag: SubheadingTag.h5,
58+
level: SubheadingLevel._5,
59+
children: testString,
60+
"data-sketch-symbol": "Subheading 5"
61+
},
62+
{
63+
tag: SubheadingTag.h6,
64+
level: SubheadingLevel._6,
65+
children: testString,
66+
"data-sketch-symbol": "Subheading 6"
67+
}
68+
]
69+
} as IComponentFactoryExample<ISubheadingHandledProps>;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from "react";
2+
import { IFoundationProps } from "@microsoft/fast-components-react-base";
3+
import Subheading, {
4+
ISubheadingHandledProps,
5+
ISubheadingUnhandledProps,
6+
SubheadingLevel,
7+
SubheadingTag
8+
} from "./subheading";
9+
import manageJss, { IJSSManagerProps } from "@microsoft/fast-jss-manager-react";
10+
import { IDesignSystem, SubheadingStyles } from "@microsoft/fast-components-styles-msft";
11+
12+
export default manageJss(SubheadingStyles)(Subheading);
13+
export * from "./subheading";
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as React from "react";
2+
import { IManagedClasses, ISubheadingClassNameContract } from "@microsoft/fast-components-class-name-contracts-msft";
3+
4+
export enum SubheadingLevel {
5+
_1 = 1,
6+
_2 = 2,
7+
_3 = 3,
8+
_4 = 4,
9+
_5 = 5,
10+
_6 = 6
11+
}
12+
13+
export enum SubheadingTag {
14+
h1 = "h1",
15+
h2 = "h2",
16+
h3 = "h3",
17+
h4 = "h4",
18+
h5 = "h5",
19+
h6 = "h6",
20+
p = "p"
21+
}
22+
23+
export interface ISubheadingHandledProps {
24+
25+
/**
26+
* The subheading content
27+
*/
28+
children?: React.ReactNode | React.ReactNode[];
29+
30+
/**
31+
* The subheading level used to map to typographic level
32+
*/
33+
level?: SubheadingLevel;
34+
35+
/**
36+
* The subheading tag used to create the underlying html element
37+
*/
38+
tag?: SubheadingTag;
39+
}
40+
41+
export interface ISubheadingUnhandledProps extends React.HTMLAttributes<HTMLHeadingElement | HTMLParagraphElement> {}
42+
export interface ISubheadingManagedClasses extends IManagedClasses<ISubheadingClassNameContract> {}
43+
export type SubheadingProps = ISubheadingHandledProps & ISubheadingUnhandledProps & ISubheadingManagedClasses;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"$schema": "http://json.schema.org/schema#",
3+
"title": "Subheading",
4+
"description": "A Subheading component's schema definition",
5+
"type": "object",
6+
"id": "Subheading",
7+
"children": true,
8+
"properties": {
9+
"tag": {
10+
"title": "HTML Tag",
11+
"type": "string",
12+
"enum": [
13+
"h1",
14+
"h2",
15+
"h3",
16+
"h4",
17+
"h5",
18+
"h6",
19+
"p"
20+
],
21+
"default": "h3"
22+
},
23+
"level": {
24+
"title": "Level",
25+
"type": "number",
26+
"enum": [
27+
1,
28+
2,
29+
3,
30+
4,
31+
5,
32+
6
33+
],
34+
"default": 1
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)