@xsolla/xui-b2b-sidebar 0.194.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/native/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,
@@ -1234,8 +1265,11 @@ var ToggleButton = styled4.button`
1234
1265
  height: ${(p) => p.$iconSize}px;
1235
1266
  }
1236
1267
  `;
1237
- var SidebarTrigger = () => {
1238
- const { collapsed, onCollapsedChange } = useSidebar();
1268
+ var SidebarTrigger = ({
1269
+ expandLabel,
1270
+ collapseLabel
1271
+ }) => {
1272
+ const { collapsed, onCollapsedChange, labels } = useSidebar();
1239
1273
  const { theme } = useResolvedTheme5();
1240
1274
  const sizing = theme.sizing.sidebar();
1241
1275
  return /* @__PURE__ */ jsx8(
@@ -1243,7 +1277,7 @@ var SidebarTrigger = () => {
1243
1277
  {
1244
1278
  type: "button",
1245
1279
  onClick: () => onCollapsedChange(!collapsed),
1246
- "aria-label": collapsed ? "Expand sidebar" : "Collapse sidebar",
1280
+ "aria-label": collapsed ? expandLabel ?? labels.expandSidebar : collapseLabel ?? labels.collapseSidebar,
1247
1281
  "aria-pressed": collapsed,
1248
1282
  $size: sizing.itemHeight,
1249
1283
  $radius: sizing.radius,
@@ -1498,13 +1532,20 @@ var SidebarMenuItem = ({
1498
1532
  beta,
1499
1533
  multiLine,
1500
1534
  extra,
1501
- isNested = false
1535
+ isNested = false,
1536
+ pinLabel,
1537
+ unpinLabel,
1538
+ pinAriaLabel,
1539
+ unpinAriaLabel,
1540
+ betaLabel
1502
1541
  }) => {
1503
- const { LinkComponent } = useSidebar();
1542
+ const { LinkComponent, labels } = useSidebar();
1504
1543
  const { theme } = useResolvedTheme7();
1505
1544
  const sizing = theme.sizing.sidebar();
1506
1545
  const shouldTruncate = Boolean(hasTooltip) && typeof label === "string" && label.length > TOOLTIP_TRUNCATE_LENGTH;
1507
1546
  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;
1547
+ const pinTooltip = isPinned ? unpinLabel ?? labels.unpin : pinLabel ?? labels.pin;
1548
+ const pinAria = isPinned ? unpinAriaLabel ?? labels.unpinItem : pinAriaLabel ?? labels.pinItem;
1508
1549
  return /* @__PURE__ */ jsx11(
1509
1550
  ItemWrapper,
1510
1551
  {
@@ -1556,40 +1597,32 @@ var SidebarMenuItem = ({
1556
1597
  }
1557
1598
  )
1558
1599
  ] }),
1559
- onPinToggle && /* @__PURE__ */ jsx11(
1560
- Tooltip,
1600
+ onPinToggle && /* @__PURE__ */ jsx11(Tooltip, { content: pinTooltip, placement: "top", size: "sm", children: /* @__PURE__ */ jsx11(
1601
+ PinButton,
1561
1602
  {
1562
- content: isPinned ? "Unpin" : "Pin",
1563
- placement: "top",
1564
- size: "sm",
1565
- children: /* @__PURE__ */ jsx11(
1566
- PinButton,
1567
- {
1568
- type: "button",
1569
- "aria-label": isPinned ? "Unpin item" : "Pin item",
1570
- "aria-pressed": Boolean(isPinned),
1571
- $size: sizing.iconSize,
1572
- $color: theme.colors.content.tertiary,
1573
- $hoverColor: theme.colors.content.primary,
1574
- $activeColor: theme.colors.content.primary,
1575
- $isPinned: Boolean(isPinned),
1576
- onClick: (e) => {
1577
- e.preventDefault();
1578
- e.stopPropagation();
1579
- onPinToggle(e);
1580
- },
1581
- children: isPinned ? /* @__PURE__ */ jsx11(Remove, { size: 12, variant: "line" }) : /* @__PURE__ */ jsx11(Pin, { size: 12, variant: "solid" })
1582
- }
1583
- )
1603
+ type: "button",
1604
+ "aria-label": pinAria,
1605
+ "aria-pressed": Boolean(isPinned),
1606
+ $size: sizing.iconSize,
1607
+ $color: theme.colors.content.tertiary,
1608
+ $hoverColor: theme.colors.content.primary,
1609
+ $activeColor: theme.colors.content.primary,
1610
+ $isPinned: Boolean(isPinned),
1611
+ onClick: (e) => {
1612
+ e.preventDefault();
1613
+ e.stopPropagation();
1614
+ onPinToggle(e);
1615
+ },
1616
+ children: isPinned ? /* @__PURE__ */ jsx11(Remove, { size: 12, variant: "line" }) : /* @__PURE__ */ jsx11(Pin, { size: 12, variant: "solid" })
1584
1617
  }
1585
- ),
1618
+ ) }),
1586
1619
  beta && /* @__PURE__ */ jsx11(
1587
1620
  BetaTag,
1588
1621
  {
1589
1622
  $bg: theme.colors.overlay.mono,
1590
1623
  $color: theme.colors.content.tertiary,
1591
1624
  $radius: sizing.radius,
1592
- children: "Beta"
1625
+ children: betaLabel ?? labels.beta
1593
1626
  }
1594
1627
  ),
1595
1628
  external && hasExternalIcon && /* @__PURE__ */ jsx11(
@@ -1865,9 +1898,11 @@ var Badge = styled7.span`
1865
1898
  `;
1866
1899
  var SidebarChatButton = ({
1867
1900
  onClick,
1868
- badge
1901
+ badge,
1902
+ label
1869
1903
  }) => {
1870
1904
  const { theme } = useResolvedTheme9();
1905
+ const { labels } = useSidebar();
1871
1906
  const sizing = theme.sizing.sidebar();
1872
1907
  return /* @__PURE__ */ jsxs7(
1873
1908
  ChatButton,
@@ -1884,7 +1919,7 @@ var SidebarChatButton = ({
1884
1919
  $focusOutlineWidth: sizing.focusOutlineWidth,
1885
1920
  children: [
1886
1921
  /* @__PURE__ */ jsx14(ChatTwoMessages2, { size: 16, variant: "line" }),
1887
- /* @__PURE__ */ jsx14(Typography5, { variant: "bodySmAccent", color: "inherit", children: "Chat" }),
1922
+ /* @__PURE__ */ jsx14(Typography5, { variant: "bodySmAccent", color: "inherit", children: label ?? labels.chat }),
1888
1923
  badge && /* @__PURE__ */ jsx14(
1889
1924
  Badge,
1890
1925
  {
@@ -1972,7 +2007,7 @@ var SidebarPinnedList = ({
1972
2007
  var getPinnedCollapsedItem = (items, options = {}) => {
1973
2008
  if (items.length === 0) return null;
1974
2009
  return {
1975
- label: options.label ?? "Pinned",
2010
+ label: options.label ?? DEFAULT_SIDEBAR_LABELS.pinned,
1976
2011
  icon: /* @__PURE__ */ jsx15(Pin2, { size: 18, variant: "solid" }),
1977
2012
  dataId: options.dataId ?? "sidebar-collapsed-pinned",
1978
2013
  children: items.map((i) => ({
@@ -1983,6 +2018,7 @@ var getPinnedCollapsedItem = (items, options = {}) => {
1983
2018
  };
1984
2019
  };
1985
2020
  export {
2021
+ DEFAULT_SIDEBAR_LABELS,
1986
2022
  Sidebar,
1987
2023
  SidebarChatButton,
1988
2024
  SidebarCollapsed,
@@ -1997,6 +2033,7 @@ export {
1997
2033
  SidebarProvider,
1998
2034
  SidebarTrigger,
1999
2035
  getPinnedCollapsedItem,
2036
+ resolveSidebarLabels,
2000
2037
  useSidebar
2001
2038
  };
2002
2039
  //# sourceMappingURL=index.mjs.map