@storybook/react-native-ui 8.0.0-alpha.3 → 8.2.0-alpha.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.
- package/dist/index.d.ts +15 -283
- package/dist/index.js +3140 -825
- package/package.json +10 -11
- package/src/Button.tsx +2 -74
- package/src/Explorer.stories.tsx +0 -6
- package/src/Explorer.tsx +0 -16
- package/src/Layout.stories.tsx +1 -6
- package/src/Layout.tsx +32 -25
- package/src/MobileAddonsPanel.tsx +141 -126
- package/src/MobileMenuDrawer.tsx +15 -10
- package/src/Refs.tsx +3 -63
- package/src/Search.tsx +4 -97
- package/src/SearchResults.tsx +3 -73
- package/src/Sidebar.stories.tsx +4 -42
- package/src/Sidebar.tsx +7 -70
- package/src/Tree.stories.tsx +2 -10
- package/src/Tree.tsx +7 -61
- package/src/TreeNode.stories.tsx +0 -5
- package/src/TreeNode.tsx +0 -1
- package/src/icon/CloseIcon.tsx +21 -20
- package/src/icon/MenuIcon.tsx +0 -1
- package/src/icon/SearchIcon.tsx +17 -14
- package/src/index.tsx +1 -0
- package/src/mockdata.ts +1 -1
- package/src/types.ts +3 -15
- package/src/useExpanded.ts +4 -62
- package/src/util/StoryHash.ts +244 -0
- package/src/util/status.tsx +1 -1
- package/src/util/tree.ts +1 -1
package/src/MobileMenuDrawer.tsx
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
+
BottomSheetBackdrop,
|
|
2
3
|
BottomSheetBackdropProps,
|
|
3
4
|
BottomSheetModal,
|
|
4
5
|
BottomSheetScrollView,
|
|
5
|
-
BottomSheetBackdrop,
|
|
6
6
|
} from '@gorhom/bottom-sheet';
|
|
7
|
-
import { ReactNode, forwardRef, useImperativeHandle, useRef
|
|
7
|
+
import { ReactNode, forwardRef, useImperativeHandle, useRef } from 'react';
|
|
8
8
|
import { Keyboard } from 'react-native';
|
|
9
9
|
import { useReducedMotion } from 'react-native-reanimated';
|
|
10
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
10
11
|
|
|
11
12
|
interface MobileMenuDrawerProps {
|
|
12
13
|
children: ReactNode | ReactNode[];
|
|
14
|
+
onStateChange: (isOpen: boolean) => void;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export interface MobileMenuDrawerRef {
|
|
16
|
-
isMobileMenuOpen: boolean;
|
|
17
18
|
setMobileMenuOpen: (isOpen: boolean) => void;
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -28,22 +29,21 @@ export const BottomSheetBackdropComponent = (backdropComponentProps: BottomSheet
|
|
|
28
29
|
);
|
|
29
30
|
|
|
30
31
|
export const MobileMenuDrawer = forwardRef<MobileMenuDrawerRef, MobileMenuDrawerProps>(
|
|
31
|
-
({ children }, ref) => {
|
|
32
|
-
const [isMobileMenuOpen, setMobileMenuOpen] = useState(false);
|
|
32
|
+
({ children, onStateChange }, ref) => {
|
|
33
33
|
const reducedMotion = useReducedMotion();
|
|
34
|
+
const insets = useSafeAreaInsets();
|
|
34
35
|
|
|
35
36
|
const menuBottomSheetRef = useRef<BottomSheetModal>(null);
|
|
36
37
|
|
|
37
38
|
useImperativeHandle(ref, () => ({
|
|
38
|
-
isMobileMenuOpen,
|
|
39
39
|
setMobileMenuOpen: (open: boolean) => {
|
|
40
40
|
if (open) {
|
|
41
|
-
|
|
41
|
+
onStateChange(true);
|
|
42
42
|
|
|
43
43
|
menuBottomSheetRef.current?.present();
|
|
44
44
|
} else {
|
|
45
45
|
Keyboard.dismiss();
|
|
46
|
-
|
|
46
|
+
onStateChange(false);
|
|
47
47
|
menuBottomSheetRef.current?.dismiss();
|
|
48
48
|
}
|
|
49
49
|
},
|
|
@@ -55,7 +55,7 @@ export const MobileMenuDrawer = forwardRef<MobileMenuDrawerRef, MobileMenuDrawer
|
|
|
55
55
|
index={1}
|
|
56
56
|
animateOnMount={!reducedMotion}
|
|
57
57
|
onDismiss={() => {
|
|
58
|
-
|
|
58
|
+
onStateChange(false);
|
|
59
59
|
}}
|
|
60
60
|
snapPoints={['50%', '75%']}
|
|
61
61
|
enableDismissOnClose
|
|
@@ -66,7 +66,12 @@ export const MobileMenuDrawer = forwardRef<MobileMenuDrawerRef, MobileMenuDrawer
|
|
|
66
66
|
stackBehavior="replace"
|
|
67
67
|
backdropComponent={BottomSheetBackdropComponent}
|
|
68
68
|
>
|
|
69
|
-
<BottomSheetScrollView
|
|
69
|
+
<BottomSheetScrollView
|
|
70
|
+
keyboardShouldPersistTaps="handled"
|
|
71
|
+
contentContainerStyle={{
|
|
72
|
+
paddingBottom: insets.bottom,
|
|
73
|
+
}}
|
|
74
|
+
>
|
|
70
75
|
{children}
|
|
71
76
|
</BottomSheetScrollView>
|
|
72
77
|
</BottomSheetModal>
|
package/src/Refs.tsx
CHANGED
|
@@ -1,82 +1,25 @@
|
|
|
1
1
|
import type { FC } from 'react';
|
|
2
2
|
import React, { useMemo, useCallback, useEffect, useState } from 'react';
|
|
3
|
-
import type { State } from '@storybook/manager-api';
|
|
4
|
-
import { useStorybookApi, useStorybookState } from '@storybook/manager-api';
|
|
3
|
+
import type { State } from '@storybook/core/manager-api';
|
|
5
4
|
import { styled } from '@storybook/react-native-theming';
|
|
6
|
-
// import { transparentize } from 'polished';
|
|
7
|
-
|
|
8
|
-
// import { AuthBlock, ErrorBlock, LoaderBlock, EmptyBlock } from './RefBlocks';
|
|
9
|
-
|
|
10
|
-
// import { RefIndicator } from './RefIndicator';
|
|
11
|
-
|
|
12
5
|
import { Tree } from './Tree';
|
|
13
|
-
|
|
14
6
|
import type { RefType } from './types';
|
|
15
7
|
import { getStateType } from './util/tree';
|
|
16
|
-
import { DEFAULT_REF_ID } from './constants';
|
|
17
|
-
|
|
18
|
-
// import { CollapseIcon } from './icon/CollapseIcon';
|
|
19
|
-
|
|
20
|
-
// import { getStateType } from '../../utils/tree';
|
|
21
|
-
// import { CollapseIcon } from './components/CollapseIcon';
|
|
22
8
|
|
|
23
9
|
export interface RefProps {
|
|
24
10
|
isLoading: boolean;
|
|
25
11
|
isBrowsing: boolean;
|
|
26
12
|
selectedStoryId: string | null;
|
|
27
13
|
setSelection: (selection: { refId: string; storyId: string }) => void;
|
|
28
|
-
// highlightedRef: MutableRefObject<Highlight>;
|
|
29
|
-
// setHighlighted: (highlight: Highlight) => void;
|
|
30
14
|
}
|
|
31
15
|
|
|
32
16
|
const Wrapper = styled.View<{ isMain: boolean }>(({}) => ({
|
|
33
17
|
position: 'relative',
|
|
34
18
|
}));
|
|
35
19
|
|
|
36
|
-
// const RefHead = styled.View(({ theme }) => ({
|
|
37
|
-
// display: 'flex',
|
|
38
|
-
// alignItems: 'center',
|
|
39
|
-
// justifyContent: 'space-between',
|
|
40
|
-
// background: 'transparent',
|
|
41
|
-
|
|
42
|
-
// width: '100%',
|
|
43
|
-
// marginTop: 20,
|
|
44
|
-
// paddingTop: 16,
|
|
45
|
-
// paddingBottom: 12,
|
|
46
|
-
// borderTopColor: theme.appBorderColor,
|
|
47
|
-
// borderTopWidth: 1,
|
|
48
|
-
// }));
|
|
49
|
-
|
|
50
|
-
// const RefTitle = styled.Text(({ theme }) => ({
|
|
51
|
-
// // textOverflow: 'ellipsis',
|
|
52
|
-
// // whiteSpace: 'nowrap',
|
|
53
|
-
// flex: 1,
|
|
54
|
-
// flexDirection: 'row',
|
|
55
|
-
// overflow: 'hidden',
|
|
56
|
-
// marginLeft: 2,
|
|
57
|
-
// fontWeight: theme.typography.weight.bold,
|
|
58
|
-
// fontSize: theme.typography.size.s2,
|
|
59
|
-
// lineHeight: 16,
|
|
60
|
-
// color:
|
|
61
|
-
// theme.base === 'light' ? theme.color.defaultText : transparentize(0.2, theme.color.defaultText),
|
|
62
|
-
// }));
|
|
63
|
-
|
|
64
|
-
// const CollapseButton = styled.TouchableOpacity(({}) => ({
|
|
65
|
-
// display: 'flex',
|
|
66
|
-
// flexDirection: 'row',
|
|
67
|
-
// paddingVertical: 0,
|
|
68
|
-
// paddingHorizontal: 8,
|
|
69
|
-
// gap: 6,
|
|
70
|
-
// alignItems: 'center',
|
|
71
|
-
// cursor: 'pointer',
|
|
72
|
-
// overflow: 'hidden',
|
|
73
|
-
// }));
|
|
74
|
-
|
|
75
20
|
export const Ref: FC<RefType & RefProps & { status?: State['status'] }> = React.memo(function Ref(
|
|
76
21
|
props
|
|
77
22
|
) {
|
|
78
|
-
const { docsOptions } = useStorybookState();
|
|
79
|
-
const api = useStorybookApi();
|
|
80
23
|
const {
|
|
81
24
|
index,
|
|
82
25
|
id: refId,
|
|
@@ -84,8 +27,6 @@ export const Ref: FC<RefType & RefProps & { status?: State['status'] }> = React.
|
|
|
84
27
|
isLoading: isLoadingMain,
|
|
85
28
|
isBrowsing,
|
|
86
29
|
selectedStoryId,
|
|
87
|
-
// highlightedRef,
|
|
88
|
-
// setHighlighted,
|
|
89
30
|
loginUrl,
|
|
90
31
|
type,
|
|
91
32
|
expanded = true,
|
|
@@ -114,9 +55,8 @@ export const Ref: FC<RefType & RefProps & { status?: State['status'] }> = React.
|
|
|
114
55
|
const onSelectStoryId = useCallback(
|
|
115
56
|
(storyId: string) => {
|
|
116
57
|
setSelection({ refId, storyId });
|
|
117
|
-
return api && api.selectStory(storyId, DEFAULT_REF_ID);
|
|
118
58
|
},
|
|
119
|
-
[
|
|
59
|
+
[refId, setSelection]
|
|
120
60
|
);
|
|
121
61
|
|
|
122
62
|
return (
|
|
@@ -130,7 +70,7 @@ export const Ref: FC<RefType & RefProps & { status?: State['status'] }> = React.
|
|
|
130
70
|
isMain={true}
|
|
131
71
|
refId={refId}
|
|
132
72
|
data={index}
|
|
133
|
-
docsMode={
|
|
73
|
+
docsMode={false}
|
|
134
74
|
selectedStoryId={selectedStoryId}
|
|
135
75
|
onSelectStoryId={onSelectStoryId}
|
|
136
76
|
/>
|
package/src/Search.tsx
CHANGED
|
@@ -1,32 +1,21 @@
|
|
|
1
|
-
import { useStorybookApi /* shortcutToHumanString */ } from '@storybook/manager-api';
|
|
2
1
|
import { styled } from '@storybook/react-native-theming';
|
|
3
|
-
// import type { DownshiftState, StateChangeOptions } from 'downshift';
|
|
4
|
-
// import Downshift from 'downshift';
|
|
5
2
|
import type { IFuseOptions } from 'fuse.js';
|
|
6
3
|
import Fuse from 'fuse.js';
|
|
7
|
-
// import { global } from '@storybook/global';
|
|
8
4
|
import React, { useRef, useState, useCallback } from 'react';
|
|
9
|
-
// import { CloseIcon, SearchIcon } from '@storybook/icons';
|
|
10
|
-
// import { DEFAULT_REF_ID } from './constants';
|
|
11
5
|
import {
|
|
12
6
|
type CombinedDataset,
|
|
13
7
|
type SearchItem,
|
|
14
8
|
type SearchResult,
|
|
15
|
-
// DownshiftItem,
|
|
16
9
|
type SearchChildrenFn,
|
|
17
10
|
type Selection,
|
|
18
11
|
type GetSearchItemProps,
|
|
19
12
|
isExpandType,
|
|
20
13
|
} from './types';
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
import { /* scrollIntoView */ searchItem } from './util/tree';
|
|
14
|
+
import { searchItem } from './util/tree';
|
|
24
15
|
import { getGroupStatus, getHighestStatus } from './util/status';
|
|
25
|
-
// import { useLayout } from './LayoutProvider';
|
|
26
16
|
import { SearchIcon } from './icon/SearchIcon';
|
|
27
17
|
import { CloseIcon } from './icon/CloseIcon';
|
|
28
18
|
import { TextInput, View } from 'react-native';
|
|
29
|
-
import { DEFAULT_REF_ID } from './constants';
|
|
30
19
|
import { BottomSheetTextInput } from '@gorhom/bottom-sheet';
|
|
31
20
|
|
|
32
21
|
const DEFAULT_MAX_SEARCH_RESULTS = 50;
|
|
@@ -65,11 +54,9 @@ const SearchField = styled.View({
|
|
|
65
54
|
display: 'flex',
|
|
66
55
|
flexDirection: 'column',
|
|
67
56
|
position: 'relative',
|
|
68
|
-
// marginBottom: 16,
|
|
69
57
|
});
|
|
70
58
|
|
|
71
59
|
const Input = styled(BottomSheetTextInput)(({ theme }) => ({
|
|
72
|
-
// appearance: 'none',
|
|
73
60
|
height: 32,
|
|
74
61
|
paddingLeft: 28,
|
|
75
62
|
paddingRight: 28,
|
|
@@ -78,59 +65,10 @@ const Input = styled(BottomSheetTextInput)(({ theme }) => ({
|
|
|
78
65
|
backgroundColor: 'transparent',
|
|
79
66
|
borderRadius: 4,
|
|
80
67
|
fontSize: theme.typography.size.s1 + 1,
|
|
81
|
-
// transition: 'all 150ms',
|
|
82
68
|
color: theme.color.defaultText,
|
|
83
69
|
width: '100%',
|
|
84
|
-
|
|
85
|
-
// '&:focus, &:active': {
|
|
86
|
-
// outline: 0,
|
|
87
|
-
// borderColor: theme.color.secondary,
|
|
88
|
-
// background: theme.background.app,
|
|
89
|
-
// },
|
|
90
|
-
// '&::placeholder': {
|
|
91
|
-
// color: theme.textMutedColor,
|
|
92
|
-
// opacity: 1,
|
|
93
|
-
// },
|
|
94
|
-
// '&:valid ~ code, &:focus ~ code': {
|
|
95
|
-
// display: 'none',
|
|
96
|
-
// },
|
|
97
|
-
// '&:invalid ~ svg': {
|
|
98
|
-
// display: 'none',
|
|
99
|
-
// },
|
|
100
|
-
// '&:valid ~ svg': {
|
|
101
|
-
// display: 'block',
|
|
102
|
-
// },
|
|
103
|
-
// '&::-ms-clear': {
|
|
104
|
-
// display: 'none',
|
|
105
|
-
// },
|
|
106
|
-
// '&::-webkit-search-decoration, &::-webkit-search-cancel-button, &::-webkit-search-results-button, &::-webkit-search-results-decoration':
|
|
107
|
-
// {
|
|
108
|
-
// display: 'none',
|
|
109
|
-
// },
|
|
110
70
|
}));
|
|
111
71
|
|
|
112
|
-
// const FocusKey = styled.Text(({ theme }) => ({
|
|
113
|
-
// position: 'absolute',
|
|
114
|
-
// top: 8,
|
|
115
|
-
// right: 9,
|
|
116
|
-
// height: 16,
|
|
117
|
-
// zIndex: 1,
|
|
118
|
-
// lineHeight: 16,
|
|
119
|
-
// textAlign: 'center',
|
|
120
|
-
// fontSize: 11,
|
|
121
|
-
// color: theme.base === 'light' ? theme.color.dark : theme.textMutedColor,
|
|
122
|
-
// userSelect: 'none',
|
|
123
|
-
// pointerEvents: 'none',
|
|
124
|
-
// display: 'flex',
|
|
125
|
-
// flexDirection: 'row',
|
|
126
|
-
// alignItems: 'center',
|
|
127
|
-
// gap: 4,
|
|
128
|
-
// }));
|
|
129
|
-
|
|
130
|
-
// const FocusKeyCmd = styled.Text({
|
|
131
|
-
// fontSize: 14,
|
|
132
|
-
// });
|
|
133
|
-
|
|
134
72
|
const ClearIcon = styled.TouchableOpacity(({ theme }) => ({
|
|
135
73
|
position: 'absolute',
|
|
136
74
|
top: 0,
|
|
@@ -145,53 +83,32 @@ const ClearIcon = styled.TouchableOpacity(({ theme }) => ({
|
|
|
145
83
|
height: '100%',
|
|
146
84
|
}));
|
|
147
85
|
|
|
148
|
-
// const FocusContainer = styled.View({});
|
|
149
|
-
|
|
150
86
|
export const Search = React.memo<{
|
|
151
87
|
children: SearchChildrenFn;
|
|
152
88
|
dataset: CombinedDataset;
|
|
153
|
-
// enableShortcuts?: boolean;
|
|
154
89
|
setSelection: (selection: Selection) => void;
|
|
155
90
|
getLastViewed: () => Selection[];
|
|
156
91
|
initialQuery?: string;
|
|
157
|
-
}>(function Search({
|
|
158
|
-
children,
|
|
159
|
-
dataset,
|
|
160
|
-
setSelection,
|
|
161
|
-
// enableShortcuts = true,
|
|
162
|
-
getLastViewed,
|
|
163
|
-
initialQuery = '',
|
|
164
|
-
}) {
|
|
165
|
-
const api = useStorybookApi();
|
|
166
|
-
// const inputRef = useRef<HTMLInputElement>(null);
|
|
167
|
-
// const [inputPlaceholder, setPlaceholder] = useState('Find components');
|
|
168
|
-
// const isFocused = useRef(false);
|
|
92
|
+
}>(function Search({ children, dataset, setSelection, getLastViewed, initialQuery = '' }) {
|
|
169
93
|
const inputRef = useRef<TextInput>(null);
|
|
170
94
|
const [inputValue, setInputValue] = useState(initialQuery);
|
|
171
95
|
const [isOpen, setIsOpen] = useState(false);
|
|
172
96
|
const [allComponents, showAllComponents] = useState(false);
|
|
173
|
-
// const searchShortcut = api ? shortcutToHumanString(api.getShortcutKeys().search) : '/';
|
|
174
97
|
|
|
175
98
|
const selectStory = useCallback(
|
|
176
99
|
(id: string, refId: string) => {
|
|
177
|
-
if (api) {
|
|
178
|
-
api.selectStory(id, undefined, { ref: refId !== DEFAULT_REF_ID && refId });
|
|
179
|
-
}
|
|
180
100
|
setSelection({ storyId: id, refId });
|
|
181
101
|
inputRef.current?.blur();
|
|
182
|
-
// inputRef.current?.clear();
|
|
183
|
-
// setInputValue('');
|
|
184
102
|
|
|
185
103
|
showAllComponents(false);
|
|
186
104
|
},
|
|
187
|
-
[
|
|
105
|
+
[setSelection]
|
|
188
106
|
);
|
|
189
107
|
|
|
190
108
|
const getItemProps: GetSearchItemProps = useCallback(
|
|
191
109
|
({ item: result }) => {
|
|
192
110
|
return {
|
|
193
111
|
icon: result?.item?.type === 'component' ? 'component' : 'story',
|
|
194
|
-
// isHighlighted:
|
|
195
112
|
result,
|
|
196
113
|
onPress: () => {
|
|
197
114
|
if (result?.item?.type === 'story') {
|
|
@@ -201,16 +118,12 @@ export const Search = React.memo<{
|
|
|
201
118
|
} else if (isExpandType(result) && result.showAll) {
|
|
202
119
|
result.showAll();
|
|
203
120
|
}
|
|
204
|
-
|
|
205
|
-
// selectStory(result.item.id, result.item.refId);
|
|
206
121
|
},
|
|
207
122
|
score: result.score,
|
|
208
123
|
refIndex: result.refIndex,
|
|
209
124
|
item: result.item,
|
|
210
125
|
matches: result.matches,
|
|
211
126
|
isHighlighted: false,
|
|
212
|
-
// isHighlighted: searchItem.
|
|
213
|
-
// isHighlighted: searchItem.item.
|
|
214
127
|
};
|
|
215
128
|
},
|
|
216
129
|
[selectStory]
|
|
@@ -289,17 +202,12 @@ export const Search = React.memo<{
|
|
|
289
202
|
[allComponents, dataset.hash, getLastViewed, makeFuse]
|
|
290
203
|
);
|
|
291
204
|
|
|
292
|
-
// const { isMobile } = useLayout();
|
|
293
|
-
|
|
294
205
|
const input = inputValue ? inputValue.trim() : '';
|
|
295
206
|
const results = input ? getResults(input) : [];
|
|
296
207
|
|
|
297
208
|
return (
|
|
298
209
|
<View style={{ flex: 1 }}>
|
|
299
|
-
<SearchField
|
|
300
|
-
// {...getRootProps({ refKey: '' }, { suppressRefError: true })}
|
|
301
|
-
// className="search-field"
|
|
302
|
-
>
|
|
210
|
+
<SearchField>
|
|
303
211
|
<SearchIconWrapper>
|
|
304
212
|
<SearchIcon />
|
|
305
213
|
</SearchIconWrapper>
|
|
@@ -327,7 +235,6 @@ export const Search = React.memo<{
|
|
|
327
235
|
results,
|
|
328
236
|
isBrowsing: !isOpen || !inputValue.length,
|
|
329
237
|
closeMenu: () => {},
|
|
330
|
-
// getMenuProps,
|
|
331
238
|
getItemProps,
|
|
332
239
|
highlightedIndex: null,
|
|
333
240
|
})}
|
package/src/SearchResults.tsx
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { styled } from '@storybook/react-native-theming';
|
|
2
2
|
import type { FC, PropsWithChildren, ReactNode } from 'react';
|
|
3
3
|
import React, { useCallback } from 'react';
|
|
4
|
-
// import type { ControllerStateAndHelpers } from 'downshift';
|
|
5
|
-
|
|
6
|
-
// import { useStorybookApi } from '@storybook/manager-api';
|
|
7
|
-
// import { PRELOAD_ENTRIES } from '@storybook/core-events';
|
|
8
4
|
import { transparentize } from 'polished';
|
|
9
|
-
// import { TrashIcon } from '@storybook/icons';
|
|
10
5
|
import type { GetSearchItemProps, SearchResult, SearchResultProps } from './types';
|
|
11
6
|
import { isExpandType } from './types';
|
|
12
7
|
|
|
@@ -17,7 +12,6 @@ import { IconButton } from './IconButton';
|
|
|
17
12
|
import { ComponentIcon } from './icon/ComponentIcon';
|
|
18
13
|
import { StoryIcon } from './icon/StoryIcon';
|
|
19
14
|
import { statusMapping } from './util/status';
|
|
20
|
-
// import { UseSymbol } from './IconSymbols';
|
|
21
15
|
|
|
22
16
|
const ResultsList = styled.View({
|
|
23
17
|
margin: 0,
|
|
@@ -67,15 +61,10 @@ const NoResults = styled.View(({ theme }) => ({
|
|
|
67
61
|
fontSize: theme.typography.size.s2,
|
|
68
62
|
lineHeight: 18,
|
|
69
63
|
color: theme.color.defaultText,
|
|
70
|
-
// small: {
|
|
71
|
-
// color: theme.barTextColor,
|
|
72
|
-
// fontSize: theme.typography.size.s1,
|
|
73
|
-
// },
|
|
74
64
|
}));
|
|
75
65
|
|
|
76
66
|
const Mark = styled.Text(({ theme }) => ({
|
|
77
67
|
backgroundColor: 'transparent',
|
|
78
|
-
// fontSize: theme.typography.size.s1 - 1,
|
|
79
68
|
color: theme.color.secondary,
|
|
80
69
|
}));
|
|
81
70
|
|
|
@@ -96,16 +85,6 @@ const RecentlyOpenedTitle = styled.View(({ theme }) => ({
|
|
|
96
85
|
marginTop: 16,
|
|
97
86
|
marginBottom: 4,
|
|
98
87
|
alignItems: 'center',
|
|
99
|
-
|
|
100
|
-
// '.search-result-recentlyOpened-clear': {
|
|
101
|
-
// visibility: 'hidden',
|
|
102
|
-
// },
|
|
103
|
-
|
|
104
|
-
// '&:hover': {
|
|
105
|
-
// '.search-result-recentlyOpened-clear': {
|
|
106
|
-
// visibility: 'visible',
|
|
107
|
-
// },
|
|
108
|
-
// },
|
|
109
88
|
}));
|
|
110
89
|
|
|
111
90
|
const Highlight: FC<PropsWithChildren<{ match?: FuseResultMatch }>> = React.memo(
|
|
@@ -129,41 +108,17 @@ const Highlight: FC<PropsWithChildren<{ match?: FuseResultMatch }>> = React.memo
|
|
|
129
108
|
);
|
|
130
109
|
|
|
131
110
|
const Title = styled.Text(({ theme }) => ({
|
|
132
|
-
// display: 'grid',
|
|
133
111
|
justifyContent: 'flex-start',
|
|
134
|
-
// gridAutoColumns: 'auto',
|
|
135
|
-
// gridAutoFlow: 'column',
|
|
136
112
|
color: theme.textMutedColor,
|
|
137
113
|
fontSize: theme.typography.size.s2,
|
|
138
|
-
// '& > span': {
|
|
139
|
-
// display: 'block',
|
|
140
|
-
// whiteSpace: 'nowrap',
|
|
141
|
-
// overflow: 'hidden',
|
|
142
|
-
// textOverflow: 'ellipsis',
|
|
143
|
-
// },
|
|
144
114
|
}));
|
|
145
115
|
|
|
146
116
|
const Path = styled.View(({ theme }) => ({
|
|
147
|
-
// display: 'grid',
|
|
148
117
|
justifyContent: 'flex-start',
|
|
149
118
|
marginVertical: 2,
|
|
150
|
-
// gridAutoColumns: 'auto',
|
|
151
|
-
// gridAutoFlow: 'column',
|
|
152
119
|
color: theme.textMutedColor,
|
|
153
120
|
fontSize: theme.typography.size.s1 - 1,
|
|
154
121
|
flexDirection: 'row',
|
|
155
|
-
// '& > span': {
|
|
156
|
-
// display: 'block',
|
|
157
|
-
// whiteSpace: 'nowrap',
|
|
158
|
-
// overflow: 'hidden',
|
|
159
|
-
// textOverflow: 'ellipsis',
|
|
160
|
-
// },
|
|
161
|
-
|
|
162
|
-
// '& > span + span': {
|
|
163
|
-
// '&:before': {
|
|
164
|
-
// content: "' / '",
|
|
165
|
-
// },
|
|
166
|
-
// },
|
|
167
122
|
}));
|
|
168
123
|
|
|
169
124
|
const PathText = styled.Text(({ theme }) => ({
|
|
@@ -186,13 +141,6 @@ const Result: FC<SearchResultProps> = React.memo(function Result({
|
|
|
186
141
|
[onPress]
|
|
187
142
|
);
|
|
188
143
|
|
|
189
|
-
// const api = useStorybookApi();
|
|
190
|
-
// useEffect(() => {
|
|
191
|
-
// if (api && props.isHighlighted && item.type === 'component') {
|
|
192
|
-
// // api.emit(PRELOAD_ENTRIES, { ids: [item.children[0]] }, { options: { target: item.refId } });
|
|
193
|
-
// }
|
|
194
|
-
// }, [props.isHighlighted, item]);
|
|
195
|
-
|
|
196
144
|
const nameMatch = matches.find((match: FuseResultMatch) => match.key === 'name');
|
|
197
145
|
const pathMatches = matches.filter((match: FuseResultMatch) => match.key === 'path');
|
|
198
146
|
|
|
@@ -217,7 +165,6 @@ const Result: FC<SearchResultProps> = React.memo(function Result({
|
|
|
217
165
|
<Highlight
|
|
218
166
|
match={pathMatches.find((match: FuseResultMatch) => match.refIndex === index)}
|
|
219
167
|
>
|
|
220
|
-
{/* {index === 0 ? '' : '/'} */}
|
|
221
168
|
{group}
|
|
222
169
|
</Highlight>
|
|
223
170
|
</PathText>
|
|
@@ -230,13 +177,10 @@ const Result: FC<SearchResultProps> = React.memo(function Result({
|
|
|
230
177
|
);
|
|
231
178
|
});
|
|
232
179
|
|
|
233
|
-
// type SearchResult = { item: API_HashEntry; matches: FuseResultMatch[]; score: number };
|
|
234
|
-
|
|
235
180
|
export const SearchResults: FC<{
|
|
236
181
|
query: string;
|
|
237
182
|
results: SearchResult[];
|
|
238
183
|
closeMenu: (cb?: () => void) => void;
|
|
239
|
-
// getMenuProps: any;
|
|
240
184
|
getItemProps: GetSearchItemProps;
|
|
241
185
|
highlightedIndex: number | null;
|
|
242
186
|
isLoading?: boolean;
|
|
@@ -246,38 +190,27 @@ export const SearchResults: FC<{
|
|
|
246
190
|
query,
|
|
247
191
|
results,
|
|
248
192
|
closeMenu,
|
|
249
|
-
// getMenuProps,
|
|
250
193
|
getItemProps,
|
|
251
194
|
highlightedIndex,
|
|
252
|
-
// isLoading = false,
|
|
253
|
-
// enableShortcuts = true,
|
|
254
195
|
clearLastViewed,
|
|
255
196
|
}) {
|
|
256
|
-
// const api = useStorybookApi();
|
|
257
|
-
|
|
258
197
|
const handleClearLastViewed = () => {
|
|
259
198
|
clearLastViewed();
|
|
260
199
|
closeMenu();
|
|
261
200
|
};
|
|
262
201
|
|
|
263
202
|
return (
|
|
264
|
-
<ResultsList
|
|
203
|
+
<ResultsList>
|
|
265
204
|
{results.length > 0 && !query && (
|
|
266
|
-
<RecentlyOpenedTitle
|
|
205
|
+
<RecentlyOpenedTitle>
|
|
267
206
|
Recently opened
|
|
268
|
-
<IconButton
|
|
269
|
-
// className="search-result-recentlyOpened-clear"
|
|
270
|
-
onPress={handleClearLastViewed}
|
|
271
|
-
>
|
|
272
|
-
{/* <TrashIcon /> */}
|
|
273
|
-
</IconButton>
|
|
207
|
+
<IconButton onPress={handleClearLastViewed} />
|
|
274
208
|
</RecentlyOpenedTitle>
|
|
275
209
|
)}
|
|
276
210
|
{results.length === 0 && query && (
|
|
277
211
|
<View>
|
|
278
212
|
<NoResults>
|
|
279
213
|
<Text style={{ marginBottom: 8 }}>No components found</Text>
|
|
280
|
-
{/* <br /> */}
|
|
281
214
|
<Text>Find components by name or path.</Text>
|
|
282
215
|
</NoResults>
|
|
283
216
|
</View>
|
|
@@ -304,9 +237,6 @@ export const SearchResults: FC<{
|
|
|
304
237
|
{...getItemProps({ key, index, item: result })}
|
|
305
238
|
isHighlighted={highlightedIndex === index}
|
|
306
239
|
key={item.id}
|
|
307
|
-
// data-id={result.item.id}
|
|
308
|
-
// data-refid={result.item.refId}
|
|
309
|
-
// className="search-result-item"
|
|
310
240
|
/>
|
|
311
241
|
);
|
|
312
242
|
})}
|
package/src/Sidebar.stories.tsx
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import { /* ManagerContext */ types } from '@storybook/manager-api';
|
|
2
|
+
import type { IndexHash, State } from '@storybook/core/manager-api';
|
|
3
|
+
import { types } from '@storybook/core/manager-api';
|
|
5
4
|
import type { StoryObj, Meta } from '@storybook/react';
|
|
6
|
-
import type { Addon_SidebarTopType } from '@storybook/types';
|
|
7
|
-
|
|
5
|
+
import type { Addon_SidebarTopType } from '@storybook/core/types';
|
|
8
6
|
import { Sidebar } from './Sidebar';
|
|
9
|
-
// import { standardData as standardHeaderData } from './Heading.stories';
|
|
10
7
|
import { mockDataset } from './mockdata';
|
|
11
8
|
import type { RefType } from './types';
|
|
12
9
|
import { LayoutProvider } from './LayoutProvider';
|
|
@@ -15,18 +12,9 @@ import { IconButton } from './IconButton';
|
|
|
15
12
|
import { FaceHappyIcon } from './icon/FaceHappyIcon';
|
|
16
13
|
import { DEFAULT_REF_ID } from './constants';
|
|
17
14
|
|
|
18
|
-
// const menuItems = [
|
|
19
|
-
// { title: 'Menu Item 1', onClick: () => console.log('onActivateMenuItem'), id: '1' },
|
|
20
|
-
// { title: 'Menu Item 2', onClick: () => console.log('onActivateMenuItem'), id: '2' },
|
|
21
|
-
// { title: 'Menu Item 3', onClick: () => console.log('onActivateMenuItem'), id: '3' },
|
|
22
|
-
// ];
|
|
23
|
-
// export const menu = menuItems;
|
|
24
15
|
const index = mockDataset.withRoot as IndexHash;
|
|
25
16
|
const storyId = 'root-1-child-a2--grandchild-a1-1';
|
|
26
17
|
|
|
27
|
-
// export const simpleData = { menu, index, storyId };
|
|
28
|
-
// export const loadingData = { menu };
|
|
29
|
-
|
|
30
18
|
const meta = {
|
|
31
19
|
component: Sidebar,
|
|
32
20
|
title: 'UI/Sidebar/Sidebar',
|
|
@@ -34,7 +22,6 @@ const meta = {
|
|
|
34
22
|
parameters: { layout: 'fullscreen' },
|
|
35
23
|
args: {
|
|
36
24
|
previewInitialized: true,
|
|
37
|
-
// menu,
|
|
38
25
|
extra: [] as Addon_SidebarTopType[],
|
|
39
26
|
index: index,
|
|
40
27
|
storyId,
|
|
@@ -43,31 +30,7 @@ const meta = {
|
|
|
43
30
|
status: {},
|
|
44
31
|
setSelection: () => {},
|
|
45
32
|
},
|
|
46
|
-
decorators: [
|
|
47
|
-
(storyFn) => (
|
|
48
|
-
// <ManagerContext.Provider
|
|
49
|
-
// value={
|
|
50
|
-
// {
|
|
51
|
-
// state: {
|
|
52
|
-
// docsOptions: {
|
|
53
|
-
// defaultName: 'Docs',
|
|
54
|
-
// autodocs: 'tag',
|
|
55
|
-
// docsMode: false,
|
|
56
|
-
// },
|
|
57
|
-
// },
|
|
58
|
-
// api: {
|
|
59
|
-
// emit: () => {},
|
|
60
|
-
// on: () => {},
|
|
61
|
-
// off: () => {},
|
|
62
|
-
// getShortcutKeys: () => ({ search: ['control', 'shift', 's'] }),
|
|
63
|
-
// },
|
|
64
|
-
// } as any
|
|
65
|
-
// }
|
|
66
|
-
// >
|
|
67
|
-
<LayoutProvider>{storyFn()}</LayoutProvider>
|
|
68
|
-
// </ManagerContext.Provider>
|
|
69
|
-
),
|
|
70
|
-
],
|
|
33
|
+
decorators: [(storyFn) => <LayoutProvider>{storyFn()}</LayoutProvider>],
|
|
71
34
|
} satisfies Meta<typeof Sidebar>;
|
|
72
35
|
|
|
73
36
|
export default meta;
|
|
@@ -98,7 +61,6 @@ const refsError = {
|
|
|
98
61
|
const refsEmpty = {
|
|
99
62
|
optimized: {
|
|
100
63
|
...refs.optimized,
|
|
101
|
-
// type: 'auto-inject',
|
|
102
64
|
index: {} as IndexHash,
|
|
103
65
|
},
|
|
104
66
|
};
|