Skip to content

Commit

Permalink
feat: The fontSize config support boolean settings. (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 9, 2023
1 parent d399a7f commit 4ac523e
Show file tree
Hide file tree
Showing 19 changed files with 24 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"svgtofont": {
"css": {
"fontSize": "12px"
"fontSize": false
}
},
"keywords": [
Expand Down
7 changes: 4 additions & 3 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function buildPathsObject(files: string[], options: SvgToFontOptions = {})

const reactSource = (name: string, size: string, fontName: string, source: string) => `import React from 'react';
export const ${name} = props => (
<svg viewBox="0 0 20 20" width="${size}" height="${size}" {...props} className={\`${fontName} \${props.className ? props.className : ''}\`}>${source}</svg>
<svg viewBox="0 0 20 20" ${size ? `width="${size}" height="${size}"` : ''} {...props} className={\`${fontName} \${props.className ? props.className : ''}\`}>${source}</svg>
);
`;

Expand All @@ -66,8 +66,9 @@ export async function generateReactIcons(options: SvgToFontOptions = {}) {
}

async function outputReactFile(files: string[], options: SvgToFontOptions = {}) {
const svgoOptions = options.svgoOptions || {}
const fontSize = options.css && typeof options.css !== 'boolean' && options.css.fontSize ? options.css.fontSize : '16px';
const svgoOptions = options.svgoOptions || {};
const fontSizeOpt = typeof options.css !== 'boolean' && options.css.fontSize
const fontSize = typeof fontSizeOpt === 'boolean' ? (fontSizeOpt === true ? '16px' : '') : fontSizeOpt;
const fontName = options.classNamePrefix || options.fontName
return Promise.all(
files.map(async filepath => {
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ export default async (options: SvgToFontOptions = {}) => {
options.svgicons2svgfont.fontName = options.fontName;
options.classNamePrefix = options.classNamePrefix || options.fontName;

const fontSize = options.css && typeof options.css !== 'boolean' && options.css.fontSize ? options.css.fontSize : '16px';
const fontSizeOpt = typeof options.css !== 'boolean' && options.css.fontSize;
const fontSize = typeof fontSizeOpt === 'boolean' ? (fontSizeOpt === true ? 'font-size: 16px;' : '') : `font-size: ${fontSizeOpt};`;
console.log('options:fontSize:', fontSize)
// If you generate a font you need to generate a style.
if (options.website && !options.css) options.css = true;

Expand Down
3 changes: 1 addition & 2 deletions src/ligature-styles/_{{filename}}.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
}

.{{prefix}} {
font-family: '{{fontname}}' !important;
font-size:{{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
3 changes: 1 addition & 2 deletions src/ligature-styles/_{{filename}}.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
}

.{{prefix}} {
font-family: '{{fontname}}' !important;
font-size: {{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
3 changes: 1 addition & 2 deletions src/ligature-styles/_{{filename}}.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
}

.{{prefix}} {
font-family: '{{fontname}}' !important;
font-size:{{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
3 changes: 1 addition & 2 deletions src/ligature-styles/_{{filename}}.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
}

.{{prefix}} {
font-family: '{{fontname}}' !important;
font-size: {{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
3 changes: 1 addition & 2 deletions src/ligature-styles/_{{filename}}.styl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
}

.{{prefix}} {
font-family: '{{fontname}}' !important;
font-size: {{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
3 changes: 1 addition & 2 deletions src/styles/_{{filename}}.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
}

[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;
font-size:{{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
3 changes: 1 addition & 2 deletions src/styles/_{{filename}}.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
}

[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;
font-size: {{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
3 changes: 1 addition & 2 deletions src/styles/_{{filename}}.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
}

[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;
font-size:{{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
3 changes: 1 addition & 2 deletions src/styles/_{{filename}}.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
}

[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;
font-size: {{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
3 changes: 1 addition & 2 deletions src/styles/_{{filename}}.styl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
}

[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;
font-size: {{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export type CSSOptions = {
/**
* Setting font size.
*/
fontSize?: string;
fontSize?: string | boolean;
/**
* Set the path in the css file
* https://github.com/jaywcjlove/svgtofont/issues/48#issuecomment-739547189
Expand Down
3 changes: 1 addition & 2 deletions test/templates/styles/_{{filename}}.css.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
}

[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;
font-size:{{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
3 changes: 1 addition & 2 deletions test/templates/styles/_{{filename}}.less.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
}

[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;
font-size: {{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
3 changes: 1 addition & 2 deletions test/templates/styles/_{{filename}}.module.less.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
}

[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;
font-size:{{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
3 changes: 1 addition & 2 deletions test/templates/styles/_{{filename}}.scss.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
}

[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;
font-size: {{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down
3 changes: 1 addition & 2 deletions test/templates/styles/_{{filename}}.styl.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
}

[class^="{{prefix}}-"], [class*=" {{prefix}}-"] {
font-family: '{{fontname}}' !important;
font-size: {{fontSize}};
font-family: '{{fontname}}' !important;{{fontSize}}
font-style:normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
Expand Down

0 comments on commit 4ac523e

Please sign in to comment.