@lattice-ui/text-field 0.4.3 → 0.5.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/default.project.json +9 -0
- package/out/TextField/TextFieldInput.luau +21 -2
- package/package.json +16 -2
- package/src/TextField/TextFieldInput.tsx +21 -2
- package/.turbo/turbo-build.log +0 -4
- package/.turbo/turbo-typecheck.log +0 -4
- package/tsconfig.json +0 -16
- package/tsconfig.typecheck.json +0 -35
|
@@ -3,6 +3,9 @@ local TS = _G[script]
|
|
|
3
3
|
local _core = TS.import(script, TS.getModule(script, "@lattice-ui", "core").out)
|
|
4
4
|
local React = _core.React
|
|
5
5
|
local Slot = _core.Slot
|
|
6
|
+
local _motion = TS.import(script, TS.getModule(script, "@lattice-ui", "motion").out)
|
|
7
|
+
local createFieldResponseRecipe = _motion.createFieldResponseRecipe
|
|
8
|
+
local useResponseMotion = _motion.useResponseMotion
|
|
6
9
|
local useTextFieldContext = TS.import(script, script.Parent, "context").useTextFieldContext
|
|
7
10
|
local function toTextBox(instance)
|
|
8
11
|
if not instance or not instance:IsA("TextBox") then
|
|
@@ -14,9 +17,20 @@ local function TextFieldInput(props)
|
|
|
14
17
|
local textFieldContext = useTextFieldContext()
|
|
15
18
|
local disabled = textFieldContext.disabled or props.disabled == true
|
|
16
19
|
local readOnly = textFieldContext.readOnly or props.readOnly == true
|
|
20
|
+
local focused, setFocused = React.useState(false)
|
|
21
|
+
local active = focused and not disabled and not readOnly
|
|
22
|
+
local localRef = useResponseMotion(active, {
|
|
23
|
+
active = {
|
|
24
|
+
BackgroundColor3 = Color3.fromRGB(35, 41, 54),
|
|
25
|
+
},
|
|
26
|
+
inactive = {
|
|
27
|
+
BackgroundColor3 = Color3.fromRGB(39, 46, 61),
|
|
28
|
+
},
|
|
29
|
+
}, createFieldResponseRecipe())
|
|
17
30
|
local setInputRef = React.useCallback(function(instance)
|
|
31
|
+
localRef.current = toTextBox(instance)
|
|
18
32
|
textFieldContext.inputRef.current = toTextBox(instance)
|
|
19
|
-
end, { textFieldContext.inputRef })
|
|
33
|
+
end, { textFieldContext.inputRef, localRef })
|
|
20
34
|
local handleTextChanged = React.useCallback(function(textBox)
|
|
21
35
|
if disabled or readOnly then
|
|
22
36
|
if textBox.Text ~= textFieldContext.value then
|
|
@@ -26,7 +40,11 @@ local function TextFieldInput(props)
|
|
|
26
40
|
end
|
|
27
41
|
textFieldContext.setValue(textBox.Text)
|
|
28
42
|
end, { disabled, readOnly, textFieldContext })
|
|
43
|
+
local handleFocused = React.useCallback(function()
|
|
44
|
+
setFocused(true)
|
|
45
|
+
end, {})
|
|
29
46
|
local handleFocusLost = React.useCallback(function(textBox)
|
|
47
|
+
setFocused(false)
|
|
30
48
|
if disabled then
|
|
31
49
|
return nil
|
|
32
50
|
end
|
|
@@ -42,6 +60,7 @@ local function TextFieldInput(props)
|
|
|
42
60
|
Text = handleTextChanged,
|
|
43
61
|
},
|
|
44
62
|
Event = {
|
|
63
|
+
Focused = handleFocused,
|
|
45
64
|
FocusLost = handleFocusLost,
|
|
46
65
|
},
|
|
47
66
|
ref = setInputRef,
|
|
@@ -57,7 +76,7 @@ local function TextFieldInput(props)
|
|
|
57
76
|
end
|
|
58
77
|
local _attributes = table.clone(sharedProps)
|
|
59
78
|
setmetatable(_attributes, nil)
|
|
60
|
-
_attributes.BackgroundColor3 = Color3.fromRGB(39, 46, 61)
|
|
79
|
+
_attributes.BackgroundColor3 = if focused and not disabled and not readOnly then Color3.fromRGB(47, 53, 68) else Color3.fromRGB(39, 46, 61)
|
|
61
80
|
_attributes.BorderSizePixel = 0
|
|
62
81
|
_attributes.PlaceholderText = "Type..."
|
|
63
82
|
_attributes.Size = UDim2.fromOffset(240, 36)
|
package/package.json
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lattice-ui/text-field",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-next.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "out/init.luau",
|
|
6
6
|
"types": "out/index.d.ts",
|
|
7
|
+
"source": "src/index.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"default.project.json",
|
|
10
|
+
"out",
|
|
11
|
+
"src",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/astra-void/lattice-ui.git"
|
|
17
|
+
},
|
|
7
18
|
"dependencies": {
|
|
8
|
-
"@lattice-ui/core": "0.
|
|
19
|
+
"@lattice-ui/core": "0.5.0-next.1",
|
|
20
|
+
"@lattice-ui/motion": "0.5.0-next.1"
|
|
9
21
|
},
|
|
10
22
|
"devDependencies": {
|
|
11
23
|
"@rbxts/react": "17.3.7-ts.1",
|
|
@@ -17,6 +29,8 @@
|
|
|
17
29
|
},
|
|
18
30
|
"scripts": {
|
|
19
31
|
"build": "rbxtsc -p tsconfig.json",
|
|
32
|
+
"lint": "eslint .",
|
|
33
|
+
"lint:fix": "eslint . --fix",
|
|
20
34
|
"typecheck": "tsc -p tsconfig.typecheck.json",
|
|
21
35
|
"watch": "rbxtsc -p tsconfig.json -w"
|
|
22
36
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { React, Slot } from "@lattice-ui/core";
|
|
2
|
+
import { createFieldResponseRecipe, useResponseMotion } from "@lattice-ui/motion";
|
|
2
3
|
import { useTextFieldContext } from "./context";
|
|
3
4
|
import type { TextFieldInputProps } from "./types";
|
|
4
5
|
|
|
@@ -14,12 +15,24 @@ export function TextFieldInput(props: TextFieldInputProps) {
|
|
|
14
15
|
const textFieldContext = useTextFieldContext();
|
|
15
16
|
const disabled = textFieldContext.disabled || props.disabled === true;
|
|
16
17
|
const readOnly = textFieldContext.readOnly || props.readOnly === true;
|
|
18
|
+
const [focused, setFocused] = React.useState(false);
|
|
19
|
+
|
|
20
|
+
const active = focused && !disabled && !readOnly;
|
|
21
|
+
const localRef = useResponseMotion<TextBox>(
|
|
22
|
+
active,
|
|
23
|
+
{
|
|
24
|
+
active: { BackgroundColor3: Color3.fromRGB(35, 41, 54) },
|
|
25
|
+
inactive: { BackgroundColor3: Color3.fromRGB(39, 46, 61) },
|
|
26
|
+
},
|
|
27
|
+
createFieldResponseRecipe(),
|
|
28
|
+
);
|
|
17
29
|
|
|
18
30
|
const setInputRef = React.useCallback(
|
|
19
31
|
(instance: Instance | undefined) => {
|
|
32
|
+
localRef.current = toTextBox(instance);
|
|
20
33
|
textFieldContext.inputRef.current = toTextBox(instance);
|
|
21
34
|
},
|
|
22
|
-
[textFieldContext.inputRef],
|
|
35
|
+
[textFieldContext.inputRef, localRef],
|
|
23
36
|
);
|
|
24
37
|
|
|
25
38
|
const handleTextChanged = React.useCallback(
|
|
@@ -37,8 +50,13 @@ export function TextFieldInput(props: TextFieldInputProps) {
|
|
|
37
50
|
[disabled, readOnly, textFieldContext],
|
|
38
51
|
);
|
|
39
52
|
|
|
53
|
+
const handleFocused = React.useCallback(() => {
|
|
54
|
+
setFocused(true);
|
|
55
|
+
}, []);
|
|
56
|
+
|
|
40
57
|
const handleFocusLost = React.useCallback(
|
|
41
58
|
(textBox: TextBox) => {
|
|
59
|
+
setFocused(false);
|
|
42
60
|
if (disabled) {
|
|
43
61
|
return;
|
|
44
62
|
}
|
|
@@ -58,6 +76,7 @@ export function TextFieldInput(props: TextFieldInputProps) {
|
|
|
58
76
|
Text: handleTextChanged,
|
|
59
77
|
},
|
|
60
78
|
Event: {
|
|
79
|
+
Focused: handleFocused,
|
|
61
80
|
FocusLost: handleFocusLost,
|
|
62
81
|
},
|
|
63
82
|
ref: setInputRef,
|
|
@@ -75,7 +94,7 @@ export function TextFieldInput(props: TextFieldInputProps) {
|
|
|
75
94
|
return (
|
|
76
95
|
<textbox
|
|
77
96
|
{...sharedProps}
|
|
78
|
-
BackgroundColor3={Color3.fromRGB(39, 46, 61)}
|
|
97
|
+
BackgroundColor3={focused && !disabled && !readOnly ? Color3.fromRGB(47, 53, 68) : Color3.fromRGB(39, 46, 61)}
|
|
79
98
|
BorderSizePixel={0}
|
|
80
99
|
PlaceholderText="Type..."
|
|
81
100
|
Size={UDim2.fromOffset(240, 36)}
|
package/.turbo/turbo-build.log
DELETED
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "src",
|
|
5
|
-
"outDir": "out",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"typeRoots": [
|
|
8
|
-
"./node_modules/@rbxts",
|
|
9
|
-
"../../node_modules/@rbxts",
|
|
10
|
-
"./node_modules/@lattice-ui",
|
|
11
|
-
"../../node_modules/@lattice-ui"
|
|
12
|
-
],
|
|
13
|
-
"types": ["types", "compiler-types"]
|
|
14
|
-
},
|
|
15
|
-
"include": ["src"]
|
|
16
|
-
}
|
package/tsconfig.typecheck.json
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"noEmit": true,
|
|
5
|
-
"baseUrl": "..",
|
|
6
|
-
"rootDir": "..",
|
|
7
|
-
"paths": {
|
|
8
|
-
"@lattice-ui/accordion": ["accordion/src/index.ts"],
|
|
9
|
-
"@lattice-ui/avatar": ["avatar/src/index.ts"],
|
|
10
|
-
"@lattice-ui/checkbox": ["checkbox/src/index.ts"],
|
|
11
|
-
"@lattice-ui/combobox": ["combobox/src/index.ts"],
|
|
12
|
-
"@lattice-ui/core": ["core/src/index.ts"],
|
|
13
|
-
"@lattice-ui/dialog": ["dialog/src/index.ts"],
|
|
14
|
-
"@lattice-ui/focus": ["focus/src/index.ts"],
|
|
15
|
-
"@lattice-ui/layer": ["layer/src/index.ts"],
|
|
16
|
-
"@lattice-ui/menu": ["menu/src/index.ts"],
|
|
17
|
-
"@lattice-ui/popover": ["popover/src/index.ts"],
|
|
18
|
-
"@lattice-ui/popper": ["popper/src/index.ts"],
|
|
19
|
-
"@lattice-ui/progress": ["progress/src/index.ts"],
|
|
20
|
-
"@lattice-ui/radio-group": ["radio-group/src/index.ts"],
|
|
21
|
-
"@lattice-ui/scroll-area": ["scroll-area/src/index.ts"],
|
|
22
|
-
"@lattice-ui/select": ["select/src/index.ts"],
|
|
23
|
-
"@lattice-ui/slider": ["slider/src/index.ts"],
|
|
24
|
-
"@lattice-ui/style": ["style/src/index.ts"],
|
|
25
|
-
"@lattice-ui/switch": ["switch/src/index.ts"],
|
|
26
|
-
"@lattice-ui/system": ["system/src/index.ts"],
|
|
27
|
-
"@lattice-ui/tabs": ["tabs/src/index.ts"],
|
|
28
|
-
"@lattice-ui/text-field": ["text-field/src/index.ts"],
|
|
29
|
-
"@lattice-ui/textarea": ["textarea/src/index.ts"],
|
|
30
|
-
"@lattice-ui/toast": ["toast/src/index.ts"],
|
|
31
|
-
"@lattice-ui/toggle-group": ["toggle-group/src/index.ts"],
|
|
32
|
-
"@lattice-ui/tooltip": ["tooltip/src/index.ts"]
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|