@storybook/blocks 7.0.0-beta.30 → 7.0.0-beta.32

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/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import * as _storybook_types from '@storybook/types';
2
- import { Conditional, DocsContextProps, PreparedStory, Renderer, StrictArgTypes, StoryId, ResolvedModuleExport, Parameters as Parameters$1, ProjectAnnotations, BaseAnnotations, ModuleExports, StoryAnnotations, ModuleExport, ComponentTitle } from '@storybook/types';
2
+ import { Conditional, DocsContextProps, PreparedStory, ModuleExports, Renderer as Renderer$1, StrictArgTypes, StoryId, ModuleExport, Parameters as Parameters$1, ProjectAnnotations, BaseAnnotations, StoryAnnotations, ComponentTitle } from '@storybook/types';
3
3
  export { DocsContextProps } from '@storybook/types';
4
4
  import React, { FunctionComponent, ComponentProps, ReactNode, FC, Context } from 'react';
5
+ import { Renderer } from '@storybook/csf';
5
6
  import { PropDescriptor } from '@storybook/preview-api';
6
7
  import { SyntaxHighlighter, ActionItem, SyntaxHighlighterFormatTypes } from '@storybook/components';
8
+ import { SourceType } from '@storybook/docs-tools';
7
9
  import { Channel } from '@storybook/channels';
8
10
  import { ThemeVars } from '@storybook/theming';
9
11
 
@@ -11,17 +13,28 @@ declare enum SourceError {
11
13
  NO_STORY = "There\u2019s no story here.",
12
14
  SOURCE_UNAVAILABLE = "Oh no! The source is not available."
13
15
  }
14
- interface SourceErrorProps {
15
- isLoading?: boolean;
16
- error?: SourceError;
17
- }
18
16
  interface SourceCodeProps {
17
+ /**
18
+ * The language the syntax highlighter uses for your story’s code
19
+ */
19
20
  language?: string;
21
+ /**
22
+ * Use this to override the content of the source block.
23
+ */
20
24
  code?: string;
25
+ /**
26
+ * The (prettier) formatter the syntax highlighter uses for your story’s code.
27
+ */
21
28
  format?: ComponentProps<typeof SyntaxHighlighter>['format'];
29
+ /**
30
+ * Display the source snippet in a dark mode.
31
+ */
22
32
  dark?: boolean;
23
33
  }
24
- type SourceProps$1 = SourceErrorProps & SourceCodeProps;
34
+ interface SourceProps$1 extends SourceCodeProps {
35
+ isLoading?: boolean;
36
+ error?: SourceError;
37
+ }
25
38
  /**
26
39
  * Syntax-highlighted source code for a component (or anything!)
27
40
  */
@@ -46,7 +59,7 @@ interface ArgType {
46
59
  if?: Conditional;
47
60
  [key: string]: any;
48
61
  }
