Skip to content

Commit afd7ef1

Browse files
authored
feat: show method params and return type (#147)
1 parent cc911b6 commit afd7ef1

File tree

8 files changed

+84
-6
lines changed

8 files changed

+84
-6
lines changed

.changeset/fast-candles-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@api-viewer/docs': patch
3+
---
4+
5+
Show method params and return type

docs/assets/custom-elements.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,32 @@
690690
"attribute": "indeterminate",
691691
"reflects": true
692692
},
693+
{
694+
"kind": "method",
695+
"name": "setBounds",
696+
"return": {
697+
"type": {
698+
"text": "void"
699+
}
700+
},
701+
"parameters": [
702+
{
703+
"name": "min",
704+
"type": {
705+
"text": "number"
706+
},
707+
"description": "minimum value"
708+
},
709+
{
710+
"name": "max",
711+
"type": {
712+
"text": "number"
713+
},
714+
"description": "maximum value"
715+
}
716+
],
717+
"description": "Set both minimum and maximum value."
718+
},
693719
{
694720
"kind": "method",
695721
"name": "_normalizedValueChanged",

docs/docs/api/styling.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The following custom CSS properties are available:
66

77
| Property | Description |
88
| -------------------------------- | ----------------------------------------------- |
9-
| `--ave-accent-color` | Accent color, used for property names |
9+
| `--ave-accent-color` | Accent color, used for property / method names |
1010
| `--ave-border-color` | Color used for borders and dividers |
1111
| `--ave-border-radius` | Border radius used for the outer border |
1212
| `--ave-button-active-background` | Color of the `:focus` and `:hover` button |
@@ -20,6 +20,7 @@ The following custom CSS properties are available:
2020
| `--ave-link-hover-color` | API description links hover color |
2121
| `--ave-monospace-font` | Monospace font stack for the API items |
2222
| `--ave-primary-color` | Primary color, used for header and active tab |
23+
| `--ave-secondary-color` | Color used for method types in API docs |
2324
| `--ave-tab-color` | Inactive tabs color |
2425
| `--ave-tab-selected-color` | Selected tab color |
2526
| `--ave-tab-indicator-size` | Size of the selected tab indicator |
@@ -47,9 +48,15 @@ The following CSS shadow parts are available:
4748
| `docs-column` | Column, child of a `docs-row` part |
4849
| `docs-item` | Item representing a single entry (property, event etc) |
4950
| `docs-label` | Label (name, attribute, type, description) |
50-
| `docs-markdown` | Iem description with parsed markdown content |
51+
| `docs-markdown` | Item description with parsed markdown content |
52+
| `docs-method` | Method name with its params and return type |
53+
| `docs-method-params` | Comma-separated list of method params their types |
54+
| `docs-method-type` | Return type of a method, or "void" if not specified |
55+
| `docs-param-name` | Name of a method parameter |
56+
| `docs-param-type` | Type of a method parameter |
5157
| `docs-row` | Row containing columns. Child of a `docs-item` part |
5258
| `docs-value` | Sibling of a `docs-label` part (name, attribute, type) |
59+
| `docs-value` | Sibling of a `docs-label` part (name, attribute, type) |
5360
| `md-h1` | Markdown `<h1>` elements |
5461
| `md-h2` | Markdown `<h2>` elements |
5562
| `md-h3` | Markdown `<h3>` elements |

fixtures/lit/src/progress-bar.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ export class ProgressBar extends LitElement {
182182
}
183183
}
184184

185+
/**
186+
* Set both minimum and maximum value.
187+
*
188+
* @param {number} min minimum value
189+
* @param {number} max maximum value
190+
*/
191+
setBounds(min: number, max: number): void {
192+
this.min = min;
193+
this.max = max;
194+
}
195+
185196
private _normalizedValueChanged(
186197
value: number,
187198
min: number,

packages/api-common/src/shared-styles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default css`
1414
border-radius: var(--ave-border-radius);
1515
1616
--ave-primary-color: #01579b;
17+
--ave-secondary-color: rgba(0, 0, 0, 0.54);
1718
--ave-accent-color: #d63200;
1819
--ave-border-color: rgba(0, 0, 0, 0.12);
1920
--ave-border-radius: 4px;

packages/api-docs/src/layout.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { parse } from './utils/markdown.js';
1515

1616
const renderItem = (
1717
prefix: string,
18-
name: string,
18+
name: string | TemplateResult,
1919
description?: string,
2020
valueType?: string,
2121
value?: unknown,
@@ -75,6 +75,26 @@ const renderTab = (
7575
`;
7676
};
7777

78+
const renderMethod = (method: ClassMethod): TemplateResult => {
79+
const params = method.parameters || [];
80+
const type = method.return?.type?.text || 'void';
81+
82+
return html`
83+
<span part="docs-method">
84+
${method.name}(<span part="docs-method-params"
85+
>${params.map(
86+
(param, idx) =>
87+
html`<span part="docs-param-name">${param.name}</span>:
88+
<span part="docs-param-type">${param.type?.text}</span>${idx ===
89+
params.length - 1
90+
? ''
91+
: ', '}`
92+
)}</span
93+
>)</span
94+
><span part="docs-method-type">: ${type}</span>
95+
`;
96+
};
97+
7898
class ApiDocsLayout extends LitElement {
7999
@property() name = '';
80100

@@ -162,8 +182,8 @@ class ApiDocsLayout extends LitElement {
162182
'Methods',
163183
methods,
164184
html`
165-
${methods.map(({ name, description }) =>
166-
renderItem('method', `${name}()`, description)
185+
${methods.map((method) =>
186+
renderItem('method', renderMethod(method), method.description)
167187
)}
168188
`
169189
)}

packages/api-docs/src/styles.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ export default css`
8686
margin: 0.5rem 0;
8787
}
8888
89+
[part$='params'] {
90+
color: var(--ave-item-color);
91+
}
92+
93+
[part$='type'] {
94+
color: var(--ave-secondary-color);
95+
}
96+
8997
.accent {
9098
color: var(--ave-accent-color);
9199
}

packages/api-viewer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"size-limit": [
6060
{
6161
"path": "lib/api-viewer.js",
62-
"limit": "38.5 KB"
62+
"limit": "38.6 KB"
6363
}
6464
]
6565
}

0 commit comments

Comments
 (0)