Skip to content

Commit 5646905

Browse files
chore: remove usage of deprecated .defaultProps (#4449)
* 4426: parse.js + eslint rules update transform.js (WIP) transform.js (WIP) transform.js: get all files (WIP) transform.js: const defaultProps (WIP) transform.js: function + eslint rules (WIP) * 4426: component changes * Revert "4426: component changes" This reverts commit bf72914. * 4426: using _. style for lodash functions * 4426: component changes * apply suggested changes * remove transform * replace getElementType with getComponentType * apply suggestions * fix tests * remove rule changes * remove transform * apply changes * apply changes * apply changes * apply changes * fix tests & use getComponentType() --------- Co-authored-by: Oleksandr Fediashov <[email protected]>
1 parent e243fa4 commit 5646905

File tree

169 files changed

+580
-674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+580
-674
lines changed

src/addons/Confirm/Confirm.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ import Modal from '../../modules/Modal'
1111
* @see Modal
1212
*/
1313
const Confirm = React.forwardRef(function (props, ref) {
14-
const { cancelButton, confirmButton, content, header, open, size } = props
14+
const {
15+
cancelButton = 'Cancel',
16+
confirmButton = 'OK',
17+
content = 'Are you sure?',
18+
header,
19+
open,
20+
size = 'small',
21+
} = props
1522
const rest = getUnhandledProps(Confirm, props)
1623

1724
const handleCancel = (e) => {
@@ -96,11 +103,4 @@ Confirm.propTypes = {
96103
size: PropTypes.oneOf(['mini', 'tiny', 'small', 'large', 'fullscreen']),
97104
}
98105

99-
Confirm.defaultProps = {
100-
cancelButton: 'Cancel',
101-
confirmButton: 'OK',
102-
content: 'Are you sure?',
103-
size: 'small',
104-
}
105-
106106
export default Confirm

src/addons/Pagination/Pagination.js

+31-29
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,28 @@ import PaginationItem from './PaginationItem'
1616
*/
1717
const Pagination = React.forwardRef(function (props, ref) {
1818
const {
19-
'aria-label': ariaLabel,
20-
boundaryRange,
19+
'aria-label': ariaLabel = 'Pagination Navigation',
20+
boundaryRange = 1,
2121
disabled,
22-
ellipsisItem,
23-
siblingRange,
22+
ellipsisItem = '...',
23+
firstItem = {
24+
'aria-label': 'First item',
25+
content: '«',
26+
},
27+
lastItem = {
28+
'aria-label': 'Last item',
29+
content: '»',
30+
},
31+
nextItem = {
32+
'aria-label': 'Next item',
33+
content: '⟩',
34+
},
35+
pageItem = {},
36+
prevItem = {
37+
'aria-label': 'Previous item',
38+
content: '⟨',
39+
},
40+
siblingRange = 1,
2441
totalPages,
2542
} = props
2643
const [activePage, setActivePage] = useAutoControlledValue({
@@ -63,10 +80,19 @@ const Pagination = React.forwardRef(function (props, ref) {
6380
})
6481
const rest = getUnhandledProps(Pagination, props)
6582

83+
const paginationItemTypes = {
84+
firstItem,
85+
lastItem,
86+
ellipsisItem,
87+
nextItem,
88+
pageItem,
89+
prevItem,
90+
}
91+
6692
return (
6793
<Menu {...rest} aria-label={ariaLabel} pagination role='navigation' ref={ref}>
6894
{_.map(items, ({ active, type, value }) =>
69-
PaginationItem.create(props[type], {
95+
PaginationItem.create(paginationItemTypes[type], {
7096
defaultProps: {
7197
content: value,
7298
disabled,
@@ -129,30 +155,6 @@ Pagination.propTypes = {
129155
totalPages: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
130156
}
131157

132-
Pagination.defaultProps = {
133-
'aria-label': 'Pagination Navigation',
134-
boundaryRange: 1,
135-
ellipsisItem: '...',
136-
firstItem: {
137-
'aria-label': 'First item',
138-
content: '«',
139-
},
140-
lastItem: {
141-
'aria-label': 'Last item',
142-
content: '»',
143-
},
144-
nextItem: {
145-
'aria-label': 'Next item',
146-
content: '⟩',
147-
},
148-
pageItem: {},
149-
prevItem: {
150-
'aria-label': 'Previous item',
151-
content: '⟨',
152-
},
153-
siblingRange: 1,
154-
}
155-
156158
Pagination.Item = PaginationItem
157159

158160
export default Pagination

src/addons/Radio/Radio.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import Checkbox from '../../modules/Checkbox'
1010
* @see Form
1111
*/
1212
const Radio = React.forwardRef(function (props, ref) {
13-
const { slider, toggle, type } = props
13+
const { slider, toggle, type = 'radio' } = props
1414

1515
const rest = getUnhandledProps(Radio, props)
16-
// const ElementType = getElementType(Radio, props)
1716
// radio, slider, toggle are exclusive
1817
// use an undefined radio if slider or toggle are present
1918
const radio = !(slider || toggle) || undefined
@@ -33,8 +32,4 @@ Radio.propTypes = {
3332
type: Checkbox.propTypes.type,
3433
}
3534

36-
Radio.defaultProps = {
37-
type: 'radio',
38-
}
39-
4035
export default Radio

src/addons/TextArea/TextArea.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import _ from 'lodash'
22
import PropTypes from 'prop-types'
33
import React from 'react'
44

5-
import { getElementType, getUnhandledProps, useMergedRefs } from '../../lib'
5+
import { getComponentType, getUnhandledProps, useMergedRefs } from '../../lib'
66

77
/**
88
* A TextArea can be used to allow for extended user input.
99
* @see Form
1010
*/
1111
const TextArea = React.forwardRef(function (props, ref) {
12-
const { rows, value } = props
12+
const { rows = 3, value } = props
1313
const elementRef = useMergedRefs(ref, React.useRef())
1414

1515
const handleChange = (e) => {
@@ -25,7 +25,7 @@ const TextArea = React.forwardRef(function (props, ref) {
2525
}
2626

2727
const rest = getUnhandledProps(TextArea, props)
28-
const ElementType = getElementType(TextArea, props)
28+
const ElementType = getComponentType(props, { defaultAs: 'textarea' })
2929

3030
return (
3131
<ElementType
@@ -65,9 +65,4 @@ TextArea.propTypes = {
6565
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
6666
}
6767

68-
TextArea.defaultProps = {
69-
as: 'textarea',
70-
rows: 3,
71-
}
72-
7368
export default TextArea

src/addons/TransitionablePortal/TransitionablePortal.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ function usePortalState(props) {
4747
* @see Transition
4848
*/
4949
function TransitionablePortal(props) {
50-
const { children, transition } = props
50+
const {
51+
children,
52+
transition = {
53+
animation: 'scale',
54+
duration: 400,
55+
},
56+
} = props
5157

5258
const [portalOpen, setPortalOpen] = usePortalState(props)
5359
const [transitionVisible, setTransitionVisible] = React.useState(false)
@@ -165,11 +171,4 @@ TransitionablePortal.propTypes = {
165171
transition: PropTypes.object,
166172
}
167173

168-
TransitionablePortal.defaultProps = {
169-
transition: {
170-
animation: 'scale',
171-
duration: 400,
172-
},
173-
}
174-
175174
export default TransitionablePortal

src/collections/Breadcrumb/Breadcrumb.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import _ from 'lodash'
33
import PropTypes from 'prop-types'
44
import React from 'react'
55

6-
import { childrenUtils, customPropTypes, getUnhandledProps, getElementType, SUI } from '../../lib'
6+
import { childrenUtils, customPropTypes, getUnhandledProps, getComponentType, SUI } from '../../lib'
77
import BreadcrumbDivider from './BreadcrumbDivider'
88
import BreadcrumbSection from './BreadcrumbSection'
99

@@ -15,7 +15,7 @@ const Breadcrumb = React.forwardRef(function (props, ref) {
1515

1616
const classes = cx('ui', size, 'breadcrumb', className)
1717
const rest = getUnhandledProps(Breadcrumb, props)
18-
const ElementType = getElementType(Breadcrumb, props)
18+
const ElementType = getComponentType(props)
1919

2020
if (!childrenUtils.isNil(children)) {
2121
return (

src/collections/Breadcrumb/BreadcrumbDivider.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
createShorthandFactory,
99
customPropTypes,
1010
getUnhandledProps,
11-
getElementType,
11+
getComponentType,
1212
} from '../../lib'
1313
import Icon from '../../elements/Icon'
1414

@@ -20,7 +20,7 @@ const BreadcrumbDivider = React.forwardRef(function (props, ref) {
2020

2121
const classes = cx('divider', className)
2222
const rest = getUnhandledProps(BreadcrumbDivider, props)
23-
const ElementType = getElementType(BreadcrumbDivider, props)
23+
const ElementType = getComponentType(props)
2424

2525
if (!_.isNil(icon)) {
2626
return Icon.create(icon, {

src/collections/Breadcrumb/BreadcrumbSection.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
createShorthandFactory,
99
customPropTypes,
1010
getUnhandledProps,
11-
getElementType,
11+
getComponentType,
1212
useKeyOnly,
1313
useEventCallback,
1414
} from '../../lib'
@@ -21,8 +21,10 @@ const BreadcrumbSection = React.forwardRef(function (props, ref) {
2121

2222
const classes = cx(useKeyOnly(active, 'active'), 'section', className)
2323
const rest = getUnhandledProps(BreadcrumbSection, props)
24-
const ElementType = getElementType(BreadcrumbSection, props, () => {
25-
if (link || onClick) return 'a'
24+
const ElementType = getComponentType(props, {
25+
getDefault: () => {
26+
if (link || onClick) return 'a'
27+
},
2628
})
2729

2830
const handleClick = useEventCallback((e) => _.invoke(props, 'onClick', e, props))

src/collections/Form/Form.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import _ from 'lodash'
33
import PropTypes from 'prop-types'
44
import React from 'react'
55

6-
import { getElementType, getUnhandledProps, SUI, useKeyOnly, useWidthProp } from '../../lib'
6+
import { getComponentType, getUnhandledProps, SUI, useKeyOnly, useWidthProp } from '../../lib'
77
import FormButton from './FormButton'
88
import FormCheckbox from './FormCheckbox'
99
import FormDropdown from './FormDropdown'
@@ -62,7 +62,7 @@ const Form = React.forwardRef(function (props, ref) {
6262
className,
6363
)
6464
const rest = getUnhandledProps(Form, props)
65-
const ElementType = getElementType(Form, props)
65+
const ElementType = getComponentType(props, { defaultAs: 'form' })
6666

6767
return (
6868
<ElementType {...rest} action={action} className={classes} onSubmit={handleSubmit} ref={ref}>
@@ -117,10 +117,6 @@ Form.propTypes = {
117117
widths: PropTypes.oneOf(['equal']),
118118
}
119119

120-
Form.defaultProps = {
121-
as: 'form',
122-
}
123-
124120
Form.Field = FormField
125121
Form.Button = FormButton
126122
Form.Checkbox = FormCheckbox

src/collections/Form/FormButton.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PropTypes from 'prop-types'
22
import React from 'react'
33

4-
import { getElementType, getUnhandledProps } from '../../lib'
4+
import { getComponentType, getUnhandledProps } from '../../lib'
55
import Button from '../../elements/Button'
66
import FormField from './FormField'
77

@@ -11,15 +11,15 @@ import FormField from './FormField'
1111
* @see Form
1212
*/
1313
const FormButton = React.forwardRef((props, ref) => {
14-
const { control } = props
14+
const { control = Button } = props
15+
1516
const rest = getUnhandledProps(FormButton, props)
16-
const ElementType = getElementType(FormButton, props)
17+
const ElementType = getComponentType(props, { defaultAs: FormField })
1718

1819
return <ElementType {...rest} control={control} ref={ref} />
1920
})
2021

2122
FormButton.displayName = 'FormButton'
22-
2323
FormButton.propTypes = {
2424
/** An element type to render as (string or function). */
2525
as: PropTypes.elementType,
@@ -28,9 +28,4 @@ FormButton.propTypes = {
2828
control: FormField.propTypes.control,
2929
}
3030

31-
FormButton.defaultProps = {
32-
as: FormField,
33-
control: Button,
34-
}
35-
3631
export default FormButton

src/collections/Form/FormCheckbox.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PropTypes from 'prop-types'
22
import React from 'react'
33

4-
import { getElementType, getUnhandledProps } from '../../lib'
4+
import { getComponentType, getUnhandledProps } from '../../lib'
55
import Checkbox from '../../modules/Checkbox'
66
import FormField from './FormField'
77

@@ -11,15 +11,15 @@ import FormField from './FormField'
1111
* @see Form
1212
*/
1313
const FormCheckbox = React.forwardRef((props, ref) => {
14-
const { control } = props
14+
const { control = Checkbox } = props
15+
1516
const rest = getUnhandledProps(FormCheckbox, props)
16-
const ElementType = getElementType(FormCheckbox, props)
17+
const ElementType = getComponentType(props, { defaultAs: FormField })
1718

1819
return <ElementType {...rest} control={control} ref={ref} />
1920
})
2021

2122
FormCheckbox.displayName = 'FormCheckbox'
22-
2323
FormCheckbox.propTypes = {
2424
/** An element type to render as (string or function). */
2525
as: PropTypes.elementType,
@@ -28,9 +28,4 @@ FormCheckbox.propTypes = {
2828
control: FormField.propTypes.control,
2929
}
3030

31-
FormCheckbox.defaultProps = {
32-
as: FormField,
33-
control: Checkbox,
34-
}
35-
3631
export default FormCheckbox

src/collections/Form/FormDropdown.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PropTypes from 'prop-types'
22
import React from 'react'
33

4-
import { getElementType, getUnhandledProps } from '../../lib'
4+
import { getComponentType, getUnhandledProps } from '../../lib'
55
import Dropdown from '../../modules/Dropdown'
66
import FormField from './FormField'
77

@@ -11,9 +11,10 @@ import FormField from './FormField'
1111
* @see Form
1212
*/
1313
const FormDropdown = React.forwardRef(function (props, ref) {
14-
const { control } = props
14+
const { control = Dropdown } = props
15+
1516
const rest = getUnhandledProps(FormDropdown, props)
16-
const ElementType = getElementType(FormDropdown, props)
17+
const ElementType = getComponentType(props, { defaultAs: FormField })
1718

1819
return <ElementType {...rest} control={control} ref={ref} />
1920
})
@@ -27,9 +28,4 @@ FormDropdown.propTypes = {
2728
control: FormField.propTypes.control,
2829
}
2930

30-
FormDropdown.defaultProps = {
31-
as: FormField,
32-
control: Dropdown,
33-
}
34-
3531
export default FormDropdown

0 commit comments

Comments
 (0)