49
- interface ArgTypes {
62
+ interface ArgTypes$1 {
50
63
  [key: string]: ArgType;
51
64
  }
52
65
  interface Args {
@@ -72,7 +85,7 @@ interface ArgsTableOptionProps {
72
85
  sort?: SortType;
73
86
  }
74
87
  interface ArgsTableDataProps {
75
- rows: ArgTypes;
88
+ rows: ArgTypes$1;
76
89
  args?: Args;
77
90
  globals?: Globals;
78
91
  }
@@ -91,17 +104,19 @@ declare const ArgsTable$1: FC<ArgsTableProps$1>;
91
104
 
92
105
  declare const NoControlsWarning: () => JSX.Element;
93
106
 
94
- interface CommonProps$1 {
107
+ interface CommonProps {
95
108
  story: PreparedStory;
96
109
  inline: boolean;
110
+ primary: boolean;
97
111
  }
98
- interface InlineStoryProps extends CommonProps$1 {
112
+ interface InlineStoryProps extends CommonProps {
99
113
  inline: true;
100
114
  height?: string;
101
115
  autoplay: boolean;
116
+ forceInitialArgs: boolean;
102
117
  renderStoryToElement: DocsContextProps['renderStoryToElement'];
103
118
  }
104
- interface IFrameStoryProps extends CommonProps$1 {
119
+ interface IFrameStoryProps extends CommonProps {
105
120
  inline: false;
106
121
  height: string;
107
122
  }
@@ -168,7 +183,17 @@ interface AnchorProps {
168
183
  }
169
184
  declare const Anchor: FC<AnchorProps>;
170
185
 
171
- declare const DocsContext: Context<DocsContextProps<Renderer>>;
186
+ type ArgTypesParameters = {
187
+ include?: PropDescriptor;
188
+ exclude?: PropDescriptor;
189
+ sort?: SortType;
190
+ };
191
+ type ArgTypesProps = ArgTypesParameters & {
192
+ of?: Renderer['component'] | ModuleExports;
193
+ };
194
+ declare const ArgTypes: FC<ArgTypesProps>;
195
+
196
+ declare const DocsContext: Context<DocsContextProps<Renderer$1>>;
172
197
 
173
198
  declare const PRIMARY_STORY = "^";
174
199
  type Component = any;
@@ -181,6 +206,8 @@ interface StoryData {
181
206
  type DocsStoryProps = StoryData & {
182
207
  expanded?: boolean;
183
208
  withToolbar?: boolean;
209
+ __forceInitialArgs?: boolean;
210
+ __primary?: boolean;
184
211
  };
185
212
 
186
213
  interface BaseProps {
@@ -212,7 +239,7 @@ declare const ArgsTable: FC<ArgsTableProps>;
212
239
 
213
240
  interface SourceItem {
214
241
  code: string;
215
- format: SyntaxHighlighterFormatTypes;
242
+ format?: SyntaxHighlighterFormatTypes;
216
243
  }
217
244
  type StorySources = Record<StoryId, SourceItem>;
218
245
  interface SourceContextProps {
@@ -229,23 +256,37 @@ declare enum SourceState {
229
256
  CLOSED = "closed",
230
257
  NONE = "none"
231
258
  }
232
- interface CommonProps {
233
- language?: string;
234
- dark?: boolean;
235
- format?: PureSourceProps['format'];
236
- code?: string;
237
- }
238
- type SingleSourceProps = {
239
- id: string;
240
- } & CommonProps;
241
- type MultiSourceProps = {
242
- ids: string[];
243
- } & CommonProps;
244
- type CodeProps = {
245
- code: string;
246
- } & CommonProps;
247
- type NoneProps = CommonProps;
248
- type SourceProps = SingleSourceProps | MultiSourceProps | CodeProps | NoneProps;
259
+ type SourceParameters = SourceCodeProps & {
260
+ /**
261
+ * Where to read the source code from, see `SourceType`
262
+ */
263
+ type?: SourceType;
264
+ /**
265
+ * Transform the detected source for display
266
+ */
267
+ transformSource?: (code: string, story: PreparedStory) => string;
268
+ /**
269
+ * Internal: set by our CSF loader (`enrichCsf` in `@storybook/csf-tools`).
270
+ */
271
+ originalSource?: string;
272
+ };
273
+ type SourceProps = Omit<SourceParameters, 'transformSource' | 'storySource'> & {
274
+ /**
275
+ * Pass the export defining a story to render its source
276
+ *
277
+ * ```jsx
278
+ * import { Source } from '@storybook/blocks';
279
+ * import * as ButtonStories from './Button.stories';
280
+ *
281
+ * <Source of={ButtonStories.Primary} />
282
+ * ```
283
+ */
284
+ of?: ModuleExport;
285
+ /** @deprecated use of={storyExport} instead */
286
+ id?: string;
287
+ /** @deprecated use of={storyExport} instead */
288
+ ids?: string[];
289
+ };
249
290
  type SourceStateProps = {
250
291
  state: SourceState;
251
292
  };
@@ -256,7 +297,7 @@ declare const useSourceProps: (props: SourceProps, docsContext: DocsContextProps
256
297
  * or the source for a story if `storyId` is provided, or
257
298
  * the source for the current story if nothing is provided.
258
299
  */
259
- declare const Source: FC<PureSourceProps>;
300
+ declare const Source: FC<SourceProps>;
260
301
 
261
302
  type CanvasProps = Omit<PreviewProps, 'isExpanded' | 'isLoading'> & {
262
303
  withSource?: SourceState;
@@ -265,14 +306,14 @@ type CanvasProps = Omit<PreviewProps, 'isExpanded' | 'isLoading'> & {
265
306
  };
266
307
  declare const Canvas: FC<CanvasProps>;
267
308
 
268
- type Of = Parameters<DocsContextProps['resolveModuleExport']>[0];
309
+ type Of = Parameters<DocsContextProps['resolveOf']>[0];
269
310
  /**
270
311
  * A hook to resolve the `of` prop passed to a block.
271
312
  * will return the resolved module
272
313
  * if the resolved module is a meta it will include a preparedMeta property similar to a preparedStory
273
314
  * if the resolved module is a component it will include the project annotations
274
315
  */
275
- declare const useOf: (of: Of, validTypes?: ResolvedModuleExport['type'][]) => {
316
+ declare const useOf: (moduleExportOrType: any, validTypes?: _storybook_types.ResolvedModuleExportType[]) => {
276
317
  type: "story";
277
318
  story: _storybook_types.PreparedStory<_storybook_types.Renderer>;
278
319
  } | {
@@ -312,7 +353,7 @@ interface DescriptionProps {
312
353
  }
313
354
  declare const DescriptionContainer: FC<DescriptionProps>;
314
355
 
315
- type DocsProps<TFramework extends Renderer = Renderer> = {
356
+ type DocsProps<TFramework extends Renderer$1 = Renderer$1> = {
316
357
  docsParameter: Parameters$1;
317
358
  context: DocsContextProps<TFramework>;
318
359
  };
@@ -320,7 +361,7 @@ declare const Docs: FunctionComponent<DocsProps>;
320
361
 
321
362
  declare const DocsPage: FC;
322
363
 
323
- interface DocsContainerProps<TFramework extends Renderer = Renderer> {
364
+ interface DocsContainerProps<TFramework extends Renderer$1 = Renderer$1> {
324
365
  context: DocsContextProps<TFramework>;
325
366
  theme?: ThemeVars;
326
367
  children?: ReactNode;
@@ -329,7 +370,7 @@ declare const DocsContainer: FunctionComponent<DocsContainerProps>;
329
370
 
330
371
  declare const DocsStory: FC<DocsStoryProps>;
331
372
 
332
- type ExternalDocsProps<TFramework extends Renderer = Renderer> = {
373
+ type ExternalDocsProps<TFramework extends Renderer$1 = Renderer$1> = {
333
374
  projectAnnotationsList: ProjectAnnotations<TFramework>[];
334
375
  };
335
376
  declare const ExternalDocs: FunctionComponent<ExternalDocsProps>;
@@ -364,7 +405,6 @@ interface StoriesProps {
364
405
  }
365
406
  declare const Stories: FC<StoriesProps>;
366
407
 
367
- declare const storyBlockIdFromId: (storyId: string) => string;
368
408
  type PureStoryProps = ComponentProps<typeof Story$1>;
369
409
  /**
370
410
  * Props to define a story
@@ -380,6 +420,10 @@ type StoryRefProps = {
380
420
  * @deprecated Use of={storyExport} instead
381
421
  */
382
422
  id?: string;
423
+ /**
424
+ * @deprecated Use of={storyExport} and define the story in the CSF file
425
+ */
426
+ story?: StoryAnnotations;
383
427
  /**
384
428
  * Pass the export defining a story to render that story
385
429
  *
@@ -417,10 +461,18 @@ type StoryParameters = {
417
461
  * Whether to run the story's play function
418
462
  */
419
463
  autoplay?: boolean;
464
+ /**
465
+ * Internal prop to control if a story re-renders on args updates
466
+ */
467
+ __forceInitialArgs?: boolean;
468
+ /**
469
+ * Internal prop if this story is the primary story
470
+ */
471
+ __primary?: boolean;
420
472
  };
421
473
  type StoryProps = (StoryDefProps | StoryRefProps) & StoryParameters;
422
474
  declare const getStoryId: (props: StoryProps, context: DocsContextProps) => StoryId;
423
- declare const getStoryProps: <TFramework extends Renderer>(props: StoryParameters, story: PreparedStory<TFramework>, context: DocsContextProps<TFramework>) => PureStoryProps;
475
+ declare const getStoryProps: <TFramework extends Renderer$1>(props: StoryParameters, story: PreparedStory<TFramework>, context: DocsContextProps<TFramework>) => PureStoryProps;
424
476
  declare const Story: FC<StoryProps>;
425
477
 
426
478
  declare const Subheading: FC<HeadingProps>;
@@ -581,4 +633,4 @@ type ColorProps = ColorControlProps;
581
633
  declare const LazyColorControl: React.LazyExoticComponent<React.FC<ColorControlProps>>;
582
634
  declare const ColorControl: (props: ComponentProps<typeof LazyColorControl>) => JSX.Element;
583
635
 
584
- export { AddContext, Anchor, AnchorMdx, AnchorProps, ArgsTable, BooleanConfig, BooleanControl, BooleanProps, BooleanValue, Canvas, CodeOrSourceMdx, ColorConfig, ColorControl, ColorItem, ColorPalette, ColorProps, ColorValue, Component, ComponentsTable, Control, ControlProps, ControlType, Controls, DateConfig, DateControl, DateProps, DateValue, DescriptionContainer as Description, DescriptionType, Docs, DocsContainer, DocsContainerProps, DocsContext, DocsPage, DocsProps, DocsStory, DocsStoryProps, ExternalDocs, ExternalDocsContainer, ExternalDocsProps, FilesControl, FilesControlProps, HeaderMdx, HeadersMdx, Heading, HeadingProps, IconGallery, IconItem, Meta, NoControlsWarning, NormalizedOptionsConfig, NumberConfig, NumberControl, NumberValue, ObjectConfig, ObjectControl, ObjectProps, ObjectValue, Of, Options, OptionsArray, OptionsConfig, OptionsControl, OptionsControlType, OptionsMultiSelection, OptionsObject, OptionsProps, OptionsSelection, OptionsSingleSelection, PRIMARY_STORY, PresetColor, Primary, ArgsTable$1 as PureArgsTable, RangeConfig, RangeControl, SortType, Source, SourceContainer, SourceContext, SourceContextProps, SourceItem, SourceState, Stories, Story, StoryData, StoryProps, StorySources, StoryTable, Subheading, Subtitle, TextConfig, TextControl, TextProps, TextValue, Title, Typeset, Unstyled, Wrapper, anchorBlockIdFromId, assertIsFn, extractComponentArgTypes, extractTitle, format, formatDate, formatTime, getComponent, getStoryId, getStoryProps, parse, parseDate, parseTime, storyBlockIdFromId, useOf, useSourceProps };
636
+ export { AddContext, Anchor, AnchorMdx, AnchorProps, ArgTypes, ArgsTable, BooleanConfig, BooleanControl, BooleanProps, BooleanValue, Canvas, CodeOrSourceMdx, ColorConfig, ColorControl, ColorItem, ColorPalette, ColorProps, ColorValue, Component, ComponentsTable, Control, ControlProps, ControlType, Controls, DateConfig, DateControl, DateProps, DateValue, DescriptionContainer as Description, DescriptionType, Docs, DocsContainer, DocsContainerProps, DocsContext, DocsPage, DocsProps, DocsStory, DocsStoryProps, ExternalDocs, ExternalDocsContainer, ExternalDocsProps, FilesControl, FilesControlProps, HeaderMdx, HeadersMdx, Heading, HeadingProps, IconGallery, IconItem, Meta, NoControlsWarning, NormalizedOptionsConfig, NumberConfig, NumberControl, NumberValue, ObjectConfig, ObjectControl, ObjectProps, ObjectValue, Of, Options, OptionsArray, OptionsConfig, OptionsControl, OptionsControlType, OptionsMultiSelection, OptionsObject, OptionsProps, OptionsSelection, OptionsSingleSelection, PRIMARY_STORY, PresetColor, Primary, ArgsTable$1 as PureArgsTable, RangeConfig, RangeControl, SortType, Source, SourceContainer, SourceContext, SourceContextProps, SourceItem, SourceState, Stories, Story, StoryData, StoryProps, StorySources, StoryTable, Subheading, Subtitle, TextConfig, TextControl, TextProps, TextValue, Title, Typeset, Unstyled, Wrapper, anchorBlockIdFromId, assertIsFn, extractComponentArgTypes, extractTitle, format, formatDate, formatTime, getComponent, getStoryId, getStoryProps, parse, parseDate, parseTime, useOf, useSourceProps };