Last active
December 26, 2016 10:32
-
-
Save MaKleSoft/3ff7cd7f79fe607899d523d26aad4dd8 to your computer and use it in GitHub Desktop.
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
///<reference path="../../../bower_components/polymer/custom_typings/dom.d.ts"/> | |
///<reference path="../../../bower_components/polymer/src/typescript/polymer.d.ts"/> | |
namespace JSX { | |
export function createElement(element: string, attributes: any, ...children: string[]): string { | |
let attrs = ""; | |
for (const attr in attributes) { | |
attrs += ` ${attr}="${attributes[attr]}"`; | |
} | |
return `<${element} ${attrs}> | |
${children.join("\n")} | |
</${element}>`; | |
} | |
export interface IntrinsicElements { | |
div: { class?: string }, | |
template: { is?: string, items?: string }, | |
style: {}, | |
"my-element": { name: string } | |
} | |
} | |
class MyElement extends Polymer.Element { | |
static get is() { return "my-element" }; | |
static get config() { return { | |
properties: { | |
name: { | |
type: String, | |
value: "World" | |
} | |
} | |
}; } | |
static get template() { | |
const t = document.createElement("template"); | |
t.innerHTML = | |
<div> | |
<style> | |
{` | |
div { color: blue; } | |
`} | |
</style> | |
<div>Hello {"{{"} name {"}}"}</div> | |
</div>; | |
return t; | |
} | |
} | |
// Register custom element definition using standard platform API | |
window.customElements.define(MyElement.is, MyElement); |
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
tsc --lib dom,es2017 --target es2015 --jsx react --reactNamespace JSX my-element.tsx |
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
///<reference path="../../../bower_components/polymer/custom_typings/dom.d.ts"/> | |
///<reference path="../../../bower_components/polymer/src/typescript/polymer.d.ts"/> | |
var JSX; | |
(function (JSX) { | |
function createElement(element, attributes, ...children) { | |
let attrs = ""; | |
for (const attr in attributes) { | |
attrs += ` ${attr}="${attributes[attr]}"`; | |
} | |
return `<${element} ${attrs}> | |
${children.join("\n")} | |
</${element}>`; | |
} | |
JSX.createElement = createElement; | |
})(JSX || (JSX = {})); | |
class MyElement extends Polymer.Element { | |
static get is() { return "my-element"; } | |
; | |
static get config() { | |
return { | |
properties: { | |
name: { | |
type: String, | |
value: "World" | |
} | |
} | |
}; | |
} | |
static get template() { | |
const t = document.createElement("template"); | |
t.innerHTML = | |
JSX.createElement("div", null, | |
JSX.createElement("style", null, ` | |
div { color: blue; } | |
`), | |
JSX.createElement("div", null, | |
"Hello ", | |
"{{", | |
" name ", | |
"}}")); | |
return t; | |
} | |
} | |
// Register custom element definition using standard platform API | |
window.customElements.define(MyElement.is, MyElement); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment