@@ -6,24 +6,31 @@ local Constants = require("../../Constants")
66local getTextSize = require ("../../getTextSize" )
77local useTheme = require ("../../Hooks/useTheme" )
88
9+ local BaseIcon = require ("./BaseIcon" )
10+
911local PADDING_X = 8
1012local PADDING_Y = 4
1113local DEFAULT_HEIGHT = Constants .DefaultButtonHeight
1214
15+ export type BaseButtonIconProps = {
16+ Image : string ,
17+ Size : Vector2 ,
18+ Transparency : number ? ,
19+ Color : Color3 ? ,
20+ ResampleMode : Enum .ResamplerMode ? ,
21+ RectOffset : Vector2 ? ,
22+ RectSize : Vector2 ? ,
23+ UseThemeColor : boolean ? ,
24+ Alignment : Enum .HorizontalAlignment ? ,
25+ }
26+
1327export type BaseButtonConsumerProps = CommonProps .T & {
1428 AutomaticSize : Enum .AutomaticSize ? ,
1529 OnActivated : (() -> ())? ,
1630 Selected : boolean ? ,
1731 Text : string ? ,
1832 TextTransparency : number ? ,
19- Icon : {
20- Image : string ,
21- Size : Vector2 ,
22- Transparency : number ? ,
23- Color : Color3 ? ,
24- UseThemeColor : boolean ? ,
25- Alignment : Enum .HorizontalAlignment ? ,
26- }? ,
33+ Icon : BaseButtonIconProps ? ,
2734}
2835
2936export type BaseButtonProps = BaseButtonConsumerProps & {
@@ -78,6 +85,17 @@ local function BaseButton(props: BaseButtonProps)
7885 size = UDim2 .new (size .Width , UDim .new (0 , math.max (DEFAULT_HEIGHT , contentHeight + PADDING_Y * 2 )))
7986 end
8087
88+ local iconNode : React .Node ?
89+ if props .Icon then
90+ local iconProps = (table.clone (props .Icon ) :: any ) :: BaseIcon .BaseIconProps
91+ iconProps .Disabled = props .Disabled
92+ iconProps .Color = iconProps .Color or if props .Icon .UseThemeColor then textColor else nil
93+ iconProps .LayoutOrder = if props .Icon .Alignment == Enum.HorizontalAlignment.Right then 3 else 1
94+ iconProps .Size = UDim2 .fromOffset (props .Icon .Size .X , props .Icon .Size .Y )
95+
96+ iconNode = React .createElement (BaseIcon , iconProps )
97+ end
98+
8199 return React .createElement ("TextButton" , {
82100 AutoButtonColor = false ,
83101 AnchorPoint = props .AnchorPoint ,
@@ -115,17 +133,7 @@ local function BaseButton(props: BaseButtonProps)
115133 HorizontalAlignment = Enum.HorizontalAlignment.Center ,
116134 VerticalAlignment = Enum.VerticalAlignment.Center ,
117135 }),
118- Icon = props .Icon and React .createElement ("ImageLabel" , {
119- Image = props .Icon .Image ,
120- Size = UDim2 .fromOffset (props .Icon .Size .X , props .Icon .Size .Y ),
121- LayoutOrder = if props .Icon .Alignment == Enum.HorizontalAlignment.Right then 3 else 1 ,
122- BackgroundTransparency = 1 ,
123- ImageColor3 = if props .Icon .Color
124- then props .Icon .Color
125- elseif props .Icon .UseThemeColor then textColor
126- else nil ,
127- ImageTransparency = 1 - (1 - (props .Icon .Transparency or 0 )) * (1 - if props .Disabled then 0.2 else 0 ),
128- }),
136+ Icon = iconNode ,
129137 Label = props .Text and React .createElement ("TextLabel" , {
130138 TextColor3 = textColor ,
131139 Font = Constants .DefaultFont ,
0 commit comments