Skip to content

Commit

Permalink
feat: implement max/min srcset widths
Browse files Browse the repository at this point in the history
  • Loading branch information
frederickfogerty committed May 1, 2020
1 parent fca264b commit 2e38068
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
19 changes: 16 additions & 3 deletions src/plugins/vue-imgix/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import ImgixClient from 'imgix-core-js';

export type IImgixParams = {};

export type IBuildSrcSetOptions = Parameters<
ImgixClient['buildSrcSet']
>[2] & {};
export type IBuildUrlOptions = {};
export type IBuildUrlObjectOptions = IBuildSrcSetOptions & IBuildUrlOptions;

export interface IImgixClientOptions {
domain: string;
includeLibraryParam?: boolean;
Expand All @@ -12,12 +20,17 @@ export interface IBuildUrlObjectResult {
}
export type IBuildUrlObject = (
url: string,
options?: IImgixParams,
ixParams?: IImgixParams,
options?: IBuildUrlObjectOptions,
) => IBuildUrlObjectResult;

export type IBuildUrl = (url: string, options?: IImgixParams) => string;
export type IBuildUrl = (url: string, ixParams?: IImgixParams) => string;

export type IBuildSrcSet = (url: string, options?: IImgixParams) => string;
export type IBuildSrcSet = (
url: string,
ixParams?: IImgixParams,
options?: IBuildSrcSetOptions,
) => string;

export interface IVueImgixClient {
buildUrlObject: IBuildUrlObject;
Expand Down
18 changes: 15 additions & 3 deletions src/plugins/vue-imgix/vue-imgix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import ImgixClient from 'imgix-core-js';
import { IxImg } from './component';
import {
IBuildSrcSet,
IBuildSrcSetOptions,
IBuildUrl,
IBuildUrlObject,
IBuildUrlObjectOptions,
IBuildUrlObjectResult,
IImgixClientOptions,
IImgixParams,
Expand Down Expand Up @@ -44,9 +46,15 @@ class VueImgixClient implements IVueImgixClient {
buildUrlObject = (
url: string,
ixParams?: IImgixParams,
options: IBuildUrlObjectOptions = {},
): IBuildUrlObjectResult => {
const { widths, ...sharedOptions } = options;

const src = this.buildUrl(url, ixParams);
const srcset = this.buildSrcSet(url, ixParams);
const srcset = this.buildSrcSet(url, ixParams, {
widths,
...sharedOptions,
});

return { src, srcset };
};
Expand All @@ -55,8 +63,12 @@ class VueImgixClient implements IVueImgixClient {
return this.client.buildURL(url, this.buildIxParams(ixParams));
};

buildSrcSet = (url: string, ixParams?: IImgixParams): string => {
return this.client.buildSrcSet(url, this.buildIxParams(ixParams));
buildSrcSet = (
url: string,
ixParams?: IImgixParams,
options?: IBuildSrcSetOptions,
): string => {
return this.client.buildSrcSet(url, this.buildIxParams(ixParams), options);
};
}

Expand Down

0 comments on commit 2e38068

Please sign in to comment.