Skip to content

Commit bae928c

Browse files
committed
feat: add collapsible
1 parent 35569df commit bae928c

4 files changed

Lines changed: 161 additions & 2 deletions

File tree

src/components/Blocks/Content.stories.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,32 @@ export const Features: Story = {
6060
},
6161
}
6262

63+
export const FullWidthCollapsable: Story = {
64+
args: {
65+
...BlocksTest.content.fullWidthCollapsable,
66+
theme: {
67+
...Default.args.theme,
68+
settings: {
69+
...Default.args.theme?.settings,
70+
box: 'collapsable',
71+
},
72+
},
73+
},
74+
}
75+
76+
export const HalfWidthCollapsable: Story = {
77+
args: {
78+
...BlocksTest.content.halfWidthCollapsable,
79+
theme: {
80+
...Default.args.theme,
81+
settings: {
82+
...Default.args.theme?.settings,
83+
box: 'collapsable',
84+
},
85+
},
86+
},
87+
}
88+
6389
export const Test: Story = {
6490
args: {
6591
id: '681a4999a2fd5620877e41a0',

src/components/Blocks/Content.tsx

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const ContentBlock: React.FC<ContentBlockProps> = (props) => {
1818
const variants = {
1919
none: '',
2020
line: 'border border-primary p-4 rounded-lg',
21+
collapsable: '',
2122
}
2223

2324
const hasRichTextMedia = (richtext: any): boolean => {
@@ -54,7 +55,9 @@ export const ContentBlock: React.FC<ContentBlockProps> = (props) => {
5455
}
5556

5657
const separateH2 = (richtext: any, theme: string, size: string): SeparateH2Result => {
57-
if (theme === 'none' || size === 'full') {
58+
console.log('separateH2 called with theme:', theme, 'size:', size)
59+
60+
if (theme === 'none' || (size === 'full' && theme !== 'collapsable')) {
5861
return { processedRichText: richtext, heading: null }
5962
}
6063
let newRichText = richtext
@@ -68,6 +71,58 @@ export const ContentBlock: React.FC<ContentBlockProps> = (props) => {
6871
}
6972

7073

74+
75+
76+
if (theme?.settings?.box === 'collapsable') {
77+
return (
78+
<div className="col-span-4 lg:col-span-12 mb-4">
79+
80+
<div className="mt-4">
81+
<div className="grid grid-cols-4 lg:grid-cols-12 gap-y-8 gap-x-8">
82+
{columns &&
83+
columns.length > 0 &&
84+
columns.map((col, index) => {
85+
const { enableLink, link, richText, size } = col
86+
// console.log('richText', index, size, richText)
87+
const { processedRichText, heading} = separateH2(richText,theme?.settings?.box || 'none', size || 'full')
88+
// console.log('processedRichText', processedRichText)
89+
console.log('heading', heading)
90+
return (
91+
<div
92+
className={cn(
93+
`col-span-4 lg:col-span-${colsSpanClasses[size!]}`,
94+
{
95+
'md:col-span-2': size !== 'full',
96+
},
97+
variants[( !hasRichTextMedia(richText as any) && theme?.settings?.box) || 'none'],
98+
'intersect-once intersect:animate-flip-up opacity-0 intersect:opacity-100 intersect:animate-duration-500',
99+
`intersect:animate-delay-${index + 1}00`
100+
)}
101+
key={index}
102+
>
103+
<details className="group">
104+
<summary className="cursor-pointer select-none bg-primary text-primary-foreground text-3xl px-4 py-4 rounded-lg">
105+
{ heading ? <span className="bg-primary text-primary-foreground mb-4 px-4 py-2 text-3xl">{heading.children[0].text}</span> : <span className="text-lg font-medium">Expand to view content</span> }
106+
{/* <span className="float-right transition-transform duration-300 ease-in-out group-open:rotate-180">
107+
</span> */}
108+
</summary>
109+
<div className="mt-4">
110+
{processedRichText && <RichText content={processedRichText} enableGutter={false} className="rich-text" />}
111+
112+
{enableLink && <CMSLink {...link} />}
113+
</div>
114+
</details>
115+
116+
</div>
117+
)
118+
})}
119+
</div>
120+
</div>
121+
</div>
122+
)
123+
}
124+
125+
71126
return (
72127
<div className="my-6">
73128

@@ -77,6 +132,7 @@ export const ContentBlock: React.FC<ContentBlockProps> = (props) => {
77132
theme?.settings?.box ? 'gap-x-8' : 'gap-x-16',
78133
)}
79134
>
135+
80136
{columns &&
81137
columns.length > 0 &&
82138
columns.map((col, index) => {

src/payload-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export interface ContentBlock {
415415
* Overlay the theme colour on top of the image
416416
*/
417417
overlay?: boolean | null;
418-
box?: ('none' | 'line') | null;
418+
box?: ('none' | 'line' | 'collapsable') | null;
419419
};
420420
};
421421
columns?:

src/tests/payload.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,83 @@ export const RichTextTest = {
679679

680680
export const BlocksTest = {
681681
content: {
682+
fullWidthCollapsable: {
683+
id: '67a74c276365f244c8b6d149',
684+
blockName: null,
685+
686+
columns: [
687+
{
688+
id: '67a74ea16365f244c8b6d14b',
689+
size: 'full',
690+
691+
richText: RichTextTest.medium,
692+
enableLink: null,
693+
694+
link: {
695+
type: 'reference',
696+
newTab: null,
697+
url: null,
698+
label: null,
699+
appearance: 'default',
700+
},
701+
},
702+
],
703+
blockType: 'content',
704+
705+
theme: {
706+
settings: {
707+
theme: 'dark',
708+
background: 'transparent',
709+
overlay: false,
710+
},
711+
},
712+
},
713+
halfWidthCollapsable: {
714+
id: '67a74c276365f244c8b6d149',
715+
blockName: null,
716+
717+
columns: [
718+
{
719+
id: '67a74ea16365f244c8b6d14b',
720+
size: 'half',
721+
722+
richText: RichTextTest.medium,
723+
enableLink: null,
724+
725+
link: {
726+
type: 'reference',
727+
newTab: null,
728+
url: null,
729+
label: null,
730+
appearance: 'default',
731+
},
732+
},
733+
{
734+
id: '67a74ea16365f244c8b6d14b',
735+
size: 'half',
736+
737+
richText: RichTextTest.medium,
738+
enableLink: null,
739+
740+
link: {
741+
type: 'reference',
742+
newTab: null,
743+
url: null,
744+
label: null,
745+
appearance: 'default',
746+
},
747+
},
748+
],
749+
blockType: 'content',
750+
751+
theme: {
752+
settings: {
753+
theme: 'dark',
754+
background: 'transparent',
755+
overlay: false,
756+
},
757+
},
758+
},
682759
halfWithEmbeddedImage: {
683760
id: '67a74c276365f244c8b6d149',
684761
blockName: null,

0 commit comments

Comments
 (0)