当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript addons.makeDecorator函数代码示例

本文整理汇总了TypeScript中@storybook/addons.makeDecorator函数的典型用法代码示例。如果您正苦于以下问题:TypeScript makeDecorator函数的具体用法?TypeScript makeDecorator怎么用?TypeScript makeDecorator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了makeDecorator函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: deprecate

import { makeDecorator, StoryContext, StoryGetter } from '@storybook/addons';
import deprecate from 'util-deprecate';

// This decorator is kept purely so we produce a decorator that is compatible with both
// `addDecorator(withBackgrounds(...))` and `addDecorator(withBackgrounds)`
export const withBackgrounds = deprecate(
  makeDecorator({
    name: 'withBackgrounds',
    parameterName: 'backgrounds',
    wrapper: (getStory: StoryGetter, context: StoryContext) => {
      return getStory(context);
    },
  }),
  `Note that withBackgrounds(options) has been replaced by addParameters({ backgrounds: options})
Read more about it in the migration guide: https://github.com/storybooks/storybook/blob/master/MIGRATION.md`
);

if (module && module.hot && module.hot.decline) {
  module.hot.decline();
}
开发者ID:chinmaymoharir,项目名称:storybook,代码行数:20,代码来源:index.ts

示例2: updateElement

    const { id, code } = r;
    updateElement(id, code, true);
  });
  removed.forEach(r => {
    const { id, code } = r;
    updateElement(id, code, false);
  });
};

export const withCssResources = makeDecorator({
  name: 'withCssResources',
  parameterName: PARAM_KEY,
  skipIfNoParametersOrOptions: true,
  allowDeprecatedUsage: false,

  wrapper: (getStory: any, context: any, { options, parameters }: any) => {
    const storyOptions = parameters || options;
    addons.getChannel().on(EVENTS.SET, setResources);

    if (!Array.isArray(storyOptions) && !Array.isArray(storyOptions.cssresources)) {
      throw new Error('The `cssresources` parameter needs to be an Array');
    }

    return getStory(context);
  },
});

if (module && module.hot && module.hot.decline) {
  module.hot.decline();
}
开发者ID:chinmaymoharir,项目名称:storybook,代码行数:30,代码来源:index.ts

示例3: makeDecorator

import addons, { makeDecorator } from "@storybook/addons";
import { addDecorator, storiesOf } from "@storybook/react";

// Example from Storybook documentation
const withNotes = makeDecorator({
    name: "withNotes",
    parameterName: "notes",
    wrapper: (getStory, context, {options, parameters}: {options: number, parameters: string}) => {
        const channel = addons.getChannel();
        channel.emit("MYADDON/add_notes", parameters);
        return getStory(context);
    }
});

// new style
addDecorator(withNotes);

// old style, but still supported
addDecorator(withNotes(42));

// the deprecated style actually isn't supported by
// @storybook/react's typings, so, no test for that...
storiesOf("Hello", module)
    .addDecorator(withNotes)        // new style
    .addDecorator(withNotes(42));   // old style, but still supported
开发者ID:MrBigDog2U,项目名称:DefinitelyTyped,代码行数:25,代码来源:storybook__addons-tests.ts

示例4: makeDecorator

import { makeDecorator, StoryContext, StoryGetter, WrapperSettings } from '@storybook/addons';
import deprecate from 'util-deprecate';

// todo resolve any after @storybook/addons and @storybook/channels are migrated to TypeScript
export const withNotes = makeDecorator({
  name: 'withNotes',
  parameterName: 'notes',
  skipIfNoParametersOrOptions: true,
  allowDeprecatedUsage: true,

  wrapper: deprecate((getStory: StoryGetter, context: StoryContext, { options, parameters }: WrapperSettings) => {
    const storyOptions = parameters || options;

    const { text, markdown } =
      typeof storyOptions === 'string'
        ? {
            text: storyOptions,
            markdown: undefined,
          }
        : storyOptions;

    if (!text && !markdown) {
      throw new Error(`Parameter 'notes' must must be a string or an object with 'text' or 'markdown' properties`);
    }

    return getStory(context);
  }, 'withNotes is deprecated'),
});

export const withMarkdownNotes = deprecate((text: string, options: any) => {}, 'withMarkdownNotes is deprecated');

if (module && module.hot && module.hot.decline) {
开发者ID:chinmaymoharir,项目名称:storybook,代码行数:32,代码来源:index.ts


注:本文中的@storybook/addons.makeDecorator函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。