react-cosmos-renderer 6.0.3 → 6.0.4-canary.2314a55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,6 +4,10 @@ import { useSetValue } from './useSetValue.js';
|
|
|
4
4
|
export function useSelect(selectName, args) {
|
|
5
5
|
if (!args || !args.options || !args.options.length)
|
|
6
6
|
throw new Error('No options provided to useSelect');
|
|
7
|
+
if (typeof args.options[0] === 'object') {
|
|
8
|
+
if (!args.options[0].options.length)
|
|
9
|
+
throw new Error('No options provided to useSelect');
|
|
10
|
+
}
|
|
7
11
|
useCreateFixtureState(selectName, args);
|
|
8
12
|
const currentValue = useCurrentValue(selectName, args);
|
|
9
13
|
const setValue = useSetValue(selectName);
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
type GroupedOptions<Option extends string> = {
|
|
2
|
+
group: string;
|
|
2
3
|
options: Option[];
|
|
4
|
+
};
|
|
5
|
+
export type UseSelectArgs<Option extends string> = {
|
|
6
|
+
options: Option[] | GroupedOptions<Option>[];
|
|
3
7
|
defaultValue?: Option;
|
|
4
8
|
};
|
|
5
9
|
export type SetSelectValue<Option extends string> = (value: Option) => void;
|
|
6
10
|
export declare function getDefaultSelectValue<Option extends string>({ options, defaultValue, }: UseSelectArgs<Option>): Option;
|
|
11
|
+
export {};
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
export function getDefaultSelectValue({ options, defaultValue, }) {
|
|
2
|
-
|
|
2
|
+
if (typeof defaultValue === 'string') {
|
|
3
|
+
return defaultValue;
|
|
4
|
+
}
|
|
5
|
+
const [firstOption] = options;
|
|
6
|
+
if (typeof firstOption === 'object') {
|
|
7
|
+
return firstOption.options[0];
|
|
8
|
+
}
|
|
9
|
+
return firstOption;
|
|
3
10
|
}
|
|
@@ -25,5 +25,5 @@ export function useCreateFixtureState(selectName, args) {
|
|
|
25
25
|
};
|
|
26
26
|
});
|
|
27
27
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
|
-
}, [
|
|
28
|
+
}, [JSON.stringify(args.options), defaultValue, selectName, setFixtureState]);
|
|
29
29
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos-renderer",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.4-canary.2314a55.0+2314a55",
|
|
4
4
|
"description": "React Cosmos Renderer",
|
|
5
5
|
"repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-renderer",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"lodash-es": "4.17.21",
|
|
15
|
-
"react-cosmos-core": "
|
|
15
|
+
"react-cosmos-core": "6.0.4-canary.2314a55.0+2314a55",
|
|
16
16
|
"react-is": "18.2.0"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "2314a552ecb325a7601415058f5dac67df41fe41"
|
|
19
19
|
}
|