github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/.storybook/config.js (about)

     1  /* eslint-env node */
     2  import { addDecorator, addParameters, configure } from '@storybook/ember';
     3  import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
     4  import theme from './theme.js';
     5  
     6  addParameters({
     7    viewport: { viewports: INITIAL_VIEWPORTS },
     8    options: {
     9      showPanel: true,
    10      theme
    11    },
    12  });
    13  
    14  addDecorator(storyFn => {
    15    let { template, context } = storyFn();
    16  
    17    let wrapperElementStyle = {
    18      margin: '20px',
    19    };
    20  
    21    let applicationWrapperElement = document.createElement('div');
    22    Object.assign(applicationWrapperElement.style, wrapperElementStyle);
    23  
    24    let storybookElement = document.createElement('div');
    25    storybookElement.setAttribute('id', 'storybook');
    26  
    27    let wormhole = document.createElement('div');
    28    wormhole.setAttribute('id', 'ember-basic-dropdown-wormhole');
    29  
    30    storybookElement.appendChild(wormhole);
    31  
    32    applicationWrapperElement.appendChild(storybookElement);
    33    storybookElement.appendTo = function appendTo(el) {
    34      el.appendChild(applicationWrapperElement);
    35    };
    36  
    37    /**
    38     * Stories that require routing (table sorting/pagination) fail
    39     * with the default iframe setup with this error:
    40     *   Path /iframe.html does not start with the provided rootURL /ui/
    41     *
    42     * Changing ENV.rootURL fixes that but then HistoryLocation.getURL
    43     * fails because baseURL is undefined, which is usually set up by
    44     * Ember CLI configuring the base element. This adds the href for
    45     * Ember CLI to use.
    46     *
    47     * The default target="_parent" breaks table sorting and pagination
    48     * by trying to navigate when clicking the query-params-changing
    49     * elements. Removing the base target for the iframe means that
    50     * navigation-requiring links within stories need to have the
    51     * target themselves.
    52     */
    53    let baseElement = document.querySelector('base');
    54    baseElement.setAttribute('href', '/');
    55    baseElement.removeAttribute('target');
    56  
    57    return {
    58      template,
    59      context,
    60      element: storybookElement,
    61    };
    62  });
    63  
    64  // The order of import controls the sorting in the sidebar
    65  configure([
    66    require.context('../stories/theme', true, /\.stories\.js$/),
    67    require.context('../stories/components', true, /\.stories\.js$/),
    68    require.context('../stories/charts', true, /\.stories\.js$/),
    69  ], module);