@reshaped/headless 3.10.0-canary.12 → 3.10.0-canary.13

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.
@@ -1,6 +1,45 @@
1
1
  import type { Attributes } from "../../types/global";
2
2
  import type { ClassName } from "@reshaped/utilities";
3
3
  import type React from "react";
4
+ /**
5
+ * Render attributes and props
6
+ */
7
+ export type TriggerRenderProps = {
8
+ active: boolean;
9
+ disabled: boolean;
10
+ };
11
+ export type TriggerAttributes = Attributes<"button"> & {
12
+ className?: ClassName;
13
+ "aria-expanded": boolean;
14
+ "aria-controls": string;
15
+ id: string;
16
+ "data-active": string;
17
+ disabled?: boolean;
18
+ onClick: () => void;
19
+ };
20
+ export type ContentRenderProps = {
21
+ active: boolean;
22
+ };
23
+ export type ContentAttributes = Attributes<"div"> & {
24
+ "data-active": string;
25
+ "aria-labelledby": string;
26
+ id: string;
27
+ role: "region";
28
+ hidden: boolean;
29
+ };
30
+ /**
31
+ * Context
32
+ */
33
+ export type ContextProps = {
34
+ triggerId: string;
35
+ contentId: string;
36
+ active: boolean;
37
+ disabled: boolean;
38
+ onToggle?: (active: boolean) => void;
39
+ };
40
+ /**
41
+ * Props
42
+ */
4
43
  export type BaseProps = {
5
44
  /** Node for inserting the trigger and the content */
6
45
  children?: React.ReactNode;
@@ -14,22 +53,24 @@ export type BaseProps = {
14
53
  attributes?: Attributes<"div">;
15
54
  };
16
55
  export type TriggerProps = {
56
+ /** Additional classname for the root element */
57
+ className?: ClassName;
58
+ /** Additional attributes for the root element */
59
+ attributes?: Attributes<"button">;
17
60
  /** Node or render function for inserting the trigger */
18
- children?: ((attributes: {
19
- "aria-expanded": boolean;
20
- "aria-controls": string;
21
- id: string;
22
- "data-active": string;
23
- disabled?: boolean;
24
- onClick: () => void;
25
- }, props: {
26
- active: boolean;
27
- disabled: boolean;
28
- }) => React.ReactNode) | React.ReactNode;
61
+ children?: React.ReactNode;
62
+ /** Render function for custom trigger rendering */
63
+ render?: (attributes: TriggerAttributes, props: TriggerRenderProps) => React.ReactNode;
29
64
  };
30
65
  export type ContentProps = {
66
+ /** Additional classname for the root element */
67
+ className?: ClassName;
68
+ /** Additional attributes for the root element */
69
+ attributes?: Attributes<"div">;
31
70
  /** Node for inserting the expandable content */
32
71
  children?: React.ReactNode;
72
+ /** Render function for custom content rendering */
73
+ render?: (attributes: ContentAttributes, props: ContentRenderProps) => React.ReactNode;
33
74
  };
34
75
  export type ControlledProps = BaseProps & {
35
76
  /** Control whether the accordion is expanded or collapsed, enables controlled mode */
@@ -44,10 +85,3 @@ export type UncontrolledProps = BaseProps & {
44
85
  defaultActive?: boolean;
45
86
  };
46
87
  export type Props = ControlledProps | UncontrolledProps;
47
- export type ContextProps = {
48
- triggerId: string;
49
- contentId: string;
50
- active: boolean;
51
- disabled: boolean;
52
- onToggle?: (active: boolean) => void;
53
- };
@@ -1,11 +1,25 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
3
+ import { classNames } from "@reshaped/utilities";
3
4
  import React from "react";
4
5
  import AccordionContext from "./Accordion.context.js";
5
6
  const AccordionContent = (props) => {
6
- const { children } = props;
7
+ const { children, render, className, attributes } = props;
7
8
  const { active, triggerId, contentId } = React.useContext(AccordionContext);
8
- return (_jsx("div", { "data-active": active ? "true" : "false", "aria-labelledby": triggerId, id: contentId, role: "region", hidden: !active, children: children }));
9
+ const contentAttributes = {
10
+ ...attributes,
11
+ className: classNames(className),
12
+ "data-active": active ? "true" : "false",
13
+ "aria-labelledby": triggerId,
14
+ id: contentId,
15
+ role: "region",
16
+ hidden: !active,
17
+ };
18
+ const renderProps = { active };
19
+ if (render) {
20
+ return _jsx(_Fragment, { children: render(contentAttributes, renderProps) });
21
+ }
22
+ return _jsx("div", { ...contentAttributes, children: children });
9
23
  };
10
24
  AccordionContent.displayName = "Headless.Accordion.Content";
11
25
  export default AccordionContent;
@@ -1,18 +1,20 @@
1
1
  "use client";
2
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { classNames } from "@reshaped/utilities";
3
4
  import React from "react";
4
5
  import Actionable from "../Actionable/index.js";
5
6
  import AccordionContext from "./Accordion.context.js";
6
7
  const AccordionTrigger = (props) => {
7
- const { children } = props;
8
+ const { children, render, className, attributes } = props;
8
9
  const { active, onToggle, triggerId, contentId, disabled } = React.useContext(AccordionContext);
9
10
  const handleClick = () => {
10
- console.log("handleClick", active, disabled);
11
11
  if (disabled)
12
12
  return;
13
13
  onToggle?.(!active);
14
14
  };
15
- const attributes = {
15
+ const triggerAttributes = {
16
+ ...attributes,
17
+ className: classNames(className),
16
18
  "aria-expanded": active,
17
19
  "aria-controls": contentId,
18
20
  id: triggerId,
@@ -20,10 +22,10 @@ const AccordionTrigger = (props) => {
20
22
  disabled: disabled ? true : undefined,
21
23
  onClick: handleClick,
22
24
  };
23
- if (typeof children === "function") {
24
- return _jsx(_Fragment, { children: children(attributes, { active, disabled }) });
25
- }
26
- return (_jsx(Actionable, { onClick: handleClick, attributes: attributes, children: children }));
25
+ const renderProps = { active, disabled };
26
+ if (render)
27
+ return render(triggerAttributes, renderProps);
28
+ return (_jsx(Actionable, { onClick: handleClick, attributes: triggerAttributes, render: render, children: children }));
27
29
  };
28
30
  AccordionTrigger.displayName = "Headless.Accordion.Trigger";
29
31
  export default AccordionTrigger;
@@ -6,4 +6,4 @@ declare const AccordionRoot: typeof Accordion & {
6
6
  Content: typeof AccordionContent;
7
7
  };
8
8
  export default AccordionRoot;
9
- export type { Props as AccordionProps, TriggerProps as AccordionTriggerProps, ContentProps as AccordionContentProps, } from "./Accordion.types";
9
+ export type { Props as AccordionProps, TriggerProps as AccordionTriggerProps, TriggerAttributes as AccordionTriggerAttributes, ContentProps as AccordionContentProps, ContentAttributes as AccordionContentAttributes, } from "./Accordion.types";
@@ -8,5 +8,23 @@ export default {
8
8
  };
9
9
  export const base = {
10
10
  name: "base",
11
- render: () => (_jsxs(Accordion, { children: [_jsx(Accordion.Trigger, { children: "Trigger" }), _jsx(Accordion.Content, { children: "Content" })] })),
11
+ render: () => (_jsxs(Accordion, { attributes: {
12
+ style: {
13
+ padding: 16,
14
+ border: "1px solid rgba(255, 255, 255, 0.08)",
15
+ borderRadius: 8,
16
+ display: "flex",
17
+ flexDirection: "column",
18
+ gap: 16,
19
+ },
20
+ }, children: [_jsx(Accordion.Trigger, { attributes: {
21
+ style: {
22
+ background: "none",
23
+ border: "none",
24
+ width: "100%",
25
+ textAlign: "start",
26
+ cursor: "pointer",
27
+ padding: 0,
28
+ },
29
+ }, children: "Trigger" }), _jsx(Accordion.Content, { attributes: { style: { padding: 0, transition: "height 0.3s ease-in-out" } }, children: "Content" }), "r"] })),
12
30
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reshaped/headless",
3
3
  "description": "Headless components and utilities for React",
4
- "version": "3.10.0-canary.12",
4
+ "version": "3.10.0-canary.13",
5
5
  "license": "MIT",
6
6
  "homepage": "https://reshaped.so",
7
7
  "repository": {
@@ -39,7 +39,7 @@
39
39
  "react-dom": "^18 || ^19"
40
40
  },
41
41
  "dependencies": {
42
- "@reshaped/utilities": "3.10.0-canary.12"
42
+ "@reshaped/utilities": "3.10.0-canary.13"
43
43
  },
44
44
  "scripts": {
45
45
  "clean": "rm -rf dist",