|
1 | 1 | import React, {useEffect, useState} from 'react';
|
2 | 2 | import {addons} from '@storybook/preview-api';
|
3 | 3 | import {makeDecorator} from '@storybook/preview-api';
|
4 |
| -import {getQueryParams} from '@storybook/preview-api'; |
5 | 4 | import {Provider} from '@react-spectrum/provider';
|
6 | 5 | import {expressThemes, themes, defaultTheme} from '../../constants';
|
7 | 6 |
|
8 | 7 | document.body.style.margin = '0';
|
9 | 8 |
|
10 |
| -const providerValuesFromUrl = Object.entries(getQueryParams()).reduce((acc, [k, v]) => { |
11 |
| - if (k.includes('providerSwitcher-')) { |
12 |
| - return { ...acc, [k.replace('providerSwitcher-', '')]: v }; |
13 |
| - } |
14 |
| - return acc; |
15 |
| -}, {}); |
16 |
| - |
17 | 9 | function ProviderUpdater(props) {
|
18 |
| - let [localeValue, setLocale] = useState(providerValuesFromUrl.locale || undefined); |
19 |
| - let [themeValue, setTheme] = useState(providerValuesFromUrl.theme || undefined); |
20 |
| - let [scaleValue, setScale] = useState(providerValuesFromUrl.scale || undefined); |
21 |
| - let [expressValue, setExpress] = useState(providerValuesFromUrl.express === 'true'); |
| 10 | + let params = new URLSearchParams(document.location.search); |
| 11 | + let localeParam = params.get("providerSwitcher-locale") || undefined; |
| 12 | + let [localeValue, setLocale] = useState(localeParam); |
| 13 | + let themeParam = params.get("providerSwitcher-theme") || undefined; |
| 14 | + let [themeValue, setTheme] = useState(themeParam); |
| 15 | + let scaleParam = params.get("providerSwitcher-scale") || undefined; |
| 16 | + let [scaleValue, setScale] = useState(scaleParam); |
| 17 | + let expressParam = params.get("providerSwitcher-express") || undefined; |
| 18 | + let [expressValue, setExpress] = useState(expressParam === 'true'); |
22 | 19 | let [storyReady, setStoryReady] = useState(window.parent === window || window.parent !== window.top); // reduce content flash because it takes a moment to get the provider details
|
23 | 20 | // Typically themes are provided with both light + dark, and both scales.
|
24 | 21 | // To build our selector to see all themes, we need to hack it a bit.
|
|
0 commit comments