@lattice-ui/accordion 0.4.3 → 0.5.0-next.1

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