Skip to content

Commit

Permalink
Merge pull request #90 from ComponentDriven/next
Browse files Browse the repository at this point in the history
0.1.7 Release
  • Loading branch information
shilman authored May 6, 2024
2 parents eb0ddd6 + 81a58c9 commit 64a25a3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ A minimal set of utility functions for dealing with [Component Story Format (CSF
### Install

```sh
yarn add @componentdriven/csf
yarn add @storybook/csf
```

### API
Expand Down
20 changes: 19 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toId, storyNameFromExport, isExportStory } from './index.js';
import { toId, storyNameFromExport, isExportStory, combineTags } from './index.js';

describe('toId', () => {
const testCases: [string, string, string | undefined, string][] = [
Expand Down Expand Up @@ -93,3 +93,21 @@ describe('isExportStory', () => {
expect(isExportStory('a', { includeStories: /a/, excludeStories: /b/ })).toBeTruthy();
});
});

describe('combineTags', () => {
it.each([
[[], []],
[
['a', 'b'],
['a', 'b'],
],
[
['a', 'b', 'b'],
['a', 'b'],
],
[['a', 'b', '!b'], ['a']],
[['b', '!b', 'b'], ['b']],
])('combineTags(%o) -> %o', (tags, expected) => {
expect(combineTags(...tags)).toEqual(expected);
});
});
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,20 @@ export const parseKind = (kind: string, { rootSeparator, groupSeparator }: Separ
};
};

/**
* Combine a set of project / meta / story tags, removing duplicates and handling negations.
*/
export const combineTags = (...tags: string[]): string[] => {
const result = tags.reduce((acc, tag) => {
if (tag.startsWith('!')) {
acc.delete(tag.slice(1));
} else {
acc.add(tag);
}
return acc;
}, new Set<string>());
return Array.from(result);
};

export { includeConditionalArg } from './includeConditionalArg';
export * from './story';
15 changes: 5 additions & 10 deletions src/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@ export type BaseAnnotations<TRenderer extends Renderer = Renderer, TArgs = Args>
* Define a custom render function for the story(ies). If not passed, a default render function by the renderer will be used.
*/
render?: ArgsStoryFn<TRenderer, TArgs>;

/**
* Named tags for a story, used to filter stories in different contexts.
*/
tags?: Tag[];
};

export type ProjectAnnotations<
Expand Down Expand Up @@ -485,11 +490,6 @@ export interface ComponentAnnotations<TRenderer extends Renderer = Renderer, TAr
* Function that is executed after the story is rendered.
*/
play?: PlayFunction<TRenderer, TArgs>;

/**
* Named tags for a story, used to filter stories in different contexts.
*/
tags?: Tag[];
}

export type StoryAnnotations<
Expand All @@ -512,11 +512,6 @@ export type StoryAnnotations<
*/
play?: PlayFunction<TRenderer, TArgs>;

/**
* Named tags for a story, used to filter stories in different contexts.
*/
tags?: Tag[];

/** @deprecated */
story?: Omit<StoryAnnotations<TRenderer, TArgs>, 'story'>;
// eslint-disable-next-line @typescript-eslint/ban-types
Expand Down

0 comments on commit 64a25a3

Please sign in to comment.