@xsolla/xui-b2b-sidebar 0.150.0 → 0.152.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/native/index.js CHANGED
@@ -40,8 +40,10 @@ __export(index_exports, {
40
40
  SidebarMenuCollapsible: () => SidebarMenuCollapsible,
41
41
  SidebarMenuItem: () => SidebarMenuItem,
42
42
  SidebarMenuSub: () => SidebarMenuSub,
43
+ SidebarPinnedList: () => SidebarPinnedList,
43
44
  SidebarProvider: () => SidebarProvider,
44
45
  SidebarTrigger: () => SidebarTrigger,
46
+ getPinnedCollapsedItem: () => getPinnedCollapsedItem,
45
47
  useSidebar: () => useSidebar
46
48
  });
47
49
  module.exports = __toCommonJS(index_exports);
@@ -1200,6 +1202,7 @@ var import_jsx_runtime9 = require("react/jsx-runtime");
1200
1202
  var SidebarGroup = ({
1201
1203
  label,
1202
1204
  dataId,
1205
+ pinnedToBottom,
1203
1206
  children
1204
1207
  }) => {
1205
1208
  const { theme } = (0, import_xui_core6.useResolvedTheme)();
@@ -1211,6 +1214,7 @@ var SidebarGroup = ({
1211
1214
  "data-id": dataId,
1212
1215
  role: label ? "group" : void 0,
1213
1216
  "aria-label": label,
1217
+ style: pinnedToBottom ? { marginTop: "auto" } : void 0,
1214
1218
  children: [
1215
1219
  label && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1216
1220
  Box,
@@ -1303,8 +1307,76 @@ var IconBox = import_styled_components5.default.div`
1303
1307
  color: inherit;
1304
1308
 
1305
1309
  svg {
1306
- width: ${(p) => p.$pin ? "12px" : `${p.$size}px`};
1307
- height: ${(p) => p.$pin ? "12px" : `${p.$size}px`};
1310
+ width: ${(p) => p.$size}px;
1311
+ height: ${(p) => p.$size}px;
1312
+ }
1313
+ `;
1314
+ var PinDragSlot = import_styled_components5.default.div`
1315
+ position: relative;
1316
+ width: ${(p) => p.$size}px;
1317
+ height: ${(p) => p.$size}px;
1318
+ flex-shrink: 0;
1319
+ cursor: grab;
1320
+
1321
+ .${ITEM_BASE_CLASS}:active & {
1322
+ cursor: grabbing;
1323
+ }
1324
+ `;
1325
+ var PinDragLayer = import_styled_components5.default.div`
1326
+ position: absolute;
1327
+ inset: 0;
1328
+ display: flex;
1329
+ align-items: center;
1330
+ justify-content: center;
1331
+ color: inherit;
1332
+ opacity: ${(p) => p.$hideOnHover ? 1 : 0};
1333
+ transition: opacity 0.15s ease-in-out;
1334
+
1335
+ .${ITEM_BASE_CLASS}:hover & {
1336
+ opacity: ${(p) => p.$hideOnHover ? 0 : 1};
1337
+ }
1338
+
1339
+ svg {
1340
+ width: 12px;
1341
+ height: 12px;
1342
+ }
1343
+ `;
1344
+ var PinButton = import_styled_components5.default.button`
1345
+ display: flex;
1346
+ width: ${(p) => p.$size}px;
1347
+ height: ${(p) => p.$size}px;
1348
+ flex-shrink: 0;
1349
+ margin-left: auto;
1350
+ align-items: center;
1351
+ justify-content: center;
1352
+ padding: 0;
1353
+ border: none;
1354
+ background: transparent;
1355
+ color: ${(p) => p.$isPinned ? p.$activeColor : p.$color};
1356
+ cursor: pointer;
1357
+ border-radius: 4px;
1358
+ opacity: 0;
1359
+ transition:
1360
+ opacity 0.15s ease-in-out,
1361
+ color 0.15s ease-in-out;
1362
+
1363
+ .${ITEM_BASE_CLASS}:hover & {
1364
+ opacity: 1;
1365
+ }
1366
+
1367
+ &:hover {
1368
+ color: ${(p) => p.$hoverColor};
1369
+ }
1370
+
1371
+ &:focus-visible {
1372
+ opacity: 1;
1373
+ outline: 1px solid currentColor;
1374
+ outline-offset: 1px;
1375
+ }
1376
+
1377
+ svg {
1378
+ width: 12px;
1379
+ height: 12px;
1308
1380
  }
1309
1381
  `;
1310
1382
  var LabelBox = import_styled_components5.default.span`
@@ -1356,6 +1428,8 @@ var SidebarMenuItem = ({
1356
1428
  dataId,
1357
1429
  isActive,
1358
1430
  isPinned,
1431
+ onPinToggle,
1432
+ dragHandle,
1359
1433
  showBadge,
1360
1434
  hasTooltip,
1361
1435
  beta,
@@ -1396,7 +1470,10 @@ var SidebarMenuItem = ({
1396
1470
  activeClassName: ITEM_ACTIVE_CLASS,
1397
1471
  dataId,
1398
1472
  children: [
1399
- icon && !isNested && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconBox, { $size: sizing.iconSize, $pin: isPinned, children: icon }),
1473
+ !isNested && (isPinned && dragHandle ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(PinDragSlot, { $size: sizing.iconSize, "data-drag-handle": "true", children: [
1474
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(PinDragLayer, { $size: sizing.iconSize, $hideOnHover: true, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_xui_icons_base2.Pin, { size: 12, variant: "solid" }) }),
1475
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(PinDragLayer, { $size: sizing.iconSize, $hideOnHover: false, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_xui_icons_base2.Drag, { size: 12, variant: "line" }) })
1476
+ ] }) : isPinned ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconBox, { $size: sizing.iconSize, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_xui_icons_base2.Pin, { size: 12, variant: "solid" }) }) : icon ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(IconBox, { $size: sizing.iconSize, children: icon }) : null),
1400
1477
  extra,
1401
1478
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(LabelBox, { children: [
1402
1479
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
@@ -1416,6 +1493,33 @@ var SidebarMenuItem = ({
1416
1493
  }
1417
1494
  )
1418
1495
  ] }),
1496
+ onPinToggle && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1497
+ import_xui_tooltip.Tooltip,
1498
+ {
1499
+ content: isPinned ? "Unpin" : "Pin",
1500
+ placement: "top",
1501
+ size: "sm",
1502
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1503
+ PinButton,
1504
+ {
1505
+ type: "button",
1506
+ "aria-label": isPinned ? "Unpin item" : "Pin item",
1507
+ "aria-pressed": Boolean(isPinned),
1508
+ $size: sizing.iconSize,
1509
+ $color: theme.colors.content.tertiary,
1510
+ $hoverColor: theme.colors.content.primary,
1511
+ $activeColor: theme.colors.content.primary,
1512
+ $isPinned: Boolean(isPinned),
1513
+ onClick: (e) => {
1514
+ e.preventDefault();
1515
+ e.stopPropagation();
1516
+ onPinToggle(e);
1517
+ },
1518
+ children: isPinned ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_xui_icons_base2.Remove, { size: 12, variant: "line" }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_xui_icons_base2.Pin, { size: 12, variant: "solid" })
1519
+ }
1520
+ )
1521
+ }
1522
+ ),
1419
1523
  beta && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1420
1524
  BetaTag,
1421
1525
  {
@@ -1489,7 +1593,7 @@ var ExpandRegion = import_styled_components6.default.div`
1489
1593
  overflow: hidden;
1490
1594
  }
1491
1595
 
1492
- & .${ITEM_BASE_CLASS} {
1596
+ && .${ITEM_BASE_CLASS} {
1493
1597
  position: relative;
1494
1598
  padding: 0 ${(p) => p.$padding}px 0 ${(p) => p.$nestedPaddingLeft}px;
1495
1599
  font-weight: 400;
@@ -1506,7 +1610,7 @@ var ExpandRegion = import_styled_components6.default.div`
1506
1610
  }
1507
1611
  }
1508
1612
 
1509
- & .${ITEM_ACTIVE_CLASS} {
1613
+ && .${ITEM_ACTIVE_CLASS} {
1510
1614
  font-weight: 500;
1511
1615
  color: ${(p) => p.$colorActive};
1512
1616
  background-color: ${(p) => p.$activeBg};
@@ -1729,6 +1833,92 @@ var SidebarChatButton = ({
1729
1833
  }
1730
1834
  );
1731
1835
  };
1836
+
1837
+ // src/SidebarPinnedList.tsx
1838
+ var import_react4 = require("react");
1839
+ var import_xui_icons_base5 = require("@xsolla/xui-icons-base");
1840
+ var import_jsx_runtime15 = require("react/jsx-runtime");
1841
+ var SidebarPinnedList = ({
1842
+ items,
1843
+ onUnpin,
1844
+ onReorder,
1845
+ spacers = true
1846
+ }) => {
1847
+ const [dragKey, setDragKey] = (0, import_react4.useState)(null);
1848
+ const canReorder = Boolean(onReorder) && items.length > 1;
1849
+ if (items.length === 0) return null;
1850
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
1851
+ spacers && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { style: { height: 8 } }),
1852
+ items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1853
+ "div",
1854
+ {
1855
+ "data-pinned-key": item.key,
1856
+ onPointerDown: (e) => {
1857
+ if (!canReorder) return;
1858
+ const t = e.target;
1859
+ if (!t.closest('[data-drag-handle="true"]')) return;
1860
+ e.preventDefault();
1861
+ setDragKey(item.key);
1862
+ e.currentTarget.setPointerCapture(e.pointerId);
1863
+ },
1864
+ onPointerMove: (e) => {
1865
+ if (dragKey !== item.key) return;
1866
+ const elt = document.elementFromPoint(
1867
+ e.clientX,
1868
+ e.clientY
1869
+ );
1870
+ const row = elt?.closest("[data-pinned-key]");
1871
+ const overKey = row?.getAttribute("data-pinned-key");
1872
+ if (overKey && overKey !== dragKey) {
1873
+ onReorder?.(dragKey, overKey);
1874
+ }
1875
+ },
1876
+ onPointerUp: (e) => {
1877
+ if (dragKey === item.key) {
1878
+ e.currentTarget.releasePointerCapture(
1879
+ e.pointerId
1880
+ );
1881
+ setDragKey(null);
1882
+ }
1883
+ },
1884
+ onPointerCancel: () => {
1885
+ if (dragKey === item.key) setDragKey(null);
1886
+ },
1887
+ style: {
1888
+ opacity: dragKey === item.key ? 0.4 : 1,
1889
+ transition: "opacity 0.15s ease-in-out",
1890
+ touchAction: canReorder ? "none" : void 0
1891
+ },
1892
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
1893
+ SidebarMenuItem,
1894
+ {
1895
+ to: item.to,
1896
+ label: item.label,
1897
+ exact: item.exact,
1898
+ isPinned: true,
1899
+ dragHandle: canReorder,
1900
+ onPinToggle: () => onUnpin(item.key)
1901
+ }
1902
+ )
1903
+ },
1904
+ item.key
1905
+ )),
1906
+ spacers && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { style: { height: 8 } })
1907
+ ] });
1908
+ };
1909
+ var getPinnedCollapsedItem = (items, options = {}) => {
1910
+ if (items.length === 0) return null;
1911
+ return {
1912
+ label: options.label ?? "Pinned",
1913
+ icon: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_xui_icons_base5.Pin, { size: 18, variant: "solid" }),
1914
+ dataId: options.dataId ?? "sidebar-collapsed-pinned",
1915
+ children: items.map((i) => ({
1916
+ to: i.to,
1917
+ label: i.label,
1918
+ exact: i.exact
1919
+ }))
1920
+ };
1921
+ };
1732
1922
  // Annotate the CommonJS export names for ESM import in node:
1733
1923
  0 && (module.exports = {
1734
1924
  Sidebar,
@@ -1741,8 +1931,10 @@ var SidebarChatButton = ({
1741
1931
  SidebarMenuCollapsible,
1742
1932
  SidebarMenuItem,
1743
1933
  SidebarMenuSub,
1934
+ SidebarPinnedList,
1744
1935
  SidebarProvider,
1745
1936
  SidebarTrigger,
1937
+ getPinnedCollapsedItem,
1746
1938
  useSidebar
1747
1939
  });
1748
1940
  //# sourceMappingURL=index.js.map