discourse/app/assets/javascripts/wizard/components/image-preview-logo.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
838 B
JavaScript
Raw Normal View History

import { createPreviewComponent, drawHeader } from "wizard/lib/preview";
import { observes } from "discourse-common/utils/decorators";
2016-09-16 16:12:56 -04:00
export default createPreviewComponent(400, 100, {
image: null,
@observes("field.value")
imageChanged() {
this.reload();
},
images() {
return { image: this.get("field.value") };
2016-09-16 16:12:56 -04:00
},
paint({ ctx, colors, font, width, height }) {
2016-09-16 16:12:56 -04:00
const headerHeight = height / 2;
drawHeader(ctx, colors, width, headerHeight);
const image = this.image;
2016-09-16 16:12:56 -04:00
const headerMargin = headerHeight * 0.2;
const imageHeight = headerHeight - headerMargin * 2;
const ratio = imageHeight / image.height;
this.scaleImage(
image,
headerMargin,
headerMargin,
image.width * ratio,
imageHeight
);
2016-09-16 16:12:56 -04:00
this.drawPills(colors, font, height / 2);
2016-09-16 16:12:56 -04:00
},
});