@topconsultnpm/sdkui-react-beta 6.15.25 → 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 =
|
|
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, getAvatarColor, 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,18 +178,6 @@ 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 extractInitialsFromName = (name) => {
|
|
182
|
-
if (!name)
|
|
183
|
-
return '';
|
|
184
|
-
const lettersOnly = name.replace(/[^a-zA-Z]/g, '');
|
|
185
|
-
if (lettersOnly.length === 0) {
|
|
186
|
-
return name[0]?.toUpperCase() || '';
|
|
187
|
-
}
|
|
188
|
-
if (lettersOnly.toLowerCase() === 'sysadmin') {
|
|
189
|
-
return 'SYS';
|
|
190
|
-
}
|
|
191
|
-
return lettersOnly.substring(0, 2).toUpperCase();
|
|
192
|
-
};
|
|
193
181
|
return _jsx(TMTooltip, { content: blogPost.ownerName ?? '-', children: _jsx("div", { style: {
|
|
194
182
|
width: "40px",
|
|
195
183
|
height: "40px",
|
package/lib/helper/TMUtils.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export interface RowData {
|
|
|
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
9
|
export declare const getAvatarColor: (name: string) => string;
|
|
10
|
+
export declare const extractInitialsFromName: (name: string) => string;
|
package/lib/helper/TMUtils.js
CHANGED
|
@@ -142,3 +142,15 @@ export const getAvatarColor = (name) => {
|
|
|
142
142
|
const hash = name.split('').reduce((acc, char) => char.charCodeAt(0) + acc, 0);
|
|
143
143
|
return colors[hash % colors.length];
|
|
144
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
|
+
};
|