@dt-dds/react-avatar 1.0.0-beta.50

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/dist/index.mjs ADDED
@@ -0,0 +1,375 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // src/Avatar.tsx
22
+ import { Tooltip } from "@dt-dds/react-tooltip";
23
+ import { useState } from "react";
24
+
25
+ // ../../dt-dds-react/core/assets/svgs/AllOut.tsx
26
+ import { jsx, jsxs } from "react/jsx-runtime";
27
+
28
+ // ../../dt-dds-react/core/assets/svgs/Apis.tsx
29
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
30
+
31
+ // ../../dt-dds-react/core/assets/svgs/Apps.tsx
32
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
33
+
34
+ // ../../dt-dds-react/core/assets/svgs/ArrowDropDown.tsx
35
+ import { jsx as jsx4 } from "react/jsx-runtime";
36
+
37
+ // ../../dt-dds-react/core/assets/svgs/ArrowDropUp.tsx
38
+ import { jsx as jsx5 } from "react/jsx-runtime";
39
+
40
+ // ../../dt-dds-react/core/assets/svgs/ArrowLeft.tsx
41
+ import { jsx as jsx6 } from "react/jsx-runtime";
42
+
43
+ // ../../dt-dds-react/core/assets/svgs/ArrowRight.tsx
44
+ import { jsx as jsx7 } from "react/jsx-runtime";
45
+
46
+ // ../../dt-dds-react/core/assets/svgs/AvatarThumbnail.tsx
47
+ import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
48
+ var AvatarThumbnail = (props) => {
49
+ return /* @__PURE__ */ jsxs4(
50
+ "svg",
51
+ __spreadProps(__spreadValues({
52
+ fill: "none",
53
+ height: "32",
54
+ viewBox: "0 0 33 32",
55
+ width: "33",
56
+ xmlns: "http://www.w3.org/2000/svg"
57
+ }, props), {
58
+ children: [
59
+ /* @__PURE__ */ jsxs4("g", { clipPath: "url(#clip0_1627_31268)", children: [
60
+ /* @__PURE__ */ jsx8("rect", { fill: "#D3D4D5", height: "32", rx: "16", width: "32", x: "0.5" }),
61
+ /* @__PURE__ */ jsx8("circle", { cx: "16.5", cy: "34", fill: "white", r: "14" }),
62
+ /* @__PURE__ */ jsx8("circle", { cx: "16.5", cy: "13", fill: "white", r: "5" })
63
+ ] }),
64
+ /* @__PURE__ */ jsx8("defs", { children: /* @__PURE__ */ jsx8("clipPath", { id: "clip0_1627_31268", children: /* @__PURE__ */ jsx8("rect", { fill: "white", height: "32", rx: "16", width: "32", x: "0.5" }) }) })
65
+ ]
66
+ })
67
+ );
68
+ };
69
+ var AvatarThumbnail_default = AvatarThumbnail;
70
+
71
+ // ../../dt-dds-react/core/assets/svgs/Bolt.tsx
72
+ import { jsx as jsx9 } from "react/jsx-runtime";
73
+
74
+ // ../../dt-dds-react/core/assets/svgs/CalendarMonth.tsx
75
+ import { jsx as jsx10 } from "react/jsx-runtime";
76
+
77
+ // ../../dt-dds-react/core/assets/svgs/Cancel.tsx
78
+ import { jsx as jsx11, jsxs as jsxs5 } from "react/jsx-runtime";
79
+
80
+ // ../../dt-dds-react/core/assets/svgs/Check.tsx
81
+ import { jsx as jsx12 } from "react/jsx-runtime";
82
+
83
+ // ../../dt-dds-react/core/assets/svgs/CheckCircle.tsx
84
+ import { jsx as jsx13 } from "react/jsx-runtime";
85
+
86
+ // ../../dt-dds-react/core/assets/svgs/CheckCircleOutline.tsx
87
+ import { jsx as jsx14 } from "react/jsx-runtime";
88
+
89
+ // ../../dt-dds-react/core/assets/svgs/Close.tsx
90
+ import { jsx as jsx15 } from "react/jsx-runtime";
91
+
92
+ // ../../dt-dds-react/core/assets/svgs/Copy.tsx
93
+ import { jsx as jsx16, jsxs as jsxs6 } from "react/jsx-runtime";
94
+
95
+ // ../../dt-dds-react/core/assets/svgs/Delete.tsx
96
+ import { jsx as jsx17, jsxs as jsxs7 } from "react/jsx-runtime";
97
+
98
+ // ../../dt-dds-react/core/assets/svgs/Edit.tsx
99
+ import { jsx as jsx18, jsxs as jsxs8 } from "react/jsx-runtime";
100
+
101
+ // ../../dt-dds-react/core/assets/svgs/Email.tsx
102
+ import { jsx as jsx19, jsxs as jsxs9 } from "react/jsx-runtime";
103
+
104
+ // ../../dt-dds-react/core/assets/svgs/EmailSend.tsx
105
+ import { jsx as jsx20, jsxs as jsxs10 } from "react/jsx-runtime";
106
+
107
+ // ../../dt-dds-react/core/assets/svgs/Error.tsx
108
+ import { useTheme } from "@emotion/react";
109
+ import { jsx as jsx21, jsxs as jsxs11 } from "react/jsx-runtime";
110
+
111
+ // ../../dt-dds-react/core/assets/svgs/ErrorOutline.tsx
112
+ import { jsx as jsx22 } from "react/jsx-runtime";
113
+
114
+ // ../../dt-dds-react/core/assets/svgs/EVStation.tsx
115
+ import { jsx as jsx23 } from "react/jsx-runtime";
116
+
117
+ // ../../dt-dds-react/core/assets/svgs/Info.tsx
118
+ import { jsx as jsx24 } from "react/jsx-runtime";
119
+
120
+ // ../../dt-dds-react/core/assets/svgs/InfoOutline.tsx
121
+ import { jsx as jsx25 } from "react/jsx-runtime";
122
+
123
+ // ../../dt-dds-react/core/assets/svgs/Input.tsx
124
+ import { jsx as jsx26, jsxs as jsxs12 } from "react/jsx-runtime";
125
+
126
+ // ../../dt-dds-react/core/assets/svgs/Language.tsx
127
+ import { jsx as jsx27 } from "react/jsx-runtime";
128
+
129
+ // ../../dt-dds-react/core/assets/svgs/LocationOn.tsx
130
+ import { jsx as jsx28, jsxs as jsxs13 } from "react/jsx-runtime";
131
+
132
+ // ../../dt-dds-react/core/assets/svgs/LocationSearching.tsx
133
+ import { jsx as jsx29 } from "react/jsx-runtime";
134
+
135
+ // ../../dt-dds-react/core/assets/svgs/MenuCompact.tsx
136
+ import { jsx as jsx30 } from "react/jsx-runtime";
137
+
138
+ // ../../dt-dds-react/core/assets/svgs/MenuExpand.tsx
139
+ import { jsx as jsx31 } from "react/jsx-runtime";
140
+
141
+ // ../../dt-dds-react/core/assets/svgs/Menu.tsx
142
+ import { jsx as jsx32 } from "react/jsx-runtime";
143
+
144
+ // ../../dt-dds-react/core/assets/svgs/MoreHorizontal.tsx
145
+ import { jsx as jsx33 } from "react/jsx-runtime";
146
+
147
+ // ../../dt-dds-react/core/assets/svgs/MoreVertical.tsx
148
+ import { jsx as jsx34 } from "react/jsx-runtime";
149
+
150
+ // ../../dt-dds-react/core/assets/svgs/NoData.tsx
151
+ import { useTheme as useTheme2 } from "@emotion/react";
152
+ import { jsx as jsx35, jsxs as jsxs14 } from "react/jsx-runtime";
153
+
154
+ // ../../dt-dds-react/core/assets/svgs/NotFound.tsx
155
+ import { jsx as jsx36, jsxs as jsxs15 } from "react/jsx-runtime";
156
+
157
+ // ../../dt-dds-react/core/assets/svgs/OutlinedArrowDropDown.tsx
158
+ import { jsx as jsx37 } from "react/jsx-runtime";
159
+
160
+ // ../../dt-dds-react/core/assets/svgs/OutlinedArrowDropUp.tsx
161
+ import { jsx as jsx38 } from "react/jsx-runtime";
162
+
163
+ // ../../dt-dds-react/core/assets/svgs/PhoneOutlined.tsx
164
+ import { jsx as jsx39 } from "react/jsx-runtime";
165
+
166
+ // ../../dt-dds-react/core/assets/svgs/Payments.tsx
167
+ import { jsx as jsx40 } from "react/jsx-runtime";
168
+
169
+ // ../../dt-dds-react/core/assets/svgs/Products.tsx
170
+ import { jsx as jsx41, jsxs as jsxs16 } from "react/jsx-runtime";
171
+
172
+ // ../../dt-dds-react/core/assets/svgs/RemoveCircleOutline.tsx
173
+ import { jsx as jsx42 } from "react/jsx-runtime";
174
+
175
+ // ../../dt-dds-react/core/assets/svgs/Share.tsx
176
+ import { jsx as jsx43, jsxs as jsxs17 } from "react/jsx-runtime";
177
+
178
+ // ../../dt-dds-react/core/assets/svgs/Signout.tsx
179
+ import { jsx as jsx44 } from "react/jsx-runtime";
180
+
181
+ // ../../dt-dds-react/core/assets/svgs/Teams.tsx
182
+ import { jsx as jsx45, jsxs as jsxs18 } from "react/jsx-runtime";
183
+
184
+ // ../../dt-dds-react/core/assets/svgs/Timeline.tsx
185
+ import { jsx as jsx46, jsxs as jsxs19 } from "react/jsx-runtime";
186
+
187
+ // ../../dt-dds-react/core/assets/svgs/Topic.tsx
188
+ import { jsx as jsx47, jsxs as jsxs20 } from "react/jsx-runtime";
189
+
190
+ // ../../dt-dds-react/core/assets/svgs/UnfoldLess.tsx
191
+ import { jsx as jsx48 } from "react/jsx-runtime";
192
+
193
+ // ../../dt-dds-react/core/assets/svgs/UnfoldMore.tsx
194
+ import { jsx as jsx49 } from "react/jsx-runtime";
195
+
196
+ // ../../dt-dds-react/core/assets/svgs/Username.tsx
197
+ import { jsx as jsx50, jsxs as jsxs21 } from "react/jsx-runtime";
198
+
199
+ // ../../dt-dds-react/core/assets/svgs/ViewAgenda.tsx
200
+ import { jsx as jsx51, jsxs as jsxs22 } from "react/jsx-runtime";
201
+
202
+ // ../../dt-dds-react/core/assets/svgs/Visibility.tsx
203
+ import { jsx as jsx52, jsxs as jsxs23 } from "react/jsx-runtime";
204
+
205
+ // ../../dt-dds-react/core/assets/svgs/VisibilityOff.tsx
206
+ import { jsx as jsx53, jsxs as jsxs24 } from "react/jsx-runtime";
207
+
208
+ // ../../dt-dds-react/core/assets/svgs/WarningOutline.tsx
209
+ import { jsx as jsx54 } from "react/jsx-runtime";
210
+
211
+ // ../../dt-dds-react/core/assets/svgs/Warning.tsx
212
+ import { jsx as jsx55 } from "react/jsx-runtime";
213
+
214
+ // ../../dt-dds-react/core/assets/svgs/Wifi.tsx
215
+ import { jsx as jsx56 } from "react/jsx-runtime";
216
+
217
+ // ../../dt-dds-react/core/assets/svgs/Settings.tsx
218
+ import { jsx as jsx57 } from "react/jsx-runtime";
219
+
220
+ // src/Avatar.styled.ts
221
+ import styled from "@emotion/styled";
222
+
223
+ // src/constants/AvatarType.ts
224
+ var AvatarType = {
225
+ Primary: "primary",
226
+ Secondary: "secondary",
227
+ Tertiary: "tertiary",
228
+ Profile: "profile"
229
+ };
230
+
231
+ // src/constants/AvatarSize.ts
232
+ var AvatarSize = {
233
+ Small: "small",
234
+ Medium: "medium",
235
+ Large: "large"
236
+ };
237
+
238
+ // src/Avatar.styled.ts
239
+ var AvatarStyled = styled.div`
240
+ ${({ theme, type, size }) => {
241
+ let styles = `
242
+ & > * {
243
+ width: 100%;
244
+ height: 100%;
245
+ display: flex;
246
+ align-items: center;
247
+ justify-content: center;
248
+ font-weight: 700;
249
+ text-transform: uppercase;
250
+ border-radius: ${theme.radius.full};
251
+ cursor: pointer;
252
+ }
253
+ `;
254
+ switch (size) {
255
+ case AvatarSize.Small:
256
+ styles += `
257
+ width: 16px;
258
+ height: 16px;
259
+ font-size: 8px;
260
+ line-height: 10px;
261
+
262
+ & > * {
263
+ padding: 3px 2px 2px 2px;
264
+ }
265
+ `;
266
+ break;
267
+ case AvatarSize.Medium:
268
+ styles += `
269
+ width: 24px;
270
+ height: 24px;
271
+ font-size: 10px;
272
+ line-height: 14px;
273
+ `;
274
+ break;
275
+ case AvatarSize.Large:
276
+ styles += `
277
+ width: 32px;
278
+ height: 32px;
279
+ font-size: 12px;
280
+ line-height: 16px;
281
+ `;
282
+ break;
283
+ }
284
+ switch (type) {
285
+ case AvatarType.Primary:
286
+ styles += `
287
+ color: ${theme.palette.content.contrast};
288
+
289
+ & > * {
290
+ background-color: ${theme.palette.primary.default};
291
+
292
+ &:hover {
293
+ background-color: ${theme.palette.primary.dark};
294
+ }
295
+ }
296
+ `;
297
+ break;
298
+ case AvatarType.Secondary:
299
+ styles += `
300
+ color: ${theme.palette.content.contrast};
301
+
302
+ & > * {
303
+ background-color: ${theme.palette.secondary.default};
304
+
305
+ &:hover {
306
+ background-color: ${theme.palette.secondary.dark};
307
+ }
308
+ }
309
+ `;
310
+ break;
311
+ case AvatarType.Tertiary:
312
+ styles += `
313
+ color: ${theme.palette.primary.default};
314
+
315
+ & > * {
316
+ background-color: ${theme.palette.content.contrast};
317
+
318
+ &:hover {
319
+ background-color: ${theme.palette.primary.light};
320
+ }
321
+ }
322
+ `;
323
+ break;
324
+ case AvatarType.Profile:
325
+ styles += `
326
+ & > * {
327
+ padding: initial;
328
+ }
329
+ `;
330
+ break;
331
+ }
332
+ return styles;
333
+ }}
334
+ `;
335
+
336
+ // src/utils/acronymGenerator.ts
337
+ var acronymGenerator = (text = "") => {
338
+ const textSliced = text.split(" ").slice(0, 2).join(" ");
339
+ return textSliced.split(/\s/).reduce((response, word) => response += word.slice(0, 1), "").toUpperCase();
340
+ };
341
+
342
+ // src/Avatar.tsx
343
+ import { jsx as jsx58, jsxs as jsxs25 } from "react/jsx-runtime";
344
+ var Avatar = ({
345
+ title,
346
+ type = AvatarType.Primary,
347
+ size = AvatarSize.Medium,
348
+ imageSrc = "",
349
+ dataTestId,
350
+ customInitials
351
+ }) => {
352
+ const [showThumbnail, setShowThumbnail] = useState(false);
353
+ const handleImageError = () => {
354
+ setShowThumbnail(true);
355
+ };
356
+ const renderProfileImage = () => showThumbnail ? /* @__PURE__ */ jsx58(AvatarThumbnail_default, {}) : /* @__PURE__ */ jsx58("img", { alt: title, onError: handleImageError, src: imageSrc });
357
+ return /* @__PURE__ */ jsxs25(Tooltip, { children: [
358
+ /* @__PURE__ */ jsx58(
359
+ AvatarStyled,
360
+ {
361
+ "data-testid": dataTestId != null ? dataTestId : "avatar",
362
+ size,
363
+ type,
364
+ children: type === AvatarType.Profile ? renderProfileImage() : /* @__PURE__ */ jsx58("div", { children: customInitials ? customInitials.substring(0, 2) : acronymGenerator(title) })
365
+ }
366
+ ),
367
+ /* @__PURE__ */ jsx58(Tooltip.Content, { children: title })
368
+ ] });
369
+ };
370
+ var Avatar_default = Avatar;
371
+ export {
372
+ Avatar_default as Avatar,
373
+ AvatarSize,
374
+ AvatarType
375
+ };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@dt-dds/react-avatar",
3
+ "version": "1.0.0-beta.50",
4
+ "license": "MIT",
5
+ "exports": {
6
+ ".": "./dist/index.js"
7
+ },
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.mjs",
10
+ "types": "./dist/index.d.ts",
11
+ "files": [
12
+ "dist/**"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsup",
16
+ "dev": "tsup --watch",
17
+ "lint": "eslint --cache .",
18
+ "test": "jest",
19
+ "test:report": "open ./jest-coverage/lcov-report/index.html",
20
+ "test:update:snapshot": "jest -u"
21
+ },
22
+ "dependencies": {
23
+ "@dt-dds/react-core": "1.0.0-beta.41",
24
+ "@dt-dds/react-tooltip": "1.0.0-beta.49"
25
+ },
26
+ "devDependencies": {
27
+ "@babel/core": "^7.22.9",
28
+ "@babel/preset-env": "^7.22.9",
29
+ "@babel/preset-react": "^7.22.5",
30
+ "@babel/preset-typescript": "^7.23.3",
31
+ "@emotion/babel-plugin": "^11.11.0",
32
+ "@emotion/css": "^11.7.1",
33
+ "@emotion/jest": "^11.10.0",
34
+ "@emotion/react": "^11.8.2",
35
+ "@emotion/styled": "^11.8.1",
36
+ "@types/react": "^18.0.9",
37
+ "@types/react-dom": "^18.0.4",
38
+ "babel-loader": "^8.3.0",
39
+ "eslint-config-custom": "*",
40
+ "eslint-plugin-storybook": "^9.1.0",
41
+ "jest-config": "*",
42
+ "react": "^18.1.0",
43
+ "react-dom": "^18.2.0",
44
+ "tsconfig": "*",
45
+ "tsup": "^6.6.3",
46
+ "typescript": "^4.5.3"
47
+ },
48
+ "peerDependencies": {
49
+ "@emotion/css": "^11.7.1",
50
+ "@emotion/react": "^11.8.2",
51
+ "@emotion/styled": "^11.8.1",
52
+ "react": ">=17.0.2",
53
+ "react-dom": ">=17.0.2"
54
+ }
55
+ }