@lattice-ui/accordion 0.4.4 → 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.
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "accordion",
3
+ "tree": {
4
+ "$path": "out",
5
+ "out": {
6
+ "$path": "out"
7
+ }
8
+ }
9
+ }
@@ -1,3 +1,3 @@
1
1
  import { React } from "@lattice-ui/core";
2
2
  import type { AccordionContentProps } from "./types";
3
- export declare function AccordionContent(props: AccordionContentProps): React.JSX.Element | undefined;
3
+ export declare function AccordionContent(props: AccordionContentProps): React.JSX.Element;
@@ -3,11 +3,25 @@ local TS = _G[script]
3
3
  local _core = TS.import(script, TS.getModule(script, "@lattice-ui", "core").out)
4
4
  local React = _core.React
5
5
  local Slot = _core.Slot
6
+ local Presence = TS.import(script, TS.getModule(script, "@lattice-ui", "layer").out).Presence
7
+ local _motion = TS.import(script, TS.getModule(script, "@lattice-ui", "motion").out)
8
+ local createSurfaceRevealRecipe = _motion.createSurfaceRevealRecipe
9
+ local usePresenceMotionController = _motion.usePresenceMotionController
6
10
  local useAccordionItemContext = TS.import(script, script.Parent, "context").useAccordionItemContext
7
- local function AccordionContent(props)
8
- local itemContext = useAccordionItemContext()
9
- local forceMount = props.forceMount == true
10
- if not itemContext.open and not forceMount then
11
+ local function AccordionContentImpl(props)
12
+ local defaultTransition = React.useMemo(function()
13
+ return createSurfaceRevealRecipe()
14
+ end, {})
15
+ local config = props.transition or defaultTransition
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
11
25
  return nil
12
26
  end
13
27
  if props.asChild then
@@ -16,16 +30,41 @@ local function AccordionContent(props)
16
30
  error("[AccordionContent] `asChild` requires a child element.")
17
31
  end
18
32
  return React.createElement(Slot, {
19
- Visible = itemContext.open,
33
+ Visible = visible,
34
+ ref = motion.ref,
20
35
  }, child)
21
36
  end
22
37
  return React.createElement("frame", {
23
38
  BackgroundColor3 = Color3.fromRGB(35, 41, 54),
24
39
  BorderSizePixel = 0,
25
40
  Size = UDim2.fromOffset(260, 44),
26
- Visible = itemContext.open,
41
+ Visible = visible,
42
+ ref = motion.ref,
27
43
  }, props.children)
28
44
  end
45
+ local function AccordionContent(props)
46
+ local itemContext = useAccordionItemContext()
47
+ local forceMount = props.forceMount == true
48
+ if forceMount then
49
+ return React.createElement(AccordionContentImpl, {
50
+ asChild = props.asChild,
51
+ forceMount = true,
52
+ present = itemContext.open,
53
+ transition = props.transition,
54
+ }, props.children)
55
+ end
56
+ return React.createElement(Presence, {
57
+ present = itemContext.open,
58
+ render = function(state)
59
+ return React.createElement(AccordionContentImpl, {
60
+ asChild = props.asChild,
61
+ onExitComplete = state.onExitComplete,
62
+ present = state.isPresent,
63
+ transition = props.transition,
64
+ }, props.children)
65
+ end,
66
+ })
67
+ end
29
68
  return {
30
69
  AccordionContent = AccordionContent,
31
70
  }
@@ -3,6 +3,9 @@ local TS = _G[script]
3
3
  local _core = TS.import(script, TS.getModule(script, "@lattice-ui", "core").out)
4
4
  local React = _core.React
5
5
  local Slot = _core.Slot
6
+ local _motion = TS.import(script, TS.getModule(script, "@lattice-ui", "motion").out)
7
+ local createSelectionResponseRecipe = _motion.createSelectionResponseRecipe
8
+ local useResponseMotion = _motion.useResponseMotion
6
9
  local _context = TS.import(script, script.Parent, "context")
7
10
  local useAccordionContext = _context.useAccordionContext
8
11
  local useAccordionItemContext = _context.useAccordionItemContext
@@ -10,6 +13,14 @@ local function AccordionTrigger(props)
10
13
  local accordionContext = useAccordionContext()
11
14
  local itemContext = useAccordionItemContext()
12
15
  local disabled = itemContext.disabled
