@lattice-ui/accordion 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,30 +6,40 @@ 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 useAccordionItemContext = TS.import(script, script.Parent, "context").useAccordionItemContext
11
11
  local function AccordionContentImpl(props)
12
12
  local defaultTransition = React.useMemo(function()
13
13
  return createSurfaceRevealRecipe()
14
14
  end, {})
15
15
  local config = props.transition or defaultTransition
16
- local motionRef = usePresenceMotion(props.motionPresent, config, props.onExitComplete)
16
+ local motion = usePresenceMotionController({
17
+ present = props.present,
18
+ forceMount = props.forceMount,
19
+ config = config,
20
+ onExitComplete = props.onExitComplete,
21
+ })
22
+ local mounted = motion.mounted
23
+ local visible = mounted and (motion.present or motion.phase ~= "exited")
24
+ if not mounted then
25
+ return nil
26
+ end
17
27
  if props.asChild then
18
28
  local child = props.children
19
29
  if not React.isValidElement(child) then
20
30
  error("[AccordionContent] `asChild` requires a child element.")
21
31
  end
22
32
  return React.createElement(Slot, {
23
- Visible = props.visible,
24
- ref = motionRef,
33
+ Visible = visible,
34
+ ref = motion.ref,
25
35
  }, child)
26
36
  end
27
37
  return React.createElement("frame", {
28
38
  BackgroundColor3 = Color3.fromRGB(35, 41, 54),
29
39
  BorderSizePixel = 0,
30
40
  Size = UDim2.fromOffset(260, 44),
31
- Visible = props.visible,
32
- ref = motionRef,
41
+ Visible = visible,
42
+ ref = motion.ref,
33
43
  }, props.children)
34
44
  end
35
45
  local function AccordionContent(props)
@@ -38,9 +48,9 @@ local function AccordionContent(props)
38
48
  if forceMount then
39
49
  return React.createElement(AccordionContentImpl, {
40
50
  asChild = props.asChild,
41
- motionPresent = itemContext.open,
51
+ forceMount = true,
52
+ present = itemContext.open,
42
53
  transition = props.transition,
43
- visible = itemContext.open,
44
54
  }, props.children)
45
55
  end
46
56
  return React.createElement(Presence, {
@@ -48,10 +58,9 @@ local function AccordionContent(props)
48
58
  render = function(state)
49
59
  return React.createElement(AccordionContentImpl, {
50
60
  asChild = props.asChild,
51
- motionPresent = state.isPresent,
52
61
  onExitComplete = state.onExitComplete,
62
+ present = state.isPresent,
53
63
  transition = props.transition,
54
- visible = true,
55
64
  }, props.children)
56
65
  end,
57
66
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lattice-ui/accordion",
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,9 +16,9 @@
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/layer": "0.5.0-next.1",
21
- "@lattice-ui/motion": "0.5.0-next.1"
19
+ "@lattice-ui/core": "0.5.0-next.2",
20
+ "@lattice-ui/motion": "0.5.0-next.2",
21
+ "@lattice-ui/layer": "0.5.0-next.2"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@rbxts/react": "17.3.7-ts.1",
@@ -1,12 +1,12 @@
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 { useAccordionItemContext } from "./context";
5
5
  import type { AccordionContentProps } from "./types";
6
6
 
7
7
  function AccordionContentImpl(props: {
8
- motionPresent: boolean;
9
- visible: boolean;
8
+ present: boolean;
9
+ forceMount?: boolean;
10
10
  transition?: PresenceMotionConfig;
11
11
  onExitComplete?: () => void;
12
12
  asChild?: boolean;
@@ -15,7 +15,19 @@ function AccordionContentImpl(props: {
15
15
  const defaultTransition = React.useMemo(() => createSurfaceRevealRecipe(), []);
16
16
  const config = props.transition ?? defaultTransition;
17
17
 
18
- const motionRef = usePresenceMotion<Frame>(props.motionPresent, config, props.onExitComplete);
18
+ const motion = usePresenceMotionController<Frame>({
19
+ present: props.present,
20
+ forceMount: props.forceMount,
21
+ config,
22
+ onExitComplete: props.onExitComplete,
23
+ });
24
+
25
+ const mounted = motion.mounted;
26
+ const visible = mounted && (motion.present || motion.phase !== "exited");
27
+
28
+ if (!mounted) {
29
+ return undefined;
30
+ }
19
31
 
20
32
  if (props.asChild) {
21
33
  const child = props.children;
@@ -24,7 +36,7 @@ function AccordionContentImpl(props: {
24
36
  }
25
37
 
26
38
  return (
27
- <Slot Visible={props.visible} ref={motionRef}>
39
+ <Slot Visible={visible} ref={motion.ref}>
28
40
  {child}
29
41
  </Slot>
30
42
  );
@@ -35,8 +47,8 @@ function AccordionContentImpl(props: {
35
47
  BackgroundColor3={Color3.fromRGB(35, 41, 54)}
36
48
  BorderSizePixel={0}
37
49
  Size={UDim2.fromOffset(260, 44)}
38
- Visible={props.visible}
39
- ref={motionRef}
50
+ Visible={visible}
51
+ ref={motion.ref}
40
52
  >
41
53
  {props.children}
42
54
  </frame>
@@ -51,9 +63,9 @@ export function AccordionContent(props: AccordionContentProps) {
51
63
  return (
52
64
  <AccordionContentImpl
53
65
  asChild={props.asChild}
54
- motionPresent={itemContext.open}
66
+ forceMount={true}
67
+ present={itemContext.open}
55
68
  transition={props.transition}
56
- visible={itemContext.open}
57
69
  >
58
70
  {props.children}
59
71
  </AccordionContentImpl>
@@ -66,10 +78,9 @@ export function AccordionContent(props: AccordionContentProps) {
66
78
  render={(state) => (
67
79
  <AccordionContentImpl
68
80
  asChild={props.asChild}
69
- motionPresent={state.isPresent}
70
81
  onExitComplete={state.onExitComplete}
82
+ present={state.isPresent}
71
83
  transition={props.transition}
72
- visible={true}
73
84
  >
74
85
  {props.children}
75
86
  </AccordionContentImpl>