Best JavaScript code snippet using storybook-root
addon-actions.stories.js
Source:addon-actions.stories.js
1import { window, File } from 'global';2import React, { Fragment } from 'react';3import {4 action,5 actions,6 configureActions,7 decorate,8 decorateAction,9} from '@storybook/addon-actions';10import { Form } from '@storybook/components';11const { Button } = Form;12const pickNative = decorate([args => [args[0].nativeEvent]]);13const pickNativeAction = decorateAction([args => [args[0].nativeEvent]]);14export default {15 title: 'Addons/Actions',16 parameters: {17 options: {18 selectedPanel: 'storybook/actions/panel',19 },20 },21};22export const BasicExample = () => <Button onClick={action('hello-world')}>Hello World</Button>;23BasicExample.story = {24 name: 'Basic example',25};26export const MultipleActions = () => (27 <Button {...actions('onClick', 'onMouseOver')}>Hello World</Button>28);29MultipleActions.story = {30 name: 'Multiple actions',31};32export const MultipleActionsConfig = () => (33 <Button {...actions('onClick', 'onMouseOver', { clearOnStoryChange: false })}>34 Moving away from this story will persist the action logger35 </Button>36);37MultipleActionsConfig.story = {38 name: 'Multiple actions + config',39};40export const MultipleActionsAsObject = () => (41 <Button {...actions({ onClick: 'clicked', onMouseOver: 'hovered' })}>Hello World</Button>42);43MultipleActionsAsObject.story = {44 name: 'Multiple actions as object',45};46export const MultipleActionsObjectConfig = () => (47 <Button48 {...actions({ onClick: 'clicked', onMouseOver: 'hovered' }, { clearOnStoryChange: false })}49 >50 Moving away from this story will persist the action logger51 </Button>52);53MultipleActionsObjectConfig.story = {54 name: 'Multiple actions, object + config',55};56export const DecoratedAction = () => (57 <Button onClick={pickNative.action('decorated')}>Native Event</Button>58);59DecoratedAction.story = {60 name: 'Decorated action',61};62export const DecoratedActionConfig = () => (63 <Button onClick={pickNative.action('decorated', { clearOnStoryChange: false })}>64 Moving away from this story will persist the action logger65 </Button>66);67DecoratedActionConfig.story = {68 name: 'Decorated action + config',69};70export const DecoratedActions = () => (71 <Button {...pickNative.actions('onClick', 'onMouseOver')}>Native Event</Button>72);73DecoratedActions.story = {74 name: 'Decorated actions',75};76export const DecoratedActionsConfig = () => (77 <Button {...pickNative.actions('onClick', 'onMouseOver', { clearOnStoryChange: false })}>78 Moving away from this story will persist the action logger79 </Button>80);81DecoratedActionsConfig.story = {82 name: 'Decorated actions + config',83};84export const CircularPayload = () => {85 const circular = { foo: {} };86 circular.foo.circular = circular;87 return <Button onClick={() => action('circular')(circular)}>Circular Payload</Button>;88};89CircularPayload.story = {90 name: 'Circular Payload',91};92export const ReservedKeywordAsName = () => <Button onClick={action('delete')}>Delete</Button>;93ReservedKeywordAsName.story = {94 name: 'Reserved keyword as name',95};96export const AllTypes = () => {97 function A() {}98 function B() {}99 const bound = B.bind({});100 let file;101 try {102 file = new File([''], 'filename.txt', { type: 'text/plain', lastModified: new Date() });103 } catch (error) {104 file = error;105 }106 const reg = /fooBar/g;107 return (108 <Fragment>109 <Button onClick={() => action('Array')(['foo', 'bar', { foo: 'bar' }])}>Array</Button>110 <Button onClick={() => action('Boolean')(false)}>Boolean</Button>111 <Button onClick={() => action('Empty Object')({})}>Empty Object</Button>112 <Button onClick={() => action('File')(file)}>File</Button>113 <Button onClick={() => action('Function', { allowFunction: true })(A)}>Function A</Button>114 <Button onClick={() => action('Function (bound)', { allowFunction: true })(bound)}>115 Bound Function B116 </Button>117 <Button onClick={() => action('Infinity')(Infinity)}>Infinity</Button>118 <Button onClick={() => action('-Infinity')(-Infinity)}>-Infinity</Button>119 <Button onClick={() => action('NaN')(NaN)}>NaN</Button>120 <Button onClick={() => action('null')(null)}>null</Button>121 <Button onClick={() => action('Number')(10000)}>Number</Button>122 <Button123 onClick={() =>124 action('Multiple')(125 'foo',126 1000,127 true,128 false,129 [1, 2, 3],130 null,131 undefined,132 { foo: 'bar' },133 window134 )135 }136 >137 Multiple138 </Button>139 <Button onClick={() => action('Plain Object')({ foo: { bar: { baz: { bar: 'foo' } } } })}>140 Plain Object141 </Button>142 <Button143 onClick={() =>144 action('ObjectDepth2', { depth: 2 })({ root: { one: { two: { three: 'foo' } } } })145 }146 >147 Object (depth: 2)148 </Button>149 <Button onClick={() => action('RegExp')(reg)}>RegExp</Button>150 <Button onClick={() => action('String')('foo')}>String</Button>151 <Button onClick={() => action('Symbol')(Symbol('A_SYMBOL'))}>Symbol</Button>152 <Button onClick={action('SyntheticMouseEvent')}>SyntheticEvent</Button>153 <Button onClick={() => action('undefined')(undefined)}>undefined</Button>154 <Button onClick={() => action('window')(window)}>Window</Button>155 </Fragment>156 );157};158AllTypes.story = {159 name: 'All types',160};161export const ConfigureActionsDepth = () => {162 configureActions({163 depth: 2,164 });165 return (166 <Button onClick={() => action('ConfiguredDepth')({ root: { one: { two: { three: 'foo' } } } })}>167 Object (configured depth: 2)168 </Button>169 );170};171export const PersistingTheActionLogger = () => (172 <Fragment>173 <p>Moving away from this story will persist the action logger</p>174 <Button onClick={action('clear-action-logger', { clearOnStoryChange: false })}>175 Object (configured clearOnStoryChange: false)176 </Button>177 </Fragment>178);179PersistingTheActionLogger.story = {180 name: 'Persisting the action logger',181};182export const LimitActionOutput = () => {183 configureActions({184 limit: 2,185 });186 return (187 <Fragment>188 <Button onClick={() => action('False')(false)}>False</Button>189 <Button onClick={() => action('True')(true)}>True</Button>190 </Fragment>191 );192};193LimitActionOutput.story = {194 name: 'Limit Action Output',...
Using AI Code Generation
1import { MultipleActionsConfig } from 'storybook-root-decorator';2import { withKnobs } from '@storybook/addon-knobs';3import { withInfo } from '@storybook/addon-info';4import { withA11y } from '@storybook/addon-a11y';5import { withOptions } from '@storybook/addon-options';6import { addDecorator } from '@storybook/react';7import { setDefaults } from '@storybook/addon-info';8import { setConsoleOptions } from '@storybook/addon-console';9import { setDefaults as knobsSetDefaults } from '@storybook/addon-knobs';10import { setDefaults as optionsSetDefaults } from '@storybook/addon-options';11import { setDefaults as a11ySetDefaults } from '@storybook/addon-a11y';12import { setDefaults as rootDecoratorSetDefaults } from 'storybook-root-decorator';13import { addDecorator as infoAddDecorator } from '@storybook/addon-info';14import { addDecorator as knobsAddDecorator } from '@storybook/addon-knobs';15import { addDecorator as a11yAddDecorator } from '@storybook/addon-a11y';16import { addDecorator as consoleAddDecorator } from '@storybook/addon-console';17import { addDecorator as optionsAddDecorator } from '@storybook/addon-options';
Using AI Code Generation
1import { MultipleActionsConfig } from 'storybook-root-decorator';2import { action } from '@storybook/addon-actions';3MultipleActionsConfig([4 {5 action: action('action1'),6 },7 {8 action: action('action2'),9 },10 {11 action: action('action3'),12 },13]);14import { configure, addDecorator } from '@storybook/react';15import { withMultipleActions } from 'storybook-root-decorator';16addDecorator(withMultipleActions);17configure(require.context('../src', true, /\.stories\.js$/), module);
Using AI Code Generation
1import { MultipleActionsConfig } from "storybook-root-decorator";2import { withKnobs } from "storybook-root-decorator";3import { withKnobs } from "storybook-root-decorator";4import { withKnobs } from "storybook-root-decorator";5import { withKnobs } from "storybook-root-decorator";6import { withKnobs } from "storybook-root-decorator";7import { withKnobs } from "storybook-root-decorator";8import { withKnobs } from "storybook-root-decorator";9import { withKnobs } from "storybook-root-decorator";10import { withKnobs } from "storybook-root-decorator";11import { withKnobs } from "storybook-root-decorator";12import { withKnobs } from "storybook-root-decorator";13import { withKnobs } from "storybook-root-decorator";14import { withKnobs } from "storybook-root-decorator";15import { withKnobs } from "storybook-root-decorator";16import { withKnobs } from "storybook-root-decorator";17import { withKnobs } from "storybook-root-decorator";
Using AI Code Generation
1import { MultipleActionsConfig } from 'storybook-root-decorator';2import { storiesOf } from '@storybook/react';3import Button from './Button';4import { action } from '@storybook/addon-actions';5storiesOf('Button', module)6 .addDecorator(MultipleActionsConfig([7 action('onClick'),8 action('onMouseOver'),9 action('onMouseOut')10 .add('with text', () => <Button>Hello Button</Button>)11 .add('with some emoji', () => <Button>๐ ๐ ๐ ๐ฏ</Button>);12import React from 'react';13import PropTypes from 'prop-types';14const Button = ({ children, onClick, onMouseOver, onMouseOut }) => (15 <button onClick={onClick} onMouseOver={onMouseOver} onMouseOut={onMouseOut}>16 {children}17);18Button.propTypes = {19};20export default Button;21import { configure } from '@storybook/react';22import { addDecorator } from '@storybook/react';23import { MultipleActionsConfig } from 'storybook-root-decorator';24addDecorator(MultipleActionsConfig([25 action('onClick'),26 action('onMouseOver'),27 action('onMouseOut')28]));29storiesOf('Button', module)30 .addDecorator(MultipleActionsConfig([31 action('onClick'),32 action('onMouseOver'),33 action('onMouseOut')34 .add('with text', () => <Button>Hello Button</Button>)35 .add('with some emoji', () => <Button>๐ ๐ ๐ ๐ฏ</Button>);36import { MultipleActionsConfig } from 'storybook-root-decorator';37import { storiesOf } from '@storybook/react';38import Button from './Button';39import { action } from '@storybook/addon-actions';40storiesOf('Button', module)41 .addDecorator(MultipleActionsConfig([42 action('onClick'),43 action('onMouseOver'),44 action('onMouseOut')
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!