@nrbx/topbar-components 1.0.6 → 1.0.7

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.
@@ -1,5 +1,4 @@
1
1
  import React from '@rbxts/react';
2
- export type Dock = 'Left' | 'Center' | 'Right';
3
2
  export interface IconProps extends React.PropsWithChildren {
4
3
  backgroundTransparency?: StateDependent<number>;
5
4
  backgroundColor?: StateDependent<Color3>;
@@ -25,7 +24,6 @@ export interface IconProps extends React.PropsWithChildren {
25
24
  textAlignment?: StateDependent<Enum.TextXAlignment>;
26
25
  richText?: StateDependent<boolean>;
27
26
  toggleStateOnClick?: boolean;
28
- dock?: Dock;
29
27
  /** When true, renders as a non-interactive label (no clicks, no hovers, no state changes) */
30
28
  static?: boolean;
31
29
  /** When true, dulls the text and icon with a dimming overlay */
@@ -1,10 +1,8 @@
1
1
  import React from '@rbxts/react';
2
- import type { Dock } from './icon';
3
2
  export type SelectionMode = 'Single' | 'Multiple';
4
- interface ContainerProps extends React.PropsWithChildren {
5
- dock: Dock;
6
- }
7
- export declare function TopBarContainer({ dock, children }: ContainerProps): React.JSX.Element;
3
+ export declare function LeftDock({ children }: React.PropsWithChildren): React.JSX.Element;
4
+ export declare function CenterDock({ children }: React.PropsWithChildren): React.JSX.Element;
5
+ export declare function RightDock({ children }: React.PropsWithChildren): React.JSX.Element;
8
6
  interface ProviderProps extends React.PropsWithChildren {
9
7
  selectionMode?: SelectionMode;
10
8
  gameVoiceChatEnabled?: boolean;
@@ -2,10 +2,6 @@
2
2
  local TS = _G[script]
3
3
  local _react = TS.import(script, TS.getModule(script, "@rbxts", "react"))
4
4
  local React = _react
5
- local createContext = _react.createContext
6
- local useContext = _react.useContext
7
- local useEffect = _react.useEffect
8
- local useMemo = _react.useMemo
9
5
  local useState = _react.useState
10
6
  local _context = TS.import(script, script.Parent.Parent, "context")
11
7
  local LocationContext = _context.LocationContext
@@ -13,136 +9,55 @@ local useStylesheet = _context.useStylesheet
13
9
  local useGuiInset = TS.import(script, script.Parent.Parent, "hooks", "use-gui-inset").useGuiInset
14
10
  local useVoicechatEnabled = TS.import(script, script.Parent.Parent, "hooks", "use-voicechat-enabled").useVoicechatEnabled
15
11
  local debugLog = TS.import(script, script.Parent.Parent, "utilities", "debug").debugLog
16
- -- ── Dock registry containers register their children by dock ──────────────
17
- local DockRegistryContext = createContext(nil)
18
- local function useDockRegistry()
19
- return useContext(DockRegistryContext)
12
+ -- ── Dock container components ───────────────────────────────────────────────
13
+ local function DockFrame(props)
14
+ local stylesheet = useStylesheet().provider
15
+ return React.createElement("frame", {
16
+ BackgroundTransparency = 1,
17
+ AnchorPoint = props.anchor,
18
+ Position = props.position,
19
+ Size = UDim2.fromScale(0, 1),
20
+ AutomaticSize = Enum.AutomaticSize.X,
21
+ }, (props.paddingLeft ~= nil or props.paddingRight ~= nil) and (React.createElement("uipadding", {
22
+ PaddingLeft = props.paddingLeft or UDim.new(0, 0),
23
+ PaddingRight = props.paddingRight or UDim.new(0, 0),
24
+ })), React.createElement("uilistlayout", {
25
+ FillDirection = Enum.FillDirection.Horizontal,
26
+ SortOrder = Enum.SortOrder.LayoutOrder,
27
+ Padding = UDim.new(0, stylesheet.iconSpacing),
28
+ VerticalAlignment = Enum.VerticalAlignment.Center,
29
+ }), props.children)
20
30
  end
21
- -- ── TopBarContainer ─────────────────────────────────────────────────────────
22
- local function TopBarContainer(_param)
23
- local dock = _param.dock
31
+ local function LeftDock(_param)
24
32
  local children = _param.children
25
- local registry = useDockRegistry()
26
- local id = useMemo(function()
27
- return math.random()
28
- end, {})
29
- useEffect(function()
30
- registry:register(dock, id, children)
31
- return function()
32
- return registry:unregister(dock, id)
33
- end
34
- end, {})
35
- return React.createElement(React.Fragment)
33
+ return React.createElement(DockFrame, {
34
+ anchor = Vector2.new(0, 0.5),
35
+ position = UDim2.new(0, 0, 0.5, 0),
36
+ children = children,
37
+ })
36
38
  end
37
- -- ── Provider ────────────────────────────────────────────────────────────────
38
- local function useDockNodes()
39
- local leftNodes, setLeftNodes = useState({})
40
- local centerNodes, setCenterNodes = useState({})
41
- local rightNodes, setRightNodes = useState({})
42
- local registry = useMemo(function()
43
- return {
44
- register = function(dock, id, element)
45
- local entry = {
46
- id = id,
47
- element = element,
48
- }
49
- debugLog(`DockRegistry: register id={id} dock="{dock}"`)
50
- if dock == "Center" then
51
- setCenterNodes(function(prev)
52
- local _array = {}
53
- local _length = #_array
54
- local _prevLength = #prev
55
- table.move(prev, 1, _prevLength, _length + 1, _array)
56
- _length += _prevLength
57
- _array[_length + 1] = entry
58
- return _array
59
- end)
60
- elseif dock == "Right" then
61
- setRightNodes(function(prev)
62
- local _array = {}
63
- local _length = #_array
64
- local _prevLength = #prev
65
- table.move(prev, 1, _prevLength, _length + 1, _array)
66
- _length += _prevLength
67
- _array[_length + 1] = entry
68
- return _array
69
- end)
70
- else
71
- setLeftNodes(function(prev)
72
- local _array = {}
73
- local _length = #_array
74
- local _prevLength = #prev
75
- table.move(prev, 1, _prevLength, _length + 1, _array)
76
- _length += _prevLength
77
- _array[_length + 1] = entry
78
- return _array
79
- end)
80
- end
81
- end,
82
- unregister = function(dock, id)
83
- debugLog(`DockRegistry: unregister id={id} dock="{dock}"`)
84
- if dock == "Center" then
85
- setCenterNodes(function(prev)
86
- -- ▼ ReadonlyArray.filter ▼
87
- local _newValue = {}
88
- local _callback = function(e)
89
- return e.id ~= id
90
- end
91
- local _length = 0
92
- for _k, _v in prev do
93
- if _callback(_v, _k - 1, prev) == true then
94
- _length += 1
95
- _newValue[_length] = _v
96
- end
97
- end
98
- -- ▲ ReadonlyArray.filter ▲
99
- return _newValue
100
- end)
101
- elseif dock == "Right" then
102
- setRightNodes(function(prev)
103
- -- ▼ ReadonlyArray.filter ▼
104
- local _newValue = {}
105
- local _callback = function(e)
106
- return e.id ~= id
107
- end
108
- local _length = 0
109
- for _k, _v in prev do
110
- if _callback(_v, _k - 1, prev) == true then
111
- _length += 1
112
- _newValue[_length] = _v
113
- end
114
- end
115
- -- ▲ ReadonlyArray.filter ▲
116
- return _newValue
117
- end)
118
- else
119
- setLeftNodes(function(prev)
120
- -- ▼ ReadonlyArray.filter ▼
121
- local _newValue = {}
122
- local _callback = function(e)
123
- return e.id ~= id
124
- end
125
- local _length = 0
126
- for _k, _v in prev do
127
- if _callback(_v, _k - 1, prev) == true then
128
- _length += 1
129
- _newValue[_length] = _v
130
- end
131
- end
132
- -- ▲ ReadonlyArray.filter ▲
133
- return _newValue
134
- end)
135
- end
136
- end,
137
- }
138
- end, {})
139
- return {
140
- registry = registry,
141
- leftNodes = leftNodes,
142
- centerNodes = centerNodes,
143
- rightNodes = rightNodes,
144
- }
39
+ local function CenterDock(_param)
40
+ local children = _param.children
41
+ local stylesheet = useStylesheet().provider
42
+ return React.createElement(DockFrame, {
43
+ anchor = Vector2.new(0.5, 0.5),
44
+ position = UDim2.new(0.5, 0, 0.5, 0),
45
+ paddingLeft = UDim.new(0, stylesheet.iconGroupSpacing),
46
+ paddingRight = UDim.new(0, stylesheet.iconGroupSpacing),
47
+ children = children,
48
+ })
145
49
  end
50
+ local function RightDock(_param)
51
+ local children = _param.children
52
+ local stylesheet = useStylesheet().provider
53
+ return React.createElement(DockFrame, {
54
+ anchor = Vector2.new(1, 0.5),
55
+ position = UDim2.new(1, 0, 0.5, 0),
56
+ paddingLeft = UDim.new(0, stylesheet.iconGroupSpacing),
57
+ children = children,
58
+ })
59
+ end
60
+ -- ── Provider ────────────────────────────────────────────────────────────────
146
61
  local function TopbarProvider(_param)
147
62
  local selectionMode = _param.selectionMode
148
63
  if selectionMode == nil then
@@ -154,117 +69,12 @@ local function TopbarProvider(_param)
154
69
  local inset = useGuiInset()
155
70
  local voiceChatEnabled = useVoicechatEnabled()
156
71
  local stylesheet = useStylesheet().provider
157
- local _binding = useDockNodes()
158
- local registry = _binding.registry
159
- local leftNodes = _binding.leftNodes
160
- local centerNodes = _binding.centerNodes
161
- local rightNodes = _binding.rightNodes
162
72
  local hasBetaLabel = gameVoiceChatEnabled and voiceChatEnabled
163
73
  local leftPadding = if hasBetaLabel then stylesheet.paddingLeft + 16 else stylesheet.paddingLeft
164
74
  local rawHeight = inset.Height - stylesheet.insetHeightOffset
165
75
  local frameHeight = if stylesheet.forceFrameHeight ~= nil then stylesheet.forceFrameHeight else rawHeight
166
76
  debugLog(`TopbarProvider frame: inset.Height={inset.Height}, inset.Width={inset.Width}`, `insetHeightOffset={stylesheet.insetHeightOffset}`, `rawHeight={rawHeight}`, `forceFrameHeight={stylesheet.forceFrameHeight}`, `finalHeight={frameHeight}`, `sizeScale=({stylesheet.sizeScale.X}, {stylesheet.sizeScale.Y})`)
167
- local hasCenter = #centerNodes > 0
168
- local hasRight = #rightNodes > 0
169
- local _exp = React.createElement("uipadding", {
170
- key = "UIPadding",
171
- PaddingLeft = UDim.new(0, leftPadding),
172
- PaddingRight = UDim.new(0, stylesheet.paddingRight),
173
- PaddingTop = UDim.new(0, stylesheet.paddingTop),
174
- PaddingBottom = UDim.new(0, stylesheet.paddingBottom),
175
- })
176
- local _exp_1 = React.createElement("uilistlayout", {
177
- FillDirection = Enum.FillDirection.Horizontal,
178
- SortOrder = Enum.SortOrder.LayoutOrder,
179
- Padding = UDim.new(0, stylesheet.iconSpacing),
180
- VerticalAlignment = Enum.VerticalAlignment.Center,
181
- })
182
- local _exp_2 = children
183
- -- ▼ ReadonlyArray.map ▼
184
- local _newValue = table.create(#leftNodes)
185
- local _callback = function(entry)
186
- return React.createElement(React.Fragment, {
187
- key = entry.id,
188
- }, entry.element)
189
- end
190
- for _k, _v in leftNodes do
191
- _newValue[_k] = _callback(_v, _k - 1, leftNodes)
192
- end
193
- -- ▲ ReadonlyArray.map ▲
194
- local _exp_3 = React.createElement("frame", {
195
- key = "LeftDock",
196
- BackgroundTransparency = 1,
197
- AnchorPoint = Vector2.new(0, 0.5),
198
- Position = UDim2.new(0, 0, 0.5, 0),
199
- Size = UDim2.fromScale(0, 1),
200
- AutomaticSize = Enum.AutomaticSize.X,
201
- }, _exp_1, _exp_2, _newValue)
202
- local _condition = hasCenter
203
- if _condition then
204
- local _exp_4 = React.createElement("uipadding", {
205
- PaddingLeft = UDim.new(0, stylesheet.iconGroupSpacing),
206
- PaddingRight = UDim.new(0, stylesheet.iconGroupSpacing),
207
- })
208
- local _exp_5 = React.createElement("uilistlayout", {
209
- FillDirection = Enum.FillDirection.Horizontal,
210
- SortOrder = Enum.SortOrder.LayoutOrder,
211
- Padding = UDim.new(0, stylesheet.iconSpacing),
212
- VerticalAlignment = Enum.VerticalAlignment.Center,
213
- })
214
- -- ▼ ReadonlyArray.map ▼
215
- local _newValue_1 = table.create(#centerNodes)
216
- local _callback_1 = function(entry)
217
- return React.createElement(React.Fragment, {
218
- key = entry.id,
219
- }, entry.element)
220
- end
221
- for _k, _v in centerNodes do
222
- _newValue_1[_k] = _callback_1(_v, _k - 1, centerNodes)
223
- end
224
- -- ▲ ReadonlyArray.map ▲
225
- _condition = (React.createElement("frame", {
226
- key = "CenterDock",
227
- BackgroundTransparency = 1,
228
- AnchorPoint = Vector2.new(0.5, 0.5),
229
- Position = UDim2.new(0.5, 0, 0.5, 0),
230
- Size = UDim2.fromScale(0, 1),
231
- AutomaticSize = Enum.AutomaticSize.X,
232
- }, _exp_4, _exp_5, _newValue_1))
233
- end
234
- local _condition_1 = hasRight
235
- if _condition_1 then
236
- local _exp_4 = React.createElement("uipadding", {
237
- PaddingLeft = UDim.new(0, stylesheet.iconGroupSpacing),
238
- })
239
- local _exp_5 = React.createElement("uilistlayout", {
240
- FillDirection = Enum.FillDirection.Horizontal,
241
- SortOrder = Enum.SortOrder.LayoutOrder,
242
- Padding = UDim.new(0, stylesheet.iconSpacing),
243
- VerticalAlignment = Enum.VerticalAlignment.Center,
244
- })
245
- -- ▼ ReadonlyArray.map ▼
246
- local _newValue_1 = table.create(#rightNodes)
247
- local _callback_1 = function(entry)
248
- return React.createElement(React.Fragment, {
249
- key = entry.id,
250
- }, entry.element)
251
- end
252
- for _k, _v in rightNodes do
253
- _newValue_1[_k] = _callback_1(_v, _k - 1, rightNodes)
254
- end
255
- -- ▲ ReadonlyArray.map ▲
256
- _condition_1 = (React.createElement("frame", {
257
- key = "RightDock",
258
- BackgroundTransparency = 1,
259
- AnchorPoint = Vector2.new(1, 0.5),
260
- Position = UDim2.new(1, 0, 0.5, 0),
261
- Size = UDim2.fromScale(0, 1),
262
- AutomaticSize = Enum.AutomaticSize.X,
263
- }, _exp_4, _exp_5, _newValue_1))
264
- end
265
- return React.createElement(DockRegistryContext.Provider, {
266
- value = registry,
267
- }, React.createElement(LocationContext.Provider, {
77
+ return React.createElement(LocationContext.Provider, {
268
78
  value = {
269
79
  type = "provider",
270
80
  selectedIcons = selectedIcons,
@@ -283,29 +93,29 @@ local function TopbarProvider(_param)
283
93
  end)
284
94
  end,
285
95
  iconDeselected = function(iconId)
286
- local _condition_2 = selectionMode == "Single"
287
- if _condition_2 then
96
+ local _condition = selectionMode == "Single"
97
+ if _condition then
288
98
  local _iconId = iconId
289
- _condition_2 = table.find(selectedIcons, _iconId) ~= nil
99
+ _condition = table.find(selectedIcons, _iconId) ~= nil
290
100
  end
291
- if _condition_2 then
101
+ if _condition then
292
102
  return setSelectedIcons({})
293
103
  end
294
104
  return setSelectedIcons(function(icons)
295
105
  -- ▼ ReadonlyArray.filter ▼
296
- local _newValue_1 = {}
297
- local _callback_1 = function(T)
106
+ local _newValue = {}
107
+ local _callback = function(T)
298
108
  return T ~= iconId
299
109
  end
300
110
  local _length = 0
301
111
  for _k, _v in icons do
302
- if _callback_1(_v, _k - 1, icons) == true then
112
+ if _callback(_v, _k - 1, icons) == true then
303
113
  _length += 1
304
- _newValue_1[_length] = _v
114
+ _newValue[_length] = _v
305
115
  end
306
116
  end
307
117
  -- ▲ ReadonlyArray.filter ▲
308
- return _newValue_1
118
+ return _newValue
309
119
  end)
310
120
  end,
311
121
  },
@@ -316,9 +126,17 @@ local function TopbarProvider(_param)
316
126
  Size = UDim2.fromOffset(inset.Width * stylesheet.sizeScale.X, frameHeight * stylesheet.sizeScale.Y),
317
127
  AnchorPoint = stylesheet.anchorPoint,
318
128
  Position = stylesheet.position,
319
- }, _exp, _exp_3, _condition, _condition_1)))
129
+ }, React.createElement("uipadding", {
130
+ key = "UIPadding",
131
+ PaddingLeft = UDim.new(0, leftPadding),
132
+ PaddingRight = UDim.new(0, stylesheet.paddingRight),
133
+ PaddingTop = UDim.new(0, stylesheet.paddingTop),
134
+ PaddingBottom = UDim.new(0, stylesheet.paddingBottom),
135
+ }), children))
320
136
  end
321
137
  return {
322
- TopBarContainer = TopBarContainer,
138
+ LeftDock = LeftDock,
139
+ CenterDock = CenterDock,
140
+ RightDock = RightDock,
323
141
  TopbarProvider = TopbarProvider,
324
142
  }
package/out/style.luau CHANGED
@@ -48,7 +48,6 @@ local DefaultStylesheet = {
48
48
  defaultState = "deselected",
49
49
  forcedState = "deselected",
50
50
  toggleStateOnClick = true,
51
- dock = "Left",
52
51
  static = false,
53
52
  disabled = false,
54
53
  selected = noop,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nrbx/topbar-components",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "main": "out/init.lua",
5
5
  "scripts": {
6
6
  "build": "rbxtsc",