@rbxts/react-clean-ui 1.0.10 → 1.0.12

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.
@@ -70,7 +70,6 @@ local function Toast(_param)
70
70
  duration = TOAST_FADE_DURATION,
71
71
  easing = "quadOut",
72
72
  })
73
- React.useEffect(function() end)
74
73
  React.useEffect(function()
75
74
  dismissRef.current = onDismiss
76
75
  end, { onDismiss })
@@ -14,12 +14,41 @@ local _Helpers = TS.import(script, script.Parent.Parent.Parent, "Helpers")
14
14
  local ColorHelper = _Helpers.ColorHelper
15
15
  local CssHelper = _Helpers.CssHelper
16
16
  local SpacingHelper = _Helpers.SpacingHelper
17
+ local useTween = TS.import(script, TS.getModule(script, "@rbxts", "react-ripple").src).useTween
17
18
  local function TooltipPopup(props)
18
19
  local theme = React.useContext(CleanThemeContext)
20
+ local groupTransparency, transparencyTween = useTween(1, {
21
+ duration = props.fadeDuration,
22
+ easing = "quadOut",
23
+ })
24
+ React.useEffect(function()
25
+ transparencyTween:setGoal(if props.visible then 0 else 1)
26
+ end, { props.visible, transparencyTween })
27
+ local resolvedPadding = {
28
+ top = 0,
29
+ bottom = 0,
30
+ left = 0,
31
+ right = 0,
32
+ }
33
+ local _value = theme.components.tooltip.boxShadow
34
+ local shadow = if _value ~= 0 and _value == _value and _value ~= "" and _value then CssHelper:parseCssShadow(theme.components.tooltip.boxShadow) else nil
35
+ if shadow ~= nil then
36
+ resolvedPadding.top += shadow.blurRadius.Offset + shadow.spread.Y.Offset - shadow.offset.Y.Offset
37
+ resolvedPadding.bottom += shadow.blurRadius.Offset + shadow.spread.Y.Offset + shadow.offset.Y.Offset
38
+ resolvedPadding.left += shadow.blurRadius.Offset + shadow.spread.X.Offset - shadow.offset.X.Offset
39
+ resolvedPadding.right += shadow.blurRadius.Offset + shadow.spread.X.Offset + shadow.offset.X.Offset
40
+ end
41
+ local pointerSize = theme.components.tooltip.pointerSize
19
42
  local anchor = Vector2.zero
20
43
  local _position = props.target.position
21
44
  local _absolutePosition = props.overlay.AbsolutePosition
22
45
  local position = _position - _absolutePosition
46
+ local pointerRotation = 45
47
+ local pointerAnchor = Vector2.new(0.5, 1)
48
+ local pointerPosition = UDim2.new(0.5, 0, 1, 0)
49
+ local factor = 1.41421356
50
+ local pointerHeight = (factor * pointerSize) / 2
51
+ local pointerDiff = pointerHeight - (pointerSize / 2)
23
52
  local _exp = props.placement or "Top"
24
53
  repeat
25
54
  if _exp == "Top" then
@@ -27,6 +56,8 @@ local function TooltipPopup(props)
27
56
  local _position_1 = position
28
57
  local _vector2 = Vector2.new(props.target.size.X / 2, 0)
29
58
  position = _position_1 + _vector2
59
+ pointerPosition = UDim2.new(0.5, (resolvedPadding.left - resolvedPadding.right) / 2, 1, -math.max(math.ceil(pointerDiff), resolvedPadding.bottom - pointerDiff))
60
+ resolvedPadding.bottom = math.max(math.floor(pointerHeight), resolvedPadding.bottom)
30
61
  break
31
62
  end
32
63
  if _exp == "Bottom" then
@@ -34,6 +65,10 @@ local function TooltipPopup(props)
34
65
  local _position_1 = position
35
66
  local _vector2 = Vector2.new(props.target.size.X / 2, props.target.size.Y)
36
67
  position = _position_1 + _vector2
68
+ pointerAnchor = Vector2.new(0.5, 0)
69
+ pointerRotation = -135
70
+ pointerPosition = UDim2.new(0.5, (resolvedPadding.left - resolvedPadding.right) / 2, 0, math.max(math.ceil(pointerDiff), resolvedPadding.top - pointerDiff))
71
+ resolvedPadding.top = math.max(math.floor(pointerHeight), resolvedPadding.top)
37
72
  break
