Skip to content

Commit b6d0f10

Browse files
hiddenisttajo
andauthored
Adds MetaJson types (#568)
* Adds types for meta.json * Adds optional generic to MetaJson types for story meta * Adds changeset * Makes the MetaJsonStory.meta type more strict --------- Co-authored-by: Vojtech Miksu <[email protected]>
1 parent c98d1af commit b6d0f10

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

.changeset/dirty-zoos-jam.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ladle/react": patch
3+
---
4+
5+
Exports meta.json types from library

packages/ladle/lib/app/exports.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88
ModeState,
99
GlobalAction,
1010
Config,
11+
KnownMeta,
12+
MetaJson as BaseMetaJson,
13+
MetaJsonStory as BaseMetaJsonStory,
1114
} from "../shared/types";
1215

1316
import * as msw from "msw";
@@ -135,9 +138,9 @@ export type ArgTypes<
135138
[key in keyof P]?: ArgType<P[key]>;
136139
};
137140

138-
export interface Meta {
139-
iframed?: boolean;
140-
width?: string | number | "xsmall" | "small" | "medium" | "large";
141-
mockDate?: string;
141+
export interface Meta extends KnownMeta {
142142
[key: string]: any;
143143
}
144+
145+
export type MetaJson = BaseMetaJson<Meta>;
146+
export type MetaJsonStory = BaseMetaJsonStory<Meta>;

packages/ladle/lib/cli/vite-plugin/generate/get-meta-json.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { storyIdToMeta } from "../naming-utils.js";
22

33
/**
44
* @param entryData {import('../../../shared/types').EntryData}
5+
* @returns {import('../../../shared/types').MetaJson}
56
*/
67
export const getMetaJson = (entryData) => {
78
/** @type {string[]} */
@@ -20,14 +21,15 @@ export const getMetaJson = (entryData) => {
2021
);
2122
storyParams = { ...storyParams, ...entryData[entry].storyParams };
2223
});
24+
25+
/** @type {import('../../../shared/types').MetaJson} */
2326
const result = {
2427
about: {
2528
homepage: "https://www.ladle.dev",
2629
github: "https://github.com/tajo/ladle",
2730
version: 1,
2831
},
29-
stories:
30-
/** @type {{[key: string]: {name: string; levels: string[]; meta: any, locStart: number; locEnd: number;}}} */ ({}),
32+
stories: {},
3133
};
3234
storyIds.forEach((storyId) => {
3335
result.stories[storyId] = {

packages/ladle/lib/shared/types.ts

+23
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,26 @@ export type GetUserViteConfig = {
280280
export type EntryData = {
281281
[key: string]: ParsedStoriesResult;
282282
};
283+
284+
export type MetaJson<M extends KnownMeta = KnownMeta> = {
285+
about: {
286+
homepage: string;
287+
github: string;
288+
version: number;
289+
};
290+
stories: { [key: string]: MetaJsonStory<M> };
291+
};
292+
293+
export type MetaJsonStory<M extends KnownMeta = KnownMeta> = {
294+
name: string;
295+
levels: string[];
296+
meta: M;
297+
locStart: number;
298+
locEnd: number;
299+
};
300+
301+
export interface KnownMeta {
302+
iframed?: boolean;
303+
width?: string | number | "xsmall" | "small" | "medium" | "large";
304+
mockDate?: string;
305+
}

0 commit comments

Comments
 (0)