Best JavaScript code snippet using storybook-root
index.js
Source: index.js
1"use strict";2import {PropTypes} from "react";3/β/βwe'll re-export these for convenience in the babel6 world.4const {string, bool, number, object, func, any, node, shape, arrayOf, instanceOf, oneOf, oneOfType} = PropTypes;5function customPropType(type, name) {6 function customPropType$return(...args) {7 return type.apply(api, args);8 }9 customPropType$return.isRequired = function customPropType$return$isRequired(...args) {10 return type.isRequired.apply(type, args);11 };12 if (name)13 customPropType$return.propTypeName = name;14 return customPropType$return;15}16function propTypeToName(propType) {17 const keys = Object.keys(api), l = keys.length;18 for (let i = 0; i < l; i++) {19 let key = keys[i], f = api[key];20 if (f.isRequired === propType) {21 return '*' + key;22 }23 if (f === propType) {24 return key;25 }26 }27}28function propTypesToNames(props) {29 return Object.keys(props).reduce((ret, k)=> {30 ret[k] = propTypeToName(props[k]);31 return ret;32 }, {});33}34const deprecated = function (message) {35 return function deprecated$propType(props, propName, componentName) {36 return propName in props ? new Error(`DEPRECATED: ${message} in ${componentName}.propTypes.${propName}`) : void(0);37 }38};39const conditional = oneOfType([string, shape({40 operator: oneOfType([string, func])41})]);42const domType = customPropType(node, 'domType');43const fields = customPropType(arrayOf(string), 'fields');44const title = customPropType(oneOfType([string, bool]), 'title');45const injector = shape({46 inject: func.isRequired47});48const blurValidate = customPropType(func, 'blurValidate');49const changeValidate = customPropType(func, 'changeValidate');50const validate = customPropType(func, 'validate');51const value = customPropType(any, 'value');52const message = customPropType(any, 'message');53const error = customPropType(any, 'error');54const errors = customPropType(any, 'errors');55const promise = shape({then: func});56const id = customPropType(string, 'id');57const htmlFor = customPropType(id, 'htmlFor');58const fieldAttrs = customPropType(object, 'fieldAttrs');59const cssClass = customPropType(string, 'cssClass');60const style = customPropType(object, 'style');61const typeClass = customPropType(cssClass, 'typeClass');62const templateClass = customPropType(cssClass, 'templateClass');63const injectedClass = customPropType(any, "injectedClass");64const event = customPropType(func, 'event');65const validator = customPropType(func, 'validator');66const path = customPropType(string, 'path');67const placeholder = customPropType(string, 'placeholder');68const arrayString = oneOfType([string, arrayOf(string)])69const submit = customPropType(func, 'submit');70const listener = customPropType(any, 'listener');71/β**72 * A valueEvent does not expect target.value73 */β74const valueEvent = customPropType(func, 'valueEvent');75/β**76 * A targetEvent expects the first arg to have target.value77 */β78const targetEvent = customPropType(func, 'targetEvent');79/β**80 * A errorEvent expects the first arg to be an error.81 */β82const errorEvent = customPropType(func, 'errorEvent');83/β**84 * Signify this is a blur Event Listener.85 */β86const blurEvent = customPropType(func, 'blurEvent');87/β**88 * Signify this is a onValid Event listener.89 */β90const validEvent = customPropType(func, 'validEvent');91const dataType = customPropType(string, 'dataType');92const type = oneOfType([string, func]);93const typeDescription = oneOfType([string, shape({94 type: string.isRequired95})]);96const _transitionTypes = oneOf(['appear', 'enter', 'leave']);97const transition = oneOfType([PropTypes.string, shape({98 transition: PropTypes.string,99 on: _transitionTypes100})]);101/β**102 * Signify this property can take an expression. This103 * allows properties to be tied to the valueManager. So104 * it will evaluate the property against the valueManager.105 *106 * It will add a listener for each of the corresponding107 * matching strings.108 *109 */β110const expression = customPropType(string, 'expression');111const loader = shape({112 loadTemplate: func,113 loadType: func,114 loadSchema: func,115 loadValidator: func,116 loadProcessor: func,117 loadOperator: func118});119const valueManager = shape({120 addListener: func,121 addErrorListener: func,122 addValidateListener: func,123 addSubmitListener: func,124 addStateListener: func,125});126let contentShape = {127 className: cssClass,128 type: string,129 children: bool130};131let pContentShape = shape(contentShape);132let contentType = oneOfType([pContentShape, string, bool, func, number, arrayOf(oneOfType([string, string, bool, number, func, pContentShape]))]);133contentShape.content = contentType;134const content = contentType;135const template = oneOfType([string, bool, shape({136 template: oneOfType([string, bool, func]),137 content: content,138 className: cssClass139}), func]);140const button = oneOfType([string, shape({141 onClick: event,142 buttonClass: cssClass,143 action: string,144 name: string,145 value: string,146 iconClass: cssClass147})]);148const buttons = oneOfType([149 button,150 arrayOf(button),151 shape({152 buttonsClass: cssClass,153 onButtonClick: event,154 buttons: oneOfType([arrayString, arrayOf(button)]),155 buttonTemplate: template,156 buttonsTemplate: template157 })158]);159const fieldset = shape({160 fields: arrayString,161 legend: content,162 className: cssClass,163 buttons: buttons,164 template: template165});166const literal = oneOfType([string, bool, number, instanceOf(Date)])167const options = oneOfType([168 arrayString,169 arrayOf(shape({170 label: string,171 val: literal172 }))173]);174const optionsGroup = oneOfType([175 arrayString,176 arrayOf(shape({177 options: options,178 group: string,179 label: string,180 labelHTML: string,181 val: literal182 }))183])184const schema = oneOfType([string, object, shape({185 fields: arrayString,186 fieldsets: oneOfType([arrayString, fieldset, arrayOf(fieldset)]),187 schema: object,188})]);189const array = arrayOf(any);190const validators = oneOfType([arrayString, arrayOf(validators)]);191const operator = oneOfType([string, func, instanceOf(RegExp)]);192const events = {193 onValidate: event,194 onFocus: event,195 onBlur: event,196 onValid: event,197 onChange: oneOfType([targetEvent, valueEvent])198};199const field = customPropType(any, 'field');200const mixin = {201 events: events,202 field: {203 ...events,204 title: content,205 help: content,206 name: string,207 placeholder: placeholder,208 dataType: dataType,209 editorClass: cssClass,210 fieldClass: cssClass,211 field: {}212 }213};...
utils.ts
Source: utils.ts
1import type { Leaves } from '../β../βtheme/βbase/βtypes';2import type { ComponentTheme, ITheme } from '../β../βtheme';3import type { ResponsiveValue } from './βresponsiveValue';4export type VariantType<5 Component extends keyof ITheme['components']6> = 'variants' extends keyof ITheme['components'][Component]7 ? ResponsiveValue<8 keyof ITheme['components'][Component]['variants'] | (string & {})9 >10 : unknown;11export type SpaceType = ResponsiveValue<12 keyof ITheme['space'] | (string & {}) | number13>;14export type SizeType = ResponsiveValue<15 keyof ITheme['sizes'] | (string & {}) | number16>;17export type ThemeComponentSizeType<18 Component extends keyof ITheme['components']19> = ResponsiveValue<20 'sizes' extends keyof ITheme['components'][Component]21 ? keyof ITheme['components'][Component]['sizes'] | (string & {}) | number22 : never23>;24export type CombinedSizeType<Component extends keyof ITheme['components']> =25 | SizeType26 | ThemeComponentSizeType<Component>;27export type ColorType = ResponsiveValue<28 Leaves<ITheme['colors']> | (string & {})29>;30export type ColorSchemeType = ResponsiveValue<31 Exclude<keyof ITheme['colors'], 'contrastThreshold'> | (string & {})32>;33type ComponentType<T extends keyof ITheme['components']> = {34 [Property in keyof ITheme['components'][T]]: ITheme['components'][T][Property];35};36type ParametersOf<T> = {37 [Key in keyof T]: T[Key] extends (...args: any) => void38 ? Parameters<T[Key]>[0] extends {}39 ? Parameters<T[Key]>[0]40 : {}41 : {};42}[keyof T];43/β/β type VariantParams<T extends keyof ITheme['components']> = ParametersOf<44/β/β /β/β@ts-ignore45/β/β ComponentType<T>['variants']46/β/β >;47/β/β type PickedVariantParams<T extends keyof ITheme['components']> = Pick<48/β/β VariantParams<T>,49/β/β keyof VariantParams<T>50/β/β >;51type ParameterType<T, Key> = ParametersOf<52 /β/β@ts-ignore53 ComponentType<T>[Key]54>;55type CustomPropType<T extends keyof ITheme['components'], Key> = Extract<56 ParameterType<T, Key>,57 Pick<ParameterType<T, Key>, keyof ParameterType<T, Key>>58>;59/β/β export type CustomProps<T extends keyof ITheme['components']> =60/β/β | CustomPropType<T, 'variants'>61/β/β | CustomPropType<T, 'baseStyle'>62/β/β | CustomPropType<T, 'sizes'>63/β/β | CustomPropType<T, 'defaultProps'>;64export type CustomComponentProps<65 T extends keyof ITheme['components']66> = Partial<67 Exclude<68 {69 [Key in keyof ComponentTheme]: CustomPropType<T, Key>;70 }[keyof ComponentTheme],71 undefined72 >73>;74export type CustomProps<75 T extends keyof ITheme['components']76> = CustomComponentProps<T> extends never77 ? {}78 : /β/β : CustomComponentProps<T> extends Record<string, any>79 /β/β ? {}80 UnionToIntersection<CustomComponentProps<T>> & {};81export type UnionToIntersection<U> = (82 U extends any ? (k: U) => void : never83) extends (k: infer I) => void84 ? I...
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/βreact';3import { action } from '@storybook/βaddon-actions';4import { customPropType } from 'storybook-root-decorator';5import Button from './βButton';6storiesOf('Button', module)7 .add('with text', () => (8 <Button onClick={action('clicked')}>Hello Button</βButton>9 .add('with some emoji', () => (10 <Button onClick={action('clicked')}>π π π π―</βButton>11 .add('with customPropType', () => (12 <Button onClick={action('clicked')} customProp={customPropType}>π π π π―</βButton>13 .add('with customPropType and customPropType', () => (14 <Button onClick={action('clicked')} customProp={customPropType} customProp2={customPropType}>π π π π―</βButton>15 ));16import React from 'react';17import PropTypes from 'prop-types';18const Button = ({ onClick, children }) => (19 <button onClick={onClick}>20 {children}21);22Button.propTypes = {23};24Button.defaultProps = {25};26export default Button;27import React from 'react';28import { configure, addDecorator } from '@storybook/βreact';29import { withInfo } from '@storybook/βaddon-info';30import { withOptions } from '@storybook/βaddon-options';31import { setDefaults } from 'storybook-root-decorator';32import '../βsrc/βindex.css';33setDefaults({34 styles: {35 header: {36 h1: {37 },38 body: {39 },40 h2: {41 },42 },43 infoBody: {44 },
Using AI Code Generation
1import { customPropType } from 'storybook-root-decorator';2import { storiesOf } from '@storybook/βreact';3import { withInfo } from '@storybook/βaddon-info';4import { withKnobs, text } from '@storybook/βaddon-knobs';5import { withCustomPropType } from 'storybook-root-decorator';6storiesOf('Test', module)7 .addDecorator(withKnobs)8 .addDecorator(withInfo)9 .addDecorator(withCustomPropType)10 .add('Test', () => {11 const propType = customPropType({12 type: {13 },14 });15 const props = {16 test: text('test', 'test'),17 };18 return <Test {...props} /β>;19 });20import { customPropType } from 'storybook-root-decorator';21import { storiesOf } from '@storybook/βreact';22import { withInfo } from '@storybook/βaddon-info';23import { withKnobs, text } from '@storybook/βaddon-knobs';24import { withCustomPropType } from 'storybook-root-decorator';25storiesOf('Test', module)26 .addDecorator(withKnobs)27 .addDecorator(withInfo)28 .addDecorator(withCustomPropType)29 .add('Test', () => {30 const propType = customPropType({31 type: {32 },33 });34 const props = {35 test: text('test', 'test'),36 };37 return <Test {...props} /β>;38 });39import { customPropType } from 'storybook-root-decorator';40import { storiesOf } from '@storybook/βreact';41import { withInfo } from '@storybook/βaddon-info';42import { withKnobs, text } from '@storybook/βaddon-knobs';43import { withCustomPropType } from 'storybook-root-decorator';44storiesOf('Test', module)45 .addDecorator(withKnobs)46 .addDecorator(withInfo)47 .addDecorator(withCustomPropType)
Using AI Code Generation
1import { customPropType } from 'storybook-root-decorator';2storiesOf('MyComponent', module)3 .addDecorator(customPropType('myProp', 'string'))4 .add('default', () => <MyComponent /β>);5storiesOf('MyComponent', module)6 .addDecorator(customPropType('myProp', 'string', 'myDefaultValue'))7 .add('default', () => <MyComponent /β>);8storiesOf('MyComponent', module)9 .addDecorator(customPropType('myProp', 'string', 'myDefaultValue', true))10 .add('default', () => <MyComponent /β>);11storiesOf('MyComponent', module)12 .addDecorator(customPropType('myProp', 'string', 'myDefaultValue', true, 'myCustomPropType'))13 .add('default', () => <MyComponent /β>);14storiesOf('MyComponent', module)15 .addDecorator(customPropType('myProp', 'string', 'myDefaultValue', true, 'myCustomPropType', 'myCustomPropTypeDescription'))16 .add('default', () => <MyComponent /β>);17storiesOf('MyComponent', module)18 .addDecorator(customPropType('myProp', 'string', 'myDefaultValue', true, 'myCustomPropType', 'myCustomPropTypeDescription', 'myCustomPropTypeDefaultValue'))19 .add('default', () => <MyComponent /β>);20storiesOf('MyComponent', module)21 .addDecorator(customPropType('myProp', 'string', 'myDefaultValue', true, 'myCustomPropType', 'myCustomPropTypeDescription', 'myCustomPropTypeDefaultValue', true))22 .add('default', () => <MyComponent /β>);23storiesOf('MyComponent', module)24 .addDecorator(customProp
Using AI Code Generation
1import { customPropType } from 'storybook-root-decorator';2export default {3 (story, context) => {4 const { kind, story: storyName } = context;5 const propType = customPropType(kind, storyName);6 return (7 <h2>PropType: {propType}</βh2>8 {story()}9 );10 },11};12export const Button = () => <button>Click Me</βbutton>;13export const ButtonWithCustomType = () => <button>Click Me</βbutton>;14import { addParameters } from '@storybook/βreact';15import { INITIAL_VIEWPORTS } from '@storybook/βaddon-viewport';16import { withRootDecorator } from 'storybook-root-decorator';17addParameters({18 viewport: {19 },20});21export const parameters = {22 actions: { argTypesRegex: '^on[A-Z].*' },23};24export const decorators = [withRootDecorator];25import { addParameters } from '@storybook/βreact';26import { INITIAL_VIEWPORTS } from '@storybook/βaddon-viewport';27import { withRootDecorator } from 'storybook-root-decorator';28addParameters({29 viewport: {30 },31});32export const parameters = {33 actions: { argTypesRegex: '^on[A-Z].*' },34};35export const decorators = [withRootDecorator];36import { addParameters } from '@storybook/βreact';37import { INITIAL_VIEWPORTS } from '@storybook/βaddon-viewport';38import { withRootDecorator } from 'storybook-root-decorator';39addParameters({40 viewport: {41 },42});43export const parameters = {44 actions: { argTypesRegex: '^on[A-Z].*' },45};46export const decorators = [withRootDecorator];47import { addons } from '@storybook/βaddons';48import { themes
Using AI Code Generation
1import { customPropType } from 'storybook-root-decorator'2const myPropType = customPropType('myPropType', (props, propName, componentName) => {3 if (!/βmatchme/β.test(props[propName])) {4 return new Error(5 `Invalid prop \`${propName}\` supplied to` +6 ` \`${componentName}\`. Validation failed.`7 }8})9import { myPropType } from './βtest.js'10storiesOf('Test', module).add('My Test', () => (
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/βreact';3import { withKnobs, text, boolean, number, object, array, select, color, date } from '@storybook/βaddon-knobs/βreact';4import { withInfo } from '@storybook/βaddon-info';5import { withNotes } from '@storybook/βaddon-notes';6import { withA11y } from '@storybook/βaddon-a11y';7import { withViewport } from '@storybook/βaddon-viewport';8import { withOptions } from '@storybook/βaddon-options';9import { withBackgrounds } from '@storybook/βaddon-backgrounds';10import { withPropsTable } from 'storybook-addon-react-docgen';11import { action } from '@storybook/βaddon-actions';12import { linkTo } from '@storybook/βaddon-links';13import { withConsole } from '@storybook/βaddon-console';14import { withTests } from '@storybook/βaddon-jest';15import { withRedux } from '@storybook/βaddon-redux';16import { withState } from '@dump247/βstorybook-state';17import { withCreevey } from 'creevey';18import { withSmartKnobs } from 'storybook-addon-smart-knobs';19import { withPropsCombinations } from 'react-storybook-addon-props-combinations';20import { withStorySource } from '@storybook/βaddon-storysource';21import { withCode } from '@storybook/βaddon-code';22import { withDocs } from 'storybook-readme';23import { withReadme } from 'storybook-readme/βwith-readme';24import { withReadme as withReadme2 } from 'storybook-readme/βwith-readme';25import { withReadme as withReadme3 } from 'storybook-readme/βwith-readme';26import { withReadme as withReadme4 } from 'storybook-readme/βwith-readme';27import { withReadme as withReadme5 } from 'storybook-readme/βwith-readme';28import { withReadme as with
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!!