@xsolla/xui-b2b-sidebar 0.193.0 → 0.195.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/web/index.mjs CHANGED
@@ -10,6 +10,24 @@ import {
10
10
  useState,
11
11
  useCallback
12
12
  } from "react";
13
+
14
+ // src/labels.ts
15
+ var DEFAULT_SIDEBAR_LABELS = {
16
+ navigation: "Sidebar navigation",
17
+ expandSidebar: "Expand sidebar",
18
+ collapseSidebar: "Collapse sidebar",
19
+ chat: "Chat",
20
+ openChat: "Open chat",
21
+ pin: "Pin",
22
+ unpin: "Unpin",
23
+ pinItem: "Pin item",
24
+ unpinItem: "Unpin item",
25
+ beta: "Beta",
26
+ pinned: "Pinned"
27
+ };
28
+ var resolveSidebarLabels = (overrides) => overrides ? { ...DEFAULT_SIDEBAR_LABELS, ...overrides } : DEFAULT_SIDEBAR_LABELS;
29
+
30
+ // src/SidebarContext.tsx
13
31
  import { jsx } from "react/jsx-runtime";
14
32
  var DefaultLink = ({
15
33
  to,
@@ -43,13 +61,15 @@ var SidebarContext = createContext({
43
61
  LinkComponent: DefaultLink,
44
62
  expandedId: null,
45
63
  onExpandedIdChange: () => {
46
- }
64
+ },
65
+ labels: DEFAULT_SIDEBAR_LABELS
47
66
  });
48
67
  var SidebarProvider = ({
49
68
  collapsed: collapsedProp,
50
69
  onCollapsedChange,
51
70
  pathname = "",
52
71
  linkComponent,
72
+ labels: labelsProp,
53
73
  children
54
74
  }) => {
55
75
  const [internalCollapsed, setInternalCollapsed] = useState(false);
@@ -65,6 +85,12 @@ var SidebarProvider = ({
65
85
  const onExpandedIdChange = useCallback((id) => {
66
86
  setExpandedId(id);
67
87
  }, []);
88
+ const labelsKey = labelsProp ? JSON.stringify(labelsProp) : "";
89
+ const labels = useMemo(
90
+ () => resolveSidebarLabels(labelsProp),
91
+ // eslint-disable-next-line react-hooks/exhaustive-deps
92
+ [labelsKey]
93
+ );
68
94
  const value = useMemo(
69
95
  () => ({
70
96
  collapsed,
@@ -72,7 +98,8 @@ var SidebarProvider = ({
72
98
  pathname,
73
99
  LinkComponent: linkComponent || DefaultLink,
74
100
  expandedId,
75
- onExpandedIdChange
101
+ onExpandedIdChange,
102
+ labels
76
103
  }),
77
104
  [
78
105
  collapsed,
@@ -80,7 +107,8 @@ var SidebarProvider = ({
80
107
  pathname,
81
108
  linkComponent,
82
109
  expandedId,
83
- onExpandedIdChange
110
+ onExpandedIdChange,
111
+ labels
84
112
  ]
85
113
  );
86
114
  return /* @__PURE__ */ jsx(SidebarContext.Provider, { value, children });
@@ -702,9 +730,11 @@ var SidebarCollapsed = ({
702
730
  onToggleCollapse,
703
731
  onChatClick,
704
732
  showChat = true,
705
- chatBadge = false
733
+ chatBadge = false,
734
+ chatAriaLabel,
735
+ expandLabel
706
736
  }) => {
707
- const { pathname } = useSidebar();
737
+ const { pathname, labels } = useSidebar();
708
738
  const { theme } = useResolvedTheme();
709
739
  const sizing = theme.sizing.sidebar();
710
740
  const colors = theme.colors;
@@ -791,7 +821,7 @@ var SidebarCollapsed = ({
791
821
  {
792
822
  onClick: onChatClick,
793
823
  type: "button",
794
- "aria-label": "Open chat",
824
+ "aria-label": chatAriaLabel ?? labels.openChat,
795
825
  $size: sizing.itemHeight,
796
826
  $radius: sizing.radius,
797
827
  $bg: colors.control.brand.primary.bg,
@@ -816,7 +846,7 @@ var SidebarCollapsed = ({
816
846
  {
817
847
  onClick: onToggleCollapse,
818
848
  type: "button",
819
- "aria-label": "Expand sidebar",
849
+ "aria-label": expandLabel ?? labels.expandSidebar,
820
850
  "aria-pressed": true,
821
851
  $size: sizing.itemHeight,
822
852
  $radius: sizing.radius,
@@ -902,16 +932,17 @@ var Sidebar = ({
902
932
  showChat = true,
903
933
  onChatClick,
904
934
  chatBadge = false,
935
+ navigationLabel,
905
936
  children
906
937
  }) => {
907
- const { collapsed, onCollapsedChange } = useSidebar();
938
+ const { collapsed, onCollapsedChange, labels } = useSidebar();
908
939
  const { theme } = useResolvedTheme2();
909
940
  const sizing = theme.sizing.sidebar();
910
941
  return /* @__PURE__ */ jsxs3(
911
942
  Outer2,
912
943
  {
913
944
  role: "navigation",
914
- "aria-label": "Sidebar navigation",
945
+ "aria-label": navigationLabel ?? labels.navigation,
915
946
  $expanded: sizing.widthExpanded,
916
947
  $collapsed: sizing.widthCollapsed,
917
948
  $width: collapsed ? sizing.widthCollapsed : sizing.widthExpanded,
@@ -1307,8 +1338,11 @@ var ToggleButton = styled5.button`
1307
1338
  height: ${(p) => p.$iconSize}px;
1308
1339
  }
1309
1340
  `;
1310
- var SidebarTrigger = () => {
1311
- const { collapsed, onCollapsedChange } = useSidebar();
1341
+ var SidebarTrigger = ({
1342
+ expandLabel,
1343
+ collapseLabel
1344
+ }) => {
1345
+ const { collapsed, onCollapsedChange, labels } = useSidebar();
1312
1346
  const { theme } = useResolvedTheme5();
1313
1347
  const sizing = theme.sizing.sidebar();
1314
1348
  return /* @__PURE__ */ jsx8(
@@ -1316,7 +1350,7 @@ var SidebarTrigger = () => {
1316
1350
  {
1317
1351
  type: "button",
1318
1352
  onClick: () => onCollapsedChange(!collapsed),
1319
- "aria-label": collapsed ? "Expand sidebar" : "Collapse sidebar",
1353
+ "aria-label": collapsed ? expandLabel ?? labels.expandSidebar : collapseLabel ?? labels.collapseSidebar,
1320
1354
  "aria-pressed": collapsed,
1321
1355
  $size: sizing.itemHeight,
1322
1356
  $radius: sizing.radius,
@@ -1571,13 +1605,20 @@ var SidebarMenuItem = ({
1571
1605
  beta,
1572
1606
  multiLine,
1573
1607
  extra,
1574
- isNested = false
1608
+ isNested = false,
1609
+ pinLabel,
1610
+ unpinLabel,
1611
+ pinAriaLabel,
1612
+ unpinAriaLabel,
1613
+ betaLabel
1575
1614
  }) => {
1576
- const { LinkComponent } = useSidebar();
1615
+ const { LinkComponent, labels } = useSidebar();
1577
1616
  const { theme } = useResolvedTheme7();
1578
1617
  const sizing = theme.sizing.sidebar();
1579
1618
  const shouldTruncate = Boolean(hasTooltip) && typeof label === "string" && label.length > TOOLTIP_TRUNCATE_LENGTH;
1580
1619
  const displayLabel = shouldTruncate ? /* @__PURE__ */ jsx11(Tooltip, { content: label, placement: "right", size: "md", children: /* @__PURE__ */ jsx11("span", { children: `${label.slice(0, TOOLTIP_TRUNCATE_LENGTH)}\u2026` }) }) : label;
1620
+ const pinTooltip = isPinned ? unpinLabel ?? labels.unpin : pinLabel ?? labels.pin;
1621
+ const pinAria = isPinned ? unpinAriaLabel ?? labels.unpinItem : pinAriaLabel ?? labels.pinItem;
1581
1622
  return /* @__PURE__ */ jsx11(
1582
1623
  ItemWrapper,
1583
1624
  {
@@ -1629,40 +1670,32 @@ var SidebarMenuItem = ({
1629
1670
  }
1630
1671
  )
1631
1672
  ] }),
1632
- onPinToggle && /* @__PURE__ */ jsx11(
1633
- Tooltip,
1673
+ onPinToggle && /* @__PURE__ */ jsx11(Tooltip, { content: pinTooltip, placement: "top", size: "sm", children: /* @__PURE__ */ jsx11(
1674
+ PinButton,
1634
1675
  {
1635
- content: isPinned ? "Unpin" : "Pin",
1636
- placement: "top",
1637
- size: "sm",
1638
- children: /* @__PURE__ */ jsx11(
1639
- PinButton,
1640
- {
1641
- type: "button",
1642
- "aria-label": isPinned ? "Unpin item" : "Pin item",
1643
- "aria-pressed": Boolean(isPinned),
1644
- $size: sizing.iconSize,
1645
- $color: theme.colors.content.tertiary,
1646
- $hoverColor: theme.colors.content.primary,
1647
- $activeColor: theme.colors.content.primary,
1648
- $isPinned: Boolean(isPinned),
1649
- onClick: (e) => {
1650
- e.preventDefault();
1651
- e.stopPropagation();
1652
- onPinToggle(e);
1653
- },
1654
- children: isPinned ? /* @__PURE__ */ jsx11(Remove, { size: 12, variant: "line" }) : /* @__PURE__ */ jsx11(Pin, { size: 12, variant: "solid" })
1655
- }
1656
- )
1676
+ type: "button",
1677
+ "aria-label": pinAria,
1678
+ "aria-pressed": Boolean(isPinned),
1679
+ $size: sizing.iconSize,
1680
+ $color: theme.colors.content.tertiary,
1681
+ $hoverColor: theme.colors.content.primary,
1682
+ $activeColor: theme.colors.content.primary,
1683
+ $isPinned: Boolean(isPinned),
1684
+ onClick: (e) => {
1685
+ e.preventDefault();
1686
+ e.stopPropagation();
1687
+ onPinToggle(e);
1688
+ },
1689
+ children: isPinned ? /* @__PURE__ */ jsx11(Remove, { size: 12, variant: "line" }) : /* @__PURE__ */ jsx11(Pin, { size: 12, variant: "solid" })
1657
1690
  }
1658
- ),
1691
+ ) }),
1659
1692
  beta && /* @__PURE__ */ jsx11(
1660
1693
  BetaTag,
1661
1694
  {
1662
1695
  $bg: theme.colors.overlay.mono,
1663
1696
  $color: theme.colors.content.tertiary,
1664
1697
  $radius: sizing.radius,
1665
- children: "Beta"
1698
+ children: betaLabel ?? labels.beta
1666
1699
  }
1667
1700
  ),
1668
1701
  external && hasExternalIcon && /* @__PURE__ */ jsx11(
@@ -1938,9 +1971,11 @@ var Badge = styled8.span`
1938
1971
  `;
1939
1972
  var SidebarChatButton = ({
1940
1973
  onClick,
1941
- badge
1974
+ badge,
1975
+ label
1942
1976
  }) => {
1943
1977
  const { theme } = useResolvedTheme9();
1978
+ const { labels } = useSidebar();
1944
1979
  const sizing = theme.sizing.sidebar();
1945
1980
  return /* @__PURE__ */ jsxs7(
1946
1981
  ChatButton,
@@ -1957,7 +1992,7 @@ var SidebarChatButton = ({
1957
1992
  $focusOutlineWidth: sizing.focusOutlineWidth,
1958
1993
  children: [
1959
1994
  /* @__PURE__ */ jsx14(ChatTwoMessages2, { size: 16, variant: "line" }),
1960
- /* @__PURE__ */ jsx14(Typography5, { variant: "bodySmAccent", color: "inherit", children: "Chat" }),
1995
+ /* @__PURE__ */ jsx14(Typography5, { variant: "bodySmAccent", color: "inherit", children: label ?? labels.chat }),
1961
1996
  badge && /* @__PURE__ */ jsx14(
1962
1997
  Badge,
1963
1998
  {
@@ -2045,7 +2080,7 @@ var SidebarPinnedList = ({
2045
2080
  var getPinnedCollapsedItem = (items, options = {}) => {
2046
2081
  if (items.length === 0) return null;
2047
2082
  return {
2048
- label: options.label ?? "Pinned",
2083
+ label: options.label ?? DEFAULT_SIDEBAR_LABELS.pinned,
2049
2084
  icon: /* @__PURE__ */ jsx15(Pin2, { size: 18, variant: "solid" }),
2050
2085
  dataId: options.dataId ?? "sidebar-collapsed-pinned",
2051
2086
  children: items.map((i) => ({
@@ -2056,6 +2091,7 @@ var getPinnedCollapsedItem = (items, options = {}) => {
2056
2091
  };
2057
2092
  };
2058
2093
  export {
2094
+ DEFAULT_SIDEBAR_LABELS,
2059
2095
  Sidebar,
2060
2096
  SidebarChatButton,
2061
2097
  SidebarCollapsed,
@@ -2070,6 +2106,7 @@ export {
2070
2106
  SidebarProvider,
2071
2107
  SidebarTrigger,
2072
2108
  getPinnedCollapsedItem,
2109
+ resolveSidebarLabels,
2073
2110
  useSidebar
2074
2111
  };
2075
2112
  //# sourceMappingURL=index.mjs.map