Skip to content

Commit 5d987c4

Browse files
committed
WIP
1 parent 40d0e50 commit 5d987c4

File tree

5 files changed

+48
-8
lines changed

5 files changed

+48
-8
lines changed

story-starter/starters/nuxt/components/StoryList.vue

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ const {
2121
goToPage,
2222
} = await useStories({ perPage: 10 });
2323
24+
const config = useConfig({
25+
selectedStories,
26+
});
27+
28+
console.log('💡 config', config);
29+
2430
// Show top progress bar on page change.
2531
watch(isLoading, () => {
2632
if (!data.value) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Story } from '~/types/story';
2+
import config from '../stories.config';
3+
import type { StoryConfig } from '~/types/config';
4+
5+
type UseConfig = (props: { selectedStories: Ref<Story[]> }) => Ref<StoryConfig>;
6+
7+
export const useConfig: UseConfig = ({ selectedStories }) => {
8+
const resolvedConfig = ref<StoryConfig>(
9+
typeof config === 'function' ? config(selectedStories.value) : config
10+
);
11+
12+
if (typeof config === 'function') {
13+
watch(selectedStories, () => {
14+
resolvedConfig.value =
15+
typeof config === 'function' ? config(selectedStories.value) : config;
16+
});
17+
}
18+
19+
return resolvedConfig;
20+
};
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
//draft for future actions implementations
2-
type StoryConfig = {
3-
actions: {
4-
label: string;
5-
handler: (selectedStories: any) => void;
6-
}[];
7-
};
1+
import type { StoryConfig } from '~/types/config';
2+
import type { Story } from '~/types/story';
83

9-
export const defineStoryConfig = (config: StoryConfig): StoryConfig => config;
4+
type StoryConfigGetter = (selectedStories: Story[]) => StoryConfig;
5+
6+
export const defineStoryConfig = (config: StoryConfig | StoryConfigGetter) =>
7+
config;

story-starter/starters/nuxt/stories.config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import { defineStoryConfig } from '~/shared/defineStoryConfig';
22

3+
// export default defineStoryConfig((selecte) => ({
4+
// actions: [
5+
// {
6+
// label: 'Translate',
7+
// handler: (selectedStories) => {},
8+
// },
9+
// ],
10+
// }));
11+
312
export default defineStoryConfig({
413
actions: [
514
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//draft for future actions implementations
2+
export type StoryConfig = {
3+
actions: {
4+
label: string;
5+
handler: (selectedStories: any) => void;
6+
}[];
7+
};

0 commit comments

Comments
 (0)