2018-04-25 14:47:49 +03:00
|
|
|
import { storiesOf } from '@storybook/html';
|
2018-04-26 01:37:36 +03:00
|
|
|
import { action } from '@storybook/addon-actions';
|
|
|
|
|
|
|
|
import {
|
|
|
|
array,
|
|
|
|
boolean,
|
|
|
|
button,
|
|
|
|
color,
|
|
|
|
date,
|
|
|
|
select,
|
|
|
|
withKnobs,
|
|
|
|
text,
|
|
|
|
number,
|
2018-05-09 18:14:04 +03:00
|
|
|
} from '@storybook/addon-knobs';
|
2018-04-25 14:47:49 +03:00
|
|
|
|
|
|
|
storiesOf('Addons|Knobs', module)
|
|
|
|
.addDecorator(withKnobs)
|
2018-04-26 01:37:36 +03:00
|
|
|
.add('Simple', () => {
|
|
|
|
const name = text('Name', 'John Doe');
|
|
|
|
const age = number('Age', 44);
|
|
|
|
const content = `I am ${name} and I'm ${age} years old.`;
|
|
|
|
|
|
|
|
return `<div>${content}</div>`;
|
|
|
|
})
|
|
|
|
.add('All knobs', () => {
|
|
|
|
const name = text('Name', 'Jane');
|
|
|
|
const stock = number('Stock', 20, {
|
|
|
|
range: true,
|
|
|
|
min: 0,
|
|
|
|
max: 30,
|
|
|
|
step: 5,
|
|
|
|
});
|
|
|
|
const fruits = {
|
2018-05-09 18:14:04 +03:00
|
|
|
Apple: 'apples',
|
|
|
|
Banana: 'bananas',
|
|
|
|
Cherry: 'cherries',
|
2018-04-26 01:37:36 +03:00
|
|
|
};
|
2018-05-09 18:14:04 +03:00
|
|
|
const fruit = select('Fruit', fruits, 'apples');
|
2018-04-26 01:37:36 +03:00
|
|
|
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 $${price} each.`
|
|
|
|
: `I'm out of ${fruit}${nice ? ', Sorry!' : '.'}`;
|
|
|
|
|
|
|
|
const salutation = nice ? 'Nice to meet you!' : 'Leave me alone!';
|
|
|
|
const dateOptions = { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' };
|
|
|
|
|
|
|
|
button('Arbitrary action', action('You clicked it!'));
|
|
|
|
|
|
|
|
const style = `border: 2px dotted ${colour}; padding: 8px 22px; border-radius: 8px`;
|
2018-04-25 14:47:49 +03:00
|
|
|
|
2018-04-26 01:37:36 +03:00
|
|
|
return `<div style="${style}">
|
|
|
|
<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>${salutation}</p>
|
|
|
|
</div>
|
|
|
|
`;
|
2018-05-09 18:14:04 +03:00
|
|
|
})
|
|
|
|
.add('XSS safety', () => text('Rendered string', '<img src=x onerror="alert(\'XSS Attack\')" >'));
|