storybook组件属性详解:组件props到strorybook Args
创始人
2025-05-30 12:49:48
0

首先我们查看官方文档:ArgsTable

官方的例子么有看到v-model如何处理,数组、对象等复杂属性定义。

这里一个是props的定义,一个是Controls

先看一下官方文档,Controls

官方的类型只有这些:Controls

Data TyeControlDescription
booleanbooleanProvides a toggle for switching between possible states.
argTypes: { active: { control: 'boolean' }}
numbernumberProvides a numeric input to include the range of all possible values.
argTypes: { even: { control: { type: 'number', min:1, max:30, step: 2 } }}
rangeProvides a range slider component to include all possible values.
argTypes: { odd: { control: { type: 'range', min: 1, max: 30, step: 3 } }}
objectobjectProvides a JSON-based editor component to handle the object's values.
Also allows edition in raw mode.
argTypes: { user: { control: 'object' }}
arrayobjectProvides a JSON-based editor component to handle the values of the array.
Also allows edition in raw mode.
argTypes: { odd: { control: 'object' }}
fileProvides a file input component that returns an array of URLs.
Can be further customized to accept specific file types.
argTypes: { avatar: { control: { type: 'file', accept: '.png' } }}
enumradioProvides a set of radio buttons based on the available options.
argTypes: { contact: { control: 'radio', options: ['email', 'phone', 'mail'] }}
inline-radioProvides a set of inlined radio buttons based on the available options.
argTypes: { contact: { control: 'inline-radio', options: ['email', 'phone', 'mail'] }}
checkProvides a set of checkbox components for selecting multiple options.
argTypes: { contact: { control: 'check', options: ['email', 'phone', 'mail'] }}
inline-checkProvides a set of inlined checkbox components for selecting multiple options.
argTypes: { contact: { control: 'inline-check', options: ['email', 'phone', 'mail'] }}
selectProvides a drop-down list component to handle single value selection. argTypes: { age: { control: 'select', options: [20, 30, 40, 50] }}
multi-selectProvides a drop-down list that allows multiple selected values. argTypes: { countries: { control: 'multi-select', options: ['USA', 'Canada', 'Mexico'] }}
stringtextProvides a freeform text input.
argTypes: { label: { control: 'text' }}
colorProvides a color picker component to handle color values.
Can be additionally configured to include a set of color presets.
argTypes: { color: { control: { type: 'color', presetColors: ['red', 'green']} }}
dateProvides a datepicker component to handle date selection. argTypes: { startDate: { control: 'date' }}

但这些都是简单类型,如果是复杂类型,react 很好办,比如:Storybook

具体写法:

ArgTypes

const argTypes = {label: {name: 'label',type: { name: 'string', required: false },defaultValue: 'Hello',description: 'demo description',table: {type: { summary: 'string' },defaultValue: { summary: 'Hello' },},control: {type: 'text'}}
}

table 能够更好的描述清属性

