@@ -14,86 +14,59 @@ import {action} from '@storybook/addon-actions';
14
14
import Bell from '@spectrum-icons/workflow/Bell' ;
15
15
import { Button } from '../' ;
16
16
import { Flex } from '@react-spectrum/layout' ;
17
+ import { mergeProps } from '@react-aria/utils' ;
17
18
import React , { ElementType } from 'react' ;
18
19
import { SpectrumButtonProps } from '@react-types/button' ;
19
20
import { storiesOf } from '@storybook/react' ;
20
21
import { Text } from '@react-spectrum/text' ;
22
+ import { Tooltip , TooltipTrigger } from '@react-spectrum/tooltip' ;
23
+
24
+ const parameters = {
25
+ args : {
26
+ variant : 'cta'
27
+ } ,
28
+ argTypes : {
29
+ variant : {
30
+ control : {
31
+ type : 'radio' ,
32
+ options : [ 'cta' , 'primary' , 'secondary' , 'negative' , 'overBackground' ]
33
+ }
34
+ }
35
+ }
36
+ } ;
37
+
38
+ let actions = {
39
+ onPress : action ( 'press' ) ,
40
+ onPressStart : action ( 'pressstart' ) ,
41
+ onPressEnd : action ( 'pressend' )
42
+ } ;
43
+
21
44
22
45
storiesOf ( 'Button' , module )
23
- . addParameters ( { providerSwitcher : { status : 'positive' } } )
46
+ . addParameters ( { providerSwitcher : { status : 'positive' } , ... parameters } )
24
47
. add (
25
- 'variant: cta ' ,
26
- ( ) => render ( { variant : 'cta' } )
48
+ 'default ' ,
49
+ ( args ) => render ( args )
27
50
)
28
51
. add (
29
52
'with icon' ,
30
- ( ) => (
31
- < Flex gap = "size-200" >
32
- < Button
33
- onPress = { action ( 'press' ) }
34
- onPressStart = { action ( 'pressstart' ) }
35
- onPressEnd = { action ( 'pressend' ) }
36
- variant = "primary" >
37
- < Bell />
38
- < Text > Default</ Text >
39
- </ Button >
40
- < Button
41
- onPress = { action ( 'press' ) }
42
- onPressStart = { action ( 'pressstart' ) }
43
- onPressEnd = { action ( 'pressend' ) }
44
- isDisabled
45
- variant = "primary" >
46
- < Text > Disabled</ Text >
47
- < Bell />
48
- </ Button >
49
- < Button
50
- onPress = { action ( 'press' ) }
51
- onPressStart = { action ( 'pressstart' ) }
52
- onPressEnd = { action ( 'pressend' ) }
53
- isQuiet
54
- variant = "primary" >
55
- < Bell />
56
- < Text > Quiet</ Text >
57
- </ Button >
58
- </ Flex >
59
- )
53
+ ( args ) => renderIconText ( args )
60
54
)
61
- . add ( 'icon only' , ( ) => (
62
- < Button variant = "cta" >
63
- < Bell />
64
- </ Button >
65
- ) )
66
55
. add (
67
- 'variant: overBackground' ,
68
- ( ) => (
69
- < div style = { { backgroundColor : 'rgb(15, 121, 125)' , color : 'rgb(15, 121, 125)' , padding : '15px 20px' , display : 'inline-block' } } >
70
- { render ( { variant : 'overBackground' } ) }
71
- </ div >
72
- )
73
- )
74
- . add (
75
- 'variant: primary' ,
76
- ( ) => render ( { variant : 'primary' } )
77
- )
78
- . add (
79
- 'variant: secondary' ,
80
- ( ) => render ( { variant : 'secondary' } )
81
- )
82
- . add (
83
- 'variant: negative' ,
84
- ( ) => render ( { variant : 'negative' } )
56
+ 'icon only' ,
57
+ ( args ) => renderIconOnly ( args )
85
58
)
86
59
. add (
87
60
'element: a' ,
88
- ( ) => render ( { elementType : 'a' , variant : 'primary' } )
61
+ ( args ) => render ( { elementType : 'a' , ... args } )
89
62
)
90
63
. add (
91
64
'element: a, href: \'//example.com\', target: \'_self\'' ,
92
- ( ) => render ( { elementType : 'a' , href : '//example.com' , target : '_self' , variant : 'primary' } )
65
+ ( args ) => render ( { elementType : 'a' , href : '//example.com' , target : '_self' , ... args } )
93
66
)
94
67
. add (
95
68
'element: a, rel: \'noopener noreferrer\'' ,
96
- ( ) => render ( { elementType : 'a' , href : '//example.com' , rel : 'noopener noreferrer' , variant : 'primary' } )
69
+ ( args ) => render ( { elementType : 'a' , href : '//example.com' , rel : 'noopener noreferrer' , ... args } )
97
70
)
98
71
. add (
99
72
'user-select:none on press test' ,
@@ -106,35 +79,105 @@ storiesOf('Button', module)
106
79
) ;
107
80
108
81
function render < T extends ElementType = 'button' > ( props : SpectrumButtonProps < T > = { variant : 'primary' } ) {
109
- return (
82
+ let buttonProps = mergeProps ( props , actions ) ;
83
+
84
+ let buttons = (
110
85
< Flex gap = "size-200" >
111
- < Button
112
- onPress = { action ( 'press' ) }
113
- onPressStart = { action ( 'pressstart' ) }
114
- onPressEnd = { action ( 'pressend' ) }
115
- { ...props } >
86
+ < Button { ...buttonProps } >
116
87
Default
117
88
</ Button >
118
- < Button
119
- onPress = { action ( 'press' ) }
120
- onPressStart = { action ( 'pressstart' ) }
121
- onPressEnd = { action ( 'pressend' ) }
122
- isDisabled
123
- { ...props } >
89
+ < Button { ...buttonProps } isDisabled >
124
90
Disabled
125
91
</ Button >
126
92
{ props . variant !== 'cta' && (
127
- < Button
128
- onPress = { action ( 'press' ) }
129
- onPressStart = { action ( 'pressstart' ) }
130
- onPressEnd = { action ( 'pressend' ) }
131
- isQuiet
132
- { ...props } >
133
- Quiet
93
+ < Button { ...buttonProps } isQuiet >
94
+ Quiet
95
+ </ Button >
96
+ ) }
97
+ </ Flex >
98
+ ) ;
99
+
100
+ if ( props . variant === 'overBackground' ) {
101
+ return (
102
+ < div style = { { backgroundColor : 'rgb(15, 121, 125)' , color : 'rgb(15, 121, 125)' , padding : '15px 20px' , display : 'inline-block' } } >
103
+ { buttons }
104
+ </ div >
105
+ ) ;
106
+ }
107
+
108
+ return buttons ;
109
+ }
110
+
111
+ function renderIconText < T extends ElementType = 'button' > ( props : SpectrumButtonProps < T > = { variant : 'primary' } ) {
112
+ let buttonProps = mergeProps ( props , actions ) ;
113
+
114
+ let buttons = (
115
+ < Flex gap = "size-200" >
116
+ < Button { ...buttonProps } >
117
+ < Bell />
118
+ < Text > Default</ Text >
134
119
</ Button >
120
+ < Button { ...buttonProps } isDisabled >
121
+ < Bell />
122
+ < Text > Disabled</ Text >
123
+ </ Button >
124
+ { props . variant !== 'cta' && (
125
+ < Button { ...buttonProps } isQuiet >
126
+ < Bell />
127
+ < Text > Quiet</ Text >
128
+ </ Button >
129
+ ) }
130
+ </ Flex >
131
+ ) ;
132
+
133
+ if ( props . variant === 'overBackground' ) {
134
+ return (
135
+ < div style = { { backgroundColor : 'rgb(15, 121, 125)' , color : 'rgb(15, 121, 125)' , padding : '15px 20px' , display : 'inline-block' } } >
136
+ { buttons }
137
+ </ div >
138
+ ) ;
139
+ }
140
+
141
+ return buttons ;
142
+ }
143
+
144
+ function renderIconOnly < T extends ElementType = 'button' > ( props : SpectrumButtonProps < T > = { variant : 'primary' } ) {
145
+ let buttonProps = mergeProps ( props , actions ) ;
146
+
147
+ let buttons = (
148
+ < Flex gap = "size-200" >
149
+ < TooltipTrigger offset = { 2 } >
150
+ < Button { ...buttonProps } aria-label = "Notifications" >
151
+ < Bell />
152
+ </ Button >
153
+ < Tooltip > Notifications</ Tooltip >
154
+ </ TooltipTrigger >
155
+ < TooltipTrigger offset = { 2 } >
156
+ < Button { ...buttonProps } aria-label = "Notifications (disabled)" isDisabled >
157
+ < Bell />
158
+ </ Button >
159
+ < Tooltip > Notifications</ Tooltip >
160
+ </ TooltipTrigger >
161
+ { props . variant !== 'cta' && (
162
+ < TooltipTrigger offset = { 2 } >
163
+ < Button { ...buttonProps } isQuiet aria-label = "Notifications (quiet)" >
164
+ < Bell />
165
+ </ Button >
166
+ < Tooltip > Notifications</ Tooltip >
167
+ </ TooltipTrigger >
135
168
) }
136
169
</ Flex >
137
170
) ;
171
+
172
+ if ( props . variant === 'overBackground' ) {
173
+ return (
174
+ < div style = { { backgroundColor : 'rgb(15, 121, 125)' , color : 'rgb(15, 121, 125)' , padding : '15px 20px' , display : 'inline-block' } } >
175
+ { buttons }
176
+ </ div >
177
+ ) ;
178
+ }
179
+
180
+ return buttons ;
138
181
}
139
182
140
183
function Example ( ) {
0 commit comments