Skip to content

Commit 7f11f06

Browse files
committed
Turn totals-view component into a custom element
1 parent 1e9421f commit 7f11f06

10 files changed

+59
-52
lines changed

Diff for: apps/embed/src/app/app.module.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import { Injector, NgModule } from '@angular/core';
33

44
import { AppComponent } from './app.component';
55
import { NxModule } from '@nrwl/nx';
6-
import { DashComponent } from './dash/dash.component';
76
import { createCustomElement } from '@angular/elements';
7+
import { TotalsComponent } from '@workspace/totals-view';
88

99
@NgModule({
10-
declarations: [AppComponent, DashComponent],
10+
declarations: [AppComponent],
1111
imports: [BrowserModule, NxModule.forRoot()],
1212
providers: [],
13-
entryComponents: [DashComponent]
13+
entryComponents: [TotalsComponent]
1414
})
1515
export class AppModule {
1616
constructor(private injector: Injector) {}
1717

1818
ngDoBootstrap() {
19-
const el = createCustomElement(DashComponent, {injector: this.injector});
20-
customElements.define('embedded-dashboard', el);
19+
const el = createCustomElement(TotalsComponent, {injector: this.injector});
20+
customElements.define('totals-view', el);
2121
}
2222

2323
}

Diff for: apps/embed/src/app/dash/dash.component.css

Whitespace-only changes.

Diff for: apps/embed/src/app/dash/dash.component.html

-1
This file was deleted.

Diff for: apps/embed/src/app/dash/dash.component.spec.ts

-25
This file was deleted.

Diff for: apps/embed/src/app/dash/dash.component.ts

-16
This file was deleted.

Diff for: elements-build.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ const concat = require('concat');
55
const files = [
66
'./dist/apps/embed/runtime.js',
77
'./dist/apps/embed/polyfills.js',
8-
'./dist/apps/embed/scripts.js',
8+
// './dist/apps/embed/scripts.js', Not currently being generated by ng build.
99
'./dist/apps/embed/main.js'
1010
];
1111

1212
await fs.ensureDir('site')
1313
await concat(files, 'site/embed.js')
1414
await fs.copyFile('./dist/apps/embed/styles.css', 'site/styles.css')
15-
await fs.copy('./dist/apps/embed/assets/', 'site/assets/')
1615

16+
// If we need pictures or other assets, uncomment below.
17+
// await fs.copy('./dist/apps/embed/assets/', 'site/assets/')
1718
})()

Diff for: site/custom.css

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.wrapper {
2+
display: flex;
3+
}
4+
5+
.box {
6+
border: 2px solid;
7+
border-radius: 3px;
8+
padding: 10px;
9+
}
10+
11+
.native {
12+
border-color: limegreen;
13+
}
14+
15+
.angular {
16+
border-color: blue;
17+
margin-left: 15px;
18+
}

Diff for: site/custom.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var collection = document.querySelector('#collection'),
2+
submit = document.querySelector('#submit');
3+
4+
collection.value = JSON.stringify([
5+
{"name": "Item 1", "price": 10},
6+
{"name": "Item 2", "price": 5.3},
7+
{"name": "Item 3", "price": 103},
8+
{"name": "Item 4", "price": 10343}
9+
]);
10+
11+
submit.addEventListener('click', () => {
12+
document.querySelector('totals-view').collection = JSON.parse(collection.value)
13+
});

Diff for: site/embed.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: site/index.html

+19-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,29 @@
55
<meta name="viewport"
66
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
77
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8-
<link rel="stylesheet" href="styles.css">
8+
<link rel="stylesheet" href="custom.css">
99
<title>Embed</title>
1010
</head>
1111
<body>
12-
<embedded-dashboard></embedded-dashboard>
12+
<div class="wrapper">
13+
<div class="box native">
14+
<textarea placeholder="Paste a JSON collection whose objects contain a 'price' property" name="collection" id="collection" cols="30" rows="10"></textarea>
15+
<br>
16+
<button id="submit">Submit</button>
17+
</div>
18+
<div class="box angular">
19+
<totals-view></totals-view>
20+
</div>
21+
</div>
22+
23+
24+
<!-- Polyfill -->
1325
<script src="https://unpkg.com/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
26+
27+
<!-- Generated by Angular -->
1428
<script src="embed.js"></script>
29+
30+
<!-- Custom DOM script -->
31+
<script src="custom.js"></script>
1532
</body>
1633
</html>

0 commit comments

Comments
 (0)