Skip to content

Commit

Permalink
feat(createStoryMetaSettings): allow generating internal stories and …
Browse files Browse the repository at this point in the history
…autodocs page with metasettings helper
  • Loading branch information
YossiSaadi committed Apr 21, 2024
1 parent fb54b9a commit 4c07b84
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
3 changes: 0 additions & 3 deletions packages/core/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ const config: StorybookConfig = {
name: "@storybook/react-webpack5",
options: {}
},
docs: {
autodocs: false
},
async webpackFinal(config, { configType }) {
if (configType === "DEVELOPMENT") {
if (config.resolve) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { createComponentTemplate } from "vibe-storybook-components";
import BaseInput from "../BaseInput";

const metaSettings = createStoryMetaSettingsDecorator({
component: BaseInput
component: BaseInput,
isInternal: true,
shouldCreateAutodocsPage: true
});

export default {
title: "Internal/BaseInput",
component: BaseInput,
argTypes: metaSettings.argTypes,
decorators: metaSettings.decorators,
tags: ["internal"]
tags: metaSettings.tags
};

const baseInputTemplate = createComponentTemplate(BaseInput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export function createStoryMetaSettingsDecorator({
enumPropNamesArray,
iconPropNamesArray,
actionPropsArray,
ignoreControlsPropNamesArray
ignoreControlsPropNamesArray,
isInternal,
shouldCreateAutodocsPage
}: Omit<CreateStoryMetaSettingsArgs, "allIconsComponents" | "iconsMetaData">) {
return createStoryMetaSettings({
component,
Expand All @@ -20,7 +22,9 @@ export function createStoryMetaSettingsDecorator({
actionPropsArray,
ignoreControlsPropNamesArray,
iconsMetaData,
allIconsComponents: AllIcons
allIconsComponents: AllIcons,
isInternal,
shouldCreateAutodocsPage
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useCallback, useMemo, useState } from 'react';
import { action } from '@storybook/addon-actions';
import { AllowedIcons, Decorator, IconMetaData, StoryMetaSettingsArgs, StoryMetaSettingsResult } from './types';
import { ArgTypes } from '@storybook/types';
import { AllowedIcons, IconMetaData, StoryMetaSettingsArgs, StoryMetaSettingsResult } from './types';
import { Decorator } from '@storybook/react';
import { ArgTypes, Tag } from '@storybook/types';

function parseStringForEnums(componentName: string, enumName: string, enumObj: { [key: string]: unknown }) {
let returnValue;
Expand Down Expand Up @@ -54,9 +55,12 @@ export function createStoryMetaSettings({
iconsMetaData,
allIconsComponents,
ignoreControlsPropNamesArray,
isInternal,
shouldCreateAutodocsPage,
}: StoryMetaSettingsArgs): StoryMetaSettingsResult {
const argTypes: ArgTypes = {};
const decorators: Decorator[] = [];
const tags = prepareTags(isInternal, shouldCreateAutodocsPage);
const allowedIcons = iconsMetaData?.reduce(
(acc: AllowedIcons, icon: IconMetaData) => {
const Component = allIconsComponents[icon.file.split('.')[0]];
Expand Down Expand Up @@ -137,7 +141,18 @@ export function createStoryMetaSettings({
}
});

return { argTypes, decorators };
return { argTypes, decorators, tags };
}

export default createStoryMetaSettings;

function prepareTags(isInternal: boolean = false, shouldCreateAutodocsPage: boolean = false) {
const tags: Tag[] = [];
if (isInternal) {
tags.push('internal');
}
if (shouldCreateAutodocsPage) {
tags.push('autodocs');
}
return tags;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ArgTypes, PartialStoryFn, StoryContext } from '@storybook/types';
import { Decorator } from '@storybook/react';
import { ArgTypes, Tag } from '@storybook/types';

export type EnumPropNames = {
propName: string;
Expand All @@ -20,9 +21,6 @@ export type AllowedIcons = {
mapping: { [key: string]: unknown };
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Decorator = (story: PartialStoryFn<any>, context: StoryContext<any>) => { storyResult: any };

export type StoryMetaSettingsArgs = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
component: any;
Expand All @@ -32,9 +30,12 @@ export type StoryMetaSettingsArgs = {
allIconsComponents: { [key: string]: unknown };
iconsMetaData?: IconMetaData[];
ignoreControlsPropNamesArray?: string[];
isInternal?: boolean;
shouldCreateAutodocsPage?: boolean;
};

export type StoryMetaSettingsResult = {
argTypes: Partial<ArgTypes>;
decorators: Decorator[];
tags: Tag[];
};

0 comments on commit 4c07b84

Please sign in to comment.