Skip to content

Commit 9ef9aef

Browse files
committed
Refactor News, Standard, and BlankSection components for improved layout and content handling; enhance Teaser component with link wrapping functionality.
1 parent c39e3c2 commit 9ef9aef

File tree

5 files changed

+106
-37
lines changed

5 files changed

+106
-37
lines changed

templates/alloy-template/src/components/News.tsx

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,42 @@ function ComponentWrapper({ children, node }: ComponentContainerProps) {
4242
}
4343

4444
function News({ opti }: NewsPageProps) {
45+
const { pa } = getPreviewUtils(opti);
4546
return (
46-
<div>
47-
<h2>{opti.title}</h2>
48-
<p>{opti.description}</p>
49-
<div>
50-
{opti.image?.url.default && (
51-
<img src={opti.image.url.default} alt={'Teaser Image'} />
52-
)}
47+
<main className="min-h-screen bg-white">
48+
<div className="mx-auto max-w-7xl px-4 py-12 sm:px-6 lg:px-8">
49+
<div className="grid grid-cols-1 gap-8 lg:grid-cols-[1fr_320px]">
50+
{/* Main Content */}
51+
<div className="space-y-8">
52+
{/* Heading and Description */}
53+
<div className="space-y-4">
54+
<h1
55+
{...pa('title')}
56+
className="text-4xl font-bold tracking-tight text-gray-900 sm:text-5xl"
57+
>
58+
{opti.title}
59+
</h1>
60+
<p
61+
{...pa('description')}
62+
className="text-lg leading-relaxed text-gray-700"
63+
>
64+
{opti.description}
65+
</p>
66+
</div>
67+
68+
{/* Main Body Content */}
69+
<div className="space-y-6">
70+
<RichText {...pa('main_body')} content={opti.main_body?.json} />
71+
</div>
72+
</div>
73+
74+
<OptimizelyExperience
75+
nodes={opti.composition.nodes ?? []}
76+
ComponentWrapper={ComponentWrapper}
77+
/>
78+
</div>
5379
</div>
54-
<RichText content={opti.main_body?.json} />
55-
<OptimizelyExperience
56-
nodes={opti.composition.nodes ?? []}
57-
ComponentWrapper={ComponentWrapper}
58-
/>
59-
</div>
80+
</main>
6081
);
6182
}
6283

templates/alloy-template/src/components/Standard.tsx

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,44 @@ function ComponentWrapper({ children, node }: ComponentContainerProps) {
4242
}
4343

4444
function Standard({ opti }: StandardPageProps) {
45+
const { pa } = getPreviewUtils(opti);
4546
return (
46-
<div>
47-
<h1 className="text-3xl font-bold">{opti.heading}</h1>
48-
<p>{opti.description}</p>
49-
<div>
50-
{opti.image?.url.default && (
51-
<img src={opti.image.url.default} alt={'Teaser Image'} />
52-
)}
47+
<main className="min-h-screen bg-white">
48+
<div className="mx-auto max-w-7xl px-4 py-12 sm:px-6 lg:px-8">
49+
<div className="grid grid-cols-1 gap-8 lg:grid-cols-[1fr_320px]">
50+
{/* Main Content */}
51+
<div className="space-y-8">
52+
{/* Heading and Description */}
53+
<div className="space-y-4">
54+
<h1
55+
{...pa('title')}
56+
className="text-4xl font-bold tracking-tight text-gray-900 sm:text-5xl"
57+
>
58+
{opti.heading}
59+
</h1>
60+
<p
61+
{...pa('description')}
62+
className="text-lg leading-relaxed text-gray-700"
63+
>
64+
{opti.description}
65+
</p>
66+
</div>
67+
68+
{/* Main Body Content */}
69+
<div className="space-y-6">
70+
<RichText {...pa('main_body')} content={opti.main_body?.json} />
71+
</div>
72+
</div>
73+
</div>
74+
</div>
75+
{/* section Area */}
76+
<div className="">
77+
<OptimizelyExperience
78+
nodes={opti.composition.nodes ?? []}
79+
ComponentWrapper={ComponentWrapper}
80+
/>
5381
</div>
54-
<RichText content={opti.main_body?.json} />
55-
<OptimizelyExperience
56-
nodes={opti.composition.nodes ?? []}
57-
ComponentWrapper={ComponentWrapper}
58-
/>
59-
</div>
82+
</main>
6083
);
6184
}
6285

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import { BlankSectionContentType, Infer } from '@optimizely/cms-sdk';
22
import {
33
OptimizelyGridSection,
4+
StructureContainerProps,
45
getPreviewUtils,
56
} from '@optimizely/cms-sdk/react/server';
67

