2018-04-26 01:37:36 +03:00
|
|
|
import { action } from '@storybook/addon-actions';
|
2019-05-14 09:34:04 +02:00
|
|
|
import { document } from 'global';
|
2018-04-26 01:37:36 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-05-14 09:34:04 +02:00
|
|
|
const cachedContainer = document.createElement('p');
|
2018-04-26 01:37:36 +03:00
|
|
|
|
2019-06-24 00:39:54 +08:00
|
|
|
export default {
|
2019-11-13 18:17:20 +08:00
|
|
|
title: 'Addons/Knobs',
|
2019-06-24 00:39:54 +08:00
|
|
|
decorators: [withKnobs],
|
|
|
|
};
|
2018-07-18 11:13:21 -07:00
|
|
|
|
2019-06-24 00:39:54 +08:00
|
|
|
export const 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>`;
|
|
|
|
};
|
2018-04-26 01:37:36 +03:00
|
|
|
|
2019-06-24 00:39:54 +08:00
|
|
|
export const DOM = () => {
|
|
|
|
const name = text('Name', 'John Doe');
|
|
|
|
const container = document.createElement('p');
|
|
|
|
container.textContent = name;
|
|
|
|
return container;
|
|
|
|
};
|
2018-04-26 01:37:36 +03:00
|
|
|
|
2019-11-19 21:08:32 +01:00
|
|
|
export const Story3 = () => {
|
2019-06-24 00:39:54 +08:00
|
|
|
const name = text('Name', 'John Doe');
|
|
|
|
const textColor = color('Text color', 'orangered');
|
|
|
|
cachedContainer.textContent = name;
|
|
|
|
cachedContainer.style.transition = 'color 0.5s ease-out';
|
|
|
|
cachedContainer.style.color = textColor;
|
|
|
|
return cachedContainer;
|
|
|
|
};
|
2020-05-25 13:32:05 +08:00
|
|
|
Story3.storyName = 'CSS transitions';
|
2018-04-26 01:37:36 +03:00
|
|
|
|
2019-11-19 21:08:32 +01:00
|
|
|
export const Story4 = () => {
|
2019-06-24 00:39:54 +08:00
|
|
|
const name = text('Name', 'Jane');
|
|
|
|
const stock = number('Stock', 20, {
|
|
|
|
range: true,
|
|
|
|
min: 0,
|
|
|
|
max: 30,
|
|
|
|
step: 5,
|
|
|
|
});
|
|
|
|
const fruits = {
|
|
|
|
Apple: 'apples',
|
|
|
|
Banana: 'bananas',
|
|
|
|
Cherry: 'cherries',
|
|
|
|
};
|
|
|
|
const fruit = select('Fruit', fruits, 'apples');
|
|
|
|
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);
|
2018-04-26 01:37:36 +03:00
|
|
|
|
2019-06-24 00:39:54 +08:00
|
|
|
const stockMessage = stock
|
|
|
|
? `I have a stock of ${stock} ${fruit}, costing $${price} each.`
|
|
|
|
: `I'm out of ${fruit}${nice ? ', Sorry!' : '.'}`;
|
2018-04-26 01:37:36 +03:00
|
|
|
|
2019-06-24 00:39:54 +08:00
|
|
|
const salutation = nice ? 'Nice to meet you!' : 'Leave me alone!';
|
|
|
|
const dateOptions = { year: 'numeric', month: 'long', day: 'numeric', timeZone: 'UTC' };
|
2018-04-25 14:47:49 +03:00
|
|
|
|
2019-06-24 00:39:54 +08:00
|
|
|
button('Arbitrary action', action('You clicked it!'));
|
|
|
|
|
|
|
|
const style = `border: 2px dotted ${colour}; padding: 8px 22px; border-radius: 8px`;
|
|
|
|
|
|
|
|
return `<div style="${style}">
|
2018-04-26 01:37:36 +03:00
|
|
|
<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>
|
2020-03-27 20:04:50 +01:00
|
|
|
<ul>${items.map((item) => `<li>${item}</li>`).join('')}</ul>
|
2018-04-26 01:37:36 +03:00
|
|
|
<p>${salutation}</p>
|
|
|
|
</div>
|
|
|
|
`;
|
2019-06-24 00:39:54 +08:00
|
|
|
};
|
2020-05-25 13:32:05 +08:00
|
|
|
Story4.storyName = 'All knobs';
|
2019-06-24 00:39:54 +08:00
|
|
|
|
2019-11-19 21:08:32 +01:00
|
|
|
export const Story5 = () => text('Rendered string', '<img src=x onerror="alert(\'XSS Attack\')" >');
|
2020-05-25 13:32:05 +08:00
|
|
|
Story5.storyName = 'XSS safety';
|