mav-expandable 1.0.0 → 1.0.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.
package/README.md CHANGED
@@ -1,2 +1,141 @@
1
- //animation on chevron (checkbox)
2
- //u can use hook inside another component calling this expandable
1
+ # mav-expandable
2
+
3
+ a lightweight, composable expandable/collapsible component for react
4
+
5
+ ## installation
6
+
7
+ ```bash
8
+ npm install mav-expandable
9
+ ```
10
+
11
+ **peer dependencies** — make sure react 19 is installed in your project
12
+
13
+ ```bash
14
+ npm install react react-dom
15
+ ```
16
+
17
+ install from gh instead of npm
18
+
19
+ ```bash
20
+ npm install github:xmavv/expandable
21
+ ```
22
+
23
+ ## requirements
24
+
25
+ - React 19+
26
+ - [Tailwind CSS](https://tailwindcss.com/)
27
+
28
+ ## usage
29
+
30
+ ### basic example
31
+
32
+ wrap your content in `Expandable`, use `Expandable.Content` to define what stays visible, and `expand` prop to define what appears when expanded, additionally add `Expandable.Chevron` as the toggle
33
+
34
+ ```tsx
35
+ import { Expandable } from "mav-expandable";
36
+
37
+ function App() {
38
+ return (
39
+ <Expandable>
40
+ <Expandable.Content expand={<p>this content is shown when expanded</p>}>
41
+ <div className="flex items-center gap-2">
42
+ <Expandable.Chevron />
43
+ <span>click the chevron to expand</span>
44
+ </div>
45
+ </Expandable.Content>
46
+ </Expandable>
47
+ );
48
+ }
49
+ ```
50
+
51
+ ### start expanded
52
+
53
+ pass `expanded` prop to open the section by default:
54
+
55
+ ```tsx
56
+ <Expandable expanded>
57
+ <Expandable.Content expand={<p>already visible on mount</p>}>
58
+ <Expandable.Chevron />
59
+ <span>Section title</span>
60
+ </Expandable.Content>
61
+ </Expandable>
62
+ ```
63
+
64
+ ### custom toggle with `useExpandable`
65
+
66
+ you are not limited to `Expandable.Chevron`
67
+
68
+ use the `useExpandable` hook inside any child component rendered within `Expandable` to build your own toggle
69
+
70
+ ```tsx
71
+ import { Expandable, useExpandable } from "mav-expandable";
72
+
73
+ function CustomToggle() {
74
+ const { isExpanded, onExpand } = useExpandable();
75
+
76
+ return (
77
+ <button onClick={() => onExpand((open) => !open)}>
78
+ {isExpanded ? "Collapse" : "Expand"}
79
+ </button>
80
+ );
81
+ }
82
+
83
+ function App() {
84
+ return (
85
+ <Expandable>
86
+ <Expandable.Content expand={<p>extra details go here</p>}>
87
+ <CustomToggle />
88
+ <h3>my section</h3>
89
+ </Expandable.Content>
90
+ </Expandable>
91
+ );
92
+ }
93
+ ```
94
+
95
+ `useExpandable` must be called within an `Expandable` provider , calling it elsewhere throws an error
96
+
97
+ what is more as said before, you must use this hook inside a child component of `Expandable` caller
98
+
99
+ ## API
100
+
101
+ ### `<Expandable>`
102
+
103
+ root provider that holds expand/collapse state
104
+
105
+ | prop | type | default | description |
106
+ |------------|-------------|---------|------------------------|
107
+ | `children` | `ReactNode` | — | child components |
108
+ | `expanded` | `boolean` | `false` | initial expanded state |
109
+
110
+ ### `<Expandable.Content>`
111
+
112
+ renders always-visible `children`, and `expand` component when expanded
113
+
114
+ | prop ** | type | default | description |
115
+ |---------------|----------------|---------|---------------------------------------------|
116
+ | `children` | `ReactNode` | — | content shown whether expanded or collapsed |
117
+ | `expand` | `ReactElement` | — | content rendered only when expanded |
118
+ | `...rest` | `div` props | — | spread onto the wrapper `<div>` |
119
+
120
+ ### `<Expandable.Chevron>`
121
+
122
+ built-in toggle button with Lucide chevron icons (`ChevronRight` / `ChevronDown`).
123
+
124
+ ### `useExpandable()`
125
+
126
+ returns:
127
+
128
+ | property | type | description |
129
+ |--------------|-------------------------------------|------------------------------------------|
130
+ | `isExpanded` | `boolean` | current expanded state |
131
+ | `onExpand` | `Dispatch<SetStateAction<boolean>>` | setter to expand or collapse the section |
132
+
133
+ ## roadmap
134
+
135
+ planned improvements:
136
+
137
+ - **chevron animation** — smooth rotation/transition on the chevron toggle
138
+
139
+ ## license
140
+
141
+ Apache-2.0
package/dist/index.cjs CHANGED
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- Expandable: () => Expandable
23
+ Expandable: () => Expandable,
24
+ useExpandable: () => useExpandable
24
25
  });
