Skip to content

Commit f882c30

Browse files
committed
Platform circles
1 parent fbdd4d6 commit f882c30

6 files changed

Lines changed: 126 additions & 0 deletions

File tree

packages/docs-gesture-handler/docusaurus.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
In swizzled components look for "SWM -" string to see our modifications
33
*/
4+
const platformsCirclePlugin = require('./plugins/platforms-circles.js');
45

56
const lightCodeTheme = require('./src/theme/CodeBlock/highlighting-light.js');
67
const darkCodeTheme = require('./src/theme/CodeBlock/highlighting-dark.js');
@@ -49,6 +50,10 @@ const config = {
4950
label: '3.x',
5051
},
5152
},
53+
beforeDefaultRemarkPlugins: [
54+
platformsCirclePlugin.processHeaderMarkers,
55+
],
56+
remarkPlugins: [platformsCirclePlugin.removeHeaderJSX],
5257
},
5358
theme: {
5459
customCss: require.resolve('./src/css/index.css'),

packages/docs-gesture-handler/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"react-native-worklets": "^0.1.0",
5252
"source-map": "^0.7.4",
5353
"source-map-loader": "^4.0.1",
54+
"unist-util-visit": "^5.1.0",
5455
"usehooks-ts": "^2.9.1",
5556
"vis-network": "^10.0.2"
5657
},
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-argument */
2+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
3+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
4+
/* eslint-disable @typescript-eslint/no-unsafe-call */
5+
6+
// plugins/remark-add-platform-metadata.js
7+
import { visit } from 'unist-util-visit';
8+
9+
const platformClasses = {
10+
'[A]': 'platform-indicator-android',
11+
'[I]': 'platform-indicator-ios',
12+
'[W]': 'platform-indicator-web',
13+
};
14+
15+
const processHeaderMarkers = () => {
16+
return (ast) => {
17+
visit(ast, 'heading', (node) => {
18+
let textContent = '';
19+
let markers = [];
20+
21+
visit(node, 'text', (textNode) => {
22+
// Split header into text and platform markers
23+
const headerParts = textNode.value
24+
.split(/(\[A\]|\[I\]|\[W\])/g)
25+
.filter((headerPart) => headerPart !== '');
26+
27+
// Assume that the first part is always the text content, and the rest are markers
28+
textContent = headerParts.shift().trimEnd();
29+
30+
// Sort markers to ensure consistent order
31+
markers = headerParts.sort();
32+
});
33+
34+
if (markers.length === 0) {
35+
return;
36+
}
37+
38+
const newChildren = [{ type: 'text', value: textContent }];
39+
40+
markers.forEach((marker) => {
41+
newChildren.push({
42+
type: 'mdxJsxTextElement',
43+
name: 'span',
44+
attributes: [
45+
{
46+
type: 'mdxJsxAttribute',
47+
name: 'className',
48+
value: platformClasses[marker],
49+
},
50+
],
51+
children: [],
52+
data: { isPlatformIndicator: true },
53+
});
54+
});
55+
56+
node.children = newChildren;
57+
});
58+
};
59+
};
60+
61+
const removeHeaderJSX = () => {
62+
return (ast) => {
63+
const classes = Object.values(platformClasses);
64+
65+
visit(ast, 'heading', (node) => {
66+
node.children = node.children.filter((child) => {
67+
if (child.type === 'mdxJsxTextElement') {
68+
const classAttr = child.attributes?.find(
69+
(a) => a.name === 'className'
70+
);
71+
72+
return !(classAttr && classes.includes(classAttr.value));
73+
}
74+
75+
return true;
76+
});
77+
});
78+
};
79+
};
80+
81+
export { processHeaderMarkers, removeHeaderJSX };
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
@import 'colors.css';
22
@import 'typography.css';
3+
@import 'toc.css';
34
@import 'overrides.css';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.table-of-contents .platform-indicator-android,
2+
.table-of-contents .platform-indicator-ios,
3+
.table-of-contents .platform-indicator-web {
4+
display: inline-block;
5+
6+
/* Circle shape */
7+
width: 7px;
8+
height: 7px;
9+
border-radius: 50%;
10+
11+
margin-left: 4px;
12+
13+
/* Vertical alignment */
14+
vertical-align: middle;
15+
position: relative;
16+
top: -1px;
17+
}
18+
19+
.table-of-contents .platform-indicator-android {
20+
background: #34a853;
21+
}
22+
23+
.table-of-contents .platform-indicator-ios {
24+
background: #000000;
25+
}
26+
27+
.table-of-contents .platform-indicator-web {
28+
background: #1067c4;
29+
}

packages/docs-gesture-handler/yarn.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12980,6 +12980,15 @@ unist-util-visit@^5.0.0:
1298012980
unist-util-is "^6.0.0"
1298112981
unist-util-visit-parents "^6.0.0"
1298212982

12983+
unist-util-visit@^5.1.0:
12984+
version "5.1.0"
12985+
resolved "https://registry.yarnpkg.com/unist-util-visit/-/unist-util-visit-5.1.0.tgz#9a2a28b0aa76a15e0da70a08a5863a2f060e2468"
12986+
integrity sha512-m+vIdyeCOpdr/QeQCu2EzxX/ohgS8KbnPDgFni4dQsfSCtpz8UqDyY5GjRru8PDKuYn7Fq19j1CQ+nJSsGKOzg==
12987+
dependencies:
12988+
"@types/unist" "^3.0.0"
12989+
unist-util-is "^6.0.0"
12990+
unist-util-visit-parents "^6.0.0"
12991+
1298312992
universalify@^0.1.0:
1298412993
version "0.1.2"
1298512994
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"

0 commit comments

Comments
 (0)