@nrbx/topbar-components 1.1.5 → 1.1.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.
@@ -19,6 +19,8 @@ export interface IconProps extends React.PropsWithChildren {
19
19
  textColor?: StateDependent<Color3>;
20
20
  /** Transparency of the icon image. Animated on state change. */
21
21
  imageTransparency?: StateDependent<number>;
22
+ /** Transparency of the label text. Animated on state change. */
23
+ textTransparency?: StateDependent<number>;
22
24
  /** Layout order used for horizontal sorting in docks. */
23
25
  layoutOrder?: StateDependent<number>;
24
26
  /** Text displayed next to or instead of the image. */
@@ -33,7 +33,7 @@ local Notification = TS.import(script, script.Parent, "notification").Notificati
33
33
  * both states, or `{ deselected: T; selected: T }` to animate between them.
34
34
 
35
35
  ]]
36
- local ANIMATEABLE = { "backgroundColor", "backgroundTransparency", "imageColor", "imageTransparency" }
36
+ local ANIMATEABLE = { "backgroundColor", "backgroundTransparency", "imageColor", "imageTransparency", "textTransparency" }
37
37
  --* Icon select/deselect state.
38
38
  --[[
39
39
  *
@@ -199,21 +199,22 @@ local function Icon(componentProps)
199
199
  end
200
200
  local imageToTextGap = _condition_3
201
201
  local imageSize = iconHeight - contentPadY * 2 + imageSizeOff
202
- local minLabelWidth = if location.type == "dropdown" then location.desiredIconWidth - sizing.minLabelWidthPadding else inset.Height - sizing.iconHorizontalPadding * 2
203
- local accumulatedLabelWidth = if currentImage ~= "" and currentImage then textBounds.X else math.max(textBounds.X, minLabelWidth)
204
- local contentWidth = if currentImage ~= "" and currentImage then imageSize + imageToTextGap + textBounds.X else textBounds.X
202
+ local _exp = (if currentImage ~= "" and currentImage then imageSize else 0)
203
+ local _condition_4 = currentImage
204
+ if _condition_4 ~= "" and _condition_4 then
205
+ _condition_4 = currentText
206
+ end
207
+ local contentWidth = _exp + (if _condition_4 ~= "" and _condition_4 then imageToTextGap else 0) + (if currentText ~= "" and currentText then textBounds.X else 0)
205
208
  local autoWidth = contentWidth + contentPadX * 2
206
- local _condition_4 = props.iconWidth
207
- if not (_condition_4 ~= 0 and _condition_4 == _condition_4 and _condition_4) then
208
- _condition_4 = sizing.iconWidth
209
- if not (_condition_4 ~= 0 and _condition_4 == _condition_4 and _condition_4) then
210
- _condition_4 = math.max(iconHeight, autoWidth)
209
+ local _condition_5 = props.iconWidth
210
+ if not (_condition_5 ~= 0 and _condition_5 == _condition_5 and _condition_5) then
211
+ _condition_5 = sizing.iconWidth
212
+ if not (_condition_5 ~= 0 and _condition_5 == _condition_5 and _condition_5) then
213
+ _condition_5 = math.max(iconHeight, autoWidth)
211
214
  end
212
215
  end
213
- local iconWidth = _condition_4
216
+ local iconWidth = _condition_5
214
217
  local iconSize = Vector2.new(iconWidth, iconHeight)
215
- local imagePosY = (iconHeight - imageSize) / 2 + imageSizeOff * -0.5
216
- local textLabelPos = UDim2.new(0, if currentImage ~= "" and currentImage then contentPadX + imageSize + imageToTextGap else contentPadX, 0.5, 0)
217
218
  useEffect(function()
218
219
  if props.static then
219
220
  return nil
@@ -260,6 +261,9 @@ local function Icon(componentProps)
260
261
  Active = not props.static,
261
262
  Selectable = not props.static,
262
263
  AutoButtonColor = not props.static,
264
+ Text = "",
265
+ BackgroundTransparency = animatedProps.backgroundTransparency,
266
+ BackgroundColor3 = animatedProps.backgroundColor,
263
267
  Event = {
264
268
  MouseButton1Click = function()
265
269
  if props.static then
@@ -304,16 +308,26 @@ local function Icon(componentProps)
304
308
  props.unhover()
305
309
  end,
306
310
  },
307
- Text = "",
308
- BackgroundTransparency = stateful(props.backgroundTransparency, currentState),
309
- BackgroundColor3 = stateful(props.backgroundColor, currentState),
310
- }, children, currentImage ~= nil and currentImage ~= "" and (React.createElement("imagelabel", {
311
+ }, React.createElement("uipadding", {
312
+ PaddingLeft = UDim.new(0, contentPadX),
313
+ PaddingRight = UDim.new(0, contentPadX),
314
+ PaddingTop = UDim.new(0, contentPadY),
315
+ PaddingBottom = UDim.new(0, contentPadY),
316
+ }), React.createElement("frame", {
317
+ Size = UDim2.fromScale(1, 1),
318
+ BackgroundTransparency = 1,
319
+ }, React.createElement("uilistlayout", {
320
+ FillDirection = Enum.FillDirection.Horizontal,
321
+ VerticalAlignment = Enum.VerticalAlignment.Center,
322
+ HorizontalAlignment = Enum.HorizontalAlignment.Center,
323
+ Padding = UDim.new(0, imageToTextGap),
324
+ SortOrder = Enum.SortOrder.LayoutOrder,
325
+ }), currentImage ~= nil and currentImage ~= "" and (React.createElement("imagelabel", {
311
326
  Size = UDim2.fromOffset(imageSize, imageSize),
312
- Position = UDim2.fromOffset(contentPadX, imagePosY),
313
327
  Image = currentImage,
314
328
  BackgroundTransparency = 1,
315
- ImageColor3 = stateful(props.imageColor, currentState),
316
- ImageTransparency = stateful(props.imageTransparency, currentState),
329
+ ImageColor3 = animatedProps.imageColor,
330
+ ImageTransparency = animatedProps.imageTransparency,
317
331
  ImageRectOffset = stateful(props.imageRectOffset, currentState),
318
332
  ImageRectSize = stateful(props.imageRectSize, currentState),
319
333
  })), currentText ~= nil and currentText ~= "" and (React.createElement("textlabel", {
@@ -321,18 +335,18 @@ local function Icon(componentProps)
321
335
  TextSize = stateful(props.textSize, currentState),
322
336
  TextColor3 = stateful(props.textColor, currentState),
323
337
  TextWrapped = false,
324
- AnchorPoint = Vector2.new(0, 0.5),
325
- Size = UDim2.new(0, accumulatedLabelWidth, sizing.buttonLabelHeightFraction, 0),
326
- Position = textLabelPos,
338
+ Size = UDim2.fromOffset(textBounds.X, 0),
339
+ AutomaticSize = Enum.AutomaticSize.Y,
327
340
  TextXAlignment = stateful(props.textAlignment, currentState),
328
341
  RichText = stateful(props.richText, currentState),
329
342
  BackgroundTransparency = 1,
343
+ TextTransparency = animatedProps.textTransparency,
330
344
  Text = currentText,
331
345
  }, React.createElement("uistroke", {
332
346
  Thickness = stateful(props.strokeThickness, currentState),
333
347
  Color = stateful(props.strokeColor, currentState),
334
348
  Transparency = stateful(props.strokeTransparency, currentState),
335
- }))), React.createElement("uicorner", {
349
+ })))), children, React.createElement("uicorner", {
336
350
  CornerRadius = if location.type == "dropdown" then stylesheet.dropdown.iconCornerRadius else stateful(props.cornerRadius, currentState),
337
351
  }), props.disabled and (React.createElement("frame", {
338
352
  Size = UDim2.fromScale(1, 1),
@@ -10,6 +10,7 @@ local springs = TS.import(script, script.Parent.Parent, "utilities", "springs").
10
10
  local function useAnimateableProps(state, props, ...)
11
11
  local keys = { ... }
12
12
  local previousProps = usePrevious(props)
13
+ local previousState = usePrevious(state)
13
14
  local motionBindings = {}
14
15
  local motionControls = {}
15
16
  for _, key in keys do
@@ -21,13 +22,13 @@ local function useAnimateableProps(state, props, ...)
21
22
  for i = 0, #keys - 1 do
22
23
  local key = keys[i + 1]
23
24
  local value = stateful(props[key], state)
24
- local previousValue = if previousProps then stateful(previousProps[key], state) else nil
25
+ local previousValue = if previousProps and previousState ~= nil then stateful(previousProps[key], previousState) else nil
25
26
  if value == previousValue then
26
27
  continue
27
28
  end
28
29
  motionControls[i + 1]:spring(value, springs.responsive)
29
30
  end
30
- end, { props })
31
+ end, { props, state })
31
32
  -- ▼ ReadonlyArray.map ▼
32
33
  local _newValue = table.create(#keys)
33
34
  local _callback = function(key, i)
@@ -1,15 +1,18 @@
1
1
  -- Compiled with roblox-ts v3.0.0
2
2
  local TS = _G[script]
3
- local useAsyncEffect = TS.import(script, TS.getModule(script, "@rbxts", "pretty-react-hooks").out).useAsyncEffect
4
- local useState = TS.import(script, TS.getModule(script, "@rbxts", "react")).useState
3
+ local _react = TS.import(script, TS.getModule(script, "@rbxts", "react"))
4
+ local useEffect = _react.useEffect
5
+ local useState = _react.useState
5
6
  local _services = TS.import(script, TS.getModule(script, "@rbxts", "services"))
6
7
  local Players = _services.Players
7
8
  local VoiceChatService = _services.VoiceChatService
8
9
  local function useVoicechatEnabled()
9
10
  local enabled, setEnabled = useState(false)
10
- useAsyncEffect(TS.async(function()
11
- setEnabled(VoiceChatService:IsVoiceEnabledForUserIdAsync(Players.LocalPlayer))
12
- end), {})
11
+ useEffect(function()
12
+ TS.Promise.try(function()
13
+ return VoiceChatService:IsVoiceEnabledForUserIdAsync(Players.LocalPlayer)
14
+ end):andThen(setEnabled)
15
+ end, {})
13
16
  return enabled
14
17
  end
15
18
  return {
package/out/style.luau CHANGED
@@ -44,6 +44,7 @@ local DefaultStylesheet = {
44
44
  playSound = defaultPlaySound,
45
45
  imageId = "",
46
46
  imageTransparency = 0,
47
+ textTransparency = 0,
47
48
  layoutOrder = 0,
48
49
  text = "",
49
50
  defaultState = "deselected",
@@ -54,8 +55,8 @@ local DefaultStylesheet = {
54
55
  toggleKey = Enum.KeyCode.Unknown,
55
56
  notificationCount = 0,
56
57
  iconWidth = 0,
57
- contentPaddingX = 6,
58
- contentPaddingY = 6,
58
+ contentPaddingX = 10,
59
+ contentPaddingY = 2,
59
60
  imageToTextSpacing = 6,
60
61
  selected = noop,
61
62
  deselected = noop,
@@ -105,8 +106,8 @@ local DefaultStylesheet = {
105
106
  imageToTextSpacing = 6,
106
107
  iconHorizontalPadding = 6,
107
108
  iconVerticalPadding = 6,
108
- contentPaddingX = 6,
109
- contentPaddingY = 6,
109
+ contentPaddingX = 10,
110
+ contentPaddingY = 2,
110
111
  textMeasurementWidth = 99999,
111
112
  minLabelWidthPadding = 12,
112
113
  buttonLabelHeightFraction = 0.8,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nrbx/topbar-components",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "main": "out/init.luau",
5
5
  "scripts": {
6
6
  "build": "rbxtsc",