Skip to content

Commit ddd0ff0

Browse files
joebuonoJoe Buono
andauthored
docs(chore): Standard HTML attributes note (#2289)
* refactored to include MDN and htmlElement in each component's frontmatter * escape < and > * change MDN to mdnUrl for consistency with frontmatter naming * modify getFrontmatter to grab all frontmatter * fixed small bug * added error handling for fs.readFileSync * refactored getFrontmatter to handle error Co-authored-by: Joe Buono <[email protected]>
1 parent 34b1059 commit ddd0ff0

File tree

76 files changed

+172
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+172
-45
lines changed

docs/scripts/generate-props-tables.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import fs from 'fs';
22
import path from 'path';
33
import { globbyStream } from 'globby';
4-
import { getCatalog } from './util/getCatalog';
5-
import { getAllTypesData } from './util/getAllTypesData';
4+
import { getAllTypesData, getCatalog, getFrontmatter } from './util';
65
import type {
76
Catalog,
87
Category,
@@ -14,7 +13,6 @@ import { capitalizeString } from '@/utils/capitalizeString';
1413

1514
const catalog = getCatalog();
1615
const { allTypeFilesInterfaceData } = getAllTypesData();
17-
debugger;
1816

1917
createAllPropsTables();
2018

@@ -62,13 +60,15 @@ async function createAllPropsTables() {
6260

6361
if (!mainTableAndExpander) continue;
6462

63+
const { mdnUrl, htmlElement } = getFrontmatter(componentFilepath as string);
64+
6565
fs.writeFileSync(
6666
path.join(
6767
__dirname,
6868
'../../docs/src/pages/[platform]/components/',
6969
`./${componentPageName}/props-table.mdx`
7070
),
71-
Output(componentName, tableAndExpanders)
71+
Output(componentName, tableAndExpanders, mdnUrl, htmlElement)
7272
);
7373
console.log(`✅ ${componentPageName} Props Tables are updated.`);
7474
}
@@ -78,10 +78,7 @@ type CategoryProperty = { [key in Category]: Properties };
7878
type SortedPropertiesByCategory = { [key: string]: Properties }[];
7979
type PropertiesByCategory = Record<Category, Properties>;
8080

81-
/**
82-
* @todo After Marketing Launch 2022-06, to update the note under the Props Heading to specify the HTML element's name and MDN link. Ticket: https://app.asana.com/0/1201736086077838/1202477702049308/f
83-
*/
84-
function Output(displayName, tableAndExpanders) {
81+
function Output(displayName, tableAndExpanders, mdnUrl, htmlElement) {
8582
return `
8683
{/* DO NOT EDIT DIRECTLY */}
8784
{/* This file is autogenerated by "docs/scripts/generate-props-tables.ts" script. */}
@@ -92,7 +89,11 @@ ${tableAndExpanders.join('')}
9289
9390
See [Style Props](/react/theming/style-props) for all supported style and layout properties.
9491
95-
The ${displayName} component will accept any of the standard HTML attributes that a HTML element accepts. Standard element attributes can be found in the <Link href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element" isExternal={true}>MDN Documentation</Link>.
92+
${displayName} will also accept any of the standard HTML attributes that a <code>\\<${
93+
htmlElement || 'div'
94+
}\\></code> element accepts, which can be found in the <Link href="${
95+
mdnUrl || 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div'
96+
}" isExternal>MDN Documentation</Link>.
9697
`;
9798
}
9899

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import fs from 'fs';
2+
import { MetaInfo } from '@/data/meta';
3+
4+
/*
5+
6+
Returns the frontmatter as an object of key/value pairs. For example:
7+
8+
Input (string):
9+
10+
---
11+
title: Flex
12+
mdnUrl: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div
13+
htmlElement: div
14+
---
15+
16+
Output (object):
17+
18+
{
19+
title: 'Flex',
20+
mdnUrl: 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div',
21+
htmlElement: 'div',
22+
}
23+
24+
*/
25+
26+
export function getFrontmatter(componentFilepath: string) {
27+
let fileData = '';
28+
try {
29+
fileData = fs.readFileSync(componentFilepath, 'utf8');
30+
} catch (err) {
31+
if (err.code === 'ENOENT') {
32+
console.log('File not found!');
33+
} else {
34+
throw err;
35+
}
36+
}
37+
38+
if (!fileData) {
39+
return {};
40+
}
41+
42+
const frontmatter = fileData.split('---')[1].trim().split('\n');
43+
44+
return frontmatter.reduce((acc, line) => {
45+
const [key, value] = line.split(': ');
46+
return { ...acc, [key]: value };
47+
}, {}) as MetaInfo;
48+
}

docs/scripts/util/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { getAllTypesData } from './getAllTypesData';
2+
export { getCatalog } from './getCatalog';
3+
export { getFrontmatter } from './getFrontmatter';
4+
export { sanitize } from './sanitize';

docs/src/data/meta.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export interface MetaInfo {
55
description?: string;
66
metaTitle?: string;
77
metaDescription?: string;
8+
mdnUrl?: string;
9+
htmlElement?: string;
810
supportedFrameworks?: string;
911
slug?: string;
1012
};

docs/src/pages/[platform]/components/alert/index.page.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ description: Alert displays a brief message in a way that attracts the user’s
44
ariaPattern: https://www.w3.org/WAI/ARIA/apg/patterns/alert
55
themeSource: packages/ui/src/theme/tokens/components/alert.ts
66
reactSource: packages/react/src/primitives/Alert/Alert.tsx
7+
mdnUrl: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div
8+
htmlElement: div
79
supportedFrameworks: react
810
---
911

docs/src/pages/[platform]/components/alert/props-table.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,4 +382,4 @@ ResponsiveStyle<Property.FlexWrap>
382382

383383
See [Style Props](/react/theming/style-props) for all supported style and layout properties.
384384

385-
The Alert component will accept any of the standard HTML attributes that a HTML element accepts. Standard element attributes can be found in the <Link href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element" isExternal={true}>MDN Documentation</Link>.
385+
Alert will also accept any of the standard HTML attributes that a <code>\<div\></code> element accepts, which can be found in the <Link href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div" isExternal>MDN Documentation</Link>.

docs/src/pages/[platform]/components/badge/index.page.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Badge
33
description: Badge is a color-coded element used to display a status or message about an item.
44
themeSource: packages/ui/src/theme/tokens/components/badge.ts
55
reactSource: packages/react/src/primitives/Badge/Badge.tsx
6+
mdnUrl: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span
7+
htmlElement: span
68
supportedFrameworks: react
79
---
810

docs/src/pages/[platform]/components/badge/props-table.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,4 @@ ResponsiveStyle<Property.FlexShrink>
262262

263263
See [Style Props](/react/theming/style-props) for all supported style and layout properties.
264264

265-
The Badge component will accept any of the standard HTML attributes that a HTML element accepts. Standard element attributes can be found in the <Link href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element" isExternal={true}>MDN Documentation</Link>.
265+
Badge will also accept any of the standard HTML attributes that a <code>\<span\></code> element accepts, which can be found in the <Link href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span" isExternal>MDN Documentation</Link>.

docs/src/pages/[platform]/components/button/index.page.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ description: Button allows users to perform actions.
44
ariaPattern: https://www.w3.org/WAI/ARIA/apg/patterns/button
55
themeSource: packages/ui/src/theme/tokens/components/button.ts
66
reactSource: packages/react/src/primitives/Button/Button.tsx
7+
mdnUrl: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button
8+
htmlElement: button
79
supportedFrameworks: react
810
---
911

docs/src/pages/[platform]/components/button/props-table.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,4 @@ ResponsiveStyle<Property.FlexWrap>
492492

493493
See [Style Props](/react/theming/style-props) for all supported style and layout properties.
494494

495-
The Button component will accept any of the standard HTML attributes that a HTML element accepts. Standard element attributes can be found in the <Link href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element" isExternal={true}>MDN Documentation</Link>.
495+
Button will also accept any of the standard HTML attributes that a <code>\<button\></code> element accepts, which can be found in the <Link href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button" isExternal>MDN Documentation</Link>.

0 commit comments

Comments
 (0)