@dt-dds/react-message 1.0.0-beta.100
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/CHANGELOG.md +907 -0
- package/LICENSE.md +21 -0
- package/README.md +94 -0
- package/dist/index.d.mts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +322 -0
- package/dist/index.mjs +314 -0
- package/package.json +58 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
25
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
26
|
+
}) : x)(function(x) {
|
|
27
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
28
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
29
|
+
});
|
|
30
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
31
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
32
|
+
};
|
|
33
|
+
var __copyProps = (to, from, except, desc) => {
|
|
34
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
35
|
+
for (let key of __getOwnPropNames(from))
|
|
36
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
37
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
38
|
+
}
|
|
39
|
+
return to;
|
|
40
|
+
};
|
|
41
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
42
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
43
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
44
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
45
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
46
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
47
|
+
mod
|
|
48
|
+
));
|
|
49
|
+
|
|
50
|
+
// ../box/dist/index.js
|
|
51
|
+
var require_dist = __commonJS({
|
|
52
|
+
"../box/dist/index.js"(exports, module) {
|
|
53
|
+
"use strict";
|
|
54
|
+
var __create2 = Object.create;
|
|
55
|
+
var __defProp2 = Object.defineProperty;
|
|
56
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
57
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
58
|
+
var __getProtoOf2 = Object.getPrototypeOf;
|
|
59
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
60
|
+
var __export = (target, all) => {
|
|
61
|
+
for (var name in all)
|
|
62
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
63
|
+
};
|
|
64
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
65
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
66
|
+
for (let key of __getOwnPropNames2(from))
|
|
67
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
68
|
+
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
69
|
+
}
|
|
70
|
+
return to;
|
|
71
|
+
};
|
|
72
|
+
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
|
|
73
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
74
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
75
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
76
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
77
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
|
|
78
|
+
mod
|
|
79
|
+
));
|
|
80
|
+
var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
81
|
+
var index_exports = {};
|
|
82
|
+
__export(index_exports, {
|
|
83
|
+
Box: () => Box2
|
|
84
|
+
});
|
|
85
|
+
module.exports = __toCommonJS(index_exports);
|
|
86
|
+
var import_styled2 = __toESM2(__require("@emotion/styled"));
|
|
87
|
+
var BoxStyled = import_styled2.default.div`
|
|
88
|
+
display: flex;
|
|
89
|
+
flex-direction: column;
|
|
90
|
+
align-items: center;
|
|
91
|
+
`;
|
|
92
|
+
var import_jsx_runtime2 = __require("react/jsx-runtime");
|
|
93
|
+
var Box2 = ({
|
|
94
|
+
dataTestId,
|
|
95
|
+
children,
|
|
96
|
+
element = "div",
|
|
97
|
+
style
|
|
98
|
+
}) => {
|
|
99
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(BoxStyled, { as: element, "data-testid": dataTestId, style, children });
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// src/Message.tsx
|
|
105
|
+
var import_react_box = __toESM(require_dist());
|
|
106
|
+
import { useMedia } from "@dt-dds/react-core";
|
|
107
|
+
import { Icon } from "@dt-dds/react-icon";
|
|
108
|
+
import { Typography } from "@dt-dds/react-typography";
|
|
109
|
+
import { useTheme } from "@emotion/react";
|
|
110
|
+
import { Children, cloneElement, useMemo } from "react";
|
|
111
|
+
|
|
112
|
+
// src/types/index.ts
|
|
113
|
+
var OMessageType = {
|
|
114
|
+
Default: "default",
|
|
115
|
+
Error: "error",
|
|
116
|
+
Info: "informative",
|
|
117
|
+
Success: "success",
|
|
118
|
+
Warning: "warning"
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// src/constants/index.ts
|
|
122
|
+
var MESSAGE_ICONS = {
|
|
123
|
+
[OMessageType.Error]: "error",
|
|
124
|
+
[OMessageType.Info]: "info",
|
|
125
|
+
[OMessageType.Success]: "check_circle",
|
|
126
|
+
[OMessageType.Warning]: "warning"
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// src/Message.styled.ts
|
|
130
|
+
import styled from "@emotion/styled";
|
|
131
|
+
var MessageStyled = styled.div`
|
|
132
|
+
display: grid;
|
|
133
|
+
width: 100%;
|
|
134
|
+
padding: ${({ theme }) => `${theme.spacing.spacing_40} ${theme.spacing.spacing_50}`};
|
|
135
|
+
border-radius: ${({ theme }) => theme.shape.message};
|
|
136
|
+
|
|
137
|
+
${({ theme, messageType, orientation }) => {
|
|
138
|
+
const isDefault = messageType === OMessageType.Default;
|
|
139
|
+
const background = isDefault ? theme.palette.surface.light : theme.palette[messageType].light;
|
|
140
|
+
const border = isDefault ? theme.palette.border.medium : theme.palette[messageType].default;
|
|
141
|
+
const baseGrid = `
|
|
142
|
+
grid-template-columns: ${isDefault ? "1fr fit-content(100%)" : "fit-content(100%) 1fr fit-content(100%)"};
|
|
143
|
+
background-color: ${background};
|
|
144
|
+
border: 1px solid ${border};
|
|
145
|
+
gap: ${theme.spacing.spacing_50}
|
|
146
|
+
`;
|
|
147
|
+
if (orientation === "vertical") {
|
|
148
|
+
return `
|
|
149
|
+
${baseGrid};
|
|
150
|
+
grid-template-columns: 1fr fit-content(100%);
|
|
151
|
+
gap: ${theme.spacing.spacing_30};
|
|
152
|
+
|
|
153
|
+
& > :nth-child(1) {
|
|
154
|
+
grid-column: 1;
|
|
155
|
+
grid-row: 1;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
${isDefault ? `
|
|
159
|
+
& > :nth-child(2) {
|
|
160
|
+
grid-column: 2;
|
|
161
|
+
grid-row: 1;
|
|
162
|
+
}
|
|
163
|
+
` : `
|
|
164
|
+
& > :nth-child(2) {
|
|
165
|
+
grid-column: 1;
|
|
166
|
+
grid-row: 2;
|
|
167
|
+
}
|
|
168
|
+
& > :nth-child(3) {
|
|
169
|
+
grid-column: 2;
|
|
170
|
+
grid-row: 1;
|
|
171
|
+
}
|
|
172
|
+
`}
|
|
173
|
+
`;
|
|
174
|
+
}
|
|
175
|
+
return baseGrid;
|
|
176
|
+
}}
|
|
177
|
+
`;
|
|
178
|
+
var MessageActionsStyled = styled.div`
|
|
179
|
+
display: flex;
|
|
180
|
+
flex-direction: row;
|
|
181
|
+
gap: ${({ theme }) => theme.spacing.spacing_20};
|
|
182
|
+
|
|
183
|
+
button {
|
|
184
|
+
${({ theme, messageType }) => {
|
|
185
|
+
const isDefault = messageType === "default";
|
|
186
|
+
const color = isDefault ? theme.palette.content.default : theme.palette[messageType].dark;
|
|
187
|
+
const hoverBg = isDefault ? theme.palette.surface.medium : theme.palette[messageType].medium;
|
|
188
|
+
return `
|
|
189
|
+
color: ${color};
|
|
190
|
+
|
|
191
|
+
&:hover {
|
|
192
|
+
background-color: ${hoverBg};
|
|
193
|
+
color: ${color};
|
|
194
|
+
}
|
|
195
|
+
`;
|
|
196
|
+
}}
|
|
197
|
+
}
|
|
198
|
+
`;
|
|
199
|
+
var MessageButtonCloseStyled = styled.button`
|
|
200
|
+
${({ theme, messageType, orientation }) => `
|
|
201
|
+
border: 0;
|
|
202
|
+
cursor: pointer;
|
|
203
|
+
background: transparent;
|
|
204
|
+
display: flex;
|
|
205
|
+
height: fit-content;
|
|
206
|
+
|
|
207
|
+
${orientation === "horizontal" && "align-self: center"};
|
|
208
|
+
|
|
209
|
+
&:focus-visible {
|
|
210
|
+
outline: 2px solid ${theme.palette.primary.default};
|
|
211
|
+
outline-offset: 1px;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
&:hover {
|
|
215
|
+
background-color: ${messageType === OMessageType.Default ? theme.palette.surface.medium : theme.palette[messageType].medium};
|
|
216
|
+
}
|
|
217
|
+
`}
|
|
218
|
+
`;
|
|
219
|
+
|
|
220
|
+
// src/Message.tsx
|
|
221
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
222
|
+
var Message = ({
|
|
223
|
+
children,
|
|
224
|
+
dataTestId,
|
|
225
|
+
style,
|
|
226
|
+
type = OMessageType.Default,
|
|
227
|
+
onClose,
|
|
228
|
+
description,
|
|
229
|
+
title,
|
|
230
|
+
orientation: propOrientation = "horizontal"
|
|
231
|
+
}) => {
|
|
232
|
+
const theme = useTheme();
|
|
233
|
+
const isDefault = type === OMessageType.Default;
|
|
234
|
+
const isMobile = useMedia(`(max-width: ${theme.breakpoints.mq2}px)`);
|
|
235
|
+
const orientation = isMobile ? "vertical" : propOrientation || "horizontal";
|
|
236
|
+
const isHorizontal = orientation === "horizontal";
|
|
237
|
+
const isDismissible = !!onClose;
|
|
238
|
+
const textColor = isDefault ? "content.default" : `${type}.dark`;
|
|
239
|
+
const iconColor = isDefault ? theme.palette.content.default : theme.palette[type].dark;
|
|
240
|
+
const clonedChildren = useMemo(
|
|
241
|
+
() => Children.map(children, (child) => {
|
|
242
|
+
return child && cloneElement(child, __spreadProps(__spreadValues({}, child.props), {
|
|
243
|
+
type
|
|
244
|
+
}));
|
|
245
|
+
}),
|
|
246
|
+
[children, type]
|
|
247
|
+
);
|
|
248
|
+
return /* @__PURE__ */ jsxs(
|
|
249
|
+
MessageStyled,
|
|
250
|
+
{
|
|
251
|
+
"data-testid": dataTestId != null ? dataTestId : "message",
|
|
252
|
+
messageType: type,
|
|
253
|
+
orientation,
|
|
254
|
+
style,
|
|
255
|
+
children: [
|
|
256
|
+
!isDefault && /* @__PURE__ */ jsx(
|
|
257
|
+
Icon,
|
|
258
|
+
{
|
|
259
|
+
code: MESSAGE_ICONS[type],
|
|
260
|
+
color: theme.palette[type].dark,
|
|
261
|
+
"data-testid": "message-icon",
|
|
262
|
+
dataTestId: "message-icon"
|
|
263
|
+
}
|
|
264
|
+
),
|
|
265
|
+
/* @__PURE__ */ jsxs(
|
|
266
|
+
import_react_box.Box,
|
|
267
|
+
{
|
|
268
|
+
dataTestId: "message-content",
|
|
269
|
+
style: {
|
|
270
|
+
flexDirection: isHorizontal ? "row" : "column",
|
|
271
|
+
justifyContent: "space-between",
|
|
272
|
+
gap: isHorizontal ? theme.spacing.spacing_30 : theme.spacing.spacing_50,
|
|
273
|
+
alignItems: isHorizontal ? "center" : "start"
|
|
274
|
+
},
|
|
275
|
+
children: [
|
|
276
|
+
/* @__PURE__ */ jsxs(
|
|
277
|
+
import_react_box.Box,
|
|
278
|
+
{
|
|
279
|
+
style: { alignItems: "flex-start", gap: theme.spacing.spacing_10 },
|
|
280
|
+
children: [
|
|
281
|
+
title ? /* @__PURE__ */ jsx(Typography, { color: textColor, fontStyles: "bodyLgBold", children: title }) : null,
|
|
282
|
+
/* @__PURE__ */ jsx(Typography, { color: textColor, fontStyles: "bodyLgRegular", children: description })
|
|
283
|
+
]
|
|
284
|
+
}
|
|
285
|
+
),
|
|
286
|
+
clonedChildren
|
|
287
|
+
]
|
|
288
|
+
}
|
|
289
|
+
),
|
|
290
|
+
isDismissible ? /* @__PURE__ */ jsx(
|
|
291
|
+
MessageButtonCloseStyled,
|
|
292
|
+
{
|
|
293
|
+
"aria-label": "Close message",
|
|
294
|
+
messageType: type,
|
|
295
|
+
onClick: onClose,
|
|
296
|
+
orientation,
|
|
297
|
+
children: /* @__PURE__ */ jsx(Icon, { code: "close", color: iconColor })
|
|
298
|
+
}
|
|
299
|
+
) : null
|
|
300
|
+
]
|
|
301
|
+
}
|
|
302
|
+
);
|
|
303
|
+
};
|
|
304
|
+
Message.Actions = ({ children, dataTestId, type }) => /* @__PURE__ */ jsx(
|
|
305
|
+
MessageActionsStyled,
|
|
306
|
+
{
|
|
307
|
+
"data-testid": dataTestId != null ? dataTestId : "message-actions",
|
|
308
|
+
messageType: type,
|
|
309
|
+
children
|
|
310
|
+
}
|
|
311
|
+
);
|
|
312
|
+
export {
|
|
313
|
+
Message
|
|
314
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dt-dds/react-message",
|
|
3
|
+
"version": "1.0.0-beta.100",
|
|
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-button": "1.0.0-beta.84",
|
|
24
|
+
"@dt-dds/react-core": "1.0.0-beta.51",
|
|
25
|
+
"@dt-dds/react-icon": "1.0.0-beta.54",
|
|
26
|
+
"@dt-dds/react-typography": "1.0.0-beta.42",
|
|
27
|
+
"@dt-dds/themes": "1.0.0-beta.9"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@babel/core": "^7.22.9",
|
|
31
|
+
"@babel/preset-env": "^7.22.9",
|
|
32
|
+
"@babel/preset-react": "^7.22.5",
|
|
33
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
34
|
+
"@emotion/babel-plugin": "^11.11.0",
|
|
35
|
+
"@emotion/css": "^11.7.1",
|
|
36
|
+
"@emotion/jest": "^11.10.0",
|
|
37
|
+
"@emotion/react": "^11.8.2",
|
|
38
|
+
"@emotion/styled": "^11.8.1",
|
|
39
|
+
"@types/react": "^18.0.9",
|
|
40
|
+
"@types/react-dom": "^18.0.4",
|
|
41
|
+
"babel-loader": "^8.3.0",
|
|
42
|
+
"eslint-config-custom": "*",
|
|
43
|
+
"eslint-plugin-storybook": "^9.1.0",
|
|
44
|
+
"jest-config": "*",
|
|
45
|
+
"react": "^18.1.0",
|
|
46
|
+
"react-dom": "^18.2.0",
|
|
47
|
+
"tsconfig": "*",
|
|
48
|
+
"tsup": "^8.5.0",
|
|
49
|
+
"typescript": "^4.5.3"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@emotion/css": "^11.7.1",
|
|
53
|
+
"@emotion/react": "^11.8.2",
|
|
54
|
+
"@emotion/styled": "^11.8.1",
|
|
55
|
+
"react": ">=17.0.2",
|
|
56
|
+
"react-dom": ">=17.0.2"
|
|
57
|
+
}
|
|
58
|
+
}
|