@nrbx/topbar-components 1.0.9 → 1.0.11
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 +3 -0
- package/out/components/icon.luau +29 -21
- package/out/style.d.ts +5 -1
- package/out/style.luau +2 -0
- package/package.json +1 -1
package/out/components/icon.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from '@rbxts/react';
|
|
2
|
+
import { type Stylesheet } from '../style';
|
|
2
3
|
export interface IconProps extends React.PropsWithChildren {
|
|
3
4
|
backgroundTransparency?: StateDependent<number>;
|
|
4
5
|
backgroundColor?: StateDependent<Color3>;
|
|
@@ -28,6 +29,8 @@ export interface IconProps extends React.PropsWithChildren {
|
|
|
28
29
|
static?: boolean;
|
|
29
30
|
/** When true, dulls the text and icon with a dimming overlay */
|
|
30
31
|
disabled?: boolean;
|
|
32
|
+
/** Per-icon stylesheet overrides — merged above the global stylesheet but below explicit props */
|
|
33
|
+
style?: Partial<IconProps & Stylesheet['sizing']>;
|
|
31
34
|
selected?: () => void;
|
|
32
35
|
deselected?: () => void;
|
|
33
36
|
hover?: () => void;
|
package/out/components/icon.luau
CHANGED
|
@@ -27,7 +27,7 @@ local ANIMATEABLE = { "backgroundColor", "backgroundTransparency", "imageColor",
|
|
|
27
27
|
local function Icon(componentProps)
|
|
28
28
|
local _binding = componentProps
|
|
29
29
|
local children = _binding.children
|
|
30
|
-
local style =
|
|
30
|
+
local style = _binding.style
|
|
31
31
|
local inset = useGuiInset()
|
|
32
32
|
local location = useLocation()
|
|
33
33
|
local id = useId()
|
|
@@ -39,22 +39,30 @@ local function Icon(componentProps)
|
|
|
39
39
|
local stylesheet = useStylesheet()
|
|
40
40
|
local _arg0 = location.type ~= "icon"
|
|
41
41
|
assert(_arg0, "Icons cannot be nested")
|
|
42
|
-
local _object = table.clone(stylesheet.
|
|
42
|
+
local _object = table.clone(stylesheet.sizing)
|
|
43
43
|
setmetatable(_object, nil)
|
|
44
44
|
for _k, _v in (style or {}) do
|
|
45
45
|
_object[_k] = _v
|
|
46
46
|
end
|
|
47
|
+
local sizing = _object
|
|
48
|
+
local _object_1 = table.clone(stylesheet.icon)
|
|
49
|
+
setmetatable(_object_1, nil)
|
|
47
50
|
for _k, _v in componentProps do
|
|
48
|
-
|
|
51
|
+
_object_1[_k] = _v
|
|
52
|
+
end
|
|
53
|
+
local animatedProps = useAnimateableProps(currentState, _object_1, unpack(ANIMATEABLE))
|
|
54
|
+
local _object_2 = table.clone(stylesheet.icon)
|
|
55
|
+
setmetatable(_object_2, nil)
|
|
56
|
+
for _k, _v in (style or {}) do
|
|
57
|
+
_object_2[_k] = _v
|
|
58
|
+
end
|
|
59
|
+
for _k, _v in componentProps do
|
|
60
|
+
_object_2[_k] = _v
|
|
49
61
|
end
|
|
50
|
-
local merged = _object
|
|
51
|
-
local animatedProps = useAnimateableProps(currentState, merged, unpack(ANIMATEABLE))
|
|
52
|
-
local _object_1 = table.clone(merged)
|
|
53
|
-
setmetatable(_object_1, nil)
|
|
54
62
|
for _k, _v in animatedProps do
|
|
55
|
-
|
|
63
|
+
_object_2[_k] = _v
|
|
56
64
|
end
|
|
57
|
-
local props =
|
|
65
|
+
local props = _object_2
|
|
58
66
|
useMountEffect(function()
|
|
59
67
|
if props.static then
|
|
60
68
|
return nil
|
|
@@ -114,31 +122,31 @@ local function Icon(componentProps)
|
|
|
114
122
|
params.Text = currentText
|
|
115
123
|
params.Font = stateful(props.fontFace, currentState)
|
|
116
124
|
params.Size = stateful(props.textSize, currentState)
|
|
117
|
-
params.Width =
|
|
125
|
+
params.Width = sizing.textMeasurementWidth
|
|
118
126
|
setTextBounds(TextService:GetTextBoundsAsync(params))
|
|
119
127
|
previousQueryRef.current = currentQuery
|
|
120
128
|
end), { currentText, props.fontFace, props.textSize, currentState })
|
|
121
129
|
local imageSizeOff = stateful(props.imageSizeOffset, currentState)
|
|
122
130
|
local forceHeight = if location.type == "dropdown" then stylesheet.dropdown.forceHeight else nil
|
|
123
|
-
local _condition =
|
|
131
|
+
local _condition = sizing.iconHeight
|
|
124
132
|
if _condition == nil then
|
|
125
133
|
_condition = forceHeight
|
|
126
134
|
if _condition == nil then
|
|
127
|
-
_condition = inset.Height -
|
|
135
|
+
_condition = inset.Height - sizing.iconVerticalPadding * 2
|
|
128
136
|
end
|
|
129
137
|
end
|
|
130
138
|
local iconHeight = _condition
|
|
131
|
-
local imageSize = iconHeight -
|
|
132
|
-
local minLabelWidth = if location.type == "dropdown" then location.desiredIconWidth -
|
|
139
|
+
local imageSize = iconHeight - sizing.imagePadding * 2 + imageSizeOff
|
|
140
|
+
local minLabelWidth = if location.type == "dropdown" then location.desiredIconWidth - sizing.minLabelWidthPadding else inset.Height - sizing.iconHorizontalPadding * 2
|
|
133
141
|
local accumulatedLabelWidth = if currentImage ~= "" and currentImage then textBounds.X else math.max(textBounds.X, minLabelWidth)
|
|
134
|
-
local _exp = textBounds.X +
|
|
142
|
+
local _exp = textBounds.X + sizing.labelPadding * 2
|
|
135
143
|
local _condition_1 = currentImage
|
|
136
144
|
if _condition_1 ~= "" and _condition_1 then
|
|
137
145
|
_condition_1 = textBounds.X ~= 0
|
|
138
146
|
end
|
|
139
|
-
local iconSize = Vector2.new(math.max(iconHeight, _exp + (if _condition_1 ~= "" and _condition_1 then imageSize +
|
|
140
|
-
local imagePos =
|
|
141
|
-
local textLabelPos = UDim2.new(0, if currentImage ~= "" and currentImage then imageSize +
|
|
147
|
+
local iconSize = Vector2.new(math.max(iconHeight, _exp + (if _condition_1 ~= "" and _condition_1 then imageSize + sizing.imageToTextSpacing else 0)), iconHeight)
|
|
148
|
+
local imagePos = sizing.imagePadding + imageSizeOff * -0.5
|
|
149
|
+
local textLabelPos = UDim2.new(0, if currentImage ~= "" and currentImage then imageSize + sizing.imagePadding * 2 else sizing.labelPadding, 0.5, 0)
|
|
142
150
|
useEffect(function()
|
|
143
151
|
if props.static then
|
|
144
152
|
return nil
|
|
@@ -234,7 +242,7 @@ local function Icon(componentProps)
|
|
|
234
242
|
TextColor3 = stateful(props.textColor, currentState),
|
|
235
243
|
TextWrapped = false,
|
|
236
244
|
AnchorPoint = Vector2.new(0, 0.5),
|
|
237
|
-
Size = UDim2.new(0, accumulatedLabelWidth,
|
|
245
|
+
Size = UDim2.new(0, accumulatedLabelWidth, sizing.buttonLabelHeightFraction, 0),
|
|
238
246
|
Position = textLabelPos,
|
|
239
247
|
TextXAlignment = stateful(props.textAlignment, currentState),
|
|
240
248
|
RichText = stateful(props.richText, currentState),
|
|
@@ -252,8 +260,8 @@ local function Icon(componentProps)
|
|
|
252
260
|
}), props.disabled and (React.createElement("frame", {
|
|
253
261
|
key = "DisabledOverlay",
|
|
254
262
|
Size = UDim2.fromScale(1, 1),
|
|
255
|
-
BackgroundTransparency =
|
|
256
|
-
BackgroundColor3 =
|
|
263
|
+
BackgroundTransparency = sizing.disabledOverlayTransparency,
|
|
264
|
+
BackgroundColor3 = sizing.disabledOverlayColor,
|
|
257
265
|
BorderSizePixel = 0,
|
|
258
266
|
ZIndex = 10,
|
|
259
267
|
})))))
|
package/out/style.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { DropdownProps } from './components/dropdown';
|
|
|
3
3
|
import type { IconProps } from './components/icon';
|
|
4
4
|
export declare function noop(): void;
|
|
5
5
|
export interface Stylesheet {
|
|
6
|
-
icon: Required<IconProps
|
|
6
|
+
icon: Required<Omit<IconProps, 'style'>>;
|
|
7
7
|
dropdown: Required<DropdownProps>;
|
|
8
8
|
/**
|
|
9
9
|
* Configure the top-level provider frame: padding, spacing, background, sizing.
|
|
@@ -44,6 +44,10 @@ export interface Stylesheet {
|
|
|
44
44
|
labelPadding: number;
|
|
45
45
|
/** Gap between the image and the text label (default 6) */
|
|
46
46
|
imageToTextSpacing: number;
|
|
47
|
+
/** Horizontal padding within the icon button (default 6, used in icon size calculations) */
|
|
48
|
+
iconHorizontalPadding: number;
|
|
49
|
+
/** Vertical padding within the icon button (default 6, subtracted from inset height) */
|
|
50
|
+
iconVerticalPadding: number;
|
|
47
51
|
/** Max width passed to GetTextBoundsParams (default 99999) */
|
|
48
52
|
textMeasurementWidth: number;
|
|
49
53
|
/** Extra padding subtracted from the min label width inside a dropdown (default 12) */
|
package/out/style.luau
CHANGED