Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/3239/3268 image default width #3270

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/block-components/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const Controls = props => {
imageId: attributes.imageId,
imageAspectRatio: attributes.imageAspectRatio,
imageWidthUnit: attributes.imageWidthUnit,
imageWidthUnitTablet: attributes.imageWidthUnitTablet,
imageWidthUnitMobile: attributes.imageWidthUnitMobile,
imageHeightUnit: attributes.imageHeightUnit,
imageWidth: attributes.imageWidth,
imageHeight: attributes.imageHeight,
Expand Down Expand Up @@ -103,6 +105,18 @@ const Controls = props => {
return 100
}, [ attributes.imageWidth, attributes.imageWidthUnit, attributes.imageHeight, attributes.imageHeightUnit ] )

const defaultWidth = useMemo( () => {
const attrImageWidthUnit = getAttributeName( 'imageWidthUnit', deviceType )
const unit = attributes[ attrImageWidthUnit ]
if ( unit === 'px' ) {
if ( imageData.media_details?.width ) {
return imageData.media_details.width
}
return 250
}
return 100
}, [ deviceType, attributes.imageWidthUnit, attributes.imageWidthUnitTablet, attributes.imageWidthUnitMobile, imageData ] )

return (
<>
{ applyFilters( 'stackable.block-component.image.before', null, props ) }
Expand Down Expand Up @@ -199,8 +213,9 @@ const Controls = props => {
sliderMax={ props.widthMax }
step={ props.widthStep }
initialPosition={ 100 }
default={ defaultWidth }
allowReset={ true }
placeholder="250" // TODO: This should be referenced somewher instead of just a static number
placeholder={ defaultWidth }
responsive="all"
helpTooltip={ {
//TODO: Add a working video
Expand Down Expand Up @@ -496,6 +511,7 @@ Edit.defaultProps = {
widthMin: [ 0, 0, 0 ],
widthMax: [ 1000, 100, 100 ],
widthStep: [ 1, 1, 1 ],
defaultWidth: [ 250, 100, 100 ],

hasHeight: true,
heightUnits: [ 'px', '%', 'vh' ],
Expand Down
Loading