38
73
  end
39
74
  if _exp == "Left" then
@@ -41,6 +76,10 @@ local function TooltipPopup(props)
41
76
  local _position_1 = position
42
77
  local _vector2 = Vector2.new(0, props.target.size.Y / 2)
43
78
  position = _position_1 + _vector2
79
+ pointerRotation = -45
80
+ pointerAnchor = Vector2.new(1, 0.5)
81
+ pointerPosition = UDim2.new(1, -math.max(math.ceil(pointerDiff), resolvedPadding.right - pointerDiff), 0.5, 0)
82
+ resolvedPadding.right = math.max(math.floor(pointerHeight), resolvedPadding.right)
44
83
  break
45
84
  end
46
85
  if _exp == "Right" then
@@ -48,24 +87,21 @@ local function TooltipPopup(props)
48
87
  local _position_1 = position
49
88
  local _vector2 = Vector2.new(props.target.size.X, props.target.size.Y / 2)
50
89
  position = _position_1 + _vector2
90
+ pointerRotation = 135
91
+ pointerAnchor = Vector2.new(0, 0.5)
92
+ pointerPosition = UDim2.new(0, math.max(math.ceil(pointerDiff), resolvedPadding.left - pointerDiff), 0.5, 0)
93
+ resolvedPadding.left = math.max(math.floor(pointerHeight), resolvedPadding.left)
51
94
  break
52
95
  end
53
96
  until true
54
97
  local intent = ColorHelper:getIntentColors(theme, props.intent, "default", theme.components.tooltip.intents)
55
- local _value = theme.components.tooltip.boxShadow
56
- local shadow = if _value ~= 0 and _value == _value and _value ~= "" and _value then CssHelper:parseCssShadow(theme.components.tooltip.boxShadow) else nil
57
98
  local padding = SpacingHelper:ResolveNumberPadding(SpacingHelper:GetPadding(theme, props.spacing, theme.components.tooltip.spacing))
58
- local _exp_1 = shadow ~= nil and React.createElement(Padding, {
59
- resolvedPadding = {
60
- top = shadow.blurRadius.Offset + shadow.spread.Y.Offset - shadow.offset.Y.Offset,
61
- bottom = shadow.blurRadius.Offset + shadow.spread.Y.Offset + shadow.offset.Y.Offset,
62
- left = shadow.blurRadius.Offset + shadow.spread.X.Offset - shadow.offset.X.Offset,
63
- right = shadow.blurRadius.Offset + shadow.spread.X.Offset + shadow.offset.X.Offset,
64
- },
99
+ local _exp_1 = React.createElement(Padding, {
100
+ resolvedPadding = resolvedPadding,
65
101
  })
66
102
  local _attributes = table.clone(props)
67
103
  setmetatable(_attributes, nil)
68
- _attributes.value = theme.components.box.boxShadow
104
+ _attributes.value = theme.components.tooltip.boxShadow
69
105
  local _exp_2 = React.createElement(BoxShadow, _attributes)
70
106
  local _exp_3 = React.createElement(Corners, {
71
107
  radius = theme.components.button.cornerRadius,
@@ -87,6 +123,11 @@ local function TooltipPopup(props)
87
123
  return React.createElement("canvasgroup", {
88
124
  Position = UDim2.fromOffset(position.X, position.Y),
89
125
  AnchorPoint = anchor,
126
+ Size = UDim2.fromOffset(0, 0),
127
+ AutomaticSize = Enum.AutomaticSize.XY,
128
+ GroupTransparency = groupTransparency,
129
+ BackgroundTransparency = 1,
130
+ }, React.createElement("frame", {
90
131
  Size = UDim2.fromOffset(0, 0),
91
132
  AutomaticSize = Enum.AutomaticSize.XY,
92
133
  BackgroundTransparency = 1,
@@ -98,12 +139,29 @@ local function TooltipPopup(props)
98
139
  }, _exp_2, _exp_3, _exp_4, _exp_5, if type(_content) == "string" then React.createElement(Text, {
99
140
  text = props.content,
100
141
  TextColor3 = intent.textColor,
101
- }) else props.content))
142
+ }) else props.content)), pointerSize > 0 and React.createElement("frame", {
143
+ Size = UDim2.fromOffset(pointerSize, pointerSize),
144
+ AnchorPoint = pointerAnchor,
145
+ Position = pointerPosition,
146
+ BorderSizePixel = 1,
147
+ BackgroundColor3 = intent.backgroundColor,
148
+ BorderColor3 = props["border-color"] or intent.borderColor,
149
+ BackgroundTransparency = intent.backgroundTransparency,
150
+ Rotation = 45,
151
+ }, React.createElement("uigradient", {
152
+ Transparency = NumberSequence.new({ NumberSequenceKeypoint.new(0, 1), NumberSequenceKeypoint.new(0.4999, 1), NumberSequenceKeypoint.new(0.5, 0), NumberSequenceKeypoint.new(1, 0) }),
153
+ Rotation = pointerRotation,
154
+ })))
102
155
  end
