Skip to content

Commit

Permalink
Doc blocks: Remove deprecated props from Source block
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Jan 5, 2024
1 parent e8278ce commit 70b462e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 47 deletions.
5 changes: 5 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- [Deprecated docs parameters](#deprecated-docs-parameters)
- [Description Doc block properties](#description-doc-block-properties)
- [Manager API expandAll and collapseAll methods](#manager-api-expandall-and-collapseall-methods)
- [Source Doc block properties](#source-doc-block-properties)
- [From version 7.5.0 to 7.6.0](#from-version-750-to-760)
- [CommonJS with Vite is deprecated](#commonjs-with-vite-is-deprecated)
- [Using implicit actions during rendering is deprecated](#using-implicit-actions-during-rendering-is-deprecated)
Expand Down Expand Up @@ -690,6 +691,10 @@ api.collapseAll() // becomes api.emit(STORIES_COLLAPSE_ALL)
api.expandAll() // becomes api.emit(STORIES_EXPAND_ALL)
```

#### Source Doc block properties

`id` and `ids` are now removed in favor of the `of` property. [More info](#doc-blocks).

## From version 7.5.0 to 7.6.0

#### CommonJS with Vite is deprecated
Expand Down
33 changes: 2 additions & 31 deletions code/ui/blocks/src/blocks/Source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ import type {
} from '@storybook/types';
import { SourceType } from '@storybook/docs-tools';

import { deprecate } from '@storybook/client-logger';
import dedent from 'ts-dedent';
import type { SourceCodeProps } from '../components/Source';
import { Source as PureSource, SourceError } from '../components/Source';
import type { DocsContextProps } from './DocsContext';
import { DocsContext } from './DocsContext';
import type { SourceContextProps, SourceItem } from './SourceContainer';
import { UNKNOWN_ARGS_HASH, argsHash, SourceContext } from './SourceContainer';

import { useStories } from './useStory';

export enum SourceState {
OPEN = 'open',
CLOSED = 'closed',
Expand Down Expand Up @@ -54,12 +50,6 @@ export type SourceProps = SourceParameters & {
*/
of?: ModuleExport;

/** @deprecated use of={storyExport} instead */
id?: string;

/** @deprecated use of={storyExport} instead */
ids?: string[];

/**
* Internal prop to control if a story re-renders on args updates
*/
Expand Down Expand Up @@ -134,11 +124,7 @@ export const useSourceProps = (
docsContext: DocsContextProps<any>,
sourceContext: SourceContextProps
): PureSourceProps & SourceStateProps => {
const storyIds = props.ids || (props.id ? [props.id] : []);
const storiesFromIds = useStories(storyIds, docsContext);

// The check didn't actually change the type.
let stories: PreparedStory[] = storiesFromIds as PreparedStory[];
let stories: PreparedStory[] = [];
const { of } = props;
if ('of' in props && of === undefined) {
throw new Error('Unexpected `of={undefined}`, did you mistype a CSF file reference?');
Expand All @@ -147,17 +133,14 @@ export const useSourceProps = (
if (of) {
const resolved = docsContext.resolveOf(of, ['story']);
stories = [resolved.story];
} else if (stories.length === 0) {
} else {
try {
// Always fall back to the primary story for source parameters, even if code is set.
stories = [docsContext.storyById()];
} catch (err) {
// You are allowed to use <Source code="..." /> and <Canvas /> unattached.
}
}
if (!storiesFromIds.every(Boolean)) {
return { error: SourceError.SOURCE_UNAVAILABLE, state: SourceState.NONE };
}

const sourceParameters = (stories[0]?.parameters?.docs?.source || {}) as SourceParameters;
let { code } = props; // We will fall back to `sourceParameters.code`, but per story below
Expand Down Expand Up @@ -213,18 +196,6 @@ export const useSourceProps = (
* the source for the current story if nothing is provided.
*/
export const Source: FC<SourceProps> = (props) => {
if (props.id) {
deprecate(dedent`The \`id\` prop on Source is deprecated, please use the \`of\` prop instead to reference a story.
Please refer to the migration guide: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#source-block
`);
}
if (props.ids) {
deprecate(dedent`The \`ids\` prop on Source is deprecated, please use the \`of\` prop instead to reference a story.
Please refer to the migration guide: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#source-block
`);
}
const sourceContext = useContext(SourceContext);
const docsContext = useContext(DocsContext);
const { state, ...sourceProps } = useSourceProps(props, docsContext, sourceContext);
Expand Down
16 changes: 0 additions & 16 deletions docs/api/doc-block-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,3 @@ Specifies how the source code is rendered.
Note that dynamic snippets will only work if the story uses [`args`](../writing-stories/args.md) and the [`Story` block](./doc-block-story.md) for that story is rendered along with the `Source` block.

</Callout>

### `id`

(⛔️ **Deprecated**)

Type: `string`

Specifies the story id for which to render the source code. Referencing a story this way is no longer supported; use the [`of` prop](#of), instead.

### `ids`

(⛔️ **Deprecated**)

Type: `string[]`

Specifies the story ids for which to render source code. Multiple stories are no longer supported; to render a single story's source, use the [`of` prop](#of).

0 comments on commit 70b462e

Please sign in to comment.