@gisce/react-ooui 1.2.0-rc.35 → 1.2.0-rc.37

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.2.0-rc.35",
3
+ "version": "1.2.0-rc.37",
4
4
  "files": [
5
5
  "dist",
6
6
  "src",
@@ -2,14 +2,29 @@ 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
+ })
19
+ test("should return gtk-go", () => {
20
+ const findAndReplaceIcon = Icons.FileSearchOutlined;
21
+ const icon = iconMapper("gtk-find-and-replace");
22
+ expect(icon).toBe(findAndReplaceIcon);
23
+ })
24
+ describe("If key doesn't exist in iconMapper", () => {
25
+ test("should return undefined", () => {
26
+ const icon = iconMapper("gtk-foo-bar");
27
+ expect(icon).toBe(undefined);
28
+ })
29
+ })
15
30
  });
@@ -163,9 +163,24 @@ function TreeActionBar(props: Props) {
163
163
  }
164
164
  }}
165
165
  />
166
+ {!treeExpandable && (
167
+ <ButtonWithBadge
168
+ icon={
169
+ <FilterOutlined
170
+ style={{ color: searchVisible ? "white" : undefined }}
171
+ />
172
+ }
173
+ tooltip={t("advanced_search")}
174
+ type={searchVisible ? "primary" : "default"}
175
+ onClick={() => {
176
+ setSearchVisible?.(!searchVisible);
177
+ }}
178
+ disabled={duplicatingItem || removingItem || treeIsLoading}
179
+ badgeNumber={searchParams?.length}
180
+ />
181
+ )}
166
182
  {separator()}
167
183
  <NewButton disabled={treeIsLoading} />
168
- {separator()}
169
184
  <ActionButton
170
185
  icon={<CopyOutlined />}
171
186
  tooltip={t("duplicate")}
@@ -191,22 +206,6 @@ function TreeActionBar(props: Props) {
191
206
  {separator()}
192
207
  </>
193
208
  )}
194
- {!treeExpandable && (
195
- <ButtonWithBadge
196
- icon={
197
- <FilterOutlined
198
- style={{ color: searchVisible ? "white" : undefined }}
199
- />
200
- }
201
- tooltip={t("advanced_search")}
202
- type={searchVisible ? "primary" : "default"}
203
- onClick={() => {
204
- setSearchVisible?.(!searchVisible);
205
- }}
206
- disabled={duplicatingItem || removingItem || treeIsLoading}
207
- badgeNumber={searchParams?.length}
208
- />
209
- )}
210
209
  <ActionButton
211
210
  icon={<InfoCircleOutlined />}
212
211
  tooltip={t("showLogs")}
@@ -100,22 +100,21 @@ const iconMapping: { [key: string]: string } = {
100
100
  STOCK_PREFERENCES: "Setting",
101
101
  };
102
102
 
103
- export default (key: string) => {
103
+ export default (key: string, className?: any) => {
104
104
  if (key.indexOf("gtk-") !== -1) {
105
- const rootIcon = key.replace("gtk-", "").replace("-", "_");
106
- const newKey = `STOCK_${rootIcon.toUpperCase()}`;
107
- return getIconForKey(iconMapping[newKey]);
105
+ const rootIcon = key.replace("gtk-", "").replace(/\-/g, "_");
106
+ key = `STOCK_${rootIcon.toUpperCase()}`;
108
107
  }
109
108
 
110
109
  if (iconMapping.hasOwnProperty(key)) {
111
- return getIconForKey(iconMapping[key]);
110
+ return getIconForKey(iconMapping[key], className);
112
111
  }
113
112
 
114
- return getIconForKey(key);
113
+ return getIconForKey(key, className);
115
114
  };
116
115
 
117
- function getIconForKey(key: string) {
118
- const IconCamelCase = `${key
116
+ function toCamelCase(key: string): string {
117
+ return `${key
119
118
  .split("-")
120
119
  .map((word) =>
121
120
  word.replace(
@@ -124,10 +123,20 @@ function getIconForKey(key: string) {
124
123
  )
125
124
  )
126
125
  .join("")}`;
126
+ }
127
+
128
+ function getIconForKey(key: string, className?: any) {
129
+ let IconCamelCase = key.charAt(0).toUpperCase() + key.slice(1); // Capitalize first letter
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]) {
130
- return AntIcons[antKey];
136
+ return () =>
137
+ React.createElement(AntIcons[antKey] as any, {
138
+ className,
139
+ });
131
140
  }
132
141
 
133
142
  const tablerKey: TablerKey = `Icon${IconCamelCase}` as any;
@@ -141,6 +150,7 @@ function getIconForKey(key: string) {
141
150
  const CustomIcon = () =>
142
151
  React.createElement(Icon, {
143
152
  component: TablerIcon,
153
+ className,
144
154
  });
145
155
  return CustomIcon;
146
156
  }