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 displaying font family in the editor #2831

Merged
merged 6 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions assets/css/amp-stories-editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
padding-right: 50px;
}

#amp-story-editor,
.amp-story-page-preview .editor-styles-wrapper,
.amp-story-resize-container,
.editor-styles-wrapper .wp-block:not([data-font-family]),
.editor-styles-wrapper #amp-story-editor,
.block-editor-block-preview .block-editor-block-preview__content > div {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
Expand Down
14 changes: 10 additions & 4 deletions assets/src/stories-editor/blocks/amp-story-text/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,26 @@ class TextBlockEdit extends Component {
width,
content,
ampFitText,
ampFontFamily,
} = attributes;

const checkFontSize = (
prevProps.attributes.height !== height ||
const checkFontSize = ampFitText && (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ This check is actually already within maybeUpdateFontSize but I guess it doesn't harm to have it here + makes it more clear/readable, too.

prevProps.attributes.ampFitText !== ampFitText ||
prevProps.attributes.ampFontFamily !== ampFontFamily ||
prevProps.attributes.width !== width ||
prevProps.attributes.height !== height ||
prevProps.attributes.content !== content
);

if ( checkFontSize ) {
maybeUpdateFontSize( this.props );
}

const checkBlockDimensions = (
const checkBlockDimensions = ! ampFitText && (
! isEqual( prevProps.fontSize, fontSize ) ||
( prevProps.attributes.ampFitText !== ampFitText && ! ampFitText )
prevProps.attributes.ampFitText !== ampFitText ||
prevProps.attributes.ampFontFamily !== ampFontFamily ||
prevProps.attributes.content !== content
);

if ( checkBlockDimensions ) {
Expand Down Expand Up @@ -183,6 +188,7 @@ TextBlockEdit.propTypes = {
tagName: PropTypes.string,
opacity: PropTypes.number,
className: PropTypes.string,
ampFontFamily: PropTypes.string,
} ).isRequired,
isSelected: PropTypes.bool.isRequired,
onReplace: PropTypes.func.isRequired,
Expand Down
19 changes: 12 additions & 7 deletions assets/src/stories-editor/components/with-meta-block-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,31 @@ class MetaBlockEdit extends Component {
}

componentDidUpdate( prevProps ) {
const { attributes, isSelected, fontSize } = this.props;
const { attributes, fontSize, blockContent } = this.props;
const {
height,
width,
ampFitText,
ampFontFamily,
} = attributes;

// If not selected, only change font size if height or width has changed.
const checkFontSize = (
isSelected ||
const checkFontSize = ampFitText && (
prevProps.attributes.ampFitText !== ampFitText ||
prevProps.attributes.ampFontFamily !== ampFontFamily ||
prevProps.attributes.width !== width ||
prevProps.attributes.height !== height ||
prevProps.attributes.width !== width
prevProps.blockContent !== blockContent
);

if ( checkFontSize ) {
maybeUpdateFontSize( this.props );
}

const checkBlockDimensions = (
const checkBlockDimensions = ! ampFitText && (
! isEqual( prevProps.fontSize, fontSize ) ||
( prevProps.attributes.ampFitText !== ampFitText && ! ampFitText )
prevProps.attributes.ampFitText !== ampFitText ||
prevProps.attributes.ampFontFamily !== ampFontFamily ||
prevProps.blockContent !== blockContent
);

if ( checkBlockDimensions ) {
Expand Down Expand Up @@ -128,6 +132,7 @@ MetaBlockEdit.propTypes = {
align: PropTypes.string,
opacity: PropTypes.number,
autoFontSize: PropTypes.number,
ampFontFamily: PropTypes.string,
} ).isRequired,
setAttributes: PropTypes.func.isRequired,
blockContent: PropTypes.string,
Expand Down