@storybook/react-native-ui-lite 10.2.2-alpha.0 → 10.2.2-alpha.2
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.js +203 -88
- package/package.json +4 -4
- package/src/Layout.tsx +94 -42
- package/src/ResizeHandle.tsx +83 -0
- package/src/Tree.tsx +8 -5
- package/src/TreeNode.tsx +0 -2
package/dist/index.js
CHANGED
|
@@ -330,7 +330,6 @@ var BranchNode = import_react_native_theming2.styled.TouchableOpacity(({ depth =
|
|
|
330
330
|
display: "flex",
|
|
331
331
|
flexDirection: "row",
|
|
332
332
|
alignItems: "center",
|
|
333
|
-
alignSelf: "flex-start",
|
|
334
333
|
paddingLeft: (isExpandable ? 8 : 22) + depth * 18,
|
|
335
334
|
backgroundColor: "transparent",
|
|
336
335
|
minHeight: 34,
|
|
@@ -346,7 +345,6 @@ var BranchNode = import_react_native_theming2.styled.TouchableOpacity(({ depth =
|
|
|
346
345
|
}));
|
|
347
346
|
var LeafNode = import_react_native_theming2.styled.TouchableOpacity(
|
|
348
347
|
({ depth = 0, selected, theme }) => ({
|
|
349
|
-
alignSelf: "flex-start",
|
|
350
348
|
cursor: "pointer",
|
|
351
349
|
color: "inherit",
|
|
352
350
|
display: "flex",
|
|
@@ -467,12 +465,13 @@ var useSelectedNode = () => (0, import_react3.useContext)(SelectedNodeContext);
|
|
|
467
465
|
// src/Tree.tsx
|
|
468
466
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
469
467
|
var TextItem = import_react_native_theming3.styled.Text(({ theme }) => ({
|
|
468
|
+
fontSize: theme.typography.size.s2 + 1,
|
|
470
469
|
color: theme.color.defaultText
|
|
471
470
|
}));
|
|
472
471
|
var Node = import_react4.default.memo(function Node2({
|
|
473
472
|
item,
|
|
474
473
|
refId,
|
|
475
|
-
isOrphan,
|
|
474
|
+
isOrphan: _isOrphan,
|
|
476
475
|
isDisplayed: _isDisplayed,
|
|
477
476
|
isSelected,
|
|
478
477
|
isFullyExpanded,
|
|
@@ -489,7 +488,7 @@ var Node = import_react4.default.memo(function Node2({
|
|
|
489
488
|
{
|
|
490
489
|
selected: isSelected,
|
|
491
490
|
id,
|
|
492
|
-
depth:
|
|
491
|
+
depth: item.depth,
|
|
493
492
|
onPress: () => {
|
|
494
493
|
onSelectStoryId(item.id);
|
|
495
494
|
},
|
|
@@ -540,7 +539,7 @@ var Node = import_react4.default.memo(function Node2({
|
|
|
540
539
|
id,
|
|
541
540
|
"aria-controls": item.children && item.children[0],
|
|
542
541
|
"aria-expanded": isExpanded,
|
|
543
|
-
depth:
|
|
542
|
+
depth: item.depth,
|
|
544
543
|
isComponent: item.type === "component",
|
|
545
544
|
isExpandable: item.children && item.children.length > 0,
|
|
546
545
|
isExpanded,
|
|
@@ -585,15 +584,17 @@ var RootNodeText = import_react_native_theming3.styled.Text(({ theme }) => ({
|
|
|
585
584
|
textTransform: "uppercase"
|
|
586
585
|
}));
|
|
587
586
|
var CollapseButton = import_react_native_theming3.styled.TouchableOpacity(() => ({
|
|
587
|
+
flex: 1,
|
|
588
588
|
display: "flex",
|
|
589
589
|
flexDirection: "row",
|
|
590
|
-
paddingVertical: 0,
|
|
591
590
|
paddingHorizontal: 8,
|
|
591
|
+
paddingTop: 8,
|
|
592
|
+
paddingBottom: 7,
|
|
592
593
|
borderRadius: 4,
|
|
593
594
|
gap: 6,
|
|
594
595
|
alignItems: "center",
|
|
595
596
|
cursor: "pointer",
|
|
596
|
-
|
|
597
|
+
minHeight: 34
|
|
597
598
|
}));
|
|
598
599
|
var flexStyle = { flex: 1 };
|
|
599
600
|
var ITEM_HEIGHT = 34;
|
|
@@ -1484,10 +1485,10 @@ var Sidebar = import_react11.default.memo(function Sidebar2({
|
|
|
1484
1485
|
|
|
1485
1486
|
// src/Layout.tsx
|
|
1486
1487
|
var import_portal2 = require("@gorhom/portal");
|
|
1487
|
-
var
|
|
1488
|
+
var import_react_native_theming11 = require("@storybook/react-native-theming");
|
|
1488
1489
|
var import_react_native_ui_common7 = require("@storybook/react-native-ui-common");
|
|
1489
|
-
var
|
|
1490
|
-
var
|
|
1490
|
+
var import_react17 = require("react");
|
|
1491
|
+
var import_react_native12 = require("react-native");
|
|
1491
1492
|
var import_react_native_safe_area_context4 = require("react-native-safe-area-context");
|
|
1492
1493
|
var import_core_events = require("storybook/internal/core-events");
|
|
1493
1494
|
var import_manager_api2 = require("storybook/manager-api");
|
|
@@ -1974,19 +1975,90 @@ var MobileMenuDrawer = (0, import_react14.memo)(
|
|
|
1974
1975
|
})
|
|
1975
1976
|
);
|
|
1976
1977
|
|
|
1977
|
-
// src/
|
|
1978
|
+
// src/ResizeHandle.tsx
|
|
1979
|
+
var import_react_native_theming10 = require("@storybook/react-native-theming");
|
|
1978
1980
|
var import_react15 = require("react");
|
|
1979
1981
|
var import_react_native10 = require("react-native");
|
|
1980
1982
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
1983
|
+
var ResizeHandle = (0, import_react15.memo)(function ResizeHandle2({
|
|
1984
|
+
direction,
|
|
1985
|
+
onResize,
|
|
1986
|
+
onResizeStart,
|
|
1987
|
+
onResizeEnd
|
|
1988
|
+
}) {
|
|
1989
|
+
const theme = (0, import_react_native_theming10.useTheme)();
|
|
1990
|
+
const [active, setActive] = (0, import_react15.useState)(false);
|
|
1991
|
+
const startValueRef = (0, import_react15.useRef)(0);
|
|
1992
|
+
const isHorizontal = direction === "horizontal";
|
|
1993
|
+
const panResponder = (0, import_react15.useMemo)(
|
|
1994
|
+
() => import_react_native10.PanResponder.create({
|
|
1995
|
+
onStartShouldSetPanResponder: () => true,
|
|
1996
|
+
onMoveShouldSetPanResponder: () => true,
|
|
1997
|
+
onPanResponderTerminationRequest: () => false,
|
|
1998
|
+
onShouldBlockNativeResponder: () => true,
|
|
1999
|
+
onPanResponderGrant: () => {
|
|
2000
|
+
startValueRef.current = 0;
|
|
2001
|
+
setActive(true);
|
|
2002
|
+
onResizeStart?.();
|
|
2003
|
+
},
|
|
2004
|
+
onPanResponderMove: (_, gestureState) => {
|
|
2005
|
+
const delta = isHorizontal ? gestureState.dx : gestureState.dy;
|
|
2006
|
+
const diff = delta - startValueRef.current;
|
|
2007
|
+
startValueRef.current = delta;
|
|
2008
|
+
onResize(diff);
|
|
2009
|
+
},
|
|
2010
|
+
onPanResponderRelease: () => {
|
|
2011
|
+
setActive(false);
|
|
2012
|
+
onResizeEnd?.();
|
|
2013
|
+
},
|
|
2014
|
+
onPanResponderTerminate: () => {
|
|
2015
|
+
setActive(false);
|
|
2016
|
+
onResizeEnd?.();
|
|
2017
|
+
}
|
|
2018
|
+
}),
|
|
2019
|
+
[isHorizontal, onResize, onResizeStart, onResizeEnd]
|
|
2020
|
+
);
|
|
2021
|
+
const style = (0, import_react15.useMemo)(() => {
|
|
2022
|
+
const borderColor = active ? theme.barSelectedColor : theme.appBorderColor;
|
|
2023
|
+
if (isHorizontal) {
|
|
2024
|
+
return {
|
|
2025
|
+
width: 5,
|
|
2026
|
+
alignSelf: "stretch",
|
|
2027
|
+
justifyContent: "center",
|
|
2028
|
+
borderLeftWidth: 1,
|
|
2029
|
+
borderLeftColor: borderColor,
|
|
2030
|
+
backgroundColor: active ? theme.barSelectedColor : "transparent",
|
|
2031
|
+
// @ts-expect-error - cursor is supported on web and desktop platforms
|
|
2032
|
+
cursor: "col-resize"
|
|
2033
|
+
};
|
|
2034
|
+
}
|
|
2035
|
+
return {
|
|
2036
|
+
height: 5,
|
|
2037
|
+
alignSelf: "stretch",
|
|
2038
|
+
justifyContent: "center",
|
|
2039
|
+
borderTopWidth: 1,
|
|
2040
|
+
borderTopColor: borderColor,
|
|
2041
|
+
backgroundColor: active ? theme.barSelectedColor : "transparent",
|
|
2042
|
+
// @ts-expect-error - cursor is supported on web and desktop platforms
|
|
2043
|
+
cursor: "row-resize"
|
|
2044
|
+
};
|
|
2045
|
+
}, [active, isHorizontal, theme.appBorderColor, theme.barSelectedColor]);
|
|
2046
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_react_native10.View, { ...panResponder.panHandlers, style });
|
|
2047
|
+
});
|
|
2048
|
+
|
|
2049
|
+
// src/StorybookLogo.tsx
|
|
2050
|
+
var import_react16 = require("react");
|
|
2051
|
+
var import_react_native11 = require("react-native");
|
|
2052
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1981
2053
|
var WIDTH = 125;
|
|
1982
2054
|
var HEIGHT = 25;
|
|
1983
|
-
var NoBrandLogo = ({ theme }) => theme.base === "light" ? /* @__PURE__ */ (0,
|
|
2055
|
+
var NoBrandLogo = ({ theme }) => theme.base === "light" ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Logo, { height: HEIGHT, width: WIDTH }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(DarkLogo, { height: HEIGHT, width: WIDTH });
|
|
1984
2056
|
function isElement(value) {
|
|
1985
|
-
return (0,
|
|
2057
|
+
return (0, import_react16.isValidElement)(value);
|
|
1986
2058
|
}
|
|
1987
2059
|
var BrandLogo = ({ theme }) => {
|
|
1988
2060
|
const imageHasNoWidthOrHeight = typeof theme.brand.image === "object" && typeof theme.brand.image === "object" && "uri" in theme.brand.image && (!("height" in theme.brand.image) || !("width" in theme.brand.image));
|
|
1989
|
-
(0,
|
|
2061
|
+
(0, import_react16.useEffect)(() => {
|
|
1990
2062
|
if (imageHasNoWidthOrHeight) {
|
|
1991
2063
|
console.warn(
|
|
1992
2064
|
"STORYBOOK: When using a remote image as the brand logo, you must also set the width and height.\nFor example: brand: { image: { uri: 'https://sb.com/img.png', height: 25, width: 25}}"
|
|
@@ -1999,8 +2071,8 @@ var BrandLogo = ({ theme }) => {
|
|
|
1999
2071
|
if (isElement(theme.brand.image)) {
|
|
2000
2072
|
return theme.brand.image;
|
|
2001
2073
|
}
|
|
2002
|
-
const image = /* @__PURE__ */ (0,
|
|
2003
|
-
|
|
2074
|
+
const image = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2075
|
+
import_react_native11.Image,
|
|
2004
2076
|
{
|
|
2005
2077
|
source: theme.brand.image,
|
|
2006
2078
|
resizeMode: theme.brand.resizeMode ?? "contain",
|
|
@@ -2008,11 +2080,11 @@ var BrandLogo = ({ theme }) => {
|
|
|
2008
2080
|
}
|
|
2009
2081
|
);
|
|
2010
2082
|
if (theme.brand.url) {
|
|
2011
|
-
return /* @__PURE__ */ (0,
|
|
2012
|
-
|
|
2083
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2084
|
+
import_react_native11.TouchableOpacity,
|
|
2013
2085
|
{
|
|
2014
2086
|
onPress: () => {
|
|
2015
|
-
if (theme.brand.url)
|
|
2087
|
+
if (theme.brand.url) import_react_native11.Linking.openURL(theme.brand.url);
|
|
2016
2088
|
},
|
|
2017
2089
|
children: image
|
|
2018
2090
|
}
|
|
@@ -2022,7 +2094,7 @@ var BrandLogo = ({ theme }) => {
|
|
|
2022
2094
|
}
|
|
2023
2095
|
};
|
|
2024
2096
|
var BrandTitle = ({ theme }) => {
|
|
2025
|
-
const brandTitleStyle = (0,
|
|
2097
|
+
const brandTitleStyle = (0, import_react16.useMemo)(() => {
|
|
2026
2098
|
return {
|
|
2027
2099
|
width: WIDTH,
|
|
2028
2100
|
height: HEIGHT,
|
|
@@ -2030,13 +2102,13 @@ var BrandTitle = ({ theme }) => {
|
|
|
2030
2102
|
fontSize: theme.typography.size.m1
|
|
2031
2103
|
};
|
|
2032
2104
|
}, [theme]);
|
|
2033
|
-
const title = /* @__PURE__ */ (0,
|
|
2105
|
+
const title = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_native11.Text, { style: brandTitleStyle, numberOfLines: 1, ellipsizeMode: "tail", children: theme.brand.title });
|
|
2034
2106
|
if (theme.brand.url) {
|
|
2035
|
-
return /* @__PURE__ */ (0,
|
|
2036
|
-
|
|
2107
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
2108
|
+
import_react_native11.TouchableOpacity,
|
|
2037
2109
|
{
|
|
2038
2110
|
onPress: () => {
|
|
2039
|
-
if (theme.brand.url)
|
|
2111
|
+
if (theme.brand.url) import_react_native11.Linking.openURL(theme.brand.url);
|
|
2040
2112
|
},
|
|
2041
2113
|
children: title
|
|
2042
2114
|
}
|
|
@@ -2046,19 +2118,19 @@ var BrandTitle = ({ theme }) => {
|
|
|
2046
2118
|
}
|
|
2047
2119
|
};
|
|
2048
2120
|
var StorybookLogo = ({ theme }) => {
|
|
2049
|
-
const image = (0,
|
|
2050
|
-
const title = (0,
|
|
2121
|
+
const image = (0, import_react16.useMemo)(() => theme.brand?.image, [theme.brand?.image]);
|
|
2122
|
+
const title = (0, import_react16.useMemo)(() => theme.brand?.title, [theme.brand?.title]);
|
|
2051
2123
|
if (image) {
|
|
2052
|
-
return /* @__PURE__ */ (0,
|
|
2124
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(BrandLogo, { theme });
|
|
2053
2125
|
} else if (title) {
|
|
2054
|
-
return /* @__PURE__ */ (0,
|
|
2126
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(BrandTitle, { theme });
|
|
2055
2127
|
} else {
|
|
2056
|
-
return /* @__PURE__ */ (0,
|
|
2128
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(NoBrandLogo, { theme });
|
|
2057
2129
|
}
|
|
2058
2130
|
};
|
|
2059
2131
|
|
|
2060
2132
|
// src/Layout.tsx
|
|
2061
|
-
var
|
|
2133
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
2062
2134
|
var desktopLogoContainer = {
|
|
2063
2135
|
flexDirection: "row",
|
|
2064
2136
|
alignItems: "center",
|
|
@@ -2080,16 +2152,16 @@ var mobileMenuDrawerContentStyle = {
|
|
|
2080
2152
|
paddingBottom: 4
|
|
2081
2153
|
};
|
|
2082
2154
|
var flexStyle6 = { flex: 1 };
|
|
2083
|
-
var LiteUI = ({ storage, theme, storyHash, story, children }) => /* @__PURE__ */ (0,
|
|
2084
|
-
/* @__PURE__ */ (0,
|
|
2085
|
-
/* @__PURE__ */ (0,
|
|
2155
|
+
var LiteUI = ({ storage, theme, storyHash, story, children }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native_safe_area_context4.SafeAreaProvider, { style: flexStyle6, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(SelectedNodeProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native_theming11.ThemeProvider, { theme, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native_ui_common7.StorageProvider, { storage, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native_ui_common7.LayoutProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_portal2.PortalProvider, { shouldAddRootHost: false, children: [
|
|
2156
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Layout, { storyHash, story, children }),
|
|
2157
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_portal2.PortalHost, { name: "storybook-lite-ui-root" })
|
|
2086
2158
|
] }) }) }) }) }) });
|
|
2087
2159
|
var Layout = ({
|
|
2088
2160
|
storyHash,
|
|
2089
2161
|
story,
|
|
2090
2162
|
children
|
|
2091
2163
|
}) => {
|
|
2092
|
-
const theme = (0,
|
|
2164
|
+
const theme = (0, import_react_native_theming11.useTheme)();
|
|
2093
2165
|
const { isDesktop } = (0, import_react_native_ui_common7.useLayout)();
|
|
2094
2166
|
const insets = (0, import_react_native_safe_area_context4.useSafeAreaInsets)();
|
|
2095
2167
|
const [desktopSidebarOpen, setDesktopSidebarOpen] = (0, import_react_native_ui_common7.useStoreBooleanState)(
|
|
@@ -2100,28 +2172,49 @@ var Layout = ({
|
|
|
2100
2172
|
"desktopPanelState",
|
|
2101
2173
|
true
|
|
2102
2174
|
);
|
|
2103
|
-
const [
|
|
2104
|
-
(0,
|
|
2175
|
+
const [sidebarWidth, setSidebarWidth] = (0, import_react_native_ui_common7.useStoreNumberState)("desktopSidebarWidth", 240);
|
|
2176
|
+
const [addonsPanelHeight, setAddonsPanelHeight] = (0, import_react_native_ui_common7.useStoreNumberState)(
|
|
2177
|
+
"desktopAddonsPanelHeight",
|
|
2178
|
+
300
|
|
2179
|
+
);
|
|
2180
|
+
const { width: windowWidth, height: windowHeight } = (0, import_react_native12.useWindowDimensions)();
|
|
2181
|
+
const handleSidebarResize = (0, import_react17.useCallback)(
|
|
2182
|
+
(delta) => {
|
|
2183
|
+
setSidebarWidth((prev) => Math.min(Math.max(prev + delta, 180), windowWidth * 0.5));
|
|
2184
|
+
},
|
|
2185
|
+
[setSidebarWidth, windowWidth]
|
|
2186
|
+
);
|
|
2187
|
+
const handleAddonsPanelResize = (0, import_react17.useCallback)(
|
|
2188
|
+
(delta) => {
|
|
2189
|
+
setAddonsPanelHeight((prev) => Math.min(Math.max(prev - delta, 100), windowHeight * 0.6));
|
|
2190
|
+
},
|
|
2191
|
+
[setAddonsPanelHeight, windowHeight]
|
|
2192
|
+
);
|
|
2193
|
+
const [isResizing, setIsResizing] = (0, import_react17.useState)(false);
|
|
2194
|
+
const onResizeStart = (0, import_react17.useCallback)(() => setIsResizing(true), []);
|
|
2195
|
+
const onResizeEnd = (0, import_react17.useCallback)(() => setIsResizing(false), []);
|
|
2196
|
+
const [uiHidden, setUiHidden] = (0, import_react17.useState)(false);
|
|
2197
|
+
(0, import_react17.useLayoutEffect)(() => {
|
|
2105
2198
|
setUiHidden(story?.parameters?.storybookUIVisibility === "hidden");
|
|
2106
2199
|
}, [story?.parameters?.storybookUIVisibility]);
|
|
2107
2200
|
const desktopSidebarStyle = (0, import_react_native_ui_common7.useStyle)(
|
|
2108
2201
|
() => ({
|
|
2109
|
-
width: desktopSidebarOpen ?
|
|
2202
|
+
width: desktopSidebarOpen ? sidebarWidth : void 0,
|
|
2110
2203
|
padding: desktopSidebarOpen ? 0 : 10,
|
|
2111
2204
|
borderColor: theme.appBorderColor,
|
|
2112
|
-
borderRightWidth: 1
|
|
2205
|
+
borderRightWidth: desktopSidebarOpen ? 0 : 1
|
|
2113
2206
|
}),
|
|
2114
|
-
[desktopSidebarOpen, theme.appBorderColor]
|
|
2207
|
+
[desktopSidebarOpen, sidebarWidth, theme.appBorderColor]
|
|
2115
2208
|
);
|
|
2116
2209
|
const desktopAddonsPanelStyle = (0, import_react_native_ui_common7.useStyle)(
|
|
2117
2210
|
() => ({
|
|
2118
|
-
height: desktopAddonsPanelOpen ?
|
|
2119
|
-
borderTopWidth: 1,
|
|
2211
|
+
height: desktopAddonsPanelOpen ? addonsPanelHeight : void 0,
|
|
2212
|
+
borderTopWidth: desktopAddonsPanelOpen ? 0 : 1,
|
|
2120
2213
|
borderColor: theme.appBorderColor,
|
|
2121
2214
|
paddingTop: desktopAddonsPanelOpen ? 4 : 0,
|
|
2122
2215
|
padding: desktopAddonsPanelOpen ? 0 : 10
|
|
2123
2216
|
}),
|
|
2124
|
-
[desktopAddonsPanelOpen, theme.appBorderColor]
|
|
2217
|
+
[desktopAddonsPanelOpen, addonsPanelHeight, theme.appBorderColor]
|
|
2125
2218
|
);
|
|
2126
2219
|
const containerStyle2 = (0, import_react_native_ui_common7.useStyle)(() => {
|
|
2127
2220
|
if (isDesktop) {
|
|
@@ -2163,54 +2256,76 @@ var Layout = ({
|
|
|
2163
2256
|
}),
|
|
2164
2257
|
[theme.barTextColor]
|
|
2165
2258
|
);
|
|
2166
|
-
const mobileMenuDrawerRef = (0,
|
|
2167
|
-
const addonPanelRef = (0,
|
|
2168
|
-
const setSelection = (0,
|
|
2259
|
+
const mobileMenuDrawerRef = (0, import_react17.useRef)(null);
|
|
2260
|
+
const addonPanelRef = (0, import_react17.useRef)(null);
|
|
2261
|
+
const setSelection = (0, import_react17.useCallback)(({ storyId: newStoryId }) => {
|
|
2169
2262
|
const channel = import_manager_api2.addons.getChannel();
|
|
2170
2263
|
channel.emit(import_core_events.SET_CURRENT_STORY, { storyId: newStoryId });
|
|
2171
2264
|
}, []);
|
|
2172
|
-
return /* @__PURE__ */ (0,
|
|
2173
|
-
isDesktop ? /* @__PURE__ */ (0,
|
|
2174
|
-
/* @__PURE__ */ (0,
|
|
2175
|
-
/* @__PURE__ */ (0,
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2265
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native12.View, { style: containerStyle2, children: [
|
|
2266
|
+
isDesktop ? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
2267
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native12.View, { style: desktopSidebarStyle, pointerEvents: isResizing ? "none" : "auto", children: desktopSidebarOpen ? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
2268
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native12.View, { style: desktopLogoContainer, children: [
|
|
2269
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(StorybookLogo, { theme }),
|
|
2270
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native_ui_common7.IconButton, { onPress: () => setDesktopSidebarOpen(false), Icon: MenuIcon })
|
|
2271
|
+
] }),
|
|
2272
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native12.View, { style: flexStyle6, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2273
|
+
Sidebar,
|
|
2274
|
+
{
|
|
2275
|
+
previewInitialized: true,
|
|
2276
|
+
indexError: void 0,
|
|
2277
|
+
refs: placeholderObject,
|
|
2278
|
+
setSelection,
|
|
2279
|
+
status: placeholderObject,
|
|
2280
|
+
index: storyHash,
|
|
2281
|
+
storyId: story?.id,
|
|
2282
|
+
refId: DEFAULT_REF_ID
|
|
2283
|
+
}
|
|
2284
|
+
) })
|
|
2285
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native_ui_common7.IconButton, { onPress: () => setDesktopSidebarOpen(true), Icon: MenuIcon }) }),
|
|
2286
|
+
desktopSidebarOpen ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2287
|
+
ResizeHandle,
|
|
2180
2288
|
{
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
status: placeholderObject,
|
|
2186
|
-
index: storyHash,
|
|
2187
|
-
storyId: story?.id,
|
|
2188
|
-
refId: DEFAULT_REF_ID
|
|
2289
|
+
direction: "horizontal",
|
|
2290
|
+
onResize: handleSidebarResize,
|
|
2291
|
+
onResizeStart,
|
|
2292
|
+
onResizeEnd
|
|
2189
2293
|
}
|
|
2190
|
-
)
|
|
2191
|
-
] }) :
|
|
2192
|
-
/* @__PURE__ */ (0,
|
|
2193
|
-
/* @__PURE__ */ (0,
|
|
2194
|
-
story?.parameters?.hideFullScreenButton || isDesktop ? null : /* @__PURE__ */ (0,
|
|
2195
|
-
|
|
2294
|
+
) : null
|
|
2295
|
+
] }) : null,
|
|
2296
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native12.View, { style: mobileContentStyle, children: [
|
|
2297
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native12.View, { style: contentContainerStyle, pointerEvents: isResizing ? "none" : "auto", children }),
|
|
2298
|
+
story?.parameters?.hideFullScreenButton || isDesktop ? null : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2299
|
+
import_react_native12.TouchableOpacity,
|
|
2196
2300
|
{
|
|
2197
2301
|
style: fullScreenButtonStyle,
|
|
2198
2302
|
hitSlop: { top: 10, bottom: 10, left: 10, right: 10 },
|
|
2199
2303
|
onPress: () => setUiHidden((prev) => !prev),
|
|
2200
|
-
children: uiHidden ? /* @__PURE__ */ (0,
|
|
2304
|
+
children: uiHidden ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(CloseFullscreenIcon, { color: theme.color.mediumdark }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(FullscreenIcon, { color: theme.color.mediumdark })
|
|
2201
2305
|
}
|
|
2202
2306
|
),
|
|
2203
|
-
isDesktop ? /* @__PURE__ */ (0,
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2307
|
+
isDesktop ? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
2308
|
+
desktopAddonsPanelOpen ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2309
|
+
ResizeHandle,
|
|
2310
|
+
{
|
|
2311
|
+
direction: "vertical",
|
|
2312
|
+
onResize: handleAddonsPanelResize,
|
|
2313
|
+
onResizeStart,
|
|
2314
|
+
onResizeEnd
|
|
2315
|
+
}
|
|
2316
|
+
) : null,
|
|
2317
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native12.View, { style: desktopAddonsPanelStyle, pointerEvents: isResizing ? "none" : "auto", children: desktopAddonsPanelOpen ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(AddonsTabs, { storyId: story?.id, onClose: () => setDesktopAddonsPanelOpen(false) }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2318
|
+
import_react_native_ui_common7.IconButton,
|
|
2319
|
+
{
|
|
2320
|
+
style: iconFloatRightStyle,
|
|
2321
|
+
onPress: () => setDesktopAddonsPanelOpen(true),
|
|
2322
|
+
Icon: BottomBarToggleIcon
|
|
2323
|
+
}
|
|
2324
|
+
) })
|
|
2325
|
+
] }) : null
|
|
2211
2326
|
] }),
|
|
2212
|
-
!uiHidden && !isDesktop ? /* @__PURE__ */ (0,
|
|
2213
|
-
/* @__PURE__ */ (0,
|
|
2327
|
+
!uiHidden && !isDesktop ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Container2, { style: navContainerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Nav, { children: [
|
|
2328
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
2214
2329
|
Button2,
|
|
2215
2330
|
{
|
|
2216
2331
|
testID: "mobile-menu-button",
|
|
@@ -2218,8 +2333,8 @@ var Layout = ({
|
|
|
2218
2333
|
hitSlop: navButtonHitSlop,
|
|
2219
2334
|
onPress: () => mobileMenuDrawerRef.current?.setMobileMenuOpen(true),
|
|
2220
2335
|
children: [
|
|
2221
|
-
/* @__PURE__ */ (0,
|
|
2222
|
-
/* @__PURE__ */ (0,
|
|
2336
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MenuIcon, { color: theme.color.mediumdark }),
|
|
2337
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_react_native12.Text, { style: navButtonTextStyle, numberOfLines: 1, children: [
|
|
2223
2338
|
story?.title,
|
|
2224
2339
|
"/",
|
|
2225
2340
|
story?.name
|
|
@@ -2227,7 +2342,7 @@ var Layout = ({
|
|
|
2227
2342
|
]
|
|
2228
2343
|
}
|
|
2229
2344
|
),
|
|
2230
|
-
/* @__PURE__ */ (0,
|
|
2345
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2231
2346
|
import_react_native_ui_common7.IconButton,
|
|
2232
2347
|
{
|
|
2233
2348
|
testID: "mobile-addons-button",
|
|
@@ -2237,9 +2352,9 @@ var Layout = ({
|
|
|
2237
2352
|
}
|
|
2238
2353
|
)
|
|
2239
2354
|
] }) }) : null,
|
|
2240
|
-
isDesktop ? null : /* @__PURE__ */ (0,
|
|
2241
|
-
/* @__PURE__ */ (0,
|
|
2242
|
-
/* @__PURE__ */ (0,
|
|
2355
|
+
isDesktop ? null : /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(MobileMenuDrawer, { ref: mobileMenuDrawerRef, children: [
|
|
2356
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_native12.View, { style: mobileMenuDrawerContentStyle, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(StorybookLogo, { theme }) }),
|
|
2357
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
2243
2358
|
Sidebar,
|
|
2244
2359
|
{
|
|
2245
2360
|
previewInitialized: true,
|
|
@@ -2253,10 +2368,10 @@ var Layout = ({
|
|
|
2253
2368
|
}
|
|
2254
2369
|
)
|
|
2255
2370
|
] }),
|
|
2256
|
-
isDesktop ? null : /* @__PURE__ */ (0,
|
|
2371
|
+
isDesktop ? null : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(MobileAddonsPanel, { ref: addonPanelRef, storyId: story?.id })
|
|
2257
2372
|
] });
|
|
2258
2373
|
};
|
|
2259
|
-
var Nav =
|
|
2374
|
+
var Nav = import_react_native_theming11.styled.View({
|
|
2260
2375
|
display: "flex",
|
|
2261
2376
|
flexDirection: "row",
|
|
2262
2377
|
alignItems: "center",
|
|
@@ -2265,14 +2380,14 @@ var Nav = import_react_native_theming10.styled.View({
|
|
|
2265
2380
|
height: 40,
|
|
2266
2381
|
paddingHorizontal: 6
|
|
2267
2382
|
});
|
|
2268
|
-
var Container2 =
|
|
2383
|
+
var Container2 = import_react_native_theming11.styled.View(({ theme }) => ({
|
|
2269
2384
|
alignSelf: "flex-end",
|
|
2270
2385
|
width: "100%",
|
|
2271
2386
|
backgroundColor: theme.barBg,
|
|
2272
2387
|
borderTopColor: theme.appBorderColor,
|
|
2273
2388
|
borderTopWidth: 1
|
|
2274
2389
|
}));
|
|
2275
|
-
var Button2 =
|
|
2390
|
+
var Button2 = import_react_native_theming11.styled.TouchableOpacity(({ theme }) => ({
|
|
2276
2391
|
display: "flex",
|
|
2277
2392
|
flexDirection: "row",
|
|
2278
2393
|
alignItems: "center",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/react-native-ui-lite",
|
|
3
|
-
"version": "10.2.2-alpha.
|
|
3
|
+
"version": "10.2.2-alpha.2",
|
|
4
4
|
"description": "lightweight ui components for react native storybook",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"@legendapp/list": "3.0.0-beta.31",
|
|
43
43
|
"@nozbe/microfuzz": "^1.0.0",
|
|
44
44
|
"@storybook/react": "^10.2.2",
|
|
45
|
-
"@storybook/react-native-theming": "^10.2.2-alpha.
|
|
46
|
-
"@storybook/react-native-ui-common": "^10.2.2-alpha.
|
|
45
|
+
"@storybook/react-native-theming": "^10.2.2-alpha.2",
|
|
46
|
+
"@storybook/react-native-ui-common": "^10.2.2-alpha.2",
|
|
47
47
|
"polished": "^4.3.1",
|
|
48
48
|
"react-native-safe-area-context": "^5"
|
|
49
49
|
},
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "af294af11927af3754f6958f0f6f2a358897f7b9"
|
|
62
62
|
}
|
package/src/Layout.tsx
CHANGED
|
@@ -8,10 +8,11 @@ import {
|
|
|
8
8
|
StorageProvider,
|
|
9
9
|
useLayout,
|
|
10
10
|
useStoreBooleanState,
|
|
11
|
+
useStoreNumberState,
|
|
11
12
|
useStyle,
|
|
12
13
|
} from '@storybook/react-native-ui-common';
|
|
13
14
|
import { ReactElement, ReactNode, useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
14
|
-
import { Text, TouchableOpacity, View, ViewStyle } from 'react-native';
|
|
15
|
+
import { Text, TouchableOpacity, useWindowDimensions, View, ViewStyle } from 'react-native';
|
|
15
16
|
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
16
17
|
import { SET_CURRENT_STORY } from 'storybook/internal/core-events';
|
|
17
18
|
import type { Args, StoryContext } from 'storybook/internal/csf';
|
|
@@ -19,6 +20,7 @@ import { type API_IndexHash } from 'storybook/internal/types';
|
|
|
19
20
|
import { addons } from 'storybook/manager-api';
|
|
20
21
|
import { AddonsTabs, MobileAddonsPanel, MobileAddonsPanelRef } from './MobileAddonsPanel';
|
|
21
22
|
import { MobileMenuDrawer, MobileMenuDrawerRef } from './MobileMenuDrawer';
|
|
23
|
+
import { ResizeHandle } from './ResizeHandle';
|
|
22
24
|
import { SelectedNodeProvider } from './SelectedNodeProvider';
|
|
23
25
|
import { Sidebar } from './Sidebar';
|
|
24
26
|
import { StorybookLogo } from './StorybookLogo';
|
|
@@ -105,6 +107,34 @@ export const Layout = ({
|
|
|
105
107
|
true
|
|
106
108
|
);
|
|
107
109
|
|
|
110
|
+
const [sidebarWidth, setSidebarWidth] = useStoreNumberState('desktopSidebarWidth', 240);
|
|
111
|
+
const [addonsPanelHeight, setAddonsPanelHeight] = useStoreNumberState(
|
|
112
|
+
'desktopAddonsPanelHeight',
|
|
113
|
+
300
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const { width: windowWidth, height: windowHeight } = useWindowDimensions();
|
|
117
|
+
|
|
118
|
+
const handleSidebarResize = useCallback(
|
|
119
|
+
(delta: number) => {
|
|
120
|
+
setSidebarWidth((prev) => Math.min(Math.max(prev + delta, 180), windowWidth * 0.5));
|
|
121
|
+
},
|
|
122
|
+
[setSidebarWidth, windowWidth]
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const handleAddonsPanelResize = useCallback(
|
|
126
|
+
(delta: number) => {
|
|
127
|
+
// Negative delta = dragging up = panel gets larger
|
|
128
|
+
setAddonsPanelHeight((prev) => Math.min(Math.max(prev - delta, 100), windowHeight * 0.6));
|
|
129
|
+
},
|
|
130
|
+
[setAddonsPanelHeight, windowHeight]
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const [isResizing, setIsResizing] = useState(false);
|
|
134
|
+
|
|
135
|
+
const onResizeStart = useCallback(() => setIsResizing(true), []);
|
|
136
|
+
const onResizeEnd = useCallback(() => setIsResizing(false), []);
|
|
137
|
+
|
|
108
138
|
const [uiHidden, setUiHidden] = useState(false);
|
|
109
139
|
|
|
110
140
|
useLayoutEffect(() => {
|
|
@@ -113,23 +143,23 @@ export const Layout = ({
|
|
|
113
143
|
|
|
114
144
|
const desktopSidebarStyle = useStyle(
|
|
115
145
|
() => ({
|
|
116
|
-
width: desktopSidebarOpen ?
|
|
146
|
+
width: desktopSidebarOpen ? sidebarWidth : undefined,
|
|
117
147
|
padding: desktopSidebarOpen ? 0 : 10,
|
|
118
148
|
borderColor: theme.appBorderColor,
|
|
119
|
-
borderRightWidth: 1,
|
|
149
|
+
borderRightWidth: desktopSidebarOpen ? 0 : 1,
|
|
120
150
|
}),
|
|
121
|
-
[desktopSidebarOpen, theme.appBorderColor]
|
|
151
|
+
[desktopSidebarOpen, sidebarWidth, theme.appBorderColor]
|
|
122
152
|
);
|
|
123
153
|
|
|
124
154
|
const desktopAddonsPanelStyle = useStyle(
|
|
125
155
|
() => ({
|
|
126
|
-
height: desktopAddonsPanelOpen ?
|
|
127
|
-
borderTopWidth: 1,
|
|
156
|
+
height: desktopAddonsPanelOpen ? addonsPanelHeight : undefined,
|
|
157
|
+
borderTopWidth: desktopAddonsPanelOpen ? 0 : 1,
|
|
128
158
|
borderColor: theme.appBorderColor,
|
|
129
159
|
paddingTop: desktopAddonsPanelOpen ? 4 : 0,
|
|
130
160
|
padding: desktopAddonsPanelOpen ? 0 : 10,
|
|
131
161
|
}),
|
|
132
|
-
[desktopAddonsPanelOpen, theme.appBorderColor]
|
|
162
|
+
[desktopAddonsPanelOpen, addonsPanelHeight, theme.appBorderColor]
|
|
133
163
|
);
|
|
134
164
|
|
|
135
165
|
const containerStyle = useStyle(() => {
|
|
@@ -189,36 +219,48 @@ export const Layout = ({
|
|
|
189
219
|
return (
|
|
190
220
|
<View style={containerStyle}>
|
|
191
221
|
{isDesktop ? (
|
|
192
|
-
|
|
222
|
+
<>
|
|
223
|
+
<View style={desktopSidebarStyle} pointerEvents={isResizing ? 'none' : 'auto'}>
|
|
224
|
+
{desktopSidebarOpen ? (
|
|
225
|
+
<>
|
|
226
|
+
<View style={desktopLogoContainer}>
|
|
227
|
+
<StorybookLogo theme={theme} />
|
|
228
|
+
|
|
229
|
+
<IconButton onPress={() => setDesktopSidebarOpen(false)} Icon={MenuIcon} />
|
|
230
|
+
</View>
|
|
231
|
+
|
|
232
|
+
<View style={flexStyle}>
|
|
233
|
+
<Sidebar
|
|
234
|
+
previewInitialized
|
|
235
|
+
indexError={undefined}
|
|
236
|
+
refs={placeholderObject}
|
|
237
|
+
setSelection={setSelection}
|
|
238
|
+
status={placeholderObject}
|
|
239
|
+
index={storyHash}
|
|
240
|
+
storyId={story?.id}
|
|
241
|
+
refId={DEFAULT_REF_ID}
|
|
242
|
+
/>
|
|
243
|
+
</View>
|
|
244
|
+
</>
|
|
245
|
+
) : (
|
|
246
|
+
<IconButton onPress={() => setDesktopSidebarOpen(true)} Icon={MenuIcon} />
|
|
247
|
+
)}
|
|
248
|
+
</View>
|
|
193
249
|
{desktopSidebarOpen ? (
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
<Sidebar
|
|
203
|
-
previewInitialized
|
|
204
|
-
indexError={undefined}
|
|
205
|
-
refs={placeholderObject}
|
|
206
|
-
setSelection={setSelection}
|
|
207
|
-
status={placeholderObject}
|
|
208
|
-
index={storyHash}
|
|
209
|
-
storyId={story?.id}
|
|
210
|
-
refId={DEFAULT_REF_ID}
|
|
211
|
-
/>
|
|
212
|
-
</View>
|
|
213
|
-
</>
|
|
214
|
-
) : (
|
|
215
|
-
<IconButton onPress={() => setDesktopSidebarOpen(true)} Icon={MenuIcon} />
|
|
216
|
-
)}
|
|
217
|
-
</View>
|
|
250
|
+
<ResizeHandle
|
|
251
|
+
direction="horizontal"
|
|
252
|
+
onResize={handleSidebarResize}
|
|
253
|
+
onResizeStart={onResizeStart}
|
|
254
|
+
onResizeEnd={onResizeEnd}
|
|
255
|
+
/>
|
|
256
|
+
) : null}
|
|
257
|
+
</>
|
|
218
258
|
) : null}
|
|
219
259
|
|
|
220
260
|
<View style={mobileContentStyle}>
|
|
221
|
-
<View style={contentContainerStyle}
|
|
261
|
+
<View style={contentContainerStyle} pointerEvents={isResizing ? 'none' : 'auto'}>
|
|
262
|
+
{children}
|
|
263
|
+
</View>
|
|
222
264
|
|
|
223
265
|
{story?.parameters?.hideFullScreenButton || isDesktop ? null : (
|
|
224
266
|
<TouchableOpacity
|
|
@@ -235,17 +277,27 @@ export const Layout = ({
|
|
|
235
277
|
)}
|
|
236
278
|
|
|
237
279
|
{isDesktop ? (
|
|
238
|
-
|
|
280
|
+
<>
|
|
239
281
|
{desktopAddonsPanelOpen ? (
|
|
240
|
-
<
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
Icon={BottomBarToggleIcon}
|
|
282
|
+
<ResizeHandle
|
|
283
|
+
direction="vertical"
|
|
284
|
+
onResize={handleAddonsPanelResize}
|
|
285
|
+
onResizeStart={onResizeStart}
|
|
286
|
+
onResizeEnd={onResizeEnd}
|
|
246
287
|
/>
|
|
247
|
-
)}
|
|
248
|
-
|
|
288
|
+
) : null}
|
|
289
|
+
<View style={desktopAddonsPanelStyle} pointerEvents={isResizing ? 'none' : 'auto'}>
|
|
290
|
+
{desktopAddonsPanelOpen ? (
|
|
291
|
+
<AddonsTabs storyId={story?.id} onClose={() => setDesktopAddonsPanelOpen(false)} />
|
|
292
|
+
) : (
|
|
293
|
+
<IconButton
|
|
294
|
+
style={iconFloatRightStyle}
|
|
295
|
+
onPress={() => setDesktopAddonsPanelOpen(true)}
|
|
296
|
+
Icon={BottomBarToggleIcon}
|
|
297
|
+
/>
|
|
298
|
+
)}
|
|
299
|
+
</View>
|
|
300
|
+
</>
|
|
249
301
|
) : null}
|
|
250
302
|
</View>
|
|
251
303
|
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { useTheme } from '@storybook/react-native-theming';
|
|
2
|
+
import { memo, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { PanResponder, View, ViewStyle } from 'react-native';
|
|
4
|
+
|
|
5
|
+
interface ResizeHandleProps {
|
|
6
|
+
direction: 'horizontal' | 'vertical';
|
|
7
|
+
onResize: (delta: number) => void;
|
|
8
|
+
onResizeStart?: () => void;
|
|
9
|
+
onResizeEnd?: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const ResizeHandle = memo(function ResizeHandle({
|
|
13
|
+
direction,
|
|
14
|
+
onResize,
|
|
15
|
+
onResizeStart,
|
|
16
|
+
onResizeEnd,
|
|
17
|
+
}: ResizeHandleProps) {
|
|
18
|
+
const theme = useTheme();
|
|
19
|
+
const [active, setActive] = useState(false);
|
|
20
|
+
const startValueRef = useRef(0);
|
|
21
|
+
|
|
22
|
+
const isHorizontal = direction === 'horizontal';
|
|
23
|
+
|
|
24
|
+
const panResponder = useMemo(
|
|
25
|
+
() =>
|
|
26
|
+
PanResponder.create({
|
|
27
|
+
onStartShouldSetPanResponder: () => true,
|
|
28
|
+
onMoveShouldSetPanResponder: () => true,
|
|
29
|
+
onPanResponderTerminationRequest: () => false,
|
|
30
|
+
onShouldBlockNativeResponder: () => true,
|
|
31
|
+
onPanResponderGrant: () => {
|
|
32
|
+
startValueRef.current = 0;
|
|
33
|
+
setActive(true);
|
|
34
|
+
onResizeStart?.();
|
|
35
|
+
},
|
|
36
|
+
onPanResponderMove: (_, gestureState) => {
|
|
37
|
+
const delta = isHorizontal ? gestureState.dx : gestureState.dy;
|
|
38
|
+
const diff = delta - startValueRef.current;
|
|
39
|
+
startValueRef.current = delta;
|
|
40
|
+
onResize(diff);
|
|
41
|
+
},
|
|
42
|
+
onPanResponderRelease: () => {
|
|
43
|
+
setActive(false);
|
|
44
|
+
onResizeEnd?.();
|
|
45
|
+
},
|
|
46
|
+
onPanResponderTerminate: () => {
|
|
47
|
+
setActive(false);
|
|
48
|
+
onResizeEnd?.();
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
[isHorizontal, onResize, onResizeStart, onResizeEnd]
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const style = useMemo((): ViewStyle => {
|
|
55
|
+
const borderColor = active ? theme.barSelectedColor : theme.appBorderColor;
|
|
56
|
+
|
|
57
|
+
if (isHorizontal) {
|
|
58
|
+
return {
|
|
59
|
+
width: 5,
|
|
60
|
+
alignSelf: 'stretch',
|
|
61
|
+
justifyContent: 'center',
|
|
62
|
+
borderLeftWidth: 1,
|
|
63
|
+
borderLeftColor: borderColor,
|
|
64
|
+
backgroundColor: active ? theme.barSelectedColor : 'transparent',
|
|
65
|
+
// @ts-expect-error - cursor is supported on web and desktop platforms
|
|
66
|
+
cursor: 'col-resize',
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
height: 5,
|
|
72
|
+
alignSelf: 'stretch',
|
|
73
|
+
justifyContent: 'center',
|
|
74
|
+
borderTopWidth: 1,
|
|
75
|
+
borderTopColor: borderColor,
|
|
76
|
+
backgroundColor: active ? theme.barSelectedColor : 'transparent',
|
|
77
|
+
// @ts-expect-error - cursor is supported on web and desktop platforms
|
|
78
|
+
cursor: 'row-resize',
|
|
79
|
+
};
|
|
80
|
+
}, [active, isHorizontal, theme.appBorderColor, theme.barSelectedColor]);
|
|
81
|
+
|
|
82
|
+
return <View {...panResponder.panHandlers} style={style} />;
|
|
83
|
+
});
|
package/src/Tree.tsx
CHANGED
|
@@ -41,13 +41,14 @@ interface NodeProps {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
const TextItem = styled.Text(({ theme }) => ({
|
|
44
|
+
fontSize: theme.typography.size.s2 + 1,
|
|
44
45
|
color: theme.color.defaultText,
|
|
45
46
|
}));
|
|
46
47
|
|
|
47
48
|
export const Node = React.memo<NodeProps>(function Node({
|
|
48
49
|
item,
|
|
49
50
|
refId,
|
|
50
|
-
isOrphan,
|
|
51
|
+
isOrphan: _isOrphan,
|
|
51
52
|
isDisplayed: _isDisplayed,
|
|
52
53
|
isSelected,
|
|
53
54
|
isFullyExpanded,
|
|
@@ -66,7 +67,7 @@ export const Node = React.memo<NodeProps>(function Node({
|
|
|
66
67
|
selected={isSelected}
|
|
67
68
|
key={id}
|
|
68
69
|
id={id}
|
|
69
|
-
depth={
|
|
70
|
+
depth={item.depth}
|
|
70
71
|
onPress={() => {
|
|
71
72
|
onSelectStoryId(item.id);
|
|
72
73
|
}}
|
|
@@ -118,7 +119,7 @@ export const Node = React.memo<NodeProps>(function Node({
|
|
|
118
119
|
id={id}
|
|
119
120
|
aria-controls={item.children && item.children[0]}
|
|
120
121
|
aria-expanded={isExpanded}
|
|
121
|
-
depth={
|
|
122
|
+
depth={item.depth}
|
|
122
123
|
isComponent={item.type === 'component'}
|
|
123
124
|
isExpandable={item.children && item.children.length > 0}
|
|
124
125
|
isExpanded={isExpanded}
|
|
@@ -168,15 +169,17 @@ export const RootNodeText = styled.Text(({ theme }) => ({
|
|
|
168
169
|
}));
|
|
169
170
|
|
|
170
171
|
const CollapseButton = styled.TouchableOpacity(() => ({
|
|
172
|
+
flex: 1,
|
|
171
173
|
display: 'flex',
|
|
172
174
|
flexDirection: 'row',
|
|
173
|
-
paddingVertical: 0,
|
|
174
175
|
paddingHorizontal: 8,
|
|
176
|
+
paddingTop: 8,
|
|
177
|
+
paddingBottom: 7,
|
|
175
178
|
borderRadius: 4,
|
|
176
179
|
gap: 6,
|
|
177
180
|
alignItems: 'center',
|
|
178
181
|
cursor: 'pointer',
|
|
179
|
-
|
|
182
|
+
minHeight: 34,
|
|
180
183
|
}));
|
|
181
184
|
|
|
182
185
|
const flexStyle: ViewStyle = { flex: 1 };
|
package/src/TreeNode.tsx
CHANGED
|
@@ -31,7 +31,6 @@ const BranchNode = styled.TouchableOpacity<{
|
|
|
31
31
|
display: 'flex',
|
|
32
32
|
flexDirection: 'row',
|
|
33
33
|
alignItems: 'center',
|
|
34
|
-
alignSelf: 'flex-start',
|
|
35
34
|
paddingLeft: (isExpandable ? 8 : 22) + depth * 18,
|
|
36
35
|
|
|
37
36
|
backgroundColor: 'transparent',
|
|
@@ -50,7 +49,6 @@ const BranchNode = styled.TouchableOpacity<{
|
|
|
50
49
|
|
|
51
50
|
const LeafNode = styled.TouchableOpacity<{ depth?: number; selected?: boolean }>(
|
|
52
51
|
({ depth = 0, selected, theme }) => ({
|
|
53
|
-
alignSelf: 'flex-start',
|
|
54
52
|
cursor: 'pointer',
|
|
55
53
|
color: 'inherit',
|
|
56
54
|
display: 'flex',
|