@lattice-ui/accordion 0.3.2 → 0.4.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,4 @@
1
+
2
+ > @lattice-ui/accordion@0.4.1 build C:\Users\retur\OneDrive\Desktop\Workspace\rojo\lattice-ui\packages\accordion
3
+ > rbxtsc -p tsconfig.json
4
+
@@ -0,0 +1,4 @@
1
+
2
+ > @lattice-ui/accordion@0.4.1 typecheck C:\Users\retur\OneDrive\Desktop\Workspace\rojo\lattice-ui\packages\accordion
3
+ > tsc -p tsconfig.typecheck.json
4
+
package/README.md CHANGED
@@ -15,4 +15,3 @@ Headless accordion primitives for Roblox UI with single and multiple disclosure
15
15
 
16
16
  - Supports `type="single" | "multiple"`.
17
17
  - Supports controlled/uncontrolled `value`.
18
- - Keyboard navigation is integrated with roving focus.
@@ -3,28 +3,22 @@ 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 useControllableState = _core.useControllableState
6
- local RovingFocusGroup = TS.import(script, TS.getModule(script, "@lattice-ui", "focus").out).RovingFocusGroup
7
6
  local AccordionContextProvider = TS.import(script, script.Parent, "context").AccordionContextProvider
8
7
  local _state = TS.import(script, script.Parent, "state")
9
8
  local nextAccordionValues = _state.nextAccordionValues
10
9
  local normalizeAccordionValue = _state.normalizeAccordionValue
11
10
  local function AccordionRoot(props)
12
11
  local accordionType = props.type or "single"
13
- local _condition = props.loop
12
+ local _condition = props.collapsible
14
13
  if _condition == nil then
15
- _condition = true
14
+ _condition = false
16
15
  end
17
- local loop = _condition
18
- local _condition_1 = props.collapsible
16
+ local collapsible = _condition
17
+ local _condition_1 = props.defaultValue
19
18
  if _condition_1 == nil then
20
- _condition_1 = false
19
+ _condition_1 = (if accordionType == "single" then "" else {})
21
20
  end
22
- local collapsible = _condition_1
23
- local _condition_2 = props.defaultValue
24
- if _condition_2 == nil then
25
- _condition_2 = (if accordionType == "single" then "" else {})
26
- end
27
- local defaultValue = _condition_2
21
+ local defaultValue = _condition_1
28
22
  local _binding = useControllableState({
29
23
  value = props.value,
30
24
  defaultValue = defaultValue,
@@ -36,11 +30,11 @@ local function AccordionRoot(props)
36
30
  local toggleItem = React.useCallback(function(candidateValue)
37
31
  local nextValues = nextAccordionValues(accordionType, openValues, candidateValue, collapsible)
38
32
  if accordionType == "single" then
39
- local _condition_3 = nextValues[1]
40
- if _condition_3 == nil then
41
- _condition_3 = ""
33
+ local _condition_2 = nextValues[1]
34
+ if _condition_2 == nil then
35
+ _condition_2 = ""
42
36
  end
43
- setRawValue(_condition_3)
37
+ setRawValue(_condition_2)
44
38
  return nil
45
39
  end
46
40
  setRawValue(nextValues)
@@ -49,18 +43,12 @@ local function AccordionRoot(props)
49
43
  return {
50
44
  type = accordionType,
51
45
  openValues = openValues,
52
- loop = loop,
53
46
  toggleItem = toggleItem,
54
47
  }
55
- end, { accordionType, loop, openValues, toggleItem })
48
+ end, { accordionType, openValues, toggleItem })
56
49
  return React.createElement(AccordionContextProvider, {
57
50
  value = contextValue,
58
- }, React.createElement(RovingFocusGroup, {
59
- active = true,
60
- autoFocus = "none",
61
- loop = loop,
62
- orientation = "vertical",
63
- }, props.children))
51
+ }, props.children)
64
52
  end