FieldDescription
nameThe name of the property.
argTypes: { label: { name: 'Something' } }
type.nameSets a type for the property.
argTypes: { label: { type: { name: 'number' } } }
type.requiredSets the property as optional or required.
argTypes: { label: { type: { required: true } }
descriptionSets a Markdown description for the property.
argTypes: { label: { description: 'Something' } }
category分类
table.type.summaryProvide a  short version of the type.
argTypes: { label: { table: { type: { summary: 'a short summary' } }}}
table.type.detailProvides an extended version of the type.
argTypes: { label: { table: { type: { detail: 'something' } }}}
table.defaultValue.summaryProvide a short version of the default value.
argTypes: { label: { table: { defaultValue: { summary: 'Hello World' } }}}
table.defaultValue.detailProvides a longer version of the default value.
argTypes: { label: { table: { defaultValue: { detail: 'Something' } }}}
controlAssociates a control for the property.
argTypes: { label: { control: { type: 'text'} } }
Read the  Essentials documentation to learn more about controls.

具体查看 ArgsTable

给一个案例

// SubmitForm.stories.ts
...
export default {title: "ui组件/SubmitForm",component: SubmitForm,argTypes: {refName: {description: '表单组件引用',type: {required: true,},table: {defaultValue: {summary: 'defaultNameRef',}},control: {type: 'text'}},schema: {type: {required: true,},table: {type: {summary: '渲染表单所需JSON结构',detail: 'JSON结构包含表单渲染、交互所需要的必要字段,也包含表单的校验规则',},defaultValue: {summary: '[]',detail: `[{key: "moduleName",name: "title",type: SchemaType.Text,label: "栏目名称",placeholder: "请输入栏目名称",attrs: {//},rules: [{required: true,message: "栏目名称必填~",trigger: RuleTrigger.Blur,},],}]`}}},runtimeChange: {description: '实时监听表单的更新',table: {category: 'Events',},}}
};
...

转载本站文章《storybook组件属性详解:组件props到strorybook Args》,
请注明出处:storybook组件属性详解:组件props到strorybook Args - Storybook Driven Development学习笔记—组件化之后之组件管理 - 周陆军的个人网站

相关内容

热门资讯

linux入门---制作进度条 了解缓冲区 我们首先来看看下面的操作: 我们首先创建了一个文件并在这个文件里面添加了...
C++ 机房预约系统(六):学... 8、 学生模块 8.1 学生子菜单、登录和注销 实现步骤: 在Student.cpp的...
JAVA多线程知识整理 Java多线程基础 线程的创建和启动 继承Thread类来创建并启动 自定义Thread类的子类&#...
【洛谷 P1090】[NOIP... [NOIP2004 提高组] 合并果子 / [USACO06NOV] Fence Repair G ...
国民技术LPUART介绍 低功耗通用异步接收器(LPUART) 简介 低功耗通用异步收发器...
城乡供水一体化平台-助力乡村振... 城乡供水一体化管理系统建设方案 城乡供水一体化管理系统是运用云计算、大数据等信息化手段࿰...
程序的循环结构和random库...   第三个参数就是步长     引入文件时记得指明字符格式,否则读入不了 ...
中国版ChatGPT在哪些方面... 目录 一、中国巨大的市场需求 二、中国企业加速创新 三、中国的人工智能发展 四、企业愿景的推进 五、...
报名开启 | 共赴一场 Flu... 2023 年 1 月 25 日,Flutter Forward 大会在肯尼亚首都内罗毕...
汇编00-MASM 和 Vis... Qt源码解析 索引 汇编逆向--- MASM 和 Visual Studio入门 前提知识ÿ...
【简陋Web应用3】实现人脸比... 文章目录🍉 前情提要🌷 效果演示🥝 实现过程1. u...
前缀和与对数器与二分法 1. 前缀和 假设有一个数组,我们想大量频繁的去访问L到R这个区间的和,...
windows安装JDK步骤 一、 下载JDK安装包 下载地址:https://www.oracle.com/jav...
分治法实现合并排序(归并排序)... 🎊【数据结构与算法】专题正在持续更新中,各种数据结构的创建原理与运用✨...
在linux上安装配置node... 目录前言1,关于nodejs2,配置环境变量3,总结 前言...
Linux学习之端口、网络协议... 端口:设备与外界通讯交流的出口 网络协议:   网络协议是指计算机通信网...
Linux内核进程管理并发同步... 并发同步并发 是指在某一时间段内能够处理多个任务的能力,而 并行 是指同一时间能够处理...
opencv学习-HOG LO... 目录1. HOG(Histogram of Oriented Gradients,方向梯度直方图)1...
EEG微状态的功能意义 导读大脑的瞬时全局功能状态反映在其电场结构上。聚类分析方法一致地提取了四种头表面脑电场结构ÿ...
【Unity 手写PBR】Bu... 写在前面 前期积累: GAMES101作业7提高-实现微表面模型你需要了解的知识 【技...