|
| 1 | +local CommonProps = require(script.Parent.Parent.Parent.CommonProps) |
| 2 | +local React = require("@pkg/@jsdotlua/react") |
| 3 | + |
| 4 | +local e = React.createElement |
| 5 | +local useTheme = require("../../Hooks/useTheme") |
| 6 | +local useToggleState = require("../../Hooks/useToggleState") |
| 7 | + |
| 8 | +local HEADER_HEIGHT = 24 |
| 9 | +local ARROW_RIGHT = "rbxasset://textures/ui/MenuBar/arrow_right.png" |
| 10 | +local ARROW_DOWN = "rbxasset://textures/ui/MenuBar/arrow_down.png" |
| 11 | + |
| 12 | +local function HeaderIcon(props: CommonProps.T & { Icon: { Image: string, UseThemeColor: boolean? } }) |
| 13 | + local theme = useTheme() |
| 14 | + |
| 15 | + return e("ImageLabel", { |
| 16 | + BackgroundTransparency = 1, |
| 17 | + BorderSizePixel = 0, |
| 18 | + LayoutOrder = props.LayoutOrder, |
| 19 | + Size = props.Size or UDim2.fromOffset(HEADER_HEIGHT, HEADER_HEIGHT), |
| 20 | + ImageColor3 = if props.Icon.UseThemeColor ~= true |
| 21 | + then Color3.fromRGB(255, 255, 255) |
| 22 | + else theme:GetColor(Enum.StudioStyleGuideColor.MainText), |
| 23 | + ImageTransparency = if props.Disabled then 0.6 else 0, |
| 24 | + Image = props.Icon.Image, |
| 25 | + }) |
| 26 | +end |
| 27 | + |
| 28 | +local function Header(props: CommonProps.T & { |
| 29 | + Selected: boolean?, |
| 30 | + Expanded: boolean?, |
| 31 | + IsBlockStyle: boolean?, |
| 32 | + OnActivated: () -> (), |
| 33 | + Text: string, |
| 34 | + Icon: { |
| 35 | + Image: string?, |
| 36 | + UseThemeColor: boolean?, |
| 37 | + }, |
| 38 | +}) |
| 39 | + local theme = useTheme() |
| 40 | + local hovering = useToggleState(false) |
| 41 | + |
| 42 | + local modifier = Enum.StudioStyleGuideModifier.Default |
| 43 | + |
| 44 | + return e("TextButton", { |
| 45 | + AutomaticSize = Enum.AutomaticSize.X, |
| 46 | + AutoButtonColor = false, |
| 47 | + BackgroundColor3 = if hovering.on |
| 48 | + then theme:GetColor(Enum.StudioStyleGuideColor.ViewPortBackground) |
| 49 | + elseif props.IsBlockStyle then theme:GetColor(Enum.StudioStyleGuideColor.Titlebar) |
| 50 | + else theme:GetColor(Enum.StudioStyleGuideColor.MainBackground), |
| 51 | + BackgroundTransparency = 0, |
| 52 | + BorderSizePixel = if props.IsBlockStyle then 1 else 0, |
| 53 | + BorderColor3 = theme:GetColor(Enum.StudioStyleGuideColor.Border, modifier), |
| 54 | + Size = UDim2.new(1, 0, 0, HEADER_HEIGHT), |
| 55 | + LayoutOrder = props.LayoutOrder, |
| 56 | + Text = "", |
| 57 | + ClipsDescendants = true, |
| 58 | + |
| 59 | + [React.Event.MouseEnter] = if not props.Disabled then hovering.enable else nil, |
| 60 | + [React.Event.MouseLeave] = if not props.Disabled then hovering.disable else nil, |
| 61 | + [React.Event.Activated] = if not props.Disabled then props.OnActivated else nil, |
| 62 | + }, { |
| 63 | + Layout = e("UIListLayout", { |
| 64 | + FillDirection = Enum.FillDirection.Horizontal, |
| 65 | + Padding = UDim.new(0, 0), |
| 66 | + HorizontalAlignment = Enum.HorizontalAlignment.Left, |
| 67 | + VerticalAlignment = Enum.VerticalAlignment.Center, |
| 68 | + SortOrder = Enum.SortOrder.LayoutOrder, |
| 69 | + }), |
| 70 | + |
| 71 | + UIPadding = e("UIPadding", { |
| 72 | + PaddingLeft = UDim.new(0, 5), |
| 73 | + }), |
| 74 | + |
| 75 | + ArrowIconFrame = e(HeaderIcon, { |
| 76 | + Icon = { |
| 77 | + Image = if props.Expanded then ARROW_DOWN else ARROW_RIGHT, |
| 78 | + UseThemeColor = true, |
| 79 | + }, |
| 80 | + Disabled = props.Disabled, |
| 81 | + LayoutOrder = 1, |
| 82 | + Size = UDim2.fromOffset(HEADER_HEIGHT * 0.75, HEADER_HEIGHT * 0.75), |
| 83 | + }), |
| 84 | + |
| 85 | + IconFrame = props.Icon and e(HeaderIcon, { |
| 86 | + Icon = props.Icon, |
| 87 | + Disabled = props.Disabled, |
| 88 | + LayoutOrder = 2, |
| 89 | + }), |
| 90 | + |
| 91 | + Title = e("TextLabel", { |
| 92 | + AutomaticSize = Enum.AutomaticSize.X, |
| 93 | + BackgroundTransparency = 1, |
| 94 | + BorderSizePixel = 0, |
| 95 | + LayoutOrder = 3, |
| 96 | + TextTransparency = if props.Disabled then 0.5 else 0, |
| 97 | + Size = UDim2.fromOffset(0, HEADER_HEIGHT), |
| 98 | + Text = props.Text, |
| 99 | + TextColor3 = theme:GetColor(Enum.StudioStyleGuideColor.MainText), |
| 100 | + TextXAlignment = Enum.TextXAlignment.Left, |
| 101 | + }, { |
| 102 | + UIPadding = e("UIPadding", { |
| 103 | + PaddingLeft = UDim.new(0, 4), |
| 104 | + }), |
| 105 | + }), |
| 106 | + }) |
| 107 | +end |
| 108 | + |
| 109 | +return Header |
0 commit comments