@ttoss/layouts 0.4.14 → 0.4.16
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/esm/index.js +148 -42
- package/dist/index.d.ts +9 -2
- package/package.json +6 -4
package/dist/esm/index.js
CHANGED
|
@@ -2275,11 +2275,23 @@ var Icon2 = React2.forwardRef((props, ref) => {
|
|
|
2275
2275
|
Icon2.displayName = "Icon";
|
|
2276
2276
|
|
|
2277
2277
|
// src/components/Header.tsx
|
|
2278
|
-
import { Box as Box3, Flex, IconButton } from "@ttoss/ui";
|
|
2279
|
-
import * as
|
|
2278
|
+
import { Box as Box3, Flex as Flex2, IconButton as IconButton2 } from "@ttoss/ui";
|
|
2279
|
+
import * as React5 from "react";
|
|
2280
2280
|
|
|
2281
2281
|
// src/components/LayoutProvider.tsx
|
|
2282
2282
|
import * as React3 from "react";
|
|
2283
|
+
|
|
2284
|
+
// src/useIsDesktop.ts
|
|
2285
|
+
import { useBreakpointIndex } from "@ttoss/ui";
|
|
2286
|
+
var useIsDesktop = () => {
|
|
2287
|
+
const breakpointIndex = useBreakpointIndex();
|
|
2288
|
+
const isDesktop = breakpointIndex >= 2;
|
|
2289
|
+
return {
|
|
2290
|
+
isDesktop
|
|
2291
|
+
};
|
|
2292
|
+
};
|
|
2293
|
+
|
|
2294
|
+
// src/components/LayoutProvider.tsx
|
|
2283
2295
|
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
2284
2296
|
var LayoutContext = React3.createContext({
|
|
2285
2297
|
isSidebarOpen: true,
|
|
@@ -2289,6 +2301,14 @@ var LayoutProvider = ({
|
|
|
2289
2301
|
children
|
|
2290
2302
|
}) => {
|
|
2291
2303
|
const [isSidebarOpen, setIsSidebarOpen] = React3.useState(true);
|
|
2304
|
+
const {
|
|
2305
|
+
isDesktop
|
|
2306
|
+
} = useIsDesktop();
|
|
2307
|
+
React3.useEffect(() => {
|
|
2308
|
+
if (!isDesktop) {
|
|
2309
|
+
setIsSidebarOpen(false);
|
|
2310
|
+
}
|
|
2311
|
+
}, [isDesktop]);
|
|
2292
2312
|
const toggleSidebar = () => {
|
|
2293
2313
|
setIsSidebarOpen(prev => {
|
|
2294
2314
|
return !prev;
|
|
@@ -2311,37 +2331,121 @@ var useLayout = () => {
|
|
|
2311
2331
|
};
|
|
2312
2332
|
|
|
2313
2333
|
// src/components/Sidebar.tsx
|
|
2314
|
-
import {
|
|
2315
|
-
import {
|
|
2334
|
+
import { Drawer } from "@ttoss/components/Drawer";
|
|
2335
|
+
import { Box as Box2, Flex, IconButton } from "@ttoss/ui";
|
|
2336
|
+
import * as React4 from "react";
|
|
2337
|
+
import { Fragment, jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
2316
2338
|
var SIDEBAR_WIDTH = "2xs";
|
|
2317
|
-
var Sidebar =
|
|
2339
|
+
var Sidebar = ({
|
|
2340
|
+
drawerSlot,
|
|
2341
|
+
showSidebarButtonInDrawer,
|
|
2342
|
+
children,
|
|
2343
|
+
...boxProps
|
|
2344
|
+
}) => {
|
|
2318
2345
|
const {
|
|
2319
|
-
isSidebarOpen
|
|
2346
|
+
isSidebarOpen,
|
|
2347
|
+
toggleSidebar
|
|
2320
2348
|
} = useLayout();
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2349
|
+
const {
|
|
2350
|
+
isDesktop
|
|
2351
|
+
} = useIsDesktop();
|
|
2352
|
+
const sidebarButtonInDrawer = React4.useMemo(() => {
|
|
2353
|
+
if (!showSidebarButtonInDrawer) {
|
|
2354
|
+
return null;
|
|
2355
|
+
}
|
|
2356
|
+
return /* @__PURE__ */jsx4(IconButton, {
|
|
2357
|
+
"aria-label": isSidebarOpen ? "Close sidebar" : "Open sidebar",
|
|
2358
|
+
"aria-expanded": isSidebarOpen,
|
|
2359
|
+
"aria-controls": "sidebar",
|
|
2360
|
+
sx: {
|
|
2361
|
+
cursor: "pointer",
|
|
2362
|
+
fontSize: ["xl", "2xl"]
|
|
2363
|
+
},
|
|
2364
|
+
"data-testid": "sidebar-button",
|
|
2365
|
+
children: /* @__PURE__ */jsx4(Icon2, {
|
|
2366
|
+
icon: isSidebarOpen ? "sidebar-close" : "sidebar-open"
|
|
2367
|
+
})
|
|
2368
|
+
});
|
|
2369
|
+
}, [isSidebarOpen, showSidebarButtonInDrawer]);
|
|
2370
|
+
const memoizedDrawerSlot = React4.useMemo(() => {
|
|
2371
|
+
if (!drawerSlot) {
|
|
2372
|
+
return /* @__PURE__ */jsx4(Fragment, {
|
|
2373
|
+
children: sidebarButtonInDrawer
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2376
|
+
return /* @__PURE__ */jsxs(Flex, {
|
|
2377
|
+
sx: {
|
|
2378
|
+
minWidth: SIDEBAR_WIDTH,
|
|
2379
|
+
width: SIDEBAR_WIDTH,
|
|
2380
|
+
borderRight: "sm",
|
|
2381
|
+
borderColor: "display.border.muted.default",
|
|
2382
|
+
alignItems: "center",
|
|
2383
|
+
gap: "2"
|
|
2384
|
+
},
|
|
2385
|
+
children: [sidebarButtonInDrawer, drawerSlot]
|
|
2386
|
+
});
|
|
2387
|
+
}, [drawerSlot, sidebarButtonInDrawer]);
|
|
2388
|
+
return /* @__PURE__ */jsx4(Fragment, {
|
|
2389
|
+
children: isDesktop ? /* @__PURE__ */jsx4(Box2, {
|
|
2390
|
+
role: "complementary",
|
|
2391
|
+
"aria-label": "Sidebar",
|
|
2392
|
+
"aria-hidden": !isSidebarOpen,
|
|
2393
|
+
sx: {
|
|
2394
|
+
position: "relative",
|
|
2395
|
+
zIndex: "dropdown",
|
|
2396
|
+
height: "full",
|
|
2397
|
+
minHeight: isSidebarOpen ? "full" : "0",
|
|
2398
|
+
width: isSidebarOpen ? SIDEBAR_WIDTH : "0",
|
|
2399
|
+
minWidth: isSidebarOpen ? SIDEBAR_WIDTH : "0",
|
|
2400
|
+
opacity: isSidebarOpen ? 1 : 0,
|
|
2401
|
+
transition: "width 0.5s ease, opacity 0.5s ease",
|
|
2402
|
+
borderRight: isSidebarOpen ? "sm" : "none",
|
|
2403
|
+
borderColor: "display.border.muted.default",
|
|
2404
|
+
backgroundColor: "navigation.background.muted.default",
|
|
2405
|
+
paddingX: isSidebarOpen ? "6" : "0",
|
|
2406
|
+
paddingY: isSidebarOpen ? "6" : "0",
|
|
2407
|
+
overflowY: "auto",
|
|
2408
|
+
...boxProps.sx
|
|
2409
|
+
},
|
|
2410
|
+
children: isSidebarOpen ? children : null
|
|
2411
|
+
}) : /* @__PURE__ */jsx4(Box2, {
|
|
2412
|
+
role: "complementary",
|
|
2413
|
+
"aria-label": "Sidebar",
|
|
2414
|
+
"aria-hidden": !isSidebarOpen,
|
|
2415
|
+
sx: {
|
|
2416
|
+
position: "fixed",
|
|
2417
|
+
border: "none",
|
|
2418
|
+
width: isSidebarOpen ? "full" : "0",
|
|
2419
|
+
height: isSidebarOpen ? "full" : "0",
|
|
2420
|
+
...boxProps.sx
|
|
2421
|
+
},
|
|
2422
|
+
onClick: () => {
|
|
2423
|
+
if (isSidebarOpen) {
|
|
2424
|
+
toggleSidebar();
|
|
2425
|
+
}
|
|
2426
|
+
},
|
|
2427
|
+
children: /* @__PURE__ */jsx4(Drawer, {
|
|
2428
|
+
open: isSidebarOpen,
|
|
2429
|
+
direction: "left",
|
|
2430
|
+
size: "100%",
|
|
2431
|
+
enableOverlay: false,
|
|
2432
|
+
children: /* @__PURE__ */jsxs(Flex, {
|
|
2433
|
+
sx: {
|
|
2434
|
+
width: "full",
|
|
2435
|
+
height: "full",
|
|
2436
|
+
gap: "6",
|
|
2437
|
+
flexDirection: "column"
|
|
2438
|
+
},
|
|
2439
|
+
children: [memoizedDrawerSlot, isSidebarOpen ? children : null]
|
|
2440
|
+
})
|
|
2441
|
+
})
|
|
2442
|
+
})
|
|
2339
2443
|
});
|
|
2340
2444
|
};
|
|
2341
2445
|
Sidebar.displayName = "Sidebar";
|
|
2342
2446
|
|
|
2343
2447
|
// src/components/Header.tsx
|
|
2344
|
-
import { Fragment, jsx as jsx5, jsxs } from "react/jsx-runtime";
|
|
2448
|
+
import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
2345
2449
|
var paddingSx = {
|
|
2346
2450
|
paddingX: "4",
|
|
2347
2451
|
paddingY: "3"
|
|
@@ -2356,11 +2460,11 @@ var Header = ({
|
|
|
2356
2460
|
isSidebarOpen,
|
|
2357
2461
|
toggleSidebar
|
|
2358
2462
|
} = useLayout();
|
|
2359
|
-
const sidebarButton =
|
|
2463
|
+
const sidebarButton = React5.useMemo(() => {
|
|
2360
2464
|
if (!showSidebarButton) {
|
|
2361
2465
|
return null;
|
|
2362
2466
|
}
|
|
2363
|
-
return /* @__PURE__ */jsx5(
|
|
2467
|
+
return /* @__PURE__ */jsx5(IconButton2, {
|
|
2364
2468
|
"aria-label": isSidebarOpen ? "Close sidebar" : "Open sidebar",
|
|
2365
2469
|
"aria-expanded": isSidebarOpen,
|
|
2366
2470
|
"aria-controls": "sidebar",
|
|
@@ -2375,13 +2479,13 @@ var Header = ({
|
|
|
2375
2479
|
})
|
|
2376
2480
|
});
|
|
2377
2481
|
}, [isSidebarOpen, showSidebarButton, toggleSidebar]);
|
|
2378
|
-
const memoizedSidebarSlot =
|
|
2482
|
+
const memoizedSidebarSlot = React5.useMemo(() => {
|
|
2379
2483
|
if (!sidebarSlot) {
|
|
2380
|
-
return /* @__PURE__ */jsx5(
|
|
2484
|
+
return /* @__PURE__ */jsx5(Fragment2, {
|
|
2381
2485
|
children: sidebarButton
|
|
2382
2486
|
});
|
|
2383
2487
|
}
|
|
2384
|
-
return /* @__PURE__ */
|
|
2488
|
+
return /* @__PURE__ */jsxs2(Flex2, {
|
|
2385
2489
|
sx: {
|
|
2386
2490
|
minWidth: SIDEBAR_WIDTH,
|
|
2387
2491
|
width: SIDEBAR_WIDTH,
|
|
@@ -2394,7 +2498,7 @@ var Header = ({
|
|
|
2394
2498
|
children: [sidebarButton, sidebarSlot]
|
|
2395
2499
|
});
|
|
2396
2500
|
}, [sidebarButton, sidebarSlot]);
|
|
2397
|
-
return /* @__PURE__ */
|
|
2501
|
+
return /* @__PURE__ */jsxs2(Flex2, {
|
|
2398
2502
|
variant: "layout.header",
|
|
2399
2503
|
...boxProps,
|
|
2400
2504
|
as: "header",
|
|
@@ -2404,6 +2508,7 @@ var Header = ({
|
|
|
2404
2508
|
alignItems: "center",
|
|
2405
2509
|
borderBottom: "sm",
|
|
2406
2510
|
borderColor: "display.border.muted.default",
|
|
2511
|
+
backgroundColor: "navigation.background.primary.default",
|
|
2407
2512
|
...(sidebarSlot ? {} : paddingSx),
|
|
2408
2513
|
...boxProps.sx
|
|
2409
2514
|
},
|
|
@@ -2456,10 +2561,10 @@ Layout.Footer = Footer;
|
|
|
2456
2561
|
Layout.Container = Container;
|
|
2457
2562
|
|
|
2458
2563
|
// src/components/SidebarCollapseLayout.tsx
|
|
2459
|
-
import { Flex as
|
|
2564
|
+
import { Flex as Flex3, Stack } from "@ttoss/ui";
|
|
2460
2565
|
|
|
2461
2566
|
// src/getSemanticElements.ts
|
|
2462
|
-
import * as
|
|
2567
|
+
import * as React6 from "react";
|
|
2463
2568
|
var semanticComponents = {
|
|
2464
2569
|
Header: "header",
|
|
2465
2570
|
Sidebar: "sidebar",
|
|
@@ -2470,7 +2575,7 @@ var getSematicElements = ({
|
|
|
2470
2575
|
children
|
|
2471
2576
|
}) => {
|
|
2472
2577
|
const semanticElements = {};
|
|
2473
|
-
|
|
2578
|
+
React6.Children.forEach(children, child => {
|
|
2474
2579
|
const displayName = child?.type?.displayName;
|
|
2475
2580
|
if (!displayName) {
|
|
2476
2581
|
return;
|
|
@@ -2483,7 +2588,7 @@ var getSematicElements = ({
|
|
|
2483
2588
|
};
|
|
2484
2589
|
|
|
2485
2590
|
// src/components/SidebarCollapseLayout.tsx
|
|
2486
|
-
import { jsx as jsx8, jsxs as
|
|
2591
|
+
import { jsx as jsx8, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
2487
2592
|
var SidebarCollapseLayout = ({
|
|
2488
2593
|
children,
|
|
2489
2594
|
...props
|
|
@@ -2496,19 +2601,20 @@ var SidebarCollapseLayout = ({
|
|
|
2496
2601
|
children
|
|
2497
2602
|
});
|
|
2498
2603
|
return /* @__PURE__ */jsx8(LayoutProvider, {
|
|
2499
|
-
children: /* @__PURE__ */
|
|
2604
|
+
children: /* @__PURE__ */jsxs3(Stack, {
|
|
2500
2605
|
...props,
|
|
2501
2606
|
sx: {
|
|
2502
|
-
height: ["
|
|
2607
|
+
height: ["100vh"],
|
|
2503
2608
|
width: "full",
|
|
2504
2609
|
overflow: "hidden",
|
|
2505
2610
|
...props.sx
|
|
2506
2611
|
},
|
|
2507
|
-
children: [header, /* @__PURE__ */
|
|
2612
|
+
children: [header, /* @__PURE__ */jsxs3(Flex3, {
|
|
2508
2613
|
sx: {
|
|
2509
2614
|
width: "full",
|
|
2510
2615
|
flex: 1,
|
|
2511
|
-
overflow: "hidden"
|
|
2616
|
+
overflow: "hidden",
|
|
2617
|
+
flexDirection: ["row"]
|
|
2512
2618
|
},
|
|
2513
2619
|
children: [sidebar, main]
|
|
2514
2620
|
})]
|
|
@@ -2518,7 +2624,7 @@ var SidebarCollapseLayout = ({
|
|
|
2518
2624
|
|
|
2519
2625
|
// src/components/StackedLayout.tsx
|
|
2520
2626
|
import { Stack as Stack2 } from "@ttoss/ui";
|
|
2521
|
-
import { jsx as jsx9, jsxs as
|
|
2627
|
+
import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
2522
2628
|
var StackedLayout = ({
|
|
2523
2629
|
children,
|
|
2524
2630
|
...props
|
|
@@ -2531,13 +2637,13 @@ var StackedLayout = ({
|
|
|
2531
2637
|
children
|
|
2532
2638
|
});
|
|
2533
2639
|
return /* @__PURE__ */jsx9(LayoutProvider, {
|
|
2534
|
-
children: /* @__PURE__ */
|
|
2640
|
+
children: /* @__PURE__ */jsxs4(Stack2, {
|
|
2535
2641
|
...props,
|
|
2536
2642
|
children: [header, main, footer]
|
|
2537
2643
|
})
|
|
2538
2644
|
});
|
|
2539
2645
|
};
|
|
2540
|
-
export { Layout, SidebarCollapseLayout, StackedLayout };
|
|
2646
|
+
export { Layout, SidebarCollapseLayout, StackedLayout, useIsDesktop };
|
|
2541
2647
|
/*! Bundled license information:
|
|
2542
2648
|
|
|
2543
2649
|
iconify-icon/dist/iconify-icon.mjs:
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,10 @@ declare const Layout: {
|
|
|
12
12
|
displayName: string;
|
|
13
13
|
};
|
|
14
14
|
Sidebar: {
|
|
15
|
-
(
|
|
15
|
+
({ drawerSlot, showSidebarButtonInDrawer, children, ...boxProps }: BoxProps & {
|
|
16
|
+
showSidebarButtonInDrawer?: boolean;
|
|
17
|
+
drawerSlot?: React.ReactNode;
|
|
18
|
+
}): react_jsx_runtime.JSX.Element;
|
|
16
19
|
displayName: string;
|
|
17
20
|
};
|
|
18
21
|
Main: {
|
|
@@ -30,4 +33,8 @@ declare const SidebarCollapseLayout: ({ children, ...props }: React.PropsWithChi
|
|
|
30
33
|
|
|
31
34
|
declare const StackedLayout: ({ children, ...props }: react.PropsWithChildren<StackProps>) => react_jsx_runtime.JSX.Element;
|
|
32
35
|
|
|
33
|
-
|
|
36
|
+
declare const useIsDesktop: () => {
|
|
37
|
+
isDesktop: boolean;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { Layout, SidebarCollapseLayout, StackedLayout, useIsDesktop };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/layouts",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.16",
|
|
4
4
|
"description": "Layout components for React",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"sideEffects": false,
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": ">=16.8.0",
|
|
28
|
-
"@ttoss/
|
|
28
|
+
"@ttoss/components": "^2.2.8",
|
|
29
|
+
"@ttoss/ui": "^5.5.5"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/jest": "^29.5.14",
|
|
@@ -33,10 +34,11 @@
|
|
|
33
34
|
"jest": "^29.7.0",
|
|
34
35
|
"react": "^19.0.0",
|
|
35
36
|
"tsup": "^8.3.5",
|
|
36
|
-
"@ttoss/
|
|
37
|
+
"@ttoss/components": "^2.2.8",
|
|
37
38
|
"@ttoss/config": "^1.35.2",
|
|
38
39
|
"@ttoss/test-utils": "^2.1.22",
|
|
39
|
-
"@ttoss/ui": "^5.5.
|
|
40
|
+
"@ttoss/ui": "^5.5.5",
|
|
41
|
+
"@ttoss/react-icons": "^0.4.9"
|
|
40
42
|
},
|
|
41
43
|
"keywords": [
|
|
42
44
|
"React"
|