78
type BlankSectionProps = {
89
opti: Infer<typeof BlankSectionContentType>;
910
};
1011

12+
function Row({ children }: StructureContainerProps) {
13+
return <div className="flex flex-wrap my-4">{children}</div>;
14+
}
15+
16+
function Column({ children }: StructureContainerProps) {
17+
return <div className="flex-1 mx-2">{children}</div>;
18+
}
19+
1120
/** Defines a component to render a blank section */
1221
export default function BlankSection({ opti }: BlankSectionProps) {
1322
const { pa } = getPreviewUtils(opti);
1423
return (
1524
<section {...pa(opti)}>
16-
<OptimizelyGridSection nodes={opti.nodes} />
25+
<OptimizelyGridSection nodes={opti.nodes} row={Row} column={Column} />
1726
</section>
1827
);
1928
}

templates/alloy-template/src/components/base/PageList.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,34 @@ const PageList = contentType({
1212
},
1313
IncludePublishDate: {
1414
type: 'boolean',
15-
displayName: 'IncludePublishDate',
15+
displayName: 'Include Publish Date',
1616
},
1717
IncludeIntroduction: {
1818
type: 'boolean',
19-
displayName: 'IncludeIntroduction',
19+
displayName: 'Include Introduction',
2020
},
2121
Count: {
2222
type: 'integer',
23-
displayName: 'Count',
23+
displayName: 'Max Count',
2424
},
2525
SortOrder: {
2626
type: 'integer',
27-
displayName: 'SortOrder',
27+
displayName: 'Sort Order',
2828
},
2929
Root: {
3030
type: 'contentReference',
3131
format: 'PageReference',
3232
displayName: 'Root',
33-
restrictedTypes: [],
3433
},
3534
PageTypeFilter: {
3635
type: 'string',
3736
format: 'PageType',
38-
displayName: 'PageTypeFilter',
37+
displayName: 'Page Type Filter',
3938
},
4039
CategoryFilter: {
4140
type: 'array',
4241
format: 'categorization',
43-
displayName: 'CategoryFilter',
42+
displayName: 'Category Filter',
4443
items: {
4544
type: 'integer',
4645
},

templates/alloy-template/src/components/base/Teaser.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { contentType, displayTemplate, Infer } from '@optimizely/cms-sdk';
2+
import Link from 'next/link';
23

34
export const TeaserContentType = contentType({
45
key: 'Teaser',
@@ -57,9 +58,21 @@ type TeaserProps = {
5758
};
5859

5960
function Teaser({ opti, displaySettings }: TeaserProps) {
61+
// Helper function to wrap content with link if available
62+
const wrapWithLink = (content: React.ReactNode) => {
63+
if (opti.link?.default) {
64+
return (
65+
<Link href={opti.link.default} className="cursor-pointer">
66+
{content}
67+
</Link>
68+
);
69+
}
70+
return content;
71+
};
72+
6073
// Horizontal layout
6174
if (displaySettings?.orientation === 'horizontal') {
62-
return (
75+
const content = (
6376
<div className="max-w-4xl mx-auto bg-white rounded-lg shadow-sm overflow-hidden">
6477
<div className="flex flex-col md:flex-row">
6578
{opti.image?.url.default && (
@@ -82,11 +95,13 @@ function Teaser({ opti, displaySettings }: TeaserProps) {
8295
</div>
8396
</div>
8497
);
98+
99+
return wrapWithLink(content);
85100
}
86101

87102
// Vertical layout (default)
88-
return (
89-
<div className="max-w-md mx-auto bg-white rounded-lg shadow-sm overflow-hidden">
103+
const verticalContent = (
104+
<div className="max-w-lg mx-auto bg-white rounded-lg shadow-sm overflow-hidden">
90105
{opti.image?.url.default && (
91106
<div className="h-48 w-full overflow-hidden">
92107
<img
@@ -104,6 +119,8 @@ function Teaser({ opti, displaySettings }: TeaserProps) {
104119
</div>
105120
</div>
106121
);
122+
123+
return wrapWithLink(verticalContent);
107124
}
108125

109126
export default Teaser;

0 commit comments

Comments
 (0)