@purr-react-tailwindcss/components.accordion 0.0.5

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
+ import { default as React } from 'react';
2
+ import { IAccordionItemExpandIconProps } from '../_types';
3
+
4
+ export declare const AccordionItemExpandIcon: React.MemoExoticComponent<({ expandIcon, isExpanded, htmlAttributes, }: IAccordionItemExpandIconProps) => React.JSX.Element>;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { IAccordionItemHeaderProps } from '../_types';
3
+
4
+ export declare const AccordionItemHeader: React.MemoExoticComponent<({ label, preIcon, postIcon, expandIcon, disabled, isExpanded, isOnlyOneExpand, id, expandIconHtmlAttributes, htmlAttributes, labelHtmlAttributes, setItemDictionary, }: IAccordionItemHeaderProps) => React.JSX.Element>;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { IAccordionItemProps } from '../_types';
3
+
4
+ export declare const AccordionItem: React.MemoExoticComponent<({ id, label, body, preIcon, postIcon, expandIcon, disabled, bodyHtmlAttributes, htmlAttributes, expandIconHtmlAttributes, itemHeaderHtmlAttributes, itemHeaderLabelHtmlAttributes, isExpanded, isOnlyOneExpand, setItemDictionary, }: IAccordionItemProps) => React.JSX.Element>;
@@ -0,0 +1,4 @@
1
+ import { default as React } from 'react';
2
+ import { IAccordionProps } from '../_types';
3
+
4
+ export declare const Accordion: ({ items, isOnlyOneExpand, expandIds, preIcon, postIcon, expandIcon, disabled, htmlAttributes, }: IAccordionProps) => React.JSX.Element;
@@ -0,0 +1,52 @@
1
+ import { ButtonHTMLAttributes, Dispatch, HTMLAttributes, ReactNode, SetStateAction } from 'react';
2
+ import { IExtendable } from '@purr-core/utils.definitions';
3
+
4
+ export type TItemDictionary = Record<string, boolean>;
5
+ export interface IAccordionItem {
6
+ id: string;
7
+ label: string;
8
+ body: ReactNode;
9
+ preIcon?: ReactNode;
10
+ postIcon?: ReactNode;
11
+ expandIcon?: ReactNode;
12
+ disabled?: boolean;
13
+ bodyHtmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
14
+ htmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
15
+ expandIconHtmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
16
+ itemHeaderHtmlAttributes?: ButtonHTMLAttributes<HTMLButtonElement> & IExtendable;
17
+ itemHeaderLabelHtmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
18
+ }
19
+ export interface IAccordionItemProps extends IAccordionItem {
20
+ isExpanded: boolean;
21
+ isOnlyOneExpand: boolean;
22
+ setItemDictionary: Dispatch<SetStateAction<TItemDictionary>>;
23
+ }
24
+ export interface IAccordionProps {
25
+ items?: IAccordionItem[];
26
+ disabled?: boolean;
27
+ preIcon?: ReactNode;
28
+ postIcon?: ReactNode;
29
+ expandIcon?: ReactNode;
30
+ expandIds?: string[];
31
+ isOnlyOneExpand?: boolean;
32
+ htmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
33
+ }
34
+ export interface IAccordionItemExpandIconProps {
35
+ expandIcon?: ReactNode;
36
+ isExpanded: boolean;
37
+ htmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
38
+ }
39
+ export interface IAccordionItemHeaderProps {
40
+ label: string;
41
+ preIcon?: ReactNode;
42
+ postIcon?: ReactNode;
43
+ expandIcon?: ReactNode;
44
+ disabled?: boolean;
45
+ isExpanded: boolean;
46
+ isOnlyOneExpand: boolean;
47
+ id: string;
48
+ expandIconHtmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
49
+ htmlAttributes?: HTMLAttributes<HTMLButtonElement> & IExtendable;
50
+ labelHtmlAttributes?: HTMLAttributes<HTMLElement> & IExtendable;
51
+ setItemDictionary: Dispatch<SetStateAction<TItemDictionary>>;
52
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),b=require("react"),h=require("clsx"),H=require("@purr-react-tailwindcss/components.icon"),A=b.memo(({expandIcon:n,isExpanded:o,htmlAttributes:r})=>t.jsx("span",{className:h("duration-250 flex h-5 w-5 items-center justify-center transition-all ease-in-out",o?"rotate-180":"","accordion-item__header__right__expand-icon"),...r,children:n??t.jsx(H.Icon,{name:"chevron-down"})}));A.displayName="AccordionItemExpandIcon";const j=b.memo(({label:n,preIcon:o,postIcon:r,expandIcon:i,disabled:c,isExpanded:l,isOnlyOneExpand:d,id:u,expandIconHtmlAttributes:m,htmlAttributes:x,labelHtmlAttributes:e,setItemDictionary:a})=>{const p=s=>()=>{a(d?_=>({...Object.keys(_).reduce((y,w)=>(y[w]=!1,y),{}),[s]:!_[s]}):_=>({..._,[s]:!_[s]}))},f=b.useMemo(()=>t.jsxs("span",{className:"flex flex-grow justify-between",children:[t.jsxs("span",{className:"accordion-item__header__left flex gap-4",children:[o,t.jsx("span",{className:"accordion-item__header-label font-sans",...e,children:n})]}),t.jsx("span",{className:"accordion-item__header__right flex gap-4",children:r})]}),[n,e,r,o]);return t.jsxs("button",{className:h("flex h-12 w-full items-center justify-between gap-4 p-0 px-4",c?"bg-white/12 pointer-events-none cursor-default text-white/50":"cursor-pointer bg-transparent text-white","accordion-item__header"),onClick:p(u),...x,children:[f,t.jsx(A,{htmlAttributes:m,expandIcon:i,isExpanded:l})]})});j.displayName="AccordionItemHeader";const g=b.memo(({id:n,label:o,body:r,preIcon:i,postIcon:c,expandIcon:l,disabled:d,bodyHtmlAttributes:u,htmlAttributes:m,expandIconHtmlAttributes:x,itemHeaderHtmlAttributes:e,itemHeaderLabelHtmlAttributes:a,isExpanded:p,isOnlyOneExpand:f,setItemDictionary:s})=>t.jsxs("div",{className:h("w-full bg-gray-900 shadow-[0px_2px_1px_-1px_#00000033,0px_1px_1px_0px_#00000024,0px_1px_3px_0px_#0000001f] transition-[margin] duration-150 ease-in-out will-change-[margin]",p?"my-4":"my-0","not-first:border-t not-first:border-gray-200 first:mt-0 last:mb-0","accordion-item"),...m,children:[t.jsx(j,{label:o,preIcon:i,postIcon:c,expandIcon:l,disabled:d,isExpanded:p,isOnlyOneExpand:f,id:n,expandIconHtmlAttributes:x,htmlAttributes:e,labelHtmlAttributes:a,setItemDictionary:s}),t.jsx("div",{className:h("overflow-hidden px-4 transition-all duration-150 ease-in-out will-change-auto",p?"accordion-item__content--isExpanded max-h-[200vh] pb-4 pt-4 opacity-100":"accordion-item__content--isExpanded max-h-0 pb-0 pt-0 opacity-0","accordion-item__content"),...u,children:r})]}));g.displayName="AccordionItem";const I=({items:n,isOnlyOneExpand:o=!1,expandIds:r,preIcon:i=null,postIcon:c=null,expandIcon:l=null,disabled:d=!1,htmlAttributes:u})=>{const[m,x]=b.useState(()=>r?r.reduce((e,a)=>(e[a]=!0,e),{}):{});return t.jsx("div",{className:"accordion text-white",...u,children:n==null?void 0:n.map(e=>t.jsx(g,{id:e.id,label:e.label,body:e.body,preIcon:i??e.preIcon,postIcon:c??e.postIcon,expandIcon:l??e.expandIcon,disabled:d||e.disabled,bodyHtmlAttributes:e.bodyHtmlAttributes,htmlAttributes:e.htmlAttributes,expandIconHtmlAttributes:e.expandIconHtmlAttributes,itemHeaderHtmlAttributes:e.itemHeaderHtmlAttributes,itemHeaderLabelHtmlAttributes:e.itemHeaderLabelHtmlAttributes,isExpanded:e.id?!!m[e.id]:!1,isOnlyOneExpand:o,setItemDictionary:x},e.id))})};exports.Accordion=I;
@@ -0,0 +1,2 @@
1
+ export * from './_components';
2
+ export * from './_types';
package/dist/index.js ADDED
@@ -0,0 +1,189 @@
1
+ import { jsx as r, jsxs as b } from "react/jsx-runtime";
2
+ import { memo as A, useMemo as N, useState as j } from "react";
3
+ import h from "clsx";
4
+ import { Icon as v } from "@purr-react-tailwindcss/components.icon";
5
+ const g = A(
6
+ ({
7
+ expandIcon: t,
8
+ isExpanded: o,
9
+ htmlAttributes: n
10
+ }) => /* @__PURE__ */ r(
11
+ "span",
12
+ {
13
+ className: h(
14
+ "duration-250 flex h-5 w-5 items-center justify-center transition-all ease-in-out",
15
+ o ? "rotate-180" : "",
16
+ "accordion-item__header__right__expand-icon"
17
+ ),
18
+ ...n,
19
+ children: t ?? /* @__PURE__ */ r(v, { name: "chevron-down" })
20
+ }
21
+ )
22
+ );
23
+ g.displayName = "AccordionItemExpandIcon";
24
+ const w = A(
25
+ ({
26
+ label: t,
27
+ preIcon: o,
28
+ postIcon: n,
29
+ expandIcon: c,
30
+ disabled: s,
31
+ isExpanded: l,
32
+ isOnlyOneExpand: d,
33
+ id: m,
34
+ expandIconHtmlAttributes: p,
35
+ htmlAttributes: u,
36
+ labelHtmlAttributes: e,
37
+ setItemDictionary: a
38
+ }) => {
39
+ const x = (i) => () => {
40
+ a(d ? (_) => ({
41
+ ...Object.keys(_).reduce(
42
+ (y, I) => (y[I] = !1, y),
43
+ {}
44
+ ),
45
+ [i]: !_[i]
46
+ }) : (_) => ({ ..._, [i]: !_[i] }));
47
+ }, f = N(
48
+ () => /* @__PURE__ */ b("span", { className: "flex flex-grow justify-between", children: [
49
+ /* @__PURE__ */ b("span", { className: "accordion-item__header__left flex gap-4", children: [
50
+ o,
51
+ /* @__PURE__ */ r(
52
+ "span",
53
+ {
54
+ className: "accordion-item__header-label font-sans",
55
+ ...e,
56
+ children: t
57
+ }
58
+ )
59
+ ] }),
60
+ /* @__PURE__ */ r("span", { className: "accordion-item__header__right flex gap-4", children: n })
61
+ ] }),
62
+ [t, e, n, o]
63
+ );
64
+ return /* @__PURE__ */ b(
65
+ "button",
66
+ {
67
+ className: h(
68
+ "flex h-12 w-full items-center justify-between gap-4 p-0 px-4",
69
+ s ? "bg-white/12 pointer-events-none cursor-default text-white/50" : "cursor-pointer bg-transparent text-white",
70
+ "accordion-item__header"
71
+ ),
72
+ onClick: x(m),
73
+ ...u,
74
+ children: [
75
+ f,
76
+ /* @__PURE__ */ r(
77
+ g,
78
+ {
79
+ htmlAttributes: p,
80
+ expandIcon: c,
81
+ isExpanded: l
82
+ }
83
+ )
84
+ ]
85
+ }
86
+ );
87
+ }
88
+ );
89
+ w.displayName = "AccordionItemHeader";
90
+ const H = A(
91
+ ({
92
+ id: t,
93
+ label: o,
94
+ body: n,
95
+ preIcon: c,
96
+ postIcon: s,
97
+ expandIcon: l,
98
+ disabled: d,
99
+ bodyHtmlAttributes: m,
100
+ htmlAttributes: p,
101
+ expandIconHtmlAttributes: u,
102
+ itemHeaderHtmlAttributes: e,
103
+ itemHeaderLabelHtmlAttributes: a,
104
+ isExpanded: x,
105
+ isOnlyOneExpand: f,
106
+ setItemDictionary: i
107
+ }) => /* @__PURE__ */ b(
108
+ "div",
109
+ {
110
+ className: h(
111
+ "w-full bg-gray-900 shadow-[0px_2px_1px_-1px_#00000033,0px_1px_1px_0px_#00000024,0px_1px_3px_0px_#0000001f] transition-[margin] duration-150 ease-in-out will-change-[margin]",
112
+ x ? "my-4" : "my-0",
113
+ "not-first:border-t not-first:border-gray-200 first:mt-0 last:mb-0",
114
+ "accordion-item"
115
+ ),
116
+ ...p,
117
+ children: [
118
+ /* @__PURE__ */ r(
119
+ w,
120
+ {
121
+ label: o,
122
+ preIcon: c,
123
+ postIcon: s,
124
+ expandIcon: l,
125
+ disabled: d,
126
+ isExpanded: x,
127
+ isOnlyOneExpand: f,
128
+ id: t,
129
+ expandIconHtmlAttributes: u,
130
+ htmlAttributes: e,
131
+ labelHtmlAttributes: a,
132
+ setItemDictionary: i
133
+ }
134
+ ),
135
+ /* @__PURE__ */ r(
136
+ "div",
137
+ {
138
+ className: h(
139
+ "overflow-hidden px-4 transition-all duration-150 ease-in-out will-change-auto",
140
+ x ? "accordion-item__content--isExpanded max-h-[200vh] pb-4 pt-4 opacity-100" : "accordion-item__content--isExpanded max-h-0 pb-0 pt-0 opacity-0",
141
+ "accordion-item__content"
142
+ ),
143
+ ...m,
144
+ children: n
145
+ }
146
+ )
147
+ ]
148
+ }
149
+ )
150
+ );
151
+ H.displayName = "AccordionItem";
152
+ const S = ({
153
+ items: t,
154
+ isOnlyOneExpand: o = !1,
155
+ expandIds: n,
156
+ preIcon: c = null,
157
+ postIcon: s = null,
158
+ expandIcon: l = null,
159
+ disabled: d = !1,
160
+ htmlAttributes: m
161
+ }) => {
162
+ const [p, u] = j(
163
+ () => n ? n.reduce((e, a) => (e[a] = !0, e), {}) : {}
164
+ );
165
+ return /* @__PURE__ */ r("div", { className: "accordion text-white", ...m, children: t == null ? void 0 : t.map((e) => /* @__PURE__ */ r(
166
+ H,
167
+ {
168
+ id: e.id,
169
+ label: e.label,
170
+ body: e.body,
171
+ preIcon: c ?? e.preIcon,
172
+ postIcon: s ?? e.postIcon,
173
+ expandIcon: l ?? e.expandIcon,
174
+ disabled: d || e.disabled,
175
+ bodyHtmlAttributes: e.bodyHtmlAttributes,
176
+ htmlAttributes: e.htmlAttributes,
177
+ expandIconHtmlAttributes: e.expandIconHtmlAttributes,
178
+ itemHeaderHtmlAttributes: e.itemHeaderHtmlAttributes,
179
+ itemHeaderLabelHtmlAttributes: e.itemHeaderLabelHtmlAttributes,
180
+ isExpanded: e.id ? !!p[e.id] : !1,
181
+ isOnlyOneExpand: o,
182
+ setItemDictionary: u
183
+ },
184
+ e.id
185
+ )) });
186
+ };
187
+ export {
188
+ S as Accordion
189
+ };
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@purr-react-tailwindcss/components.accordion",
3
+ "version": "0.0.5",
4
+ "type": "module",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.ts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "peerDependencies": {
24
+ "typescript": "*",
25
+ "react": "*",
26
+ "clsx": "*",
27
+ "@purr-core/utils.definitions": "0.0.10",
28
+ "@purr-react-tailwindcss/components.icon": "0.0.6",
29
+ "@purr-react-styled-components/utils.helpers": "0.0.6"
30
+ },
31
+ "author": "@DinhThienPhuc",
32
+ "license": "ISC",
33
+ "description": "",
34
+ "sideEffects": false,
35
+ "scripts": {
36
+ "dev": "vite build --watch",
37
+ "build": "tsc && vite build",
38
+ "lint": "eslint . --ext ts,tsx --max-warnings 0"
39
+ }
40
+ }