Separate polymer examples

This commit is contained in:
igor 2018-02-06 10:33:08 +02:00
parent fe35a3009f
commit afc895d57a
11 changed files with 148 additions and 130 deletions

View File

@ -2,3 +2,4 @@ import '@storybook/addon-actions/register';
import '@storybook/addon-notes/register';
import '@storybook/addon-knobs/register';
import '@storybook/addon-viewport/register';
import '@storybook/addon-options/register';

View File

@ -1,10 +1,15 @@
/* eslint-disable import/no-extraneous-dependencies, import/no-unresolved, import/extensions */
import { configure } from '@storybook/polymer';
import { setOptions } from '@storybook/addon-options';
setOptions({
hierarchyRootSeparator: /\|/,
});
function loadStories() {
require('../src/stories/index.stories');
require('../src/stories/advanced.stories');
const req = require.context('../src/stories', true, /\.stories\.js$/);
req.keys().forEach((filename) => req(filename));
}
configure(loadStories, module);

View File

@ -11,6 +11,7 @@
"@storybook/addon-actions": "^3.4.0-alpha.7",
"@storybook/addon-knobs": "^3.4.0-alpha.7",
"@storybook/addon-notes": "^3.4.0-alpha.7",
"@storybook/addon-options": "^3.4.0-alpha.7",
"@storybook/addon-viewport": "^3.4.0-alpha.7",
"@storybook/polymer": "^3.4.0-alpha.7",
"@webcomponents/webcomponentsjs": "^1.1.0",

View File

@ -4,7 +4,15 @@
<template>
<style>
.square {
border: 1px solid black;
border: 1px solid #3c763d;
background-color: #5cb85c;
padding: 10px;
}
.rounded {
border-radius: 5px;
border: 1px solid #1b6d85;
background-color: #5bc0de;
padding: 10px;
}
</style>
<button on-click="handleTap"
@ -41,7 +49,7 @@
}
_computeClass(isSquare) {
return isSquare && 'square';
return isSquare ? 'square' : 'rounded';
}
}

View File

@ -0,0 +1,15 @@
import { storiesOf } from '@storybook/polymer';
import { action } from '@storybook/addon-actions';
import { document } from 'global';
storiesOf('Addon|Actions', module)
.add('Action only', () => {
const el = document.createElement('playground-button');
el.addEventListener('click', action('log1'));
return el;
})
.add('Action and method', () => {
const el = document.createElement('playground-button');
el.addEventListener('click', e => action('log2')(e.target));
return el;
});

View File

