mirror of
https://github.com/discourse/discourse.git
synced 2025-02-09 04:44:59 +00:00
This commit refactors the Wizard component code in preparation for moving it to the 'static' directory for Embroider route-splitting. It also includes a number of general improvements and simplifications. Extracted from https://github.com/discourse/discourse/pull/23678 Co-authored-by: Godfrey Chan <godfreykfc@gmail.com>
51 lines
1.1 KiB
JavaScript
51 lines
1.1 KiB
JavaScript
import { action } from "@ember/object";
|
|
import { drawHeader } from "../../../lib/preview";
|
|
import PreviewBaseComponent from "../styling-preview/-preview-base";
|
|
|
|
export default PreviewBaseComponent.extend({
|
|
width: 400,
|
|
height: 100,
|
|
image: null,
|
|
|
|
didInsertElement() {
|
|
this._super(...arguments);
|
|
this.field.addListener(this.imageChanged);
|
|
},
|
|
|
|
willDestroyElement() {
|
|
this._super(...arguments);
|
|
this.field.removeListener(this.imageChanged);
|
|
},
|
|
|
|
@action
|
|
imageChanged() {
|
|
this.reload();
|
|
},
|
|
|
|
images() {
|
|
return { image: this.field.value };
|
|
},
|
|
|
|
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;
|
|
const ratio = imageHeight / image.height;
|
|
this.scaleImage(
|
|
image,
|
|
headerMargin,
|
|
headerMargin,
|
|
image.width * ratio,
|
|
imageHeight
|
|
);
|
|
|
|
this.drawPills(colors, font, height / 2);
|
|
},
|
|
});
|