-
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 'main' into strict-mode-fixes
- Loading branch information
Showing
9 changed files
with
110 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2020 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
import {ProviderContext} from '@react-types/provider'; | ||
import React from 'react'; | ||
|
||
// Context is placed in a separate file to avoid fast refresh issue where the old provider context values | ||
// are immediately replaced with the null default. Stopgap solution until we fix this in parcel. | ||
export const Context = React.createContext<ProviderContext | null>(null); | ||
Context.displayName = 'ProviderContext'; |
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