Skip to content

Commit e4c09e9

Browse files
authored
EDU-122: Blueprints - Hero section - all frameworks (BuilderIO#4023)
## Description This PR introduces code for blueprints in the hero section across all frameworks. Parent Jira: https://builder-io.atlassian.net/browse/EDU-122 React ticket: https://builder-io.atlassian.net/browse/EDU-645 this PR ticket: https://builder-io.atlassian.net/browse/EDU-652
1 parent 6ab68f5 commit e4c09e9

File tree

21 files changed

+484
-11
lines changed

21 files changed

+484
-11
lines changed

packages/sdks-tests/src/snippet-tests/blueprints-hero.spec.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,21 @@ test.describe('Hero Section', () => {
99
'react-native-76-fabric',
1010
'solid',
1111
'solid-start',
12-
'qwik-city',
13-
'react-sdk-next-pages',
1412
'remix',
15-
'hydrogen',
16-
'react-sdk-next-14-app',
1713
'react-sdk-next-15-app',
1814
'nextjs-sdk-next-app',
19-
'vue',
20-
'nuxt',
21-
'svelte',
22-
'sveltekit',
23-
'angular-17',
24-
'angular-17-ssr',
2515
'angular-19-ssr',
2616
'gen1-react',
2717
'gen1-remix',
2818
'gen1-next14-pages',
2919
'gen1-next15-app',
3020
].includes(packageName)
3121
);
32-
await page.goto('/marketing-event');
22+
23+
const testUrl =
24+
packageName === 'react-sdk-next-14-app' ? '/blueprints/marketing-event' : '/marketing-event';
25+
26+
await page.goto(testUrl);
3327
});
3428

