@topconsultnpm/sdkui-react-beta 6.15.24 → 6.15.26

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.
@@ -1,41 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import TMTooltip from './TMTooltip';
3
+ import { extractInitialsFromName, getAvatarColor } from '../../helper';
3
4
  const TMUserAvatar = (props) => {
4
5
  const { displayName, nameForColorCalculation, tooltipName, returnType } = props;
5
- // Helper function to generate dark color from name
6
- const generateDarkColorFromName = (str) => {
7
- let hash = 0;
8
- for (let i = 0; i < str.length; i++) {
9
- hash = str.charCodeAt(i) + ((hash << 5) - hash);
10
- }
11
- const hue = Math.floor((hash & 0x00FFFFFF) / 0x10000);
12
- let colorRange;
13
- if (hue >= 0 && hue < 30)
14
- colorRange = 0; // Dark red
15
- else if (hue >= 30 && hue < 90)
16
- colorRange = 60; // Dark orange to yellow
17
- else if (hue >= 90 && hue < 150)
18
- colorRange = 120; // Dark green
19
- else if (hue >= 150 && hue < 210)
20
- colorRange = 180; // Dark cyan
21
- else if (hue >= 210 && hue < 270)
22
- colorRange = 240; // Dark blue
23
- else if (hue >= 270 && hue < 330)
24
- colorRange = 300; // Dark purple
25
- else
26
- colorRange = 360; // Dark magenta
27
- return `hsl(${colorRange}, 70%, 30%)`; // Dark color
28
- };
29
- // Helper function to extract initials from name
30
- const extractInitialsFromName = (name) => {
31
- if (name.length >= 2) {
32
- const lettersOnly = name.replace(/[^a-zA-Z]/g, '');
33
- return lettersOnly.substring(0, 3).toUpperCase();
34
- }
35
- return name[0].toUpperCase();
36
- };
37
6
  const initials = extractInitialsFromName(displayName ?? '-');
38
- const bgColor = generateDarkColorFromName(nameForColorCalculation ?? '-');
7
+ const bgColor = getAvatarColor(nameForColorCalculation ?? '-');
39
8
  if (returnType === 'svg') {
40
9
  return `
41
10
  <svg width="30" height="30" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg">
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import styled from "styled-components";
3
3
  import { SDK_Globals } from "@topconsultnpm/sdk-ts-beta";
4
- import { formatBytes, getFileIcon, IconAttachment, IconCADossier, IconMenuCAWorkingGroups, SDKUI_Localizator } from "../../helper";
4
+ import { extractInitialsFromName, formatBytes, getAvatarColor, getFileIcon, IconAttachment, IconCADossier, IconMenuCAWorkingGroups, SDKUI_Localizator } from "../../helper";
5
5
  import TMTooltip from "../base/TMTooltip";
6
6
  import { DownloadTypes } from '../../ts';
7
7
  import { TMColors } from '../../utils/theme';
@@ -178,57 +178,11 @@ export const AttachmentElement = (attachment, treeFs, draftLatestInfoMap, archiv
178
178
  }, children: _jsxs("div", { style: { alignItems: 'center', display: 'flex' }, children: [fileExt ? _jsx("span", { style: { marginRight: "10px" }, children: getFileIcon(fileExt, undefined, tooltipContent) }) : _jsx(IconAttachment, { style: { marginRight: "5px" } }), _jsx("span", { children: nameElement })] }) }, attachment.did);
179
179
  };
180
180
  export const OwnerInitialsBadge = (blogPost) => {
181
- const generateDarkColorFromName = (str) => {
182
- // Create a hash of the string
183
- let hash = 0;
184
- for (let i = 0; i < str.length; i++) {
185
- hash = str.charCodeAt(i) + ((hash << 5) - hash);
186
- }
187
- // Convert the hash to a color (ensure it's within RGB range)
188
- const hue = Math.floor((hash & 0x00FFFFFF) / 0x10000);
189
- // Define color ranges for dark red, green, yellow, and others
190
- let colorRange;
191
- if (hue >= 0 && hue < 30) { // Dark red
192
- colorRange = 0; // Red hue
193
- }
194
- else if (hue >= 30 && hue < 90) { // Dark orange to yellow
195
- colorRange = 60; // Yellow hue
196
- }
197
- else if (hue >= 90 && hue < 150) { // Dark green
198
- colorRange = 120; // Green hue
199
- }
200
- else if (hue >= 150 && hue < 210) { // Dark cyan
201
- colorRange = 180; // Cyan hue
202
- }
203
- else if (hue >= 210 && hue < 270) { // Dark blue
204
- colorRange = 240; // Blue hue
205
- }
206
- else if (hue >= 270 && hue < 330) { // Dark purple
207
- colorRange = 300; // Purple hue
208
- }
209
- else { // Dark magenta
210
- colorRange = 360; // Magenta hue
211
- }
212
- // Use a low lightness value to keep the color dark
213
- return `hsl(${colorRange}, 70%, 30%)`; // Low lightness for dark colors
214
- };
215
- const extractInitialsFromName = (name) => {
216
- if (!name)
217
- return '';
218
- const lettersOnly = name.replace(/[^a-zA-Z]/g, '');
219
- if (lettersOnly.length === 0) {
220
- return name[0]?.toUpperCase() || '';
221
- }
222
- if (lettersOnly.toLowerCase() === 'sysadmin') {
223
- return 'SYS';
224
- }
225
- return lettersOnly.substring(0, 2).toUpperCase();
226
- };
227
181
  return _jsx(TMTooltip, { content: blogPost.ownerName ?? '-', children: _jsx("div", { style: {
228
182
  width: "40px",
229
183
  height: "40px",
230
184
  borderRadius: "50%",
231
- backgroundColor: generateDarkColorFromName(blogPost.ownerName ?? '-'),
185
+ backgroundColor: getAvatarColor(blogPost.ownerName ?? '-'),
232
186
  display: "flex",
233
187
  alignItems: "center",
234
188
  justifyContent: "center",
@@ -27,7 +27,6 @@ interface ITMHeader {
27
27
  onSettingsClick?: () => void;
28
28
  }
29
29
  export declare const getInitials: (name: string) => string;
30
- export declare const getAvatarColor: (name: string) => string;
31
30
  export declare const getCultureFlag: (cultureId: CultureIDs) => string;
32
31
  export declare const getCultureDisplayName: (cultureId: CultureIDs) => string;
33
32
  export declare const copyUserInfoToClipboard: (userName: string, cultureId: string, archiveId: string, archiveDesc: string, endpoint: string, domain?: string) => void;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useState, useEffect, useRef, useMemo } from 'react';
3
3
  import six from '../../assets/six.png';
4
- import { IconCloseOutline, IconCopy, IconSearch, openApps, SDKUI_Localizator } from '../../helper';
4
+ import { getAvatarColor, IconCloseOutline, IconCopy, IconSearch, openApps, SDKUI_Localizator } from '../../helper';
5
5
  import styled, { keyframes } from 'styled-components';
6
6
  import { SDK_Globals, AuthenticationModes, AppModules, UserLevels, CultureIDs } from '@topconsultnpm/sdk-ts-beta';
7
7
  import { TMColors } from '../../utils/theme';
@@ -36,15 +36,6 @@ export const getInitials = (name) => {
36
36
  }
37
37
  return (words[0][0] + words[words.length - 1][0]).toUpperCase();
38
38
  };
39
- export const getAvatarColor = (name) => {
40
- const colors = [
41
- '#6264A7', '#8C6BAD', '#C239B3', '#E33B9A', '#F2707C',
42
- '#FF8C00', '#CA5010', '#8E562E', '#498205', '#107C10',
43
- '#0078D4', '#038387', '#8764B8', '#881798', '#C50E20'
44
- ];
45
- const hash = name.split('').reduce((acc, char) => char.charCodeAt(0) + acc, 0);
46
- return colors[hash % colors.length];
47
- };
48
39
  export const getCultureFlag = (cultureId) => {
49
40
  switch (cultureId) {
50
41
  case 'it_IT': return it;
@@ -6,3 +6,5 @@ export interface RowData {
6
6
  }
7
7
  export declare const associateColumnsToRows: (columns: Array<DataColumnDescriptor> | undefined, rows: Array<Array<string>> | undefined) => Array<RowData>;
8
8
  export declare const buildValueToLabelMapFromDataColumns: (columns: Array<DataColumnDescriptor>) => Promise<Map<string, string>>;
9
+ export declare const getAvatarColor: (name: string) => string;
10
+ export declare const extractInitialsFromName: (name: string) => string;
@@ -133,3 +133,24 @@ export const buildValueToLabelMapFromDataColumns = async (columns) => {
133
133
  }
134
134
  return valueToNameMap;
135
135
  };
136
+ export const getAvatarColor = (name) => {
137
+ const colors = [
138
+ '#6264A7', '#8C6BAD', '#C239B3', '#E33B9A', '#F2707C',
139
+ '#FF8C00', '#CA5010', '#8E562E', '#498205', '#107C10',
140
+ '#0078D4', '#038387', '#8764B8', '#881798', '#C50E20'
141
+ ];
142
+ const hash = name.split('').reduce((acc, char) => char.charCodeAt(0) + acc, 0);
143
+ return colors[hash % colors.length];
144
+ };
145
+ export const extractInitialsFromName = (name) => {
146
+ if (!name)
147
+ return '';
148
+ const lettersOnly = name.replace(/[^a-zA-Z]/g, '');
149
+ if (lettersOnly.length === 0) {
150
+ return name[0]?.toUpperCase() || '';
151
+ }
152
+ if (lettersOnly.toLowerCase() === 'sysadmin') {
153
+ return 'SYS';
154
+ }
155
+ return lettersOnly.substring(0, 2).toUpperCase();
156
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topconsultnpm/sdkui-react-beta",
3
- "version": "6.15.24",
3
+ "version": "6.15.26",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",