How to use showNoPreview method in storybook-root

Best JavaScript code snippet using storybook-root

start.js

Source:start.js Github

copy

Full Screen

1import { createStore } from 'redux';2import addons from '@storybook/addons';3import { navigator, window, document } from 'global';4import createChannel from '@storybook/channel-postmessage';5import { handleKeyboardShortcuts } from '@storybook/ui/dist/libs/key_events';6import { logger } from '@storybook/client-logger';7import Events from '@storybook/core-events';8import StoryStore from './story_store';9import ClientApi from './client_api';10import ConfigApi from './config_api';11import reducer from './reducer';12import * as Actions from './actions';13import syncUrlWithStore from './syncUrlWithStore';14const classes = {15 MAIN: 'sb-show-main',16 NOPREVIEW: 'sb-show-nopreview',17 ERROR: 'sb-show-errordisplay',18};19function showMain() {20 document.body.classList.remove(classes.NOPREVIEW);21 document.body.classList.remove(classes.ERROR);22 document.body.classList.add(classes.MAIN);23}24function showNopreview() {25 document.body.classList.remove(classes.MAIN);26 document.body.classList.remove(classes.ERROR);27 document.body.classList.add(classes.NOPREVIEW);28}29function showErrorDisplay({ message, stack }) {30 document.getElementById('error-message').textContent = message;31 document.getElementById('error-stack').textContent = stack;32 document.body.classList.remove(classes.MAIN);33 document.body.classList.remove(classes.NOPREVIEW);34 document.body.classList.add(classes.ERROR);35}36// showError is used by the various app layers to inform the user they have done something37// wrong -- for instance returned the wrong thing from a story38function showError({ title, description }) {39 addons.getChannel().emit(Events.STORY_ERRORED, { title, description });40 showErrorDisplay({41 message: title,42 stack: description,43 });44}45// showException is used if we fail to render the story and it is uncaught by the app layer46function showException(exception) {47 addons.getChannel().emit(Events.STORY_THREW_EXCEPTION, exception);48 showErrorDisplay(exception);49 // Log the stack to the console. So, user could check the source code.50 logger.error(exception.stack);51}52export default function start(render, { decorateStory } = {}) {53 // check whether we're running on node/browser54 const isBrowser =55 navigator &&56 navigator.userAgent &&57 navigator.userAgent !== 'storyshots' &&58 !(navigator.userAgent.indexOf('Node.js') > -1) &&59 !(navigator.userAgent.indexOf('jsdom') > -1);60 const storyStore = new StoryStore();61 const reduxStore = createStore(reducer);62 const context = {63 storyStore,64 reduxStore,65 decorateStory,66 showMain,67 showError,68 showException,69 };70 const clientApi = new ClientApi(context);71 let channel;72 if (isBrowser) {73 // setup preview channel74 channel = createChannel({ page: 'preview' });75 channel.on(Events.SET_CURRENT_STORY, data => {76 reduxStore.dispatch(Actions.selectStory(data.kind, data.story));77 });78 addons.setChannel(channel);79 Object.assign(context, { channel });80 syncUrlWithStore(reduxStore);81 // Handle keyboard shortcuts82 window.onkeydown = handleKeyboardShortcuts(channel);83 }84 // Provide access to external scripts if `window` is defined.85 // NOTE this is different to isBrowser, primarily for the JSDOM use case86 if (typeof window !== 'undefined') {87 window.__STORYBOOK_CLIENT_API__ = clientApi;88 window.__STORYBOOK_ADDONS_CHANNEL__ = channel; // may not be defined89 }90 const { clearDecorators } = clientApi;91 const configApi = new ConfigApi({ clearDecorators, ...context });92 let previousKind = '';93 let previousStory = '';94 let previousRevision = -1;95 const renderMain = forceRender => {96 if (storyStore.size() === 0) {97 showNopreview();98 return;99 }100 const { selectedKind, selectedStory } = reduxStore.getState();101 const revision = storyStore.getRevision();102 const story = storyStore.getStoryWithContext(selectedKind, selectedStory);103 if (!story) {104 showNopreview();105 return;106 }107 // Render story only if selectedKind or selectedStory has changed.108 // renderMain() gets executed after each action. Actions will cause the whole109 // story to re-render without this check.110 // https://github.com/storybooks/react-storybook/issues/116111 // However, we do want the story to re-render if the store itself has changed112 // (which happens at the moment when HMR occurs)113 if (114 !forceRender &&115 revision === previousRevision &&116 selectedKind === previousKind &&117 previousStory === selectedStory118 ) {119 return;120 }121 if (!forceRender) {122 // Scroll to top of the page when changing story123 document.documentElement.scrollTop = 0;124 }125 previousRevision = revision;126 previousKind = selectedKind;127 previousStory = selectedStory;128 render({129 ...context,130 story,131 selectedKind,132 selectedStory,133 forceRender,134 });135 };136 // initialize the UI137 const renderUI = forceRender => {138 if (isBrowser) {139 const { error } = reduxStore.getState();140 if (error) {141 showException(error);142 return;143 }144 try {145 renderMain(forceRender);146 addons.getChannel().emit(Events.STORY_RENDERED);147 } catch (ex) {148 showException(ex);149 }150 }151 };152 const forceReRender = () => renderUI(true);153 if (isBrowser) {154 channel.on(Events.FORCE_RE_RENDER, forceReRender);155 }156 renderUI();157 reduxStore.subscribe(renderUI);158 return { context, clientApi, configApi, forceReRender };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { showNoPreview } from 'storybook-root-provider';2showNoPreview();3import { showPreview } from 'storybook-root-provider';4showPreview();5import { showNoPreview } from 'storybook-root-provider';6showNoPreview();7import { showPreview } from 'storybook-root-provider';8showPreview();9import { showNoPreview } from 'storybook-root-provider';10showNoPreview();11import { showPreview } from 'storybook-root-provider';12showPreview();13import { showNoPreview } from 'storybook-root-provider';14showNoPreview();15import { showPreview } from 'storybook-root-provider';16showPreview();17import { showNoPreview } from 'storybook-root-provider';18showNoPreview();19import { showPreview } from 'storybook-root-provider';20showPreview();21import { showNoPreview } from 'storybook-root-provider';22showNoPreview();23import { showPreview } from 'storybook-root-provider';24showPreview();25import { showNoPreview } from 'storybook-root-provider';26showNoPreview();27import { showPreview } from 'storybook-root-provider';28showPreview();29import { showNoPreview } from 'storybook-root-provider';30showNoPreview();31import { showPreview } from 'storybook-root-provider';32showPreview();33import { showNoPreview } from 'storybook-root-provider';34showNoPreview();35import { showPreview } from 'storybook-root-provider';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { showNoPreview } from '@storybook/addon-docs/dist/frameworks/common/config';2showNoPreview();3import { showMain } from '@storybook/addon-docs/dist/frameworks/common/config';4showMain();5import { showDocsPage } from '@storybook/addon-docs/dist/frameworks/web/config/preview';6showDocsPage();7import { showNoPreview } from '@storybook/addon-docs/dist/frameworks/web/config/preview';8showNoPreview();9import { showMain } from '@storybook/addon-docs/dist/frameworks/web/config/preview';10showMain();11import { showDocsPage } from '@storybook/addon-docs/dist/frameworks/react/config/preview';12showDocsPage();13import { showNoPreview } from '@storybook/addon-docs/dist/frameworks/react/config/preview';14showNoPreview();15import { showMain } from '@storybook/addon-docs/dist/frameworks/react/config/preview';16showMain();17import { showDocsPage } from '@storybook/addon-docs/dist/frameworks/vue/config/preview';18showDocsPage();19import { showNoPreview } from '@storybook/addon-docs/dist/frameworks/vue/config/preview';20showNoPreview();21import { showMain } from '@storybook/addon-docs/dist/frameworks/vue/config/preview';22showMain();23import { showDocsPage } from '@storybook/addon-docs/dist/frameworks/angular/config/preview';24showDocsPage();

