@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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Daimler Truck AG.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Message Package
2
+
3
+ This component fills the width of the container where is placed and its height varies depending on the content in it.
4
+ The usage of this component is to show a message to call attention to something, be it useful information or a warning message. They should be used to provide context in proximity to a piece of content.
5
+ Furthermore, it can be used to add an action like a link, by passing it as a children.
6
+
7
+ ## Usage
8
+
9
+ ```jsx
10
+ import { Message, Button } from '@dt-dds/react';
11
+
12
+ export const App = () => {
13
+ const title = 'Some Title';
14
+ const description = 'Some Description';
15
+ const type = 'Error';
16
+
17
+ return (
18
+ <Message type={type} title={title} description={description}>
19
+ <Message.Actions>
20
+ <Button size='small' variant='text'>
21
+ View action
22
+ </Button>
23
+ </Message.Actions>
24
+ </Message>
25
+ );
26
+ };
27
+ ```
28
+
29
+ ## API
30
+
31
+ ### Message
32
+
33
+ | Property | Type | Default | Description |
34
+ | ------------- | --------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
35
+ | `children` | `ReactNode` | - | Child components to be rendered. There is flexibility on what the content can be, but the recommendation is that it should be a link with a character count limit of 25. |
36
+ | `dataTestId` | `string` | `'message'` | Customizable test identifier. |
37
+ | `style` | `React.CSSProperties` | - | Customizable styles |
38
+ | `type` | `MessageType` | `'default'` | Sets the type of the Message, responsible for the icon and It's color, the background color and color of the dashed border |
39
+ | `title` | `string` | - | Optional Text to be presented as Title within the Message.Content, It should have text character count limit: 50. |
40
+ | `description` | `string` | - | Text to be presented as Description within the Message.Content, It should have text character count limit: 230. |
41
+ | `onClose` | `function` | - | When provided, a close button is displayed and, when clicked, it triggers this function. |
42
+ | `orientation` | `Orientation` | `'horizontal'` | Sets the orientation of the message component. On mobile the orientation is vertical |
43
+
44
+ ### Message.Actions
45
+
46
+ | Property | Type | Default | Description |
47
+ | ------------ | ----------- | ------------------ | ------------------------------------------------ |
48
+ | `children` | `ReactNode` | - | Container to render actions. Button is expected. |
49
+ | `dataTestId` | `string` | `'message-action'` | Customizable test identifier for the action. |
50
+
51
+ ## Stack
52
+
53
+ - [TypeScript](https://www.typescriptlang.org/) for static type checking
54
+ - [React](https://reactjs.org/) — JavaScript library for user interfaces
55
+ - [Emotion](https://emotion.sh/docs/introduction) — for writing css styles with JavaScript
56
+ - [Storybook](https://storybook.js.org/) — UI component environment powered by Vite
57
+ - [Jest](https://jestjs.io/) - JavaScript Testing Framework
58
+ - [React Testing Library](https://testing-library.com/) - to test UI components in a user-centric way
59
+ - [ESLint](https://eslint.org/) for code linting
60
+ - [Prettier](https://prettier.io) for code formatting
61
+ - [Tsup](https://github.com/egoist/tsup) — TypeScript bundler powered by esbuild
62
+ - [Yarn](https://yarnpkg.com/) from managing packages
63
+
64
+ ## Commands
65
+
66
+ - `yarn build` - Build the package
67
+ - `yarn dev` - Run the package locally
68
+ - `yarn lint` - Lint all files within this package
69
+ - `yarn test` - Run all unit tests
70
+ - `yarn test:report` - Open the test coverage report
71
+ - `yarn test:update:snapshot` - Run all unit tests and update the snapshot
72
+
73
+ ## Compilation
74
+
75
+ Running `yarn build` from the root of the package will use [tsup](https://tsup.egoist.dev/) to compile the raw TypeScript and React code to plain JavaScript.
76
+
77
+ The `/dist` folder contains the compiled output.
78
+
79
+ ```bash
80
+ message
81
+ └── dist
82
+ ├── index.d.ts <-- Types
83
+ ├── index.js <-- CommonJS version
84
+ └── index.mjs <-- ES Modules version
85
+ ...
86
+ ```
87
+
88
+ ## Versioning
89
+
90
+ Follows [semantic versioning](https://semver.org/)
91
+
92
+ ## &copy; License
93
+
94
+ Licensed under [MIT License](LICENSE.md)
@@ -0,0 +1,35 @@
1
+ import { CustomTheme } from '@dt-dds/themes';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import { BaseProps, Orientation } from '@dt-dds/react-core';
4
+ import { ReactNode } from 'react';
5
+
6
+ declare const OMessageType: {
7
+ readonly Default: "default";
8
+ readonly Error: "error";
9
+ readonly Info: "informative";
10
+ readonly Success: "success";
11
+ readonly Warning: "warning";
12
+ };
13
+ type MessageType = (typeof OMessageType)[keyof typeof OMessageType];
14
+ interface MessageProps extends BaseProps {
15
+ type: MessageType;
16
+ onClose?: (event: React.MouseEvent<HTMLButtonElement>) => void;
17
+ title?: string;
18
+ description: ReactNode;
19
+ orientation?: Orientation;
20
+ }
21
+ interface ActionsProps extends BaseProps {
22
+ type?: MessageType;
23
+ }
24
+
25
+ declare const Message: {
26
+ ({ children, dataTestId, style, type, onClose, description, title, orientation: propOrientation, }: MessageProps): react_jsx_runtime.JSX.Element;
27
+ Actions({ children, dataTestId, type }: ActionsProps): react_jsx_runtime.JSX.Element;
28
+ };
29
+
30
+ declare module '@emotion/react' {
31
+ interface Theme extends CustomTheme {
32
+ }
33
+ }
34
+
35
+ export { Message };
@@ -0,0 +1,35 @@
1
+ import { CustomTheme } from '@dt-dds/themes';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import { BaseProps, Orientation } from '@dt-dds/react-core';
4
+ import { ReactNode } from 'react';
5
+
6
+ declare const OMessageType: {
7
+ readonly Default: "default";
8
+ readonly Error: "error";
9
+ readonly Info: "informative";
10
+ readonly Success: "success";
11
+ readonly Warning: "warning";
12
+ };
13
+ type MessageType = (typeof OMessageType)[keyof typeof OMessageType];
14
+ interface MessageProps extends BaseProps {
15
+ type: MessageType;
16
+ onClose?: (event: React.MouseEvent<HTMLButtonElement>) => void;
17
+ title?: string;
18
+ description: ReactNode;
19
+ orientation?: Orientation;
20
+ }
21
+ interface ActionsProps extends BaseProps {
22
+ type?: MessageType;
23
+ }
24
+
25
+ declare const Message: {
26
+ ({ children, dataTestId, style, type, onClose, description, title, orientation: propOrientation, }: MessageProps): react_jsx_runtime.JSX.Element;
27
+ Actions({ children, dataTestId, type }: ActionsProps): react_jsx_runtime.JSX.Element;
28
+ };
29
+
30
+ declare module '@emotion/react' {
31
+ interface Theme extends CustomTheme {
32
+ }
33
+ }
34
+
35
+ export { Message };
package/dist/index.js ADDED
@@ -0,0 +1,322 @@
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 __commonJS = (cb, mod) => function __require() {
26
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
27
+ };
28
+ var __export = (target, all) => {
29
+ for (var name in all)
30
+ __defProp(target, name, { get: all[name], enumerable: true });
31
+ };
32
+ var __copyProps = (to, from, except, desc) => {
33
+ if (from && typeof from === "object" || typeof from === "function") {
34
+ for (let key of __getOwnPropNames(from))
35
+ if (!__hasOwnProp.call(to, key) && key !== except)
36
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
37
+ }
38
+ return to;
39
+ };
40
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
41
+ // If the importer is in node compatibility mode or this is not an ESM
42
+ // file that has been converted to a CommonJS file using a Babel-
43
+ // compatible transform (i.e. "__esModule" has not been set), then set
44
+ // "default" to the CommonJS "module.exports" for node compatibility.
45
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
46
+ mod
47
+ ));
48
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
49
+
50
+ // ../box/dist/index.js
51
+ var require_dist = __commonJS({
52
+ "../box/dist/index.js"(exports2, module2) {
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 __export2 = (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 __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
81
+ var index_exports2 = {};
82
+ __export2(index_exports2, {
83
+ Box: () => Box2
84
+ });
85
+ module2.exports = __toCommonJS2(index_exports2);
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
+ // index.ts
105
+ var index_exports = {};
106
+ __export(index_exports, {
107
+ Message: () => Message
108
+ });
109
+ module.exports = __toCommonJS(index_exports);
110
+
111
+ // src/Message.tsx
112
+ var import_react_box = __toESM(require_dist());
113
+ var import_react_core = require("@dt-dds/react-core");
114
+ var import_react_icon = require("@dt-dds/react-icon");
115
+ var import_react_typography = require("@dt-dds/react-typography");
116
+ var import_react = require("@emotion/react");
117
+ var import_react2 = require("react");
118
+
119
+ // src/types/index.ts
120
+ var OMessageType = {
121
+ Default: "default",
122
+ Error: "error",
123
+ Info: "informative",
124
+ Success: "success",
125
+ Warning: "warning"
126
+ };
127
+
128
+ // src/constants/index.ts
129
+ var MESSAGE_ICONS = {
130
+ [OMessageType.Error]: "error",
131
+ [OMessageType.Info]: "info",
132
+ [OMessageType.Success]: "check_circle",
133
+ [OMessageType.Warning]: "warning"
134
+ };
135
+
136
+ // src/Message.styled.ts
137
+ var import_styled = __toESM(require("@emotion/styled"));
138
+ var MessageStyled = import_styled.default.div`
139
+ display: grid;
140
+ width: 100%;
141
+ padding: ${({ theme }) => `${theme.spacing.spacing_40} ${theme.spacing.spacing_50}`};
142
+ border-radius: ${({ theme }) => theme.shape.message};
143
+
144
+ ${({ theme, messageType, orientation }) => {
145
+ const isDefault = messageType === OMessageType.Default;
146
+ const background = isDefault ? theme.palette.surface.light : theme.palette[messageType].light;
147
+ const border = isDefault ? theme.palette.border.medium : theme.palette[messageType].default;
148
+ const baseGrid = `
149
+ grid-template-columns: ${isDefault ? "1fr fit-content(100%)" : "fit-content(100%) 1fr fit-content(100%)"};
150
+ background-color: ${background};
151
+ border: 1px solid ${border};
152
+ gap: ${theme.spacing.spacing_50}
153
+ `;
154
+ if (orientation === "vertical") {
155
+ return `
156
+ ${baseGrid};
157
+ grid-template-columns: 1fr fit-content(100%);
158
+ gap: ${theme.spacing.spacing_30};
159
+
160
+ & > :nth-child(1) {
161
+ grid-column: 1;
162
+ grid-row: 1;
163
+ }
164
+
165
+ ${isDefault ? `
166
+ & > :nth-child(2) {
167
+ grid-column: 2;
168
+ grid-row: 1;
169
+ }
170
+ ` : `
171
+ & > :nth-child(2) {
172
+ grid-column: 1;
173
+ grid-row: 2;
174
+ }
175
+ & > :nth-child(3) {
176
+ grid-column: 2;
177
+ grid-row: 1;
178
+ }
179
+ `}
180
+ `;
181
+ }
182
+ return baseGrid;
183
+ }}
184
+ `;
185
+ var MessageActionsStyled = import_styled.default.div`
186
+ display: flex;
187
+ flex-direction: row;
188
+ gap: ${({ theme }) => theme.spacing.spacing_20};
189
+
190
+ button {
191
+ ${({ theme, messageType }) => {
192
+ const isDefault = messageType === "default";
193
+ const color = isDefault ? theme.palette.content.default : theme.palette[messageType].dark;
194
+ const hoverBg = isDefault ? theme.palette.surface.medium : theme.palette[messageType].medium;
195
+ return `
196
+ color: ${color};
197
+
198
+ &:hover {
199
+ background-color: ${hoverBg};
200
+ color: ${color};
201
+ }
202
+ `;
203
+ }}
204
+ }
205
+ `;
206
+ var MessageButtonCloseStyled = import_styled.default.button`
207
+ ${({ theme, messageType, orientation }) => `
208
+ border: 0;
209
+ cursor: pointer;
210
+ background: transparent;
211
+ display: flex;
212
+ height: fit-content;
213
+
214
+ ${orientation === "horizontal" && "align-self: center"};
215
+
216
+ &:focus-visible {
217
+ outline: 2px solid ${theme.palette.primary.default};
218
+ outline-offset: 1px;
219
+ }
220
+
221
+ &:hover {
222
+ background-color: ${messageType === OMessageType.Default ? theme.palette.surface.medium : theme.palette[messageType].medium};
223
+ }
224
+ `}
225
+ `;
226
+
227
+ // src/Message.tsx
228
+ var import_jsx_runtime = require("react/jsx-runtime");
229
+ var Message = ({
230
+ children,
231
+ dataTestId,
232
+ style,
233
+ type = OMessageType.Default,
234
+ onClose,
235
+ description,
236
+ title,
237
+ orientation: propOrientation = "horizontal"
238
+ }) => {
239
+ const theme = (0, import_react.useTheme)();
240
+ const isDefault = type === OMessageType.Default;
241
+ const isMobile = (0, import_react_core.useMedia)(`(max-width: ${theme.breakpoints.mq2}px)`);
242
+ const orientation = isMobile ? "vertical" : propOrientation || "horizontal";
243
+ const isHorizontal = orientation === "horizontal";
244
+ const isDismissible = !!onClose;
245
+ const textColor = isDefault ? "content.default" : `${type}.dark`;
246
+ const iconColor = isDefault ? theme.palette.content.default : theme.palette[type].dark;
247
+ const clonedChildren = (0, import_react2.useMemo)(
248
+ () => import_react2.Children.map(children, (child) => {
249
+ return child && (0, import_react2.cloneElement)(child, __spreadProps(__spreadValues({}, child.props), {
250
+ type
251
+ }));
252
+ }),
253
+ [children, type]
254
+ );
255
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
256
+ MessageStyled,
257
+ {
258
+ "data-testid": dataTestId != null ? dataTestId : "message",
259
+ messageType: type,
260
+ orientation,
261
+ style,
262
+ children: [
263
+ !isDefault && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
264
+ import_react_icon.Icon,
265
+ {
266
+ code: MESSAGE_ICONS[type],
267
+ color: theme.palette[type].dark,
268
+ "data-testid": "message-icon",
269
+ dataTestId: "message-icon"
270
+ }
271
+ ),
272
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
273
+ import_react_box.Box,
274
+ {
275
+ dataTestId: "message-content",
276
+ style: {
277
+ flexDirection: isHorizontal ? "row" : "column",
278
+ justifyContent: "space-between",
279
+ gap: isHorizontal ? theme.spacing.spacing_30 : theme.spacing.spacing_50,
280
+ alignItems: isHorizontal ? "center" : "start"
281
+ },
282
+ children: [
283
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
284
+ import_react_box.Box,
285
+ {
286
+ style: { alignItems: "flex-start", gap: theme.spacing.spacing_10 },
287
+ children: [
288
+ title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_typography.Typography, { color: textColor, fontStyles: "bodyLgBold", children: title }) : null,
289
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_typography.Typography, { color: textColor, fontStyles: "bodyLgRegular", children: description })
290
+ ]
291
+ }
292
+ ),
293
+ clonedChildren
294
+ ]
295
+ }
296
+ ),
297
+ isDismissible ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
298
+ MessageButtonCloseStyled,
299
+ {
300
+ "aria-label": "Close message",
301
+ messageType: type,
302
+ onClick: onClose,
303
+ orientation,
304
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_icon.Icon, { code: "close", color: iconColor })
305
+ }
306
+ ) : null
307
+ ]
308
+ }
309
+ );
310
+ };
311
+ Message.Actions = ({ children, dataTestId, type }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
312
+ MessageActionsStyled,
313
+ {
314
+ "data-testid": dataTestId != null ? dataTestId : "message-actions",
315
+ messageType: type,
316
+ children
317
+ }
318
+ );
319
+ // Annotate the CommonJS export names for ESM import in node:
320
+ 0 && (module.exports = {
321
+ Message
322
+ });