Skip to content

Commit

Permalink
feat: implement attribute mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
frederickfogerty committed May 1, 2020
1 parent 8c13da5 commit 74d1c08
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/plugins/vue-imgix/ix-img.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {
ensureVueImgixClientSingleton,
IVueImgixClient,
} from '@/plugins/vue-imgix/vue-imgix';
import Vue, { CreateElement } from 'vue';
import Component from 'vue-class-component';
import { ensureVueImgixClientSingleton, IVueImgixClient } from '@/plugins/vue-imgix/vue-imgix';

const IxImgProps = Vue.extend({
props: {
Expand All @@ -11,9 +14,15 @@ const IxImgProps = Vue.extend({
imgixParams: Object,
width: [String, Number],
height: [String, Number],
attributeConfig: Object,
},
});

const defaultAttributeMap = {
src: 'src',
srcset: 'srcset',
};

@Component
export class IxImg extends IxImgProps {
// Using !: here because we ensure it is set in created()
Expand All @@ -34,10 +43,17 @@ export class IxImg extends IxImgProps {
...this.imgixParams,
});

console.log('typeof this.attributeConfig', typeof this.attributeConfig);
console.log('this.attributeConfig', this.attributeConfig);
const attributeConfig = {
...defaultAttributeMap,
...this.attributeConfig,
};

return createElement('img', {
attrs: {
src,
srcset,
[attributeConfig.src]: src,
[attributeConfig.srcset]: srcset,
width: this.width,
height: this.height,
},
Expand Down

0 comments on commit 74d1c08

Please sign in to comment.