All files / RadioButtonLabeled RadioButtonLabeled.stories.tsx

70% Statements 14/20
100% Branches 0/0
40% Functions 4/10
70% Lines 14/20

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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186                                          1x 1x       1x   1x       1x                                                                                                                           1x 1x         1x                                                         1x 1x     1x                             1x 1x       1x                                                                
import React, { useState } from 'react';
import { Meta, Story } from '@storybook/react';
 
import RadioButtonLabeled, {
	IRadioButtonLabeledProps,
} from './RadioButtonLabeled';
 
export default {
	title: 'Controls/RadioButtonLabeled',
	component: RadioButtonLabeled,
	parameters: {
		docs: {
			description: {
				component: RadioButtonLabeled.peek.description,
			},
		},
	},
	args: RadioButtonLabeled.defaultProps,
} as Meta;
 
/* Basic */
export const Basic: Story<IRadioButtonLabeledProps> = (args) => {
	const style = {
		marginBottom: '3px',
	};
 
	const [flavor, setFlavor] = useState('vanilla');
 
	const handleSelectedFlavor = (flavor: string) => {
		setFlavor(flavor);
	};
 
	return (
		<section>
			<span
				style={{
					display: 'inline-flex',
					flexDirection: 'column',
					alignItems: 'flex-start',
				}}
			>
				<RadioButtonLabeled
					{...args}
					isSelected={flavor === 'vanilla'}
					name='interactive-radio-buttons'
					onSelect={() => handleSelectedFlavor('vanilla')}
					style={style}
				>
					<RadioButtonLabeled.Label>Vanilla</RadioButtonLabeled.Label>
				</RadioButtonLabeled>
				<RadioButtonLabeled
					{...args}
					isSelected={flavor === 'chocolate'}
					name='interactive-radio-buttons'
					onSelect={() => handleSelectedFlavor('chocolate')}
					style={style}
				>
					<RadioButtonLabeled.Label>Chocolate</RadioButtonLabeled.Label>
				</RadioButtonLabeled>
				<RadioButtonLabeled
					{...args}
					isSelected={flavor === 'strawberry'}
					name='interactive-radio-buttons'
					onSelect={() => handleSelectedFlavor('strawberry')}
					style={style}
				>
					<RadioButtonLabeled.Label>Strawberry</RadioButtonLabeled.Label>
				</RadioButtonLabeled>
				<RadioButtonLabeled
					{...args}
					isSelected={flavor === 'saltedCaramel'}
					name='interactive-radio-buttons'
					onSelect={() => handleSelectedFlavor('saltedCaramel')}
					style={style}
				>
					<RadioButtonLabeled.Label>Salted caramel</RadioButtonLabeled.Label>
				</RadioButtonLabeled>
				<RadioButtonLabeled
					{...args}
					isSelected={flavor === 'mintChip'}
					name='interactive-radio-buttons'
					onSelect={() => handleSelectedFlavor('mintChip')}
					style={style}
				>
					<RadioButtonLabeled.Label>
						Mint chocolate chip (the best)
					</RadioButtonLabeled.Label>
				</RadioButtonLabeled>
			</span>
		</section>
	);
};
 
/* States */
export const States: Story<IRadioButtonLabeledProps> = (args) => {
	const style = {
		marginBottom: '3px',
		marginRight: '13px',
	};
 
	return (
		<section>
			<RadioButtonLabeled {...args} style={style}>
				<RadioButtonLabeled.Label>(default props)</RadioButtonLabeled.Label>
			</RadioButtonLabeled>
 
			<section style={{ display: 'flex' }}>
				<RadioButtonLabeled {...args} isDisabled={true} style={style}>
					<RadioButtonLabeled.Label>Disabled</RadioButtonLabeled.Label>
				</RadioButtonLabeled>
				<RadioButtonLabeled {...args} isSelected={true} style={style}>
					<RadioButtonLabeled.Label>Selected</RadioButtonLabeled.Label>
				</RadioButtonLabeled>
				<RadioButtonLabeled
					{...args}
					isDisabled={true}
					isSelected={true}
					style={style}
				>
					<RadioButtonLabeled.Label>
						Disabled and Selected
					</RadioButtonLabeled.Label>
				</RadioButtonLabeled>
			</section>
		</section>
	);
};
 
/* Label As Child */
export const LabelAsChild: Story<IRadioButtonLabeledProps> = (args) => {
	const style = {
		marginBottom: '3px',
	};
	return (
		<section>
			<RadioButtonLabeled {...args} style={style}>
				<RadioButtonLabeled.Label>Just text</RadioButtonLabeled.Label>
			</RadioButtonLabeled>
			<RadioButtonLabeled {...args} style={style}>
				<RadioButtonLabeled.Label>
					<span>HTML element</span>
				</RadioButtonLabeled.Label>
			</RadioButtonLabeled>
		</section>
	);
};
 
/* Label As Prop */
export const LabelAsProp: Story<IRadioButtonLabeledProps> = (args) => {
	const style = {
		marginBottom: '3px',
	};
 
	return (
		<section>
			<RadioButtonLabeled Label='Just text' style={style}></RadioButtonLabeled>
			<RadioButtonLabeled
				Label={<span>HTML element</span>}
				style={style}
			></RadioButtonLabeled>
			<RadioButtonLabeled
				Label={
					[
						'Text in an array',
						'Only the first value in the array is used',
						'The rest of these should be ignored',
					] as any
				}
				style={style}
			></RadioButtonLabeled>
			<RadioButtonLabeled
				Label={
					[
						<span key='1'>HTML element in an array</span>,
						<span key='2'>
							Again only the first value in the array is used
						</span>,
						<span key='3'>The rest should not be rendered</span>,
					] as any
				}
				style={style}
			></RadioButtonLabeled>
		</section>
	);
};