Skip to content

Commit

Permalink
Merge pull request #276 from gisce/unify-icon-styles
Browse files Browse the repository at this point in the history
Add className as parameter for iconMapper in order to unify styling
  • Loading branch information
mguellsegarra authored Mar 31, 2023
2 parents 6de7142 + d483545 commit b275d70
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gisce/react-ooui",
"version": "1.1.30",
"version": "1.1.31",
"files": [
"dist",
"src",
Expand Down
14 changes: 9 additions & 5 deletions src/helpers/iconMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ const iconMapping: { [key: string]: string } = {
STOCK_PREFERENCES: "Setting",
};

export default (key: string) => {
export default (key: string, className?: any) => {
if (key.indexOf("gtk-") !== -1) {
const rootIcon = key.replace("gtk-", "").replace(/\-/g, "_");
key = `STOCK_${rootIcon.toUpperCase()}`;
}

if (iconMapping.hasOwnProperty(key)) {
return getIconForKey(iconMapping[key]);
return getIconForKey(iconMapping[key], className);
}

return getIconForKey(key);
return getIconForKey(key, className);
};

function toCamelCase(key: string): string {
Expand All @@ -125,15 +125,18 @@ function toCamelCase(key: string): string {
.join("")}`;
}

function getIconForKey(key: string) {
function getIconForKey(key: string, className?: any) {
let IconCamelCase = key.charAt(0).toUpperCase() + key.slice(1); // Capitalize first letter
if (IconCamelCase.indexOf("-") !== -1) {
IconCamelCase = toCamelCase(IconCamelCase);
}

const antKey: AntKey = `${IconCamelCase}Outlined` as any;
if (AntIcons[antKey]) {
return AntIcons[antKey];
return () =>
React.createElement(AntIcons[antKey] as any, {
className,
});
}

const tablerKey: TablerKey = `Icon${IconCamelCase}` as any;
Expand All @@ -147,6 +150,7 @@ function getIconForKey(key: string) {
const CustomIcon = () =>
React.createElement(Icon, {
component: TablerIcon,
className,
});
return CustomIcon;
}
Expand Down

0 comments on commit b275d70

Please sign in to comment.