Skip to content

Commit

Permalink
feat: enable variants extention (resolves #102)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadsammy committed Jan 7, 2021
1 parent e501fc5 commit 380e5d7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/cli/core/ConfigScanner.ts
Expand Up @@ -57,7 +57,28 @@ export class ConfigScanner {
return this._themeConfig;
};

public getVariants = (): TConfigVariants => this._variantsConfig;
public getVariants = (): Omit<TConfigVariants, 'extend'> => {
// Get the `variants.extend` object
const variantsConfigExtend = this._variantsConfig?.extend;

// If the variants.extend exists...
if (!!variantsConfigExtend) {
//Return the result of merging the variants with extend
return _.mergeWith(
this._variantsConfig,
variantsConfigExtend,
(variantsValues, variantsExtendValues) => {
if (_.isArray(variantsValues)) {
return variantsValues.concat(variantsExtendValues);
}
},
);
// Otherwise...
} else {
// Return the variants
return this._variantsConfig;
}
};

public getThemeProperty = (
themeProperty: keyof TThemeItems,
Expand Down
4 changes: 3 additions & 1 deletion src/cli/lib/types/config.ts
Expand Up @@ -8,6 +8,8 @@ export type TConfigDarkMode = false | 'media' | 'class';

export type TConfigTheme = TThemeItems & {extend?: TThemeItems};

export type TConfigVariants = typeof defaultTailwindConfig.variants;
export type TConfigVariants = TVariantsItems & {extend?: Partial<TVariantsItems>};

export type TThemeItems = typeof defaultTailwindConfig.theme;

type TVariantsItems = typeof defaultTailwindConfig.variants;

0 comments on commit 380e5d7

Please sign in to comment.