@rbxts/uiblox 0.1.23 → 0.1.26

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.
@@ -3,5 +3,5 @@ export type GenericStyle = {
3
3
  [property: string]: boolean;
4
4
  };
5
5
  export type ConditionalStyles<T extends Instance> = Map<WriteableStyle<T>, boolean>;
6
- declare const classNames: <T extends Instance>(conditionalStyles?: ConditionalStyles<T>, ...styles: Array<WriteableStyle<T>>) => WriteableStyle<T>;
6
+ declare function classNames<T extends Instance>(...args: [...Array<WriteableStyle<T>>, ConditionalStyles<T>] | [...Array<WriteableStyle<T>>]): WriteableStyle<T>;
7
7
  export default classNames;
@@ -1,8 +1,7 @@
1
1
  -- Compiled with roblox-ts v3.0.0
2
2
  -- eslint-disable-next-line @typescript-eslint/no-explicit-any
3
- local classNames = function(conditionalStyles, ...)
3
+ local classNamesInternal = function(conditionalStyles, ...)
4
4
  local styles = { ... }
5
- -- eslint-disable-next-line @typescript-eslint/no-explicit-any
6
5
  local style = {}
7
6
  local _result = conditionalStyles
8
7
  if _result ~= nil then
@@ -41,6 +40,34 @@ local classNames = function(conditionalStyles, ...)
41
40
  setmetatable(_object, nil)
42
41
  return _object
43
42
  end
43
+ -- Use variadic tuple types to allow for multiple WriteableStyle<T> arguments with an optional ConditionalStyles<T> argument at the end
44
+ local function classNames(...)
45
+ local args = { ... }
46
+ -- Check if last argument is ConditionalStyles
47
+ local hasConditionalStyles = function(args)
48
+ local lastArg = args[#args]
49
+ if lastArg == nil then
50
+ return false
51
+ end
52
+ return type(lastArg) == "table"
53
+ end
54
+ if hasConditionalStyles(args) then
55
+ -- Handle case with ConditionalStyles
56
+ -- ▼ Array.pop ▼
57
+ local _length = #args
58
+ local _result = args[_length]
59
+ args[_length] = nil
60
+ -- ▲ Array.pop ▲
61
+ local conditionalStyles = _result
62
+ local styles = args
63
+ -- ConditionalStyles<T> is the last argument
64
+ return classNamesInternal(conditionalStyles, unpack(styles))
65
+ end
66
+ -- Handle case without ConditionalStyles
67
+ -- All args are WriteableStyle<T>
68
+ local styles = args
69
+ return classNamesInternal(nil, unpack(styles))
70
+ end
44
71
  local default = classNames
45
72
  return {
46
73
  default = default,
@@ -4,6 +4,7 @@ local _react = TS.import(script, TS.getModule(script, "@rbxts", "react"))
4
4
  local React = _react
5
5
  local useState = _react.useState
6
6
  local useMemo = _react.useMemo
7
+ local useEffect = _react.useEffect
7
8
  local _pretty_react_hooks = TS.import(script, TS.getModule(script, "@rbxts", "pretty-react-hooks").out)
8
9
  local useAsyncEffect = _pretty_react_hooks.useAsyncEffect
9
10
  local useDeferState = _pretty_react_hooks.useDeferState
@@ -77,15 +78,16 @@ local function Preloader(props)
77
78
  local _assetId = assetId
78
79
  setCurrentAsset(contentNamesById[_assetId])
79
80
  setPercentage(function(prev)
80
- local newPercentage = math.clamp(prev + unit, 0, 100)
81
- if math.round(newPercentage) >= 100 then
82
- setLoaded(true)
83
- end
84
- return newPercentage
81
+ return math.clamp(prev + unit, 0, 100)
85
82
  end)
86
83
  end)
87
84
  setCurrentAsset(nil)
88
85
  end), {})
86
+ useEffect(function()
87
+ if math.round(percentage) >= 100 then
88
+ setLoaded(true)
89
+ end
90
+ end, { percentage })
89
91
  local percentageStr = useMemo(function()
90
92
  if not showPercentage then
91
93
  return nil
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/uiblox",
3
- "version": "0.1.23",
3
+ "version": "0.1.26",
4
4
  "description": "UI Library and theming for roblox-ts projects",
5
5
  "main": "out/init.lua",
6
6
  "scripts": {