@rbxts/uiblox 0.1.27 → 0.1.29
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/out/theme/styles/index.d.ts +1 -0
- package/out/theme/styles/types/ConditionalStylesMap.d.ts +2 -0
- package/out/theme/styles/types/ConditionalStylesMap.luau +2 -0
- package/out/theme/styles/types/index.d.ts +1 -0
- package/out/theme/styles/utilities/classNames.d.ts +2 -6
- package/out/theme/styles/utilities/classNames.luau +75 -32
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { ClassNameMap } from "./types/index";
|
|
2
2
|
export { WriteableStyle } from "./types/index";
|
|
3
|
+
export { ConditionalStylesMap } from "./types/index";
|
|
3
4
|
export { createStyles } from "./utilities/index";
|
|
4
5
|
export { makeStyles } from "./utilities/index";
|
|
5
6
|
export { classNames } from "./utilities/index";
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { WriteableStyle } from "../types/
|
|
2
|
-
|
|
3
|
-
[property: string]: boolean;
|
|
4
|
-
};
|
|
5
|
-
export type ConditionalStyles<T extends Instance> = Map<WriteableStyle<T>, boolean>;
|
|
6
|
-
declare function classNames<T extends Instance>(...args: [...Array<WriteableStyle<T>>, ConditionalStyles<T>] | [...Array<WriteableStyle<T>>]): WriteableStyle<T>;
|
|
1
|
+
import { WriteableStyle, ConditionalStylesMap } from "../types/index";
|
|
2
|
+
declare function classNames<T extends Instance>(...args: [...Array<WriteableStyle<T>>, ConditionalStylesMap<T>] | [...Array<WriteableStyle<T>>]): WriteableStyle<T>;
|
|
7
3
|
export default classNames;
|
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
-- Compiled with roblox-ts v3.0.0
|
|
2
|
-
|
|
2
|
+
local TS = _G[script]
|
|
3
3
|
local classNamesInternal = function(conditionalStyles, ...)
|
|
4
4
|
local styles = { ... }
|
|
5
5
|
local style = {}
|
|
6
|
+
-- ▼ ReadonlyArray.forEach ▼
|
|
7
|
+
local _callback = function(value)
|
|
8
|
+
if value ~= 0 and value == value and value ~= "" and value then
|
|
9
|
+
local _object = table.clone(style)
|
|
10
|
+
setmetatable(_object, nil)
|
|
11
|
+
for _k, _v in value do
|
|
12
|
+
_object[_k] = _v
|
|
13
|
+
end
|
|
14
|
+
style = _object
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
for _k, _v in styles do
|
|
18
|
+
_callback(_v, _k - 1, styles)
|
|
19
|
+
end
|
|
20
|
+
-- ▲ ReadonlyArray.forEach ▲
|
|
6
21
|
local _result = conditionalStyles
|
|
7
22
|
if _result ~= nil then
|
|
8
23
|
-- ▼ ReadonlyMap.forEach ▼
|
|
9
|
-
local
|
|
24
|
+
local _callback_1 = function(value, key)
|
|
10
25
|
if value then
|
|
11
26
|
local _object = table.clone(style)
|
|
12
27
|
setmetatable(_object, nil)
|
|
@@ -17,25 +32,10 @@ local classNamesInternal = function(conditionalStyles, ...)
|
|
|
17
32
|
end
|
|
18
33
|
end
|
|
19
34
|
for _k, _v in _result do
|
|
20
|
-
|
|
35
|
+
_callback_1(_v, _k, _result)
|
|
21
36
|
end
|
|
22
37
|
-- ▲ ReadonlyMap.forEach ▲
|
|
23
38
|
end
|
|
24
|
-
-- ▼ ReadonlyArray.forEach ▼
|
|
25
|
-
local _callback = function(value)
|
|
26
|
-
if value ~= 0 and value == value and value ~= "" and value then
|
|
27
|
-
local _object = table.clone(style)
|
|
28
|
-
setmetatable(_object, nil)
|
|
29
|
-
for _k, _v in value do
|
|
30
|
-
_object[_k] = _v
|
|
31
|
-
end
|
|
32
|
-
style = _object
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
for _k, _v in styles do
|
|
36
|
-
_callback(_v, _k - 1, styles)
|
|
37
|
-
end
|
|
38
|
-
-- ▲ ReadonlyArray.forEach ▲
|
|
39
39
|
local _object = table.clone(style)
|
|
40
40
|
setmetatable(_object, nil)
|
|
41
41
|
return _object
|
|
@@ -45,23 +45,66 @@ local function classNames(...)
|
|
|
45
45
|
local args = { ... }
|
|
46
46
|
-- Check if last argument is ConditionalStyles
|
|
47
47
|
local hasConditionalStyles = function(args)
|
|
48
|
-
local
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
local _exitType, _returns = TS.try(function()
|
|
49
|
+
local lastArg = args[#args]
|
|
50
|
+
-- If the last argument is undefined or not a table then its not a ConditionalStyles<T>
|
|
51
|
+
-- Map<K, V> compiles to a table literal (ref: https://roblox-ts.com/docs/api/constructors)
|
|
52
|
+
if lastArg == nil or not (type(lastArg) == "table") then
|
|
53
|
+
return TS.TRY_RETURN, { false }
|
|
54
|
+
end
|
|
55
|
+
local lastArgAsConditionalStylesMap = lastArg
|
|
56
|
+
local matchesMapFormat = true
|
|
57
|
+
local _result = lastArgAsConditionalStylesMap
|
|
58
|
+
if _result ~= nil then
|
|
59
|
+
-- ▼ ReadonlyMap.forEach ▼
|
|
60
|
+
local _callback = function(value, key)
|
|
61
|
+
-- Assume that the last argument is a ConditionalStyles<T> with correct format (Map<WriteableStyle<T>, boolean>)
|
|
62
|
+
-- If the key is not a WriteableStyle<T> then it does not match the format
|
|
63
|
+
-- If the value is not a boolean then it does not match the format
|
|
64
|
+
local _value = value
|
|
65
|
+
local _condition = not (type(_value) == "boolean")
|
|
66
|
+
if not _condition then
|
|
67
|
+
local _key = key
|
|
68
|
+
_condition = not (type(_key) == "table")
|
|
69
|
+
end
|
|
70
|
+
if _condition then
|
|
71
|
+
matchesMapFormat = false
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
for _k, _v in _result do
|
|
75
|
+
_callback(_v, _k, _result)
|
|
76
|
+
end
|
|
77
|
+
-- ▲ ReadonlyMap.forEach ▲
|
|
78
|
+
end
|
|
79
|
+
return TS.TRY_RETURN, { matchesMapFormat }
|
|
80
|
+
end, function()
|
|
81
|
+
-- If we catch an error, it means that the last argument is not a ConditionalStyles<T>
|
|
82
|
+
return TS.TRY_RETURN, { false }
|
|
83
|
+
end)
|
|
84
|
+
if _exitType then
|
|
85
|
+
return unpack(_returns)
|
|
51
86
|
end
|
|
52
|
-
return type(lastArg) == "table"
|
|
53
87
|
end
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
88
|
+
local _exitType, _returns = TS.try(function()
|
|
89
|
+
if hasConditionalStyles(args) then
|
|
90
|
+
-- Handle case with ConditionalStyles
|
|
91
|
+
-- ▼ Array.pop ▼
|
|
92
|
+
local _length = #args
|
|
93
|
+
local _result = args[_length]
|
|
94
|
+
args[_length] = nil
|
|
95
|
+
-- ▲ Array.pop ▲
|
|
96
|
+
local conditionalStyles = _result
|
|
97
|
+
local styles = args
|
|
98
|
+
-- ConditionalStyles<T> is the last argument
|
|
99
|
+
return TS.TRY_RETURN, { classNamesInternal(conditionalStyles, unpack(styles)) }
|
|
100
|
+
end
|
|
101
|
+
end, function()
|
|
102
|
+
-- If we catch an error, like attempt to iterate over a string value, it means that the last argument is not a ConditionalStyles<T>
|
|
62
103
|
local styles = args
|
|
63
|
-
|
|
64
|
-
|
|
104
|
+
return TS.TRY_RETURN, { classNamesInternal(nil, unpack(styles)) }
|
|
105
|
+
end)
|
|
106
|
+
if _exitType then
|
|
107
|
+
return unpack(_returns)
|
|
65
108
|
end
|
|
66
109
|
-- Handle case without ConditionalStyles
|
|
67
110
|
-- All args are WriteableStyle<T>
|