Skip to content

Commit 8ae9bd7

Browse files
committed
refacto destructure customElement and add Syntax for custom css properties
1 parent 2c3a91f commit 8ae9bd7

File tree

3 files changed

+49
-40
lines changed

3 files changed

+49
-40
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![edit-in-webcomponents.dev](https://webcomponents.dev/assets/ext/edit_in_wcd.svg)](https://webcomponents.dev/edit/XPmoswtdx4DjIFzaPMBB)
2+
23
# text-field
34

45
A text field web component
@@ -40,8 +41,8 @@ A text field web component
4041

4142
## CSS Custom Properties
4243

43-
| Property | Description |
44-
| --------------------- | ------------------------------------- |
45-
| `--placeholder-color` | Controls the color of the placeholder |
44+
| Property | Syntax | Description |
45+
| --------------------- | ------ | ------------------------------------- |
46+
| `--placeholder-color` | | Controls the color of the placeholder |
4647

4748
> Created with [webcomponents.dev](https://webcomponents.dev)

src/index.stories.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import transform from "./index";
2+
23
const customElements = {
34
version: 2,
45
tags: [
@@ -75,4 +76,4 @@ const customElements = {
7576
]
7677
};
7778

78-
export const story1 = () => transform(customElements);
79+
export const story1 = () => `<pre>${transform(customElements)}</pre>`;

src/index.ts

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ ${attributes
88
.map(
99
attr => `| ${code(attr.name)} | ${code(attr.type)} | ${attr.description} |`
1010
)
11-
.join("\n")}
12-
`;
11+
.join("\n")}`;
1312

1413
const transformProperties = (properties: any[]) => `
1514
## Properties
@@ -23,8 +22,7 @@ ${properties
2322
prop.default
2423
} | ${prop.description} |`
2524
)
26-
.join("\n")}
27-
`;
25+
.join("\n")}`;
2826

2927
const transformEvents = (events: any[]) => `
3028
## Events
@@ -33,16 +31,16 @@ const transformEvents = (events: any[]) => `
3331
| ----- | ----------- |
3432
${events
3533
.map(event => `| ${code(event.name)} | ${code(event.description)} |`)
36-
.join("\n")}
37-
`;
34+
.join("\n")}`;
3835

3936
const transformSlots = (slots: any[]) => `
4037
## Slots
4138
4239
| Name | Description |
4340
| ---- | ----------- |
44-
${slots.map(slot => `| ${code(slot.name)} | ${slot.description} |`).join("\n")}
45-
`;
41+
${slots
42+
.map(slot => `| ${code(slot.name)} | ${slot.description} |`)
43+
.join("\n")}`;
4644

4745
const transformCSSParts = (shadowParts: any[]) => `
4846
## CSS Shadow Parts
@@ -51,43 +49,52 @@ const transformCSSParts = (shadowParts: any[]) => `
5149
| ---- | ----------- |
5250
${shadowParts
5351
.map(part => `| ${code(part.name)} | ${part.description} |`)
54-
.join("\n")}
55-
`;
52+
.join("\n")}`;
5653

5754
const transformCSSProperties = (cssProperties: any[]) => `
5855
## CSS Custom Properties
5956
60-
| Property | Description |
61-
| -------- | ----------- |
57+
| Property | Syntax | Description |
58+
| -------- | ------ | ----------- |
6259
${cssProperties
63-
.map(cssProp => `| ${code(cssProp.name)} | ${cssProp.description} |`)
64-
.join("\n")}
65-
`;
60+
.map(
61+
cssProp =>
62+
`| ${code(cssProp.name)} | ${code(cssProp.syntax)} | ${
63+
cssProp.description
64+
} |`
65+
)
66+
.join("\n")}`;
6667

6768
export default customElements => {
6869
let markdownParts = [];
6970
for (const customElement of customElements.tags) {
7071
if (!customElement) return undefined;
71-
markdownParts.push(`# ${customElement.name}`);
72-
markdownParts.push(customElement.description);
73-
customElement.attributes &&
74-
customElement.attributes.length > 0 &&
75-
markdownParts.push(transformAttributes(customElement.attributes));
76-
customElement.properties &&
77-
customElement.properties.length > 0 &&
78-
markdownParts.push(transformProperties(customElement.properties));
79-
customElement.events &&
80-
customElement.events.length > 0 &&
81-
markdownParts.push(transformEvents(customElement.events));
82-
customElement.slots &&
83-
customElement.slots.length > 0 &&
84-
markdownParts.push(transformSlots(customElement.slots));
85-
customElement.cssParts &&
86-
customElement.cssParts.length > 0 &&
87-
markdownParts.push(transformCSSParts(customElement.cssParts));
88-
customElement.cssProperties &&
89-
customElement.cssProperties.length > 0 &&
90-
markdownParts.push(transformCSSProperties(customElement.cssProperties));
72+
const {
73+
name,
74+
description,
75+
attributes,
76+
properties,
77+
events,
78+
slots,
79+
cssParts,
80+
cssProperties
81+
} = customElement;
82+
markdownParts.push(`# ${name}`);
83+
markdownParts.push(description);
84+
attributes &&
85+
attributes.length > 0 &&
86+
markdownParts.push(transformAttributes(attributes));
87+
properties &&
88+
properties.length > 0 &&
89+
markdownParts.push(transformProperties(properties));
90+
events && events.length > 0 && markdownParts.push(transformEvents(events));
91+
slots && slots.length > 0 && markdownParts.push(transformSlots(slots));
92+
cssParts &&
93+
cssParts.length > 0 &&
94+
markdownParts.push(transformCSSParts(cssParts));
95+
cssProperties &&
96+
cssProperties.length > 0 &&
97+
markdownParts.push(transformCSSProperties(cssProperties));
9198
}
92-
return markdownParts.join("\n");
99+
return markdownParts.join("\n\n");
93100
};

0 commit comments

Comments
 (0)