Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add default color hex support (#195) #197

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ function DefaultColorExample() {
}
```

### Use default color as hex

Append `Hex` to the icon name to use the default color as hex string

```jsx
import { SiReact, SiReactHex } from '@icons-pack/react-simple-icons';

function DefaultColorExample() {
return <SiReact color={SiReactHex} size={24} />;
}
```

## Custom styles

```jsx
Expand Down
9 changes: 5 additions & 4 deletions scripts/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ const iconComponenteTemplate = (componentName, title, colorHex, path) => {
size?: string | number;
}

const defaultColor = '${colorHex}';

const ${componentName}: IconType = React.forwardRef<SVGSVGElement, ${componentName}Props>(function ${componentName}({title = '${title}', color = 'currentColor', size = 24, ...others }, ref) {
if (color === 'default') {
color = '${colorHex}';
color = defaultColor;
}

return (
Expand All @@ -48,15 +50,14 @@ const iconComponenteTemplate = (componentName, title, colorHex, path) => {
);
});

export default ${componentName};

export { ${componentName} as default, defaultColor };
`;
};

/**
The single line for exporting component in `src/index.ts`.
*/
const iconExportTemplate = (componentName) => `export { default as ${componentName} } from './icons/${componentName}';`;
const iconExportTemplate = (componentName) => `export { default as ${componentName}, defaultColor as ${componentName}Hex } from './icons/${componentName}';`;


module.exports = {
Expand Down
Loading
Loading