|
| 1 | +const code = (s: string) => (s ? `\`${s}\`` : ""); |
| 2 | +const transformAttributes = (attributes: any[]) => ` |
| 3 | +## Attributes |
| 4 | +
|
| 5 | +| Attribute | Type | Description | |
| 6 | +| --------- | ---- | ----------- | |
| 7 | +${attributes |
| 8 | + .map( |
| 9 | + attr => `| ${code(attr.name)} | ${code(attr.type)} | ${attr.description} |` |
| 10 | + ) |
| 11 | + .join("\n")} |
| 12 | +`; |
| 13 | + |
| 14 | +const transformProperties = (properties: any[]) => ` |
| 15 | +## Properties |
| 16 | +
|
| 17 | +| Property | Attribute | Type | Default | Description | |
| 18 | +| -------- | --------- | ---- | ------- | ----------- | |
| 19 | +${properties |
| 20 | + .map( |
| 21 | + prop => |
| 22 | + `| ${code(prop.name)} | ${code(prop.attribute)} | ${code(prop.type)} | ${ |
| 23 | + prop.default |
| 24 | + } | ${prop.description} |` |
| 25 | + ) |
| 26 | + .join("\n")} |
| 27 | +`; |
| 28 | + |
| 29 | +const transformEvents = (events: any[]) => ` |
| 30 | +## Events |
| 31 | +
|
| 32 | +| Event | Description | |
| 33 | +| ----- | ----------- | |
| 34 | +${events |
| 35 | + .map(event => `| ${code(event.name)} | ${code(event.description)} |`) |
| 36 | + .join("\n")} |
| 37 | +`; |
| 38 | + |
| 39 | +const transformSlots = (slots: any[]) => ` |
| 40 | +## Slots |
| 41 | +
|
| 42 | +| Name | Description | |
| 43 | +| ---- | ----------- | |
| 44 | +${slots.map(slot => `| ${code(slot.name)} | ${slot.description} |`).join("\n")} |
| 45 | +`; |
| 46 | + |
| 47 | +const transformCSSParts = (shadowParts: any[]) => ` |
| 48 | +## CSS Shadow Parts |
| 49 | +
|
| 50 | +| Part | Description | |
| 51 | +| ---- | ----------- | |
| 52 | +${shadowParts |
| 53 | + .map(part => `| ${code(part.name)} | ${part.description} |`) |
| 54 | + .join("\n")} |
| 55 | +`; |
| 56 | + |
| 57 | +const transformCSSProperties = (cssProperties: any[]) => ` |
| 58 | +## CSS Custom Properties |
| 59 | +
|
| 60 | +| Property | Description | |
| 61 | +| -------- | ----------- | |
| 62 | +${cssProperties |
| 63 | + .map(cssProp => `| ${code(cssProp.name)} | ${cssProp.description} |`) |
| 64 | + .join("\n")} |
| 65 | +`; |
| 66 | + |
| 67 | +export default customElements => { |
| 68 | + const customElement = customElements.tags[0]; |
| 69 | + let markdownParts = [`# ${customElement.name}`]; |
| 70 | + markdownParts.push(customElement.description); |
| 71 | + customElement.attributes && |
| 72 | + markdownParts.push(transformAttributes(customElement.attributes)); |
| 73 | + customElement.properties && |
| 74 | + markdownParts.push(transformProperties(customElement.properties)); |
| 75 | + customElement.events && |
| 76 | + markdownParts.push(transformEvents(customElement.events)); |
| 77 | + customElement.slots && |
| 78 | + markdownParts.push(transformSlots(customElement.slots)); |
| 79 | + customElement.cssParts && |
| 80 | + markdownParts.push(transformCSSParts(customElement.cssParts)); |
| 81 | + customElement.cssProperties && |
| 82 | + markdownParts.push(transformCSSProperties(customElement.cssProperties)); |
| 83 | + return markdownParts.join("\n"); |
| 84 | +}; |
0 commit comments