-- Compiled with roblox-ts v1.2.7 local TS = _G[script] local Maid = TS.import(script, TS.getModule(script, "@rbxts", "maid").Maid) local Roact = TS.import(script, TS.getModule(script, "@rbxts", "roact").src) local Snapdragon = TS.import(script, TS.getModule(script, "@rbxts", "snapdragon").src) local ThemeContext = TS.import(script, script.Parent.Parent, "UIKit", "ThemeContext").default local ZirconIcon = TS.import(script, script.Parent, "Icon").default local TITLEBAR_SIZE = 30 local ZirconTitlebar do ZirconTitlebar = Roact.Component:extend("ZirconTitlebar") function ZirconTitlebar:init(props) self.dragRef = Snapdragon.createRef() self.frameRef = Roact.createRef() self.maid = Maid.new() self.state = {} end function ZirconTitlebar:didMount() local frameRef = self.frameRef:getValue() local _binding = self.props local Draggable = _binding.Draggable if frameRef and Draggable then local _binding_1 = self.props local SnapEnabled = _binding_1.SnapEnabled local SnapMargin = _binding_1.SnapMargin local SnapThreshold = _binding_1.SnapThresholdMargin self.dragRef:Update(frameRef) self.dragController = Snapdragon.createDragController(self.dragRef, { DragGui = frameRef.Parent, SnapEnabled = SnapEnabled, SnapMargin = SnapMargin, SnapThreshold = SnapThreshold, }) self.dragController:Connect() self.maid:GiveTask(self.dragController) if self.props.DragBegan ~= nil then self.maid:GiveTask(self.dragController.DragEnded:Connect(function(ended) local _result = self.props.DragEnded if _result ~= nil then _result(ended.InputPosition) end end)) end if self.props.DragEnded ~= nil then self.maid:GiveTask(self.dragController.DragEnded:Connect(function(ended) local _result = self.props.DragEnded if _result ~= nil then _result(ended.InputPosition) end end)) end end end function ZirconTitlebar:willUnmount() self.maid:DoCleaning() end function ZirconTitlebar:render() local _binding = self.props local Buttons = _binding.Buttons local RenderContent = _binding.RenderContent local leftButtons = {} local rightButtons = {} local LeftButtons = function() if #leftButtons > 0 then local _attributes = { Size = UDim2.new(0.25, 0, 1, 0), Position = UDim2.new(0, 0, 0, 0), BackgroundTransparency = 1, } local _children = { Roact.createElement("UIListLayout", { HorizontalAlignment = Enum.HorizontalAlignment.Left, FillDirection = Enum.FillDirection.Horizontal, }), } local _length = #_children for _k, _v in ipairs(leftButtons) do _children[_length + _k] = _v end return Roact.createElement("Frame", _attributes, _children) else return Roact.createFragment({}) end end local RightButtons = function() if #rightButtons > 0 then local _attributes = { Size = UDim2.new(0.25, 0, 1, 0), Position = UDim2.new(0.75, 0, 0, 0), BackgroundTransparency = 1, } local _children = { Roact.createElement("UIListLayout", { HorizontalAlignment = Enum.HorizontalAlignment.Right, FillDirection = Enum.FillDirection.Horizontal, }), } local _length = #_children for _k, _v in ipairs(rightButtons) do _children[_length + _k] = _v end return Roact.createElement("Frame", _attributes, _children) else return Roact.createFragment({}) end end if Buttons then for _, button in ipairs(Buttons) do local _attributes = { Text = "", BackgroundTransparency = 1, } local _condition = button.Size if _condition == nil then _condition = UDim2.new(0, TITLEBAR_SIZE, 0, TITLEBAR_SIZE) end _attributes.Size = _condition _attributes[Roact.Event.MouseButton1Click] = button.OnClick local btn = (Roact.createElement("TextButton", _attributes, { Roact.createElement("UIListLayout", { VerticalAlignment = "Center", HorizontalAlignment = "Center", }), Roact.createElement(ZirconIcon, { Icon = button.Icon, }), })) if button.Alignment == "right" then -- ▼ Array.push ▼ rightButtons[#rightButtons + 1] = btn -- ▲ Array.push ▲ elseif button.Alignment == "left" then -- ▼ Array.push ▼ leftButtons[#leftButtons + 1] = btn -- ▲ Array.push ▲ end end end return Roact.createElement(ThemeContext.Consumer, { render = function(value) return Roact.createElement("Frame", { BackgroundColor3 = Color3.fromRGB(33, 37, 43), BorderColor3 = Color3.fromRGB(33, 37, 43), Size = self.props.Size or UDim2.new(1, 0, 0, TITLEBAR_SIZE), [Roact.Ref] = self.frameRef, }, { Roact.createElement("TextLabel", { Text = self.props.Text ~= nil and self.props.Text or "", BackgroundTransparency = 1, Font = value.Font, Size = #leftButtons > 0 and UDim2.new(0.5, -10, 1, 0) or UDim2.new(1, -10, 1, 0), TextColor3 = self.props.TextColor or Color3.fromRGB(220, 220, 220), TextXAlignment = #leftButtons > 0 and Enum.TextXAlignment.Center or Enum.TextXAlignment.Left, Position = #leftButtons > 0 and UDim2.new(0.25, 10, 0, 0) or UDim2.new(0, 10, 0, 0), TextSize = self.props.TextSize ~= nil and self.props.TextSize or 18, }), Roact.createElement(LeftButtons), Roact.createElement(RightButtons), }) end, }) end end return { TITLEBAR_SIZE = TITLEBAR_SIZE, default = ZirconTitlebar, }