@histoire/plugin-svelte
Version:
Histoire plugin for Svelte support
28 lines (27 loc) • 917 B
JavaScript
import { openStory, sendEvent } from 'histoire/plugin';
import { paramCase } from 'change-case';
export default {
prompts: [
{
field: 'component',
label: 'Choose a component',
type: 'select',
options: async (search) => sendEvent('listSvelteComponents', { search }),
required: true,
},
{
field: 'fileName',
label: 'File name',
type: 'text',
required: true,
defaultValue: answers => answers.component?.replace(/.+\/(.+?)\.svelte$/, '$1.story.svelte'),
},
],
clientAction: (params) => {
const index = params.component.lastIndexOf('/');
const dirname = params.component.substring(0, index + 1);
const file = `${dirname}${params.fileName}`;
const storyId = paramCase(file.toLowerCase());
openStory(storyId);
},
};