Skip to content

Commit 9c60a0a

Browse files
authored
fix: update slot knobs to render name properly (#133)
1 parent e51bd2f commit 9c60a0a

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

.changeset/nice-brooms-tell.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@api-viewer/demo': patch
3+
'api-viewer-element': patch
4+
---
5+
6+
Update slot knobs to render name properly

packages/api-demo/src/controllers/slots-controller.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@ import {
77
AbstractController,
88
AbstractControllerHost
99
} from './abstract-controller.js';
10+
import { formatSlot } from '../ui/controls.js';
1011
import { SlotValue } from '../types.js';
1112

12-
const capitalize = (name: string): string =>
13-
name[0].toUpperCase() + name.slice(1);
14-
15-
const getSlotContent = (name: string): string =>
16-
capitalize(name === '' ? 'content' : name);
17-
1813
export class SlotsController extends AbstractController<SlotValue> {
1914
enabled: boolean;
2015

@@ -40,7 +35,7 @@ export class SlotsController extends AbstractController<SlotValue> {
4035
.map((slot) => {
4136
return {
4237
...slot,
43-
content: getSlotContent(slot.name)
38+
content: formatSlot(slot.name)
4439
};
4540
}) as SlotValue[];
4641
}

packages/api-demo/src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export type Knob<T extends Knobable = unknown> = T & {
2121
custom?: boolean;
2222
options?: string[];
2323
knobType: string;
24-
content?: string;
2524
};
2625

2726
export type PropertyKnob = Knob<ClassField>;

packages/api-demo/src/ui/controls.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import {
88

99
type InputRenderer = (item: Knobable, id: string) => TemplateResult;
1010

11+
const capitalize = (name: string): string =>
12+
name[0].toUpperCase() + name.slice(1);
13+
14+
export const formatSlot = (name: string): string =>
15+
capitalize(name === '' ? 'content' : name);
16+
1117
export const cssPropRenderer: InputRenderer = (
1218
knob: Knobable,
1319
id: string
@@ -90,9 +96,9 @@ export const renderKnobs = (
9096
renderer: InputRenderer
9197
): TemplateResult => {
9298
const rows = items.map((item: Knobable) => {
93-
const { name, content } = item as PropertyKnob;
99+
const { name } = item as PropertyKnob;
94100
const id = `${type}-${name || 'default'}`;
95-
const label = type === 'slot' ? content : name;
101+
const label = type === 'slot' ? formatSlot(name) : name;
96102
return html`
97103
<tr>
98104
<td>

0 commit comments

Comments
 (0)