From 8d4085e32de6bedbb7a360da3a7d56168f3ad970 Mon Sep 17 00:00:00 2001 From: Jerome Cukier Date: Mon, 26 Mar 2018 15:01:32 -0700 Subject: [PATCH] storybook-jsx-addon-syntax-fix (#763) --- website/storybook/axis-story.js | 303 +++++++++++++----------- website/storybook/barseries-story.js | 243 +++++++++++--------- website/storybook/lineseries-story.js | 199 +++++++++------- website/storybook/markseries-story.js | 317 +++++++++++++++----------- website/storybook/storybook-utils.js | 2 +- 5 files changed, 614 insertions(+), 450 deletions(-) diff --git a/website/storybook/axis-story.js b/website/storybook/axis-story.js index 325f8d7dd..6409de3fa 100644 --- a/website/storybook/axis-story.js +++ b/website/storybook/axis-story.js @@ -1,6 +1,9 @@ import React from 'react'; -import {storiesOf} from '@storybook/react'; +import {setAddon, storiesOf} from '@storybook/react'; +import JSXAddon from 'storybook-addon-jsx'; + +setAddon(JSXAddon); import {withKnobs, number, select} from '@storybook/addon-knobs/react'; import {LineSeries, VerticalBarSeries, XAxis, YAxis} from 'react-vis'; @@ -10,139 +13,179 @@ import {SimpleChartWrapperNoAxes, jsxOptions} from './storybook-utils'; storiesOf('Axes and scales/Axis Formatting/Base', module) .addDecorator(withKnobs) - .addWithJSX('Axis orientation', () => { - const XAxisOrientation = select('XAxis.orientation', {bottom: 'bottom', top: 'top'}, 'bottom'); - const YAxisOrientation = select('YAxis.orientation', {left: 'left', right: 'right'}, 'left'); - return ( - - - - - - ); - }, jsxOptions) - .addWithJSX('Axis titles', () => { - const XAxisPosition = select('XAxis.position', {start: 'start', middle: 'middle', end: 'end'}, 'end'); - const YAxisPosition = select('YAxis.position', {start: 'start', middle: 'middle', end: 'end'}, 'end'); + .addWithJSX( + 'Axis orientation', + () => { + const XAxisOrientation = select('XAxis.orientation', {bottom: 'bottom', top: 'top'}, 'bottom'); + const YAxisOrientation = select('YAxis.orientation', {left: 'left', right: 'right'}, 'left'); + return ( + + + + + + ); + }, + jsxOptions + ) + .addWithJSX( + 'Axis titles', + () => { + const XAxisPosition = select('XAxis.position', {start: 'start', middle: 'middle', end: 'end'}, 'end'); + const YAxisPosition = select('YAxis.position', {start: 'start', middle: 'middle', end: 'end'}, 'end'); - return ( - - - - - - ); - }, jsxOptions) - .addWithJSX('Tick total', () => { - const xTickTotal = number('XAxis.tickTotal', 10, {max: 20, min: 0, range: true}); - const yTickTotal = number('YAxis.tickTotal', 10, {max: 20, min: 0, range: true}); + return ( + + + + + + ); + }, + jsxOptions + ) + .addWithJSX( + 'Tick total', + () => { + const xTickTotal = number('XAxis.tickTotal', 10, {max: 20, min: 0, range: true}); + const yTickTotal = number('YAxis.tickTotal', 10, {max: 20, min: 0, range: true}); - return ( - - - - - - ); - }, jsxOptions) - .addWithJSX('Tick Size', () => { - const xTickSize = number('XAxis.tickSize', 6, {max: 10, min: 0, range: true}); - const yTickSize = number('YAxis.tickSize', 6, {max: 10, min: 0, range: true}); + return ( + + + + + + ); + }, + jsxOptions + ) + .addWithJSX( + 'Tick Size', + () => { + const xTickSize = number('XAxis.tickSize', 6, {max: 10, min: 0, range: true}); + const yTickSize = number('YAxis.tickSize', 6, {max: 10, min: 0, range: true}); - return ( - - - - - - ); - }, jsxOptions) - .addWithJSX('Tick Size (Inner)', () => { - const xTickSize = number('XAxis.tickSizeInner', 6, {max: 10, min: 0, range: true}); - const yTickSize = number('YAxis.tickSizeInner', 6, {max: 10, min: 0, range: true}); + return ( + + + + + + ); + }, + jsxOptions + ) + .addWithJSX( + 'Tick Size (Inner)', + () => { + const xTickSize = number('XAxis.tickSizeInner', 6, {max: 10, min: 0, range: true}); + const yTickSize = number('YAxis.tickSizeInner', 6, {max: 10, min: 0, range: true}); - return ( - - - - - - ); - }, jsxOptions) - .addWithJSX('Tick Size (Outer)', () => { - const xTickSize = number('XAxis.tickSizeOuter', 6, {max: 10, min: 0, range: true}); - const yTickSize = number('YAxis.tickSizeOuter', 6, {max: 10, min: 0, range: true}); + return ( + + + + + + ); + }, + jsxOptions + ) + .addWithJSX( + 'Tick Size (Outer)', + () => { + const xTickSize = number('XAxis.tickSizeOuter', 6, {max: 10, min: 0, range: true}); + const yTickSize = number('YAxis.tickSizeOuter', 6, {max: 10, min: 0, range: true}); - return ( - - - - - - ); - }, jsxOptions) - .addWithJSX('Tick orientation', () => { - const tickLabelAngle = number('tickLabelAngle', 0, {max: 90, min: -90, range: true}); - return ( - - new Date(d).toLocaleDateString()} tickLabelAngle={tickLabelAngle} /> - - - - ); - }, jsxOptions); + return ( + + + + + + ); + }, + jsxOptions + ) + .addWithJSX( + 'Tick orientation', + () => { + const tickLabelAngle = number('tickLabelAngle', 0, {max: 90, min: -90, range: true}); + return ( + + new Date(d).toLocaleDateString()} tickLabelAngle={tickLabelAngle} /> + + + + ); + }, + jsxOptions + ); storiesOf('Axes and scales/Scales', module) .addDecorator(withKnobs) - .addWithJSX('time Scale', () => { - return ( - - new Date(d).toLocaleDateString()} /> - - - - ); - }, jsxOptions) - .addWithJSX('category scale', () => { - const data = generateLinearData({ - nbPoints: 8, - changeRatio: 0.4, - key: 'bar1' - }); - return ( - - - - - - ); - }, jsxOptions) - .addWithJSX('ordinal scale', () => { - const data = generateLinearData({ - nbPoints: 8, - changeRatio: 0.4, - key: 'bar-with-words', - extraParams: [['x', getWord({})]] - }); - return ( - - - - - - ); - }, jsxOptions); + .addWithJSX( + 'time Scale', + () => { + return ( + + new Date(d).toLocaleDateString()} /> + + + + ); + }, + jsxOptions + ) + .addWithJSX( + 'category scale', + () => { + const data = generateLinearData({ + nbPoints: 8, + changeRatio: 0.4, + key: 'bar1' + }); + return ( + + + + + + ); + }, + jsxOptions + ) + .addWithJSX( + 'ordinal scale', + () => { + const data = generateLinearData({ + nbPoints: 8, + changeRatio: 0.4, + key: 'bar-with-words', + extraParams: [['x', getWord({})]] + }); + return ( + + + + + + ); + }, + jsxOptions + ); diff --git a/website/storybook/barseries-story.js b/website/storybook/barseries-story.js index dc96728a3..a3ca51e76 100644 --- a/website/storybook/barseries-story.js +++ b/website/storybook/barseries-story.js @@ -1,6 +1,9 @@ import React from 'react'; -import {storiesOf} from '@storybook/react'; +import {setAddon, storiesOf} from '@storybook/react'; +import JSXAddon from 'storybook-addon-jsx'; + +setAddon(JSXAddon); import {withKnobs, color, number, object, text} from '@storybook/addon-knobs/react'; import {HorizontalBarSeries, VerticalBarSeries} from 'react-vis'; @@ -31,52 +34,64 @@ function addBarSeriesStory(isVertical = true) { storiesOf(`Series/${seriesName}/Base`, module) .addDecorator(withKnobs) - .addWithJSX(`single ${seriesName}`, () => { - return ( - - - - ); - }, jsxOptions) - .addWithJSX(`multiple ${seriesName} - clustered`, () => { - return ( - - - - - - ); - }, jsxOptions) - .addWithJSX(`multiple ${seriesName} - stacked`, () => { - return ( - - - - - - ); - }, jsxOptions); + .addWithJSX( + `single ${seriesName}`, + () => { + return ( + + + + ); + }, + jsxOptions + ) + .addWithJSX( + `multiple ${seriesName} - clustered`, + () => { + return ( + + + + + + ); + }, + jsxOptions + ) + .addWithJSX( + `multiple ${seriesName} - stacked`, + () => { + return ( + + + + + + ); + }, + jsxOptions + ); storiesOf(`Series/${seriesName}/Styling/By datapoint`, module) .addDecorator(withKnobs) @@ -96,66 +111,86 @@ function addBarSeriesStory(isVertical = true) { ); }) - .addWithJSX('opacity', () => { - return ( - - - - ); - }, jsxOptions); + .addWithJSX( + 'opacity', + () => { + return ( + + + + ); + }, + jsxOptions + ); storiesOf(`Series/${seriesName}/Styling/At series level`, module) .addDecorator(withKnobs) - .addWithJSX('fill', () => { - return ( - - {styledSeries({ - data: dataGenerator({nbPoints: 8, changeRatio: 0.4, key: 'bar1'}), - fill: '#2c51be' - })} - - ); - }, jsxOptions) - .addWithJSX('opacity', () => { - return ( - - {styledSeries({ - data: dataGenerator({nbPoints: 8, changeRatio: 0.4, key: 'bar1'}), - opacity: 0.5 - })} - - ); - }, jsxOptions) - .addWithJSX('stroke', () => { - return ( - - {styledSeries({ - data: dataGenerator({nbPoints: 8, changeRatio: 0.4, key: 'bar1'}), - stroke: '#2c51be' - })} - - ); - }, jsxOptions) - .addWithJSX('style', () => { - return ( - - {styledSeries({ - data: dataGenerator({nbPoints: 8, changeRatio: 0.4, key: 'bar1'}), - style: { - stroke: '#2c51be', - strokeWidth: '3px' - } - })} - - ); - }, jsxOptions); + .addWithJSX( + 'fill', + () => { + return ( + + {styledSeries({ + data: dataGenerator({nbPoints: 8, changeRatio: 0.4, key: 'bar1'}), + fill: '#2c51be' + })} + + ); + }, + jsxOptions + ) + .addWithJSX( + 'opacity', + () => { + return ( + + {styledSeries({ + data: dataGenerator({nbPoints: 8, changeRatio: 0.4, key: 'bar1'}), + opacity: 0.5 + })} + + ); + }, + jsxOptions + ) + .addWithJSX( + 'stroke', + () => { + return ( + + {styledSeries({ + data: dataGenerator({nbPoints: 8, changeRatio: 0.4, key: 'bar1'}), + stroke: '#2c51be' + })} + + ); + }, + jsxOptions + ) + .addWithJSX( + 'style', + () => { + return ( + + {styledSeries({ + data: dataGenerator({nbPoints: 8, changeRatio: 0.4, key: 'bar1'}), + style: { + stroke: '#2c51be', + strokeWidth: '3px' + } + })} + + ); + }, + jsxOptions + ); } addBarSeriesStory(); addBarSeriesStory(false); diff --git a/website/storybook/lineseries-story.js b/website/storybook/lineseries-story.js index 25c6b87b4..194925bbc 100644 --- a/website/storybook/lineseries-story.js +++ b/website/storybook/lineseries-story.js @@ -1,6 +1,9 @@ import React from 'react'; -import {storiesOf} from '@storybook/react'; +import {setAddon, storiesOf} from '@storybook/react'; +import JSXAddon from 'storybook-addon-jsx'; + +setAddon(JSXAddon); import {withKnobs, color, number, object, select, text} from '@storybook/addon-knobs/react'; import {LineSeries} from 'react-vis'; @@ -35,90 +38,122 @@ storiesOf('Series/LineSeries/Base', module) }, jsxOptions ) - .addWithJSX('Multiple Line series', () => { - return ( - - - - - - ); - }, jsxOptions); + .addWithJSX( + 'Multiple Line series', + () => { + return ( + + + + + + ); + }, + jsxOptions + ); storiesOf('Series/LineSeries/Styling', module) .addDecorator(withKnobs) - .addWithJSX('opacity', () => { - return ( - - {styledLineSeries({data: generateLinearData({key: 'line1'}), opacity: 0.5})} - - ); - }, jsxOptions) - .addWithJSX('stroke', () => { - return ( - - {styledLineSeries({data: generateLinearData({key: 'line1'}), stroke: '#2c51be'})} - - ); - }, jsxOptions) - .addWithJSX('strokeDasharray', () => { - return ( - - {styledLineSeries({data: generateLinearData({key: 'line1'}), strokeDasharray: '5, 5, 1, 5'})} - - ); - }, jsxOptions) - .addWithJSX('strokeStyle', () => { - return ( - - {styledLineSeries({data: generateLinearData({key: 'line1'}), strokeStyle: 'dashed'})} - - ); - }, jsxOptions) - .addWithJSX('strokeWidth', () => { - return ( - - {styledLineSeries({data: generateLinearData({key: 'line1'}), strokeWidth: '5px'})} - - ); - }, jsxOptions) - .addWithJSX('style object', () => { - return ( - - {styledLineSeries({ - data: generateLinearData({key: 'line1'}), - style: { - stroke: '#E48000', - strokeLinejoin: 'round', - strokeWidth: '3px' - } - })} - - ); - }, jsxOptions); + .addWithJSX( + 'opacity', + () => { + return ( + + {styledLineSeries({data: generateLinearData({key: 'line1'}), opacity: 0.5})} + + ); + }, + jsxOptions + ) + .addWithJSX( + 'stroke', + () => { + return ( + + {styledLineSeries({data: generateLinearData({key: 'line1'}), stroke: '#2c51be'})} + + ); + }, + jsxOptions + ) + .addWithJSX( + 'strokeDasharray', + () => { + return ( + + {styledLineSeries({data: generateLinearData({key: 'line1'}), strokeDasharray: '5, 5, 1, 5'})} + + ); + }, + jsxOptions + ) + .addWithJSX( + 'strokeStyle', + () => { + return ( + + {styledLineSeries({data: generateLinearData({key: 'line1'}), strokeStyle: 'dashed'})} + + ); + }, + jsxOptions + ) + .addWithJSX( + 'strokeWidth', + () => { + return ( + + {styledLineSeries({data: generateLinearData({key: 'line1'}), strokeWidth: '5px'})} + + ); + }, + jsxOptions + ) + .addWithJSX( + 'style object', + () => { + return ( + + {styledLineSeries({ + data: generateLinearData({key: 'line1'}), + style: { + stroke: '#E48000', + strokeLinejoin: 'round', + strokeWidth: '3px' + } + })} + + ); + }, + jsxOptions + ); storiesOf('Series/LineSeries/Curve', module) .addDecorator(withKnobs) - .addWithJSX('Curve', () => { - return ( - - - - ); - }, jsxOptions); + .addWithJSX( + 'Curve', + () => { + return ( + + + + ); + }, + jsxOptions + ); diff --git a/website/storybook/markseries-story.js b/website/storybook/markseries-story.js index 8cd25755a..f649892e8 100644 --- a/website/storybook/markseries-story.js +++ b/website/storybook/markseries-story.js @@ -1,6 +1,9 @@ import React from 'react'; -import {storiesOf} from '@storybook/react'; +import {setAddon, storiesOf} from '@storybook/react'; +import JSXAddon from 'storybook-addon-jsx'; + +setAddon(JSXAddon); import {withKnobs, color, number, object, select} from '@storybook/addon-knobs/react'; import {MarkSeries} from 'react-vis'; @@ -24,143 +27,191 @@ function styledMarkSeries(props) { storiesOf('Series/MarkSeries/Base', module) .addDecorator(withKnobs) - .addWithJSX('Single scatterplot', () => { - return ( - - - - ); - }, jsxOptions) - .addWithJSX('Multiple MarkSeries', () => { - return ( - - - - - - ); - }, jsxOptions); + .addWithJSX( + 'Single scatterplot', + () => { + return ( + + + + ); + }, + jsxOptions + ) + .addWithJSX( + 'Multiple MarkSeries', + () => { + return ( + + + + + + ); + }, + jsxOptions + ); storiesOf('Series/MarkSeries/Styling/By Datapoint', module) .addDecorator(withKnobs) - .addWithJSX('color', () => { - const {colorScale, colorRange} = chooseColorScale(); - return ( - - { + const {colorScale, colorRange} = chooseColorScale(); + return ( + + + + ); + }, + jsxOptions + ) + .addWithJSX( + 'fill', + () => { + const {colorScale, colorRange} = chooseColorScale(); + return ( + + + + ); + }, + jsxOptions + ) + .addWithJSX( + 'opacity', + () => { + return ( + + + + ); + }, + jsxOptions + ) + .addWithJSX( + 'size', + () => { + return ( + + + + ); + }, + jsxOptions + ) + .addWithJSX( + 'stroke', + () => { + const {colorScale, colorRange} = chooseColorScale(); + return ( + + + + ); + }, + jsxOptions + ); + +storiesOf('Series/MarkSeries/Styling/At series level', module) + .addDecorator(withKnobs) + .addWithJSX( + 'fill', + () => { + return ( + + {styledMarkSeries({ + data: generateScatterplotData({key: 'scatter1'}), + fill: '#2c51be' })} - /> - - ); - }, jsxOptions) - .addWithJSX('fill', () => { - const {colorScale, colorRange} = chooseColorScale(); - return ( - - + ); + }, + jsxOptions + ) + .addWithJSX( + 'opacity', + () => { + return ( + + {styledMarkSeries({ + data: generateScatterplotData({key: 'scatter1'}), + opacity: 0.5 })} - /> - - ); - }, jsxOptions) - .addWithJSX('opacity', () => { - return ( - - + ); + }, + jsxOptions + ) + .addWithJSX( + 'stroke', + () => { + return ( + + {styledMarkSeries({ + data: generateScatterplotData({key: 'scatter1'}), + stroke: '#2c51be' })} - /> - - ); - }, jsxOptions) - .addWithJSX('size', () => { - return ( - - + ); + }, + jsxOptions + ) + .addWithJSX( + 'strokeWidth', + () => { + return ( + + {styledMarkSeries({ + data: generateScatterplotData({key: 'scatter1'}), + strokeWidth: '3px' })} - /> - - ); - }, jsxOptions) - .addWithJSX('stroke', () => { - const {colorScale, colorRange} = chooseColorScale(); - return ( - - + ); + }, + jsxOptions + ) + .addWithJSX( + 'style', + () => { + return ( + + {styledMarkSeries({ + data: generateScatterplotData({key: 'scatter1'}), + style: { + stroke: '#E48000', + strokeOpacity: 0.5, + strokeWidth: '3px' + } })} - style={{strokeWidth: '2px'}} - /> - - ); - }, jsxOptions); - -storiesOf('Series/MarkSeries/Styling/At series level', module) - .addDecorator(withKnobs) - .addWithJSX('fill', () => { - return ( - - {styledMarkSeries({ - data: generateScatterplotData({key: 'scatter1'}), - fill: '#2c51be' - })} - - ); - }, jsxOptions) - .addWithJSX('opacity', () => { - return ( - - {styledMarkSeries({ - data: generateScatterplotData({key: 'scatter1'}), - opacity: 0.5 - })} - - ); - }, jsxOptions) - .addWithJSX('stroke', () => { - return ( - - {styledMarkSeries({ - data: generateScatterplotData({key: 'scatter1'}), - stroke: '#2c51be' - })} - - ); - }, jsxOptions) - .addWithJSX('strokeWidth', () => { - return ( - - {styledMarkSeries({ - data: generateScatterplotData({key: 'scatter1'}), - strokeWidth: '3px' - })} - - ); - }, jsxOptions) - .addWithJSX('style', () => { - return ( - - {styledMarkSeries({ - data: generateScatterplotData({key: 'scatter1'}), - style: { - stroke: '#E48000', - strokeOpacity: 0.5, - strokeWidth: '3px' - } - })} - - ); - }, jsxOptions); + + ); + }, + jsxOptions + ); diff --git a/website/storybook/storybook-utils.js b/website/storybook/storybook-utils.js index 2d10ff90d..c12b3ee10 100644 --- a/website/storybook/storybook-utils.js +++ b/website/storybook/storybook-utils.js @@ -80,5 +80,5 @@ export const jsxOptions = { } return component.type.displayName; }, - filterProps: ['className', 'nullAccessor'] + filterProps: ['className', 'getNull', 'nullAccessor'] };