Skip to content

Commit 7b71628

Browse files
committed
CMS-45730 Add Button component and update Start
1 parent a761fcd commit 7b71628

File tree

4 files changed

+50
-70
lines changed

4 files changed

+50
-70
lines changed

templates/alloy-template/src/app/layout.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import News, { NewsContentType } from '@/components/News';
1818
import Article, { ArticleContentType } from '@/components/base/Article';
1919
import BlankSection from '@/components/base/BlankSection';
2020
import { SEOContentType } from '@/components/base/SEO';
21+
import Button, { ButtonContentType } from '@/components/base/Button';
2122

2223
const geistSans = Geist({
2324
variable: '--font-geist-sans',
@@ -46,6 +47,7 @@ initContentTypeRegistry([
4647
TeaserContentType,
4748
StandardContentType,
4849
SEOContentType,
50+
ButtonContentType,
4951
]);
5052

5153
initReactComponentRegistry({
@@ -60,6 +62,7 @@ initReactComponentRegistry({
6062
Start,
6163
Teaser,
6264
BlankSection,
65+
Button,
6366
},
6467
});
6568

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { contentType, Infer } from '@optimizely/cms-sdk';
22
import {
33
ComponentContainerProps,
44
getPreviewUtils,
5+
OptimizelyComponent,
56
OptimizelyExperience,
67
} from '@optimizely/cms-sdk/react/server';
78
import { ProductContentType } from './Product';
89
import { StandardContentType } from './Standard';
910
import { SEOContentType } from './base/SEO';
11+
import { ButtonContentType } from './base/Button';
1012

1113
export const StartContentType = contentType({
1214
key: 'Start',
@@ -33,14 +35,10 @@ export const StartContentType = contentType({
3335
displayName: 'Description',
3436
group: 'Information',
3537
},
36-
button_link: {
37-
type: 'url',
38-
displayName: 'Button Link',
39-
group: 'Information',
40-
},
41-
button_text: {
42-
type: 'string',
43-
displayName: 'Button Text',
38+
button: {
39+
type: 'component',
40+
contentType: ButtonContentType,
41+
displayName: 'Button',
4442
group: 'Information',
4543
},
4644

@@ -152,16 +150,8 @@ function Start({ opti }: StartProps) {
152150
{opti.description}
153151
</p>
154152
)}
155-
156-
{/* Call to Action Button */}
157-
{opti.button_link && opti.button_text && (
158-
<a
159-
href={opti.button_link.default ?? undefined}
160-
className="inline-block bg-teal-500 hover:bg-teal-600 text-white font-medium py-3 px-8 rounded-md transition-colors duration-200 text-base"
161-
>
162-
{opti.button_text}
163-
</a>
164-
)}
153+
{/* Button */}
154+
<OptimizelyComponent opti={opti} />
165155
</div>
166156
</div>
167157
</div>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { contentType, Infer } from '@optimizely/cms-sdk';
2+
3+
export const ButtonContentType = contentType({
4+
key: 'Button',
5+
displayName: 'Button',
6+
baseType: '_component',
7+
description:
8+
'The Button content type represents a button component on the website.',
9+
properties: {
10+
link: {
11+
type: 'url',
12+
displayName: 'Button Link',
13+
group: 'Information',
14+
},
15+
text: {
16+
type: 'string',
17+
displayName: 'Button Text',
18+
group: 'Information',
19+
},
20+
},
21+
compositionBehaviors: ['elementEnabled'],
22+
});
23+
24+
type ButtonProps = {
25+
opti: Infer<typeof ButtonContentType>;
26+
};
27+
28+
function Button({ opti }: ButtonProps) {
29+
return (
30+
<a
31+
href={opti?.link?.default ?? undefined}
32+
className="inline-block bg-teal-500 hover:bg-teal-600 text-white font-medium py-3 px-8 rounded-md transition-colors duration-200 text-base"
33+
>
34+
{opti.text}
35+
</a>
36+
);
37+
}
38+
39+
export default Button;

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

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)