25
26
  module.exports = __toCommonJS(index_exports);
26
27
 
@@ -67,5 +68,6 @@ Expandable.Content = ExpandableContent;
67
68
  Expandable.Chevron = ExpandableChevron;
68
69
  // Annotate the CommonJS export names for ESM import in node:
69
70
  0 && (module.exports = {
70
- Expandable
71
+ Expandable,
72
+ useExpandable
71
73
  });
package/dist/index.d.cts CHANGED
@@ -1,6 +1,10 @@
1
1
  import * as react from 'react';
2
- import { PropsWithChildren, ComponentPropsWithoutRef, ReactElement } from 'react';
2
+ import { PropsWithChildren, ComponentPropsWithoutRef, ReactElement, Dispatch, SetStateAction } from 'react';
3
3
 
4
+ declare function useExpandable(): {
5
+ isExpanded: boolean;
6
+ onExpand: Dispatch<SetStateAction<boolean>>;
7
+ };
4
8
  interface ExpandableProps extends PropsWithChildren {
5
9
  expanded?: boolean;
6
10
  }
@@ -15,4 +19,4 @@ interface ExpandableContentProps extends PropsWithChildren, ComponentPropsWithou
15
19
  declare function ExpandableContent({ children, expand, ...rest }: ExpandableContentProps): react.JSX.Element;
16
20
  declare function ExpandableChevron(): react.JSX.Element;
17
21
 
18
- export { Expandable };
22
+ export { Expandable, useExpandable };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import * as react from 'react';
2
- import { PropsWithChildren, ComponentPropsWithoutRef, ReactElement } from 'react';
2
+ import { PropsWithChildren, ComponentPropsWithoutRef, ReactElement, Dispatch, SetStateAction } from 'react';
3
3
 
4
+ declare function useExpandable(): {
5
+ isExpanded: boolean;
6
+ onExpand: Dispatch<SetStateAction<boolean>>;
7
+ };
4
8
  interface ExpandableProps extends PropsWithChildren {
5
9
  expanded?: boolean;
6
10
  }
@@ -15,4 +19,4 @@ interface ExpandableContentProps extends PropsWithChildren, ComponentPropsWithou
15
19
  declare function ExpandableContent({ children, expand, ...rest }: ExpandableContentProps): react.JSX.Element;
16
20
  declare function ExpandableChevron(): react.JSX.Element;
17
21
 
18
- export { Expandable };
22
+ export { Expandable, useExpandable };
package/dist/index.js CHANGED
@@ -44,5 +44,6 @@ function ExpandableChevron() {
44
44
  Expandable.Content = ExpandableContent;
45
45
  Expandable.Chevron = ExpandableChevron;
46
46
  export {
47
- Expandable
47
+ Expandable,
48
+ useExpandable
48
49
  };
package/package.json CHANGED
@@ -1,6 +1,14 @@
1
1
  {
2
2
  "name": "mav-expandable",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
+ "description": "Expandable component for React",
5
+ "keywords": ["react", "expand", "expandable", "lightweight", "component", "ui"],
6
+ "homepage": "https://github.com/xmavv/expandable",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/xmavv/expandable.git"
10
+ },
11
+ "license": "Apache-2.0",
4
12
  "type": "module",
5
13
  "main": "./dist/index.js",
6
14
  "module": "./dist/index.js",