Skip to content

Commit f946a3e

Browse files
authored
feat(doc): add Web Types (#1301)
1 parent d582e62 commit f946a3e

File tree

3 files changed

+124
-1
lines changed

3 files changed

+124
-1
lines changed

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@
7474
"license": "MIT",
7575
"sideEffects": [
7676
"icons/imports/"
77-
]
77+
],
78+
"web-types": "dist/ionic.web-types.json"
7879
}

Diff for: scripts/build.ts

+27
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ async function build(rootDir: string) {
3131

3232
await createCheatsheet(version, rootDir, distDir, svgSymbolsContent, srcSvgData);
3333

34+
await createWebTypes(version, rootDir, distDir, srcSvgData);
35+
3436
await copyToTesting(rootDir, distDir, srcSvgData);
3537
} catch (e) {
3638
console.error(e);
@@ -269,6 +271,31 @@ async function createCheatsheet(
269271
await fs.writeFile(distCheatsheetFilePath, html);
270272
}
271273

274+
async function createWebTypes(
275+
version: string,
276+
rootDir: string,
277+
distDir: any,
278+
srcSvgData: SvgData[]
279+
) {
280+
const srcWebTypeFilePath = join(rootDir, 'src/ionicons.web-types.json');
281+
const distWebTypesFilePath = join(distDir, 'ionicons.web-types.json');
282+
283+
const webTypes = JSON.parse(await fs.readFile(srcWebTypeFilePath, 'utf8'))
284+
285+
webTypes.version = version
286+
287+
const icons = webTypes.contributions.html.ionicons
288+
for (let data of srcSvgData) {
289+
icons.push({
290+
name: data.iconName,
291+
icon: "dist/svg/" + data.fileName
292+
})
293+
}
294+
295+
const jsonStr = JSON.stringify(webTypes, null, 2) + '\n';
296+
await fs.writeFile(distWebTypesFilePath, jsonStr);
297+
}
298+
272299
async function getSvgs(srcSvgDir: string, distSvgDir: string, distIoniconsDir: string): Promise<SvgData[]> {
273300
const optimizedSvgDir = join(distIoniconsDir, 'svg');
274301
await fs.emptyDir(optimizedSvgDir);

Diff for: src/ionicons.web-types.json

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"$schema": "http://json.schemastore.org/web-types",
3+
"name": "ionicons",
4+
"version": "0.0.0",
5+
"description-markup": "markdown",
6+
"contributions": {
7+
"html": {
8+
"elements": [
9+
{
10+
"name": "ion-icon",
11+
"description": "The Ionicons Web Component is an easy and performant way to use Ionicons in your app. The component will dynamically load an SVG for each icon, so your app is only requesting the icons that you need.",
12+
"doc-url": "https://ionic.io/ionicons/usage",
13+
"attributes": [
14+
{
15+
"name": "name",
16+
"description": "The name of the built-in icon from the Ionicons package.",
17+
"priority": "high",
18+
"doc-url": "https://ionic.io/ionicons/usage#basic-usage",
19+
"value": {
20+
"type": "symbol"
21+
},
22+
"values": [
23+
{
24+
"name": "The ion-icon",
25+
"pattern": {
26+
"items": "ionicons"
27+
}
28+
}
29+
]
30+
},
31+
{
32+
"name": "src",
33+
"priority": "high",
34+
"description": "Provide url of a custom SVG icon. The `src` attribute works the same as `<img src=\"...\">` in that the url must be accessible from the webpage that's making a request for the image. Additionally, the external file can only be a valid `svg` and does not allow scripts or events within the `svg` element.",
35+
"doc-url": "https://ionic.io/ionicons/usage#basic-usage"
36+
},
37+
{
38+
"name": "md",
39+
"description": "Provide icon variant specific to MD platform",
40+
"priority": "high",
41+
"doc-url": "https://ionic.io/ionicons/usage#basic-usage",
42+
"value": {
43+
"type": "symbol"
44+
},
45+
"values": [
46+
{
47+
"name": "The ion-icon",
48+
"pattern": {
49+
"items": "ionicons"
50+
}
51+
}
52+
]
53+
},
54+
{
55+
"name": "ios",
56+
"description": "Provide icon variant specific to iOS platform",
57+
"priority": "high",
58+
"doc-url": "https://ionic.io/ionicons/usage#basic-usage",
59+
"value": {
60+
"type": "symbol"
61+
},
62+
"values": [
63+
{
64+
"name": "The ion-icon",
65+
"pattern": {
66+
"items": "ionicons"
67+
}
68+
}
69+
]
70+
},
71+
{
72+
"name": "size",
73+
"description": "Specify the icon size using one of the pre-defined font sizes.\n\nAlternatively you can set a specific size by applying the `font-size` CSS property on the `ion-icon` component. It's recommended to use pixel sizes that are a multiple of 8 (8, 16, 32, 64, etc.)",
74+
"doc-url": "https://ionic.io/ionicons/usage#basic-usage",
75+
"priority": "high",
76+
"value": {
77+
"type": "enum"
78+
},
79+
"values": [
80+
{
81+
"name": "small"
82+
},
83+
{
84+
"name": "large"
85+
}
86+
]
87+
}
88+
]
89+
}
90+
],
91+
"ionicons": [
92+
]
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)