-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b2879b
commit f6e8bd6
Showing
5 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
local Vendor = script.Parent.Parent | ||
local Roact = require(Vendor.Roact) | ||
|
||
local withTheme = require(script.Parent.withTheme) | ||
local TextInput = Roact.Component:extend("TextInput") | ||
|
||
local PLACEHOLDER_TEXT_COLOR = Color3.fromRGB(102, 102, 102) -- works for both themes | ||
|
||
local function joinDictionaries(...) | ||
local out = {} | ||
for i = 1, select("#", ...) do | ||
for key, val in pairs(select(i, ...)) do | ||
out[key] = val | ||
end | ||
end | ||
return out | ||
end | ||
|
||
local noop = function() | ||
end | ||
|
||
TextInput.defaultProps = { | ||
LayoutOrder = 0, | ||
Disabled = false, | ||
Text = "", | ||
PlaceholderText = "", | ||
ClearTextOnFocus = true, | ||
OnFocused = noop, | ||
OnFocusLost = noop, | ||
OnChanged = noop, | ||
} | ||
|
||
function TextInput:init() | ||
self:setState({ | ||
Hover = false, | ||
Focused = false, | ||
}) | ||
self.onInputBegan = function(_, inputObject) | ||
if self.props.Disabled then | ||
return | ||
elseif inputObject.UserInputType == Enum.UserInputType.MouseMovement then | ||
self:setState({ Hover = true }) | ||
end | ||
end | ||
self.onInputEnded = function(_, inputObject) | ||
if self.props.Disabled then | ||
return | ||
elseif inputObject.UserInputType == Enum.UserInputType.MouseMovement then | ||
self:setState({ Hover = false }) | ||
end | ||
end | ||
self.onFocused = function() | ||
self:setState({ Focused = true }) | ||
self.props.OnFocused() | ||
end | ||
self.onFocusLost = function(_, enterPressed, inputObject) | ||
self:setState({ Focused = false }) | ||
self.props.OnFocusLost(enterPressed, inputObject) | ||
end | ||
self.onChanged = function(rbx) | ||
self.props.OnChanged(rbx.Text) | ||
end | ||
end | ||
|
||
function TextInput:render() | ||
local padding = Roact.createElement("UIPadding", { | ||
PaddingLeft = UDim.new(0, 5), | ||
PaddingRight = UDim.new(0, 5), | ||
}) | ||
local mainModifier = Enum.StudioStyleGuideModifier.Default | ||
local borderModifier = Enum.StudioStyleGuideModifier.Default | ||
if self.props.Disabled then | ||
mainModifier = Enum.StudioStyleGuideModifier.Disabled | ||
borderModifier = Enum.StudioStyleGuideModifier.Disabled | ||
elseif self.state.Focused then | ||
borderModifier = Enum.StudioStyleGuideModifier.Selected | ||
elseif self.state.Hover then | ||
borderModifier = Enum.StudioStyleGuideModifier.Hover | ||
end | ||
return withTheme(function(theme) | ||
local textFieldProps = { | ||
Size = UDim2.new(1, -5, 0, 21), -- temp | ||
BackgroundColor3 = theme:GetColor(Enum.StudioStyleGuideColor.InputFieldBackground, mainModifier), | ||
BorderColor3 = theme:GetColor(Enum.StudioStyleGuideColor.InputFieldBorder, borderModifier), | ||
BorderMode = Enum.BorderMode.Inset, | ||
LayoutOrder = self.props.LayoutOrder, | ||
Font = Enum.Font.SourceSans, | ||
Text = self.props.Text, | ||
TextSize = 14, | ||
TextColor3 = theme:GetColor(Enum.StudioStyleGuideColor.MainText, mainModifier), | ||
TextXAlignment = Enum.TextXAlignment.Left, | ||
} | ||
return self.props.Disabled | ||
and Roact.createElement("TextLabel", textFieldProps, { Padding = padding }) | ||
or Roact.createElement( | ||
"TextBox", | ||
joinDictionaries(textFieldProps, { | ||
PlaceholderText = self.props.PlaceholderText, | ||
PlaceholderColor3 = PLACEHOLDER_TEXT_COLOR, | ||
ClearTextOnFocus = self.props.ClearTextOnFocus, | ||
[Roact.Event.Focused] = self.onFocused, | ||
[Roact.Event.FocusLost] = self.onFocusLost, | ||
[Roact.Event.InputBegan] = self.onInputBegan, | ||
[Roact.Event.InputEnded] = self.onInputEnded, | ||
[Roact.Change.Text] = self.onChanged, | ||
}), | ||
{ | ||
Padding = padding, | ||
} | ||
) | ||
end) | ||
end | ||
|
||
return TextInput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
local Vendor = script.Parent.Parent | ||
local Roact = require(Vendor.Roact) | ||
|
||
local TextInput = require(script.Parent.TextInput) | ||
local Checkbox = require(script.Parent.Checkbox) | ||
|
||
local Wrapper = Roact.Component:extend("TestWrapper") | ||
|
||
function Wrapper:init() | ||
self:setState({ | ||
Disabled = false, | ||
}) | ||
end | ||
|
||
function Wrapper:render() | ||
return Roact.createFragment({ | ||
Layout = Roact.createElement("UIListLayout", { | ||
Padding = UDim.new(0, 5), | ||
SortOrder = Enum.SortOrder.LayoutOrder, | ||
FillDirection = Enum.FillDirection.Vertical, | ||
}), | ||
Input = Roact.createElement(TextInput, { | ||
LayoutOrder = 0, | ||
PlaceholderText = "Placeholder text", | ||
Disabled = self.state.Disabled, | ||
}), | ||
Checkbox = Roact.createElement(Checkbox, { | ||
LayoutOrder = 1, | ||
Value = not self.state.Disabled, | ||
Label = "Enable input", | ||
OnActivated = function() | ||
self:setState({ Disabled = not self.state.Disabled }) | ||
end, | ||
}), | ||
}) | ||
end | ||
|
||
return function(target) | ||
local element = Roact.createElement(Wrapper) | ||
local handle = Roact.mount(element, target) | ||
return function() | ||
Roact.unmount(handle) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
column_width = 100 |