65
53
  return {
66
54
  AccordionRoot = AccordionRoot,
@@ -3,7 +3,6 @@ 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 RovingFocusItem = TS.import(script, TS.getModule(script, "@lattice-ui", "focus").out).RovingFocusItem
7
6
  local _context = TS.import(script, script.Parent, "context")
8
7
  local useAccordionContext = _context.useAccordionContext
9
8
  local useAccordionItemContext = _context.useAccordionItemContext
@@ -37,25 +36,19 @@ local function AccordionTrigger(props)
37
36
  if not child then
38
37
  error("[AccordionTrigger] `asChild` requires a child element.")
39
38
  end
40
- return React.createElement(RovingFocusItem, {
41
- asChild = true,
42
- disabled = disabled,
43
- }, React.createElement(Slot, {
39
+ return React.createElement(Slot, {
44
40
  Active = not disabled,
45
41
  Event = eventHandlers,
46
- Selectable = not disabled,
47
- }, child))
42
+ Selectable = false,
43
+ }, child)
48
44
  end
49
- return React.createElement(RovingFocusItem, {
50
- asChild = true,
51
- disabled = disabled,
52
- }, React.createElement("textbutton", {
45
+ return React.createElement("textbutton", {
53
46
  Active = not disabled,
54
47
  AutoButtonColor = false,
55
48
  BackgroundColor3 = Color3.fromRGB(41, 48, 63),
56
49
  BorderSizePixel = 0,
57
50
  Event = eventHandlers,
58
- Selectable = not disabled,
51
+ Selectable = false,
59
52
  Size = UDim2.fromOffset(260, 34),
60
53
  Text = if itemContext.open then "Collapse" else "Expand",
61
54
  TextColor3 = if disabled then Color3.fromRGB(143, 150, 165) else Color3.fromRGB(236, 241, 249),
@@ -63,7 +56,7 @@ local function AccordionTrigger(props)
63
56
  TextXAlignment = Enum.TextXAlignment.Left,
64
57
  }, React.createElement("uipadding", {
65
58
  PaddingLeft = UDim.new(0, 10),
66
- }), props.children))
59
+ }), props.children)
67
60
  end
