热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Storybooksupportforcells

We(storybookteam)thinkthisisareallyinterestingproject,andwedlovetohelpge

We (storybook team) think this is a really interesting project, and we'd love to help getting first class support for SB in the project (as mentioned in the README).

One thing that's especially interesting is the Cell files; you don't need to squint very hard to see they look a lot like story files (as pointed out by -yx).

We've been thinking about it and we reckon someone could pretty easily write a babel plugin or webpack loader to compile a Cell file to a CSF file. This would be similar to the way that Storybook natively supports MDX by compiling it to CSF via a webpack loader.

That would mean that a user of Redwood could have a storybook setup where they just point SB at all their cell files and get a bunch of stories for free. That'd be pretty amazing! I'm sure there are lot more points we could integrate but this one seems like the most interesting (to me anyway).

Here's a bit of detail on how it might work:

If you take the example UsersCell.js file from the homepage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
js

export const QUERY = gql`

  query USERS {

    users {

      id

      name

    }

  }

`

export const Loading = () =>
Loading users...


export const Empty = () =>
No users yet!


export const Failure = ({ message }) =>
Error: {message}


export const Success = ({ users }) => {

  return (

   


          { users.map(user => (

           
  • {user.id} | {user.name}


  •       ))}

       


  )

}

The compiler might compile it to something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
js

export default {

  title: 'UsersCell',

}



const QUERY = gql`

  query USERS {

    users {

      id

      name

    }

  }

`

export const Loading = () =>
Loading users...


export const Empty = () =>
No users yet!


export const Failure = ({ message }) =>
Error: {message}


Failure.story = {

  args: { message: faker.string() }

};

export const Success = ({ users }) => {

  return (

   


          { users.map(user => (

           
  • {user.id} | {user.name}


  •       ))}

       


  )

}

Success.story = {

  args: { users: generateMockFromQuery(QUERY) }

}

To implement the

1
generateMockFromQuery()

function we could use Apollo's query mocking code.

[Note that the syntax above uses the new args feature that's coming in SB6 and we are publishing an RFC about this week, but hopefully you get the idea!]

If the user wanted to write a set of specific stories (i.e. for different values of

1
users

in the success case), I guess a generator that generated a story file that just imported from the Cell and re-exported would make sense.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
js

import { QUERY, Loading, Empty, Failure as FailureInput, Success as SuccessInput } from './UsersCell';



export default {

  title: 'UsersCell',

}



export { Loading, Empty };



export const Failure = props => ;

Failure.story = {

  args: { message: faker.string() }

};



export const Success = props => ;

// User can override this or make multiple stories based on `SuccessInput`

Success.story = {

  args: { users: generateMockFromQuery(QUERY) }

}

Another option is the single-file components (that combine cells and stories) that -yx mentioned, but I'm not sure of folks' appetite for that.

该提问来源于开源项目:redwoodjs/redwood

I've been playing around with Storybook on a non-Redwood project, and one thing that's been really nice is pairing it with GraphQL mocking. Since we're embracing GraphQL, we should be prepared to automatically run a mocked GraphQL server on the same port / location as the normal one as part of our Storybook development flow (whatever would run when we type the imaginary command




1
yarn rw sb

/

1
yarn redwood storybook

)



Just something to think about when we do finally implement this.


   



推荐阅读
  • egg实现登录鉴权(七):权限管理
    权限管理包含三部分:访问页面的权限,操作功能的权限和获取数据权限。页面权限:登录用户所属角色的可访问页面的权限功能权限:登录用户所属角色的可访问页面的操作权限数据权限:登录用户所属 ... [详细]
  • Python3爬虫入门:pyspider的基本使用[python爬虫入门]
    Python学习网有大量免费的Python入门教程,欢迎大家来学习。本文主要通过爬取去哪儿网的旅游攻略来给大家介绍pyspid ... [详细]
  • 本文详细介绍如何在 Apache 中设置虚拟主机,包括基本配置和高级设置,帮助用户更好地理解和使用虚拟主机功能。 ... [详细]
  • 长期从事ABAP开发工作的专业人士,在面对行业新趋势时,往往需要重新审视自己的发展方向。本文探讨了几位资深专家对ABAP未来走向的看法,以及开发者应如何调整技能以适应新的技术环境。 ... [详细]
  • 在尝试启动Java应用服务器Tomcat时,遇到了org.apache.catalina.LifecycleException异常。本文详细记录了异常的具体表现形式,并提供了有效的解决方案。 ... [详细]
  • Java虚拟机及其发展历程
    Java虚拟机(JVM)是每个Java开发者日常工作中不可或缺的一部分,但其背后的运作机制却往往显得神秘莫测。本文将探讨Java及其虚拟机的发展历程,帮助读者深入了解这一关键技术。 ... [详细]
  • 本文详细介绍了如何使用C#实现不同类型的系统服务账户(如Windows服务、计划任务和IIS应用池)的密码重置方法。 ... [详细]
  • Spring Security基础配置详解
    本文详细介绍了Spring Security的基础配置方法,包括如何搭建Maven多模块工程以及具体的安全配置步骤,帮助开发者更好地理解和应用这一强大的安全框架。 ... [详细]
  • 本文回顾了作者在求职阿里和腾讯实习生过程中,从最初的迷茫到最后成功获得Offer的心路历程。文中不仅分享了个人的面试经历,还提供了宝贵的面试准备建议和技巧。 ... [详细]
  • H5技术实现经典游戏《贪吃蛇》
    本文将分享一个使用HTML5技术实现的经典小游戏——《贪吃蛇》。通过H5技术,我们将探讨如何构建这款游戏的两种主要玩法:积分闯关和无尽模式。 ... [详细]
  • 本文详细介绍了Oracle 11g中的创建表空间的方法,以及如何设置客户端和服务端的基本配置,包括用户管理、环境变量配置等。 ... [详细]
  • 对于初学者而言,搭建一个高效稳定的 Python 开发环境是入门的关键一步。本文将详细介绍如何利用 Anaconda 和 Jupyter Notebook 来构建一个既易于管理又功能强大的开发环境。 ... [详细]
  • Flutter 核心技术与混合开发模式深入解析
    本文深入探讨了 Flutter 的核心技术,特别是其混合开发模式,包括统一管理模式和三端分离模式,以及混合栈原理。通过对比不同模式的优缺点,帮助开发者选择最适合项目的混合开发策略。 ... [详细]
  • 本文探讨了 Java 中 Unsafe.park 和 Object.wait 方法的区别,分析了它们的性能和适用场景,并提供了专业建议。 ... [详细]
  • 在项目需要国际化处理时,即支持多种语言切换的功能,通常有两种方案:单个包和多个包。本文将重点讨论单个包的实现方法。 ... [详细]
author-avatar
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有