-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'strict-mode-fixes' of github.com:adobe/react-spectrum i…
…nto focusscope_strict_mode_fix
- Loading branch information
Showing
35 changed files
with
543 additions
and
365 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,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> | ||
) : children; | ||
} | ||
|
||
export const withStrictModeSwitcher = makeDecorator({ | ||
name: 'withStrictModeSwitcher', | ||
parameterName: 'strictModeSwitcher', | ||
wrapper: (getStory, context) => { | ||
return ( | ||
<StrictModeDecorator> | ||
{getStory(context)} | ||
</StrictModeDecorator> | ||
); | ||
} | ||
}); |
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,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 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
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"remove": "Remove" | ||
"remove": "Press Space or Delete to remove tag." | ||
} |
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
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
Oops, something went wrong.