@dt-dds/react-text-area 1.0.0-beta.23

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 ADDED
@@ -0,0 +1,227 @@
1
+ # @dt-ui/react-text-area
2
+
3
+ ## 1.0.0-beta.23
4
+
5
+ ### Major Changes
6
+
7
+ - refactor!: rename pkg and publish to npmjs
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @dt-dds/react-core@1.0.0-beta.41
13
+ - @dt-dds/react-label-field@1.0.0-beta.37
14
+ - @dt-dds/react-typography@1.0.0-beta.32
15
+
16
+ ## 0.1.0-beta.22
17
+
18
+ ### Patch Changes
19
+
20
+ - refactor: theme typography values
21
+ - Updated dependencies
22
+ - @dt-ui/react-core@0.1.0-beta.40
23
+ - @dt-ui/react-label-field@0.1.0-beta.36
24
+ - @dt-ui/react-typography@0.1.0-beta.31
25
+
26
+ ## 0.1.0-beta.21
27
+
28
+ ### Minor Changes
29
+
30
+ - feat: update shadow theme values
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies
35
+ - @dt-ui/react-core@0.1.0-beta.39
36
+ - @dt-ui/react-label-field@0.1.0-beta.35
37
+ - @dt-ui/react-typography@0.1.0-beta.30
38
+
39
+ ## 0.1.0-beta.20
40
+
41
+ ### Patch Changes
42
+
43
+ - chore: update theme font-styles
44
+ - Updated dependencies
45
+ - @dt-ui/react-core@0.1.0-beta.38
46
+ - @dt-ui/react-label-field@0.1.0-beta.34
47
+ - @dt-ui/react-typography@0.1.0-beta.29
48
+
49
+ ## 0.1.0-beta.19
50
+
51
+ ### Patch Changes
52
+
53
+ - chore: review OSS files
54
+ - Updated dependencies
55
+ - @dt-ui/react-core@0.1.0-beta.37
56
+ - @dt-ui/react-label-field@0.1.0-beta.33
57
+ - @dt-ui/react-typography@0.1.0-beta.28
58
+
59
+ ## 0.1.0-beta.18
60
+
61
+ ### Patch Changes
62
+
63
+ - chore: update contextual colors
64
+ - Updated dependencies
65
+ - @dt-ui/react-core@0.1.0-beta.36
66
+ - @dt-ui/react-label-field@0.1.0-beta.32
67
+ - @dt-ui/react-typography@0.1.0-beta.27
68
+
69
+ ## 0.1.0-beta.17
70
+
71
+ ### Patch Changes
72
+
73
+ - fix: text-area container spacing
74
+
75
+ ## 0.1.0-beta.16
76
+
77
+ ### Patch Changes
78
+
79
+ - fix: text overflow on textarea label
80
+
81
+ ## 0.1.0-beta.15
82
+
83
+ ### Patch Changes
84
+
85
+ - fix: change content.light contextual color
86
+ - Updated dependencies
87
+ - @dt-ui/react-core@0.1.0-beta.35
88
+ - @dt-ui/react-label-field@0.1.0-beta.31
89
+ - @dt-ui/react-typography@0.1.0-beta.26
90
+
91
+ ## 0.1.0-beta.14
92
+
93
+ ### Patch Changes
94
+
95
+ - fix: add accent to colors type
96
+ - Updated dependencies
97
+ - @dt-ui/react-core@0.1.0-beta.34
98
+ - @dt-ui/react-label-field@0.1.0-beta.30
99
+ - @dt-ui/react-typography@0.1.0-beta.25
100
+
101
+ ## 0.1.0-beta.13
102
+
103
+ ### Patch Changes
104
+
105
+ - fix: change button text according to ux
106
+ - Updated dependencies
107
+ - @dt-ui/react-core@0.1.0-beta.33
108
+ - @dt-ui/react-label-field@0.1.0-beta.29
109
+ - @dt-ui/react-typography@0.1.0-beta.24
110
+
111
+ ## 0.1.0-beta.12
112
+
113
+ ### Patch Changes
114
+
115
+ - chore: update contexual colors
116
+ - Updated dependencies
117
+ - @dt-ui/react-core@0.1.0-beta.32
118
+ - @dt-ui/react-label-field@0.1.0-beta.28
119
+ - @dt-ui/react-typography@0.1.0-beta.23
120
+
121
+ ## 0.1.0-beta.11
122
+
123
+ ### Patch Changes
124
+
125
+ - style: update responsive font styles
126
+ - Updated dependencies
127
+ - @dt-ui/react-core@0.1.0-beta.31
128
+ - @dt-ui/react-label-field@0.1.0-beta.27
129
+ - @dt-ui/react-typography@0.1.0-beta.22
130
+
131
+ ## 0.1.0-beta.10
132
+
133
+ ### Minor Changes
134
+
135
+ - feat: add options for variant, bgfill, resize, message
136
+
137
+ ## 0.1.0-beta.9
138
+
139
+ ### Minor Changes
140
+
141
+ - feat: add spinner size 'extra-small' & update specs
142
+
143
+ ### Patch Changes
144
+
145
+ - Updated dependencies
146
+ - @dt-ui/react-core@0.1.0-beta.30
147
+ - @dt-ui/react-label-field@0.1.0-beta.26
148
+ - @dt-ui/react-typography@0.1.0-beta.21
149
+
150
+ ## 0.1.0-beta.8
151
+
152
+ ### Patch Changes
153
+
154
+ - chore: add theme breakpoints
155
+ - Updated dependencies
156
+ - @dt-ui/react-core@0.1.0-beta.29
157
+ - @dt-ui/react-label-field@0.1.0-beta.25
158
+ - @dt-ui/react-typography@0.1.0-beta.20
159
+
160
+ ## 0.1.0-beta.7
161
+
162
+ ### Minor Changes
163
+
164
+ - feat: add id to base props
165
+
166
+ ### Patch Changes
167
+
168
+ - Updated dependencies
169
+ - @dt-ui/react-core@0.1.0-beta.28
170
+ - @dt-ui/react-typography@0.1.0-beta.19
171
+ - @dt-ui/react-label-field@0.1.0-beta.24
172
+
173
+ ## 0.1.0-beta.6
174
+
175
+ ### Minor Changes
176
+
177
+ - feat: change breakpoints values
178
+
179
+ ### Patch Changes
180
+
181
+ - Updated dependencies
182
+ - @dt-ui/react-core@0.1.0-beta.27
183
+ - @dt-ui/react-label-field@0.1.0-beta.23
184
+ - @dt-ui/react-typography@0.1.0-beta.18
185
+
186
+ ## 0.1.0-beta.5
187
+
188
+ ### Patch Changes
189
+
190
+ - fix: replace body to correct one
191
+ - Updated dependencies
192
+ - @dt-ui/react-core@0.1.0-beta.26
193
+ - @dt-ui/react-label-field@0.1.0-beta.22
194
+ - @dt-ui/react-typography@0.1.0-beta.17
195
+
196
+ ## 0.1.0-beta.4
197
+
198
+ ### Patch Changes
199
+
200
+ - chore: add theme colors missing types
201
+ - Updated dependencies
202
+ - @dt-ui/react-core@0.1.0-beta.25
203
+ - @dt-ui/react-label-field@0.1.0-beta.21
204
+ - @dt-ui/react-typography@0.1.0-beta.16
205
+
206
+ ## 0.1.0-beta.3
207
+
208
+ ### Minor Changes
209
+
210
+ - feat: add search functionality to text-field
211
+
212
+ ### Patch Changes
213
+
214
+ - Updated dependencies
215
+ - @dt-ui/react-label-field@0.1.0-beta.20
216
+
217
+ ## 0.1.0-beta.2
218
+
219
+ ### Minor Changes
220
+
221
+ - feat: add text-area input state
222
+
223
+ ## 0.1.0-beta.1
224
+
225
+ ### Patch Changes
226
+
227
+ - chore: text-area independent pkg
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,74 @@
1
+ # TextArea Package
2
+
3
+ Textarea is an input that provides the same features as the text field, but accepts multiple lines of text.
4
+
5
+ ## TextArea Usage
6
+
7
+ ```jsx
8
+ import { TextArea } from '@dt-dds/react';
9
+
10
+ export const App = () => {
11
+ return <TextArea label='My text area' maxLength={200} />;
12
+ };
13
+ ```
14
+
15
+ ## Properties
16
+
17
+ | Property | Type | Default | Description |
18
+ | ---------------- | --------------------------- | ---------------- | ----------------------------------------------------------------------------------------- |
19
+ | `label` | `string` | - | A label to help users understand the scope of the text area. |
20
+ | `name` | `string` | - | The attribute to specify the name of the text area. |
21
+ | `value` | `string` | - | Value of the text area |
22
+ | `dataTestId` | `string` | `label`-textarea | Customizable test identifier |
23
+ | `maxLength` | `number` | | The maximum number of characters that user can enter. |
24
+ | `onChange` | `function` | - | The triggered function when the input change. |
25
+ | `variant` | `[outlined,bottomLine]` | `outlined` | Styles the input with outlined or with bottom line |
26
+ | `hasError` | `boolean` | - | Set error state for text field. |
27
+ | `backgroundFill` | `[default, contrast,light]` | `default` | Styles the input with background color |
28
+ | `enableResize` | `boolean` | `false` | Enables the vertical resizing |
29
+ | `message` | `string` | - | The message to be displayed below the input field. Useful for hints or to display errors. |
30
+
31
+ ## Stack
32
+
33
+ - [TypeScript](https://www.typescriptlang.org/) for static type checking
34
+ - [React](https://reactjs.org/) — JavaScript library for user interfaces
35
+ - [Emotion](https://emotion.sh/docs/introduction) — for writing css styles with JavaScript
36
+ - [Storybook](https://storybook.js.org/) — UI component environment powered by Vite
37
+ - [Jest](https://jestjs.io/) - JavaScript Testing Framework
38
+ - [React Testing Library](https://testing-library.com/) - to test UI components in a user-centric way
39
+ - [ESLint](https://eslint.org/) for code linting
40
+ - [Prettier](https://prettier.io) for code formatting
41
+ - [Tsup](https://github.com/egoist/tsup) — TypeScript bundler powered by esbuild
42
+ - [Yarn](https://yarnpkg.com/) from managing packages
43
+
44
+ ## Commands
45
+
46
+ - `yarn build` - Build the package
47
+ - `yarn dev` - Run the package locally
48
+ - `yarn lint` - Lint all files within this package
49
+ - `yarn test` - Run all unit tests
50
+ - `yarn test:report` - Open the test coverage report
51
+ - `yarn test:update:snapshot` - Run all unit tests and update the snapshot
52
+
53
+ ## Compilation
54
+
55
+ 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.
56
+
57
+ The `/dist` folder contains the compiled output.
58
+
59
+ ```bash
60
+ text-area
61
+ └── dist
62
+ ├── index.d.ts <-- Types
63
+ ├── index.js <-- CommonJS version
64
+ └── index.mjs <-- ES Modules version
65
+ ...
66
+ ```
67
+
68
+ ## Versioning
69
+
70
+ Follows [semantic versioning](https://semver.org/)
71
+
72
+ ## &copy; License
73
+
74
+ Licensed under [MIT License](LICENSE.md)
@@ -0,0 +1,26 @@
1
+ import { BaseProps, Theme } from '@dt-dds/react-core';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import { ComponentPropsWithoutRef } from 'react';
4
+
5
+ type TextAreaVariant = 'outlined' | 'bottom-line';
6
+ type TextAreaBackgroundFill = 'default' | 'contrast' | 'light';
7
+
8
+ interface TextAreaProps extends ComponentPropsWithoutRef<'textarea'>, BaseProps {
9
+ label: string;
10
+ name?: string;
11
+ maxLength?: number;
12
+ enableResize?: boolean;
13
+ value?: string;
14
+ variant?: TextAreaVariant;
15
+ backgroundFill?: TextAreaBackgroundFill;
16
+ hasError?: boolean;
17
+ message?: string;
18
+ }
19
+ declare const TextArea: ({ label, dataTestId, name, value, style, variant, backgroundFill, maxLength, enableResize, disabled, required, hasError, message: messageProp, onChange, ...rest }: TextAreaProps) => react_jsx_runtime.JSX.Element;
20
+
21
+ declare module '@emotion/react' {
22
+ interface Theme extends Theme {
23
+ }
24
+ }
25
+
26
+ export { TextArea, TextAreaProps };
package/dist/index.js ADDED
@@ -0,0 +1,292 @@
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 __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __export = (target, all) => {
38
+ for (var name in all)
39
+ __defProp(target, name, { get: all[name], enumerable: true });
40
+ };
41
+ var __copyProps = (to, from, except, desc) => {
42
+ if (from && typeof from === "object" || typeof from === "function") {
43
+ for (let key of __getOwnPropNames(from))
44
+ if (!__hasOwnProp.call(to, key) && key !== except)
45
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
46
+ }
47
+ return to;
48
+ };
49
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
50
+ // If the importer is in node compatibility mode or this is not an ESM
51
+ // file that has been converted to a CommonJS file using a Babel-
52
+ // compatible transform (i.e. "__esModule" has not been set), then set
53
+ // "default" to the CommonJS "module.exports" for node compatibility.
54
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
55
+ mod
56
+ ));
57
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
+
59
+ // index.ts
60
+ var text_area_exports = {};
61
+ __export(text_area_exports, {
62
+ TextArea: () => TextArea
63
+ });
64
+ module.exports = __toCommonJS(text_area_exports);
65
+
66
+ // src/TextArea.tsx
67
+ var import_react_label_field = require("@dt-dds/react-label-field");
68
+ var import_react_typography = require("@dt-dds/react-typography");
69
+ var import_react = require("react");
70
+
71
+ // src/TextArea.styled.ts
72
+ var import_styled = __toESM(require("@emotion/styled"));
73
+
74
+ // src/constants/helpers.ts
75
+ var getThemedBackgroundFill = (backgroundFill, theme) => ({
76
+ default: theme.palette.surface.default,
77
+ contrast: theme.palette.surface.contrast,
78
+ light: theme.palette.surface.light
79
+ })[backgroundFill] || theme.palette.surface.default;
80
+
81
+ // src/TextArea.styled.ts
82
+ var TextAreaWrapper = import_styled.default.div`
83
+ ${({ theme }) => `
84
+ display: flex;
85
+ flex-direction: column;
86
+ align-items: flex-end;
87
+ position: relative;
88
+ width: 100%;
89
+
90
+ border-style: solid;
91
+ border-width: 0;
92
+ border-color: ${theme.palette.border.dark};
93
+ `}
94
+ `;
95
+ var TextAreaMessageStyled = import_styled.default.div`
96
+ ${({ theme }) => `padding-left: ${theme.spacing["2xs"]}`};
97
+ `;
98
+ var TextAreaMessages = import_styled.default.div`
99
+ display: flex;
100
+ flex-direction: row;
101
+ flex-wrap: wrap;
102
+ justify-content: space-between;
103
+ align-items: baseline;
104
+ width: 100%;
105
+ `;
106
+ var TextAreaStyled = import_styled.default.textarea`
107
+ ${({ theme, enableResize = false, backgroundFill }) => `
108
+ ${theme.fontStyles.body1}
109
+
110
+ background-color: ${getThemedBackgroundFill(backgroundFill, theme)};
111
+
112
+ border-style: none;
113
+ width: 100%;
114
+ color: ${theme.palette.content.dark};
115
+ resize: ${enableResize ? "vertical" : "none"};
116
+ outline: none;
117
+ padding-right: 10px;
118
+ `}
119
+ `;
120
+ var ContainerStyled = import_styled.default.div`
121
+ ${({ theme, variant, hasError = false, backgroundFill }) => {
122
+ const borderColor = hasError ? theme.palette.error.default : theme.palette.primary.default;
123
+ return `
124
+ background-color: ${getThemedBackgroundFill(backgroundFill, theme)};
125
+ position: relative;
126
+ padding: 25px 0px 0px 10px;
127
+ width: 100%;
128
+
129
+ ${variant === "outlined" ? `border-radius: ${theme.shape.formField};
130
+ border: 1px solid ${hasError ? theme.palette.error.default : theme.palette.border.default};
131
+ &:focus-within, &:hover { { border: 1px solid ${borderColor}};
132
+ ` : `border-radius: ${theme.shape.formField} ${theme.shape.formField} 0 0;
133
+ border-bottom: 1px solid ${hasError ? theme.palette.error.default : theme.palette.border.default};
134
+ &:focus-within, &:hover { { border-bottom: 1px solid ${borderColor}};
135
+ `};
136
+
137
+ ${variant === "outlined" ? "border-width: 1px" : "border-width: 0 0 1px"};
138
+ `;
139
+ }}
140
+ `;
141
+
142
+ // src/TextArea.tsx
143
+ var import_jsx_runtime = require("react/jsx-runtime");
144
+ var TextArea = (_a) => {
145
+ var _b = _a, {
146
+ label,
147
+ dataTestId,
148
+ name,
149
+ value,
150
+ style,
151
+ variant = "outlined",
152
+ backgroundFill = "default",
153
+ maxLength,
154
+ enableResize = false,
155
+ disabled = false,
156
+ required = false,
157
+ hasError = false,
158
+ message: messageProp = "",
159
+ onChange = () => {
160
+ }
161
+ } = _b, rest = __objRest(_b, [
162
+ "label",
163
+ "dataTestId",
164
+ "name",
165
+ "value",
166
+ "style",
167
+ "variant",
168
+ "backgroundFill",
169
+ "maxLength",
170
+ "enableResize",
171
+ "disabled",
172
+ "required",
173
+ "hasError",
174
+ "message",
175
+ "onChange"
176
+ ]);
177
+ const [chars, setChars] = (0, import_react.useState)(0);
178
+ const [activeInput, setActiveInput] = (0, import_react.useState)(false);
179
+ const [inputValue, setInputValue] = (0, import_react.useState)("");
180
+ const [hasRequiredError, setHasRequiredError] = (0, import_react.useState)(false);
181
+ (0, import_react.useEffect)(() => {
182
+ if (!!value) {
183
+ setInputValue(value);
184
+ setActiveInput(true);
185
+ setChars(value.length);
186
+ setHasRequiredError(false);
187
+ } else {
188
+ setInputValue("");
189
+ }
190
+ }, [value]);
191
+ const handleChange = (evt) => {
192
+ setInputValue(evt.target.value);
193
+ setHasRequiredError(false);
194
+ setChars(evt.target.value.length);
195
+ if (onChange) {
196
+ onChange(evt);
197
+ }
198
+ };
199
+ const onFocus = (event) => {
200
+ setActiveInput(true);
201
+ if (rest.onFocus) {
202
+ rest.onFocus(event);
203
+ }
204
+ };
205
+ const onBlur = (event) => {
206
+ const isEmptyOrOnlySpaces = event.currentTarget.value.trim().length === 0;
207
+ if (isEmptyOrOnlySpaces) {
208
+ setActiveInput(false);
209
+ if (required) {
210
+ setHasRequiredError(true);
211
+ }
212
+ }
213
+ if (rest.onBlur) {
214
+ rest.onBlur(event);
215
+ }
216
+ };
217
+ const testId = dataTestId != null ? dataTestId : `${label.replaceAll(" ", "-").toLocaleLowerCase()}-textarea`;
218
+ const messageColor = disabled ? "content.light" : "content.medium";
219
+ const showError = hasError || hasRequiredError;
220
+ const message = messageProp;
221
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextAreaWrapper, { children: [
222
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
223
+ import_react_label_field.LabelField,
224
+ {
225
+ hasError: showError,
226
+ htmlFor: testId,
227
+ isActive: activeInput,
228
+ isDisabled: disabled,
229
+ isRequired: required,
230
+ style: { zIndex: 1 },
231
+ children: label
232
+ }
233
+ ),
234
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
235
+ ContainerStyled,
236
+ {
237
+ backgroundFill,
238
+ "data-testid": "textarea-container",
239
+ hasError: showError,
240
+ variant,
241
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
242
+ TextAreaStyled,
243
+ __spreadProps(__spreadValues({
244
+ backgroundFill,
245
+ "data-error": showError,
246
+ disabled,
247
+ enableResize,
248
+ id: testId,
249
+ maxLength,
250
+ name,
251
+ style,
252
+ value: inputValue
253
+ }, rest), {
254
+ onBlur,
255
+ onChange: handleChange,
256
+ onFocus
257
+ })
258
+ )
259
+ }
260
+ ),
261
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(TextAreaMessages, { children: [
262
+ message ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TextAreaMessageStyled, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
263
+ import_react_typography.Typography,
264
+ {
265
+ color: showError ? "error.default" : messageColor,
266
+ element: "span",
267
+ fontStyles: "body3",
268
+ children: message
269
+ }
270
+ ) }) : null,
271
+ maxLength ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
272
+ import_react_typography.Typography,
273
+ {
274
+ color: "content.medium",
275
+ element: "span",
276
+ fontStyles: "body2",
277
+ id: testId,
278
+ style: { marginLeft: "auto" },
279
+ children: [
280
+ chars,
281
+ " / ",
282
+ maxLength
283
+ ]
284
+ }
285
+ ) : null
286
+ ] })
287
+ ] });
288
+ };
289
+ // Annotate the CommonJS export names for ESM import in node:
290
+ 0 && (module.exports = {
291
+ TextArea
292
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,261 @@
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
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+
33
+ // src/TextArea.tsx
34
+ import { LabelField } from "@dt-dds/react-label-field";
35
+ import { Typography } from "@dt-dds/react-typography";
36
+ import {
37
+ useEffect,
38
+ useState
39
+ } from "react";
40
+
41
+ // src/TextArea.styled.ts
42
+ import styled from "@emotion/styled";
43
+
44
+ // src/constants/helpers.ts
45
+ var getThemedBackgroundFill = (backgroundFill, theme) => ({
46
+ default: theme.palette.surface.default,
47
+ contrast: theme.palette.surface.contrast,
48
+ light: theme.palette.surface.light
49
+ })[backgroundFill] || theme.palette.surface.default;
50
+
51
+ // src/TextArea.styled.ts
52
+ var TextAreaWrapper = styled.div`
53
+ ${({ theme }) => `
54
+ display: flex;
55
+ flex-direction: column;
56
+ align-items: flex-end;
57
+ position: relative;
58
+ width: 100%;
59
+
60
+ border-style: solid;
61
+ border-width: 0;
62
+ border-color: ${theme.palette.border.dark};
63
+ `}
64
+ `;
65
+ var TextAreaMessageStyled = styled.div`
66
+ ${({ theme }) => `padding-left: ${theme.spacing["2xs"]}`};
67
+ `;
68
+ var TextAreaMessages = styled.div`
69
+ display: flex;
70
+ flex-direction: row;
71
+ flex-wrap: wrap;
72
+ justify-content: space-between;
73
+ align-items: baseline;
74
+ width: 100%;
75
+ `;
76
+ var TextAreaStyled = styled.textarea`
77
+ ${({ theme, enableResize = false, backgroundFill }) => `
78
+ ${theme.fontStyles.body1}
79
+
80
+ background-color: ${getThemedBackgroundFill(backgroundFill, theme)};
81
+
82
+ border-style: none;
83
+ width: 100%;
84
+ color: ${theme.palette.content.dark};
85
+ resize: ${enableResize ? "vertical" : "none"};
86
+ outline: none;
87
+ padding-right: 10px;
88
+ `}
89
+ `;
90
+ var ContainerStyled = styled.div`
91
+ ${({ theme, variant, hasError = false, backgroundFill }) => {
92
+ const borderColor = hasError ? theme.palette.error.default : theme.palette.primary.default;
93
+ return `
94
+ background-color: ${getThemedBackgroundFill(backgroundFill, theme)};
95
+ position: relative;
96
+ padding: 25px 0px 0px 10px;
97
+ width: 100%;
98
+
99
+ ${variant === "outlined" ? `border-radius: ${theme.shape.formField};
100
+ border: 1px solid ${hasError ? theme.palette.error.default : theme.palette.border.default};
101
+ &:focus-within, &:hover { { border: 1px solid ${borderColor}};
102
+ ` : `border-radius: ${theme.shape.formField} ${theme.shape.formField} 0 0;
103
+ border-bottom: 1px solid ${hasError ? theme.palette.error.default : theme.palette.border.default};
104
+ &:focus-within, &:hover { { border-bottom: 1px solid ${borderColor}};
105
+ `};
106
+
107
+ ${variant === "outlined" ? "border-width: 1px" : "border-width: 0 0 1px"};
108
+ `;
109
+ }}
110
+ `;
111
+
112
+ // src/TextArea.tsx
113
+ import { jsx, jsxs } from "react/jsx-runtime";
114
+ var TextArea = (_a) => {
115
+ var _b = _a, {
116
+ label,
117
+ dataTestId,
118
+ name,
119
+ value,
120
+ style,
121
+ variant = "outlined",
122
+ backgroundFill = "default",
123
+ maxLength,
124
+ enableResize = false,
125
+ disabled = false,
126
+ required = false,
127
+ hasError = false,
128
+ message: messageProp = "",
129
+ onChange = () => {
130
+ }
131
+ } = _b, rest = __objRest(_b, [
132
+ "label",
133
+ "dataTestId",
134
+ "name",
135
+ "value",
136
+ "style",
137
+ "variant",
138
+ "backgroundFill",
139
+ "maxLength",
140
+ "enableResize",
141
+ "disabled",
142
+ "required",
143
+ "hasError",
144
+ "message",
145
+ "onChange"
146
+ ]);
147
+ const [chars, setChars] = useState(0);
148
+ const [activeInput, setActiveInput] = useState(false);
149
+ const [inputValue, setInputValue] = useState("");
150
+ const [hasRequiredError, setHasRequiredError] = useState(false);
151
+ useEffect(() => {
152
+ if (!!value) {
153
+ setInputValue(value);
154
+ setActiveInput(true);
155
+ setChars(value.length);
156
+ setHasRequiredError(false);
157
+ } else {
158
+ setInputValue("");
159
+ }
160
+ }, [value]);
161
+ const handleChange = (evt) => {
162
+ setInputValue(evt.target.value);
163
+ setHasRequiredError(false);
164
+ setChars(evt.target.value.length);
165
+ if (onChange) {
166
+ onChange(evt);
167
+ }
168
+ };
169
+ const onFocus = (event) => {
170
+ setActiveInput(true);
171
+ if (rest.onFocus) {
172
+ rest.onFocus(event);
173
+ }
174
+ };
175
+ const onBlur = (event) => {
176
+ const isEmptyOrOnlySpaces = event.currentTarget.value.trim().length === 0;
177
+ if (isEmptyOrOnlySpaces) {
178
+ setActiveInput(false);
179
+ if (required) {
180
+ setHasRequiredError(true);
181
+ }
182
+ }
183
+ if (rest.onBlur) {
184
+ rest.onBlur(event);
185
+ }
186
+ };
187
+ const testId = dataTestId != null ? dataTestId : `${label.replaceAll(" ", "-").toLocaleLowerCase()}-textarea`;
188
+ const messageColor = disabled ? "content.light" : "content.medium";
189
+ const showError = hasError || hasRequiredError;
190
+ const message = messageProp;
191
+ return /* @__PURE__ */ jsxs(TextAreaWrapper, { children: [
192
+ /* @__PURE__ */ jsx(
193
+ LabelField,
194
+ {
195
+ hasError: showError,
196
+ htmlFor: testId,
197
+ isActive: activeInput,
198
+ isDisabled: disabled,
199
+ isRequired: required,
200
+ style: { zIndex: 1 },
201
+ children: label
202
+ }
203
+ ),
204
+ /* @__PURE__ */ jsx(
205
+ ContainerStyled,
206
+ {
207
+ backgroundFill,
208
+ "data-testid": "textarea-container",
209
+ hasError: showError,
210
+ variant,
211
+ children: /* @__PURE__ */ jsx(
212
+ TextAreaStyled,
213
+ __spreadProps(__spreadValues({
214
+ backgroundFill,
215
+ "data-error": showError,
216
+ disabled,
217
+ enableResize,
218
+ id: testId,
219
+ maxLength,
220
+ name,
221
+ style,
222
+ value: inputValue
223
+ }, rest), {
224
+ onBlur,
225
+ onChange: handleChange,
226
+ onFocus
227
+ })
228
+ )
229
+ }
230
+ ),
231
+ /* @__PURE__ */ jsxs(TextAreaMessages, { children: [
232
+ message ? /* @__PURE__ */ jsx(TextAreaMessageStyled, { children: /* @__PURE__ */ jsx(
233
+ Typography,
234
+ {
235
+ color: showError ? "error.default" : messageColor,
236
+ element: "span",
237
+ fontStyles: "body3",
238
+ children: message
239
+ }
240
+ ) }) : null,
241
+ maxLength ? /* @__PURE__ */ jsxs(
242
+ Typography,
243
+ {
244
+ color: "content.medium",
245
+ element: "span",
246
+ fontStyles: "body2",
247
+ id: testId,
248
+ style: { marginLeft: "auto" },
249
+ children: [
250
+ chars,
251
+ " / ",
252
+ maxLength
253
+ ]
254
+ }
255
+ ) : null
256
+ ] })
257
+ ] });
258
+ };
259
+ export {
260
+ TextArea
261
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@dt-dds/react-text-area",
3
+ "version": "1.0.0-beta.23",
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-typography": "1.0.0-beta.32",
25
+ "@dt-dds/react-label-field": "1.0.0-beta.37"
26
+ },
27
+ "devDependencies": {
28
+ "@babel/core": "^7.22.9",
29
+ "@babel/preset-env": "^7.22.9",
30
+ "@babel/preset-react": "^7.22.5",
31
+ "@babel/preset-typescript": "^7.23.3",
32
+ "@emotion/babel-plugin": "^11.11.0",
33
+ "@emotion/css": "^11.7.1",
34
+ "@emotion/jest": "^11.10.0",
35
+ "@emotion/react": "^11.8.2",
36
+ "@emotion/styled": "^11.8.1",
37
+ "@types/react": "^18.0.9",
38
+ "@types/react-dom": "^18.0.4",
39
+ "babel-loader": "^8.3.0",
40
+ "eslint-config-custom": "*",
41
+ "eslint-plugin-storybook": "^9.1.0",
42
+ "jest-config": "*",
43
+ "react": "^18.1.0",
44
+ "react-dom": "^18.2.0",
45
+ "tsconfig": "*",
46
+ "tsup": "^6.6.3",
47
+ "typescript": "^4.5.3"
48
+ },
49
+ "peerDependencies": {
50
+ "@emotion/css": "^11.7.1",
51
+ "@emotion/react": "^11.8.2",
52
+ "@emotion/styled": "^11.8.1",
53
+ "react": ">=17.0.2",
54
+ "react-dom": ">=17.0.2"
55
+ }
56
+ }