Skip to content

Commit

Permalink
feat(debug): add the props factory to the debug route
Browse files Browse the repository at this point in the history
  • Loading branch information
jgroth committed Aug 30, 2024
1 parent b118675 commit 65e6fa6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export class App {
componentProps={{
docs: this.data.docs,
schemas: this.data.schemas,
examplePropsFactory:
this.examplePropsFactory,
}}
/>
<stencil-route
Expand Down
10 changes: 10 additions & 0 deletions src/components/debug/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
JsonDocsTag,
} from '@stencil/core/internal';
import { MatchResults } from '@stencil/router';
import { PropsFactory } from '../playground/playground.types';

@Component({
tag: 'kompendium-debug',
Expand All @@ -29,6 +30,13 @@ export class KompendiumDebug {
@Prop()
public match: MatchResults;

/**
* Factory for creating props for example components
* @returns {Record<string, unknown>} props
*/
@Prop()
public examplePropsFactory?: PropsFactory = () => ({});

public render(): HTMLElement {
const tag = this.match.params.name;
const component = findComponent(tag, this.docs);
Expand All @@ -46,8 +54,10 @@ export class KompendiumDebug {
const ExampleComponent = component.tag;
const ownerComponent = this.docs.components.find(isOwnerOf(component));
const schema = this.schemas.find((s) => s.$id === ownerComponent.tag);
const factory = this.examplePropsFactory;
const props = {
schema: schema,
...factory(ExampleComponent),
};

return (
Expand Down

0 comments on commit 65e6fa6

Please sign in to comment.