@lattice-ui/tabs 0.5.0-next.1 → 0.5.0-next.2

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.
@@ -6,7 +6,7 @@ local Slot = _core.Slot
6
6
  local Presence = TS.import(script, TS.getModule(script, "@lattice-ui", "layer").out).Presence
7
7
  local _motion = TS.import(script, TS.getModule(script, "@lattice-ui", "motion").out)
8
8
  local createSurfaceRevealRecipe = _motion.createSurfaceRevealRecipe
9
- local usePresenceMotion = _motion.usePresenceMotion
9
+ local usePresenceMotionController = _motion.usePresenceMotionController
10
10
  local useTabsContext = TS.import(script, script.Parent, "context").useTabsContext
11
11
  local createTabsContentName = TS.import(script, script.Parent, "internals", "ids").createTabsContentName
12
12
  local function TabsContentImpl(props)
@@ -20,7 +20,17 @@ local function TabsContentImpl(props)
20
20
  end
21
21
  return props.transition
22
22
  end, { defaultTransition, props.transition })
23
- local motionRef = usePresenceMotion(props.motionPresent, config, props.onExitComplete)
23
+ local motion = usePresenceMotionController({
24
+ present = props.present,
25
+ forceMount = props.forceMount,
26
+ config = config,
27
+ onExitComplete = props.onExitComplete,
28
+ })
29
+ local mounted = motion.mounted
30
+ local visible = mounted and (motion.present or motion.phase ~= "exited")
31
+ if not mounted then
32
+ return nil
33
+ end
24
34
  if props.asChild then
25
35
  local child = props.children
26
36
  if not React.isValidElement(child) then
@@ -28,16 +38,16 @@ local function TabsContentImpl(props)
28
38
  end
29
39
  return React.createElement(Slot, {
30
40
  Name = contentName,
31
- Visible = props.visible,
32
- ref = motionRef,
41
+ Visible = visible,
42
+ ref = motion.ref,
33
43
  }, child)
34
44
  end
35
45
  return React.createElement("frame", {
36
46
  BackgroundTransparency = 1,
37
47
  BorderSizePixel = 0,
38
48
  Size = UDim2.fromOffset(0, 0),
39
- Visible = props.visible,
40
- ref = motionRef,
49
+ Visible = visible,
50
+ ref = motion.ref,
41
51
  }, props.children)
42
52
  end
43
53
  local function TabsContent(props)
@@ -47,10 +57,10 @@ local function TabsContent(props)
47
57
  if forceMount then
48
58
  return React.createElement(TabsContentImpl, {
49
59
  asChild = props.asChild,
50
- motionPresent = selected,
60
+ forceMount = true,
61
+ present = selected,
51
62
  transition = props.transition,
52
63
  value = props.value,
53
- visible = selected,
54
64
  }, props.children)
55
65
  end
56
66
  return React.createElement(Presence, {
@@ -58,11 +68,10 @@ local function TabsContent(props)
58
68
  render = function(state)
59
69
  return React.createElement(TabsContentImpl, {
60
70
  asChild = props.asChild,
61
- motionPresent = state.isPresent,
62
71
  onExitComplete = state.onExitComplete,
72
+ present = state.isPresent,
63
73
  transition = props.transition,
64
74
  value = props.value,
65
- visible = true,
66
75
  }, props.children)
67
76
  end,
68
77
  })
@@ -23,9 +23,7 @@ local function TabsTrigger(props)
23
23
  local selected = tabsContext.value == props.value
24
24
  local disabled = props.disabled == true
25
25
  local disabledRef = React.useRef(disabled)
26
- React.useEffect(function()
27
- disabledRef.current = disabled
28
- end, { disabled })
26
+ disabledRef.current = disabled
29
27
  local triggerIdRef = React.useRef(0)
30
28
  if triggerIdRef.current == 0 then
31
29
  nextTriggerId += 1
@@ -46,7 +44,7 @@ local function TabsTrigger(props)
46
44
  return disabledRef.current
47
45
  end,
48
46
  })
