@lattice-ui/progress 0.3.1 → 0.4.0
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.
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
-- Compiled with roblox-ts v3.0.0
|
|
2
2
|
local TS = _G[script]
|
|
3
|
-
local
|
|
4
|
-
local React = _core.React
|
|
5
|
-
local Slot = _core.Slot
|
|
3
|
+
local React = TS.import(script, TS.getModule(script, "@lattice-ui", "core").out).React
|
|
6
4
|
local useProgressContext = TS.import(script, script.Parent, "context").useProgressContext
|
|
5
|
+
local function toGuiPropBag(value)
|
|
6
|
+
local _value = value
|
|
7
|
+
return if type(_value) == "table" then value else {}
|
|
8
|
+
end
|
|
7
9
|
local function ProgressIndicator(props)
|
|
8
10
|
local progressContext = useProgressContext()
|
|
9
11
|
local widthScale = if progressContext.indeterminate then 0.35 else progressContext.ratio
|
|
10
|
-
local xScale = if progressContext.indeterminate then 0 else 0
|
|
11
12
|
if props.asChild then
|
|
12
13
|
local child = props.children
|
|
13
14
|
if not child then
|
|
14
15
|
error("[ProgressIndicator] `asChild` requires a child element.")
|
|
15
16
|
end
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
local childProps = toGuiPropBag(child.props)
|
|
18
|
+
local _object = table.clone(childProps)
|
|
19
|
+
setmetatable(_object, nil)
|
|
20
|
+
_object.Position = UDim2.fromScale(0, 0)
|
|
21
|
+
_object.Size = UDim2.fromScale(widthScale, 1)
|
|
22
|
+
local mergedProps = _object
|
|
23
|
+
return React.cloneElement(child, mergedProps)
|
|
20
24
|
end
|
|
21
25
|
return React.createElement("frame", {
|
|
22
26
|
BackgroundColor3 = Color3.fromRGB(102, 156, 255),
|
|
23
27
|
BorderSizePixel = 0,
|
|
24
|
-
Position = UDim2.fromScale(
|
|
28
|
+
Position = UDim2.fromScale(0, 0),
|
|
25
29
|
Size = UDim2.fromScale(widthScale, 1),
|
|
26
30
|
}, props.children)
|
|
27
31
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
-- Compiled with roblox-ts v3.0.0
|
|
2
2
|
local TS = _G[script]
|
|
3
3
|
local _core = TS.import(script, TS.getModule(script, "@lattice-ui", "core").out)
|
|
4
|
+
local composeRefs = _core.composeRefs
|
|
4
5
|
local React = _core.React
|
|
5
|
-
local Slot = _core.Slot
|
|
6
6
|
local RunService = game:GetService("RunService")
|
|
7
7
|
local function toGuiObject(instance)
|
|
8
8
|
if not instance or not instance:IsA("GuiObject") then
|
|
@@ -10,6 +10,24 @@ local function toGuiObject(instance)
|
|
|
10
10
|
end
|
|
11
11
|
return instance
|
|
12
12
|
end
|
|
13
|
+
local function toGuiPropBag(value)
|
|
14
|
+
local _value = value
|
|
15
|
+
return if type(_value) == "table" then value else {}
|
|
16
|
+
end
|
|
17
|
+
local function toInstanceRef(value)
|
|
18
|
+
if value == nil then
|
|
19
|
+
return nil
|
|
20
|
+
end
|
|
21
|
+
local _value = value
|
|
22
|
+
if type(_value) == "function" then
|
|
23
|
+
return value
|
|
24
|
+
end
|
|
25
|
+
local _value_1 = value
|
|
26
|
+
if type(_value_1) == "table" then
|
|
27
|
+
return value
|
|
28
|
+
end
|
|
29
|
+
return nil
|
|
30
|
+
end
|
|
13
31
|
local function Spinner(props)
|
|
14
32
|
local _condition = props.spinning
|
|
15
33
|
if _condition == nil then
|
|
@@ -45,10 +63,13 @@ local function Spinner(props)
|
|
|
45
63
|
if not child then
|
|
46
64
|
error("[Spinner] `asChild` requires a child element.")
|
|
47
65
|
end
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
66
|
+
local childProps = toGuiPropBag(child.props)
|
|
67
|
+
local _object = table.clone(childProps)
|
|
68
|
+
setmetatable(_object, nil)
|
|
69
|
+
_object.Visible = spinning
|
|
70
|
+
_object.ref = composeRefs(toInstanceRef(childProps.ref), setSpinnerRef)
|
|
71
|
+
local mergedProps = _object
|
|
72
|
+
return React.cloneElement(child, mergedProps)
|
|
52
73
|
end
|
|
53
74
|
return React.createElement("frame", {
|
|
54
75
|
BackgroundTransparency = 1,
|
|
@@ -61,7 +82,16 @@ local function Spinner(props)
|
|
|
61
82
|
}), React.createElement("uistroke", {
|
|
62
83
|
Color = Color3.fromRGB(102, 156, 255),
|
|
63
84
|
Thickness = 2,
|
|
64
|
-
|
|
85
|
+
Transparency = 0.35,
|
|
86
|
+
}), React.createElement("frame", {
|
|
87
|
+
AnchorPoint = Vector2.new(0.5, 0.5),
|
|
88
|
+
BackgroundColor3 = Color3.fromRGB(102, 156, 255),
|
|
89
|
+
BorderSizePixel = 0,
|
|
90
|
+
Position = UDim2.fromScale(0.5, 0.1),
|
|
91
|
+
Size = UDim2.fromOffset(4, 4),
|
|
92
|
+
}, React.createElement("uicorner", {
|
|
93
|
+
CornerRadius = UDim.new(1, 0),
|
|
94
|
+
})))
|
|
65
95
|
end
|
|
66
96
|
return {
|
|
67
97
|
Spinner = Spinner,
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lattice-ui/progress",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "out/init.luau",
|
|
6
6
|
"types": "out/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@lattice-ui/core": "0.
|
|
8
|
+
"@lattice-ui/core": "0.4.0"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@rbxts/react": "17.3.7-ts.1",
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { React
|
|
1
|
+
import { React } from "@lattice-ui/core";
|
|
2
2
|
import { useProgressContext } from "./context";
|
|
3
3
|
import type { ProgressIndicatorProps } from "./types";
|
|
4
4
|
|
|
5
|
+
type GuiPropBag = React.Attributes & Record<string, unknown>;
|
|
6
|
+
|
|
7
|
+
function toGuiPropBag(value: unknown): GuiPropBag {
|
|
8
|
+
return typeIs(value, "table") ? (value as GuiPropBag) : {};
|
|
9
|
+
}
|
|
10
|
+
|
|
5
11
|
export function ProgressIndicator(props: ProgressIndicatorProps) {
|
|
6
12
|
const progressContext = useProgressContext();
|
|
7
13
|
|
|
8
14
|
const widthScale = progressContext.indeterminate ? 0.35 : progressContext.ratio;
|
|
9
|
-
const xScale = progressContext.indeterminate ? 0 : 0;
|
|
10
15
|
|
|
11
16
|
if (props.asChild) {
|
|
12
17
|
const child = props.children;
|
|
@@ -14,18 +19,21 @@ export function ProgressIndicator(props: ProgressIndicatorProps) {
|
|
|
14
19
|
error("[ProgressIndicator] `asChild` requires a child element.");
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
const childProps = toGuiPropBag((child as { props?: unknown }).props);
|
|
23
|
+
const mergedProps: GuiPropBag = {
|
|
24
|
+
...childProps,
|
|
25
|
+
Position: UDim2.fromScale(0, 0),
|
|
26
|
+
Size: UDim2.fromScale(widthScale, 1),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return React.cloneElement(child as React.ReactElement<GuiPropBag>, mergedProps);
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
return (
|
|
25
33
|
<frame
|
|
26
34
|
BackgroundColor3={Color3.fromRGB(102, 156, 255)}
|
|
27
35
|
BorderSizePixel={0}
|
|
28
|
-
Position={UDim2.fromScale(
|
|
36
|
+
Position={UDim2.fromScale(0, 0)}
|
|
29
37
|
Size={UDim2.fromScale(widthScale, 1)}
|
|
30
38
|
>
|
|
31
39
|
{props.children}
|
package/src/Progress/Spinner.tsx
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { composeRefs, React } from "@lattice-ui/core";
|
|
2
|
+
import type ReactTypes from "@rbxts/react";
|
|
2
3
|
import type { SpinnerProps } from "./types";
|
|
3
4
|
|
|
4
5
|
const RunService = game.GetService("RunService");
|
|
5
6
|
|
|
7
|
+
type GuiPropBag = React.Attributes & Record<string, unknown>;
|
|
8
|
+
|
|
6
9
|
function toGuiObject(instance: Instance | undefined) {
|
|
7
10
|
if (!instance || !instance.IsA("GuiObject")) {
|
|
8
11
|
return undefined;
|
|
@@ -11,6 +14,26 @@ function toGuiObject(instance: Instance | undefined) {
|
|
|
11
14
|
return instance;
|
|
12
15
|
}
|
|
13
16
|
|
|
17
|
+
function toGuiPropBag(value: unknown): GuiPropBag {
|
|
18
|
+
return typeIs(value, "table") ? (value as GuiPropBag) : {};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function toInstanceRef(value: unknown): ReactTypes.Ref<Instance> | undefined {
|
|
22
|
+
if (value === undefined) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (typeIs(value, "function")) {
|
|
27
|
+
return value as (instance: Instance | undefined) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (typeIs(value, "table")) {
|
|
31
|
+
return value as ReactTypes.MutableRefObject<Instance | undefined>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
14
37
|
export function Spinner(props: SpinnerProps) {
|
|
15
38
|
const spinning = props.spinning ?? true;
|
|
16
39
|
const speedDegPerSecond = props.speedDegPerSecond ?? 180;
|
|
@@ -46,11 +69,14 @@ export function Spinner(props: SpinnerProps) {
|
|
|
46
69
|
error("[Spinner] `asChild` requires a child element.");
|
|
47
70
|
}
|
|
48
71
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
72
|
+
const childProps = toGuiPropBag((child as { props?: unknown }).props);
|
|
73
|
+
const mergedProps: GuiPropBag = {
|
|
74
|
+
...childProps,
|
|
75
|
+
Visible: spinning,
|
|
76
|
+
ref: composeRefs(toInstanceRef((childProps as { ref?: unknown }).ref), setSpinnerRef),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return React.cloneElement(child as React.ReactElement<GuiPropBag>, mergedProps);
|
|
54
80
|
}
|
|
55
81
|
|
|
56
82
|
return (
|
|
@@ -62,7 +88,16 @@ export function Spinner(props: SpinnerProps) {
|
|
|
62
88
|
ref={setSpinnerRef}
|
|
63
89
|
>
|
|
64
90
|
<uicorner CornerRadius={new UDim(1, 0)} />
|
|
65
|
-
<uistroke Color={Color3.fromRGB(102, 156, 255)} Thickness={2} />
|
|
91
|
+
<uistroke Color={Color3.fromRGB(102, 156, 255)} Thickness={2} Transparency={0.35} />
|
|
92
|
+
<frame
|
|
93
|
+
AnchorPoint={new Vector2(0.5, 0.5)}
|
|
94
|
+
BackgroundColor3={Color3.fromRGB(102, 156, 255)}
|
|
95
|
+
BorderSizePixel={0}
|
|
96
|
+
Position={UDim2.fromScale(0.5, 0.1)}
|
|
97
|
+
Size={UDim2.fromOffset(4, 4)}
|
|
98
|
+
>
|
|
99
|
+
<uicorner CornerRadius={new UDim(1, 0)} />
|
|
100
|
+
</frame>
|
|
66
101
|
</frame>
|
|
67
102
|
);
|
|
68
103
|
}
|