@repobuddy/storybook 2.22.0 โ†’ 2.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/index.d.ts CHANGED
@@ -85,6 +85,10 @@ type StoryCardProps = {
85
85
  * Can be any React node (string, JSX, etc.).
86
86
  */
87
87
  children?: ReactNode | undefined;
88
+ /**
89
+ * Test identifier for the card.
90
+ */
91
+ 'data-testid'?: string | undefined;
88
92
  };
89
93
  type StoryCardThemeState = Pick<StoryCardProps, 'status' | 'appearance'> & {
90
94
  defaultClassName: string;
@@ -106,7 +110,7 @@ declare const StoryCard: react.NamedExoticComponent<StoryCardProps>;
106
110
  * @property showOriginalSource - When true, use the story's original (untransformed) source instead of the rendered source.
107
111
  * @property placement - Where to show the source code relative to the story. Defaults to `'before'`.
108
112
  */
109
- type ShowSourceOptions = Pick<StoryCardProps, 'className'> & {
113
+ type ShowSourceOptions = Pick<StoryCardProps, 'className' | 'data-testid'> & {
110
114
  source?: ((source: string | undefined) => string) | string | undefined;
111
115
  showOriginalSource?: boolean | undefined;
112
116
  placement?: 'before' | 'after' | undefined;
@@ -122,7 +126,13 @@ type ShowSourceOptions = Pick<StoryCardProps, 'className'> & {
122
126
  * @param options.placement - Where to show the source code relative to the story.
123
127
  * @returns A decorator function that shows the source code of a story above or below the rendered story
124
128
  */
125
- declare function showSource<TRenderer extends Renderer = Renderer, TArgs = Args>(options?: ShowSourceOptions): DecoratorFunction<TRenderer, TArgs>;
129
+ declare function showSource<TRenderer extends Renderer = Renderer, TArgs = Args>({
130
+ className,
131
+ placement,
132
+ showOriginalSource,
133
+ source,
134
+ ...options
135
+ }?: ShowSourceOptions): DecoratorFunction<TRenderer, TArgs>;
126
136
  //#endregion
127
137
  //#region src/decorators/show_doc_source.d.ts
128
138
  /**
package/esm/index.js CHANGED
@@ -64,7 +64,7 @@ const storyCardVariants = cva("rbsb:py-3 rbsb:px-4 rbsb:rounded rbsb:border rbsb
64
64
  * @param props - StoryCard component props
65
65
  * @returns A section element containing the card content
66
66
  */
67
- const StoryCard = memo(function StoryCard({ status, appearance, className, children, title }) {
67
+ const StoryCard = memo(function StoryCard({ status, appearance, className, children, title, ...rest }) {
68
68
  const resolvedAppearance = resolveAppearance(appearance, status);
69
69
  return /* @__PURE__ */ jsxs("section", {
70
70
  className: storyCardTheme({
@@ -72,6 +72,7 @@ const StoryCard = memo(function StoryCard({ status, appearance, className, child
72
72
  appearance: resolvedAppearance,
73
73
  defaultClassName: storyCardVariants({ appearance: resolvedAppearance })
74
74
  }, className),
75
+ ...rest,
75
76
  children: [title && /* @__PURE__ */ jsx("h2", {
76
77
  className: "rbsb:text-lg rbsb:font-bold",
77
78
  children: title
@@ -196,7 +197,7 @@ const channel = addons.getChannel();
196
197
  * @param options.placement - Where to show the source code relative to the story.
197
198
  * @returns A decorator function that shows the source code of a story above or below the rendered story
198
199
  */
199
- function showSource(options) {
200
+ function showSource({ className, placement, showOriginalSource, source, ...options } = {}) {
200
201
  if (isRunningInTest()) return (Story) => /* @__PURE__ */ jsx(Story, {});
201
202
  return (Story, { parameters: { docs, darkMode } }) => {
202
203
  const storedItem = window.localStorage.getItem("sb-addon-themes-3");
@@ -206,8 +207,8 @@ function showSource(options) {
206
207
  channel.on("DARK_MODE", setIsDark);
207
208
  return () => channel.off("DARK_MODE", setIsDark);
208
209
  }, []);
209
- const originalSource = options?.showOriginalSource ? docs?.source?.originalSource : docs?.source?.code ?? docs?.source?.originalSource;
210
- const code = typeof options?.source === "function" ? options?.source(originalSource) : options?.source ?? originalSource;
210
+ const originalSource = showOriginalSource ? docs?.source?.originalSource : docs?.source?.code ?? docs?.source?.originalSource;
211
+ const code = typeof source === "function" ? source(originalSource) : source ?? originalSource;
211
212
  const language = code === docs?.source?.originalSource ? void 0 : docs?.source?.language;
212
213
  const isOriginalSource = code === docs?.source?.originalSource;
213
214
  const sourceContent = useMemo(() => /* @__PURE__ */ jsx(SyntaxHighlighter, {
@@ -215,15 +216,14 @@ function showSource(options) {
215
216
  language,
216
217
  children: code
217
218
  }), [code, language]);
218
- const showBefore = (options?.placement ?? "before") === "before";
219
+ const showBefore = (placement ?? "before") === "before";
219
220
  const sourceCardClassName = useCallback((state) => {
220
221
  const modifiedState = {
221
222
  ...state,
222
223
  defaultClassName: twJoin(state.defaultClassName, isOriginalSource && "rbsb:bg-transparent rbsb:dark:bg-transparent")
223
224
  };
224
- const className = options?.className;
225
225
  return typeof className === "function" ? className(modifiedState) : twJoin(modifiedState.defaultClassName, className);
226
- }, [options?.className, isOriginalSource]);
226
+ }, [className, isOriginalSource]);
227
227
  const theme = convert(docs?.theme ?? (isDark ? themes.dark : themes.light));
228
228
  function DocSourceCard({ children }) {
229
229
  return /* @__PURE__ */ jsx("div", { children });
@@ -238,6 +238,12 @@ function showSource(options) {
238
238
  className: sourceCardClassName,
239
239
  appearance: "source"
240
240
  });
241
+ const storyCard = /* @__PURE__ */ jsx(StoryCard, {
242
+ className: sourceCardClassName,
243
+ appearance: "source",
244
+ ...options,
245
+ children: /* @__PURE__ */ jsx(DocSourceCard, { children: sourceContent })
246
+ });
241
247
  return /* @__PURE__ */ jsx(ThemeProvider, {
242
248
  theme,
243
249
  children: /* @__PURE__ */ jsxs("section", {
@@ -246,11 +252,7 @@ function showSource(options) {
246
252
  flexDirection: "column",
247
253
  gap: "1rem"
248
254
  },
249
- children: [/* @__PURE__ */ jsx(Story, {}), /* @__PURE__ */ jsx(StoryCard, {
250
- className: sourceCardClassName,
251
- appearance: "source",
252
- children: /* @__PURE__ */ jsx(DocSourceCard, { children: sourceContent })
253
- })]
255
+ children: [/* @__PURE__ */ jsx(Story, {}), storyCard]
254
256
  })
255
257
  });
256
258
  };
package/package.json CHANGED
@@ -1,12 +1,21 @@
1
1
  {
2
2
  "name": "@repobuddy/storybook",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "description": "Storybook repo buddy",
5
5
  "keywords": [
6
6
  "storybook",
7
7
  "testing",
8
8
  "documentation"
9
9
  ],
10
+ "homepage": "https://github.com/repobuddy/storybook",
11
+ "bugs": {
12
+ "url": "https://github.com/repobuddy/storybook/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/repobuddy/storybook.git",
17
+ "directory": "libs/storybook"
18
+ },
10
19
  "license": "MIT",
11
20
  "author": {
12
21
  "name": "Homa Wong",
package/readme.md CHANGED
@@ -78,31 +78,33 @@ addons.setConfig({
78
78
  If you use [`storybook-addon-tag-badges`][`storybook-addon-tag-badges`],
79
79
  we provide a different set of badges that uses emojis (order: first match wins):
80
80
 
81
- - ๐Ÿ†• `new` - Recently added stories
82
- - ๐Ÿ”ด `alpha` - Features in alpha
83
- - ๐ŸŸก `beta` - Features in beta
84
- - ๐Ÿ”ต `rc` - Release candidate
85
- - ๐Ÿ—‘๏ธ `deprecated` - Deprecated features
86
- - โ˜ ๏ธ `remove` or `remove:next` (same) or `remove:<version>` - Will be removed in the next or specified version
87
- - โš ๏ธ `outdated` - Stories that need updating
88
- - ๐Ÿšจ `danger` - Dangerous or cautionary patterns
89
- - ๐ŸŽฏ `use-case` - Specific use case or scenario
90
- - โœจ `example` - Example or demo stories
91
- - โšก `perf` - Performance (stories that demonstrate or test performance)
92
- - โŒจ๏ธ `keyboard` - Keyboard interaction
93
- - `</>` `source` - Source-code-focused stories
94
- - `<T>` `type` - TypeScript types (shown in MDX)
95
- - `ฦ’(x)` `func` - Functions (shown in MDX)
96
- - `var` `var` - Variables (shown in MDX)
97
- - ๐Ÿ”ง `props` - Props or configuration
98
- - ๐Ÿ“‹ `todo` - Todo or incomplete stories
99
- - ๐Ÿงช `unit` - Unit tests
100
- - ๐Ÿ”— `integration` - Integration tests (hidden in sidebar)
101
- - โœ๏ธ `editor` - Live editor stories (with [`storybook-addon-code-editor`][`storybook-addon-code-editor`])
102
- - ๐Ÿ“ `code-only` - Stories without visual examples (hidden in MDX)
103
- - Version indicators (unchanged)
104
- - ๐Ÿ”’ `internal` - Internal or private-use-only stories
105
- - ๐Ÿ“ธ `snapshot` - Snapshot tests (toolbar only, not sidebar)
81
+ | Badge | Tag | Description |
82
+ | :----- | :------------------------------------------------------- | :---------------------------------------------------------------------------------------- |
83
+ | ๐Ÿ†• | `new` | Recently added stories |
84
+ | ๐Ÿ”ด | `alpha` | Features in alpha |
85
+ | ๐ŸŸก | `beta` | Features in beta |
86
+ | ๐Ÿ”ต | `rc` | Release candidate |
87
+ | ๐Ÿ—‘๏ธ | `deprecated` | Deprecated features |
88
+ | โ˜ ๏ธ | `remove`<br/>`remove:next` (same)<br/>`remove:<version>` | Will be removed in the next or specified version |
89
+ | โš ๏ธ | `outdated` | Stories that need updating |
90
+ | ๐Ÿšจ | `danger` | Dangerous or cautionary patterns |
91
+ | ๐ŸŽฏ | `use-case` | Specific use case or scenario |
92
+ | โœจ | `example` | Example or demo stories |
93
+ | โšก | `perf` | Performance (stories that demonstrate or test performance) |
94
+ | โŒจ๏ธ | `keyboard` | Keyboard interaction |
95
+ | `</>` | `source` | Source-code-focused stories |
96
+ | `<T>` | `type` | TypeScript types (shown in MDX) |
97
+ | `ฦ’(x)` | `func` | Functions (shown in MDX) |
98
+ | `var` | `var` | Variables (shown in MDX) |
99
+ | ๐Ÿ”ง | `props` | Props or configuration |
100
+ | ๐Ÿ“‹ | `todo` | Todo or incomplete stories |
101
+ | ๐Ÿงช | `unit` | Unit tests |
102
+ | ๐Ÿ”— | `integration` | Integration tests (hidden in sidebar) |
103
+ | โœ๏ธ | `editor` | Live editor stories (with [`storybook-addon-code-editor`][`storybook-addon-code-editor`]) |
104
+ | ๐Ÿ“ | `code-only` | Stories without visual examples (hidden in MDX) |
105
+ | | Version indicators | (unchanged) |
106
+ | ๐Ÿ”’ | `internal` | Internal or private-use-only stories |
107
+ | ๐Ÿ“ธ | `snapshot` | Snapshot tests (toolbar only, not sidebar) |
106
108
 
107
109
  To use them, add them to your `.storybook/manager.ts`:
108
110
 
@@ -48,6 +48,10 @@ export type StoryCardProps = {
48
48
  * Can be any React node (string, JSX, etc.).
49
49
  */
50
50
  children?: ReactNode | undefined
51
+ /**
52
+ * Test identifier for the card.
53
+ */
54
+ 'data-testid'?: string | undefined
51
55
  }
52
56
 
53
57
  export type StoryCardThemeState = Pick<StoryCardProps, 'status' | 'appearance'> & { defaultClassName: string }
@@ -90,7 +94,14 @@ const storyCardVariants = cva(
90
94
  * @param props - StoryCard component props
91
95
  * @returns A section element containing the card content
92
96
  */
93
- export const StoryCard = memo(function StoryCard({ status, appearance, className, children, title }: StoryCardProps) {
97
+ export const StoryCard = memo(function StoryCard({
98
+ status,
99
+ appearance,
100
+ className,
101
+ children,
102
+ title,
103
+ ...rest
104
+ }: StoryCardProps) {
94
105
  const resolvedAppearance = resolveAppearance(appearance, status)
95
106
  const state: StoryCardThemeState = {
96
107
  status,
@@ -98,7 +109,7 @@ export const StoryCard = memo(function StoryCard({ status, appearance, className
98
109
  defaultClassName: storyCardVariants({ appearance: resolvedAppearance })
99
110
  }
100
111
  return (
101
- <section className={storyCardTheme(state, className)}>
112
+ <section className={storyCardTheme(state, className)} {...rest}>
102
113
  {title && <h2 className="rbsb:text-lg rbsb:font-bold">{title}</h2>}
103
114
  {children}
104
115
  </section>
@@ -18,7 +18,7 @@ const channel = addons.getChannel()
18
18
  * @property showOriginalSource - When true, use the story's original (untransformed) source instead of the rendered source.
19
19
  * @property placement - Where to show the source code relative to the story. Defaults to `'before'`.
20
20
  */
21
- export type ShowSourceOptions = Pick<StoryCardProps, 'className'> & {
21
+ export type ShowSourceOptions = Pick<StoryCardProps, 'className' | 'data-testid'> & {
22
22
  source?: ((source: string | undefined) => string) | string | undefined
23
23
  showOriginalSource?: boolean | undefined
24
24
  placement?: 'before' | 'after' | undefined
@@ -35,9 +35,13 @@ export type ShowSourceOptions = Pick<StoryCardProps, 'className'> & {
35
35
  * @param options.placement - Where to show the source code relative to the story.
36
36
  * @returns A decorator function that shows the source code of a story above or below the rendered story
37
37
  */
38
- export function showSource<TRenderer extends Renderer = Renderer, TArgs = Args>(
39
- options?: ShowSourceOptions
40
- ): DecoratorFunction<TRenderer, TArgs> {
38
+ export function showSource<TRenderer extends Renderer = Renderer, TArgs = Args>({
39
+ className,
40
+ placement,
41
+ showOriginalSource,
42
+ source,
43
+ ...options
44
+ }: ShowSourceOptions = {}): DecoratorFunction<TRenderer, TArgs> {
41
45
  if (isRunningInTest()) {
42
46
  return (Story) => <Story />
43
47
  }
@@ -54,12 +58,11 @@ export function showSource<TRenderer extends Renderer = Renderer, TArgs = Args>(
54
58
  return () => channel.off('DARK_MODE', setIsDark)
55
59
  }, [])
56
60
 
57
- const originalSource = options?.showOriginalSource
61
+ const originalSource = showOriginalSource
58
62
  ? docs?.source?.originalSource
59
63
  : (docs?.source?.code ?? docs?.source?.originalSource)
60
64
 
61
- const code =
62
- typeof options?.source === 'function' ? options?.source(originalSource) : (options?.source ?? originalSource)
65
+ const code = typeof source === 'function' ? source(originalSource) : (source ?? originalSource)
63
66
 
64
67
  const language = code === docs?.source?.originalSource ? undefined : docs?.source?.language
65
68
 
@@ -74,7 +77,7 @@ export function showSource<TRenderer extends Renderer = Renderer, TArgs = Args>(
74
77
  [code, language]
75
78
  )
76
79
 
77
- const showBefore = (options?.placement ?? 'before') === 'before'
80
+ const showBefore = (placement ?? 'before') === 'before'
78
81
 
79
82
  const sourceCardClassName = useCallback(
80
83
  (state: Pick<StoryCardProps, 'status' | 'appearance'> & { defaultClassName: string }) => {
@@ -86,12 +89,11 @@ export function showSource<TRenderer extends Renderer = Renderer, TArgs = Args>(
86
89
  )
87
90
  }
88
91
 
89
- const className = options?.className
90
92
  return typeof className === 'function'
91
93
  ? className(modifiedState)
92
94
  : twJoin(modifiedState.defaultClassName, className)
93
95
  },
94
- [options?.className, isOriginalSource]
96
+ [className, isOriginalSource]
95
97
  )
96
98
 
97
99
  const theme = convert(docs?.theme ?? (isDark ? themes.dark : themes.light))
@@ -116,7 +118,7 @@ export function showSource<TRenderer extends Renderer = Renderer, TArgs = Args>(
116
118
  }
117
119
 
118
120
  const storyCard = (
119
- <StoryCard className={sourceCardClassName} appearance="source">
121
+ <StoryCard className={sourceCardClassName} appearance="source" {...options}>
120
122
  <DocSourceCard>{sourceContent}</DocSourceCard>
121
123
  </StoryCard>
122
124
  )