49
- end, { props.value, tabsContext })
47
+ end, { disabled, props.value, tabsContext })
50
48
  useFocusNode({
51
49
  ref = triggerRef,
52
50
  getDisabled = function()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lattice-ui/tabs",
3
- "version": "0.5.0-next.1",
3
+ "version": "0.5.0-next.2",
4
4
  "private": false,
5
5
  "main": "out/init.luau",
6
6
  "types": "out/index.d.ts",
@@ -16,10 +16,10 @@
16
16
  "url": "https://github.com/astra-void/lattice-ui.git"
17
17
  },
18
18
  "dependencies": {
19
- "@lattice-ui/core": "0.5.0-next.1",
20
- "@lattice-ui/focus": "0.5.0-next.1",
21
- "@lattice-ui/layer": "0.5.0-next.1",
22
- "@lattice-ui/motion": "0.5.0-next.1"
19
+ "@lattice-ui/core": "0.5.0-next.2",
20
+ "@lattice-ui/layer": "0.5.0-next.2",
21
+ "@lattice-ui/motion": "0.5.0-next.2",
22
+ "@lattice-ui/focus": "0.5.0-next.2"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@rbxts/react": "17.3.7-ts.1",
@@ -1,13 +1,13 @@
1
1
  import { React, Slot } from "@lattice-ui/core";
2
2
  import { Presence } from "@lattice-ui/layer";
3
- import { createSurfaceRevealRecipe, type PresenceMotionConfig, usePresenceMotion } from "@lattice-ui/motion";
3
+ import { createSurfaceRevealRecipe, type PresenceMotionConfig, usePresenceMotionController } from "@lattice-ui/motion";
4
4
  import { useTabsContext } from "./context";
5
5
  import { createTabsContentName } from "./internals/ids";
6
6
  import type { TabsContentProps } from "./types";
7
7
 
8
8
  function TabsContentImpl(props: {
9
- motionPresent: boolean;
10
- visible: boolean;
9
+ present: boolean;
10
+ forceMount?: boolean;
11
11
  transition?: PresenceMotionConfig;
12
12
  onExitComplete?: () => void;
13
13
  value: string;
@@ -22,7 +22,19 @@ function TabsContentImpl(props: {
22
22
  return props.transition;
23
23
  }, [defaultTransition, props.transition]);
24
24
 
25
- const motionRef = usePresenceMotion<Frame>(props.motionPresent, config, props.onExitComplete);
25
+ const motion = usePresenceMotionController<Frame>({
26
+ present: props.present,
27
+ forceMount: props.forceMount,
28
+ config,
29
+ onExitComplete: props.onExitComplete,
30
+ });
31
+
32
+ const mounted = motion.mounted;
33
+ const visible = mounted && (motion.present || motion.phase !== "exited");
34
+
35
+ if (!mounted) {
36
+ return undefined;
37
+ }
26
38
 
27
39
  if (props.asChild) {
28
40
  const child = props.children;
@@ -31,7 +43,7 @@ function TabsContentImpl(props: {
31
43
  }
32
44
 
33
45
  return (
34
- <Slot Name={contentName} Visible={props.visible} ref={motionRef}>
46
+ <Slot Name={contentName} Visible={visible} ref={motion.ref}>
35
47
  {child}
36
48
  </Slot>
37
49
  );
@@ -42,8 +54,8 @@ function TabsContentImpl(props: {
42
54
  BackgroundTransparency={1}
43
55
  BorderSizePixel={0}
44
56
  Size={UDim2.fromOffset(0, 0)}
45
- Visible={props.visible}
46
- ref={motionRef}
57
+ Visible={visible}
58
+ ref={motion.ref}
47
59
  >
48
60
  {props.children}
49
61
  </frame>
@@ -59,10 +71,10 @@ export function TabsContent(props: TabsContentProps) {
59
71
  return (
60
72
  <TabsContentImpl
61
73
  asChild={props.asChild}
62
- motionPresent={selected}
74
+ forceMount={true}
75
+ present={selected}
63
76
  transition={props.transition}
64
77
  value={props.value}
65
- visible={selected}
66
78
  >
67
79
  {props.children}
68
80
  </TabsContentImpl>
@@ -75,11 +87,10 @@ export function TabsContent(props: TabsContentProps) {
75
87
  render={(state) => (
76
88
  <TabsContentImpl
77
89
  asChild={props.asChild}
78
- motionPresent={state.isPresent}
79
90
  onExitComplete={state.onExitComplete}
91
+ present={state.isPresent}
80
92
  transition={props.transition}
81
93
  value={props.value}
82
- visible={true}
83
94
  >
84
95
  {props.children}
85
96
  </TabsContentImpl>
@@ -22,10 +22,7 @@ export function TabsTrigger(props: TabsTriggerProps) {
22
22
  const selected = tabsContext.value === props.value;
23
23
  const disabled = props.disabled === true;
24
24
  const disabledRef = React.useRef(disabled);
25
-
26
- React.useEffect(() => {
27
- disabledRef.current = disabled;
28
- }, [disabled]);
25
+ disabledRef.current = disabled;
29
26
 
30
27
  const triggerIdRef = React.useRef(0);
31
28
  if (triggerIdRef.current === 0) {
@@ -47,7 +44,7 @@ export function TabsTrigger(props: TabsTriggerProps) {
47
44
  order: triggerOrderRef.current,
48
45
  getDisabled: () => disabledRef.current,
49
46
  });
50
- }, [props.value, tabsContext]);
47
+ }, [disabled, props.value, tabsContext]);
51
48
 
52
49
  useFocusNode({
53
50
  ref: triggerRef,