import React from 'react'; import { storiesOf } from '@storybook/react'; import moment from 'moment'; import { withKnobs, number, object, boolean, text, select, date, array, color, files, } from '../../src'; const stories = storiesOf('Example of Knobs', module); stories.addDecorator(withKnobs); stories.add('simple example', () => ); stories.add('with all knobs', () => { const name = text('Name', 'Tom Cary'); const dob = date('DOB', new Date('January 20 1887')); const bold = boolean('Bold', false); const selectedColor = color('Color', 'black'); const favoriteNumber = number('Favorite Number', 42); const comfortTemp = number('Comfort Temp', 72, { range: true, min: 60, max: 90, step: 1 }); const passions = array('Passions', ['Fishing', 'Skiing']); const images = files('Happy Picture', 'image/*', [ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAHdElNRQfiARwMCyEWcOFPAAAAP0lEQVQoz8WQMQoAIAwDL/7/z3GwghSp4KDZyiUpBMCYUgd8rehtH16/l3XewgU2KAzapjXBbNFaPS6lDMlKB6OiDv3iAH1OAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE4LTAxLTI4VDEyOjExOjMzLTA3OjAwlAHQBgAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxOC0wMS0yOFQxMjoxMTozMy0wNzowMOVcaLoAAAAASUVORK5CYII=', ]); const customStyle = object('Style', { fontFamily: 'Arial', padding: 20, }); const style = { ...customStyle, fontWeight: bold ? 800 : 400, favoriteNumber, color: selectedColor, }; return (
My favorite number is {favoriteNumber}.
My most comfortable room temperature is {comfortTemp} degrees Fahrenheit.
When I am happy I look like this:
Javascript Date default value, passes date value
const myDob = date('My DOB', new Date('July 07 1993'));
{`// I was born in: "${moment(myDob).format('DD MMM YYYY')}"`}
undefined default value passes today's date
const today = date('today');
{`// Today's date is: "${moment(today).format('DD MMM YYYY')}"`}
null default value passes null value
const dob = date('DOB', null);
{`// You were born in: "${ dob ? moment(dob).format('DD MMM YYYY') : 'Please select date.' }"`}