Skip to content

Commit

Permalink
feat(code)!: exclude global decorators by default (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
igvnv committed Jan 9, 2024
1 parent 1d397ff commit 3c1aa4c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ export default {

The addon can be configured via the `playroom` [parameter](https://storybook.js.org/docs/react/writing-stories/parameters). The following options are available:

| Option | Type | Description | Default |
| :------------------------------- | :-------- | :--------------------------------------- | :---------------------- |
| `url` | `string` | the Playroom URL | `http://localhost:9000` |
| `code` | `string` | code to be used instead of story source | |
| `disable` | `boolean` | whether to disable the addon | `false` |
| `reactElementToJSXStringOptions` | `object` | [react-element-to-jsx-string options][1] | `{ sortProps: false }` |
| Option | Type | Description | Default |
| :------------------------------- | :-------- | :--------------------------------------------------- | :---------------------- |
| `url` | `string` | the Playroom URL | `http://localhost:9000` |
| `code` | `string` | code to be used instead of story source | |
| `disable` | `boolean` | whether to disable the addon | `false` |
| `includeDecorators` | `boolean` | whether to include global decorators in stories code | `false` |
| `reactElementToJSXStringOptions` | `object` | [react-element-to-jsx-string options][1] | `{ sortProps: false }` |

To configure for all stories, set the `playroom` parameter in [`.storybook/preview.js`](https://storybook.js.org/docs/react/configure/overview#configure-story-rendering):

Expand Down
3 changes: 3 additions & 0 deletions src/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ type Options = {
url?: string
code?: string
disable?: boolean
includeDecorators?: boolean
reactElementToJSXStringOptions?: ReactElementToJSXStringOptions
}

export const getOptions = ({
url = 'http://localhost:9000',
code = '',
disable = false,
includeDecorators = false,
reactElementToJSXStringOptions = { sortProps: false },
}: Options = {}): Required<Options> => ({
url,
code,
disable,
includeDecorators,
reactElementToJSXStringOptions,
})
10 changes: 7 additions & 3 deletions src/withGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ export const withGlobals = (
StoryFn: StoryFunction<Renderer>,
context: StoryContext<Renderer>,
) => {
const { parameters } = context
const { parameters, undecoratedStoryFn } = context
const playroomConfig = parameters[PARAM_KEY]
const { url, code, reactElementToJSXStringOptions } =
const { url, code, includeDecorators, reactElementToJSXStringOptions } =
getOptions(playroomConfig)
const story = StoryFn() as ReactElement
const storyCode = includeDecorators
? story
: (undecoratedStoryFn(context) as ReactElement)

const jsxString =
code || reactElementToJSXString(story, reactElementToJSXStringOptions)
code || reactElementToJSXString(storyCode, reactElementToJSXStringOptions)
const codeUrl = url && createUrl({ baseUrl: url, code: jsxString })

const emit = useChannel({})
Expand Down

0 comments on commit 3c1aa4c

Please sign in to comment.