16
+ local motionRef = useResponseMotion(itemContext.open, {
17
+ active = {
18
+ BackgroundColor3 = Color3.fromRGB(59, 66, 84),
19
+ },
20
+ inactive = {
21
+ BackgroundColor3 = Color3.fromRGB(41, 48, 63),
22
+ },
23
+ }, createSelectionResponseRecipe(0.15))
13
24
  local handleActivated = React.useCallback(function()
14
25
  if disabled then
15
26
  return nil
@@ -40,12 +51,13 @@ local function AccordionTrigger(props)
40
51
  Active = not disabled,
41
52
  Event = eventHandlers,
42
53
  Selectable = false,
54
+ ref = motionRef,
43
55
  }, child)
44
56
  end
45
57
  return React.createElement("textbutton", {
46
58
  Active = not disabled,
47
59
  AutoButtonColor = false,
48
- BackgroundColor3 = Color3.fromRGB(41, 48, 63),
60
+ BackgroundColor3 = if itemContext.open then Color3.fromRGB(59, 66, 84) else Color3.fromRGB(41, 48, 63),
49
61
  BorderSizePixel = 0,
50
62
  Event = eventHandlers,
51
63
  Selectable = false,
@@ -54,6 +66,7 @@ local function AccordionTrigger(props)
54
66
  TextColor3 = if disabled then Color3.fromRGB(143, 150, 165) else Color3.fromRGB(236, 241, 249),
55
67
  TextSize = 14,
56
68
  TextXAlignment = Enum.TextXAlignment.Left,
69
+ ref = motionRef,
57
70
  }, React.createElement("uipadding", {
58
71
  PaddingLeft = UDim.new(0, 10),
59
72
  }), props.children)
@@ -1,3 +1,4 @@
1
+ import type { PresenceMotionConfig } from "@lattice-ui/motion";
1
2
  import type React from "@rbxts/react";
2
3
  import type { AccordionType } from "./state";