3529
test('should display the hero section with title and call-to-action', async ({ page }) => {

packages/sdks/snippets/angular-16-ssr/src/app/app.module.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { CustomChildComponent } from './custom-child/custom-child.component';
1919
import { customChildResolver } from './custom-child/custom-child.resolver';
2020
import { editableRegionsResolver } from './editable-regions/editable-regions-resolver';
2121
import { EditableRegionComponent } from './editable-regions/editable-regions.component';
22+
import { HeroComponent } from './hero/hero.component';
23+
import { heroResolver } from './hero/hero.resolver';
2224
import { HomepageComponent } from './home/homepage.component';
2325
import { homepageResolver } from './home/homepage.resolver';
2426
import { LivePreviewComponent } from './live-preview/live-preview.component';
@@ -81,6 +83,11 @@ import { productEditorialResolver } from './product-editorial/product-editorial.
8183
path: 'live-preview',
8284
component: LivePreviewComponent,
8385
},
86+
{
87+
path: 'marketing-event',
88+
component: HeroComponent,
89+
resolve: { content: heroResolver },
90+
},
8491
{
8592
path: 'home',
8693
component: HomepageComponent,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { CommonModule } from '@angular/common';
2+
import { Component, OnInit } from '@angular/core';
3+
import { ActivatedRoute } from '@angular/router';
4+
import {
5+
Content,
6+
isPreviewing,
7+
type BuilderContent,
8+
} from '@builder.io/sdk-angular';
9+
@Component({
10+
selector: 'app-hero',
11+
standalone: true,
12+
imports: [Content, CommonModule],
13+
template: `
14+
<!-- Your nav goes here -->
15+
<!-- Hero Section -->
16+
<div *ngIf="productHero || isPreviewing(); else notFound">
17+
<builder-content
18+
[model]="model"
19+
[content]="productHero"
20+
[apiKey]="apiKey"
21+
></builder-content>
22+
</div>
23+
<ng-template #notFound>
24+
<div>404</div>
25+
</ng-template>
26+
<!-- The rest of your page goes here -->
27+
`,
28+
})
29+
export class HeroComponent implements OnInit {
30+
productHero: BuilderContent | null = null;
31+
model = 'collection-hero';
32+
apiKey = 'ee9f13b4981e489a9a1209887695ef2b';
33+
34+
isPreviewing = isPreviewing;
35+
36+
constructor(private route: ActivatedRoute) {}
37+
38+
async ngOnInit() {
39+
this.route.data.subscribe((data: any) => {
40+
this.productHero = data.content;
41+
});
42+
}
43+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {
2+
ActivatedRouteSnapshot,
3+
ResolveFn,
4+
RouterStateSnapshot,
5+
} from '@angular/router';
6+
import { BuilderContent, fetchOneEntry } from '@builder.io/sdk-angular';
7+
8+
export const heroResolver: ResolveFn<BuilderContent | null> = async (
9+
_route: ActivatedRouteSnapshot,
10+
state: RouterStateSnapshot
11+
) => {
12+
return await fetchOneEntry({
13+
model: 'collection-hero',
14+
apiKey: 'ee9f13b4981e489a9a1209887695ef2b',
15+
userAttributes: {
16+
urlPath: state.url,
17+
},
18+
});
19+
};

packages/sdks/snippets/angular-16/src/app/app.module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import { CustomChildComponent } from './custom-child/custom-child.component';
1616
import { CustomHeroComponent } from './custom-child/custom-hero/custom-hero.component';
1717
import { CustomColumnsComponent } from './editable-regions/custom-columns/custom-columns.component';
1818
import { EditableRegionComponent } from './editable-regions/editable-regions.component';
19+
import { HeroComponent } from './hero/hero.component';
1920
import { HomepageComponent } from './home/homepage.component';
2021
import { LivePreviewComponent } from './live-preview/live-preview.component';
2122
import { NavBarComponent } from './nav-bar/nav-bar.component';
2223
import { ProductDetailsComponent } from './product-details/product-details.component';
2324
import { ProductEditorialComponent } from './product-editorial/product-editorial.component';
25+
2426
@NgModule({
2527
declarations: [AppComponent],
2628
imports: [
@@ -56,6 +58,7 @@ import { ProductEditorialComponent } from './product-editorial/product-editorial
5658
},
5759
{ path: 'advanced-child', component: AdvancedChildComponent },
5860
{ path: 'live-preview', component: LivePreviewComponent },
61+
{ path: 'marketing-event', component: HeroComponent },
5962
{ path: 'home', component: HomepageComponent },
6063
{ path: '**', component: CatchAllComponent },
6164
]),
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { CommonModule } from '@angular/common';
2+
import { Component } from '@angular/core';
3+
import {
4+
Content,
5+
fetchOneEntry,
6+
isPreviewing,
7+
type BuilderContent,
8+
} from '@builder.io/sdk-angular';
9+
10+
@Component({
11+
selector: 'app-hero',
12+
standalone: true,
13+
imports: [Content, CommonModule],
14+
template: `
15+
<!-- Your nav goes here -->
16+
<!-- Hero Section -->
17+
<div *ngIf="productHero || isPreviewing(); else notFound">
18+
<builder-content
19+
[model]="model"
20+
[content]="productHero"
21+
[apiKey]="apiKey"
22+
></builder-content>
23+
</div>
24+
<ng-template #notFound>
25+
<div>404</div>
26+
</ng-template>
27+
<!-- The rest of your page goes here -->
28+
`,
29+
})
30+
export class HeroComponent {
31+
productHero: BuilderContent | null = null;
32+
33+
isPreviewing = isPreviewing;
34+
model = 'collection-hero';
35+
apiKey = 'ee9f13b4981e489a9a1209887695ef2b';
36+
37+
async ngOnInit() {
38+
this.productHero = await fetchOneEntry({
39+
model: this.model,
40+
apiKey: this.apiKey,
41+
userAttributes: {
42+
urlPath: window.location.pathname,
43+
},
44+
});
45+
}
46+
}

packages/sdks/snippets/angular-17-ssr/src/app/app.routes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BlogArticleComponent } from './blog-article/blog-article.component';
55
import { CatchAllComponent } from './catch-all/catch-all.component';
66
import { CustomChildComponent } from './custom-child/custom-child.component';
77
import { EditableRegionComponent } from './editable-regions/editable-regions.component';
8+
import { HeroComponent } from './hero/hero.component';
89
import { HomepageComponent } from './home/homepage.component';
910
import { LivePreviewComponent } from './live-preview/live-preview.component';
1011
import { NavBarComponent } from './nav-bar/nav-bar.component';
@@ -25,8 +26,10 @@ export const routes: Routes = [
2526
path: 'editable-region',
2627
component: EditableRegionComponent,
2728
},
29+
{ path: 'marketing-event', component: HeroComponent },
2830
{ path: 'advanced-child', component: AdvancedChildComponent },
2931
{ path: 'live-preview', component: LivePreviewComponent },
32+
{ path: 'marketing-event', component: HeroComponent },
3033
{ path: 'home', component: HomepageComponent },
3134
{ path: '**', component: CatchAllComponent },
3235
];
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Component, inject, type OnInit } from '@angular/core';
2+
import { Router } from '@angular/router';
3+
import {
4+
Content,
5+
fetchOneEntry,
6+
isPreviewing,
7+
type BuilderContent,
8+
} from '@builder.io/sdk-angular';
9+
10+
@Component({
11+
selector: 'app-hero',
12+
standalone: true,
13+
imports: [Content],
14+
template: `
15+
<!-- Your nav goes here -->
16+
<!-- Hero Section -->
17+
@if (productHero || isPreviewing()) {
18+
<builder-content
19+
[model]="model"
20+
[content]="productHero"
21+
[apiKey]="apiKey"
22+
></builder-content>
23+
} @else {
24+
<div>404</div>
25+
}
26+
<!-- The rest of your page goes here -->
27+
`,
28+
})
29+
export class HeroComponent implements OnInit {
30+
productHero: BuilderContent | null = null;
31+
model = 'collection-hero';
32+
apiKey = 'ee9f13b4981e489a9a1209887695ef2b';
33+
34+
isPreviewing = isPreviewing;
35+
36+
private router = inject(Router);
37+
38+
async ngOnInit() {
39+
this.productHero = await fetchOneEntry({
40+
model: this.model,
41+
apiKey: this.apiKey,
42+
userAttributes: {
43+
urlPath: this.router.url,
44+
},
45+
});
46+
}
47+
}

