@gisce/react-ooui 1.1.26 → 1.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/react-ooui",
3
- "version": "1.1.26",
3
+ "version": "1.1.27",
4
4
  "files": [
5
5
  "dist",
6
6
  "src",
@@ -2,14 +2,18 @@ import iconMapper from "../helpers/iconMapper";
2
2
  import * as Icons from "@ant-design/icons";
3
3
 
4
4
  describe("A IconMapper instance", () => {
5
- test("should return the default icon when key not found", () => {
6
- const defaultIcon = Icons.RightOutlined;
7
- const icon = iconMapper("RANDOM_KEY");
8
- expect(icon).toBe(defaultIcon);
5
+ test("should return undefined when key not found", () => {
6
+ const icon = iconMapper("foo-bar");
7
+ expect(icon).toBe(undefined);
9
8
  });
10
9
  test("should return proper help icon when requested", () => {
11
10
  const helpIcon = Icons.QuestionOutlined;
12
- const icon = iconMapper("STOCK_HELP");
11
+ const icon = iconMapper("gtk-help");
13
12
  expect(icon).toBe(helpIcon);
14
13
  });
14
+ test("should replace all - for _", () => {
15
+ const findAndReplaceIcon = Icons.FileSearchOutlined;
16
+ const icon = iconMapper("gtk-find-and-replace");
17
+ expect(icon).toBe(findAndReplaceIcon);
18
+ })
15
19
  });
@@ -102,7 +102,7 @@ const iconMapping: { [key: string]: string } = {
102
102
 
103
103
  export default (key: string) => {
104
104
  if (key.indexOf("gtk-") !== -1) {
105
- const rootIcon = key.replace("gtk-", "").replace("-", "_");
105
+ const rootIcon = key.replace("gtk-", "").replace(/\-/g, "_");
106
106
  const newKey = `STOCK_${rootIcon.toUpperCase()}`;
107
107
  return getIconForKey(iconMapping[newKey]);
108
108
  }
@@ -114,8 +114,8 @@ export default (key: string) => {
114
114
  return getIconForKey(key);
115
115
  };
116
116
 
117
- function getIconForKey(key: string) {
118
- const IconCamelCase = `${key
117
+ function toCamelCase(key: string) : string {
118
+ return `${key
119
119
  .split("-")
120
120
  .map((word) =>
121
121
  word.replace(
@@ -124,6 +124,12 @@ function getIconForKey(key: string) {
124
124
  )
125
125
  )
126
126
  .join("")}`;
127
+ }
128
+
129
+ function getIconForKey(IconCamelCase: string) {
130
+ if (IconCamelCase.indexOf("-") !== -1) {
131
+ IconCamelCase = toCamelCase(IconCamelCase);
132
+ }
127
133
 
128
134
  const antKey: AntKey = `${IconCamelCase}Outlined` as any;
129
135
  if (AntIcons[antKey]) {