3
4
  export type AccordionContextValue = {
@@ -35,5 +36,6 @@ export type AccordionTriggerProps = {
35
36
  export type AccordionContentProps = {
36
37
  asChild?: boolean;
37
38
  forceMount?: boolean;
39
+ transition?: PresenceMotionConfig;
38
40
  children?: React.ReactNode;
39
41
  };
package/package.json CHANGED
@@ -1,11 +1,24 @@
1
1
  {
2
2
  "name": "@lattice-ui/accordion",
3
- "version": "0.4.4",
3
+ "version": "0.5.0-next.2",
4
4
  "private": false,
5
5
  "main": "out/init.luau",
6
6
  "types": "out/index.d.ts",
7
+ "source": "src/index.ts",
8
+ "files": [
9
+ "default.project.json",
10
+ "out",
11
+ "src",
12
+ "README.md"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/astra-void/lattice-ui.git"
17
+ },
7
18
  "dependencies": {
8
- "@lattice-ui/core": "0.4.4"
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"
9
22
  },
10
23
  "devDependencies": {
11
24
  "@rbxts/react": "17.3.7-ts.1",
@@ -17,6 +30,8 @@
17
30
  },
18
31
  "scripts": {
19
32
  "build": "rbxtsc -p tsconfig.json",
33
+ "lint": "eslint .",
34
+ "lint:fix": "eslint . --fix",
20
35
  "typecheck": "tsc -p tsconfig.typecheck.json",
21
36
  "watch": "rbxtsc -p tsconfig.json -w"
22
37
  }
@@ -1,12 +1,31 @@
1
1
  import { React, Slot } from "@lattice-ui/core";
2
+ import { Presence } from "@lattice-ui/layer";
3
+ import { createSurfaceRevealRecipe, type PresenceMotionConfig, usePresenceMotionController } from "@lattice-ui/motion";
2
4
  import { useAccordionItemContext } from "./context";
3
5
  import type { AccordionContentProps } from "./types";
4
6
 
5
- export function AccordionContent(props: AccordionContentProps) {
6
- const itemContext = useAccordionItemContext();
7
- const forceMount = props.forceMount === true;
7
+ function AccordionContentImpl(props: {
8
+ present: boolean;
9
+ forceMount?: boolean;
10
+ transition?: PresenceMotionConfig;
11
+ onExitComplete?: () => void;
12
+ asChild?: boolean;
13
+ children?: React.ReactNode;
14
+ }) {
15
+ const defaultTransition = React.useMemo(() => createSurfaceRevealRecipe(), []);
16
+ const config = props.transition ?? defaultTransition;
17
+
18
+ const motion = usePresenceMotionController<Frame>({
19
+ present: props.present,
20
+ forceMount: props.forceMount,
21
+ config,
22
+ onExitComplete: props.onExitComplete,
23
+ });
8
24
 
9
- if (!itemContext.open && !forceMount) {
25
+ const mounted = motion.mounted;
26
+ const visible = mounted && (motion.present || motion.phase !== "exited");
27
+
28
+ if (!mounted) {
10
29
  return undefined;
11
30
  }
12
31
 
@@ -16,7 +35,11 @@ export function AccordionContent(props: AccordionContentProps) {
16
35
  error("[AccordionContent] `asChild` requires a child element.");
17
36
  }
18
37
 
19
- return <Slot Visible={itemContext.open}>{child}</Slot>;
38
+ return (
39
+ <Slot Visible={visible} ref={motion.ref}>
40
+ {child}
41
+ </Slot>
42
+ );
20
43
  }
21
44
 
22
45
  return (
@@ -24,9 +47,44 @@ export function AccordionContent(props: AccordionContentProps) {
24
47
  BackgroundColor3={Color3.fromRGB(35, 41, 54)}
25
48
  BorderSizePixel={0}
26
49
  Size={UDim2.fromOffset(260, 44)}
27
- Visible={itemContext.open}
50
+ Visible={visible}
51
+ ref={motion.ref}
28
52
  >
29
53
  {props.children}
30
54
  </frame>
31
55
  );
32
56
  }
57
+
58
+ export function AccordionContent(props: AccordionContentProps) {
59
+ const itemContext = useAccordionItemContext();
60
+ const forceMount = props.forceMount === true;
61
+
62
+ if (forceMount) {
63
+ return (
64
+ <AccordionContentImpl
65
+ asChild={props.asChild}
66
+ forceMount={true}
67
+ present={itemContext.open}
68
+ transition={props.transition}
69
+ >
70
+ {props.children}
71
+ </AccordionContentImpl>
72
+ );
73
+ }
74
+
75
+ return (
76
+ <Presence
77
+ present={itemContext.open}
78
+ render={(state) => (
79
+ <AccordionContentImpl
80
+ asChild={props.asChild}
81
+ onExitComplete={state.onExitComplete}
82
+ present={state.isPresent}
83
+ transition={props.transition}
84
+ >
85
+ {props.children}
86
+ </AccordionContentImpl>
87
+ )}
88
+ />
89
+ );
90
+ }
@@ -1,4 +1,5 @@
1
1
  import { React, Slot } from "@lattice-ui/core";
2
+ import { createSelectionResponseRecipe, useResponseMotion } from "@lattice-ui/motion";
2
3
  import { useAccordionContext, useAccordionItemContext } from "./context";
3
4
  import type { AccordionTriggerProps } from "./types";
4
5
 
@@ -7,6 +8,15 @@ export function AccordionTrigger(props: AccordionTriggerProps) {
7
8
  const itemContext = useAccordionItemContext();
8
9
  const disabled = itemContext.disabled;
9
10
 
11
+ const motionRef = useResponseMotion<TextButton>(
12
+ itemContext.open,
13
+ {
14
+ active: { BackgroundColor3: Color3.fromRGB(59, 66, 84) },
15
+ inactive: { BackgroundColor3: Color3.fromRGB(41, 48, 63) },
16
+ },
17
+ createSelectionResponseRecipe(0.15),
18
+ );
19
+
10
20
  const handleActivated = React.useCallback(() => {
11
21
  if (disabled) {
12
22
  return;
@@ -44,7 +54,7 @@ export function AccordionTrigger(props: AccordionTriggerProps) {
44
54
  }
45
55
 
46
56
  return (
47
- <Slot Active={!disabled} Event={eventHandlers} Selectable={false}>
57
+ <Slot Active={!disabled} Event={eventHandlers} Selectable={false} ref={motionRef}>
48
58
  {child}
49
59
  </Slot>
50
60
  );
@@ -54,7 +64,7 @@ export function AccordionTrigger(props: AccordionTriggerProps) {
54
64
  <textbutton
55
65
  Active={!disabled}
56
66
  AutoButtonColor={false}
57
- BackgroundColor3={Color3.fromRGB(41, 48, 63)}
67
+ BackgroundColor3={itemContext.open ? Color3.fromRGB(59, 66, 84) : Color3.fromRGB(41, 48, 63)}
58
68
  BorderSizePixel={0}
59
69
  Event={eventHandlers}
60
70
  Selectable={false}
@@ -63,6 +73,7 @@ export function AccordionTrigger(props: AccordionTriggerProps) {
63
73
  TextColor3={disabled ? Color3.fromRGB(143, 150, 165) : Color3.fromRGB(236, 241, 249)}
64
74
  TextSize={14}
65
75
  TextXAlignment={Enum.TextXAlignment.Left}
76
+ ref={motionRef}
66
77
  >
67
78
  <uipadding PaddingLeft={new UDim(0, 10)} />
68
79
  {props.children}
@@ -1,3 +1,4 @@
1
+ import type { PresenceMotionConfig } from "@lattice-ui/motion";
1
2
  import type React from "@rbxts/react";
2
3
  import type { AccordionType } from "./state";
3
4
 
@@ -42,5 +43,6 @@ export type AccordionTriggerProps = {
42
43
  export type AccordionContentProps = {
43
44
  asChild?: boolean;
44
45
  forceMount?: boolean;
46
+ transition?: PresenceMotionConfig;
45
47
  children?: React.ReactNode;
46
48
  };
@@ -1,4 +0,0 @@
1
-
2
- > @lattice-ui/accordion@0.4.4 build C:\Users\retur\OneDrive\Desktop\Workspace\rojo\lattice-ui\packages\accordion
3
- > rbxtsc -p tsconfig.json
4
-
@@ -1,4 +0,0 @@
1
-
2
- > @lattice-ui/accordion@0.4.4 typecheck C:\Users\retur\OneDrive\Desktop\Workspace\rojo\lattice-ui\packages\accordion
3
- > tsc -p tsconfig.typecheck.json
4
-
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "out",
6
- "declaration": true,
7
- "typeRoots": [
8
- "./node_modules/@rbxts",
9
- "../../node_modules/@rbxts",
10
- "./node_modules/@lattice-ui",
11
- "../../node_modules/@lattice-ui"
12
- ],
13
- "types": ["types", "compiler-types"]
14
- },
15
- "include": ["src"]
16
- }
@@ -1,35 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "noEmit": true,
5
- "baseUrl": "..",
6
- "rootDir": "..",
7
- "paths": {
8
- "@lattice-ui/accordion": ["accordion/src/index.ts"],
9
- "@lattice-ui/avatar": ["avatar/src/index.ts"],
10
- "@lattice-ui/checkbox": ["checkbox/src/index.ts"],
11
- "@lattice-ui/combobox": ["combobox/src/index.ts"],
12
- "@lattice-ui/core": ["core/src/index.ts"],
13
- "@lattice-ui/dialog": ["dialog/src/index.ts"],
14
- "@lattice-ui/focus": ["focus/src/index.ts"],
15
- "@lattice-ui/layer": ["layer/src/index.ts"],
16
- "@lattice-ui/menu": ["menu/src/index.ts"],
17
- "@lattice-ui/popover": ["popover/src/index.ts"],
18
- "@lattice-ui/popper": ["popper/src/index.ts"],
19
- "@lattice-ui/progress": ["progress/src/index.ts"],
20
- "@lattice-ui/radio-group": ["radio-group/src/index.ts"],
21
- "@lattice-ui/scroll-area": ["scroll-area/src/index.ts"],
22
- "@lattice-ui/select": ["select/src/index.ts"],
23
- "@lattice-ui/slider": ["slider/src/index.ts"],
24
- "@lattice-ui/style": ["style/src/index.ts"],
25
- "@lattice-ui/switch": ["switch/src/index.ts"],
26
- "@lattice-ui/system": ["system/src/index.ts"],
27
- "@lattice-ui/tabs": ["tabs/src/index.ts"],
28
- "@lattice-ui/text-field": ["text-field/src/index.ts"],
29
- "@lattice-ui/textarea": ["textarea/src/index.ts"],
30
- "@lattice-ui/toast": ["toast/src/index.ts"],
31
- "@lattice-ui/toggle-group": ["toggle-group/src/index.ts"],
32
- "@lattice-ui/tooltip": ["tooltip/src/index.ts"]
33
- }
34
- }
35
- }