-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Enable strict mode in storybook on a per story basis #3333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6322a8f
add checkbox to enable strict mode on a story by story basis
LFDanLu 5f08d97
checkbox for strict
LFDanLu 72bb886
Merge branch 'main' of github.com:adobe/react-spectrum into strict_mo…
LFDanLu 002ff44
getting rid of storybook globals in favor of state
LFDanLu e829d36
me dumb, me forget to convert to boolean
LFDanLu ed3f5bd
removing style
LFDanLu 1e23c66
Merge branch 'main' into strict_mode_per_story
LFDanLu 0b024a0
Merge branch 'main' of github.com:adobe/react-spectrum into strict_mo…
LFDanLu 96f2478
Merge branch 'main' of github.com:adobe/react-spectrum into strict_mo…
LFDanLu a91afbc
Merge branch 'main' into strict_mode_per_story
snowystinger 9fe0a6f
Merge branch 'main' into strict_mode_per_story
LFDanLu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,37 @@ | ||
| import {addons, makeDecorator} from '@storybook/addons'; | ||
| import {getQueryParams} from '@storybook/client-api'; | ||
| import React, {StrictMode, useEffect, useState} from 'react'; | ||
|
|
||
| function StrictModeDecorator(props) { | ||
| let {children} = props; | ||
| let [isStrict, setStrict] = useState(getQueryParams()?.strict === 'true' || false); | ||
|
|
||
| useEffect(() => { | ||
| let channel = addons.getChannel(); | ||
| let updateStrict = (val) => { | ||
| setStrict(val); | ||
| }; | ||
| channel.on('strict/updated', updateStrict); | ||
| return () => { | ||
| channel.removeListener('strict/updated', updateStrict); | ||
| }; | ||
| }, []); | ||
|
|
||
| return isStrict ? ( | ||
| <StrictMode> | ||
| {children} | ||
| </StrictMode> | ||
|
LFDanLu marked this conversation as resolved.
|
||
| ) : children; | ||
| } | ||
|
|
||
| export const withStrictModeSwitcher = makeDecorator({ | ||
| name: 'withStrictModeSwitcher', | ||
| parameterName: 'strictModeSwitcher', | ||
| wrapper: (getStory, context) => { | ||
| return ( | ||
| <StrictModeDecorator> | ||
| {getStory(context)} | ||
| </StrictModeDecorator> | ||
| ); | ||
| } | ||
| }); | ||
This file contains hidden or 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,40 @@ | ||
| import {addons, types} from '@storybook/addons'; | ||
| import {getQueryParams} from '@storybook/client-api'; | ||
| import React, {useEffect, useState} from 'react'; | ||
|
|
||
| const StrictModeToolBar = ({api}) => { | ||
| let channel = addons.getChannel(); | ||
| let [isStrict, setStrict] = useState(getQueryParams()?.strict === 'true' || false); | ||
| let onChange = () => { | ||
| setStrict((old) => { | ||
| channel.emit('strict/updated', !old); | ||
| return !old; | ||
| }) | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| api.setQueryParams({ | ||
| 'strict': isStrict | ||
| }); | ||
| }); | ||
|
|
||
| return ( | ||
| <div style={{display: 'flex', alignItems: 'center', fontSize: '12px'}}> | ||
| <div style={{marginRight: '10px'}}> | ||
| <label htmlFor="strictmode">StrictMode: | ||
| <input type="checkbox" id="strictmode" name="strictmode" checked={isStrict} onChange={onChange} /> | ||
| </label> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| addons.register('StrictModeSwitcher', (api) => { | ||
| addons.add('StrictModeSwitcher', { | ||
| title: 'Strict mode switcher', | ||
| type: types.TOOL, | ||
| //👇 Shows the Toolbar UI element if either the Canvas or Docs tab is active | ||
| match: ({ viewMode }) => !!(viewMode && viewMode.match(/^(story|docs)$/)), | ||
| render: () => <StrictModeToolBar api={api} /> | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would've like to used the storybook globals but for some reason it stopped working