@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 CHANGED
@@ -1 +1,71 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),y=require("clsx"),h=require("react"),N=require("@purr-react-styled-components/components.divider"),n=require("styled-components"),z=require("@purr-react-styled-components/utils.helpers"),A=require("@purr-react-styled-components/components.typography"),S=require("@purr-react-styled-components/components.icon"),r={Container:n.div.withConfig({displayName:"_styles__Container",componentId:"sc-ob6zrz-0"})(["border:1px solid #d9d9d9;border-radius:8px;overflow:hidden;"]),ItemContainer:n.div.withConfig({displayName:"_styles__ItemContainer",componentId:"sc-ob6zrz-1"})(["transition:margin 150ms ease-in-out;width:100%;will-change:margin;&:first-of-type{margin-top:0px;}&:last-of-type{margin-bottom:0px;}",";"],({$disabled:t})=>t?n.css(["opacity:0.3;pointer-events:none;cursor:not-allowed;"]):n.css(["cursor:pointer;"])),ItemHeader:n.button.withConfig({displayName:"_styles__ItemHeader",componentId:"sc-ob6zrz-2"})(["display:flex;align-items:center;justify-content:space-between;gap:16px;padding:0px 16px;width:100%;height:46px;border-bottom:1px solid ",";background-color:#00000005;",""],({$isExpanded:t})=>t?"#d9d9d9":"transparent",z.getInvisibleButton),ItemHeaderSection:n.span.withConfig({displayName:"_styles__ItemHeaderSection",componentId:"sc-ob6zrz-3"})(["display:flex;align-items:center;gap:16px;"]),ItemHeaderSectionGroup:n.span.withConfig({displayName:"_styles__ItemHeaderSectionGroup",componentId:"sc-ob6zrz-4"})(["display:flex;justify-content:space-between;flex-grow:1;"]),ItemHeaderExpandIcon:n.span.withConfig({displayName:"_styles__ItemHeaderExpandIcon",componentId:"sc-ob6zrz-5"})(["display:flex;transition:all 250ms ease-in-out;transform:",";"],({$isExpanded:t})=>t?"rotate(180deg)":"none"),ItemContent:n.div.withConfig({displayName:"_styles__ItemContent",componentId:"sc-ob6zrz-6"})(["transition:max-height 150ms ease-in-out,opacity 150ms ease-in-out,padding-top 150ms ease-in-out,padding-bottom 150ms ease-in-out;padding-left:16px;padding-right:16px;overflow:hidden;will-change:max-height,opacity,padding-top,padding-bottom;",";"],({$isExpanded:t})=>t?n.css(["max-height:200vh;padding-top:16px;padding-bottom:16px;opacity:1;"]):n.css(["max-height:0px;padding-top:0px;padding-bottom:0px;opacity:0;"]))},H=h.memo(({expandIcon:t,isExpanded:i,htmlAttributes:l,showExpandIcon:a})=>(console.log("showExpandIcon",a),a?o.jsx(r.ItemHeaderExpandIcon,{...l,$isExpanded:i,className:"collapse-item__header__right__expand-icon",children:t??o.jsx(S.Icon,{name:"chevron-down",width:14,height:14})}):null));H.displayName="CollapseItemExpandIcon";const C=h.memo(({label:t,preIcon:i,postIcon:l,expandIcon:a,isExpanded:c,isOnlyOneExpand:x,id:p,showExpandIcon:b,expandIconHtmlAttributes:g,htmlAttributes:I,labelHtmlAttributes:m,setItemDictionary:e})=>{const s=u=>()=>{e(x?d=>({...Object.keys(d).reduce((f,j)=>(f[j]=!1,f),{}),[u]:!d[u]}):d=>({...d,[u]:!d[u]}))},_=h.useMemo(()=>o.jsxs(r.ItemHeaderSectionGroup,{children:[o.jsxs(r.ItemHeaderSection,{className:"collapse-item__header__left",children:[i,o.jsx(A.Typography,{className:"collapse-item__header-label",htmlAttributes:m,children:t})]}),o.jsx(r.ItemHeaderSection,{className:"collapse-item__header__right",children:l})]}),[t,m,l,i]);return o.jsxs(r.ItemHeader,{...I,$isExpanded:c,className:"collapse-item__header",onClick:s(p),children:[o.jsx(H,{htmlAttributes:g,expandIcon:a,isExpanded:c,showExpandIcon:b}),_]})});C.displayName="CollapseItemHeader";const w=h.memo(({id:t,label:i,body:l,preIcon:a,postIcon:c,expandIcon:x,disabled:p,bodyHtmlAttributes:b,htmlAttributes:g,expandIconHtmlAttributes:I,itemHeaderHtmlAttributes:m,itemHeaderLabelHtmlAttributes:e,isExpanded:s,isOnlyOneExpand:_,showExpandIcon:u,setItemDictionary:d})=>o.jsxs(r.ItemContainer,{...g,$disabled:p,className:y("collapse-item",s&&"collapse-item--isExpanded",p&&"collapse-item--disabled"),children:[o.jsx(C,{label:i,preIcon:a,postIcon:c,expandIcon:x,isExpanded:s,isOnlyOneExpand:_,id:t,showExpandIcon:u,expandIconHtmlAttributes:I,htmlAttributes:m,labelHtmlAttributes:e,setItemDictionary:d}),o.jsx(r.ItemContent,{...b,$isExpanded:s,className:y("collapse-item__content",s&&"collapse-item__content--isExpanded"),children:l})]}));w.displayName="CollapseItem";const v=({items:t,className:i,isOnlyOneExpand:l=!1,expandIds:a,preIcon:c=null,postIcon:x=null,expandIcon:p=null,disabled:b=!1,htmlAttributes:g})=>{const[I,m]=h.useState(()=>a?a.reduce((e,s)=>(e[s]=!0,e),{}):{});return o.jsx(r.Container,{...g,className:y("collapse",i),children:t==null?void 0:t.map((e,s)=>o.jsxs(h.Fragment,{children:[!!s&&o.jsx(N.Divider,{color:"#d9d9d9",className:"collapse-divider"}),o.jsx(w,{id:e.id,label:e.label,body:e.body,preIcon:c??e.preIcon,postIcon:x??e.postIcon,expandIcon:p??e.expandIcon,disabled:b||e.disabled,bodyHtmlAttributes:e.bodyHtmlAttributes,htmlAttributes:e.htmlAttributes,expandIconHtmlAttributes:e.expandIconHtmlAttributes,itemHeaderHtmlAttributes:e.itemHeaderHtmlAttributes,itemHeaderLabelHtmlAttributes:e.itemHeaderLabelHtmlAttributes,isExpanded:e.id?!!I[e.id]:!1,showExpandIcon:e.showExpandIcon??!0,isOnlyOneExpand:l,setItemDictionary:m})]},e.id))})};exports.Collapse=v;
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 { ButtonHTMLAttributes, Dispatch, HTMLAttributes, ReactNode, SetStateAction } from 'react';
1
+ import React, { ReactNode, HTMLAttributes, ButtonHTMLAttributes, Dispatch, SetStateAction } from 'react';
2
2
  import { IExtendable } from '@purr-core/utils.definitions';
