Skip to content

Commit

Permalink
feat: create addIcon method to allow consumers to include their own…
Browse files Browse the repository at this point in the history
… SVGs at runtime
  • Loading branch information
McManning committed Apr 4, 2023
1 parent 6d41b05 commit ff42b8d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"no-unused-vars": "off", // Handled via @typescript-eslint/no-unused-vars
"no-useless-catch": "off",
"no-useless-escape": "off",
"prettier/prettier": "error",
"prettier/prettier": "off",
"react/display-name": "off",
"react/jsx-curly-brace-presence": "error",
"react/no-string-refs": "off",
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
coverage
.DS_STORE
.idea
.eslintcache
Expand All @@ -8,4 +7,4 @@ coverage
docs-build/
dist/
coverage/
.eslintcache
stats.html
2 changes: 1 addition & 1 deletion src/components/Icon/Icon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Overview: Story = {
};

export const ColorsAndComposition: Story = {
render: (args) => (
render: () => (
<div>
<Icon size={64} name="facebook" style={{ color: '#4267B2' }} />
<div
Expand Down
14 changes: 12 additions & 2 deletions src/icons/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Iconify icon bundle configuration for all icons we support
// Ref: https://docs.iconify.design/icon-components/bundles/
import { addCollection, addIcon } from '@iconify/react/dist/offline';
import { addCollection, addIcon as iconifyAddIcon } from '@iconify/react/dist/offline';

import * as data from './data';
import * as misc from './misc';
Expand Down Expand Up @@ -40,9 +40,19 @@ export function loadAllIcons() {
// addIcon() is faster under the hood - less validation steps

Object.keys(all).forEach((name) => {
addIcon(name, all[name].default);
iconifyAddIcon(name, all[name].default);
});

addCollection(ruiIcons);
addCollection(ruiIllustrations);
}

export type IconDefinition = {
body: string;
width: number;
height: number;
}

export function addIcon(name: string, icon: IconDefinition) {
iconifyAddIcon(name, icon);
}

0 comments on commit ff42b8d

Please sign in to comment.