68
61
  return {
69
62
  AccordionTrigger = AccordionTrigger,
@@ -3,7 +3,6 @@ import type { AccordionType } from "./state";
3
3
  export type AccordionContextValue = {
4
4
  type: AccordionType;
5
5
  openValues: Array<string>;
6
- loop: boolean;
7
6
  toggleItem: (value: string) => void;
8
7
  };
9
8
  export type AccordionItemContextValue = {
@@ -17,7 +16,6 @@ export type AccordionProps = {
17
16
  defaultValue?: string | Array<string>;
18
17
  onValueChange?: (value: string | Array<string>) => void;
19
18
  collapsible?: boolean;
20
- loop?: boolean;
21
19
  children?: React.ReactNode;
22
20
  };
23
21
  export type AccordionItemProps = {
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@lattice-ui/accordion",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "private": false,
5
5
  "main": "out/init.luau",
6
6
  "types": "out/index.d.ts",
7
7
  "dependencies": {
8
- "@lattice-ui/core": "0.3.2",
9
- "@lattice-ui/focus": "0.3.2"
8
+ "@lattice-ui/core": "0.4.1"
10
9
  },
11
10
  "devDependencies": {
12
11
  "@rbxts/react": "17.3.7-ts.1",
@@ -1,12 +1,10 @@
1
1
  import { React, useControllableState } from "@lattice-ui/core";
2
- import { RovingFocusGroup } from "@lattice-ui/focus";
3
2
  import { AccordionContextProvider } from "./context";
4
3
  import { nextAccordionValues, normalizeAccordionValue } from "./state";
5
4
  import type { AccordionProps } from "./types";
6
5
 
7
6
  export function AccordionRoot(props: AccordionProps) {
8
7
  const accordionType = props.type ?? "single";
9
- const loop = props.loop ?? true;
10
8
  const collapsible = props.collapsible ?? false;
11
9
 
12
10
  const defaultValue = props.defaultValue ?? (accordionType === "single" ? "" : []);
@@ -36,19 +34,12 @@ export function AccordionRoot(props: AccordionProps) {
36
34
  () => ({
37
35
  type: accordionType,
38
36
  openValues,
39
- loop,
40
37
  toggleItem,
41
38
  }),
42
- [accordionType, loop, openValues, toggleItem],
39
+ [accordionType, openValues, toggleItem],
43
40
  );
44
41
 
45
- return (
46
- <AccordionContextProvider value={contextValue}>
47
- <RovingFocusGroup active autoFocus="none" loop={loop} orientation="vertical">
48
- {props.children}
49
- </RovingFocusGroup>
50
- </AccordionContextProvider>
51
- );
42
+ return <AccordionContextProvider value={contextValue}>{props.children}</AccordionContextProvider>;
52
43
  }
53
44
 
54
45
  export { AccordionRoot as Accordion };
@@ -1,5 +1,4 @@
1
1
  import { React, Slot } from "@lattice-ui/core";
2
- import { RovingFocusItem } from "@lattice-ui/focus";
3
2
  import { useAccordionContext, useAccordionItemContext } from "./context";
4
3
  import type { AccordionTriggerProps } from "./types";
5
4
 
@@ -45,32 +44,28 @@ export function AccordionTrigger(props: AccordionTriggerProps) {
45
44
  }
46
45
 
47
46
  return (
48
- <RovingFocusItem asChild disabled={disabled}>
49
- <Slot Active={!disabled} Event={eventHandlers} Selectable={!disabled}>
50
- {child}
51
- </Slot>
52
- </RovingFocusItem>
47
+ <Slot Active={!disabled} Event={eventHandlers} Selectable={false}>
48
+ {child}
49
+ </Slot>
53
50
  );
54
51
  }
55
52
 
56
53
  return (
57
- <RovingFocusItem asChild disabled={disabled}>
58
- <textbutton
59
- Active={!disabled}
60
- AutoButtonColor={false}
61
- BackgroundColor3={Color3.fromRGB(41, 48, 63)}
62
- BorderSizePixel={0}
63
- Event={eventHandlers}
64
- Selectable={!disabled}
65
- Size={UDim2.fromOffset(260, 34)}
66
- Text={itemContext.open ? "Collapse" : "Expand"}
67
- TextColor3={disabled ? Color3.fromRGB(143, 150, 165) : Color3.fromRGB(236, 241, 249)}
68
- TextSize={14}
69
- TextXAlignment={Enum.TextXAlignment.Left}
70
- >
71
- <uipadding PaddingLeft={new UDim(0, 10)} />
72
- {props.children}
73
- </textbutton>
74
- </RovingFocusItem>
54
+ <textbutton
55
+ Active={!disabled}
56
+ AutoButtonColor={false}
57
+ BackgroundColor3={Color3.fromRGB(41, 48, 63)}
58
+ BorderSizePixel={0}
59
+ Event={eventHandlers}
60
+ Selectable={false}
61
+ Size={UDim2.fromOffset(260, 34)}
62
+ Text={itemContext.open ? "Collapse" : "Expand"}
63
+ TextColor3={disabled ? Color3.fromRGB(143, 150, 165) : Color3.fromRGB(236, 241, 249)}
64
+ TextSize={14}
65
+ TextXAlignment={Enum.TextXAlignment.Left}
66
+ >
67
+ <uipadding PaddingLeft={new UDim(0, 10)} />
68
+ {props.children}
69
+ </textbutton>
75
70
  );
76
71
  }
@@ -4,7 +4,6 @@ import type { AccordionType } from "./state";
4
4
  export type AccordionContextValue = {
5
5
  type: AccordionType;
6
6
  openValues: Array<string>;
7
- loop: boolean;
8
7
  toggleItem: (value: string) => void;
9
8
  };
10
9
 
@@ -20,7 +19,6 @@ export type AccordionProps = {
20
19
  defaultValue?: string | Array<string>;
21
20
  onValueChange?: (value: string | Array<string>) => void;
22
21
  collapsible?: boolean;
23
- loop?: boolean;
24
22
  children?: React.ReactNode;
25
23
  };
26
24