@ -0,0 +1,56 @@
import { storiesOf } from '@storybook/polymer';
import { action } from '@storybook/addon-actions';
import { document } from 'global';
import {
withKnobs,
text,
button,
number,
select,
date,
color,
array,
boolean,
} from '@storybook/addon-knobs/polymer';
storiesOf('Addon|Knobs', module)
.addDecorator(withKnobs)
.add('simple', () => {
const title = text('Button title', 'Hello');
const el = document.createElement('playground-button');
el.setAttribute('title', title);
button('callback', () => el.setAttribute('title', 'testing'));
return el;
})
.add('complex', () => {
const name = text('Name', 'Jane');
const stock = number('Stock', 20, { range: true, min: 0, max: 30, step: 5 });
const fruits = { apples: 'Apple', bananas: 'Banana', cherries: 'Cherry' };
const fruit = select('Fruit', fruits, 'apple');
const price = number('Price', 2.25);
const colour = color('Border', 'deeppink');
const today = date('Today', new Date('Jan 20 2017 GMT+0'));
const items = array('Items', ['Laptop', 'Book', 'Whiskey']);
const nice = boolean('Nice', true);
const stockMessage = stock
? `I have a stock of ${stock} ${fruit}, costing &dollar;${price} each.`
: `I'm out of ${fruit}${nice ? ', Sorry!' : '.'}`;
const dateOptions = { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' };
button('Arbitrary action', action('You clicked it!'));
return `
<div style="border:2px dotted ${colour}; padding: 8px 22px; border-radius: 8px">
<h1>My name is ${name},</h1>
<h3>today is ${new Date(today).toLocaleDateString('en-US', dateOptions)}</h3>
<p>${stockMessage}</p>
<p>Also, I have:</p>
<ul>
${items.map(item => `<li>${item}</li>`).join('')}
</ul>
<p>${nice ? 'Nice to meet you!' : 'Leave me alone!'}</p>
</div>
`;
});

View File

@ -0,0 +1,23 @@
import { storiesOf } from '@storybook/polymer';
import { withNotes } from '@storybook/addon-notes';
storiesOf('Addon|Notes', module)
.add(
'Simple note',
withNotes({ text: 'My notes on some bold text' })(
() =>
'<p><strong>Etiam vulputate elit eu venenatis eleifend. Duis nec lectus augue. Morbi egestas diam sed vulputate mollis. Fusce egestas pretium vehicula. Integer sed neque diam. Donec consectetur velit vitae enim varius, ut placerat arcu imperdiet. Praesent sed faucibus arcu. Nullam sit amet nibh a enim eleifend rhoncus. Donec pretium elementum leo at fermentum. Nulla sollicitudin, mauris quis semper tempus, sem metus tristique diam, efficitur pulvinar mi urna id urna.</strong></p>'
)
)
.add(
'Note with HTML',
withNotes({
text: `
<h2>My notes on emojies</h2>
<em>It's not all that important to be honest, but..</em>
Emojis are great, I love emojis, in fact I like using them in my Component notes too! 😇
`,
})(() => '<p>🤔😳😯😮<br/>😄😩😓😱<br/>🤓😑😶😊</p>')
);

View File

@ -1,105 +0,0 @@
import { storiesOf } from '@storybook/polymer';
import { action } from '@storybook/addon-actions';
import { withNotes } from '@storybook/addon-notes';
import {
withKnobs,
text,
button,
number,
select,
date,
color,
array,
boolean,
} from '@storybook/addon-knobs/polymer';
import { document } from 'global';
import '../polymer-playground-app.html';
import '../playground-button.html';
import '../separated-button/separated-button.html';
import './storybook-welcome-to-polymer.html';
storiesOf('Advanced/Decorator', module)
.addDecorator(story => {
const el = story();
el.setAttribute('title', `${el.getAttribute('title')} - decorated`);
return el;
})
.add('example decoration', () => {
const el = document.createElement('playground-button');
el.setAttribute('title', 'An example title');
return el;
});
storiesOf('Advanced/Addon Actions', module)
.add('Action only', () => {
const el = document.createElement('playground-button');
el.addEventListener('click', action('log1'));
return el;
})
.add('Action and method', () => {
const el = document.createElement('playground-button');
el.addEventListener('click', e => action('log2')(e.target));
return el;
});
storiesOf('Advanced/Addon Notes', module)
.add(
'Simple note',
withNotes({ text: 'My notes on some bold text' })(
() =>
'<p><strong>Etiam vulputate elit eu venenatis eleifend. Duis nec lectus augue. Morbi egestas diam sed vulputate mollis. Fusce egestas pretium vehicula. Integer sed neque diam. Donec consectetur velit vitae enim varius, ut placerat arcu imperdiet. Praesent sed faucibus arcu. Nullam sit amet nibh a enim eleifend rhoncus. Donec pretium elementum leo at fermentum. Nulla sollicitudin, mauris quis semper tempus, sem metus tristique diam, efficitur pulvinar mi urna id urna.</strong></p>'
)
)
.add(
'Note with HTML',
withNotes({
text: `
<h2>My notes on emojies</h2>
<em>It's not all that important to be honest, but..</em>
Emojis are great, I love emojis, in fact I like using them in my Component notes too! 😇
`,
})(() => '<p>🤔😳😯😮<br/>😄😩😓😱<br/>🤓😑😶😊</p>')
);
storiesOf('Advanced/Addon Knobs', module)
.addDecorator(withKnobs)
.add('simple', () => {
const title = text('Button title', 'Hello');
const el = document.createElement('playground-button');
el.setAttribute('title', title);
button('callback', () => el.setAttribute('title', 'testing'));
return el;
})
.add('complex', () => {
const name = text('Name', 'Jane');
const stock = number('Stock', 20, { range: true, min: 0, max: 30, step: 5 });
const fruits = { apples: 'Apple', bananas: 'Banana', cherries: 'Cherry' };
const fruit = select('Fruit', fruits, 'apple');
const price = number('Price', 2.25);
const colour = color('Border', 'deeppink');
const today = date('Today', new Date('Jan 20 2017 GMT+0'));
const items = array('Items', ['Laptop', 'Book', 'Whiskey']);
const nice = boolean('Nice', true);
const stockMessage = stock
? `I have a stock of ${stock} ${fruit}, costing &dollar;${price} each.`
: `I'm out of ${fruit}${nice ? ', Sorry!' : '.'}`;
const dateOptions = { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' };
button('Arbitrary action', action('You clicked it!'));
return `
<div style="border:2px dotted ${colour}; padding: 8px 22px; border-radius: 8px">
<h1>My name is ${name},</h1>
<h3>today is ${new Date(today).toLocaleDateString('en-US', dateOptions)}</h3>
<p>${stockMessage}</p>
<p>Also, I have:</p>
<ul>
${items.map(item => `<li>${item}</li>`).join('')}
</ul>
<p>${nice ? 'Nice to meet you!' : 'Leave me alone!'}</p>
</div>
`;
});

View File

@ -0,0 +1,14 @@
import { storiesOf } from '@storybook/polymer';
import { document } from 'global';
storiesOf('Custom|Decorator', module)
.addDecorator(story => {
const el = story();
el.setAttribute('title', `${el.getAttribute('title')} - decorated`);
return el;
})
.add('example decoration', () => {
const el = document.createElement('playground-button');
el.setAttribute('title', 'An example title');
return el;
});

View File

@ -0,0 +1,15 @@
import { storiesOf } from '@storybook/polymer';
import { document } from 'global';
import { StringTemplateButton } from '../string-template-button';
import '../separated-button/separated-button.html';
storiesOf('Custom|Methods for rendering', module)
.add('html string', () => '<div>Rendered with string</div>')
.add('html with custom elements', () => '<separated-button title="Click me!"></separated-button>')
.add('document.createElement', () => {
const el = document.createElement('playground-button');
el.setAttribute('title', 'Rendered with document.createElement');
return el;
})
.add('Polymer instance', () => new StringTemplateButton());

View File

@ -1,34 +1,19 @@
import { storiesOf } from '@storybook/polymer';
import { withKnobs, text } from '@storybook/addon-knobs/polymer';
import { document } from 'global';
import '../polymer-playground-app.html';
import '../playground-button.html';
import '../separated-button/separated-button.html';
import './storybook-welcome-to-polymer.html';
import { StringTemplateButton } from '../string-template-button';
storiesOf('Welcome', module).add(
'Welcome',
() => '<storybook-welcome-to-polymer></storybook-welcome-to-polymer>'
);
storiesOf('App', module)
.addDecorator(withKnobs)
.add('full app', () => {
const title = text('title', 'This title can be edited via a knob');
return `<polymer-playground-app title="${title}"></polymer-playground-app>`;
});
storiesOf('App', module).add(
'full app',
() => '<polymer-playground-app title="Storybook fro Polymer"></polymer-playground-app>'
);
storiesOf('Button', module)
.add('rounded', () => '<playground-button></playground-button>')
.add('square', () => '<playground-button is-square></playground-button>');
storiesOf('Methods for rendering', module)
.add('html string', () => '<div>Rendered with string</div>')
.add('html with custom elements', () => '<separated-button title="Click me!"></separated-button>')
.add('document.createElement', () => {
const el = document.createElement('playground-button');
el.setAttribute('title', 'Rendered with document.createElement');
return el;
})
.add('Polymer instance', () => new StringTemplateButton());