All files / VerticalTabs VerticalTabs.stories.tsx

100% Statements 17/17
100% Branches 0/0
100% Functions 3/3
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153                                                  1x       12x       1x 3x                   1x 1x                   1x 1x                                                 1x   1x                 1x 1x 1x   1x     1x               1x                                                                                          
import { map } from 'lodash';
import React from 'react';
import { Meta, Story } from '@storybook/react';
 
import * as d3Scale from 'd3-scale';
import VerticalTabs, { IVerticalTabsProps } from './VerticalTabs';
import Lines from '../Lines/Lines';
import SuccessIcon from '../Icon/SuccessIcon/SuccessIcon';
import WarningIcon from '../Icon/WarningIcon/WarningIcon';
 
//πŸ‘‡ Provide Storybook with the component name, 'section', any subcomponents and a description
export default {
	title: 'Navigation/VerticalTabs',
	component: VerticalTabs,
	parameters: {
		docs: {
			description: {
				component: VerticalTabs.peek.description,
			},
		},
	},
	args: VerticalTabs.defaultProps,
} as Meta;
 
//πŸ‘‡ Destructure any child components that we will need
const { Tab, Title } = VerticalTabs;
 
//πŸ‘‡ Add a key prop to each child element of the array
function addKeys(children: any) {
	return map(children, (child, index) => ({ ...child, key: index }));
}
 
//πŸ‘‡ Create a β€œtemplate” of how args map to rendering
const Template: Story<IVerticalTabsProps> = (args) => {
	return (
		<section>
			<VerticalTabs {...(args as any)} />
		</section>
	);
};
 
//πŸ‘‡ Each story then reuses that template
 
/** Default: Title as Prop */
export const Basic = Template.bind({});
Basic.args = {
	children: addKeys([
		<Tab Title='One'>One content</Tab>,
		<Tab Title='Two'>Two content</Tab>,
		<Tab Title='Three'>Three content</Tab>,
		<Tab Title='Four'>Four content</Tab>,
	]),
};
 
/** Title as Child */
export const TitleAsChild = Template.bind({});
TitleAsChild.args = {
	children: addKeys([
		<Tab>
			<Title>One</Title>
			One content
		</Tab>,
 
		<Tab>
			<Title>Two</Title>
			Two content
		</Tab>,
 
		<Tab>
			<Title>Three</Title>
			Three content
		</Tab>,
 
		<Tab>
			<Title>Four</Title>
			Four content
		</Tab>,
	]),
};
 
/** Complex Title as Child */
export const ComplexTitleAsChild = Template.bind({});
 
const dataSet = [
	{ x: 'OR', y: 1 },
	{ x: 'CA', y: 0 },
	{ x: 'WA', y: 3 },
	{ x: 'NY', y: 2 },
	{ x: 'TX', y: 1 },
	{ x: 'WV', y: 3 },
];
 
const width = 200;
const height = 50;
const xScale = d3Scale.scalePoint().domain(map(dataSet, 'x')).range([0, width]);
 
const yScale = d3Scale.scaleLinear().domain([0, 4]).range([height, 0]);
 
const titleThree = (
	<span>
		<h2 style={{ margin: 0 }}>Performance</h2>
		<svg width={width} height={height}>
			<Lines data={dataSet} xScale={xScale} yScale={yScale} />
		</svg>
	</span>
);
 
ComplexTitleAsChild.args = {
	children: addKeys([
		<VerticalTabs.Tab>
			<Title>
				<h2 style={{ margin: 0 }}>One</h2>
				<SuccessIcon />
				<span
					style={{
						fontWeight: 'normal',
						marginLeft: '5px',
					}}
				>
					Lorem ipsum dolor sit amet, consectetur adipiscing elit.
				</span>
			</Title>
			One content
		</VerticalTabs.Tab>,
 
		<VerticalTabs.Tab>
			<VerticalTabs.Title>
				<h2 style={{ margin: 0 }}>Two</h2>
				<WarningIcon />
				<span
					style={{
						fontWeight: 'normal',
						marginLeft: '5px',
					}}
				>
					Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
				</span>
			</VerticalTabs.Title>
			Two content
		</VerticalTabs.Tab>,
 
		<VerticalTabs.Tab>
			<VerticalTabs.Title>{titleThree}</VerticalTabs.Title>
			Three content
		</VerticalTabs.Tab>,
 
		<VerticalTabs.Tab>
			<VerticalTabs.Title>Four</VerticalTabs.Title>
			Four content
		</VerticalTabs.Tab>,
	]),
};