Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(debug): add the props factory to the debug route #147

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading