11import type { Meta , StoryObj } from '@storybook/react-vite' ;
2- import { App as AntdApp , message } from 'antd' ;
2+ import type { ButtonProps , SwitchProps } from 'antd' ;
3+ import { App as AntdApp } from 'antd' ;
4+ import type { LinkProps } from 'antd/es/typography/Link' ;
5+ import type { ConfirmActionProps } from '../../src/components/ConfirmAction' ;
36import ConfirmAction from '../../src/components/ConfirmAction' ;
47
5- type TriggerType = 'button ' | 'switch ' | 'link ' ;
8+ type TriggerType = 'Button ' | 'Switch ' | 'Link ' ;
69
7- interface ConfirmActionStoryArgs {
10+ type ConfirmActionStoryArgs = ConfirmActionProps < object , never > & {
811 triggerType : TriggerType ;
9- triggerText : string ;
10- title : string ;
11- content : string ;
12- danger : boolean ;
13- okText : string ;
14- cancelText : string ;
15- }
12+ } ;
1613
1714const meta : Meta < ConfirmActionStoryArgs > = {
1815 title : 'Components/ConfirmAction' ,
1916 args : {
20- triggerType : 'button' ,
21- triggerText : '执行操作' ,
17+ triggerType : 'Button' ,
18+ triggerProps : {
19+ children : '执行操作' ,
20+ } ,
2221 title : '确认执行该操作?' ,
2322 content : '这是一个可交互的 ConfirmAction demo。' ,
2423 danger : false ,
@@ -28,46 +27,10 @@ const meta: Meta<ConfirmActionStoryArgs> = {
2827 argTypes : {
2928 triggerType : {
3029 control : 'radio' ,
31- options : [ 'button ' , 'switch ' , 'link ' ] ,
30+ options : [ 'Button ' , 'Switch ' , 'Link ' ] ,
3231 description : `- **EN:** Demo-only option to switch trigger component type.
3332- **CN:** 示例专用:切换触发器组件类型。` ,
34- table : { defaultValue : { summary : 'button(demo)' } } ,
35- } ,
36- triggerText : {
37- control : 'text' ,
38- description : `- **EN:** Custom trigger content.
39- - **CN:** 自定义触发器内容。` ,
40- table : { defaultValue : { summary : '执行操作(demo)' } } ,
41- } ,
42- title : {
43- control : 'text' ,
44- description : `- **EN:** Confirm box title.
45- - **CN:** 确认框标题。` ,
46- table : { defaultValue : { summary : '确认执行该操作?(demo)' } } ,
47- } ,
48- content : {
49- control : 'text' ,
50- description : `- **EN:** Confirm box content text.
51- - **CN:** 确认框内容文本。` ,
52- table : { defaultValue : { summary : '这是一个可交互的 ConfirmAction demo。(demo)' } } ,
53- } ,
54- danger : {
55- control : 'boolean' ,
56- description : `- **EN:** Whether to display in red danger mode.
57- - **CN:** 是否显示为红色危险模式。` ,
58- table : { defaultValue : { summary : 'false' } } ,
59- } ,
60- okText : {
61- control : 'text' ,
62- description : `- **EN:** Confirm button text.
63- - **CN:** 确认按钮文本。` ,
64- table : { defaultValue : { summary : '确认(demo)' } } ,
65- } ,
66- cancelText : {
67- control : 'text' ,
68- description : `- **EN:** Cancel button text.
69- - **CN:** 取消按钮文本。` ,
70- table : { defaultValue : { summary : '取消(demo)' } } ,
33+ table : { defaultValue : { summary : '"Button"' } } ,
7134 } ,
7235 } ,
7336} ;
@@ -77,36 +40,27 @@ type Story = StoryObj<ConfirmActionStoryArgs>;
7740
7841export const Playground : Story = {
7942 render : ( args : ConfirmActionStoryArgs ) => {
80- const commonProps = {
81- title : args . title ,
82- content : args . content ,
83- danger : args . danger ,
84- okText : args . okText ,
85- cancelText : args . cancelText ,
86- onOk : async ( ) => {
87- message . success ( '操作成功' ) ;
88- } ,
89- } ;
43+ const { triggerType, ...props } = args ;
9044
91- if ( args . triggerType === 'switch ' ) {
45+ if ( triggerType === 'Switch ' ) {
9246 return (
9347 < AntdApp >
94- < ConfirmAction . Switch { ...commonProps } />
48+ < ConfirmAction . Switch { ...( props as ConfirmActionProps < SwitchProps , 'onChange' > ) } />
9549 </ AntdApp >
9650 ) ;
9751 }
9852
99- if ( args . triggerType === 'link ' ) {
53+ if ( triggerType === 'Link ' ) {
10054 return (
10155 < AntdApp >
102- < ConfirmAction . Link { ...commonProps } > { args . triggerText } </ ConfirmAction . Link >
56+ < ConfirmAction . Link { ...( props as ConfirmActionProps < LinkProps , 'onClick' > ) } / >
10357 </ AntdApp >
10458 ) ;
10559 }
10660
10761 return (
10862 < AntdApp >
109- < ConfirmAction . Button { ...commonProps } > { args . triggerText } </ ConfirmAction . Button >
63+ < ConfirmAction . Button { ...( props as ConfirmActionProps < ButtonProps , 'onClick' > ) } / >
11064 </ AntdApp >
11165 ) ;
11266 } ,
0 commit comments