-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21907 from storybookjs/tom/21649-change-react-dec…
…orator-order React: Don't show decorators in JSX snippets
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { defaultDecorateStory } from '@storybook/preview-api'; | ||
import type { LegacyStoryFn, DecoratorFunction } from '@storybook/types'; | ||
|
||
import type { ReactRenderer } from './types'; | ||
import { jsxDecorator } from './docs/jsxDecorator'; | ||
|
||
export const applyDecorators = ( | ||
storyFn: LegacyStoryFn<ReactRenderer>, | ||
decorators: DecoratorFunction<ReactRenderer>[] | ||
): LegacyStoryFn<ReactRenderer> => { | ||
// @ts-expect-error originalFn is not defined on the type for decorator. This is a temporary fix | ||
// that we will remove soon (likely) in favour of a proper concept of "inner" decorators. | ||
const jsxIndex = decorators.findIndex((d) => d.originalFn === jsxDecorator); | ||
|
||
const reorderedDecorators = | ||
jsxIndex === -1 ? decorators : [...decorators.splice(jsxIndex, 1), ...decorators]; | ||
|
||
return defaultDecorateStory(storyFn, reorderedDecorators); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters