Skip to content

Instantly share code, notes, and snippets.

@3cp
Created September 25, 2020 00:01
Show Gist options
  • Save 3cp/5cad80f518b54432273605e17bd73190 to your computer and use it in GitHub Desktop.
Save 3cp/5cad80f518b54432273605e17bd73190 to your computer and use it in GitHub Desktop.
aurelia-dialog-lite: customise position (ts)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dumber Gist</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<base href="/">
</head>
<!--
Dumber gist uses dumber bundler, the default bundle file
is /dist/entry-bundle.js.
The starting module is pointed to aurelia-bootstrapper
(data-main attribute on script) for Aurelia,
The aurelia bootstrapper then loads up user module "main"
(aurelia-app attribute on <body>) which is your src/main.js.
-->
<body aurelia-app="main">
<script src="/dist/entry-bundle.js" data-main="aurelia-bootstrapper"></script>
</body>
</html>
{
"dependencies": {
"aurelia-bootstrapper": "^2.3.3"
}
}
<template>
<require from="./app.scss"></require>
<button click.trigger="openDialog()">Open a dialog</button>
<p>${message}</p>
</template>
.my-dialog {
border-radius: 3px;
padding: .5rem;
box-shadow: 0 0 2rem gray;
}
.dialog-lite-overlay {
// only overwrite display: flex
display: block;
.my-dialog {
position: absolute;
top: 1rem;
text-align: center;
width: 10rem;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
}
}
import { autoinject } from 'aurelia-framework';
import { DialogService } from 'aurelia-dialog-lite';
import { TestDialog } from './test-dialog';
@autoinject
export class App {
message: string = '';
constructor(private dialogService: DialogService) {}
openDialog() {
this.message = '';
this.dialogService.open({
viewModel: TestDialog,
model: { title: 'Test dialog' }
}).then(
result => this.message = 'Got ' + JSON.stringify(result),
err => this.message = err.message
);
}
}
import { Aurelia } from 'aurelia-framework';
export function configure(aurelia: Aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging('info')
.plugin('aurelia-dialog-lite');
aurelia.start().then(() => aurelia.setRoot());
}
<template>
<div class="my-dialog">
<h4>${title}</h4>
<p>Top and centered</p>
<button click.trigger="controller.cancel()">Cancel</button>
<button click.trigger="controller.ok({any: 'thing'})">OK</button>
</div>
</template>
import { autoinject } from 'aurelia-framework';
import { DialogController } from 'aurelia-dialog-lite';
@autoinject
export class TestDialog {
title: string;
constructor(public controller: DialogController) {}
activate(model) {
this.title = model.title as string;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment