File tree Expand file tree Collapse file tree 4 files changed +50
-70
lines changed
templates/alloy-template/src Expand file tree Collapse file tree 4 files changed +50
-70
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import News, { NewsContentType } from '@/components/News';
1818import Article , { ArticleContentType } from '@/components/base/Article' ;
1919import BlankSection from '@/components/base/BlankSection' ;
2020import { SEOContentType } from '@/components/base/SEO' ;
21+ import Button , { ButtonContentType } from '@/components/base/Button' ;
2122
2223const geistSans = Geist ( {
2324 variable : '--font-geist-sans' ,
@@ -46,6 +47,7 @@ initContentTypeRegistry([
4647 TeaserContentType ,
4748 StandardContentType ,
4849 SEOContentType ,
50+ ButtonContentType ,
4951] ) ;
5052
5153initReactComponentRegistry ( {
@@ -60,6 +62,7 @@ initReactComponentRegistry({
6062 Start,
6163 Teaser,
6264 BlankSection,
65+ Button,
6366 } ,
6467} ) ;
6568
Original file line number Diff line number Diff line change @@ -2,11 +2,13 @@ import { contentType, Infer } from '@optimizely/cms-sdk';
22import {
33 ComponentContainerProps ,
44 getPreviewUtils ,
5+ OptimizelyComponent ,
56 OptimizelyExperience ,
67} from '@optimizely/cms-sdk/react/server' ;
78import { ProductContentType } from './Product' ;
89import { StandardContentType } from './Standard' ;
910import { SEOContentType } from './base/SEO' ;
11+ import { ButtonContentType } from './base/Button' ;
1012
1113export 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 >
Original file line number Diff line number Diff line change 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 ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments