forked from storybookjs/storybook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce examples for mixins and string templates
- Loading branch information
1 parent
d972843
commit 1e3bcd9
Showing
6 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
globals: { | ||
Polymer: true, | ||
customElements: true, | ||
CustomEvent: true, | ||
}, | ||
}; |
17 changes: 17 additions & 0 deletions
17
examples/polymer-cli/src/separated-button/separated-button.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<link rel="import" href="../../../../node_modules/@polymer/polymer/polymer-element.html"> | ||
|
||
<dom-module id="separated-button"> | ||
<template> | ||
<button on-click="handleTap"> | ||
[[title]] [[counter]] | ||
</button> | ||
</template> | ||
<script> | ||
import { separatedButton } from './separated-button'; | ||
|
||
class PlaygroundButton extends separatedButton(Polymer.Element) { | ||
} | ||
|
||
customElements.define(PlaygroundButton.is, PlaygroundButton); | ||
</script> | ||
</dom-module> |
26 changes: 26 additions & 0 deletions
26
examples/polymer-cli/src/separated-button/separated-button.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { uselessMixin } from './useless-mixin'; | ||
|
||
export const separatedButton = superClass => | ||
class SeparatedButton extends uselessMixin(superClass) { | ||
static get is() { | ||
return 'separated-button'; | ||
} | ||
|
||
static get properties() { | ||
return { | ||
title: { | ||
type: String, | ||
value: 'Click me:', | ||
}, | ||
counter: { | ||
type: Number, | ||
value: 0, | ||
}, | ||
}; | ||
} | ||
|
||
async handleTap() { | ||
this.counter += await Promise.resolve(1); | ||
this.someMethod(); | ||
} | ||
}; |
12 changes: 12 additions & 0 deletions
12
examples/polymer-cli/src/separated-button/useless-mixin.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const uselessMixin = superClass => | ||
class UselessMixin extends superClass { | ||
constructor() { | ||
super(); | ||
|
||
this.eventType = 'test'; | ||
} | ||
|
||
someMethod() { | ||
this.dispatchEvent(new CustomEvent(this.eventType, { detail: 'test' })); | ||
} | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export class StringTemplateButton extends Polymer.Element { | ||
static get is() { | ||
return 'string-template-button'; | ||
} | ||
|
||
static get properties() { | ||
return { | ||
title: { | ||
type: String, | ||
value: 'Wow, I am inline', | ||
}, | ||
counter: { | ||
type: Number, | ||
value: 0, | ||
}, | ||
}; | ||
} | ||
|
||
static get template() { | ||
return '<button on-click="handleTap">[[title]]: [[counter]]</button>'; | ||
} | ||
|
||
handleTap() { | ||
this.counter += 1; | ||
} | ||
} | ||
|
||
customElements.define(StringTemplateButton.is, StringTemplateButton); |