Best JavaScript code snippet using storybook-root
useGalleryContext.js
Source:useGalleryContext.js
...22 };23 const getBlueprintFromServer = async (params) => {24 let { items, options, container } = params;25 container = container || context.container || calcGalleryContainer();26 const _options = options || context.options || flatToNested(getInitialOptions());27 const url = `https://www.wix.com/_serverless/pro-gallery-blueprints-server/createBlueprint`;28 if (!items || !container || !_options) {29 return;30 }31 const response = await fetch(url, {32 method: 'POST',33 credentials: 'omit', // include, *same-origin, omit34 headers: {35 'Content-Type': 'application/json'36 },37 body: JSON.stringify({38 items,39 options,40 container41 }) // body data type must match "Content-Type" header42 });43 const data = await response.json();44 setBlueprint(data.blueprint);45 };46 const requestNewBlueprint = (newContext, settingNewItems) => {47 if (getGallerySettings().shouldUseBlueprintsFromServer) {48 getBlueprintFromServer({ ...context, ...newContext });49 } else {50 if (settingNewItems) {51 blueprintsManager.resetItemLooping();52 }53 blueprintsManager.createBlueprint({ ...newContext });54 }55 };56 const setContainer = (config = {}) => {57 const { width, height } = config;58 const newContext = {59 container: {60 ...calcGalleryContainer(),61 ...(width && { width }),62 ...(height && { height }),63 },64 };65 if (66 JSON.stringify(newContext.container) !==67 JSON.stringify({ ...context.container })68 ) {69 if (getGallerySettings().useBlueprints) {70 requestNewBlueprint(newContext);71 }72 setContext(newContext);73 }74 };75 const setPreset = (newPreset) => {76 const newContext = {77 preset: newPreset,78 options: flatToNested(getInitialOptions(newPreset)),79 };80 if (getGallerySettings().useBlueprints) {81 requestNewBlueprint(newContext);82 }83 setContext(newContext);84 };85 const setOptions = (newProp, value) => {86 // console.log(`[OPTIONS - VALIDATION] settings options in the context`, newProp, value, context.options);87 const options = flatToNested({88 ...getInitialOptions(),89 ...getOptionsFromUrl(window.location.search),90 [newProp]: value,91 })92 console.log('setting new context and requesting BP', options.layoutParams)93 const newContext = {94 options,95 };96 if (getGallerySettings().useBlueprints) {97 requestNewBlueprint(newContext);98 }99 // console.log(`[OPTIONS - VALIDATION] settings options in the context`, newContext.options);100 setContext(newContext);101 };102 const setItems = (items) => {103 const newContext = { items };104 if (getGallerySettings().useBlueprints) {105 requestNewBlueprint(newContext, true);106 }107 setContext(newContext);108 };109 const setBlueprint = (blueprint) => {110 setContext({ blueprint });111 };112 const setGalleryReady = (galleryReady) => {113 setContext({ galleryReady });114 };115 const setGallerySettings = (_gallerySettings) => {116 const gallerySettings = { ...getGallerySettings(), ..._gallerySettings };117 const newContext = { gallerySettings };118 setContext(newContext);119 try {120 localStorage.gallerySettings = JSON.stringify(gallerySettings);121 } catch (e) {122 console.error('Could not save gallerySettings', e);123 }124 };125 const getGallerySettings = () => {126 if (typeof context.gallerySettings === 'object') {127 return context.gallerySettings;128 } else {129 try {130 return JSON.parse(localStorage.gallerySettings) || {};131 } catch (e) {132 // console.error('Could not get gallerySettings', e);133 return {};134 }135 }136 };137 const calcGalleryContainer = () => {138 let container = {};139 const showSide = !!getGallerySettings().showSide && !utils.isMobile();140 // eslint-disable-next-line no-extra-boolean-cast141 if (!!getGallerySettings().isUnknownDimensions) {142 container = !utils.isMobile()143 ? {144 width: 500,145 height: 500,146 }147 : {148 width: 320,149 height: 500,150 };151 } else {152 container.width = !showSide153 ? window.innerWidth154 : window.innerWidth - SIDEBAR_WIDTH;155 container.height = window.innerHeight;156 }157 return container;158 };159 const res = {160 showSide: context.showSide,161 setShowSide,162 preset: context.preset,163 setPreset,164 options: addPresetOptions(165 context.options || flatToNested(getInitialOptions())166 ), //TODO - this is a double even for the normal flow - maybe used for the sidebar somehow?167 setOptions,168 items: context.items,169 setItems,170 blueprint: context.blueprint,171 setBlueprint,172 galleryReady: context.galleryReady,173 setGalleryReady,174 gallerySettings: getGallerySettings(),175 setGallerySettings,176 container: context.container || calcGalleryContainer(),177 setContainer,178 getBlueprintFromServer,179 };...
jmTypes.test.js
Source:jmTypes.test.js
1import jm from '../dist/jm.cjs'2import { TYPE_KEY, isFunction, isRegExp } from '../src/is'3function getInitialOptions(type) {4 if (type === 'sameAs')5 return {6 [TYPE_KEY]: true,7 config: {8 sameAs: '',9 },10 }11 return {12 [TYPE_KEY]: true,13 message: {},14 config: {15 ...(type ? { type } : ''),16 required: true,17 },18 }19}20describe('json-msg types', () => {21 it('check all the initial options', () => {22 expect(jm.str({ min: 4 })).toMatchObject(getInitialOptions('string'))23 expect(jm.array()).toMatchObject(getInitialOptions('array'))24 expect(jm.num()).toMatchObject(getInitialOptions('number'))25 expect(jm.sameAs()).toMatchObject(getInitialOptions('sameAs'))26 expect(jm.bool()).toMatchObject(getInitialOptions('boolean'))27 expect(jm.any()).toMatchObject(getInitialOptions())28 })29 it('jm.str()', () => {30 const min = 531 const max = 532 const label = 'user'33 const test = jm.str({ min, max, label, email: true, alphanum: true })34 expect(test).toMatchObject({35 config: { min, max },36 label,37 })38 expect(isFunction(test.config.email)).toBe(true)39 expect(isRegExp(test.config.alphanum)).toBe(true)40 })41 it('jm.num()', () => {...
getInitialOptions.ts
Source:getInitialOptions.ts
1import { Options, parse } from 'type-args';2import optionDefs from './optionDefs';3function getInitialOptions(argv: string[] = process.argv): Options {4 return parse(argv, optionDefs)[0];5}...
Using AI Code Generation
1import React from 'react';2import ReactDOM from 'react-dom';3import { getInitialOptions } from '@storybook/core-client';4import { RootProvider } from '@storybook/addon-docs/blocks';5const rootElement = document.getElementById('root');6const options = getInitialOptions();7const { globals, parameters } = options;8ReactDOM.render(9 <RootProvider globals={globals} parameters={parameters}>10);11module.exports = {12 stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],13 refs: {14 'storybook-addon-docs-root-provider': {15 },16 },17};18import { useGlobals, useParameter } from '@storybook/client-api';19import { RootProvider } from '@storybook/addon-docs/blocks';20 (Story, context) => {21 const [globals] = useGlobals();22 const parameters = useParameter('docs', {});23 return (24 <RootProvider globals={globals} parameters={parameters}>25 <Story {...context} />26 );27 },28];29import { addons } from '@storybook/addons';30import { STORY_RENDERED } from '@storybook/core-events';31addons.register('storybook-addon-docs-root-provider', () => {32 addons.add(STORY_RENDERED, () => {33 window.parent.postMessage(34 {35 globals: window.__STORYBOOK_CLIENT_API__.getCurrentGlobals(),36 parameters: window.__STORYBOOK_CLIENT_API__.getCurrentParameter(37 },38 );39 });40});41 window.addEventListener('message', (event) => {42 if (event.data.type === 'storybook-addon-docs
Using AI Code Generation
1import { getInitialOptions } from 'storybook-addon-root-decorator';2const options = getInitialOptions();3const options = { backgroundColor: 'red' };4import { setInitialOptions } from 'storybook-addon-root-decorator';5setInitialOptions(options);6import { rootDecorator } from 'storybook-addon-root-decorator';7export const decorators = [rootDecorator];8export const globalTypes = {9 backgroundColor: {10 toolbar: {11 },12 },13};14export const parameters = {15 rootDecorator: {16 },17};18import { useRootDecorator } from 'storybook-addon-root-decorator';19export const parameters = {20};21import { useRootDecorator } from 'storybook-addon-root-decorator';22export const parameters = {23};24import { rootDecorator } from 'storybook-addon-root-decorator';25export const decorators = [rootDecorator];
Using AI Code Generation
1import { getInitialOptions } from 'storybook-root-decorator'2import { configure, addDecorator } from '@storybook/react'3import { withThemesProvider } from 'storybook-addon-styled-component-theme'4import { themes } from '../src/themes'5const { theme } = getInitialOptions()6addDecorator(withThemesProvider([theme], { withTheme: themes[theme] }))7configure(require.context('../src', true, /\.stories\.js$/), module)
Using AI Code Generation
1import { getInitialOptions } from 'storybook-root';2const options = getInitialOptions();3import { addInitialOptions } from 'storybook-root';4addInitialOptions({5});6import { addInitialOptions } from 'storybook-root';7addInitialOptions({8});9import { addInitialOptions } from 'storybook-root';10addInitialOptions({11});12import { addInitialOptions } from 'storybook-root';13addInitialOptions({14});15import { addInitialOptions } from 'storybook-root';16addInitialOptions({17});18import { addInitialOptions } from 'storybook-root';19addInitialOptions({20});21import { addInitialOptions } from 'storybook-root';22addInitialOptions({23});24import { addInitialOptions } from 'storybook-root';25addInitialOptions({26});27import
Using AI Code Generation
1import { getInitialOptions } from 'storybook-root';2const options = getInitialOptions();3const storybook = new Storybook(options);4const storybookEl = storybook.render();5document.body.appendChild(storybookEl);6import { getInitialOptions } from 'storybook-core';7export { getInitialOptions };8import { getInitialOptions } from 'storybook-core';9export { getInitialOptions };10{11}12export { getInitialOptions };13{14}15{16}17{18}19{20}21{22}23{24}25{26}27{
Using AI Code Generation
1import React from 'react';2import { getInitialOptions } from 'storybook-root';3import { storiesOf } from '@storybook/react';4import { withKnobs, text, boolean, number } from '@storybook/addon-knobs';5import { withInfo } from '@storybook/addon-info';6import { withReadme } from 'storybook-readme';7import { withTests } from '@storybook/addon-jest';8import results from '../.jest-test-results.json';9import { withState } from '@dump247/storybook-state';10import { withOptions } from '@storybook/addon-options';11import { withOptions as withOptions2 } from '@storybook/addon-options2';12import { withViewport } from '@storybook/addon-viewport';13import { withViewport as withViewport2 } from '@storybook/addon-viewport2';14import { withViewport as withViewport3 } from '@storybook/addon-viewport3';15import { withViewport as withViewport4 } from '@storybook/addon-viewport4';16import { withViewport as withViewport5 } from '@storybook/addon-viewport5';17import { withViewport as withViewport6 } from '@storybook/addon-viewport6';18import { withViewport as withViewport7 } from '@storybook/addon-viewport7';19import { withViewport as withViewport8 } from '@storybook/addon-viewport8';20import { withViewport as withViewport9 } from '@storybook/addon-viewport9';21import { withViewport as withViewport10 } from '@storybook/addon-viewport10';22import { withViewport as withViewport11 } from '@storybook/addon-viewport11';23import { withViewport as withViewport12 } from '@storybook/addon-viewport12';24import { withViewport as withViewport13 } from '@storybook/addon-viewport13';25import { withViewport as withViewport14 } from '@storybook/addon-viewport14';26import { withViewport as withViewport15 } from '@storybook/addon-viewport15';27import { withViewport as withViewport16 } from '@storybook/addon-viewport16';28import { withViewport as withViewport17 } from '@storybook/addon-viewport17';29import { withViewport as withViewport18 } from '@storybook/addon-
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!!