-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
TypographyPage.tsx
160 lines (154 loc) · 4.86 KB
/
TypographyPage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import * as React from 'react';
import { css } from 'office-ui-fabric-react';
import { IPageSectionProps, Markdown, Table, ITableRowProps, ITableColumnProps } from '@uifabric/example-app-base/lib/index2';
import { IStylesPageProps, StylesAreaPage } from '../StylesAreaPage';
import { TypographyPageProps, sizeUsage, weightUsage } from './TypographyPage.doc';
import * as styles from './TypographyPage.module.scss';
import { Platforms } from '../../../interfaces/Platforms';
const typeSizes = require('office-ui-fabric-core/src/data/type-sizes.json');
const typeWeights = require('office-ui-fabric-core/src/data/type-weights.json');
const baseUrl = 'https://github.com/OfficeDev/office-ui-fabric-react/tree/master/apps/fabric-website/src/pages/Styles/TypographyPage/docs';
export const TypographyPage: React.StatelessComponent<IStylesPageProps> = props => {
const { platform } = props;
return <StylesAreaPage {...props} {...TypographyPageProps[platform]} otherSections={_otherSections(platform) as IPageSectionProps[]} />;
};
function _otherSections(platform: Platforms): IPageSectionProps<Platforms>[] {
switch (platform) {
case 'web':
return [
{
sectionName: 'Weights',
editUrl: `${baseUrl}/web/TypographyWeights.md`,
content: (
<>
<Markdown>
{require('!raw-loader!@uifabric/fabric-website/src/pages/Styles/TypographyPage/docs/web/TypographyWeights.md') as string}
</Markdown>
{_renderWeightsTable(typeWeights)}
</>
)
},
{
sectionName: 'Sizes',
editUrl: `${baseUrl}/web/TypographySizes.md`,
content: (
<>
<Markdown>
{require('!raw-loader!@uifabric/fabric-website/src/pages/Styles/TypographyPage/docs/web/TypographySizes.md') as string}
</Markdown>
{_renderSizesTable(typeSizes)}
</>
)
},
{
sectionName: 'Implementation',
editUrl: `${baseUrl}/web/TypographyImplementation.md`,
content: (
<Markdown>
{
require('!raw-loader!@uifabric/fabric-website/src/pages/Styles/TypographyPage/docs/web/TypographyImplementation.md') as string
}
</Markdown>
)
}
];
}
}
function _renderWeightsTable(weights: ITableRowProps[]) {
return (
<Table
columns={[
{
title: 'Weight',
percentWidth: 10
},
{
title: 'Example',
data: 'example'
},
{
title: 'Usage',
percentWidth: 20
},
{
title: 'Core class',
percentWidth: 15
},
{
title: 'React variable',
percentWidth: 20,
overflowX: 'auto'
}
]}
rows={weights}
// tslint:disable-next-line jsx-no-lambda
formatter={(column, row) => {
const content = row[column.data];
switch (column.title) {
case 'Weight':
return `${row.name} (${row.weight})`;
case 'Core class':
return `ms-fontWeight-${row.name.toLowerCase()}`;
case 'React variable':
return `FontWeights.${row.name.toLowerCase()}`;
case 'Example':
return <span className={`ms-fontWeight-${row.name.toLowerCase()}`}>The quick brown fox jumps over the lazy dog</span>;
case 'Usage':
return weightUsage.filter(x => x.name === row.name)[0].usage;
default:
return content;
}
}}
/>
);
}
function _renderSizesTable(sizes: ITableColumnProps[]) {
return (
<Table
columns={[
{
title: 'Size',
data: 'size',
percentWidth: 10
},
{
title: 'Example',
data: 'example',
overflowX: 'auto'
},
{
title: 'Usage',
percentWidth: 20
},
{
title: 'Core class',
percentWidth: 15
},
{
title: 'React variable',
percentWidth: 20,
overflowX: 'auto'
}
]}
rows={sizes}
// tslint:disable-next-line jsx-no-lambda
formatter={(column, row) => {
const content = row[column.data];
switch (column.title) {
case 'Core class':
return `ms-fontSize-${row.size}`;
case 'React variable':
return `FontSizes.size${row.size}`;
case 'Size':
return `${row.size}px`;
case 'Example':
return <div className={css(styles.example, `ms-fontSize-${row.size}`)}>The quick brown fox jumps over the lazy dog</div>;
case 'Usage':
return sizeUsage.filter(x => x.size === row.size)[0].usage;
default:
return content;
}
}}
/>
);
}