Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Searchbar #39

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 6 additions & 30 deletions plugin/src/components/Home.luau
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ local React = require("@pkg/React")
local types = require("@root/types")
local LoadingSpinner = require("./LoadingSpinner")
local ExtensionsList = require("./ExtensionsList")
local Searchbar = require("./Searchbar")
local getLayoutOrder = require("./getLayoutOrder")
local useCombinedSize = require("./useCombinedSize")

type PublishedExtension = types.PublishedExtension
type ExtensionTheme = types.ExtensionTheme

local useCallback = React.useCallback
local useMemo = React.useMemo

local PADDING = UDim.new(0, 8)
Expand All @@ -27,12 +26,6 @@ local function Home(props: Props)
return #props.extensions == 0 and not props.err
end, { props.extensions, props.err })

local onSearch = useCallback(function(rbx: TextBox, enterPressed: boolean)
if enterPressed and rbx.Text ~= "" then
props.onSearch(rbx.Text)
end
end, {})

local combinedSize = useCombinedSize()

return React.createElement("Frame", {
Expand All @@ -52,32 +45,15 @@ local function Home(props: Props)
PaddingLeft = PADDING,
}),

SearchForm = React.createElement("Frame", {
SearchbarWrapper = React.createElement("Frame", {
LayoutOrder = getLayoutOrder(),
Size = UDim2.fromScale(1, 0),
AutomaticSize = Enum.AutomaticSize.Y,
AutomaticSize = Enum.AutomaticSize.XY,
BackgroundTransparency = 1,
[React.Tag] = combinedSize.tag,
}, {
Input = React.createElement("TextBox", {
Text = if props.searchTerm then props.searchTerm else "",
PlaceholderText = "Search themes...",
Size = UDim2.fromScale(1, 0),
TextColor3 = Color3.fromRGB(255, 255, 255),
PlaceholderColor3 = Color3.fromRGB(200, 200, 200),
TextSize = 16,
Font = Enum.Font.Gotham,
AutomaticSize = Enum.AutomaticSize.Y,
BorderSizePixel = 0,
BackgroundColor3 = Color3.fromRGB(100, 100, 100),
[React.Event.FocusLost] = onSearch,
}, {
Padding = React.createElement("UIPadding", {
PaddingTop = PADDING,
PaddingRight = PADDING,
PaddingBottom = PADDING,
PaddingLeft = PADDING,
}),
Searchbar = React.createElement(Searchbar, {
searchTerm = props.searchTerm,
onSearch = props.onSearch,
}),
}),

Expand Down
53 changes: 53 additions & 0 deletions plugin/src/components/Searchbar.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
local React = require("@pkg/React")

local useCallback = React.useCallback

local PADDING = UDim.new(0, 8)

export type Props = {
searchTerm: string?,
onSearch: (searchTerm: string) -> (),
LayoutOrder: number?,
}

local function Searchbar(props: Props)
local onSearch = useCallback(function(rbx: TextBox, enterPressed: boolean)
if enterPressed and rbx.Text ~= "" then
props.onSearch(rbx.Text)
end
end, { props.onSearch })

return React.createElement("Frame", {
LayoutOrder = props.LayoutOrder,
Size = UDim2.fromScale(1, 0),
AutomaticSize = Enum.AutomaticSize.Y,
BackgroundTransparency = 1,
}, {
Input = React.createElement("TextBox", {
Text = if props.searchTerm then props.searchTerm else "",
PlaceholderText = "Search themes...",
Size = UDim2.fromScale(1, 0),
TextColor3 = Color3.fromRGB(255, 255, 255),
PlaceholderColor3 = Color3.fromRGB(200, 200, 200),
TextSize = 16,
Font = Enum.Font.Gotham,
AutomaticSize = Enum.AutomaticSize.Y,
BorderSizePixel = 0,
BackgroundColor3 = Color3.fromRGB(100, 100, 100),
[React.Event.FocusLost] = onSearch,
}, {
BorderRadius = React.createElement("UICorner", {
CornerRadius = PADDING,
}),

Padding = React.createElement("UIPadding", {
PaddingTop = PADDING,
PaddingRight = PADDING,
PaddingBottom = PADDING,
PaddingLeft = PADDING,
}),
}),
})
end

return Searchbar
15 changes: 15 additions & 0 deletions plugin/src/components/Searchbar.story.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local React = require("@pkg/React")
local Searchbar = require("./Searchbar")

local useState = React.useState

return {
story = function()
local searchTerm, setSearchTerm = useState(nil :: string?)

return React.createElement(Searchbar, {
searchTerm = searchTerm,
onSearch = setSearchTerm,
})
end,
}
Loading