packages/sdks/snippets/angular-17/src/app/app.routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BlogArticleComponent } from './blog-article/blog-article.component';
55
import { CatchAllComponent } from './catch-all/catch-all.component';
66
import { CustomChildComponent } from './custom-child/custom-child.component';
77
import { EditableRegionComponent } from './editable-regions/editable-regions.component';
8+
import { HeroComponent } from './hero/hero.component';
89
import { HomepageComponent } from './home/homepage.component';
910
import { LivePreviewComponent } from './live-preview/live-preview.component';
1011
import { NavBarComponent } from './nav-bar/nav-bar.component';
@@ -27,6 +28,7 @@ export const routes: Routes = [
2728
},
2829
{ path: 'advanced-child', component: AdvancedChildComponent },
2930
{ path: 'live-preview', component: LivePreviewComponent },
31+
{ path: 'marketing-event', component: HeroComponent },
3032
{ path: 'home', component: HomepageComponent },
3133
{ path: '**', component: CatchAllComponent },
3234
];
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Component, inject } from '@angular/core';
2+
import { Router } from '@angular/router';
3+
import {
4+
Content,
5+
fetchOneEntry,
6+
isPreviewing,
7+
type BuilderContent,
8+
} from '@builder.io/sdk-angular';
9+
10+
@Component({
11+
selector: 'app-hero',
12+
standalone: true,
13+
imports: [Content],
14+
template: `
15+
<!-- Your nav goes here -->
16+
<!-- Hero Section -->
17+
@if (productHero || isPreviewing()) {
18+
<builder-content
19+
[model]="model"
20+
[content]="productHero"
21+
[apiKey]="apiKey"
22+
></builder-content>
23+
} @else {
24+
<div>404</div>
25+
}
26+
<!-- The rest of your page goes here -->
27+
`,
28+
})
29+
export class HeroComponent {
30+
productHero: BuilderContent | null = null;
31+
32+
isPreviewing = isPreviewing;
33+
model = 'collection-hero';
34+
apiKey = 'ee9f13b4981e489a9a1209887695ef2b';
35+
36+
private router = inject(Router);
37+
38+
async ngOnInit() {
39+
this.productHero = await fetchOneEntry({
40+
model: this.model,
41+
apiKey: this.apiKey,
42+
userAttributes: {
43+
urlPath: this.router.url,
44+
},
45+
});
46+
}
47+
}

0 commit comments

Comments
 (0)