@storybook/react-native-ui-common 10.2.2-alpha.0 → 10.2.2-alpha.1
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.
- package/dist/index.d.ts +2 -1
- package/dist/index.js +27 -0
- package/package.json +3 -3
- package/src/hooks/useStoreState.ts +34 -1
package/dist/index.d.ts
CHANGED
|
@@ -193,5 +193,6 @@ declare const useLastViewed: (selection: Selection) => {
|
|
|
193
193
|
};
|
|
194
194
|
|
|
195
195
|
declare const useStoreBooleanState: (key: string, defaultValue: boolean) => ReturnType<typeof useState<boolean>>;
|
|
196
|
+
declare const useStoreNumberState: (key: string, defaultValue: number) => [number, (value: number | ((prev: number) => number)) => void];
|
|
196
197
|
|
|
197
|
-
export { Button, ButtonIcon, type ButtonProps, ButtonText, type CombinedDataset, type Dataset, type ExpandAction, type ExpandType, type ExpandedProps, type ExpandedState, type GetSearchItemProps, type Highlight, type HighlightRange, type HighlightRanges, IconButton, type Item, type ItemRef, LayoutProvider, type RefType, type Refs, type SBUI, type SearchChildrenFn, type SearchItem, type SearchResult, type SearchResultProps, type Selection, type Storage, StorageProvider, type StoryRef, createId, cycle, get, getAncestorIds, getDescendantIds, getParent, getParents, getPath, getStateType, intersect, isAncestor, isExpandType, isStoryHoistable, merge, noArrayMerge, prevent, removeNoiseFromName, searchItem, transformStoryIndexToStoriesHash, transformStoryIndexV2toV3, transformStoryIndexV3toV4, transformStoryIndexV4toV5, useExpanded, useLastViewed, useLayout, useStorage, useStoreBooleanState, useStyle };
|
|
198
|
+
export { Button, ButtonIcon, type ButtonProps, ButtonText, type CombinedDataset, type Dataset, type ExpandAction, type ExpandType, type ExpandedProps, type ExpandedState, type GetSearchItemProps, type Highlight, type HighlightRange, type HighlightRanges, IconButton, type Item, type ItemRef, LayoutProvider, type RefType, type Refs, type SBUI, type SearchChildrenFn, type SearchItem, type SearchResult, type SearchResultProps, type Selection, type Storage, StorageProvider, type StoryRef, createId, cycle, get, getAncestorIds, getDescendantIds, getParent, getParents, getPath, getStateType, intersect, isAncestor, isExpandType, isStoryHoistable, merge, noArrayMerge, prevent, removeNoiseFromName, searchItem, transformStoryIndexToStoriesHash, transformStoryIndexV2toV3, transformStoryIndexV3toV4, transformStoryIndexV4toV5, useExpanded, useLastViewed, useLayout, useStorage, useStoreBooleanState, useStoreNumberState, useStyle };
|
package/dist/index.js
CHANGED
|
@@ -62,6 +62,7 @@ __export(index_exports, {
|
|
|
62
62
|
useLayout: () => useLayout,
|
|
63
63
|
useStorage: () => useStorage,
|
|
64
64
|
useStoreBooleanState: () => useStoreBooleanState,
|
|
65
|
+
useStoreNumberState: () => useStoreNumberState,
|
|
65
66
|
useStyle: () => useStyle
|
|
66
67
|
});
|
|
67
68
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -664,6 +665,31 @@ var useStoreBooleanState = (key, defaultValue) => {
|
|
|
664
665
|
}, [key, storage, val]);
|
|
665
666
|
return [val, setVal];
|
|
666
667
|
};
|
|
668
|
+
var useStoreNumberState = (key, defaultValue) => {
|
|
669
|
+
const storage = useStorage();
|
|
670
|
+
const [val, setVal] = (0, import_react8.useState)(defaultValue);
|
|
671
|
+
(0, import_react8.useEffect)(() => {
|
|
672
|
+
storage.getItem(key).then((newVal) => {
|
|
673
|
+
if (newVal === null || newVal === void 0) {
|
|
674
|
+
setVal(defaultValue);
|
|
675
|
+
} else {
|
|
676
|
+
const parsed = parseFloat(newVal);
|
|
677
|
+
setVal(isNaN(parsed) ? defaultValue : parsed);
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
}, [key, storage, defaultValue]);
|
|
681
|
+
const setAndStore = (0, import_react8.useCallback)(
|
|
682
|
+
(value) => {
|
|
683
|
+
setVal((prev) => {
|
|
684
|
+
const next = typeof value === "function" ? value(prev) : value;
|
|
685
|
+
storage.setItem(key, next.toString());
|
|
686
|
+
return next;
|
|
687
|
+
});
|
|
688
|
+
},
|
|
689
|
+
[key, storage]
|
|
690
|
+
);
|
|
691
|
+
return [val, setAndStore];
|
|
692
|
+
};
|
|
667
693
|
// Annotate the CommonJS export names for ESM import in node:
|
|
668
694
|
0 && (module.exports = {
|
|
669
695
|
Button,
|
|
@@ -699,5 +725,6 @@ var useStoreBooleanState = (key, defaultValue) => {
|
|
|
699
725
|
useLayout,
|
|
700
726
|
useStorage,
|
|
701
727
|
useStoreBooleanState,
|
|
728
|
+
useStoreNumberState,
|
|
702
729
|
useStyle
|
|
703
730
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/react-native-ui-common",
|
|
3
|
-
"version": "10.2.2-alpha.
|
|
3
|
+
"version": "10.2.2-alpha.1",
|
|
4
4
|
"description": "common ui components for react native storybook",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@nozbe/microfuzz": "^1.0.0",
|
|
41
41
|
"@storybook/react": "^10.2.2",
|
|
42
|
-
"@storybook/react-native-theming": "^10.2.2-alpha.
|
|
42
|
+
"@storybook/react-native-theming": "^10.2.2-alpha.1",
|
|
43
43
|
"es-toolkit": "^1.41.0",
|
|
44
44
|
"memoizerific": "^1.11.3",
|
|
45
45
|
"ts-dedent": "^2.2.0"
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "900db1ac2a226eb8206cc89b7142d1ea50272a9e"
|
|
59
59
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
2
|
import { useStorage } from '../StorageProvider';
|
|
3
3
|
|
|
4
4
|
export const useStoreBooleanState = (
|
|
@@ -25,3 +25,36 @@ export const useStoreBooleanState = (
|
|
|
25
25
|
|
|
26
26
|
return [val, setVal];
|
|
27
27
|
};
|
|
28
|
+
|
|
29
|
+
export const useStoreNumberState = (
|
|
30
|
+
key: string,
|
|
31
|
+
defaultValue: number
|
|
32
|
+
): [number, (value: number | ((prev: number) => number)) => void] => {
|
|
33
|
+
const storage = useStorage();
|
|
34
|
+
|
|
35
|
+
const [val, setVal] = useState<number>(defaultValue);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
storage.getItem(key).then((newVal) => {
|
|
39
|
+
if (newVal === null || newVal === undefined) {
|
|
40
|
+
setVal(defaultValue);
|
|
41
|
+
} else {
|
|
42
|
+
const parsed = parseFloat(newVal);
|
|
43
|
+
setVal(isNaN(parsed) ? defaultValue : parsed);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}, [key, storage, defaultValue]);
|
|
47
|
+
|
|
48
|
+
const setAndStore = useCallback(
|
|
49
|
+
(value: number | ((prev: number) => number)) => {
|
|
50
|
+
setVal((prev) => {
|
|
51
|
+
const next = typeof value === 'function' ? value(prev) : value;
|
|
52
|
+
storage.setItem(key, next.toString());
|
|
53
|
+
return next;
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
[key, storage]
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return [val, setAndStore];
|
|
60
|
+
};
|