{ props.value }
@@ -27,7 +29,7 @@ const PostPickerItem = props => {
)
}
-PostPickerItem.defaultProps = {
+const POST_PICKER_ITEM_DEFAULT_PROPS = {
value: '',
url: '',
onRemove: () => {},
@@ -43,7 +45,8 @@ const getName = ( {
return `${ title || noTitlePost( postId ) } - ${ postType }`
}
-const PostPickerControl = props => {
+const PostPickerControl = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, POST_PICKER_CONTROL_DEFAULT_PROPS )
const [ inputValue, setInputValue ] = useState( '' )
const [ searchResults, setSearchResults ] = useState( [] )
const [ focused, setFocused ] = useState( false )
@@ -162,7 +165,7 @@ const PostPickerControl = props => {
)
}
-PostPickerControl.defaultProps = {
+const POST_PICKER_CONTROL_DEFAULT_PROPS = {
className: '',
label: __( 'Pick a post', i18n ),
value: [],
diff --git a/src/components/admin-base-setting/index.js b/src/components/admin-base-setting/index.js
index 3ba23258b9..7eb59de569 100644
--- a/src/components/admin-base-setting/index.js
+++ b/src/components/admin-base-setting/index.js
@@ -1,9 +1,11 @@
import { useState } from '@wordpress/element'
import classnames from 'classnames'
+import { getPropsWithDefaults } from '../../util/props'
let i = 1
-const AdminBaseSetting = props => {
+const AdminBaseSetting = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADMIN_BASE_SETTING_DEFAULT_PROPS )
const { showLabel = true } = props
const [ uid ] = useState( `ugb-admin-setting-${ i++ }` )
const isSearched = props.searchedSettings ? props.searchedSettings.includes( props.label ) : true
@@ -32,7 +34,7 @@ const AdminBaseSetting = props => {
)
}
-AdminBaseSetting.defaultProps = {
+const ADMIN_BASE_SETTING_DEFAULT_PROPS = {
label: '',
onClick: () => {},
}
diff --git a/src/components/admin-icon-setting/index.js b/src/components/admin-icon-setting/index.js
index d27554e708..9da8970543 100644
--- a/src/components/admin-icon-setting/index.js
+++ b/src/components/admin-icon-setting/index.js
@@ -1,10 +1,12 @@
import AdminBaseSetting from '../admin-base-setting'
import IconControl from '../icon-control'
import classnames from 'classnames'
+import { getPropsWithDefaults } from '../../util/props'
const defaultIcon = '
'
-const AdminIconSetting = props => {
+const AdminIconSetting = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADMIN_ICON_SETTING_DEFAULT_PROPS )
return (
{
)
}
-AdminIconSetting.defaultProps = {
+const ADMIN_ICON_SETTING_DEFAULT_PROPS = {
value: '',
onChange: () => {},
}
diff --git a/src/components/admin-select-setting/index.js b/src/components/admin-select-setting/index.js
index 05b8fa5147..60945579bf 100644
--- a/src/components/admin-select-setting/index.js
+++ b/src/components/admin-select-setting/index.js
@@ -1,6 +1,8 @@
import AdminBaseSetting from '../admin-base-setting'
+import { getPropsWithDefaults } from '../../util/props'
-const AdminSelectSetting = props => {
+const AdminSelectSetting = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADMIN_SELECT_SETTING_DEFAULT_PROPS )
return (
{ /* eslint-disable-next-line jsx-a11y/no-onchange */ }
@@ -23,7 +25,7 @@ const AdminSelectSetting = props => {
)
}
-AdminSelectSetting.defaultProps = {
+const ADMIN_SELECT_SETTING_DEFAULT_PROPS = {
label: '',
value: '',
onChange: () => {},
diff --git a/src/components/admin-text-setting/index.js b/src/components/admin-text-setting/index.js
index 0c187b30de..4fa5340e38 100644
--- a/src/components/admin-text-setting/index.js
+++ b/src/components/admin-text-setting/index.js
@@ -1,8 +1,10 @@
import AdminBaseSetting from '../admin-base-setting'
import { useRef, useState } from '@wordpress/element'
import { maskSensitiveValue } from '~stackable/util/mask-sensitive-value'
+import { getPropsWithDefaults } from '../../util/props'
-const AdminTextSetting = props => {
+const AdminTextSetting = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADMIN_TEXT_SETTING_DEFAULT_PROPS )
const ref = useRef()
const [ isEditing, setIsEditing ] = useState( false )
const value = props.maskValue && ! isEditing ? maskSensitiveValue( props.value ) : props.value
@@ -48,7 +50,7 @@ const AdminTextSetting = props => {
)
}
-AdminTextSetting.defaultProps = {
+const ADMIN_TEXT_SETTING_DEFAULT_PROPS = {
label: '',
type: 'text',
value: '',
diff --git a/src/components/admin-toggle-setting/index.js b/src/components/admin-toggle-setting/index.js
index 0b37e7f71c..dfca5efb1f 100644
--- a/src/components/admin-toggle-setting/index.js
+++ b/src/components/admin-toggle-setting/index.js
@@ -3,8 +3,10 @@ import AdminBaseSetting from '../admin-base-setting'
import { createRef } from '@wordpress/element'
import { __ } from '@wordpress/i18n'
import classnames from 'classnames'
+import { getPropsWithDefaults } from '../../util/props'
-const AdminToggleSetting = props => {
+const AdminToggleSetting = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADMIN_TOGGLE_SETTING_DEFAULT_PROPS )
const ref = createRef()
return (
{
)
}
-AdminToggleSetting.defaultProps = {
+const ADMIN_TOGGLE_SETTING_DEFAULT_PROPS = {
label: '',
value: false,
placeholder: '',
diff --git a/src/components/admin-toolbar-setting/index.js b/src/components/admin-toolbar-setting/index.js
index cf848dcd22..d343dced60 100644
--- a/src/components/admin-toolbar-setting/index.js
+++ b/src/components/admin-toolbar-setting/index.js
@@ -3,8 +3,10 @@ import Button from '../button'
import { ButtonGroup } from '@wordpress/components'
import { __ } from '@wordpress/i18n'
import { i18n } from 'stackable'
+import { getPropsWithDefaults } from '../../util/props'
-const AdminToolbarSetting = props => {
+const AdminToolbarSetting = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADMIN_TOOLBAR_SETTING_DEFAULT_PROPS )
return (
{
)
}
-AdminToolbarSetting.defaultProps = {
+const ADMIN_TOOLBAR_SETTING_DEFAULT_PROPS = {
controls: [],
label: '',
value: '',
diff --git a/src/components/advanced-focal-point-control/index.js b/src/components/advanced-focal-point-control/index.js
index 05c07714b9..b5478dea8d 100644
--- a/src/components/advanced-focal-point-control/index.js
+++ b/src/components/advanced-focal-point-control/index.js
@@ -16,12 +16,14 @@ import { memo } from '@wordpress/element'
* External dependencies
*/
import classnames from 'classnames'
+import { getPropsWithDefaults } from '../../util/props'
// This is only used for display purposes in the focal picker because it doesn't
// accept blank/empty string/null/undefined.
const FOCAL_DEFAULT_VALUE = { x: 0.5, y: 0.5 }
-const AdvancedFocalPointControl = props => {
+const AdvancedFocalPointControl = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADVANCED_FOCAL_POINT_CONTROL_DEFAULT_PROPS )
const [ _value, onChange ] = useControlHandlers( props.attribute, props.responsive, props.hover )
const [ propsToPass, controlProps ] = extractControlProps( props )
@@ -54,7 +56,7 @@ const AdvancedFocalPointControl = props => {
)
}
-AdvancedFocalPointControl.defaultProps = {
+const ADVANCED_FOCAL_POINT_CONTROL_DEFAULT_PROPS = {
className: '',
url: '',
diff --git a/src/components/advanced-radio-control/index.js b/src/components/advanced-radio-control/index.js
index 3a708997ed..c41c9a0f24 100644
--- a/src/components/advanced-radio-control/index.js
+++ b/src/components/advanced-radio-control/index.js
@@ -9,9 +9,11 @@ import { RadioControl } from '@wordpress/components'
import classnames from 'classnames'
import { omit } from 'lodash'
import { BaseControl } from '..'
+import { getPropsWithDefaults } from '../../util/props'
// TODO: reset not showing up
-const AdvancedRadioControl = props => {
+const AdvancedRadioControl = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADVANCED_RADIO_CONTROL_DEFAULT_PROPS )
return (
{
)
}
-AdvancedRadioControl.defaultProps = {
+const ADVANCED_RADIO_CONTROL_DEFAULT_PROPS = {
onChange: () => {},
onChangeUnit: () => {},
help: '',
diff --git a/src/components/advanced-range-control/index.js b/src/components/advanced-range-control/index.js
index 340a38e9f6..83cdf8f06e 100644
--- a/src/components/advanced-range-control/index.js
+++ b/src/components/advanced-range-control/index.js
@@ -20,6 +20,7 @@ import {
import {
extractNumbersAndUnits, getCSSVarName, convertToPxIfUnsupported,
} from '~stackable/util'
+import { getPropsWithDefaults } from '../../util/props'
import { settings as stackableSettings } from 'stackable'
/**
@@ -32,7 +33,8 @@ import { Button } from '@wordpress/components'
import { settings } from '@wordpress/icons'
import { dispatch } from '@wordpress/data'
-const AdvancedRangeControl = props => {
+const AdvancedRangeControl = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADVANCED_RANGE_CONTROL_DEFAULT_PROPS )
const [ value, onChange ] = useControlHandlers( props.attribute, props.responsive, props.hover, props.valueCallback, props.changeCallback )
const [ propsToPass, controlProps ] = extractControlProps( props )
@@ -325,7 +327,7 @@ const AdvancedRangeControl = props => {
)
}
-AdvancedRangeControl.defaultProps = {
+const ADVANCED_RANGE_CONTROL_DEFAULT_PROPS = {
allowReset: true,
onReset: undefined,
showReset: undefined,
diff --git a/src/components/advanced-range-control/range-control.js b/src/components/advanced-range-control/range-control.js
index d14bb6c1e6..2b6638afce 100644
--- a/src/components/advanced-range-control/range-control.js
+++ b/src/components/advanced-range-control/range-control.js
@@ -27,6 +27,7 @@ import { __ } from '@wordpress/i18n'
import classnames from 'classnames'
import { clamp } from 'lodash'
import { i18n } from 'stackable'
+import { getPropsWithDefaults } from '../../util/props'
// NumberControl is only supported in WP 5.5
const isNumberControlSupported = !! NumberControl
@@ -36,7 +37,8 @@ export const getPercentageValue = ( value, min, max ) => {
return `${ clamp( percentageValue, 0, 100 ) }%`
}
-const StackableRangeControl = memo( props => {
+const StackableRangeControl = memo( incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, STACKABLE_RANGE_CONTROL_DEFAULT_PROPS )
const {
allowReset,
withInputField,
@@ -198,7 +200,7 @@ const StackableRangeControl = memo( props => {
} )
-StackableRangeControl.defaultProps = {
+const STACKABLE_RANGE_CONTROL_DEFAULT_PROPS = {
className: '',
allowReset: false,
withInputField: true,
diff --git a/src/components/advanced-select-control/index.js b/src/components/advanced-select-control/index.js
index 9bcd105bd7..a8b5ba2fab 100644
--- a/src/components/advanced-select-control/index.js
+++ b/src/components/advanced-select-control/index.js
@@ -16,8 +16,10 @@ import { memo } from '@wordpress/element'
*/
import classnames from 'classnames'
import { isEqual } from 'lodash'
+import { getPropsWithDefaults } from '../../util/props'
-const AdvancedSelectControl = memo( props => {
+const AdvancedSelectControl = memo( incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADVANCED_SELECT_CONTROL_DEFAULT_PROPS )
const [ value, onChange ] = useControlHandlers( props.attribute, props.responsive, props.hover, props.valueCallback, props.changeCallback )
const [ propsToPass, controlProps ] = extractControlProps( props )
const {
@@ -48,7 +50,7 @@ const AdvancedSelectControl = memo( props => {
)
}, isEqual )
-AdvancedSelectControl.defaultProps = {
+const ADVANCED_SELECT_CONTROL_DEFAULT_PROPS = {
className: '',
url: '',
diff --git a/src/components/advanced-text-control/index.js b/src/components/advanced-text-control/index.js
index 0a30a83b9a..6bcb62ccd0 100644
--- a/src/components/advanced-text-control/index.js
+++ b/src/components/advanced-text-control/index.js
@@ -18,8 +18,10 @@ import { memo } from '@wordpress/element'
*/
import classnames from 'classnames'
import { isEqual } from 'lodash'
+import { getPropsWithDefaults } from '../../util/props'
-const AdvancedTextControl = memo( props => {
+const AdvancedTextControl = memo( incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADVANCED_TEXT_CONTROL_DEFAULT_PROPS )
const [ value, onChange ] = useControlHandlers( props.attribute, props.responsive, props.hover, props.valueCallback, props.changeCallback )
const [ propsToPass, controlProps ] = extractControlProps( props )
const {
@@ -81,7 +83,7 @@ const AdvancedTextControl = memo( props => {
)
}, isEqual )
-AdvancedTextControl.defaultProps = {
+const ADVANCED_TEXT_CONTROL_DEFAULT_PROPS = {
className: '',
isMultiline: false,
allowReset: true,
diff --git a/src/components/advanced-toggle-control/index.js b/src/components/advanced-toggle-control/index.js
index 7ea26bae50..75af4dc79f 100644
--- a/src/components/advanced-toggle-control/index.js
+++ b/src/components/advanced-toggle-control/index.js
@@ -18,8 +18,10 @@ import { useInstanceId } from '@wordpress/compose'
import { FormToggle } from '@wordpress/components'
import { memo } from '@wordpress/element'
import { useControlHandlers } from '../base-control2/hooks'
+import { getPropsWithDefaults } from '../../util/props'
-const AdvancedToggleControl = memo( props => {
+const AdvancedToggleControl = memo( incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADVANCED_TOGGLE_CONTROL_DEFAULT_PROPS )
const {
help,
} = props
@@ -71,7 +73,7 @@ const AdvancedToggleControl = memo( props => {
)
} )
-AdvancedToggleControl.defaultProps = {
+const ADVANCED_TOGGLE_CONTROL_DEFAULT_PROPS = {
className: '',
allowReset: true,
showReset: null,
diff --git a/src/components/advanced-token-field/index.js b/src/components/advanced-token-field/index.js
index 28e46aeb19..8d71ab73c1 100644
--- a/src/components/advanced-token-field/index.js
+++ b/src/components/advanced-token-field/index.js
@@ -14,8 +14,10 @@ import { FormTokenField } from '@wordpress/components'
* External dependencies
*/
import classnames from 'classnames'
+import { getPropsWithDefaults } from '../../util/props'
-const AdvancedTokenField = props => {
+const AdvancedTokenField = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADVANCED_TOKEN_FIELD_DEFAULT_PROPS )
const [ value, onChange ] = useControlHandlers( props.attribute, props.responsive, props.hover )
const [ propsToPass, controlProps ] = extractControlProps( props )
const {
@@ -45,7 +47,7 @@ const AdvancedTokenField = props => {
)
}
-AdvancedTokenField.defaultProps = {
+const ADVANCED_TOKEN_FIELD_DEFAULT_PROPS = {
className: '',
allowReset: true,
default: '',
diff --git a/src/components/advanced-toolbar-control/index.js b/src/components/advanced-toolbar-control/index.js
index c0796a7063..80b36699bf 100644
--- a/src/components/advanced-toolbar-control/index.js
+++ b/src/components/advanced-toolbar-control/index.js
@@ -16,6 +16,7 @@ import Button from '../button'
import AdvancedControl, { extractControlProps } from '../base-control2'
import { useControlHandlers } from '../base-control2/hooks'
import { ResetButton } from '../base-control2/reset-button'
+import { getPropsWithDefaults } from '../../util/props'
/**
* External dependencies
@@ -194,7 +195,28 @@ export const CONTROLS = {
vertical: VERTICAL_ALIGN_OPTIONS,
}
-const AdvancedToolbarControl = props => {
+const EMPTY_ARR = []
+
+const ADVANCED_TOOLBAR_CONTROL_DEFAULT_PROPS = {
+ controls: EMPTY_ARR,
+ multiline: false,
+ fullwidth: true,
+ isSmall: false,
+ isToggleOnly: false,
+ allowReset: true,
+ default: '',
+ attribute: '',
+ responsive: false,
+ hover: false,
+ value: undefined,
+ onChange: undefined,
+ placeholder: '',
+ disabled: EMPTY_ARR,
+ omit: EMPTY_ARR,
+}
+
+const AdvancedToolbarControl = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADVANCED_TOOLBAR_CONTROL_DEFAULT_PROPS )
const [ _value, _onChange ] = useControlHandlers( props.attribute, props.responsive, props.hover, props.valueCallback, props.changeCallback )
const [ _propsToPass, controlProps ] = extractControlProps( props )
@@ -290,27 +312,4 @@ const AdvancedToolbarControl = props => {
)
}
-const EMPTY_ARR = []
-
-AdvancedToolbarControl.defaultProps = {
- controls: EMPTY_ARR,
- multiline: false,
- fullwidth: true,
- isSmall: false,
- isToggleOnly: false,
-
- allowReset: true,
- default: '',
-
- attribute: '',
- responsive: false,
- hover: false,
-
- value: undefined,
- onChange: undefined,
- placeholder: '',
- disabled: EMPTY_ARR,
- omit: EMPTY_ARR,
-}
-
export default memo( AdvancedToolbarControl, isEqual )
diff --git a/src/components/align-buttons-control/index.js b/src/components/align-buttons-control/index.js
index c9a6c71264..1709c40f53 100644
--- a/src/components/align-buttons-control/index.js
+++ b/src/components/align-buttons-control/index.js
@@ -9,6 +9,7 @@ import { __ } from '@wordpress/i18n'
import { i18n } from 'stackable'
import { AdvancedToolbarControl } from '~stackable/components'
import classnames from 'classnames'
+import { getPropsWithDefaults } from '../../util/props'
const ALIGN_OPTIONS = [
{
@@ -35,7 +36,8 @@ const ALIGN_OPTIONS = [
const ALIGN_OPTIONS_NO_JUSTIFY = ALIGN_OPTIONS.filter( option => option.value !== 'justify' )
-const AlignButtonsControl = props => {
+const AlignButtonsControl = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ALIGN_BUTTONS_CONTROL_DEFAULT_PROPS )
const {
justified,
className,
@@ -57,7 +59,7 @@ const AlignButtonsControl = props => {
)
}
-AlignButtonsControl.defaultProps = {
+const ALIGN_BUTTONS_CONTROL_DEFAULT_PROPS = {
className: '',
label: __( 'Align', i18n ),
justified: false,
diff --git a/src/components/base-control-multi-label/index.js b/src/components/base-control-multi-label/index.js
index b4ae594da9..70d872517d 100644
--- a/src/components/base-control-multi-label/index.js
+++ b/src/components/base-control-multi-label/index.js
@@ -10,8 +10,10 @@ import LabelTooltip from '../base-control2/label-tooltip'
* External dependencies
*/
import { __ } from '@wordpress/i18n'
+import { getPropsWithDefaults } from '../../util/props'
-const BaseControlMultiLabel = props => {
+const BaseControlMultiLabel = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, BASE_CONTROL_MULTI_LABEL_DEFAULT_PROPS )
const screens = props.screens === 'all' ? [ 'desktop', 'tablet', 'mobile' ] : props.screens
const units = props.units?.map( unit => {
@@ -42,7 +44,7 @@ const BaseControlMultiLabel = props => {
)
}
-BaseControlMultiLabel.defaultProps = {
+const BASE_CONTROL_MULTI_LABEL_DEFAULT_PROPS = {
label: '',
units: [ 'px' ],
unit: 'px',
diff --git a/src/components/base-control/index.js b/src/components/base-control/index.js
index f2fcae93f2..be35dde2f3 100644
--- a/src/components/base-control/index.js
+++ b/src/components/base-control/index.js
@@ -21,8 +21,10 @@ import classnames from 'classnames'
import { BaseControl as _BaseControl, Dashicon } from '@wordpress/components'
import { i18n } from 'stackable'
import { __ } from '@wordpress/i18n'
+import { getPropsWithDefaults } from '../../util/props'
-const BaseControl = props => {
+const BaseControl = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, BASE_CONTROL_DEFAULT_PROPS )
const isVisible = useResponsiveControlVisibility( props.screens )
// Register even when this control returns null so its parent panel can tell
// when responsive filtering has removed every control inside it.
@@ -90,7 +92,7 @@ const BaseControl = props => {
)
}
-BaseControl.defaultProps = {
+const BASE_CONTROL_DEFAULT_PROPS = {
className: '',
help: '',
id: '',
diff --git a/src/components/base-control2/hover-state-toggle.js b/src/components/base-control2/hover-state-toggle.js
index 2f13f75a45..6c9a355a68 100644
--- a/src/components/base-control2/hover-state-toggle.js
+++ b/src/components/base-control2/hover-state-toggle.js
@@ -22,6 +22,7 @@ import { __, sprintf } from '@wordpress/i18n'
import { dispatch } from '@wordpress/data'
import { upperFirst, camelCase } from 'lodash'
import { isEmptyAttribute } from '~stackable/util'
+import { getPropsWithDefaults } from '../../util/props'
const HOVER_OPTIONS = [
{
@@ -50,7 +51,8 @@ const ALL_HOVER = [ 'normal', 'hover', 'parent-hover', 'collapsed' ]
const _ALL_HOVER = [ 'normal', 'hover', 'parent-hover', 'collapsed' ]
const ALL_HOVER_ATTRIBUTE_SUFFIX = ALL_HOVER.map( s => upperFirst( camelCase( s ) ) )
-const HoverStateToggle = props => {
+const HoverStateToggle = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, HOVER_STATE_TOGGLE_DEFAULT_PROPS )
const [ currentHoverState, _blockHoverClass, hasParentHoverState, hasCollapsedState, isCollapsedBlock ] = useBlockHoverState( { forceUpdateHoverState: props.forceUpdateHoverState } )
const deviceType = useDeviceType()
@@ -120,7 +122,7 @@ const HoverStateToggle = props => {
)
}
-HoverStateToggle.defaultProps = {
+const HOVER_STATE_TOGGLE_DEFAULT_PROPS = {
hover: false,
attribute: '',
hasResponsive: false, // Wether the attribute has responsive attributes (where we have hover states per device type)
diff --git a/src/components/base-control2/index.js b/src/components/base-control2/index.js
index 11c44650e5..0fbca2bf8c 100644
--- a/src/components/base-control2/index.js
+++ b/src/components/base-control2/index.js
@@ -29,6 +29,7 @@ import { pick, omit } from 'lodash'
import { __ } from '@wordpress/i18n'
import { Fragment } from '@wordpress/element'
import { BaseControl as GutBaseControl } from '@wordpress/components'
+import { getPropsWithDefaults } from '../../util/props'
// Expose useControlHandlers to our API.
export { useControlHandlers } from './hooks'
@@ -36,7 +37,8 @@ export { useControlHandlers } from './hooks'
const ALL_SCREENS = [ 'desktop', 'tablet', 'mobile' ]
const EMPTY_OBJ = {}
-export const BaseControl = props => {
+export const BaseControl = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, BASE_CONTROL_DEFAULT_PROPS )
const deviceType = useDeviceType()
const isVisible = useResponsiveControlVisibility( props.responsive )
// Register even when this control returns null so its parent panel can tell
@@ -127,7 +129,7 @@ export const BaseControl = props => {
)
}
-BaseControl.defaultProps = {
+const BASE_CONTROL_DEFAULT_PROPS = {
className: '',
label: '',
help: '',
@@ -160,7 +162,8 @@ BaseControl.defaultProps = {
hasHoverStateValue: undefined,
}
-const AdvancedControl = props => {
+const AdvancedControl = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, ADVANCED_CONTROL_DEFAULT_PROPS )
// Unit handles
const unitAttrName = useAttributeName( `${ props.attribute }Unit`, props.responsive, props.hover )
const unitAttribute = useBlockAttributesContext( attributes => attributes[ unitAttrName ] ) || ''
@@ -183,7 +186,7 @@ const AdvancedControl = props => {
)
}
-AdvancedControl.defaultProps = {
+const ADVANCED_CONTROL_DEFAULT_PROPS = {
// Control props
className: '',
label: '',
@@ -222,7 +225,7 @@ AdvancedControl.defaultProps = {
export default AdvancedControl
export const extractControlProps = props => {
- const advancedControlProps = [ ...Object.keys( AdvancedControl.defaultProps ), 'allowReset', 'screens' ]
+ const advancedControlProps = [ ...Object.keys( ADVANCED_CONTROL_DEFAULT_PROPS ), 'allowReset', 'screens' ]
const controlProps = pick( props, advancedControlProps )
if ( props.screens ) {
controlProps.responsive = props.screens
diff --git a/src/components/base-control2/label-tooltip.js b/src/components/base-control2/label-tooltip.js
index 939bbba4ef..a343b62c13 100644
--- a/src/components/base-control2/label-tooltip.js
+++ b/src/components/base-control2/label-tooltip.js
@@ -8,6 +8,7 @@
*/
import HelpTooltip from '../help-tooltip'
import { fetchSettings } from '~stackable/util'
+import { getPropsWithDefaults } from '../../util/props'
/**
* WordPress dependencies
@@ -18,7 +19,8 @@ import {
import { models } from '@wordpress/api'
import domReady from '@wordpress/dom-ready'
-const LabelTooltip = props => {
+const LabelTooltip = incomingProps => {
+ const props = getPropsWithDefaults( incomingProps, LABEL_TOOLTIP_DEFAULT_PROPS )
const {
title,
label: controlLabel,
@@ -98,7 +100,7 @@ const LabelTooltip = props => {
)
}
-LabelTooltip.defaultProps = {
+const LABEL_TOOLTIP_DEFAULT_PROPS = {
label: '',
description: '',
video: '',
diff --git a/src/components/base-control2/reset-button.js b/src/components/base-control2/reset-button.js
index 6ca2e43eae..d432d21723 100644
--- a/src/components/base-control2/reset-button.js
+++ b/src/components/base-control2/reset-button.js
@@ -11,10 +11,12 @@ import { __ } from '@wordpress/i18n'
import { Dashicon } from '@wordpress/components'
import { memo } from '@wordpress/element'
import classnames from 'classnames'
+import { getPropsWithDefaults } from '../../util/props'
const icon =