diff --git a/README.md b/README.md index 97c5d60e..97accc29 100644 --- a/README.md +++ b/README.md @@ -92,12 +92,23 @@ function ChangeTitle() { } ``` +## Use default color + +Set color as `default` to use the default color for each icon + +```jsx +import { ReactJs } from '@icons-pack/react-simple-icons'; + +function DefaultColorExample() { + return ; +} +``` + ## Custom styles ```jsx import { ReactJs } from '@icons-pack/react-simple-icons'; -// title default "React" function CustomStyles() { return ; } diff --git a/scripts/generate-components.js b/scripts/generate-components.js index fb4d7d09..12b042c9 100644 --- a/scripts/generate-components.js +++ b/scripts/generate-components.js @@ -38,7 +38,7 @@ Promise.all( return fsPromise.writeFile( componentFilePath, - iconFileTemplate(componentName, baseName, simpleIcons[baseName].path), + iconFileTemplate(componentName, baseName, `#${simpleIcons[baseName].hex}`, simpleIcons[baseName].path), formatFile, ); }), diff --git a/scripts/templates.js b/scripts/templates.js index a92f2c2e..5b10c202 100644 --- a/scripts/templates.js +++ b/scripts/templates.js @@ -1,8 +1,8 @@ /** This icon component file as `src/components/[componentName].ts`. */ -const iconFileTemplate = (componentName, baseName, path) => `import baseIcon from '../base'; -const ${componentName} = baseIcon('${baseName}', '${path}'); +const iconFileTemplate = (componentName, baseName, hex, path) => `import baseIcon from '../base'; +const ${componentName} = baseIcon('${baseName}', '${hex}', '${path}'); export default ${componentName};\n`; /** diff --git a/src/base.tsx b/src/base.tsx index 5b1e7f22..453a298b 100644 --- a/src/base.tsx +++ b/src/base.tsx @@ -1,11 +1,14 @@ import * as React from 'react'; import { IconProps, IconType } from './types'; -const baseIcon = (iconTitle: string, iconPath: string): IconType => +const baseIcon = (iconTitle: string, hex: string, iconPath: string): IconType => React.forwardRef(function( { title = iconTitle, color = 'currentColor', size = 24, ...others }, ref, ) { + if (color === 'default') { + color = hex; + } return ( & { /** - * Hex color or color name + * The title provides an accessible short text description to the SVG */ title?: string; /** - * The size of the Icon. + * Hex color or color name or `default` to use the default hex for each icon */ color?: string; /** - * The title provides an accessible short text description to the SVG + * The size of the Icon. */ size?: string | number; };