How to use customPropType method in storybook-root

Best JavaScript code snippet using storybook-root

index.js

Source:index.js Github

copy

Full Screen

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};...

Full Screen

Full Screen

utils.ts

Source:utils.ts Github

copy

Full Screen

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...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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 },

Full Screen

Using AI Code Generation

copy

Full Screen

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)

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

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', () => (

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful