7
7
8
8
import React , { Component , useEffect , useRef , useState } from 'react' ;
9
9
import PropTypes from 'prop-types' ;
10
- import classNames from 'classnames' ;
10
+ import cx from 'classnames' ;
11
11
import { settings } from 'carbon-components' ;
12
12
import Link from '../Link' ;
13
13
import {
@@ -45,16 +45,16 @@ export class Tile extends Component {
45
45
} ;
46
46
47
47
render ( ) {
48
- const { children, className, light, ...other } = this . props ;
49
- const tileClasses = classNames (
48
+ const { children, className, light, ...rest } = this . props ;
49
+ const tileClasses = cx (
50
50
`${ prefix } --tile` ,
51
51
{
52
52
[ `${ prefix } --tile--light` ] : light ,
53
53
} ,
54
54
className
55
55
) ;
56
56
return (
57
- < div className = { tileClasses } { ...other } >
57
+ < div className = { tileClasses } { ...rest } >
58
58
{ children }
59
59
</ div >
60
60
) ;
@@ -76,14 +76,20 @@ export class ClickableTile extends Component {
76
76
className : PropTypes . string ,
77
77
78
78
/**
79
- * Specify the function to run when the ClickableTile is clicked
79
+ * Deprecated in v11. Use 'onClick' instead.
80
80
*/
81
- handleClick : PropTypes . func ,
81
+ handleClick : deprecate (
82
+ PropTypes . func ,
83
+ 'The handleClick prop for ClickableTile has been deprecated in favor of onClick. It will be removed in the next major release.'
84
+ ) ,
82
85
83
86
/**
84
87
* Specify the function to run when the ClickableTile is interacted with via a keyboard
85
88
*/
86
- handleKeyDown : PropTypes . func ,
89
+ handleKeyDown : deprecate (
90
+ PropTypes . func ,
91
+ 'The handleKeyDown prop for ClickableTile has been deprecated in favor of onKeyDown. It will be removed in the next major release.'
92
+ ) ,
87
93
88
94
/**
89
95
* The href for the link.
@@ -96,6 +102,16 @@ export class ClickableTile extends Component {
96
102
*/
97
103
light : PropTypes . bool ,
98
104
105
+ /**
106
+ * Specify the function to run when the ClickableTile is clicked
107
+ */
108
+ onClick : PropTypes . func ,
109
+
110
+ /**
111
+ * Specify the function to run when the ClickableTile is interacted with via a keyboard
112
+ */
113
+ onKeyDown : PropTypes . func ,
114
+
99
115
/**
100
116
* The rel property for the link.
101
117
*/
@@ -104,8 +120,8 @@ export class ClickableTile extends Component {
104
120
105
121
static defaultProps = {
106
122
clicked : false ,
107
- handleClick : ( ) => { } ,
108
- handleKeyDown : ( ) => { } ,
123
+ onClick : ( ) => { } ,
124
+ onKeyDown : ( ) => { } ,
109
125
light : false ,
110
126
} ;
111
127
@@ -116,7 +132,8 @@ export class ClickableTile extends Component {
116
132
clicked : ! this . state . clicked ,
117
133
} ,
118
134
( ) => {
119
- this . props . handleClick ( evt ) ;
135
+ // TODO: Remove handleClick prop when handleClick is deprecated
136
+ this . props . handleClick ?. ( evt ) || this . props . onClick ?. ( evt ) ;
120
137
}
121
138
) ;
122
139
} ;
@@ -129,11 +146,13 @@ export class ClickableTile extends Component {
129
146
clicked : ! this . state . clicked ,
130
147
} ,
131
148
( ) => {
132
- this . props . handleKeyDown ( evt ) ;
149
+ // TODO: Remove handleKeyDown prop when handleKeyDown is deprecated
150
+ this . props . handleKeyDown ?. ( evt ) || this . props . onKeyDown ( evt ) ;
133
151
}
134
152
) ;
135
153
} else {
136
- this . props . handleKeyDown ( evt ) ;
154
+ // TODO: Remove handleKeyDown prop when handleKeyDown is deprecated
155
+ this . props . handleKeyDown ?. ( evt ) || this . props . onKeyDown ( evt ) ;
137
156
}
138
157
} ;
139
158
@@ -155,12 +174,14 @@ export class ClickableTile extends Component {
155
174
className,
156
175
handleClick, // eslint-disable-line
157
176
handleKeyDown, // eslint-disable-line
177
+ onClick, // eslint-disable-line
178
+ onKeyDown, // eslint-disable-line
158
179
clicked, // eslint-disable-line
159
180
light,
160
- ...other
181
+ ...rest
161
182
} = this . props ;
162
183
163
- const classes = classNames (
184
+ const classes = cx (
164
185
`${ prefix } --tile` ,
165
186
`${ prefix } --tile--clickable` ,
166
187
{
@@ -174,7 +195,7 @@ export class ClickableTile extends Component {
174
195
< Link
175
196
href = { href }
176
197
className = { classes }
177
- { ...other }
198
+ { ...rest }
178
199
onClick = { this . handleClick }
179
200
onKeyDown = { this . handleKeyDown } >
180
201
{ children }
@@ -187,7 +208,7 @@ export function SelectableTile(props) {
187
208
const {
188
209
children,
189
210
id,
190
- tabIndex = 0 ,
211
+ tabIndex,
191
212
value,
192
213
name,
193
214
title,
@@ -196,24 +217,24 @@ export function SelectableTile(props) {
196
217
className,
197
218
handleClick,
198
219
handleKeyDown,
199
- onClick = ( ) => { } ,
200
- onChange = ( ) => { } ,
201
- onKeyDown = ( ) => { } ,
220
+ onClick,
221
+ onChange,
222
+ onKeyDown,
202
223
light,
203
224
disabled,
204
225
selected,
205
- ...other
226
+ ...rest
206
227
} = props ;
207
228
208
229
// TODO: replace with onClick when handleClick prop is deprecated
209
230
const clickHandler = handleClick || onClick ;
210
231
211
- // TODO: replace with onClick when handleClick prop is deprecated
232
+ // TODO: replace with onKeyDown when handleKeyDown prop is deprecated
212
233
const keyDownHandler = handleKeyDown || onKeyDown ;
213
234
214
235
const [ isSelected , setIsSelected ] = useState ( selected ) ;
215
236
const input = useRef ( null ) ;
216
- const classes = classNames (
237
+ const classes = cx (
217
238
`${ prefix } --tile` ,
218
239
`${ prefix } --tile--selectable` ,
219
240
{
@@ -223,7 +244,7 @@ export function SelectableTile(props) {
223
244
} ,
224
245
className
225
246
) ;
226
- const inputClasses = classNames ( `${ prefix } --tile-input` , {
247
+ const inputClasses = cx ( `${ prefix } --tile-input` , {
227
248
[ `${ prefix } --tile-input--checked` ] : isSelected ,
228
249
} ) ;
229
250
@@ -277,7 +298,7 @@ export function SelectableTile(props) {
277
298
className = { classes }
278
299
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
279
300
tabIndex = { ! disabled ? tabIndex : null }
280
- { ...other }
301
+ { ...rest }
281
302
onClick = { ! disabled ? handleOnClick : null }
282
303
onKeyDown = { ! disabled ? handleOnKeyDown : null } >
283
304
< span
@@ -295,6 +316,9 @@ SelectableTile.defaultProps = {
295
316
selected : false ,
296
317
tabIndex : 0 ,
297
318
light : false ,
319
+ onClick : ( ) => { } ,
320
+ onChange : ( ) => { } ,
321
+ onKeyDown : ( ) => { } ,
298
322
} ;
299
323
SelectableTile . propTypes = {
300
324
/**
@@ -409,9 +433,12 @@ export class ExpandableTile extends Component {
409
433
expanded : PropTypes . bool ,
410
434
411
435
/**
412
- * Specify the function to run when the ExpandableTile is clicked
436
+ * Deprecated in v11. Use 'onClick' instead.
413
437
*/
414
- handleClick : PropTypes . func ,
438
+ handleClick : deprecate (
439
+ PropTypes . func ,
440
+ 'The handleClick prop for ClickableTile has been deprecated in favor of onClick. It will be removed in the next major release.'
441
+ ) ,
415
442
416
443
/**
417
444
* An ID that can be provided to aria-labelledby
@@ -430,7 +457,8 @@ export class ExpandableTile extends Component {
430
457
onBeforeClick : PropTypes . func ,
431
458
432
459
/**
433
- * optional handler to trigger a function the Tile is clicked
460
+ * Specify the function to run when the ExpandableTile is clicked
461
+
434
462
*/
435
463
onClick : PropTypes . func ,
436
464
@@ -471,7 +499,7 @@ export class ExpandableTile extends Component {
471
499
tileMaxHeight : 0 ,
472
500
tilePadding : 0 ,
473
501
onBeforeClick : ( ) => true ,
474
- handleClick : ( ) => { } ,
502
+ onClick : ( ) => { } ,
475
503
tileCollapsedIconText : 'Interact to expand Tile' ,
476
504
tileExpandedIconText : 'Interact to collapse Tile' ,
477
505
light : false ,
@@ -549,7 +577,8 @@ export class ExpandableTile extends Component {
549
577
} ,
550
578
( ) => {
551
579
this . setMaxHeight ( ) ;
552
- this . props . handleClick ( evt ) ;
580
+ // TODO: Remove handleClick prop when handleClick is deprecated
581
+ this . props . handleClick ?. ( evt ) || this . props . onClick ?. ( evt ) ;
553
582
}
554
583
) ;
555
584
} ;
@@ -582,12 +611,12 @@ export class ExpandableTile extends Component {
582
611
tileExpandedLabel,
583
612
onBeforeClick, // eslint-disable-line
584
613
light,
585
- ...other
614
+ ...rest
586
615
} = this . props ;
587
616
588
617
const { expanded : isExpanded } = this . state ;
589
618
590
- const classes = classNames (
619
+ const classes = cx (
591
620
`${ prefix } --tile` ,
592
621
`${ prefix } --tile--expandable` ,
593
622
{
@@ -616,7 +645,7 @@ export class ExpandableTile extends Component {
616
645
className = { classes }
617
646
aria-expanded = { isExpanded }
618
647
title = { isExpanded ? tileExpandedIconText : tileCollapsedIconText }
619
- { ...other }
648
+ { ...rest }
620
649
onKeyUp = { composeEventHandlers ( [ onKeyUp , this . handleKeyUp ] ) }
621
650
onClick = { composeEventHandlers ( [ onClick , this . handleClick ] ) }
622
651
tabIndex = { tabIndex } >
0 commit comments