Full Screen

Using AI Code Generation

copy

Full Screen

1import { showNoPreview } from 'storybook-root'2showNoPreview()3import { showNoPreview } from 'storybook-root'4showNoPreview()5import { showNoPreview } from 'storybook-root'6showNoPreview()7import { showNoPreview } from 'storybook-root'8showNoPreview()9import { showNoPreview } from 'storybook-root'10showNoPreview()11import { showNoPreview } from 'storybook-root'12showNoPreview()13import { showNoPreview } from 'storybook-root'14showNoPreview()15import { showNoPreview } from 'storybook-root'16showNoPreview()17import { showNoPreview } from 'storybook-root'18showNoPreview()19import { showNoPreview } from 'storybook-root'20showNoPreview()21import { showNoPreview } from 'storybook-root'22showNoPreview()23import { showNoPreview } from 'storybook-root'24showNoPreview()25import { showNoPreview } from 'storybook-root'26showNoPreview()27import { showNoPreview } from 'storybook-root'28showNoPreview()29import { showNoPreview } from 'storybook-root'

Full Screen

Using AI Code Generation

copy

Full Screen

1import { showNoPreview } from 'storybook-root';2showNoPreview();3export function showNoPreview() {4 document.querySelector('.sb-show-main').style.display = 'none';5}6If you want to use the same webpack config for both storybook and the app, you can create a new file and import it in both webpack.config.js and .storybook/webpack.config.js

Full Screen

Using AI Code Generation

copy

Full Screen

1import { showNoPreview } from 'storybook-root';2import { storiesOf } from '@storybook/react';3storiesOf('Storybook Root', module)4 .add('showNoPreview', () => showNoPreview());5import React from 'react';6export const showNoPreview = () => (7);

Full Screen

Using AI Code Generation

copy

Full Screen

1showNoPreview() {2 this.setState({ preview: false });3}4render() {5 const { preview } = this.state;6 return (7 {preview ? <Preview /> : null}8 );9}

Full Screen

Using AI Code Generation

copy

Full Screen

1import {showNoPreview} from 'storybook-root';2import {showNoPreview} from 'storybook-root';3import {showNoPreview} from 'storybook-root';4import {showNoPreview} from 'storybook-root';5import {showNoPreview} from 'storybook-root';6import {showNoPreview} from 'storybook-root';7import {showNoPreview} from 'storybook-root';8import {showNoPreview} from 'storybook-root';9import {showNoPreview} from 'storybook-root';10import {showNoPreview} from 'storybook-root';11import {showNoPreview} from 'storybook-root';12import {showNoPreview} from 'storybook-root';13import {showNoPreview} from 'storybook-root';

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