diff --git a/app/assets/javascripts/wizard/components/font-preview.js b/app/assets/javascripts/wizard/components/font-preview.js index 1a5d71bc5bc..fef9fa56d4d 100644 --- a/app/assets/javascripts/wizard/components/font-preview.js +++ b/app/assets/javascripts/wizard/components/font-preview.js @@ -1,30 +1,26 @@ import I18n from "I18n"; -import discourseComputed from "discourse-common/utils/decorators"; import { observes } from "discourse-common/utils/decorators"; import { createPreviewComponent, darkLightDiff, chooseDarker, - LOREM, } from "wizard/lib/preview"; -export default createPreviewComponent(305, 165, { +const LOREM = ` +Lorem ipsum dolor sit amet, consectetur adipiscing. +Nullam eget sem non elit tincidunt rhoncus. Fusce +velit nisl, porttitor sed nisl ac, consectetur interdum +metus. Fusce in consequat augue, vel facilisis felis.`; + +export default createPreviewComponent(659, 320, { logo: null, avatar: null, - classNameBindings: ["isSelected"], - - @discourseComputed("selectedId", "fontId") - isSelected(selectedId, fontId) { - return selectedId === fontId; - }, - - click() { - this.onChange(this.fontId); - }, - - @observes("step.fieldsById.base_scheme_id.value") - themeChanged() { + @observes( + "step.fieldsById.body_font.value", + "step.fieldsById.heading_font.value" + ) + fontChanged() { this.triggerRepaint(); }, @@ -35,47 +31,44 @@ export default createPreviewComponent(305, 165, { }; }, - paint(ctx, colors, font, width, height) { + paint({ ctx, colors, font, headingFont, width, height }) { const headerHeight = height * 0.3; - this.drawFullHeader(colors, font); + + this.drawFullHeader(colors, headingFont, this.logo); const margin = width * 0.04; const avatarSize = height * 0.2; - const lineHeight = height / 9.5; + const lineHeight = height / 11; // Draw a fake topic this.scaleImage( this.avatar, margin, - headerHeight + height * 0.085, + headerHeight + height * 0.11, avatarSize, avatarSize ); - const titleFontSize = headerHeight / 44; + const titleFontSize = headerHeight / 55; ctx.beginPath(); ctx.fillStyle = colors.primary; - ctx.font = `bold ${titleFontSize}em '${font}'`; - ctx.fillText( - I18n.t("wizard.previews.font_title", { font }), - margin, - height * 0.3 - ); + ctx.font = `bold ${titleFontSize}em '${headingFont}'`; + ctx.fillText(I18n.t("wizard.previews.topic_title"), margin, height * 0.3); - const bodyFontSize = height / 220.0; + const bodyFontSize = height / 330.0; ctx.font = `${bodyFontSize}em '${font}'`; let line = 0; const lines = LOREM.split("\n"); - for (let i = 0; i < 4; i++) { + for (let i = 0; i < 5; i++) { line = height * 0.35 + i * lineHeight; ctx.fillText(lines[i], margin + avatarSize + margin, line); } // Share Button ctx.beginPath(); - ctx.rect(margin, line + lineHeight, width * 0.14, height * 0.14); + ctx.rect(margin, line + lineHeight, width * 0.1, height * 0.12); ctx.fillStyle = darkLightDiff(colors.primary, colors.secondary, 90, 65); ctx.fill(); ctx.fillStyle = chooseDarker(colors.primary, colors.secondary); @@ -89,10 +82,10 @@ export default createPreviewComponent(305, 165, { // Reply Button ctx.beginPath(); ctx.rect( - margin * 2 + width * 0.14, + margin + width * 0.12, line + lineHeight, - width * 0.14, - height * 0.14 + width * 0.1, + height * 0.12 ); ctx.fillStyle = colors.tertiary; ctx.fill(); @@ -100,12 +93,12 @@ export default createPreviewComponent(305, 165, { ctx.font = `${bodyFontSize}em '${font}'`; ctx.fillText( I18n.t("wizard.previews.reply_button"), - margin * 2 + width * 0.14 + width / 55, + margin + width * 0.12 + width / 55, line + lineHeight * 1.85 ); // Draw Timeline - const timelineX = width * 0.8; + const timelineX = width * 0.86; ctx.beginPath(); ctx.strokeStyle = colors.tertiary; ctx.lineWidth = 0.5; diff --git a/app/assets/javascripts/wizard/components/font-previews.js b/app/assets/javascripts/wizard/components/font-previews.js deleted file mode 100644 index 65c8d2f4c7a..00000000000 --- a/app/assets/javascripts/wizard/components/font-previews.js +++ /dev/null @@ -1,8 +0,0 @@ -import Component from "@ember/component"; -export default Component.extend({ - actions: { - changed(value) { - this.set("field.value", value); - }, - }, -}); diff --git a/app/assets/javascripts/wizard/components/homepage-preview.js b/app/assets/javascripts/wizard/components/homepage-preview.js index 898ef406e72..8848ebd3176 100644 --- a/app/assets/javascripts/wizard/components/homepage-preview.js +++ b/app/assets/javascripts/wizard/components/homepage-preview.js @@ -21,8 +21,8 @@ export default createPreviewComponent(659, 320, { }; }, - paint(ctx, colors, font, width, height) { - this.drawFullHeader(colors, font); + paint({ ctx, colors, font, width, height }) { + this.drawFullHeader(colors, font, this.logo); if (this.get("step.fieldsById.homepage_style.value") === "latest") { this.drawPills(colors, font, height * 0.15); diff --git a/app/assets/javascripts/wizard/components/image-preview-favicon.js b/app/assets/javascripts/wizard/components/image-preview-favicon.js index 06884b0d687..82b0e95cee0 100644 --- a/app/assets/javascripts/wizard/components/image-preview-favicon.js +++ b/app/assets/javascripts/wizard/components/image-preview-favicon.js @@ -14,7 +14,8 @@ export default createPreviewComponent(371, 124, { return { tab: "/images/wizard/tab.png", image: this.get("field.value") }; }, - paint(ctx, colors, font, width, height) { + paint(options) { + const { ctx, width, height } = options; this.scaleImage(this.tab, 0, 0, width, height); this.scaleImage(this.image, 40, 25, 30, 30); diff --git a/app/assets/javascripts/wizard/components/image-preview-large-icon.js b/app/assets/javascripts/wizard/components/image-preview-large-icon.js index b687d6a5ec0..0d7c86a7d60 100644 --- a/app/assets/javascripts/wizard/components/image-preview-large-icon.js +++ b/app/assets/javascripts/wizard/components/image-preview-large-icon.js @@ -17,7 +17,8 @@ export default createPreviewComponent(325, 125, { }; }, - paint(ctx, colors, font, width, height) { + paint(options) { + const { width, height } = options; this.scaleImage(this.image, 10, 8, 87, 87); this.scaleImage(this.ios, 0, 0, width, height); }, diff --git a/app/assets/javascripts/wizard/components/image-preview-logo-small.js b/app/assets/javascripts/wizard/components/image-preview-logo-small.js index ec18f0fe314..ba55380d159 100644 --- a/app/assets/javascripts/wizard/components/image-preview-logo-small.js +++ b/app/assets/javascripts/wizard/components/image-preview-logo-small.js @@ -13,7 +13,8 @@ export default createPreviewComponent(375, 100, { return { image: this.get("field.value") }; }, - paint(ctx, colors, font, width, height) { + paint(options) { + const { ctx, colors, font, headingFont, width, height } = options; const headerHeight = height / 2; drawHeader(ctx, colors, width, headerHeight); @@ -39,7 +40,8 @@ export default createPreviewComponent(375, 100, { const afterLogo = headerMargin * 1.7 + imageWidth; const fontSize = Math.round(headerHeight * 0.4); - ctx.font = `Bold ${fontSize}px '${font}'`; + + ctx.font = `Bold ${fontSize}px '${headingFont}'`; ctx.fillStyle = colors.primary; const title = LOREM.substring(0, 27); ctx.fillText( diff --git a/app/assets/javascripts/wizard/components/image-preview-logo.js b/app/assets/javascripts/wizard/components/image-preview-logo.js index f5d941789e9..acad28063a2 100644 --- a/app/assets/javascripts/wizard/components/image-preview-logo.js +++ b/app/assets/javascripts/wizard/components/image-preview-logo.js @@ -13,12 +13,13 @@ export default createPreviewComponent(400, 100, { return { image: this.get("field.value") }; }, - paint(ctx, colors, font, width, height) { + paint({ ctx, colors, font, width, height }) { const headerHeight = height / 2; drawHeader(ctx, colors, width, headerHeight); const image = this.image; + const headerMargin = headerHeight * 0.2; const imageHeight = headerHeight - headerMargin * 2; diff --git a/app/assets/javascripts/wizard/components/theme-preview.js b/app/assets/javascripts/wizard/components/theme-preview.js index 8db5dcfb5a9..0abbb21583b 100644 --- a/app/assets/javascripts/wizard/components/theme-preview.js +++ b/app/assets/javascripts/wizard/components/theme-preview.js @@ -35,10 +35,10 @@ export default createPreviewComponent(305, 165, { }; }, - paint(ctx, colors, font, width, height) { + paint({ ctx, colors, font, headingFont, width, height }) { const headerHeight = height * 0.3; - this.drawFullHeader(colors, font); + this.drawFullHeader(colors, headingFont, this.logo); const margin = width * 0.04; const avatarSize = height * 0.2; @@ -57,7 +57,7 @@ export default createPreviewComponent(305, 165, { ctx.beginPath(); ctx.fillStyle = colors.primary; - ctx.font = `bold ${titleFontSize}em '${font}'`; + ctx.font = `bold ${titleFontSize}em '${headingFont}'`; ctx.fillText(I18n.t("wizard.previews.topic_title"), margin, height * 0.3); const bodyFontSize = height / 220.0; diff --git a/app/assets/javascripts/wizard/components/wizard-field-dropdown.js b/app/assets/javascripts/wizard/components/wizard-field-dropdown.js index a3b4bcdc322..3e49cb3561f 100644 --- a/app/assets/javascripts/wizard/components/wizard-field-dropdown.js +++ b/app/assets/javascripts/wizard/components/wizard-field-dropdown.js @@ -1,4 +1,5 @@ import Component from "@ember/component"; + export default Component.extend({ keyPress(e) { e.stopPropagation(); diff --git a/app/assets/javascripts/wizard/controllers/application.js b/app/assets/javascripts/wizard/controllers/application.js index 76192cc6a05..a9f67bbe49e 100644 --- a/app/assets/javascripts/wizard/controllers/application.js +++ b/app/assets/javascripts/wizard/controllers/application.js @@ -1,4 +1,5 @@ import Controller from "@ember/controller"; +import { dasherize } from "@ember/string"; import discourseComputed from "discourse-common/utils/decorators"; export default Controller.extend({ @@ -16,7 +17,9 @@ export default Controller.extend({ return []; } - const fontField = fontsStep.get("fieldsById.font_previews"); - return fontField.choices.map((choice) => `font-${choice.data.class}`); + const fontField = fontsStep.get("fieldsById.body_font"); + return fontField.choices.map( + (choice) => `body-font-${dasherize(choice.id)}` + ); }, }); diff --git a/app/assets/javascripts/wizard/lib/preview.js b/app/assets/javascripts/wizard/lib/preview.js index 90d7fe3cf95..73b4513d224 100644 --- a/app/assets/javascripts/wizard/lib/preview.js +++ b/app/assets/javascripts/wizard/lib/preview.js @@ -93,6 +93,10 @@ export function createPreviewComponent(width, height, obj) { } const font = this.wizard.getCurrentFont(this.fontId); + const headingFont = this.wizard.getCurrentFont( + this.fontId, + "heading_font" + ); if (!font) { return; } @@ -102,7 +106,15 @@ export function createPreviewComponent(width, height, obj) { ctx.fillStyle = colors.secondary; ctx.fillRect(0, 0, width, height); - this.paint(ctx, colors, font, this.width, this.height); + const options = { + ctx, + colors, + font, + headingFont, + width: this.width, + height: this.height, + }; + this.paint(options); // draw border ctx.beginPath(); @@ -142,7 +154,7 @@ export function createPreviewComponent(width, height, obj) { ctx.drawImage(scaled[key], x, y, w, h); }, - drawFullHeader(colors, font) { + drawFullHeader(colors, font, logo) { const { ctx } = this; const headerHeight = height * 0.15; @@ -154,10 +166,16 @@ export function createPreviewComponent(width, height, obj) { const headerMargin = headerHeight * 0.2; const logoHeight = headerHeight - headerMargin * 2; - ctx.beginPath(); - ctx.fillStyle = colors.header_primary; - ctx.font = `bold ${logoHeight}px '${font}'`; - ctx.fillText("Discourse", headerMargin, headerHeight - headerMargin); + const ratio = logoHeight / logo.height; + this.scaleImage( + logo, + headerMargin, + headerMargin, + logo.width * ratio, + logoHeight + ); + + this.scaleImage(logo, width, headerMargin); // Top right menu this.scaleImage( diff --git a/app/assets/javascripts/wizard/models/wizard.js b/app/assets/javascripts/wizard/models/wizard.js index db2f583c210..1d8cbdbd615 100644 --- a/app/assets/javascripts/wizard/models/wizard.js +++ b/app/assets/javascripts/wizard/models/wizard.js @@ -21,7 +21,7 @@ const Wizard = EmberObject.extend({ if (!logoStep) { return; } - return logoStep.get("fieldsById.logo_url.value"); + return logoStep.get("fieldsById.logo.value"); }, // A bit clunky, but get the current colors from the appropriate step @@ -54,13 +54,13 @@ const Wizard = EmberObject.extend({ return option.data.colors; }, - getCurrentFont(fontId) { + getCurrentFont(fontId, type = "body_font") { const fontsStep = this.steps.findBy("id", "fonts"); if (!fontsStep) { return; } - const fontChoice = fontsStep.get("fieldsById.font_previews"); + const fontChoice = fontsStep.get(`fieldsById.${type}`); if (!fontChoice) { return; } @@ -80,7 +80,7 @@ const Wizard = EmberObject.extend({ return; } - return option.data.name; + return option.label; }, }); diff --git a/app/assets/javascripts/wizard/templates/components/font-previews.hbs b/app/assets/javascripts/wizard/templates/components/font-previews.hbs deleted file mode 100644 index 623118246a0..00000000000 --- a/app/assets/javascripts/wizard/templates/components/font-previews.hbs +++ /dev/null @@ -1,14 +0,0 @@ -