• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

TypeScript addons.makeDecorator函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript angular.moduleMetadata函数代码示例发布时间:2022-05-28
下一篇:
TypeScript addon-storyshots.default函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap