mav-expandable 1.0.0
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 +2 -0
- package/dist/index.cjs +71 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +48 -0
- package/package.json +31 -0
package/README.md
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Expandable: () => Expandable
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/expandable.tsx
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_lucide_react = require("lucide-react");
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
+
var ExpandableContext = (0, import_react.createContext)(null);
|
|
32
|
+
function useExpandable() {
|
|
33
|
+
const value = (0, import_react.useContext)(ExpandableContext);
|
|
34
|
+
if (!value)
|
|
35
|
+
throw new Error("Expandable context is used outside it's provider!");
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function Expandable({ children, expanded = false }) {
|
|
39
|
+
const [isExpanded, setIsExpanded] = (0, import_react.useState)(expanded);
|
|
40
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ExpandableContext.Provider, { value: { isExpanded, onExpand: setIsExpanded }, children });
|
|
41
|
+
}
|
|
42
|
+
function ExpandableContent({
|
|
43
|
+
children,
|
|
44
|
+
expand,
|
|
45
|
+
...rest
|
|
46
|
+
}) {
|
|
47
|
+
const { isExpanded } = useExpandable();
|
|
48
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...rest, children: [
|
|
49
|
+
children,
|
|
50
|
+
" ",
|
|
51
|
+
isExpanded && expand
|
|
52
|
+
] });
|
|
53
|
+
}
|
|
54
|
+
function ExpandableChevron() {
|
|
55
|
+
const { isExpanded, onExpand } = useExpandable();
|
|
56
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
57
|
+
"button",
|
|
58
|
+
{
|
|
59
|
+
onClick: () => onExpand((e) => !e),
|
|
60
|
+
className: "p-1 h-6 w-6 hover:bg-gray-200",
|
|
61
|
+
title: isExpanded ? "Collapse" : "Expand",
|
|
62
|
+
children: isExpanded ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ChevronDown, { size: 16 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ChevronRight, { size: 16 })
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
Expandable.Content = ExpandableContent;
|
|
67
|
+
Expandable.Chevron = ExpandableChevron;
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
Expandable
|
|
71
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { PropsWithChildren, ComponentPropsWithoutRef, ReactElement } from 'react';
|
|
3
|
+
|
|
4
|
+
interface ExpandableProps extends PropsWithChildren {
|
|
5
|
+
expanded?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare function Expandable({ children, expanded }: ExpandableProps): react.JSX.Element;
|
|
8
|
+
declare namespace Expandable {
|
|
9
|
+
var Content: typeof ExpandableContent;
|
|
10
|
+
var Chevron: typeof ExpandableChevron;
|
|
11
|
+
}
|
|
12
|
+
interface ExpandableContentProps extends PropsWithChildren, ComponentPropsWithoutRef<"div"> {
|
|
13
|
+
expand: ReactElement;
|
|
14
|
+
}
|
|
15
|
+
declare function ExpandableContent({ children, expand, ...rest }: ExpandableContentProps): react.JSX.Element;
|
|
16
|
+
declare function ExpandableChevron(): react.JSX.Element;
|
|
17
|
+
|
|
18
|
+
export { Expandable };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { PropsWithChildren, ComponentPropsWithoutRef, ReactElement } from 'react';
|
|
3
|
+
|
|
4
|
+
interface ExpandableProps extends PropsWithChildren {
|
|
5
|
+
expanded?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare function Expandable({ children, expanded }: ExpandableProps): react.JSX.Element;
|
|
8
|
+
declare namespace Expandable {
|
|
9
|
+
var Content: typeof ExpandableContent;
|
|
10
|
+
var Chevron: typeof ExpandableChevron;
|
|
11
|
+
}
|
|
12
|
+
interface ExpandableContentProps extends PropsWithChildren, ComponentPropsWithoutRef<"div"> {
|
|
13
|
+
expand: ReactElement;
|
|
14
|
+
}
|
|
15
|
+
declare function ExpandableContent({ children, expand, ...rest }: ExpandableContentProps): react.JSX.Element;
|
|
16
|
+
declare function ExpandableChevron(): react.JSX.Element;
|
|
17
|
+
|
|
18
|
+
export { Expandable };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/expandable.tsx
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
useContext,
|
|
5
|
+
useState
|
|
6
|
+
} from "react";
|
|
7
|
+
import { ChevronDown, ChevronRight } from "lucide-react";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
var ExpandableContext = createContext(null);
|
|
10
|
+
function useExpandable() {
|
|
11
|
+
const value = useContext(ExpandableContext);
|
|
12
|
+
if (!value)
|
|
13
|
+
throw new Error("Expandable context is used outside it's provider!");
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function Expandable({ children, expanded = false }) {
|
|
17
|
+
const [isExpanded, setIsExpanded] = useState(expanded);
|
|
18
|
+
return /* @__PURE__ */ jsx(ExpandableContext.Provider, { value: { isExpanded, onExpand: setIsExpanded }, children });
|
|
19
|
+
}
|
|
20
|
+
function ExpandableContent({
|
|
21
|
+
children,
|
|
22
|
+
expand,
|
|
23
|
+
...rest
|
|
24
|
+
}) {
|
|
25
|
+
const { isExpanded } = useExpandable();
|
|
26
|
+
return /* @__PURE__ */ jsxs("div", { ...rest, children: [
|
|
27
|
+
children,
|
|
28
|
+
" ",
|
|
29
|
+
isExpanded && expand
|
|
30
|
+
] });
|
|
31
|
+
}
|
|
32
|
+
function ExpandableChevron() {
|
|
33
|
+
const { isExpanded, onExpand } = useExpandable();
|
|
34
|
+
return /* @__PURE__ */ jsx(
|
|
35
|
+
"button",
|
|
36
|
+
{
|
|
37
|
+
onClick: () => onExpand((e) => !e),
|
|
38
|
+
className: "p-1 h-6 w-6 hover:bg-gray-200",
|
|
39
|
+
title: isExpanded ? "Collapse" : "Expand",
|
|
40
|
+
children: isExpanded ? /* @__PURE__ */ jsx(ChevronDown, { size: 16 }) : /* @__PURE__ */ jsx(ChevronRight, { size: 16 })
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
Expandable.Content = ExpandableContent;
|
|
45
|
+
Expandable.Chevron = ExpandableChevron;
|
|
46
|
+
export {
|
|
47
|
+
Expandable
|
|
48
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mav-expandable",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
13
|
+
"dev": "tsup src/index.ts --watch",
|
|
14
|
+
"prepublishOnly": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"react": "^19",
|
|
18
|
+
"react-dom": "^19"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"lucide-react": "^0.540.0",
|
|
22
|
+
"tailwind-merge": "^3.3.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/react": "^19",
|
|
26
|
+
"@types/react-dom": "^19",
|
|
27
|
+
"tailwindcss": "^4",
|
|
28
|
+
"typescript": "^5.8.3",
|
|
29
|
+
"tsup": "^8"
|
|
30
|
+
}
|
|
31
|
+
}
|