@dt-dds/react-tag 1.0.0-beta.43

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.js ADDED
@@ -0,0 +1,463 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+
47
+ // index.ts
48
+ var tag_exports = {};
49
+ __export(tag_exports, {
50
+ Tag: () => Tag
51
+ });
52
+ module.exports = __toCommonJS(tag_exports);
53
+
54
+ // src/Tag.tsx
55
+ var import_react_tooltip = require("@dt-dds/react-tooltip");
56
+ var import_react3 = require("react");
57
+
58
+ // ../../dt-dds-react/core/assets/svgs/AllOut.tsx
59
+ var import_jsx_runtime = require("react/jsx-runtime");
60
+
61
+ // ../../dt-dds-react/core/assets/svgs/Apis.tsx
62
+ var import_jsx_runtime2 = require("react/jsx-runtime");
63
+
64
+ // ../../dt-dds-react/core/assets/svgs/Apps.tsx
65
+ var import_jsx_runtime3 = require("react/jsx-runtime");
66
+
67
+ // ../../dt-dds-react/core/assets/svgs/ArrowDropDown.tsx
68
+ var import_jsx_runtime4 = require("react/jsx-runtime");
69
+
70
+ // ../../dt-dds-react/core/assets/svgs/ArrowDropUp.tsx
71
+ var import_jsx_runtime5 = require("react/jsx-runtime");
72
+
73
+ // ../../dt-dds-react/core/assets/svgs/ArrowLeft.tsx
74
+ var import_jsx_runtime6 = require("react/jsx-runtime");
75
+
76
+ // ../../dt-dds-react/core/assets/svgs/ArrowRight.tsx
77
+ var import_jsx_runtime7 = require("react/jsx-runtime");
78
+
79
+ // ../../dt-dds-react/core/assets/svgs/AvatarThumbnail.tsx
80
+ var import_jsx_runtime8 = require("react/jsx-runtime");
81
+
82
+ // ../../dt-dds-react/core/assets/svgs/Bolt.tsx
83
+ var import_jsx_runtime9 = require("react/jsx-runtime");
84
+
85
+ // ../../dt-dds-react/core/assets/svgs/CalendarMonth.tsx
86
+ var import_jsx_runtime10 = require("react/jsx-runtime");
87
+
88
+ // ../../dt-dds-react/core/assets/svgs/Cancel.tsx
89
+ var import_jsx_runtime11 = require("react/jsx-runtime");
90
+
91
+ // ../../dt-dds-react/core/assets/svgs/Check.tsx
92
+ var import_jsx_runtime12 = require("react/jsx-runtime");
93
+
94
+ // ../../dt-dds-react/core/assets/svgs/CheckCircle.tsx
95
+ var import_jsx_runtime13 = require("react/jsx-runtime");
96
+
97
+ // ../../dt-dds-react/core/assets/svgs/CheckCircleOutline.tsx
98
+ var import_jsx_runtime14 = require("react/jsx-runtime");
99
+
100
+ // ../../dt-dds-react/core/assets/svgs/Close.tsx
101
+ var import_jsx_runtime15 = require("react/jsx-runtime");
102
+ var CloseIcon = (props) => {
103
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
104
+ "svg",
105
+ __spreadProps(__spreadValues({
106
+ fill: "none",
107
+ height: "24",
108
+ viewBox: "0 0 24 24",
109
+ width: "24",
110
+ xmlns: "http://www.w3.org/2000/svg"
111
+ }, props), {
112
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
113
+ "path",
114
+ {
115
+ d: "M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z",
116
+ fill: "currentColor"
117
+ }
118
+ )
119
+ })
120
+ );
121
+ };
122
+ var Close_default = CloseIcon;
123
+
124
+ // ../../dt-dds-react/core/assets/svgs/Copy.tsx
125
+ var import_jsx_runtime16 = require("react/jsx-runtime");
126
+
127
+ // ../../dt-dds-react/core/assets/svgs/Delete.tsx
128
+ var import_jsx_runtime17 = require("react/jsx-runtime");
129
+
130
+ // ../../dt-dds-react/core/assets/svgs/Edit.tsx
131
+ var import_jsx_runtime18 = require("react/jsx-runtime");
132
+
133
+ // ../../dt-dds-react/core/assets/svgs/Email.tsx
134
+ var import_jsx_runtime19 = require("react/jsx-runtime");
135
+
136
+ // ../../dt-dds-react/core/assets/svgs/EmailSend.tsx
137
+ var import_jsx_runtime20 = require("react/jsx-runtime");
138
+
139
+ // ../../dt-dds-react/core/assets/svgs/Error.tsx
140
+ var import_react = require("@emotion/react");
141
+ var import_jsx_runtime21 = require("react/jsx-runtime");
142
+
143
+ // ../../dt-dds-react/core/assets/svgs/ErrorOutline.tsx
144
+ var import_jsx_runtime22 = require("react/jsx-runtime");
145
+
146
+ // ../../dt-dds-react/core/assets/svgs/EVStation.tsx
147
+ var import_jsx_runtime23 = require("react/jsx-runtime");
148
+
149
+ // ../../dt-dds-react/core/assets/svgs/Info.tsx
150
+ var import_jsx_runtime24 = require("react/jsx-runtime");
151
+
152
+ // ../../dt-dds-react/core/assets/svgs/InfoOutline.tsx
153
+ var import_jsx_runtime25 = require("react/jsx-runtime");
154
+
155
+ // ../../dt-dds-react/core/assets/svgs/Input.tsx
156
+ var import_jsx_runtime26 = require("react/jsx-runtime");
157
+
158
+ // ../../dt-dds-react/core/assets/svgs/Language.tsx
159
+ var import_jsx_runtime27 = require("react/jsx-runtime");
160
+
161
+ // ../../dt-dds-react/core/assets/svgs/LocationOn.tsx
162
+ var import_jsx_runtime28 = require("react/jsx-runtime");
163
+
164
+ // ../../dt-dds-react/core/assets/svgs/LocationSearching.tsx
165
+ var import_jsx_runtime29 = require("react/jsx-runtime");
166
+
167
+ // ../../dt-dds-react/core/assets/svgs/MenuCompact.tsx
168
+ var import_jsx_runtime30 = require("react/jsx-runtime");
169
+
170
+ // ../../dt-dds-react/core/assets/svgs/MenuExpand.tsx
171
+ var import_jsx_runtime31 = require("react/jsx-runtime");
172
+
173
+ // ../../dt-dds-react/core/assets/svgs/Menu.tsx
174
+ var import_jsx_runtime32 = require("react/jsx-runtime");
175
+
176
+ // ../../dt-dds-react/core/assets/svgs/MoreHorizontal.tsx
177
+ var import_jsx_runtime33 = require("react/jsx-runtime");
178
+
179
+ // ../../dt-dds-react/core/assets/svgs/MoreVertical.tsx
180
+ var import_jsx_runtime34 = require("react/jsx-runtime");
181
+
182
+ // ../../dt-dds-react/core/assets/svgs/NoData.tsx
183
+ var import_react2 = require("@emotion/react");
184
+ var import_jsx_runtime35 = require("react/jsx-runtime");
185
+
186
+ // ../../dt-dds-react/core/assets/svgs/NotFound.tsx
187
+ var import_jsx_runtime36 = require("react/jsx-runtime");
188
+
189
+ // ../../dt-dds-react/core/assets/svgs/OutlinedArrowDropDown.tsx
190
+ var import_jsx_runtime37 = require("react/jsx-runtime");
191
+
192
+ // ../../dt-dds-react/core/assets/svgs/OutlinedArrowDropUp.tsx
193
+ var import_jsx_runtime38 = require("react/jsx-runtime");
194
+
195
+ // ../../dt-dds-react/core/assets/svgs/PhoneOutlined.tsx
196
+ var import_jsx_runtime39 = require("react/jsx-runtime");
197
+
198
+ // ../../dt-dds-react/core/assets/svgs/Payments.tsx
199
+ var import_jsx_runtime40 = require("react/jsx-runtime");
200
+
201
+ // ../../dt-dds-react/core/assets/svgs/Products.tsx
202
+ var import_jsx_runtime41 = require("react/jsx-runtime");
203
+
204
+ // ../../dt-dds-react/core/assets/svgs/RemoveCircleOutline.tsx
205
+ var import_jsx_runtime42 = require("react/jsx-runtime");
206
+
207
+ // ../../dt-dds-react/core/assets/svgs/Share.tsx
208
+ var import_jsx_runtime43 = require("react/jsx-runtime");
209
+
210
+ // ../../dt-dds-react/core/assets/svgs/Signout.tsx
211
+ var import_jsx_runtime44 = require("react/jsx-runtime");
212
+
213
+ // ../../dt-dds-react/core/assets/svgs/Teams.tsx
214
+ var import_jsx_runtime45 = require("react/jsx-runtime");
215
+
216
+ // ../../dt-dds-react/core/assets/svgs/Timeline.tsx
217
+ var import_jsx_runtime46 = require("react/jsx-runtime");
218
+
219
+ // ../../dt-dds-react/core/assets/svgs/Topic.tsx
220
+ var import_jsx_runtime47 = require("react/jsx-runtime");
221
+
222
+ // ../../dt-dds-react/core/assets/svgs/UnfoldLess.tsx
223
+ var import_jsx_runtime48 = require("react/jsx-runtime");
224
+
225
+ // ../../dt-dds-react/core/assets/svgs/UnfoldMore.tsx
226
+ var import_jsx_runtime49 = require("react/jsx-runtime");
227
+
228
+ // ../../dt-dds-react/core/assets/svgs/Username.tsx
229
+ var import_jsx_runtime50 = require("react/jsx-runtime");
230
+
231
+ // ../../dt-dds-react/core/assets/svgs/ViewAgenda.tsx
232
+ var import_jsx_runtime51 = require("react/jsx-runtime");
233
+
234
+ // ../../dt-dds-react/core/assets/svgs/Visibility.tsx
235
+ var import_jsx_runtime52 = require("react/jsx-runtime");
236
+
237
+ // ../../dt-dds-react/core/assets/svgs/VisibilityOff.tsx
238
+ var import_jsx_runtime53 = require("react/jsx-runtime");
239
+
240
+ // ../../dt-dds-react/core/assets/svgs/WarningOutline.tsx
241
+ var import_jsx_runtime54 = require("react/jsx-runtime");
242
+
243
+ // ../../dt-dds-react/core/assets/svgs/Warning.tsx
244
+ var import_jsx_runtime55 = require("react/jsx-runtime");
245
+
246
+ // ../../dt-dds-react/core/assets/svgs/Wifi.tsx
247
+ var import_jsx_runtime56 = require("react/jsx-runtime");
248
+
249
+ // ../../dt-dds-react/core/assets/svgs/Settings.tsx
250
+ var import_jsx_runtime57 = require("react/jsx-runtime");
251
+
252
+ // src/Tag.styled.ts
253
+ var import_styled = __toESM(require("@emotion/styled"));
254
+
255
+ // src/utils/tagVariantColors.ts
256
+ var getColors = (variant, theme, isDisabled, color) => {
257
+ const resolvedColor = color === "primary" ? "accent" : color;
258
+ if (variant === "solid") {
259
+ const palette = theme.palette[resolvedColor];
260
+ return {
261
+ bgColor: isDisabled ? palette.light : palette.default,
262
+ hoveredBgColor: palette.dark
263
+ };
264
+ }
265
+ if (variant === "outlined") {
266
+ const palette = theme.palette[resolvedColor];
267
+ return {
268
+ bgColor: palette.light,
269
+ hoveredBgColor: palette.medium,
270
+ borderTextColor: isDisabled ? palette.medium : palette.default,
271
+ hoveredBorderTextColor: palette.dark
272
+ };
273
+ }
274
+ };
275
+ var tagVariantColors = ({
276
+ theme,
277
+ color,
278
+ variant,
279
+ hasHover,
280
+ isDisabled
281
+ }) => {
282
+ const colors = getColors(variant, theme, isDisabled, color);
283
+ return {
284
+ solid: __spreadValues({
285
+ border: theme.spacing.none,
286
+ color: theme.palette.content.contrast,
287
+ backgroundColor: colors == null ? void 0 : colors.bgColor
288
+ }, hasHover && {
289
+ "&:hover": {
290
+ backgroundColor: colors == null ? void 0 : colors.hoveredBgColor,
291
+ color: theme.palette.content.contrast
292
+ }
293
+ }),
294
+ outlined: __spreadValues({
295
+ border: `1px solid ${colors == null ? void 0 : colors.borderTextColor}`,
296
+ color: colors == null ? void 0 : colors.borderTextColor,
297
+ backgroundColor: colors == null ? void 0 : colors.bgColor
298
+ }, hasHover && {
299
+ "&:hover": {
300
+ borderColor: colors == null ? void 0 : colors.hoveredBorderTextColor,
301
+ color: colors == null ? void 0 : colors.hoveredBorderTextColor,
302
+ backgroundColor: colors == null ? void 0 : colors.hoveredBgColor
303
+ }
304
+ })
305
+ }[variant];
306
+ };
307
+
308
+ // src/utils/tagVariantSize.ts
309
+ var tagSizeStyles = (theme, size) => ({
310
+ medium: {
311
+ fontSize: "0.75rem",
312
+ fontWeight: "700",
313
+ lineHeight: "1rem",
314
+ padding: `${theme.spacing["4xs"]} ${theme.spacing["3xs"]}`,
315
+ height: "32px"
316
+ },
317
+ small: {
318
+ fontSize: "0.625rem",
319
+ fontWeight: "700",
320
+ lineHeight: "0.875rem",
321
+ padding: `${theme.spacing["6xs"]} ${theme.spacing["4xs"]}`,
322
+ height: "18px"
323
+ }
324
+ })[size];
325
+
326
+ // src/Tag.styled.ts
327
+ var TagStyled = import_styled.default.div(
328
+ ({
329
+ theme,
330
+ border,
331
+ isDisabled,
332
+ isClickable,
333
+ isDismissible,
334
+ size,
335
+ variant,
336
+ color,
337
+ hasHover
338
+ }) => __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadValues({}, tagSizeStyles(theme, size)), tagVariantColors({ theme, variant, color, hasHover, isDisabled })), {
339
+ display: "flex",
340
+ textTransform: "uppercase",
341
+ alignItems: "center",
342
+ maxWidth: "max-content",
343
+ gap: theme.spacing["5xs"],
344
+ borderRadius: theme.radius[border === "rounded" ? "s" : "none"],
345
+ width: "150px",
346
+ ["> :first-child"]: {
347
+ whiteSpace: "nowrap",
348
+ display: "block",
349
+ overflow: "hidden",
350
+ textOverflow: "ellipsis"
351
+ }
352
+ }), (isClickable || isDismissible) && { userSelect: "none" }), isClickable && { cursor: "pointer" }), isDisabled && { cursor: "not-allowed" }), {
353
+ ["&:focus-visible"]: {
354
+ outline: `2px solid ${theme.palette.border.dark}`,
355
+ outlineOffset: "1px"
356
+ }
357
+ })
358
+ );
359
+ var TagButtonCloseStyled = import_styled.default.button`
360
+ ${({ theme }) => ({
361
+ backgroundColor: "transparent",
362
+ color: "currentColor",
363
+ display: "inherit",
364
+ border: 0,
365
+ cursor: "pointer",
366
+ ["&:disabled"]: { cursor: "not-allowed" },
367
+ ["&:focus-visible"]: {
368
+ outline: `2px solid ${theme.palette.border.dark}`,
369
+ outlineOffset: "1px"
370
+ }
371
+ })}
372
+ `;
373
+
374
+ // src/Tag.tsx
375
+ var import_jsx_runtime58 = require("react/jsx-runtime");
376
+ var Tag = (0, import_react3.forwardRef)(
377
+ ({
378
+ style,
379
+ children,
380
+ dataTestId,
381
+ variant = "solid",
382
+ color = "primary",
383
+ border = "squared",
384
+ size = "small",
385
+ isClickable = false,
386
+ isDisabled = false,
387
+ onClick,
388
+ onClose,
389
+ tooltipVariant = "opacity"
390
+ }, ref) => {
391
+ const dataTestIdName = dataTestId != null ? dataTestId : "tag";
392
+ const isDismissible = !!onClose;
393
+ const hasHoverStyle = !isDisabled && (!!onClick || isClickable || isDismissible);
394
+ const hasClickableStyle = !isDismissible && hasHoverStyle;
395
+ const handleClickTag = (event) => {
396
+ if (isDisabled || isDismissible) {
397
+ return;
398
+ }
399
+ onClick == null ? void 0 : onClick(event);
400
+ };
401
+ const cellRef = (0, import_react3.useRef)(null);
402
+ const [isOverflow, setIsOverflow] = (0, import_react3.useState)(false);
403
+ const handleClickOnEnterKey = (event) => {
404
+ if (event.code === "Enter") {
405
+ handleClickTag(event);
406
+ }
407
+ };
408
+ const handleCloseOnEnterKey = (event) => {
409
+ if (event.code === "Enter") {
410
+ onClose == null ? void 0 : onClose(event);
411
+ }
412
+ };
413
+ (0, import_react3.useEffect)(() => {
414
+ if (cellRef.current) {
415
+ const { current } = cellRef;
416
+ setIsOverflow(current.scrollWidth > current.clientWidth);
417
+ }
418
+ }, [children]);
419
+ return /* @__PURE__ */ (0, import_jsx_runtime58.jsxs)(import_react_tooltip.Tooltip, { children: [
420
+ /* @__PURE__ */ (0, import_jsx_runtime58.jsxs)(
421
+ TagStyled,
422
+ __spreadProps(__spreadValues(__spreadProps(__spreadValues({
423
+ "aria-disabled": isDisabled,
424
+ border,
425
+ color,
426
+ "data-testid": dataTestIdName,
427
+ hasHover: hasHoverStyle,
428
+ isClickable: hasClickableStyle,
429
+ isDisabled,
430
+ isDismissible,
431
+ onClick: handleClickTag
432
+ }, isClickable && { onKeyDown: handleClickOnEnterKey }), {
433
+ ref,
434
+ size,
435
+ style
436
+ }), isClickable && { tabIndex: 0 }), {
437
+ variant,
438
+ children: [
439
+ /* @__PURE__ */ (0, import_jsx_runtime58.jsx)("span", { ref: cellRef, children }),
440
+ isDismissible ? /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(
441
+ TagButtonCloseStyled,
442
+ {
443
+ "aria-disabled": isDisabled,
444
+ color,
445
+ "data-testid": `${dataTestIdName}-close-button`,
446
+ disabled: isDisabled,
447
+ onClick: onClose,
448
+ onKeyDown: handleCloseOnEnterKey,
449
+ tabIndex: 0,
450
+ children: /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(Close_default, { height: 12, width: 12 })
451
+ }
452
+ ) : null
453
+ ]
454
+ })
455
+ ),
456
+ /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(import_react_tooltip.Tooltip.Content, { background: tooltipVariant, children: isOverflow ? children : "" })
457
+ ] });
458
+ }
459
+ );
460
+ // Annotate the CommonJS export names for ESM import in node:
461
+ 0 && (module.exports = {
462
+ Tag
463
+ });