Best JavaScript code snippet using storybook-root
prop-types.js
Source: prop-types.js
1/β* eslint-disable react/βno-unused-prop-types */β2import React from 'react';3/β/β @ts-ignore4import PropTypes, { string, shape } from 'prop-types';5import momentPropTypes from 'react-moment-proptypes';6import { PRESET_SHAPE, SOME_PROP_TYPES } from './βext';7const NAMED_OBJECT = {8 text: PropTypes.string.isRequired,9 value: PropTypes.string.isRequired,10};11const ANOTHER_OBJECT = {12 foo: PropTypes.string,13 bar: PropTypes.string,14};15const NAMED_SHAPE = PropTypes.shape({16 foo: PropTypes.string,17});18export const POSITIONS = ['top-left', 'top-right', 'top-center'];19const FunctionalComponent = () => {20 return <div>FunctionnalComponent!</βdiv>;21};22class ClassComponent extends React.PureComponent {23 render() {24 return <div>ClassComponent!</βdiv>;25 }26}27function concat(a, b) {28 return a + b;29}30function customPropType() {31 return null;32}33const nestedCustomPropType = {34 custom: customPropType,35};36const SOME_INLINE_PROP_TYPES = {37 /β**38 * Hey Hey!39 */β40 inlineString: PropTypes.string,41 inlineBool: PropTypes.bool,42 inlineNumber: PropTypes.number,43 inlineObj: PropTypes.shape({44 foo: PropTypes.string,45 }),46 inlineArray: PropTypes.arrayOf(PropTypes.number),47 inlineArrayOfObjects: PropTypes.arrayOf({ foo: PropTypes.string }),48 inlineFunctionalElement: PropTypes.element,49 inlineFunctionalElementInline: PropTypes.element,50 inlineFunctionalElementInlineReturningNull: PropTypes.element,51 inlineHtmlElement: PropTypes.element,52 inlineFunctionalElementInlineWithProps: PropTypes.element,53 inlineFunctionalElementNamedInline: PropTypes.element,54 inlineClassElement: PropTypes.element,55 inlineClassElementWithProps: PropTypes.element,56 inlineClassElementWithChildren: PropTypes.element,57 inlineClassElementInline: PropTypes.element,58 inlineFunc: PropTypes.func,59};60const SOME_INLINE_DEFAULT_PROPS = {61 inlineString: 'Inline prop default value',62 inlineBool: true,63 inlineNumber: 10,64 inlineObj: { foo: 'bar' },65 inlineArray: [1, 2, 3],66 inlineArrayOfObjects: [67 { foo: 'bar' },68 { foo: 'bar' },69 { foo: 'bar' },70 { foo: 'bar' },71 { foo: 'bar' },72 ],73 inlineFunctionalElement: <FunctionalComponent /β>,74 inlineFunctionalElementInline: () => {75 return <div>Inlined FunctionnalComponent!</βdiv>;76 },77 inlineFunctionalElementInlineReturningNull: () => {78 return null;79 },80 inlineHtmlElement: <div>Hey!</βdiv>,81 /β/β eslint-disable-next-line react/βprop-types82 inlineFunctionalElementInlineWithProps: ({ foo }) => {83 return <div>{foo}</βdiv>;84 },85 inlineFunctionalElementNamedInline: function InlinedFunctionalComponent() {86 return <div>Inlined FunctionnalComponent!</βdiv>;87 },88 inlineClassElement: <ClassComponent /β>,89 inlineClassElementWithProps: <ClassComponent className="toto" /β>,90 inlineClassElementWithChildren: (91 <ClassComponent>92 <div>hey!</βdiv>93 </βClassComponent>94 ),95 inlineClassElementInline: class InlinedClassComponent extends React.PureComponent {96 render() {97 return <div>Inlined ClassComponent!</βdiv>;98 }99 },100 inlineFunc: function add(a, b) {101 return a + b;102 },103};104export const PropTypesProps = () => <div>PropTypes!</βdiv>;105PropTypesProps.propTypes = {106 /β/β eslint-disable-next-line react/βforbid-prop-types107 any: PropTypes.any,108 bool: PropTypes.bool,109 string: PropTypes.string,110 func: PropTypes.func,111 /β**112 * A function with JSDoc tags.113 *114 * @param {string} foo - A foo value.115 * @param {number} bar - A bar value.116 * @returns {ComplexObject} - Returns a complex object.117 */β118 funcWithJsDoc: PropTypes.func,119 /β**120 * @param {string} foo - A foo value.121 * @param {number} bar - A bar value.122 * @param {number} bar1 - A bar value.123 * @param {number} bar2 - A bar value.124 * @param {number} bar3 - A bar value.125 * @param {number} bar4 - A bar value.126 * @param {number} bar5 - A bar value.127 * @returns {ComplexObject} - Returns a complex object.128 */β129 semiLongFuncWithJsDoc: PropTypes.func,130 /β**131 * @param {string} foo - A foo value.132 * @param {number} bar - A bar value.133 * @param {number} bar1 - A bar value.134 * @param {number} bar2 - A bar value.135 * @param {number} bar3 - A bar value.136 * @param {number} bar4 - A bar value.137 * @param {number} bar5 - A bar value.138 * @param {number} bar6 - A bar value.139 * @param {number} bar7 - A bar value.140 * @param {number} bar8 - A bar value.141 * @param {number} bar9 - A bar value.142 * @param {number} bar10 - A bar value.143 * @returns {ComplexObject} - Returns a complex object.144 */β145 veryLongFuncWithJsDoc: PropTypes.func,146 namedDefaultFunc: PropTypes.func,147 number: PropTypes.number,148 /β**149 * Plain object propType (use shape!!)150 */β151 obj: PropTypes.object, /β/β eslint-disable-line react/βforbid-prop-types152 symbol: PropTypes.symbol,153 node: PropTypes.node,154 useCustomPropType: customPropType,155 useNestedCustomPropType: nestedCustomPropType.custom,156 externalMomentPropType: momentPropTypes.momentObj,157 functionalElement: PropTypes.element,158 functionalElementInline: PropTypes.element,159 functionalElementNamedInline: PropTypes.element,160 classElement: PropTypes.element,161 classElementInline: PropTypes.element,162 functionalElementType: PropTypes.elementType,163 classElementType: PropTypes.elementType,164 elementWithProps: PropTypes.elementType,165 /β**166 * `instanceOf` is also supported and the custom type will be shown instead of `instanceOf`167 */β168 instanceOf: PropTypes.instanceOf(Set),169 /β**170 * `oneOf` is basically an Enum which is also supported but can be pretty big.171 */β172 oneOfString: PropTypes.oneOf(['News', 'Photos']),173 oneOfNumeric: PropTypes.oneOf([0, 1, 2, 3]),174 oneOfShapes: PropTypes.oneOf([175 PropTypes.shape({ foo: PropTypes.string }),176 PropTypes.shape({ bar: PropTypes.number }),177 ]),178 oneOfComplexShapes: PropTypes.oneOf([179 PropTypes.shape({180 /β**181 * Just an internal propType for a shape.182 * It's also required, and as you can see it supports multi-line comments!183 */β184 id: PropTypes.number.isRequired,185 /β**186 * A simple non-required function187 */β188 func: PropTypes.func,189 /β**190 * An `arrayOf` shape191 */β192 arr: PropTypes.arrayOf(193 PropTypes.shape({194 /β**195 * 5-level deep propType definition and still works.196 */β197 index: PropTypes.number.isRequired,198 })199 ),200 }),201 shape({ bar: PropTypes.number }),202 ]),203 oneOfComplexType: PropTypes.oneOf([NAMED_OBJECT, ANOTHER_OBJECT]),204 oneOfComponents: PropTypes.oneOf([FunctionalComponent, ClassComponent]),205 oneOfEval: PropTypes.oneOf((() => ['News', 'Photos'])()),206 oneOfVar: PropTypes.oneOf(POSITIONS),207 oneOfNested: PropTypes.oneOf(['News', ['bottom-left', 'botton-center', 'bottom-right']]),208 oneOfNestedSimpleInlineObject: PropTypes.oneOf(['News', [{ foo: PropTypes.string }]]),209 oneOfNestedComplexInlineObject: PropTypes.oneOf([210 'News',211 [{ nested: { foo: PropTypes.string } }],212 ]),213 oneOfNestedComplexShape: PropTypes.oneOf([214 'News',215 [{ nested: PropTypes.shape({ foo: PropTypes.string }) }],216 ]),217 /β**218 * A multi-type prop is also valid and is displayed as `Union<String|Message>`219 */β220 oneOfType: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Set)]),221 /β**222 * array of a primitive type223 */β224 arrayOfPrimitive: PropTypes.arrayOf(PropTypes.number),225 arrayOfNamedObject: PropTypes.arrayOf(NAMED_OBJECT),226 arrayOfShortInlineObject: PropTypes.arrayOf({227 foo: PropTypes.string,228 }),229 arrayOfInlineObject: PropTypes.arrayOf({230 text: PropTypes.string.isRequired,231 value: PropTypes.string.isRequired,232 }),233 arrayOfComplexInlineObject: PropTypes.arrayOf({234 text: PropTypes.string.isRequired,235 value: PropTypes.string.isRequired,236 shape: {237 id: PropTypes.string.isRequired,238 age: PropTypes.number.isRequired,239 },240 }),241 arrayOfShortShape: PropTypes.arrayOf(242 PropTypes.shape({243 bar: PropTypes.string,244 })245 ),246 arrayOfComplexShape: PropTypes.arrayOf(247 PropTypes.shape({248 /β**249 * Just an internal propType for a shape.250 * It's also required, and as you can see it supports multi-line comments!251 */β252 id: PropTypes.number.isRequired,253 /β**254 * A simple non-required function255 */β256 func: PropTypes.func,257 /β**258 * An `arrayOf` shape259 */β260 arr: PropTypes.arrayOf(261 PropTypes.shape({262 /β**263 * 5-level deep propType definition and still works.264 */β265 index: PropTypes.number.isRequired,266 })267 ),268 })269 ),270 arrayExternalShape: PropTypes.arrayOf(PropTypes.shape(PRESET_SHAPE)),271 /β**272 * A simple `objectOf` propType.273 */β274 simpleObjectOf: PropTypes.objectOf(PropTypes.number),275 objectOfShortInlineObject: PropTypes.objectOf({276 foo: PropTypes.string,277 }),278 objectOfInlineObject: PropTypes.objectOf({279 foo: PropTypes.string,280 bar: PropTypes.string,281 barry: PropTypes.string,282 }),283 objectOfShortShape: PropTypes.objectOf(284 PropTypes.shape({285 foo: string,286 })287 ),288 /β**289 * A very complex `objectOf` propType.290 */β291 objectOfComplexShape: PropTypes.objectOf(292 PropTypes.shape({293 /β**294 * Just an internal propType for a shape.295 * It's also required, and as you can see it supports multi-line comments!296 */β297 id: PropTypes.number.isRequired,298 /β**299 * A simple non-required function300 */β301 func: PropTypes.func,302 /β**303 * An `arrayOf` shape304 */β305 arr: PropTypes.arrayOf(306 PropTypes.shape({307 /β**308 * 5-level deep propType definition and still works.309 */β310 index: PropTypes.number.isRequired,311 })312 ),313 })314 ),315 namedObjectOf: PropTypes.objectOf(NAMED_OBJECT),316 shapeShort: PropTypes.shape({317 foo: string,318 }),319 shapeLong: PropTypes.shape({320 foo: string,321 prop1: string,322 prop2: string,323 prop3: string,324 prop4: string,325 prop5: string,326 prop6: string,327 prop7: string,328 }),329 /β**330 * propType for shape with nested arrayOf331 *332 * Also, multi-line description333 */β334 shapeComplex: PropTypes.shape({335 /β**336 * Just an internal propType for a shape.337 * It's also required, and as you can see it supports multi-line comments!338 */β339 id: PropTypes.number.isRequired,340 /β**341 * A simple non-required function342 */β343 func: PropTypes.func,344 /β**345 * An `arrayOf` shape346 */β347 arr: PropTypes.arrayOf(348 PropTypes.shape({349 /β**350 * 5-level deep propType definition and still works.351 */β352 index: PropTypes.number.isRequired,353 })354 ),355 shape: PropTypes.shape({356 shape: PropTypes.shape({357 foo: PropTypes.string,358 oneOf: PropTypes.oneOf(['one', 'two']),359 }),360 }),361 oneOf: PropTypes.oneOf(['one', 'two']),362 }),363 shapeWithArray: PropTypes.shape({364 arr: PropTypes.arrayOf({ foo: PropTypes.string }),365 }),366 namedShape: NAMED_SHAPE,367 namedObjectInShape: PropTypes.shape(NAMED_OBJECT),368 exact: PropTypes.exact({369 name: PropTypes.string,370 quantity: PropTypes.number,371 }),372 namedExact: PropTypes.exact(NAMED_OBJECT),373 /β**374 * test string with a comment that has375 * two identical lines376 * two identical lines377 */β378 optionalString: PropTypes.string,379 requiredString: PropTypes.string.isRequired,380 nullDefaultValue: PropTypes.string,381 undefinedDefaultValue: PropTypes.string,382 ...SOME_INLINE_PROP_TYPES,383 ...SOME_PROP_TYPES,384};385PropTypesProps.defaultProps = {386 any: 'Default any',387 bool: false,388 string: 'Default string',389 func: () => {},390 funcWithJsDoc: (foo, bar) => {391 /β/β eslint-disable-next-line392 const yo = window.document;393 /β/β eslint-disable-next-line394 const pouf = souffle;395 return { foo, bar };396 },397 namedDefaultFunc: concat,398 number: 5,399 obj: {400 key: 'value',401 },402 symbol: Symbol('Default symbol'),403 node: <div>Hello!</βdiv>,404 functionalElement: <FunctionalComponent className="toto" /β>,405 functionalElementInline: () => {406 return <div>Inlined FunctionnalComponent!</βdiv>;407 },408 functionalElementNamedInline: function InlinedFunctionalComponent() {409 return <div>Inlined FunctionnalComponent!</βdiv>;410 },411 classElement: <ClassComponent /β>,412 classElementInline: class InlinedClassComponent extends React.PureComponent {413 render() {414 return <div>Inlined ClassComponent!</βdiv>;415 }416 },417 functionalElementType: FunctionalComponent,418 classElementType: ClassComponent,419 elementWithProps: <ClassComponent className="w8 h8 fill-marine-500" /β>,420 instanceOf: new Set(),421 oneOfString: 'News',422 oneOfNumeric: 1,423 oneOfShapes: { foo: 'bar' },424 oneOfComplexShapes: {425 thing: {426 id: 2,427 func: () => {},428 arr: [],429 },430 },431 oneOfComplexType: { text: 'foo', value: 'bar' },432 oneOfComponents: <FunctionalComponent /β>,433 oneOfEval: 'Photos',434 oneOfVar: 'top-right',435 oneOfNested: 'top-right',436 oneOfType: 'hello',437 arrayOfPrimitive: [1, 2, 3],438 arrayOfString: ['0px', '0px'],439 arrayOfNamedObject: [{ text: 'foo', value: 'bar' }],440 arrayOfShortInlineObject: [{ foo: 'bar' }],441 arrayOfInlineObject: [{ text: 'foo', value: 'bar' }],442 arrayOfComplexInlineObject: [{ text: 'foo', value: 'bar' }],443 arrayOfShortShape: [{ bar: 'foo' }],444 arrayOfComplexShape: [445 {446 thing: {447 id: 2,448 func: () => {},449 arr: [],450 },451 },452 ],453 simpleObjectOf: { key: 1 },454 objectOfShortInlineObject: { foo: 'bar' },455 objectOfInlineObject: { foo: 'bar', bar: 'foo' },456 objectOfShortShape: { foo: 'bar' },457 objectOfComplexShape: {458 thing: {459 id: 2,460 func: () => {},461 arr: [],462 },463 },464 namedObjectOf: { text: 'foo', value: 'bar' },465 shapeShort: { foo: 'bar' },466 shapeComplex: {467 id: 3,468 func: () => {},469 arr: [],470 shape: {471 shape: {472 foo: 'bar',473 },474 },475 },476 namedShape: { foo: 'bar' },477 namedObjectInShape: { text: 'foo', value: 'bar' },478 exact: { name: 'foo', quantity: 2 },479 namedExact: { text: 'foo', value: 'bar' },480 optionalString: 'Default String',481 nullDefaultValue: null,482 undefinedDefaultValue: undefined,483 ...SOME_INLINE_DEFAULT_PROPS,...
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/βreact';3import { withInfo } from '@storybook/βaddon-info';4import { action } from '@storybook/βaddon-actions';5import { Button } from '@storybook/βreact/βdemo';6storiesOf('Button', module)7 .addDecorator((story, context) => withInfo('common info')(story)(context))8 .add('with text', () => (9 <Button onClick={action('clicked')}>Hello Button</βButton>10 .add('with some emoji', () => (11 <Button onClick={action('clicked')}>π π π π―</βButton>12 ));13import React from 'react';14import { storiesOf } from '@storybook/βreact';15import { withInfo } from '@storybook/βaddon-info';16import { action } from '@storybook/βaddon-actions';17import { Button } from '@storybook/βreact/βdemo';18storiesOf('Button', module)19 .addDecorator((story, context) => withInfo('common info')(story)(context))20 .add('with text', () => (21 <Button onClick={action('clicked')}>Hello Button</βButton>22 .add('with some emoji', () => (23 <Button onClick={action('clicked')}>π π π π―</βButton>24 ));25import React from 'react';26import { storiesOf } from '@storybook/βreact';27import { withInfo } from '@storybook/βaddon-info';28import { action } from '@storybook/βaddon-actions';29import { Button } from '@storybook/βreact/βdemo';30storiesOf('Button', module)31 .addDecorator((story, context) => withInfo('common info')(story)(context))32 .add('with text', () => (33 <Button onClick={action('clicked')}>Hello Button</βButton>34 .add('with some emoji', () => (35 <Button onClick={action('clicked')}>π π π π―</βButton>36 ));37import React from 'react';38import { storiesOf } from '@storybook/βreact';39import { withInfo } from '@storybook/βaddon-info';40import { action } from '@
Using AI Code Generation
1import { PropTypesProps } from 'storybook-root';2import { PropTypesProps } from 'storybook-root';3import { PropTypesProps } from 'storybook-root';4import { PropTypesProps } from 'storybook-root';5import { PropTypesProps } from 'storybook-root';6import { PropTypesProps } from 'storybook-root';7import { PropTypesProps } from 'storybook-root';8import { PropTypesProps } from 'storybook-root';9import { PropTypesProps } from 'storybook-root';10import { PropTypesProps } from 'storybook-root';11import { PropTypesProps } from 'storybook-root';12import { PropTypesProps } from 'storybook-root';13import { PropTypesProps } from 'storybook-root';14import { PropTypesProps } from 'storybook-root';15import { PropTypesProps } from 'storybook-root';16import { PropTypesProps } from 'storybook-root';17import { PropTypesProps } from 'storybook-root';18import { PropTypesProps } from 'storybook-root';19import { PropTypesProps } from 'storybook-root';20import { PropTypesProps } from 'storybook-root';21import { PropTypesProps } from 'storybook-root';22import { PropTypesProps } from 'storybook-root';23import { PropTypesProps } from 'storybook-root';
Using AI Code Generation
1import PropTypes from 'prop-types';2import { storiesOf } from '@storybook/βreact';3import { withInfo } from '@storybook/βaddon-info';4import Button from '../βsrc/βcomponents/βButton';5const stories = storiesOf('Button', module);6stories.add(7 withInfo({8 })(() => <Button>Click Here</βButton>)9);
Using AI Code Generation
1import { PropTypesProps } from 'storybook-root-decorator';2PropTypesProps.propTypes = {3 fifteenthProp: PropTypes.oneOf(['News', 'Photos']),4 sixteenthProp: PropTypes.oneOf(['News', 'Photos']).isRequired,5 seventeenthProp: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),6 eighteenthProp: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,7 nineteenthProp: PropTypes.arrayOf(PropTypes.number),8 twentiethProp: PropTypes.arrayOf(PropTypes.number).isRequired,9 twentyFirstProp: PropTypes.objectOf(PropTypes.number),10 twentySecondProp: PropTypes.objectOf(PropTypes.number).isRequired,11 twentyThirdProp: PropTypes.shape({12 }),13 twentyFourthProp: PropTypes.shape({
Check out the latest blogs from LambdaTest on this topic:
In 2007, Steve Jobs launched the first iPhone, which revolutionized the world. But because of that, many businesses dealt with the problem of changing the layout of websites from desktop to mobile by delivering completely different mobile-compatible websites under the subdomain of βmβ (e.g., https://m.facebook.com). And we were all trying to figure out how to work in this new world of contending with mobile and desktop screen sizes.
One of the essential parts when performing automated UI testing, whether using Selenium or another framework, is identifying the correct web elements the tests will interact with. However, if the web elements are not located correctly, you might get NoSuchElementException in Selenium. This would cause a false negative result because we wonβt get to the actual functionality check. Instead, our test will fail simply because it failed to interact with the correct element.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
When most firms employed a waterfall development model, it was widely joked about in the industry that Google kept its products in beta forever. Google has been a pioneer in making the case for in-production testing. Traditionally, before a build could go live, a tester was responsible for testing all scenarios, both defined and extempore, in a testing environment. However, this concept is evolving on multiple fronts today. For example, the tester is no longer testing alone. Developers, designers, build engineers, other stakeholders, and end users, both inside and outside the product team, are testing the product and providing feedback.
Have you ever visited a website that only has plain text and images? Most probably, no. Itβs because such websites do not exist now. But there was a time when websites only had plain text and images with almost no styling. For the longest time, websites did not focus on user experience. For instance, this is how eBayβs homepage looked in 1999.
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!!