Skip to content

Commit

Permalink
Merge pull request #45 from material-components/fix/17-card-image
Browse files Browse the repository at this point in the history
Fix card image remove
  • Loading branch information
emeaguiar authored and ravichdev committed Apr 13, 2021
2 parents 349519e + ccb8cc9 commit af0f869
Show file tree
Hide file tree
Showing 16 changed files with 424 additions and 186 deletions.
186 changes: 95 additions & 91 deletions plugin/assets/src/block-editor/blocks/card/block.json
Original file line number Diff line number Diff line change
@@ -1,92 +1,96 @@
{
"name": "material/card",
"category": "material",
"attributes": {
"contentLayout": {
"type": "string",
"default": "text-under-media"
},
"title": {
"type": "string",
"default": ""
},
"displayTitle": {
"type": "boolean",
"default": true
},
"secondaryText": {
"type": "string",
"default": ""
},
"displaySecondaryText": {
"type": "boolean",
"default": true
},
"imageSourceUrl": {
"type": "string"
},
"isImageEditMode": {
"type": "boolean"
},
"displayImage": {
"type": "boolean",
"default": true
},
"supportingText": {
"type": "string",
"default": ""
},
"displaySupportingText": {
"type": "boolean",
"default": true
},
"primaryActionButtonLabel": {
"type": "string",
"default": ""
},
"primaryActionButtonUrl": {
"type": "string"
},
"primaryActionButtonNewTab": {
"type": "bool",
"default": false
},
"primaryActionButtonNoFollow": {
"type": "bool",
"default": false
},
"secondaryActionButtonLabel": {
"type": "string",
"default": ""
},
"secondaryActionButtonUrl": {
"type": "string"
},
"secondaryActionButtonNewTab": {
"type": "bool",
"default": false
},
"secondaryActionButtonNoFollow": {
"type": "bool",
"default": false
},
"displayActions": {
"type": "boolean",
"default": true
},
"displaySecondaryActionButton": {
"type": "bool",
"default": false
},
"cornerRadius": {
"type": "number"
},
"outlined": {
"type": "boolean",
"default": false
}
},
"supports": {
"align": [ "left", "right" ]
}
}
"name": "material/card",
"category": "material",
"attributes": {
"contentLayout": {
"type": "string",
"default": "text-under-media"
},
"title": {
"type": "string",
"default": ""
},
"displayTitle": {
"type": "boolean",
"default": true
},
"secondaryText": {
"type": "string",
"default": ""
},
"displaySecondaryText": {
"type": "boolean",
"default": true
},
"imageSourceUrl": {
"type": "string"
},
"isImageEditMode": {
"type": "boolean"
},
"displayImage": {
"type": "boolean",
"default": true
},
"supportingText": {
"type": "string",
"default": ""
},
"displaySupportingText": {
"type": "boolean",
"default": true
},
"primaryActionButtonLabel": {
"type": "string",
"default": ""
},
"primaryActionButtonUrl": {
"type": "string"
},
"primaryActionButtonNewTab": {
"type": "bool",
"default": false
},
"primaryActionButtonNoFollow": {
"type": "bool",
"default": false
},
"secondaryActionButtonLabel": {
"type": "string",
"default": ""
},
"secondaryActionButtonUrl": {
"type": "string"
},
"secondaryActionButtonNewTab": {
"type": "bool",
"default": false
},
"secondaryActionButtonNoFollow": {
"type": "bool",
"default": false
},
"displayActions": {
"type": "boolean",
"default": true
},
"displaySecondaryActionButton": {
"type": "bool",
"default": false
},
"cornerRadius": {
"type": "number"
},
"outlined": {
"type": "boolean",
"default": false
},
"imageElement": {
"type": "boolean",
"default": true
}
},
"supports": {
"align": [ "left", "right" ]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const CardImage = ( {
cardIndex,
setter,
isEditMode,
imageElement,
} ) => {
const { isFocused } = cardPrimaryProps;
const cardImageEditProps = {
Expand All @@ -66,6 +67,10 @@ const CardImage = ( {
isFocused,
};

const style = ! imageElement
? { backgroundImage: `url(${ imageSourceUrl })` }
: {};

return (
<>
{ isEditMode ? (
Expand All @@ -82,8 +87,14 @@ const CardImage = ( {
[ `material-design-card-with-${ contentLayout }` ]: contentLayout,
}
) }
style={ { backgroundImage: `url(${ imageSourceUrl })` } }
style={ style }
>
{ imageElement && (
<img
src={ imageSourceUrl }
alt={ cardPrimaryProps.title || '' }
/>
) }
{ contentLayout === 'text-over-media' && (
<div className="mdc-card__media-content">
<CardPrimary { ...cardPrimaryProps } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const HorizontalCardLayout = ( {
displayActions,
outlined,
cornerRadius,
imageElement,
setter,
isEditMode,
isFocused,
Expand Down Expand Up @@ -105,6 +106,7 @@ const HorizontalCardLayout = ( {
setter,
isEditMode,
isFocused,
imageElement,
};

const styles = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const VerticalCardLayout = ( {
displayActions,
outlined,
cornerRadius,
imageElement,
setter,
isEditMode,
isFocused,
Expand All @@ -108,6 +109,7 @@ const VerticalCardLayout = ( {
cardIndex,
setter,
isEditMode,
imageElement,
};

const styles = {};
Expand Down
52 changes: 52 additions & 0 deletions plugin/assets/src/block-editor/blocks/card/deprecated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* External dependencies
*/
import { omit } from 'lodash';

/**
* Internal dependencies
*/
import save from './save';
import metadata from './block.json';

const { attributes } = metadata;

const deprecated = [
{
attributes: { ...omit( attributes, [ 'imageElement' ] ) },
save,
migrate( attr ) {
if ( 'undefined' === typeof attr.imageElement ) {
attr = {
...attr,
...{
imageElement: true,
},
};
}

return attr;
},
isEligible( attr ) {
return 'undefined' === typeof attr.imageElement;
},
},
];

export default deprecated;
1 change: 1 addition & 0 deletions plugin/assets/src/block-editor/blocks/card/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const Edit = ( { attributes, setAttributes, className } ) => {
cornerRadius,
setter,
isEditMode: true,
isFocused: true,
};

const inspectorControlsStylePanelProps = {
Expand Down
5 changes: 3 additions & 2 deletions plugin/assets/src/block-editor/blocks/card/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
}
}

.material-design-card__media-close-button {
.edit-post-visual-editor .material-design-card__media-close-button {
min-width: 0;
padding: 2px !important;

& .dashicon {
margin: 0 !important;
margin: 0;
}
}

Expand Down
2 changes: 2 additions & 0 deletions plugin/assets/src/block-editor/blocks/card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import deprecated from './deprecated';
import edit from './edit';
import save from './save';
import metadata from './block.json';
Expand All @@ -45,4 +46,5 @@ export const settings = {
example,
edit,
save,
deprecated,
};
2 changes: 2 additions & 0 deletions plugin/assets/src/block-editor/blocks/card/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const Save = ( { attributes, className } ) => {
displaySecondaryActionButton,
outlined,
cornerRadius,
imageElement,
} = attributes;

const cardProps = {
Expand All @@ -81,6 +82,7 @@ const Save = ( { attributes, className } ) => {
displaySecondaryActionButton,
outlined,
cornerRadius,
imageElement,
setter: () => {},
isEditMode: false,
};
Expand Down
Loading

0 comments on commit af0f869

Please sign in to comment.