Skip to content

Commit

Permalink
feat: generate SVG types
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadsammy committed Jun 25, 2020
1 parent b7c3c6f commit 3ce6d80
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
14 changes: 14 additions & 0 deletions src/generation/ClassesGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Typography as defaultTypography } from '../classes/Typography';
import { Transitions as defaultTransitions } from '../classes/Transitions';
import { Transforms as defaultTransforms } from '../classes/Transforms';
import { Interactivity as defaultInteractivity } from '../classes/Interactivity';
import { SVG as defaultSVG } from '../classes/SVG';
import isEmpty from 'lodash.isempty';

export class ClassesGenerator implements IClassesGenerator {
Expand Down Expand Up @@ -152,6 +153,19 @@ export class ClassesGenerator implements IClassesGenerator {
return new ClassesGroupTemplateGenerator(Interactivity, 'Interactivity', this.configScanner.prefix).generate();
};

public SVG = (): string => {
const SVG = {
...defaultSVG,
fill: Object.keys(this.configScanner.themeConfig.fill).map(value => 'fill-' + value),
stroke: Object.keys(this.configScanner.themeConfig.stroke).map(value => 'stroke-' + value),
strokeWidth: Object.keys(this.configScanner.themeConfig.strokeWidth).map(value => 'stroke-' + value),
};

this.allGeneratedClasses.SVG = SVG;

return new ClassesGroupTemplateGenerator(SVG, 'SVG', this.configScanner.prefix).generate();
};

public flexBox = (): string => {
const FlexBox = {
...defaultFlexBox,
Expand Down
2 changes: 1 addition & 1 deletion src/generation/IGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface IClassesGenerator {
interactivity: () => string;
// layout: () => string;
// sizing: () => string;
// SVG: () => string;
SVG: () => string;
transforms: () => string;
typography: () => string;
}
2 changes: 1 addition & 1 deletion src/generation/createFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export function createFileWithGeneratedTypes(options: Options): void {
? `import {${customClassesTypeName} as TCustomClassesFromExternalFile} from './${customClassesFilename}';`
: '';

// prettier-ignore
const result = baseTemplateString
.replace(/_PREFIX_/g, prefix)
.replace(/_SEPARATOR_/g, separator)
Expand All @@ -73,6 +72,7 @@ export function createFileWithGeneratedTypes(options: Options): void {
.replace(/___TRANSITIONS___/g, classesGenerator.transitions)
.replace(/___TRANSFORMS___/g, classesGenerator.transforms)
.replace(/___INTERACTIVITY___/g, classesGenerator.interactivity)
.replace(/___SVG___/g, classesGenerator.SVG)

.replace(/MAX_WIDTH_BY_BREAKPOINTS/g, generateTypes(classesGenerator.getGeneratedMaxWidthByBreakpointsClasses()))
.replace(/WIDTH_SPACINGS/g, generateTypes(classesGenerator.getGeneratedClassesWithSpacing().widths, prefix))
Expand Down
8 changes: 1 addition & 7 deletions src/generation/utils/baseTemplateString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,7 @@ ___TRANSFORMS___
___INTERACTIVITY___
export type TFill = '_PREFIX_fill-current';
export type TStroke = '_PREFIX_stroke-current';
export type TStrokeWidth = '_PREFIX_stroke-0' | '_PREFIX_stroke-1' | '_PREFIX_stroke- 2';
export type TSvg = TFill | TStroke | TStrokeWidth;
___SVG___
export type TScreenReaders = '_PREFIX_sr-only' | '_PREFIX_not-sr-only';
Expand Down

0 comments on commit 3ce6d80

Please sign in to comment.