103
156
  local function Tooltip(props)
104
157
  local targetRef = React.useRef()
158
+ local hideRequest = React.useRef(0)
105
159
  local target, setTarget = React.useState()
160
+ local visible, setVisible = React.useState(false)
161
+ local theme = React.useContext(CleanThemeContext)
162
+ local fadeDuration = theme.components.tooltip.fadeDuration
106
163
  local show = function()
164
+ hideRequest.current += 1
107
165
  local _result = targetRef.current
108
166
  if _result ~= nil then
109
167
  _result = _result.AbsolutePosition
@@ -124,9 +182,22 @@ local function Tooltip(props)
124
182
  _object[_left_1] = _result_2
125
183
  setTarget(_object)
126
184
  end
185
+ setVisible(true)
127
186
  end
128
187
  local hide = function()
129
- setTarget(nil)
188
+ setVisible(false)
189
+ local request = hideRequest.current + 1
190
+ hideRequest.current = request
191
+ if fadeDuration <= 0 then
192
+ setTarget(nil)
193
+ return nil
194
+ end
195
+ task.delay(fadeDuration, function()
196
+ -- Do not remove it if the tooltip was shown again.
197
+ if hideRequest.current == request then
198
+ setTarget(nil)
199
+ end
200
+ end)
130
201
  end
131
202
  local _exp = props.children
132
203
  local _object = {
@@ -167,10 +238,15 @@ local function Tooltip(props)
167
238
  if overlay == nil then
168
239
  return nil
169
240
  end
170
- local _attributes = table.clone(props)
171
- setmetatable(_attributes, nil)
241
+ local _attributes = {
242
+ fadeDuration = fadeDuration,
243
+ }
244
+ for _k, _v in props do
245
+ _attributes[_k] = _v
246
+ end
172
247
  _attributes.overlay = overlay
173
248
  _attributes.target = target
249
+ _attributes.visible = visible
174
250
  return ReactRoblox.createPortal(React.createElement(TooltipPopup, _attributes), overlay)
175
251
  end,
176
252
  })))
@@ -1,4 +1,4 @@
1
- export * from './theme.template';
1
+ export type * from './theme.template';
2
2
  export * from './theme.factory';
3
3
  export * from './icons.default';
4
4
  export * from './themes/';
@@ -1,9 +1,6 @@
1
1
  -- Compiled with roblox-ts v3.0.0
2
2
  local TS = _G[script]
3
3
  local exports = {}
4
- for _k, _v in TS.import(script, script, "theme.template") or {} do
5
- exports[_k] = _v
6
- end
7
4
  for _k, _v in TS.import(script, script, "theme.factory") or {} do
8
5
  exports[_k] = _v
9
6
  end
@@ -181,6 +181,8 @@ export interface CleanTheme {
181
181
  };
182
182
  };
183
183
  tooltip: {
184
+ fadeDuration: number;
185
+ pointerSize: number;
184
186
  spacing?: ScaleSizeValue<number>;
185
187
  boxShadow?: CssShadow;
186
188
  cornerRadius: CssSize;
@@ -442,6 +442,8 @@ local DefaultTheme = {
442
442
  },
443
443
  },
444
444
  tooltip = {
445
+ fadeDuration = 0.25,
446
+ pointerSize = 10,
445
447
  spacing = {
446
448
  xs = 2,
447
449
  sm = 6,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/react-clean-ui",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "",
5
5
  "main": "out/init.lua",
6
6
  "scripts": {