@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.
- package/out/components/icon.d.ts +0 -2
- package/out/components/provider.d.ts +3 -5
- package/out/components/provider.luau +65 -247
- package/out/style.luau +0 -1
- package/package.json +1 -1
package/out/components/icon.d.ts
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
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
|
|
17
|
-
local
|
|
18
|
-
local
|
|
19
|
-
return
|
|
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
|
-
|
|
22
|
-
local function TopBarContainer(_param)
|
|
23
|
-
local dock = _param.dock
|
|
31
|
+
local function LeftDock(_param)
|
|
24
32
|
local children = _param.children
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
38
|
-
local
|
|
39
|
-
local
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
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
|
|
287
|
-
if
|
|
96
|
+
local _condition = selectionMode == "Single"
|
|
97
|
+
if _condition then
|
|
288
98
|
local _iconId = iconId
|
|
289
|
-
|
|
99
|
+
_condition = table.find(selectedIcons, _iconId) ~= nil
|
|
290
100
|
end
|
|
291
|
-
if
|
|
101
|
+
if _condition then
|
|
292
102
|
return setSelectedIcons({})
|
|
293
103
|
end
|
|
294
104
|
return setSelectedIcons(function(icons)
|
|
295
105
|
-- ▼ ReadonlyArray.filter ▼
|
|
296
|
-
local
|
|
297
|
-
local
|
|
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
|
|
112
|
+
if _callback(_v, _k - 1, icons) == true then
|
|
303
113
|
_length += 1
|
|
304
|
-
|
|
114
|
+
_newValue[_length] = _v
|
|
305
115
|
end
|
|
306
116
|
end
|
|
307
117
|
-- ▲ ReadonlyArray.filter ▲
|
|
308
|
-
return
|
|
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
|
-
},
|
|
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
|
-
|
|
138
|
+
LeftDock = LeftDock,
|
|
139
|
+
CenterDock = CenterDock,
|
|
140
|
+
RightDock = RightDock,
|
|
323
141
|
TopbarProvider = TopbarProvider,
|
|
324
142
|
}
|
package/out/style.luau
CHANGED