Last active
July 25, 2018 11:31
-
-
Save martonsagi/0bf83980935015217cfb83250643c13f to your computer and use it in GitHub Desktop.
Dynamic custom components with Aurelia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<require from="./frame-slot"></require> | |
<require from="./frame-inline"></require> | |
<require from="./frame-innerhtml"></require> | |
<div class="panel panel-primary"> | |
<div class="panel-heading">Slots</div> | |
<div class="panel-body"> | |
<frame-slot> | |
<div slot="str1"><h3>${slotStr1}</h3></div> | |
<div slot="str2"> | |
<h3>${slotStr2}</h3> | |
<div> | |
<frame-slot></frame-slot> | |
</div> | |
</div> | |
</frame-slot> | |
</div> | |
</div> | |
<div class="panel panel-success"> | |
<div class="panel-heading">Inline template</div> | |
<div class="panel-body"> | |
<frame-inline template.bind="inlineTemplate" model.bind="inlineModel"></frame-inline> | |
</div> | |
</div> | |
<div class="panel panel-danger"> | |
<div class="panel-heading">InnerHTML template</div> | |
<div class="panel-body"> | |
<frame-innerhtml content.bind="innerHtmlContent"></frame-inline> | |
</div> | |
</div> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class App { | |
slotStr1 = "Slot Str1"; | |
slotStr2 = "Slot Str2"; | |
inlineModel = { | |
name: "inline-template", | |
description: "This is an inline template", | |
slot: "Frame-slot Str1 content within frame-inline" | |
}; | |
inlineTemplate = '<require from="./frame-slot"></require>' + | |
'<div>${model.name}: ${model.description}</div>' + | |
'<br>' + | |
'<frame-slot>' + | |
'<div slot="str1">${model.slot}</div>' + | |
'</frame-slot>'; | |
innerHtmlContent = '<div><a href="http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/securing-your-app/3" target="_blank">InnerHTML usage is not recommended</a></div>'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<compose view.bind="viewStrategy" model.bind="model"></compose> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { bindable, InlineViewStrategy } from 'aurelia-framework'; | |
export class FrameInline { | |
@bindable template; | |
@bindable model; | |
viewStrategy; | |
attached() { | |
this.viewStrategy = new InlineViewStrategy(`<template>${this.template}</template>`); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div innerhtml.bind="content | sanitizeHTML"></div> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { bindable } from 'aurelia-framework'; | |
export class FrameInnerhtml { | |
@bindable content; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<slot name="str1">Default str1</slot> | |
</div> | |
<div> | |
<slot name="str2">Default str2</slot> | |
</div> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class FrameSlot { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Aurelia</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | |
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script> | |
<script> | |
require(['aurelia-bootstrapper']); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* todo: add styles */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment