-- 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 Players = game:GetService("Players") local ThemeContext = TS.import(script, script.Parent.Parent, "UIKit", "ThemeContext").default local ZirconIcon = TS.import(script, script.Parent, "Icon").default local Padding = TS.import(script, script.Parent, "Padding").default local ScrollView = TS.import(script, script.Parent, "ScrollView").default local Dropdown do Dropdown = Roact.Component:extend("Dropdown") function Dropdown:init(props) self.dropdownRef = Roact.createRef() self.maid = Maid.new() self.state = { selectedItemIndex = props.SelectedItemIndex ~= nil and props.SelectedItemIndex or 0, active = false, } if props.SelectedItemId ~= nil then local _items = props.Items local _arg0 = function(f) return f.Id == props.SelectedItemId end -- ▼ ReadonlyArray.findIndex ▼ local _result = -1 for _i, _v in ipairs(_items) do if _arg0(_v, _i - 1, _items) == true then _result = _i - 1 break end end -- ▲ ReadonlyArray.findIndex ▲ local selectedItemIndex = _result if selectedItemIndex ~= -1 then self:setState({ selectedItemIndex = selectedItemIndex, }) end end self.portalPosition, self.setPortalPosition = Roact.createBinding(UDim2.new()) self.portalSizeX, self.setPortalSizeX = Roact.createBinding(0) end function Dropdown:setPortalPositionRelativeTo(frame) local _binding = frame local AbsolutePosition = _binding.AbsolutePosition local AbsoluteSize = _binding.AbsoluteSize self.setPortalPosition(UDim2.new(0, AbsolutePosition.X, 0, AbsolutePosition.Y + AbsoluteSize.Y)) self.setPortalSizeX(AbsoluteSize.X) end function Dropdown:didUpdate(prevProps) if prevProps.SelectedItemId ~= self.props.SelectedItemId then local _items = self.props.Items local _arg0 = function(f) return f.Id == self.props.SelectedItemId end -- ▼ ReadonlyArray.findIndex ▼ local _result = -1 for _i, _v in ipairs(_items) do if _arg0(_v, _i - 1, _items) == true then _result = _i - 1 break end end -- ▲ ReadonlyArray.findIndex ▲ local selectedItemIndex = _result if selectedItemIndex ~= -1 then self:setState({ selectedItemIndex = selectedItemIndex, }) end end end function Dropdown:didMount() local frame = self.dropdownRef:getValue() if frame then self.maid:GiveTask(frame:GetPropertyChangedSignal("AbsoluteSize"):Connect(function() self:setPortalPositionRelativeTo(frame) end)) self.maid:GiveTask(frame:GetPropertyChangedSignal("AbsolutePosition"):Connect(function() self:setPortalPositionRelativeTo(frame) end)) self:setPortalPositionRelativeTo(frame) end end function Dropdown:willUnmount() self.maid:DoCleaning() end function Dropdown:renderDropdownItems() local _binding = self.state local selectedItemIndex = _binding.selectedItemIndex local _items = self.props.Items local _arg0 = function(item, idx) return Roact.createElement(ThemeContext.Consumer, { render = function(theme) local _attributes = { Size = UDim2.new(1, 0, 0, 30), BackgroundColor3 = selectedItemIndex == idx and theme.PrimarySelectColor3 or theme.SecondaryBackgroundColor3, BorderSizePixel = 0, } local _children = {} local _length = #_children local _attributes_1 = { Size = UDim2.new(1, 0, 1, 0), BackgroundTransparency = 1, } local _children_1 = { Roact.createElement(Padding, { Padding = { Right = 20, Horizontal = 5, }, }), } local _length_1 = #_children_1 local _child = item.Icon and Roact.createElement(ZirconIcon, { Icon = item.Icon, Position = UDim2.new(0, 0, 0.5, -8), }) if _child then if _child.elements ~= nil or _child.props ~= nil and _child.component ~= nil then _children_1[_length_1 + 1] = _child else for _k, _v in ipairs(_child) do _children_1[_length_1 + _k] = _v end end end _length_1 = #_children_1 _children_1[_length_1 + 1] = Roact.createElement("TextButton", { Font = theme.Font, TextXAlignment = "Left", TextSize = 15, BackgroundTransparency = 1, Size = UDim2.new(1, 0, 1, 0), Position = item.Icon and UDim2.new(0, 20, 0, 0) or UDim2.new(), TextColor3 = theme.PrimaryTextColor3, Text = item.Text, [Roact.Event.MouseButton1Click] = function() self:setState({ selectedItemIndex = idx, active = false, }) if self.props.ItemSelected ~= nil then self.props.ItemSelected(item) end end, }) _children[_length + 1] = Roact.createElement("Frame", _attributes_1, _children_1) return Roact.createElement("Frame", _attributes, _children) end, }) end -- ▼ ReadonlyArray.map ▼ local _newValue = table.create(#_items) for _k, _v in ipairs(_items) do _newValue[_k] = _arg0(_v, _k - 1, _items) end -- ▲ ReadonlyArray.map ▲ return _newValue end function Dropdown:renderDropdown() local _binding = self.state local active = _binding.active if active == false then return Roact.createFragment() end local activeSizeY = math.min(#self.props.Items * 30, 30 * 4) local portal = (Roact.createElement(ThemeContext.Consumer, { render = function(theme) local _attributes = { BackgroundColor3 = theme.PrimaryBackgroundColor3, BorderColor3 = theme.SecondaryBackgroundColor3, Position = self.portalPosition, Size = self.portalSizeX:map(function(x) return UDim2.new(0, x, 0, activeSizeY) end), [Roact.Event.MouseLeave] = function() return self:setState({ active = false, }) end, } local _children = {} local _length = #_children local _children_1 = {} local _length_1 = #_children_1 for _k, _v in ipairs(self:renderDropdownItems()) do _children_1[_length_1 + _k] = _v end _children[_length + 1] = Roact.createElement(ScrollView, {}, _children_1) return Roact.createFragment({ DropdownPortal = Roact.createElement("Frame", _attributes, _children), }) end, })) return Roact.createElement(Roact.Portal, { target = Players.LocalPlayer:FindFirstChildOfClass("PlayerGui"), }, { HostedDropdownPortal = Roact.createElement("ScreenGui", { DisplayOrder = 10500, }, { portal, }), }) end function Dropdown:render() local _binding = self.props local Items = _binding.Items local Disabled = _binding.Disabled local Size = _binding.Size if Size == nil then Size = UDim2.new(0, 150, 0, 30) end local Position = _binding.Position local _binding_1 = self.state local selectedItemIndex = _binding_1.selectedItemIndex local item = Items[selectedItemIndex + 1] local _arg1 = "Invalid Item Index " .. tostring(selectedItemIndex) assert(item, _arg1) return Roact.createElement(ThemeContext.Consumer, { render = function(theme) local _attributes = { BackgroundColor3 = theme.SecondaryBackgroundColor3, BorderColor3 = theme.PrimaryBackgroundColor3, Size = Size, Position = Position, [Roact.Ref] = self.dropdownRef, } local _children = {} local _length = #_children local _attributes_1 = { Size = UDim2.new(1, -25, 1, 0), BackgroundTransparency = 1, } local _children_1 = { Roact.createElement(Padding, { Padding = { Horizontal = 10, }, }), } local _length_1 = #_children_1 local _child = item.Icon and Roact.createElement(ZirconIcon, { Icon = item.Icon, Position = UDim2.new(0, 0, 0.5, -8), }) if _child then if _child.elements ~= nil or _child.props ~= nil and _child.component ~= nil then _children_1[_length_1 + 1] = _child else for _k, _v in ipairs(_child) do _children_1[_length_1 + _k] = _v end end end _length_1 = #_children_1 local _attributes_2 = { Size = UDim2.new(1, 0, 1, 0), Position = item.Icon and UDim2.new(0, 20, 0, 0) or UDim2.new(), BackgroundTransparency = 1, Font = theme.Font, TextSize = 15, TextXAlignment = "Left", TextColor3 = Disabled and theme.PrimaryDisabledColor3 or (item.TextColor3 and item.TextColor3 or theme.PrimaryTextColor3), } local _condition = item.SelectedText if _condition == nil then _condition = item.Text end _attributes_2.Text = _condition _attributes_2[Roact.Event.MouseButton1Click] = function() return not Disabled and self:setState({ active = not self.state.active, }) end _children_1[_length_1 + 1] = Roact.createElement("TextButton", _attributes_2) _children.Content = Roact.createElement("Frame", _attributes_1, _children_1) _children[_length + 1] = Roact.createElement("ImageLabel", { Image = "rbxassetid://2657038128", ImageColor3 = Disabled and theme.PrimaryDisabledColor3 or theme.PrimaryTextColor3, Position = UDim2.new(1, -25, 0, 5), BackgroundTransparency = 1, Rotation = self.state.active and 0 or 180, Size = UDim2.new(0, 20, 0, 20), }) _children[_length + 2] = self:renderDropdown() return Roact.createElement("Frame", _attributes, _children) end, }) end end return { default = Dropdown, }