Skip to content

Commit 6d5f607

Browse files
committed
Cleaned things up for next version.
1 parent 33c3a22 commit 6d5f607

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,15 @@ openDialog({
283283
<h3>Do you like this dialog?</h3>
284284
<button @click="${() => $dialog.open = false}">Umm, yeah!</button>
285285
`, $dialog)
286-
}));
286+
});
287287
```
288288

289289

290290
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/colored.png)](#extend-webdialog)
291291

292292
## ➤ Extend WebDialog
293293

294-
It is totally possible to extend the web dialog. The only thing you have to do it define a new class and extend the WebDialog class. Then you can add your custom logic and define a new custom element with your new class. Here's an example of what you could if you for example want a custom dialog that shows an image.
294+
It is totally possible to extend the dialog. The only thing you have to do it define a new class and extend the `WebDialog` class. Then you can add your custom logic and define a new custom element with your new class. Here's an example of what you could if you for example want a custom dialog that shows an image.
295295

296296
```js
297297
import { WebDialog } from "web-dialog";
@@ -327,7 +327,6 @@ class ImageDialog extends WebDialog {
327327

328328
// Get a reference to the img element
329329
this.$img = this.shadowRoot.querySelector("#img");
330-
this.$img.src = this.src;
331330
}
332331

333332
// Each time the src attribute changes we set the src of the image element
@@ -340,16 +339,31 @@ class ImageDialog extends WebDialog {
340339
}
341340
}
342341

343-
// Remember to define your custom element
342+
// Remember to define your new custom element
344343
customElements.define("image-dialog", ImageDialog);
345344
```
346345

347-
Then you would be able to use it like this.
346+
After you have defined your new dialog you are be able to use it like this.
348347

349348
```html
350349
<image-dialog open center src="https://i.ytimg.com/vi/NCZ0eg1zEvw/maxresdefault.jpg"></image-dialog>
351350
```
352351

352+
Or this
353+
354+
```js
355+
import {openDialog} from "web-dialog";
356+
357+
openDialog({
358+
initialize: () => {
359+
const $dialog = new ImageDialog();
360+
$dialog.src = `https://i.ytimg.com/vi/NCZ0eg1zEvw/maxresdefault.jpg`;
361+
$dialog.center = true;
362+
return $dialog;
363+
}
364+
});
365+
```
366+
353367
When our custom dialog opens it will look like this.
354368

355369
<img src="https://raw.githubusercontent.com/andreasbm/web-dialog/master/examples/example9.png" width="600">

blueprint.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ openDialog({
227227
<h3>Do you like this dialog?</h3>
228228
<button @click="${() => $dialog.open = false}">Umm, yeah!</button>
229229
`, $dialog)
230-
}));
230+
});
231231
```
232232

233233
## Extend WebDialog
234234

235-
It is totally possible to extend the web dialog. The only thing you have to do it define a new class and extend the WebDialog class. Then you can add your custom logic and define a new custom element with your new class. Here's an example of what you could if you for example want a custom dialog that shows an image.
235+
It is totally possible to extend the dialog. The only thing you have to do it define a new class and extend the `WebDialog` class. Then you can add your custom logic and define a new custom element with your new class. Here's an example of what you could if you for example want a custom dialog that shows an image.
236236

237237
```js
238238
import { WebDialog } from "web-dialog";
@@ -268,7 +268,6 @@ class ImageDialog extends WebDialog {
268268

269269
// Get a reference to the img element
270270
this.$img = this.shadowRoot.querySelector("#img");
271-
this.$img.src = this.src;
272271
}
273272

274273
// Each time the src attribute changes we set the src of the image element
@@ -281,16 +280,31 @@ class ImageDialog extends WebDialog {
281280
}
282281
}
283282

284-
// Remember to define your custom element
283+
// Remember to define your new custom element
285284
customElements.define("image-dialog", ImageDialog);
286285
```
287286

288-
Then you would be able to use it like this.
287+
After you have defined your new dialog you are be able to use it like this.
289288

290289
```html
291290
<image-dialog open center src="https://i.ytimg.com/vi/NCZ0eg1zEvw/maxresdefault.jpg"></image-dialog>
292291
```
293292

293+
Or this
294+
295+
```js
296+
import {openDialog} from "web-dialog";
297+
298+
openDialog({
299+
initialize: () => {
300+
const $dialog = new ImageDialog();
301+
$dialog.src = `https://i.ytimg.com/vi/NCZ0eg1zEvw/maxresdefault.jpg`;
302+
$dialog.center = true;
303+
return $dialog;
304+
}
305+
});
306+
```
307+
294308
When our custom dialog opens it will look like this.
295309

296310
<img src="https://raw.githubusercontent.com/andreasbm/web-dialog/master/examples/example9.png" width="600">

src/demo/app.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { LightBoxDialog } from "./dialogs/lightbox-dialog";
44
import { NestedDialog } from "./dialogs/nested-dialog";
55
import { ResultDialog } from "./dialogs/result-dialog";
66
import sharedStyles from "./styles/shared.scss";
7-
import "./dialogs/image-dialog";
87

98
const template = document.createElement("template");
109
template.innerHTML = `
@@ -104,8 +103,6 @@ template.innerHTML = `
104103
<br />
105104
<p id="returnvalue-result"></p>
106105
</div>
107-
108-
<image-dialog open center src="https://i.ytimg.com/vi/NCZ0eg1zEvw/maxresdefault.jpg"></image-dialog>
109106
`;
110107

111108
export class WebDialogApp extends HTMLElement {

src/lib/open-dialog.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export function openDialog<T extends WebDialog<R>, R = any> ({
2323

2424
// Construct the dialog
2525
const $dialog = initialize();
26-
$dialog.center = center;
26+
27+
// Set the properties
28+
center != null ? $dialog.center = center : {};
2729

2830
// Attach the template to the dialog
2931
$content != null? (

0 commit comments

Comments
 (0)