3
3
 
4
- export type TItemDictionary = Record<string, boolean>;
5
- export interface ICollapseItem {
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
- export interface ICollapseItemProps extends ICollapseItem {
20
+ interface ICollapseItemProps extends ICollapseItem {
21
21
  isExpanded: boolean;
22
22
  isOnlyOneExpand: boolean;
23
23
  setItemDictionary: Dispatch<SetStateAction<TItemDictionary>>;
24
24
  }
25
- export interface ICollapseProps {
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
- export interface ICollapseItemExpandIconProps {
36
+ interface ICollapseItemExpandIconProps {
37
37
  expandIcon?: ReactNode;
38
38
  isExpanded: boolean;
39
39
  htmlAttributes?: HTMLAttributes<HTMLSpanElement> & IExtendable;
40
40
  showExpandIcon?: boolean;
41
41
  }
42
- export interface ICollapseItemHeaderProps {
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
- export * from './_components';
2
- export * from './_types';
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 { jsx as n, jsxs as x } from "react/jsx-runtime";
2
- import f from "clsx";
3
- import { memo as H, useMemo as S, useState as v, Fragment as E } from "react";
4
- import { Divider as j } from "@purr-react-styled-components/components.divider";
5
- import d, { css as _ } from "styled-components";
6
- import { getInvisibleButton as k } from "@purr-react-styled-components/utils.helpers";
7
- import { Typography as $ } from "@purr-react-styled-components/components.typography";
8
- import { Icon as G } from "@purr-react-styled-components/components.icon";
9
- const s = {
10
- Container: d.div.withConfig({
11
- displayName: "_styles__Container",
12
- componentId: "sc-ob6zrz-0"
13
- })(["border:1px solid #d9d9d9;border-radius:8px;overflow:hidden;"]),
14
- ItemContainer: d.div.withConfig({
15
- displayName: "_styles__ItemContainer",
16
- componentId: "sc-ob6zrz-1"
17
- })(["transition:margin 150ms ease-in-out;width:100%;will-change:margin;&:first-of-type{margin-top:0px;}&:last-of-type{margin-bottom:0px;}", ";"], ({
18
- $disabled: t
19
- }) => t ? _(["opacity:0.3;pointer-events:none;cursor:not-allowed;"]) : _(["cursor:pointer;"])),
20
- ItemHeader: d.button.withConfig({
21
- displayName: "_styles__ItemHeader",
22
- componentId: "sc-ob6zrz-2"
23
- })(["display:flex;align-items:center;justify-content:space-between;gap:16px;padding:0px 16px;width:100%;height:46px;border-bottom:1px solid ", ";background-color:#00000005;", ""], ({
24
- $isExpanded: t
25
- }) => t ? "#d9d9d9" : "transparent", k),
26
- ItemHeaderSection: d.span.withConfig({
27
- displayName: "_styles__ItemHeaderSection",
28
- componentId: "sc-ob6zrz-3"
29
- })(["display:flex;align-items:center;gap:16px;"]),
30
- ItemHeaderSectionGroup: d.span.withConfig({
31
- displayName: "_styles__ItemHeaderSectionGroup",
32
- componentId: "sc-ob6zrz-4"
33
- })(["display:flex;justify-content:space-between;flex-grow:1;"]),
34
- ItemHeaderExpandIcon: d.span.withConfig({
35
- displayName: "_styles__ItemHeaderExpandIcon",
36
- componentId: "sc-ob6zrz-5"
37
- })(["display:flex;transition:all 250ms ease-in-out;transform:", ";"], ({
38
- $isExpanded: t
39
- }) => t ? "rotate(180deg)" : "none"),
40
- ItemContent: d.div.withConfig({
41
- displayName: "_styles__ItemContent",
42
- componentId: "sc-ob6zrz-6"
43
- })(["transition:max-height 150ms ease-in-out,opacity 150ms ease-in-out,padding-top 150ms ease-in-out,padding-bottom 150ms ease-in-out;padding-left:16px;padding-right:16px;overflow:hidden;will-change:max-height,opacity,padding-top,padding-bottom;", ";"], ({
44
- $isExpanded: t
45
- }) => t ? _(["max-height:200vh;padding-top:16px;padding-bottom:16px;opacity:1;"]) : _(["max-height:0px;padding-top:0px;padding-bottom:0px;opacity:0;"]))
46
- }, w = H(({
47
- expandIcon: t,
48
- isExpanded: i,
49
- htmlAttributes: l,
50
- showExpandIcon: a
51
- }) => (console.log("showExpandIcon", a), a ? /* @__PURE__ */ n(s.ItemHeaderExpandIcon, { ...l, $isExpanded: i, className: "collapse-item__header__right__expand-icon", children: t ?? /* @__PURE__ */ n(G, { name: "chevron-down", width: 14, height: 14 }) }) : null));
52
- w.displayName = "CollapseItemExpandIcon";
53
- const N = H(({
54
- label: t,
55
- preIcon: i,
56
- postIcon: l,
57
- expandIcon: a,
58
- isExpanded: p,
59
- isOnlyOneExpand: u,
60
- id: m,
61
- showExpandIcon: b,
62
- expandIconHtmlAttributes: I,
63
- htmlAttributes: g,
64
- labelHtmlAttributes: c,
65
- setItemDictionary: e
66
- }) => {
67
- const o = (h) => () => {
68
- e(u ? (r) => ({
69
- ...Object.keys(r).reduce((C, A) => (C[A] = !1, C), {}),
70
- [h]: !r[h]
71
- }) : (r) => ({
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",
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.10",
29
- "@purr-react-styled-components/utils.helpers": "0.0.6",
30
- "@purr-react-styled-components/components.icon": "0.0.7",
31
- "@purr-react-styled-components/components.typography": "0.0.8",
32
- "@purr-react-styled-components/components.divider": "0.0.3"
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.8"
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>;
@@ -1,4 +0,0 @@
1
- import { default as React } from 'react';
2
- import { ICollapseProps } from '../_types';
3
-
4
- export declare const Collapse: ({ items, className, isOnlyOneExpand, expandIds, preIcon, postIcon, expandIcon, disabled, htmlAttributes, }: ICollapseProps) => 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
- };