@storybook/react-native 6.5.4 → 6.5.5-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.
Files changed (43) hide show
  1. package/dist/hooks.d.ts +6 -5
  2. package/dist/hooks.js +24 -5
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +3 -3
  5. package/dist/preview/View.d.ts +2 -3
  6. package/dist/preview/View.js +7 -34
  7. package/dist/preview/components/OnDeviceUI/OnDeviceUI.d.ts +1 -1
  8. package/dist/preview/components/OnDeviceUI/OnDeviceUI.js +9 -24
  9. package/dist/preview/components/OnDeviceUI/Panel.d.ts +1 -1
  10. package/dist/preview/components/OnDeviceUI/Panel.js +2 -1
  11. package/dist/preview/components/OnDeviceUI/absolute-positioned-keyboard-aware-view.d.ts +1 -1
  12. package/dist/preview/components/OnDeviceUI/absolute-positioned-keyboard-aware-view.js +3 -3
  13. package/dist/preview/components/OnDeviceUI/addons/Addons.d.ts +1 -1
  14. package/dist/preview/components/OnDeviceUI/addons/Addons.js +4 -7
  15. package/dist/preview/components/OnDeviceUI/addons/AddonsSkeleton.js +7 -16
  16. package/dist/preview/components/OnDeviceUI/addons/List.d.ts +1 -1
  17. package/dist/preview/components/OnDeviceUI/addons/List.js +6 -5
  18. package/dist/preview/components/OnDeviceUI/addons/Wrapper.d.ts +1 -1
  19. package/dist/preview/components/OnDeviceUI/addons/Wrapper.js +3 -3
  20. package/dist/preview/components/OnDeviceUI/navigation/Navigation.d.ts +1 -1
  21. package/dist/preview/components/OnDeviceUI/navigation/Navigation.js +4 -8
  22. package/dist/preview/components/OnDeviceUI/navigation/NavigationBar.d.ts +1 -1
  23. package/dist/preview/components/OnDeviceUI/navigation/NavigationBar.js +2 -4
  24. package/dist/preview/components/OnDeviceUI/navigation/NavigationButton.d.ts +2 -3
  25. package/dist/preview/components/OnDeviceUI/navigation/NavigationButton.js +4 -10
  26. package/dist/preview/components/Shared/icons.d.ts +22 -4
  27. package/dist/preview/components/Shared/icons.js +12 -5
  28. package/dist/preview/components/Shared/layout.d.ts +15 -1
  29. package/dist/preview/components/Shared/layout.js +4 -24
  30. package/dist/preview/components/Shared/tabs.d.ts +2 -2
  31. package/dist/preview/components/Shared/tabs.js +6 -7
  32. package/dist/preview/components/StoryListView/StoryListView.d.ts +1 -1
  33. package/dist/preview/components/StoryListView/StoryListView.js +54 -59
  34. package/dist/preview/components/StoryListView/getNestedStories.d.ts +10 -0
  35. package/dist/preview/components/StoryListView/getNestedStories.js +95 -0
  36. package/dist/preview/components/StoryListView/getNestedStories.test.d.ts +1 -0
  37. package/dist/preview/components/StoryListView/getNestedStories.test.js +237 -0
  38. package/dist/preview/components/StoryView/StoryView.d.ts +1 -1
  39. package/dist/preview/components/StoryView/StoryView.js +3 -3
  40. package/dist/preview/start.js +2 -2
  41. package/package.json +10 -6
  42. package/dist/preview/components/Shared/theme.d.ts +0 -189
  43. package/dist/preview/components/Shared/theme.js +0 -321
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { Image, ImageBackground, ImageBackgroundProps, ImageStyle } from 'react-native';
2
3
  declare const iconSources: {
3
4
  grid: {
4
5
  uri: string;
@@ -24,12 +25,29 @@ declare const iconSources: {
24
25
  'layout-split-inverse': {
25
26
  uri: string;
26
27
  };
28
+ folder: {
29
+ uri: string;
30
+ };
27
31
  };
28
32
  export type IconName = keyof typeof iconSources;
29
- declare const StyledImage: any;
30
- interface IconProps extends React.ComponentProps<typeof StyledImage> {
33
+ declare const StyledImage: import("@emotion/native").StyledComponent<import("react-native").ImageProps & {
34
+ theme?: import("@emotion/react").Theme;
35
+ as?: React.ElementType<any>;
36
+ } & ImageStyle & ImageBackgroundProps, {}, {
37
+ ref?: React.Ref<Image>;
38
+ }>;
39
+ declare const StyledImageBackground: import("@emotion/native").StyledComponent<ImageBackgroundProps & {
40
+ theme?: import("@emotion/react").Theme;
41
+ as?: React.ElementType<any>;
42
+ } & ImageStyle, {}, {
43
+ ref?: React.Ref<ImageBackground>;
44
+ }>;
45
+ interface IconProps extends Omit<React.ComponentProps<typeof StyledImage>, 'source'> {
46
+ name: IconName;
47
+ }
48
+ export declare function Icon({ name, ...props }: IconProps): import("react/jsx-runtime").JSX.Element;
49
+ interface BackgroungIconProps extends Omit<React.ComponentProps<typeof StyledImageBackground>, 'source'> {
31
50
  name: IconName;
32
- background?: boolean;
33
51
  }
34
- export declare function Icon({ name, background, ...props }: IconProps): JSX.Element;
52
+ export declare function BackgroundIcon({ name, ...props }: BackgroungIconProps): import("react/jsx-runtime").JSX.Element;
35
53
  export {};
@@ -25,8 +25,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
25
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
26
  };
27
27
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.Icon = void 0;
29
- var react_1 = __importDefault(require("react"));
28
+ exports.BackgroundIcon = exports.Icon = void 0;
29
+ var jsx_runtime_1 = require("react/jsx-runtime");
30
30
  var react_native_1 = require("react-native");
31
31
  var native_1 = __importDefault(require("@emotion/native"));
32
32
  var iconSources = {
@@ -54,12 +54,19 @@ var iconSources = {
54
54
  'layout-split-inverse': {
55
55
  uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAEaSURBVHgB7ZntDYJADIaLcQBGYARHgAl0I0YQJ8BNdAPZ4BzBDWov8ENrkYuJtJA+SUO4D/K+1yaQAuA4jmMaRCwpjhQB5+NG0VIU8Cu0OR+EaxM15GM6szHxdLlQ7MAGHUWVZdmDT2xGNtRgR3wkaqmliY8MYF93AWwSs3B9HZAyUINdDnxAMmCpdDh7PiCVEIJhqITeNG9g4bgBbdyANm5AGzegzeINbKcW8Ff33Ex92ngJaeMGtHED2rgBbdZv4FtbzwKSgTu7V2uz0OHxPlCXsqlhzdWgkQXsm8uBaWlTNpZChzgIp/EXBuElyu38IvUhDdqjkbSus70+LKwoTqBP1CCKT4KyUVCcsf/tMxcB+zIuwXEcxzRPpfGo9y3IYogAAAAASUVORK5CYII=',
56
56
  },
57
+ folder: {
58
+ uri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAuIwAALiMBeKU/dgAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAHTSURBVGiB7Zk7LwRRGIbf7wwRRIJGlDSEpdmI6Fw6lRWZXiJ0lkZUsn8A2dD5B0MhkS1UepGIXZu4hsKlJASxyZyjoJAx4uzutztjc57yXN58T+Z8M5kZoEKg2R4nSpL6IdCQ72YlhQLh3LLc/dUj+7YUBepC8ciWYshxidSy+1a/tHYx+s6QlzeCKcdSihZEzWtqfsCpZcrMCy6RTwgj8knsBCHDKwIEJsPVI36cKOCGK4ygnkHYbcpkNxJISO98lc+eR4Au9eJVG4DmXyY7CejUrvRPCFCIPUQifTjG1I9ZnyuynTyeiOlEx3udDkixB6CVo1RdXCHb19P21fexonokmbZPIeQQgPuiKssTS1K3d6zoZg9Choh+tATLXSuZtk8tSwyC1B1HXiH4NXtBrByNn8V7nWFIMcmVCVJzAGp0lrKJAF/HDFjkyotHtmagKcL/QAwIIxI2jEjYMCJhw4iEDSMSNoxI2DAiYcOIhI2KEfF71W2c7XGiZa/EDwVLd6mfyCApccBYTlmomKNlRAJFymvv0P8TIRzediHjHRYAMgBK9Y+EkxygUpBybHPTdr2TBADT0Z06K/ek9UUvKFpk9Usia+eCrsNgMBgMBkM5+ADkCHptw04GlAAAAABJRU5ErkJggg==',
59
+ },
57
60
  };
58
61
  var StyledImage = (0, native_1.default)(react_native_1.Image)();
59
62
  var StyledImageBackground = (0, native_1.default)(react_native_1.ImageBackground)();
60
63
  function Icon(_a) {
61
- var name = _a.name, _b = _a.background, background = _b === void 0 ? false : _b, props = __rest(_a, ["name", "background"]);
62
- var IconComponent = background ? StyledImageBackground : StyledImage;
63
- return (react_1.default.createElement(IconComponent, __assign({ source: __assign(__assign({}, iconSources[name]), { width: 16, height: 16 }) }, props)));
64
+ var name = _a.name, props = __rest(_a, ["name"]);
65
+ return ((0, jsx_runtime_1.jsx)(StyledImage, __assign({ source: __assign(__assign({}, iconSources[name]), { width: 16, height: 16 }) }, props)));
64
66
  }
65
67
  exports.Icon = Icon;
68
+ function BackgroundIcon(_a) {
69
+ var name = _a.name, props = __rest(_a, ["name"]);
70
+ return ((0, jsx_runtime_1.jsx)(StyledImageBackground, __assign({ source: __assign(__assign({}, iconSources[name]), { width: 16, height: 16 }) }, props)));
71
+ }
72
+ exports.BackgroundIcon = BackgroundIcon;
@@ -1,3 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { ViewProps, ViewStyle } from 'react-native';
3
+ interface BoxProps extends ViewProps, Omit<ViewStyle, 'flex'> {
4
+ /**
5
+ * Flex value, can be `true` to mean the commonly used `flex={1}`.
6
+ */
7
+ flex?: boolean | number;
8
+ }
1
9
  /**
2
10
  * A general (flex)box layout component that accepts props for flexbox layout
3
11
  * styles, such as `flex`, `alignItems`, `marginVertical`, etc.
@@ -9,4 +17,10 @@
9
17
  * </Box>
10
18
  * ```
11
19
  */
12
- export declare const Box: any;
20
+ export declare const Box: import("@emotion/native").StyledComponent<ViewProps & {
21
+ theme?: import("@emotion/react").Theme;
22
+ as?: import("react").ElementType<any>;
23
+ } & BoxProps, {}, {
24
+ ref?: import("react").Ref<import("react-native").View>;
25
+ }>;
26
+ export {};
@@ -1,26 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __rest = (this && this.__rest) || function (s, e) {
14
- var t = {};
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
- t[p] = s[p];
17
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
- t[p[i]] = s[p[i]];
21
- }
22
- return t;
23
- };
24
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
25
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
4
  };
@@ -39,6 +17,8 @@ var native_1 = __importDefault(require("@emotion/native"));
39
17
  * ```
40
18
  */
41
19
  exports.Box = native_1.default.View(function (_a) {
42
- var flex = _a.flex, layoutProps = __rest(_a, ["flex"]);
43
- return (__assign({ flex: flex === true ? 1 : flex === false ? 0 : flex }, layoutProps));
20
+ var flex = _a.flex;
21
+ return ({
22
+ flex: flex === true ? 1 : flex === false ? 0 : flex,
23
+ });
44
24
  });
@@ -7,7 +7,7 @@ interface TabButtonProps {
7
7
  testID?: string;
8
8
  children: React.ReactNode;
9
9
  }
10
- export declare const TabButton: React.MemoExoticComponent<({ onPress, id, active, children, testID }: TabButtonProps) => JSX.Element>;
10
+ export declare const TabButton: React.MemoExoticComponent<({ onPress, id, active, children, testID }: TabButtonProps) => import("react/jsx-runtime").JSX.Element>;
11
11
  interface TabBarProps {
12
12
  /**
13
13
  * Should the tab bar contents scroll horizontally?
@@ -16,5 +16,5 @@ interface TabBarProps {
16
16
  style?: StyleProp<ViewStyle>;
17
17
  children: React.ReactNode;
18
18
  }
19
- export declare const TabBar: React.MemoExoticComponent<({ scrollable, style, children }: TabBarProps) => JSX.Element>;
19
+ export declare const TabBar: React.MemoExoticComponent<({ scrollable, style, children }: TabBarProps) => import("react/jsx-runtime").JSX.Element>;
20
20
  export {};
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.TabBar = exports.TabButton = void 0;
7
+ var jsx_runtime_1 = require("react/jsx-runtime");
7
8
  var react_1 = __importDefault(require("react"));
8
9
  var react_native_1 = require("react-native");
9
10
  var native_1 = __importDefault(require("@emotion/native"));
@@ -30,20 +31,18 @@ var TabButtonTouchable = native_1.default.TouchableOpacity(function (_a) {
30
31
  });
31
32
  exports.TabButton = react_1.default.memo(function (_a) {
32
33
  var onPress = _a.onPress, id = _a.id, active = _a.active, children = _a.children, testID = _a.testID;
33
- return (react_1.default.createElement(TabButtonTouchable, { active: active, testID: testID, onPress: function () { return onPress(id); }, activeOpacity: 0.8, hitSlop: hitSlop },
34
- react_1.default.createElement(TabButtonText, { active: active }, children)));
34
+ return ((0, jsx_runtime_1.jsx)(TabButtonTouchable, { active: active, testID: testID, onPress: function () { return onPress(id); }, activeOpacity: 0.8, hitSlop: hitSlop, children: (0, jsx_runtime_1.jsx)(TabButtonText, { active: active, children: children }) }));
35
35
  });
36
36
  exports.TabBar = react_1.default.memo(function (_a) {
37
37
  var _b = _a.scrollable, scrollable = _b === void 0 ? false : _b, style = _a.style, children = _a.children;
38
38
  var theme = (0, hooks_1.useTheme)();
39
39
  if (scrollable) {
40
- children = (react_1.default.createElement(react_native_1.ScrollView, { showsHorizontalScrollIndicator: false, horizontal: true, contentContainerStyle: { paddingHorizontal: theme.tokens.spacing2 } }, children));
40
+ children = ((0, jsx_runtime_1.jsx)(react_native_1.ScrollView, { showsHorizontalScrollIndicator: false, horizontal: true, contentContainerStyle: { paddingHorizontal: theme.tokens.spacing2 }, children: children }));
41
41
  }
42
- return (react_1.default.createElement(react_native_1.View, { style: style },
43
- react_1.default.createElement(TabBarContainer, null, children)));
42
+ return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: style, children: (0, jsx_runtime_1.jsx)(TabBarContainer, { children: children }) }));
44
43
  });
45
- var TabBarContainer = native_1.default.View({
44
+ var TabBarContainer = native_1.default.View(function () { return ({
46
45
  flexDirection: 'row',
47
46
  paddingVertical: 6,
48
47
  justifyItems: 'center',
49
- });
48
+ }); });
@@ -3,5 +3,5 @@ import React from 'react';
3
3
  interface Props {
4
4
  storyIndex: StoryIndex;
5
5
  }
6
- declare const _default: React.MemoExoticComponent<({ storyIndex }: Props) => JSX.Element>;
6
+ declare const _default: React.MemoExoticComponent<({ storyIndex }: Props) => import("react/jsx-runtime").JSX.Element>;
7
7
  export default _default;
@@ -37,20 +37,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
+ var jsx_runtime_1 = require("react/jsx-runtime");
40
41
  var native_1 = __importDefault(require("@emotion/native"));
41
42
  var addons_1 = require("@storybook/addons");
42
43
  var core_events_1 = __importDefault(require("@storybook/core-events"));
43
44
  var react_1 = __importStar(require("react"));
44
45
  var react_native_1 = require("react-native");
46
+ var hooks_1 = require("../../../hooks");
45
47
  var icons_1 = require("../Shared/icons");
46
48
  var layout_1 = require("../Shared/layout");
47
- var hooks_1 = require("../../../hooks");
49
+ var getNestedStories_1 = require("./getNestedStories");
48
50
  var SectionHeaderText = native_1.default.Text(function (_a) {
49
51
  var theme = _a.theme;
50
52
  return ({
51
53
  fontSize: theme.storyList.fontSize,
52
54
  color: theme.storyList.headerTextColor,
53
55
  fontWeight: theme.storyList.headerFontWeight,
56
+ flexShrink: 1,
54
57
  });
55
58
  });
56
59
  var StoryNameText = native_1.default.Text(function (_a) {
@@ -86,15 +89,13 @@ var SearchContainer = native_1.default.View(function (_a) {
86
89
  });
87
90
  var SearchBar = function (props) {
88
91
  var theme = (0, hooks_1.useTheme)();
89
- return (react_1.default.createElement(SearchContainer, null,
90
- react_1.default.createElement(icons_1.Icon, { name: "search", opacity: 0.5, color: 'white' }),
91
- react_1.default.createElement(SearchInput, __assign({}, props, { autoCapitalize: "none", autoComplete: "off", autoCorrect: false, spellCheck: false, clearButtonMode: "while-editing", disableFullscreenUI: true, placeholderTextColor: theme.storyList.search.placeholderTextColor, returnKeyType: "search" }))));
92
+ return ((0, jsx_runtime_1.jsxs)(SearchContainer, { children: [(0, jsx_runtime_1.jsx)(icons_1.Icon, { name: "search", opacity: 0.5 }), (0, jsx_runtime_1.jsx)(SearchInput, __assign({}, props, { autoCapitalize: "none", autoComplete: "off", autoCorrect: false, spellCheck: false, clearButtonMode: "while-editing", disableFullscreenUI: true, placeholderTextColor: theme.storyList.search.placeholderTextColor, returnKeyType: "search" }))] }));
92
93
  };
93
94
  var HeaderContainer = native_1.default.TouchableOpacity({
94
95
  flexDirection: 'row',
95
96
  alignItems: 'center',
96
97
  }, function (_a) {
97
- var selected = _a.selected, theme = _a.theme;
98
+ var selected = _a.selected, theme = _a.theme, childSelected = _a.childSelected;
98
99
  return ({
99
100
  marginTop: theme.storyList.sectionSpacing,
100
101
  paddingHorizontal: theme.storyList.headerPaddingHorizontal,
@@ -102,14 +103,19 @@ var HeaderContainer = native_1.default.TouchableOpacity({
102
103
  backgroundColor: selected ? theme.storyList.sectionActiveBackgroundColor : undefined,
103
104
  borderTopLeftRadius: theme.storyList.sectionBorderRadius,
104
105
  borderTopRightRadius: theme.storyList.sectionBorderRadius,
106
+ borderBottomLeftRadius: selected && !childSelected ? theme.storyList.sectionBorderRadius : undefined,
107
+ borderBottomRightRadius: selected && !childSelected ? theme.storyList.sectionBorderRadius : undefined,
105
108
  });
106
109
  });
107
110
  var SectionHeader = react_1.default.memo(function (_a) {
108
- var title = _a.title, onPress = _a.onPress;
109
- var selected = (0, hooks_1.useIsStorySectionSelected)(title);
110
- return (react_1.default.createElement(HeaderContainer, { key: title, selected: selected, onPress: onPress, activeOpacity: 0.8 },
111
- react_1.default.createElement(icons_1.Icon, { name: "grid", width: 12, height: 12, marginRight: 6 }),
112
- react_1.default.createElement(SectionHeaderText, { selected: selected }, title)));
111
+ var name = _a.name, onPress = _a.onPress, isChildSelected = _a.isChildSelected, _b = _a.icon, icon = _b === void 0 ? 'grid' : _b, expanded = _a.expanded;
112
+ var selected = (0, hooks_1.useIsStorySectionSelected)(name) || isChildSelected;
113
+ return ((0, jsx_runtime_1.jsxs)(HeaderContainer, { selected: selected, childSelected: isChildSelected, onPress: onPress, activeOpacity: 0.8, children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: {
114
+ transform: [{ rotate: expanded ? '90deg' : '0deg' }],
115
+ marginRight: 6,
116
+ alignItems: 'center',
117
+ justifyContent: 'center',
118
+ }, children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: { fontSize: 8, color: 'grey', lineHeight: 8 }, children: '➤' }) }), (0, jsx_runtime_1.jsx)(icons_1.Icon, { name: icon, width: 12, height: 12, marginRight: 6 }), (0, jsx_runtime_1.jsx)(SectionHeaderText, { numberOfLines: 2, selected: selected, children: name })] }, name));
113
119
  });
114
120
  var ItemTouchable = native_1.default.TouchableOpacity({
115
121
  flexDirection: 'row',
@@ -128,38 +134,44 @@ var ItemTouchable = native_1.default.TouchableOpacity({
128
134
  borderBottomRightRadius: isLastItem ? theme.storyList.sectionBorderRadius : undefined,
129
135
  });
130
136
  });
131
- var ListItem = react_1.default.memo(function (_a) {
132
- var storyId = _a.storyId, kind = _a.kind, title = _a.title, isLastItem = _a.isLastItem, onPress = _a.onPress;
137
+ var ListItem = function (_a) {
138
+ var storyId = _a.storyId, kind = _a.kind, title = _a.title, isLastItem = _a.isLastItem, onPress = _a.onPress, isSiblingSelected = _a.isSiblingSelected;
133
139
  var selected = (0, hooks_1.useIsStorySelected)(storyId);
134
- var sectionSelected = (0, hooks_1.useIsStorySectionSelected)(kind);
135
- return (react_1.default.createElement(ItemTouchable, { key: title, onPress: onPress, activeOpacity: 0.8, testID: "Storybook.ListItem.".concat(kind, ".").concat(title), accessibilityLabel: "Storybook.ListItem.".concat(title), selected: selected, sectionSelected: sectionSelected, isLastItem: isLastItem },
136
- react_1.default.createElement(icons_1.Icon, { width: 14, height: 14, name: selected ? 'story-white' : 'story-blue', marginRight: 6 }),
137
- react_1.default.createElement(StoryNameText, { selected: selected }, title)));
138
- }, function (prevProps, nextProps) { return prevProps.storyId === nextProps.storyId; });
139
- var getStories = function (storyIndex) {
140
- if (!storyIndex) {
141
- return [];
142
- }
143
- var groupedStories = Object.values(storyIndex.stories).reduce(function (acc, story) {
144
- var _a, _b;
145
- acc[story.title] = {
146
- title: story.title,
147
- data: ((_b = (_a = acc[story.title]) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : []).concat(story),
148
- };
149
- return acc;
150
- }, {});
151
- return Object.values(groupedStories);
140
+ var sectionSelected = (0, hooks_1.useIsStorySectionSelected)(kind) || isSiblingSelected;
141
+ return ((0, jsx_runtime_1.jsxs)(ItemTouchable, { onPress: onPress, activeOpacity: 0.8, testID: "Storybook.ListItem.".concat(kind, ".").concat(title), accessibilityLabel: "Storybook.ListItem.".concat(title), selected: selected, sectionSelected: sectionSelected, isLastItem: isLastItem, children: [(0, jsx_runtime_1.jsx)(icons_1.Icon, { width: 14, height: 14, name: selected ? 'story-white' : 'story-blue', marginRight: 6 }), (0, jsx_runtime_1.jsx)(StoryNameText, { selected: selected, children: title })] }, title));
152
142
  };
153
143
  var styles = react_native_1.StyleSheet.create({
154
144
  sectionList: { flex: 1 },
155
145
  sectionListContentContainer: { paddingBottom: 6 },
156
146
  });
157
147
  function keyExtractor(item, index) {
158
- return item.id + index;
148
+ return item.name + index;
159
149
  }
150
+ var RenderItem = function (_a) {
151
+ var _b, _c;
152
+ var item = _a.item, changeStory = _a.changeStory;
153
+ var isChildSelected = (0, hooks_1.useIsChildSelected)(item.stories);
154
+ var firstChild = (0, getNestedStories_1.findFirstChildStory)(item);
155
+ var firstChildSelected = (0, hooks_1.useIsStorySelected)(firstChild === null || firstChild === void 0 ? void 0 : firstChild.id);
156
+ var _d = (0, react_1.useState)(false), showChildren = _d[0], setShowChildren = _d[1];
157
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SectionHeader, { name: item.name, isChildSelected: isChildSelected, onPress: function () {
158
+ if (firstChildSelected && showChildren) {
159
+ setShowChildren(false);
160
+ }
161
+ else if (!showChildren && firstChild) {
162
+ setShowChildren(true);
163
+ changeStory(firstChild.id);
164
+ }
165
+ else if (showChildren && !firstChildSelected && firstChild) {
166
+ changeStory(firstChild.id);
167
+ }
168
+ }, icon: item.children.length ? 'folder' : 'grid', expanded: showChildren }), showChildren &&
169
+ ((_b = item.stories) === null || _b === void 0 ? void 0 : _b.map(function (story, idx) { return ((0, jsx_runtime_1.jsx)(ListItem, { storyId: story.id, title: story.name, kind: item.name, isSiblingSelected: isChildSelected, isLastItem: idx === item.stories.length - 1, onPress: function () { return changeStory(story.id); } }, story.id)); })), showChildren &&
170
+ ((_c = item.children) === null || _c === void 0 ? void 0 : _c.map(function (child, idx) { return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: { marginLeft: 16 }, children: (0, jsx_runtime_1.jsx)(RenderItem, { item: child, changeStory: changeStory }) }, "".concat(child.title, "-").concat(idx))); }))] }));
171
+ };
160
172
  var StoryListView = function (_a) {
161
173
  var storyIndex = _a.storyIndex;
162
- var originalData = (0, react_1.useMemo)(function () { return getStories(storyIndex); }, [storyIndex]);
174
+ var originalData = (0, react_1.useMemo)(function () { return (0, getNestedStories_1.getNestedStories)(storyIndex); }, [storyIndex]);
163
175
  var _b = (0, react_1.useState)(originalData), data = _b[0], setData = _b[1];
164
176
  var theme = (0, hooks_1.useTheme)();
165
177
  var handleChangeSearchText = function (text) {
@@ -168,39 +180,22 @@ var StoryListView = function (_a) {
168
180
  setData(originalData);
169
181
  return;
170
182
  }
171
- var checkValue = function (value) { return value.toLowerCase().includes(query.toLowerCase()); };
172
- var filteredData = originalData.reduce(function (acc, story) {
173
- var hasTitle = checkValue(story.title);
174
- var hasKind = story.data.some(function (ref) { return checkValue(ref.name); });
175
- if (hasTitle || hasKind) {
176
- acc.push(__assign(__assign({}, story), {
177
- // in case the query matches component's title, all of its stories will be shown
178
- data: !hasTitle ? story.data.filter(function (ref) { return checkValue(ref.name); }) : story.data }));
179
- }
180
- return acc;
181
- }, []);
182
- setData(filteredData);
183
+ setData((0, getNestedStories_1.filterNestedStories)(originalData, query));
183
184
  };
184
185
  var changeStory = function (storyId) {
185
186
  var channel = addons_1.addons.getChannel();
186
187
  channel.emit(core_events_1.default.SET_CURRENT_STORY, { storyId: storyId });
187
188
  };
188
189
  var renderItem = react_1.default.useCallback(function (_a) {
189
- var item = _a.item, index = _a.index, section = _a.section;
190
- return (react_1.default.createElement(ListItem, { storyId: item.id, title: item.name, kind: item.title, isLastItem: index === section.data.length - 1, onPress: function () { return changeStory(item.id); } }));
191
- }, []);
192
- var renderSectionHeader = react_1.default.useCallback(function (_a) {
193
- var _b = _a.section, title = _b.title, sectionData = _b.data;
194
- return (react_1.default.createElement(SectionHeader, { title: title, onPress: function () { return changeStory(sectionData[0].id); } }));
190
+ var item = _a.item;
191
+ return (0, jsx_runtime_1.jsx)(RenderItem, { item: item, changeStory: changeStory });
195
192
  }, []);
196
- return (react_1.default.createElement(layout_1.Box, { flex: true },
197
- react_1.default.createElement(SearchBar, { testID: "Storybook.ListView.SearchBar", onChangeText: handleChangeSearchText, placeholder: "Find by name" }),
198
- react_1.default.createElement(react_native_1.SectionList, { style: styles.sectionList, contentContainerStyle: [
199
- styles.sectionListContentContainer,
200
- {
201
- paddingVertical: theme.panel.paddingVertical,
202
- paddingHorizontal: theme.panel.paddingHorizontal,
203
- },
204
- ], testID: "Storybook.ListView", renderItem: renderItem, renderSectionHeader: renderSectionHeader, keyExtractor: keyExtractor, sections: data, stickySectionHeadersEnabled: false })));
193
+ return ((0, jsx_runtime_1.jsxs)(layout_1.Box, { flex: true, children: [(0, jsx_runtime_1.jsx)(SearchBar, { testID: "Storybook.ListView.SearchBar", onChangeText: handleChangeSearchText, placeholder: "Find by name" }), (0, jsx_runtime_1.jsx)(react_native_1.FlatList, { style: styles.sectionList, contentContainerStyle: [
194
+ styles.sectionListContentContainer,
195
+ {
196
+ paddingVertical: theme.panel.paddingVertical,
197
+ paddingHorizontal: theme.panel.paddingHorizontal,
198
+ },
199
+ ], testID: "Storybook.ListView", renderItem: renderItem, keyExtractor: keyExtractor, data: data })] }));
205
200
  };
206
201
  exports.default = react_1.default.memo(StoryListView);
@@ -0,0 +1,10 @@
1
+ import { StoryIndex, StoryIndexEntry } from '@storybook/client-api';
2
+ export interface StoryGroup {
3
+ name: string;
4
+ title: string;
5
+ children: StoryGroup[];
6
+ stories: StoryIndexEntry[];
7
+ }
8
+ export declare function getNestedStories(storyIndex: StoryIndex): StoryGroup[];
9
+ export declare const filterNestedStories: (stories: StoryGroup[], filter: string) => StoryGroup[];
10
+ export declare const findFirstChildStory: (story: StoryGroup) => StoryIndexEntry | undefined;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.findFirstChildStory = exports.filterNestedStories = exports.getNestedStories = void 0;
15
+ // recursive funciton that transforms storyIndex to be StoryGroup[]
16
+ function getNestedStories(storyIndex) {
17
+ var stories = Object.values(storyIndex.stories);
18
+ var group = [];
19
+ stories.forEach(function (story) {
20
+ var nameParts = story.title.split('/');
21
+ formGroup(nameParts, story, group);
22
+ });
23
+ return group;
24
+ }
25
+ exports.getNestedStories = getNestedStories;
26
+ function formGroup(nameParts, story, group) {
27
+ if (nameParts.length === 1) {
28
+ var current = group.find(function (_a) {
29
+ var name = _a.name;
30
+ return name === nameParts[0];
31
+ });
32
+ if (current) {
33
+ current.stories.push(story);
34
+ }
35
+ else {
36
+ group.push({
37
+ title: story.title,
38
+ name: nameParts[0],
39
+ children: [],
40
+ stories: [story],
41
+ });
42
+ }
43
+ return;
44
+ }
45
+ var newParts = nameParts.slice(1);
46
+ var currentListPart = group.find(function (_a) {
47
+ var name = _a.name;
48
+ return name === nameParts[0];
49
+ });
50
+ if (!currentListPart) {
51
+ var toPush = {
52
+ name: nameParts[0],
53
+ title: story.title,
54
+ children: [],
55
+ stories: [],
56
+ };
57
+ group.push(toPush);
58
+ return formGroup(newParts, story, toPush.children);
59
+ }
60
+ else if (!currentListPart.children) {
61
+ currentListPart.children = [];
62
+ }
63
+ var newGroup = currentListPart.children;
64
+ return formGroup(newParts, story, newGroup);
65
+ }
66
+ var filterNestedStories = function (stories, filter) {
67
+ var filteredStories = [];
68
+ stories.forEach(function (story) {
69
+ var filtered = filterStoryGroup(story, filter);
70
+ if (filtered) {
71
+ filteredStories.push(filtered);
72
+ }
73
+ });
74
+ return filteredStories;
75
+ };
76
+ exports.filterNestedStories = filterNestedStories;
77
+ var filterStoryGroup = function (story, filter) {
78
+ var filteredStories = story.stories.filter(function (item) {
79
+ return item.title.toLowerCase().includes(filter.toLowerCase()) ||
80
+ item.name.toLowerCase().includes(filter.toLowerCase());
81
+ });
82
+ var filteredChildren = (0, exports.filterNestedStories)(story.children, filter);
83
+ if (filteredStories.length || filteredChildren.length) {
84
+ return __assign(__assign({}, story), { children: filteredChildren, stories: filteredStories });
85
+ }
86
+ };
87
+ var findFirstChildStory = function (story) {
88
+ if (story.stories.length) {
89
+ return story.stories[0];
90
+ }
91
+ if (story.children.length) {
92
+ return (0, exports.findFirstChildStory)(story.children[0]);
93
+ }
94
+ };
95
+ exports.findFirstChildStory = findFirstChildStory;