Skip to content

Commit

Permalink
Address some PR reviews.
Browse files Browse the repository at this point in the history
  • Loading branch information
obetomuniz committed May 5, 2020
1 parent 3a91999 commit b65c513
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
7 changes: 3 additions & 4 deletions assets/src/edit-story/app/font/actions/useLoadFontFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function useLoadFontFiles() {
*
* Allows dynamically enqueuing font styles when needed.
*
* @param {Array} props An array of fonts properties to create a valid FontFaceSet to inject and preload a font-face
* @param {Array} fonts An array of fonts properties to create a valid FontFaceSet to inject and preload a font-face
* @return {Promise} Returns fonts loaded promise
*/
const maybeEnqueueFontStyle = useCallback((fonts) => {
Expand Down Expand Up @@ -72,11 +72,10 @@ function useLoadFontFiles() {

const appendFontLink = () => {
return new Promise((resolve, reject) => {
const src = getGoogleFontURL([{ family, variants }]);
const src = getGoogleFontURL([{ family, variants }], 'auto');
const fontStylesheet = document.createElement('link');
const fontHref = src.replace('display=swap', 'display=auto');
fontStylesheet.id = elementId;
fontStylesheet.href = fontHref;
fontStylesheet.href = src;
fontStylesheet.rel = 'stylesheet';
fontStylesheet.type = 'text/css';
fontStylesheet.media = 'all';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ FontPreview.propTypes = {
font: FontPropType,
fontSize: PropTypes.number,
fontWeight: PropTypes.number,
fontStyle: PropTypes.number,
fontStyle: PropTypes.string,
onClick: PropTypes.func,
};

Expand Down
13 changes: 7 additions & 6 deletions assets/src/edit-story/components/panels/textStyle/font.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,20 @@ function FontControls({ selectedElements, pushUpdate }) {
]),
};
const { weights } = fontObj;
await maybeEnqueueFontStyle(
selectedElements.map((e) => ({
...e,
font: newFont,
}))
);
// Find the nearest font weight from the available font weight list
const newFontWeight = weights.reduce((a, b) =>
Math.abs(parseInt(b) - fontWeight) <
Math.abs(parseInt(a) - fontWeight)
? b
: a
);
await maybeEnqueueFontStyle(
selectedElements.map((e) => ({
...e,
font: newFont,
fontWeight: newFontWeight,
}))
);

pushUpdate(
{
Expand Down

0 comments on commit b65c513

Please sign in to comment.