@purr-react-styled-components/components.collapse 0.0.3 → 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.
- package/dist/index.cjs +71 -1
- package/dist/{_types.d.ts → index.d.cts} +11 -7
- package/dist/index.d.ts +59 -2
- package/dist/index.js +71 -129
- package/package.json +9 -7
- package/dist/_components/_expand-icon.d.ts +0 -4
- package/dist/_components/_item-header.d.ts +0 -4
- package/dist/_components/_item.d.ts +0 -4
- package/dist/_components/index.d.ts +0 -4
- package/dist/_styles.d.ts +0 -17
package/dist/index.cjs
CHANGED
|
@@ -1 +1,71 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';var A=require('clsx'),I=require('react'),components_divider=require('@purr-react-styled-components/components.divider'),p=require('styled-components'),utils_helpers=require('@purr-react-styled-components/utils.helpers'),components_typography=require('@purr-react-styled-components/components.typography'),components_icon=require('@purr-react-styled-components/components.icon');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var A__default=/*#__PURE__*/_interopDefault(A);var I__default=/*#__PURE__*/_interopDefault(I);var p__default=/*#__PURE__*/_interopDefault(p);var o={Container:p__default.default.div`
|
|
2
|
+
border: 1px solid #d9d9d9;
|
|
3
|
+
border-radius: 8px;
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
`,ItemContainer:p__default.default.div`
|
|
6
|
+
transition: margin 150ms ease-in-out;
|
|
7
|
+
width: 100%;
|
|
8
|
+
will-change: margin;
|
|
9
|
+
|
|
10
|
+
&:first-of-type {
|
|
11
|
+
margin-top: 0px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
&:last-of-type {
|
|
15
|
+
margin-bottom: 0px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
${({$disabled:t})=>t?p.css`
|
|
19
|
+
opacity: 0.3;
|
|
20
|
+
pointer-events: none;
|
|
21
|
+
cursor: not-allowed;
|
|
22
|
+
`:p.css`
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
`};
|
|
25
|
+
`,ItemHeader:p__default.default.button`
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
justify-content: space-between;
|
|
29
|
+
gap: 16px;
|
|
30
|
+
padding: 0px 16px;
|
|
31
|
+
width: 100%;
|
|
32
|
+
height: 46px;
|
|
33
|
+
border-bottom: 1px solid
|
|
34
|
+
${({$isExpanded:t})=>t?"#d9d9d9":"transparent"};
|
|
35
|
+
background-color: #00000005;
|
|
36
|
+
${utils_helpers.getInvisibleButton}
|
|
37
|
+
`,ItemHeaderSection:p__default.default.span`
|
|
38
|
+
display: flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
gap: 16px;
|
|
41
|
+
`,ItemHeaderSectionGroup:p__default.default.span`
|
|
42
|
+
display: flex;
|
|
43
|
+
justify-content: space-between;
|
|
44
|
+
flex-grow: 1;
|
|
45
|
+
`,ItemHeaderExpandIcon:p__default.default.span`
|
|
46
|
+
display: flex;
|
|
47
|
+
transition: all 250ms ease-in-out;
|
|
48
|
+
transform: ${({$isExpanded:t})=>t?"rotate(180deg)":"none"};
|
|
49
|
+
`,ItemContent:p__default.default.div`
|
|
50
|
+
transition:
|
|
51
|
+
max-height 150ms ease-in-out,
|
|
52
|
+
opacity 150ms ease-in-out,
|
|
53
|
+
padding-top 150ms ease-in-out,
|
|
54
|
+
padding-bottom 150ms ease-in-out;
|
|
55
|
+
padding-left: 16px;
|
|
56
|
+
padding-right: 16px;
|
|
57
|
+
overflow: hidden;
|
|
58
|
+
will-change: max-height, opacity, padding-top, padding-bottom;
|
|
59
|
+
|
|
60
|
+
${({$isExpanded:t})=>t?p.css`
|
|
61
|
+
max-height: 200vh;
|
|
62
|
+
padding-top: 16px;
|
|
63
|
+
padding-bottom: 16px;
|
|
64
|
+
opacity: 1;
|
|
65
|
+
`:p.css`
|
|
66
|
+
max-height: 0px;
|
|
67
|
+
padding-top: 0px;
|
|
68
|
+
padding-bottom: 0px;
|
|
69
|
+
opacity: 0;
|
|
70
|
+
`};
|
|
71
|
+
`};var H=I.memo(({expandIcon:t,isExpanded:r,htmlAttributes:l,showExpandIcon:n})=>(console.log("showExpandIcon",n),n?I__default.default.createElement(o.ItemHeaderExpandIcon,{...l,$isExpanded:r,className:"collapse-item__header__right__expand-icon"},t??I__default.default.createElement(components_icon.Icon,{name:"chevron-down",width:14,height:14})):null));H.displayName="CollapseItemExpandIcon";var C=I.memo(({label:t,preIcon:r,postIcon:l,expandIcon:n,isExpanded:s,isOnlyOneExpand:x,id:d,showExpandIcon:u,expandIconHtmlAttributes:y,htmlAttributes:b,labelHtmlAttributes:m,setItemDictionary:e})=>{let a=c=>()=>{e(x?i=>({...Object.keys(i).reduce((E,$)=>(E[$]=false,E),{}),[c]:!i[c]}):i=>({...i,[c]:!i[c]}));},h=I.useMemo(()=>I__default.default.createElement(o.ItemHeaderSectionGroup,null,I__default.default.createElement(o.ItemHeaderSection,{className:"collapse-item__header__left"},r,I__default.default.createElement(components_typography.Typography,{className:"collapse-item__header-label",htmlAttributes:m},t)),I__default.default.createElement(o.ItemHeaderSection,{className:"collapse-item__header__right"},l)),[t,m,l,r]);return I__default.default.createElement(o.ItemHeader,{...b,$isExpanded:s,className:"collapse-item__header",onClick:a(d)},I__default.default.createElement(H,{htmlAttributes:y,expandIcon:n,isExpanded:s,showExpandIcon:u}),h)});C.displayName="CollapseItemHeader";var _=I.memo(({id:t,label:r,body:l,preIcon:n,postIcon:s,expandIcon:x,disabled:d,bodyHtmlAttributes:u,htmlAttributes:y,expandIconHtmlAttributes:b,itemHeaderHtmlAttributes:m,itemHeaderLabelHtmlAttributes:e,isExpanded:a,isOnlyOneExpand:h,showExpandIcon:c,setItemDictionary:i})=>I__default.default.createElement(o.ItemContainer,{...y,$disabled:d,className:A__default.default("collapse-item",a&&"collapse-item--isExpanded",d&&"collapse-item--disabled")},I__default.default.createElement(C,{label:r,preIcon:n,postIcon:s,expandIcon:x,isExpanded:a,isOnlyOneExpand:h,id:t,showExpandIcon:c,expandIconHtmlAttributes:b,htmlAttributes:m,labelHtmlAttributes:e,setItemDictionary:i}),I__default.default.createElement(o.ItemContent,{...u,$isExpanded:a,className:A__default.default("collapse-item__content",a&&"collapse-item__content--isExpanded")},l)));_.displayName="CollapseItem";var pe=({items:t,className:r,isOnlyOneExpand:l=false,expandIds:n,preIcon:s=null,postIcon:x=null,expandIcon:d=null,disabled:u=false,htmlAttributes:y})=>{let[b,m]=I.useState(()=>n?n.reduce((e,a)=>(e[a]=true,e),{}):{});return I__default.default.createElement(o.Container,{...y,className:A__default.default("collapse",r)},t?.map((e,a)=>I__default.default.createElement(I.Fragment,{key:e.id},!!a&&I__default.default.createElement(components_divider.Divider,{color:"#d9d9d9",className:"collapse-divider"}),I__default.default.createElement(_,{id:e.id,label:e.label,body:e.body,preIcon:s??e.preIcon,postIcon:x??e.postIcon,expandIcon:d??e.expandIcon,disabled:u||e.disabled,bodyHtmlAttributes:e.bodyHtmlAttributes,htmlAttributes:e.htmlAttributes,expandIconHtmlAttributes:e.expandIconHtmlAttributes,itemHeaderHtmlAttributes:e.itemHeaderHtmlAttributes,itemHeaderLabelHtmlAttributes:e.itemHeaderLabelHtmlAttributes,isExpanded:e.id?!!b[e.id]:false,showExpandIcon:e.showExpandIcon??true,isOnlyOneExpand:l,setItemDictionary:m}))))};exports.Collapse=pe;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import React, { ReactNode, HTMLAttributes, ButtonHTMLAttributes, Dispatch, SetStateAction } from 'react';
|
|
2
2
|
import { IExtendable } from '@purr-core/utils.definitions';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type TItemDictionary = Record<string, boolean>;
|
|
5
|
+
interface ICollapseItem {
|
|
6
6
|
id: string;
|
|
7
7
|
label: string;
|
|
8
8
|
body: ReactNode;
|
|
@@ -17,12 +17,12 @@ export interface ICollapseItem {
|
|
|
17
17
|
itemHeaderLabelHtmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
|
|
18
18
|
showExpandIcon?: boolean;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
interface ICollapseItemProps extends ICollapseItem {
|
|
21
21
|
isExpanded: boolean;
|
|
22
22
|
isOnlyOneExpand: boolean;
|
|
23
23
|
setItemDictionary: Dispatch<SetStateAction<TItemDictionary>>;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
interface ICollapseProps {
|
|
26
26
|
items?: ICollapseItem[];
|
|
27
27
|
className?: string;
|
|
28
28
|
disabled?: boolean;
|
|
@@ -33,13 +33,13 @@ export interface ICollapseProps {
|
|
|
33
33
|
isOnlyOneExpand?: boolean;
|
|
34
34
|
htmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
interface ICollapseItemExpandIconProps {
|
|
37
37
|
expandIcon?: ReactNode;
|
|
38
38
|
isExpanded: boolean;
|
|
39
39
|
htmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
|
|
40
40
|
showExpandIcon?: boolean;
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
interface ICollapseItemHeaderProps {
|
|
43
43
|
label: string;
|
|
44
44
|
preIcon?: ReactNode;
|
|
45
45
|
postIcon?: ReactNode;
|
|
@@ -53,3 +53,7 @@ export interface ICollapseItemHeaderProps {
|
|
|
53
53
|
labelHtmlAttributes?: HTMLAttributes<HTMLElement> & IExtendable;
|
|
54
54
|
setItemDictionary: Dispatch<SetStateAction<TItemDictionary>>;
|
|
55
55
|
}
|
|
56
|
+
|
|
57
|
+
declare const Collapse: ({ items, className, isOnlyOneExpand, expandIds, preIcon, postIcon, expandIcon, disabled, htmlAttributes, }: ICollapseProps) => React.JSX.Element;
|
|
58
|
+
|
|
59
|
+
export { Collapse, type ICollapseItem, type ICollapseItemExpandIconProps, type ICollapseItemHeaderProps, type ICollapseItemProps, type ICollapseProps, type TItemDictionary };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import React, { ReactNode, HTMLAttributes, ButtonHTMLAttributes, Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { IExtendable } from '@purr-core/utils.definitions';
|
|
3
|
+
|
|
4
|
+
type TItemDictionary = Record<string, boolean>;
|
|
5
|
+
interface ICollapseItem {
|
|
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
|
+
showExpandIcon?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface ICollapseItemProps extends ICollapseItem {
|
|
21
|
+
isExpanded: boolean;
|
|
22
|
+
isOnlyOneExpand: boolean;
|
|
23
|
+
setItemDictionary: Dispatch<SetStateAction<TItemDictionary>>;
|
|
24
|
+
}
|
|
25
|
+
interface ICollapseProps {
|
|
26
|
+
items?: ICollapseItem[];
|
|
27
|
+
className?: string;
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
preIcon?: ReactNode;
|
|
30
|
+
postIcon?: ReactNode;
|
|
31
|
+
expandIcon?: ReactNode;
|
|
32
|
+
expandIds?: string[];
|
|
33
|
+
isOnlyOneExpand?: boolean;
|
|
34
|
+
htmlAttributes?: HTMLAttributes<HTMLDivElement> & IExtendable;
|
|
35
|
+
}
|
|
36
|
+
interface ICollapseItemExpandIconProps {
|
|
37
|
+
expandIcon?: ReactNode;
|
|
38
|
+
isExpanded: boolean;
|
|
39
|
+
htmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
|
|
40
|
+
showExpandIcon?: boolean;
|
|
41
|
+
}
|
|
42
|
+
interface ICollapseItemHeaderProps {
|
|
43
|
+
label: string;
|
|
44
|
+
preIcon?: ReactNode;
|
|
45
|
+
postIcon?: ReactNode;
|
|
46
|
+
expandIcon?: ReactNode;
|
|
47
|
+
isExpanded: boolean;
|
|
48
|
+
isOnlyOneExpand: boolean;
|
|
49
|
+
id: string;
|
|
50
|
+
showExpandIcon?: boolean;
|
|
51
|
+
expandIconHtmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
|
|
52
|
+
htmlAttributes?: HTMLAttributes<HTMLButtonElement> & IExtendable;
|
|
53
|
+
labelHtmlAttributes?: HTMLAttributes<HTMLElement> & IExtendable;
|
|
54
|
+
setItemDictionary: Dispatch<SetStateAction<TItemDictionary>>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare const Collapse: ({ items, className, isOnlyOneExpand, expandIds, preIcon, postIcon, expandIcon, disabled, htmlAttributes, }: ICollapseProps) => React.JSX.Element;
|
|
58
|
+
|
|
59
|
+
export { Collapse, type ICollapseItem, type ICollapseItemExpandIconProps, type ICollapseItemHeaderProps, type ICollapseItemProps, type ICollapseProps, type TItemDictionary };
|
package/dist/index.js
CHANGED
|
@@ -1,129 +1,71 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
$disabled:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
...r,
|
|
73
|
-
[h]: !r[h]
|
|
74
|
-
}));
|
|
75
|
-
}, y = S(() => /* @__PURE__ */ x(s.ItemHeaderSectionGroup, { children: [
|
|
76
|
-
/* @__PURE__ */ x(s.ItemHeaderSection, { className: "collapse-item__header__left", children: [
|
|
77
|
-
i,
|
|
78
|
-
/* @__PURE__ */ n($, { className: "collapse-item__header-label", htmlAttributes: c, children: t })
|
|
79
|
-
] }),
|
|
80
|
-
/* @__PURE__ */ n(s.ItemHeaderSection, { className: "collapse-item__header__right", children: l })
|
|
81
|
-
] }), [t, c, l, i]);
|
|
82
|
-
return /* @__PURE__ */ x(s.ItemHeader, { ...g, $isExpanded: p, className: "collapse-item__header", onClick: o(m), children: [
|
|
83
|
-
/* @__PURE__ */ n(w, { htmlAttributes: I, expandIcon: a, isExpanded: p, showExpandIcon: b }),
|
|
84
|
-
y
|
|
85
|
-
] });
|
|
86
|
-
});
|
|
87
|
-
N.displayName = "CollapseItemHeader";
|
|
88
|
-
const z = H(({
|
|
89
|
-
id: t,
|
|
90
|
-
label: i,
|
|
91
|
-
body: l,
|
|
92
|
-
preIcon: a,
|
|
93
|
-
postIcon: p,
|
|
94
|
-
expandIcon: u,
|
|
95
|
-
disabled: m,
|
|
96
|
-
bodyHtmlAttributes: b,
|
|
97
|
-
htmlAttributes: I,
|
|
98
|
-
expandIconHtmlAttributes: g,
|
|
99
|
-
itemHeaderHtmlAttributes: c,
|
|
100
|
-
itemHeaderLabelHtmlAttributes: e,
|
|
101
|
-
isExpanded: o,
|
|
102
|
-
isOnlyOneExpand: y,
|
|
103
|
-
showExpandIcon: h,
|
|
104
|
-
setItemDictionary: r
|
|
105
|
-
}) => /* @__PURE__ */ x(s.ItemContainer, { ...I, $disabled: m, className: f("collapse-item", o && "collapse-item--isExpanded", m && "collapse-item--disabled"), children: [
|
|
106
|
-
/* @__PURE__ */ n(N, { label: i, preIcon: a, postIcon: p, expandIcon: u, isExpanded: o, isOnlyOneExpand: y, id: t, showExpandIcon: h, expandIconHtmlAttributes: g, htmlAttributes: c, labelHtmlAttributes: e, setItemDictionary: r }),
|
|
107
|
-
/* @__PURE__ */ n(s.ItemContent, { ...b, $isExpanded: o, className: f("collapse-item__content", o && "collapse-item__content--isExpanded"), children: l })
|
|
108
|
-
] }));
|
|
109
|
-
z.displayName = "CollapseItem";
|
|
110
|
-
const J = ({
|
|
111
|
-
items: t,
|
|
112
|
-
className: i,
|
|
113
|
-
isOnlyOneExpand: l = !1,
|
|
114
|
-
expandIds: a,
|
|
115
|
-
preIcon: p = null,
|
|
116
|
-
postIcon: u = null,
|
|
117
|
-
expandIcon: m = null,
|
|
118
|
-
disabled: b = !1,
|
|
119
|
-
htmlAttributes: I
|
|
120
|
-
}) => {
|
|
121
|
-
const [g, c] = v(() => a ? a.reduce((e, o) => (e[o] = !0, e), {}) : {});
|
|
122
|
-
return /* @__PURE__ */ n(s.Container, { ...I, className: f("collapse", i), children: t == null ? void 0 : t.map((e, o) => /* @__PURE__ */ x(E, { children: [
|
|
123
|
-
!!o && /* @__PURE__ */ n(j, { color: "#d9d9d9", className: "collapse-divider" }),
|
|
124
|
-
/* @__PURE__ */ n(z, { id: e.id, label: e.label, body: e.body, preIcon: p ?? e.preIcon, postIcon: u ?? e.postIcon, expandIcon: m ?? e.expandIcon, disabled: b || e.disabled, bodyHtmlAttributes: e.bodyHtmlAttributes, htmlAttributes: e.htmlAttributes, expandIconHtmlAttributes: e.expandIconHtmlAttributes, itemHeaderHtmlAttributes: e.itemHeaderHtmlAttributes, itemHeaderLabelHtmlAttributes: e.itemHeaderLabelHtmlAttributes, isExpanded: e.id ? !!g[e.id] : !1, showExpandIcon: e.showExpandIcon ?? !0, isOnlyOneExpand: l, setItemDictionary: c })
|
|
125
|
-
] }, e.id)) });
|
|
126
|
-
};
|
|
127
|
-
export {
|
|
128
|
-
J as Collapse
|
|
129
|
-
};
|
|
1
|
+
import A from'clsx';import I,{memo,useMemo,useState,Fragment}from'react';import {Divider}from'@purr-react-styled-components/components.divider';import p,{css}from'styled-components';import {getInvisibleButton}from'@purr-react-styled-components/utils.helpers';import {Typography}from'@purr-react-styled-components/components.typography';import {Icon}from'@purr-react-styled-components/components.icon';var o={Container:p.div`
|
|
2
|
+
border: 1px solid #d9d9d9;
|
|
3
|
+
border-radius: 8px;
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
`,ItemContainer:p.div`
|
|
6
|
+
transition: margin 150ms ease-in-out;
|
|
7
|
+
width: 100%;
|
|
8
|
+
will-change: margin;
|
|
9
|
+
|
|
10
|
+
&:first-of-type {
|
|
11
|
+
margin-top: 0px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
&:last-of-type {
|
|
15
|
+
margin-bottom: 0px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
${({$disabled:t})=>t?css`
|
|
19
|
+
opacity: 0.3;
|
|
20
|
+
pointer-events: none;
|
|
21
|
+
cursor: not-allowed;
|
|
22
|
+
`:css`
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
`};
|
|
25
|
+
`,ItemHeader:p.button`
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
justify-content: space-between;
|
|
29
|
+
gap: 16px;
|
|
30
|
+
padding: 0px 16px;
|
|
31
|
+
width: 100%;
|
|
32
|
+
height: 46px;
|
|
33
|
+
border-bottom: 1px solid
|
|
34
|
+
${({$isExpanded:t})=>t?"#d9d9d9":"transparent"};
|
|
35
|
+
background-color: #00000005;
|
|
36
|
+
${getInvisibleButton}
|
|
37
|
+
`,ItemHeaderSection:p.span`
|
|
38
|
+
display: flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
gap: 16px;
|
|
41
|
+
`,ItemHeaderSectionGroup:p.span`
|
|
42
|
+
display: flex;
|
|
43
|
+
justify-content: space-between;
|
|
44
|
+
flex-grow: 1;
|
|
45
|
+
`,ItemHeaderExpandIcon:p.span`
|
|
46
|
+
display: flex;
|
|
47
|
+
transition: all 250ms ease-in-out;
|
|
48
|
+
transform: ${({$isExpanded:t})=>t?"rotate(180deg)":"none"};
|
|
49
|
+
`,ItemContent:p.div`
|
|
50
|
+
transition:
|
|
51
|
+
max-height 150ms ease-in-out,
|
|
52
|
+
opacity 150ms ease-in-out,
|
|
53
|
+
padding-top 150ms ease-in-out,
|
|
54
|
+
padding-bottom 150ms ease-in-out;
|
|
55
|
+
padding-left: 16px;
|
|
56
|
+
padding-right: 16px;
|
|
57
|
+
overflow: hidden;
|
|
58
|
+
will-change: max-height, opacity, padding-top, padding-bottom;
|
|
59
|
+
|
|
60
|
+
${({$isExpanded:t})=>t?css`
|
|
61
|
+
max-height: 200vh;
|
|
62
|
+
padding-top: 16px;
|
|
63
|
+
padding-bottom: 16px;
|
|
64
|
+
opacity: 1;
|
|
65
|
+
`:css`
|
|
66
|
+
max-height: 0px;
|
|
67
|
+
padding-top: 0px;
|
|
68
|
+
padding-bottom: 0px;
|
|
69
|
+
opacity: 0;
|
|
70
|
+
`};
|
|
71
|
+
`};var H=memo(({expandIcon:t,isExpanded:r,htmlAttributes:l,showExpandIcon:n})=>(console.log("showExpandIcon",n),n?I.createElement(o.ItemHeaderExpandIcon,{...l,$isExpanded:r,className:"collapse-item__header__right__expand-icon"},t??I.createElement(Icon,{name:"chevron-down",width:14,height:14})):null));H.displayName="CollapseItemExpandIcon";var C=memo(({label:t,preIcon:r,postIcon:l,expandIcon:n,isExpanded:s,isOnlyOneExpand:x,id:d,showExpandIcon:u,expandIconHtmlAttributes:y,htmlAttributes:b,labelHtmlAttributes:m,setItemDictionary:e})=>{let a=c=>()=>{e(x?i=>({...Object.keys(i).reduce((E,$)=>(E[$]=false,E),{}),[c]:!i[c]}):i=>({...i,[c]:!i[c]}));},h=useMemo(()=>I.createElement(o.ItemHeaderSectionGroup,null,I.createElement(o.ItemHeaderSection,{className:"collapse-item__header__left"},r,I.createElement(Typography,{className:"collapse-item__header-label",htmlAttributes:m},t)),I.createElement(o.ItemHeaderSection,{className:"collapse-item__header__right"},l)),[t,m,l,r]);return I.createElement(o.ItemHeader,{...b,$isExpanded:s,className:"collapse-item__header",onClick:a(d)},I.createElement(H,{htmlAttributes:y,expandIcon:n,isExpanded:s,showExpandIcon:u}),h)});C.displayName="CollapseItemHeader";var _=memo(({id:t,label:r,body:l,preIcon:n,postIcon:s,expandIcon:x,disabled:d,bodyHtmlAttributes:u,htmlAttributes:y,expandIconHtmlAttributes:b,itemHeaderHtmlAttributes:m,itemHeaderLabelHtmlAttributes:e,isExpanded:a,isOnlyOneExpand:h,showExpandIcon:c,setItemDictionary:i})=>I.createElement(o.ItemContainer,{...y,$disabled:d,className:A("collapse-item",a&&"collapse-item--isExpanded",d&&"collapse-item--disabled")},I.createElement(C,{label:r,preIcon:n,postIcon:s,expandIcon:x,isExpanded:a,isOnlyOneExpand:h,id:t,showExpandIcon:c,expandIconHtmlAttributes:b,htmlAttributes:m,labelHtmlAttributes:e,setItemDictionary:i}),I.createElement(o.ItemContent,{...u,$isExpanded:a,className:A("collapse-item__content",a&&"collapse-item__content--isExpanded")},l)));_.displayName="CollapseItem";var pe=({items:t,className:r,isOnlyOneExpand:l=false,expandIds:n,preIcon:s=null,postIcon:x=null,expandIcon:d=null,disabled:u=false,htmlAttributes:y})=>{let[b,m]=useState(()=>n?n.reduce((e,a)=>(e[a]=true,e),{}):{});return I.createElement(o.Container,{...y,className:A("collapse",r)},t?.map((e,a)=>I.createElement(Fragment,{key:e.id},!!a&&I.createElement(Divider,{color:"#d9d9d9",className:"collapse-divider"}),I.createElement(_,{id:e.id,label:e.label,body:e.body,preIcon:s??e.preIcon,postIcon:x??e.postIcon,expandIcon:d??e.expandIcon,disabled:u||e.disabled,bodyHtmlAttributes:e.bodyHtmlAttributes,htmlAttributes:e.htmlAttributes,expandIconHtmlAttributes:e.expandIconHtmlAttributes,itemHeaderHtmlAttributes:e.itemHeaderHtmlAttributes,itemHeaderLabelHtmlAttributes:e.itemHeaderLabelHtmlAttributes,isExpanded:e.id?!!b[e.id]:false,showExpandIcon:e.showExpandIcon??true,isOnlyOneExpand:l,setItemDictionary:m}))))};export{pe as Collapse};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purr-react-styled-components/components.collapse",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"react": "*",
|
|
26
26
|
"styled-components": "*",
|
|
27
27
|
"clsx": "*",
|
|
28
|
-
"@purr-core/utils.definitions": "0.0.
|
|
29
|
-
"@purr-react-styled-components/utils.helpers": "0.0.
|
|
30
|
-
"@purr-react-styled-components/components.icon": "0.0.
|
|
31
|
-
"@purr-react-styled-components/components.typography": "0.0.
|
|
32
|
-
"@purr-react-styled-components/components.divider": "0.0.
|
|
28
|
+
"@purr-core/utils.definitions": "0.0.12",
|
|
29
|
+
"@purr-react-styled-components/utils.helpers": "0.0.8",
|
|
30
|
+
"@purr-react-styled-components/components.icon": "0.0.9",
|
|
31
|
+
"@purr-react-styled-components/components.typography": "0.0.10",
|
|
32
|
+
"@purr-react-styled-components/components.divider": "0.0.5"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@purr-react-styled-components/components.flex-box": "0.0.
|
|
35
|
+
"@purr-react-styled-components/components.flex-box": "0.0.10"
|
|
36
36
|
},
|
|
37
37
|
"author": "@DinhThienPhuc",
|
|
38
38
|
"license": "ISC",
|
|
@@ -41,6 +41,8 @@
|
|
|
41
41
|
"scripts": {
|
|
42
42
|
"dev": "vite build --watch",
|
|
43
43
|
"build": "tsc && vite build",
|
|
44
|
+
"build:vite": "tsc && vite build",
|
|
45
|
+
"build:tsup": "tsup",
|
|
44
46
|
"lint": "eslint . --ext ts,tsx --max-warnings 0"
|
|
45
47
|
}
|
|
46
48
|
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
|
-
import { ICollapseItemExpandIconProps } from '../_types';
|
|
3
|
-
|
|
4
|
-
export declare const CollapseItemExpandIcon: React.MemoExoticComponent<({ expandIcon, isExpanded, htmlAttributes, showExpandIcon, }: ICollapseItemExpandIconProps) => React.JSX.Element | null>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
|
-
import { ICollapseItemHeaderProps } from '../_types';
|
|
3
|
-
|
|
4
|
-
export declare const CollapseItemHeader: React.MemoExoticComponent<({ label, preIcon, postIcon, expandIcon, isExpanded, isOnlyOneExpand, id, showExpandIcon, expandIconHtmlAttributes, htmlAttributes, labelHtmlAttributes, setItemDictionary, }: ICollapseItemHeaderProps) => React.JSX.Element>;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { default as React } from 'react';
|
|
2
|
-
import { ICollapseItemProps } from '../_types';
|
|
3
|
-
|
|
4
|
-
export declare const CollapseItem: React.MemoExoticComponent<({ id, label, body, preIcon, postIcon, expandIcon, disabled, bodyHtmlAttributes, htmlAttributes, expandIconHtmlAttributes, itemHeaderHtmlAttributes, itemHeaderLabelHtmlAttributes, isExpanded, isOnlyOneExpand, showExpandIcon, setItemDictionary, }: ICollapseItemProps) => React.JSX.Element>;
|
package/dist/_styles.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare const Styled: {
|
|
2
|
-
Container: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
3
|
-
ItemContainer: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
|
|
4
|
-
$disabled?: boolean;
|
|
5
|
-
}>> & string;
|
|
6
|
-
ItemHeader: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, {
|
|
7
|
-
$isExpanded: boolean;
|
|
8
|
-
}>> & string;
|
|
9
|
-
ItemHeaderSection: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>> & string;
|
|
10
|
-
ItemHeaderSectionGroup: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components').FastOmit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>> & string;
|
|
11
|
-
ItemHeaderExpandIcon: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, {
|
|
12
|
-
$isExpanded: boolean;
|
|
13
|
-
}>> & string;
|
|
14
|
-
ItemContent: import('styled-components/dist/types').IStyledComponentBase<"web", import('styled-components/dist/types').Substitute<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
|
|
15
|
-
$isExpanded: boolean;
|
|
16
|
-
}>> & string;
|
|
17
|
-
};
|