@dr.pogodin/react-utils 1.44.8 → 1.44.9

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.
@@ -1,8 +1,9 @@
1
- import { type ChangeEventHandler, type FocusEventHandler, type KeyboardEventHandler } from 'react';
1
+ import { type ChangeEventHandler, type FocusEventHandler, type KeyboardEventHandler, type ReactNode } from 'react';
2
2
  import { type Theme } from '@dr.pogodin/react-themes';
3
- type ThemeKeyT = 'container' | 'hidden' | 'label' | 'textarea';
3
+ type ThemeKeyT = 'container' | 'error' | 'errorMessage' | 'hidden' | 'label' | 'textarea';
4
4
  type Props = {
5
5
  disabled?: boolean;
6
+ error?: ReactNode;
6
7
  label?: string;
7
8
  onBlur?: FocusEventHandler<HTMLTextAreaElement>;
8
9
  onChange?: ChangeEventHandler<HTMLTextAreaElement>;
@@ -1,6 +1,8 @@
1
1
  export declare const ad: string;
2
2
  export declare const container: string;
3
3
  export declare const context: string;
4
+ export declare const error: string;
5
+ export declare const errorMessage: string;
4
6
  export declare const hidden: string;
5
7
  export declare const hoc: string;
6
8
  export declare const label: string;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.44.8",
2
+ "version": "1.44.9",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-setup": "bin/setup.js"
@@ -90,7 +90,7 @@
90
90
  "identity-obj-proxy": "^3.0.0",
91
91
  "jest": "^30.1.3",
92
92
  "jest-environment-jsdom": "^30.1.2",
93
- "memfs": "^4.42.0",
93
+ "memfs": "^4.46.0",
94
94
  "mini-css-extract-plugin": "^2.9.4",
95
95
  "mockdate": "^3.0.5",
96
96
  "nodelist-foreach-polyfill": "^1.2.0",
@@ -101,7 +101,7 @@
101
101
  "react-refresh": "^0.17.0",
102
102
  "regenerator-runtime": "^0.14.1",
103
103
  "resolve-url-loader": "^5.0.0",
104
- "sass": "^1.92.1",
104
+ "sass": "^1.93.2",
105
105
  "sass-loader": "^16.0.5",
106
106
  "sitemap": "^8.0.0",
107
107
  "source-map-loader": "^5.0.0",
@@ -113,7 +113,7 @@
113
113
  "typed-scss-modules": "^8.1.1",
114
114
  "typescript": "^5.9.2",
115
115
  "webpack": "^5.101.3",
116
- "webpack-dev-middleware": "^7.4.3",
116
+ "webpack-dev-middleware": "^7.4.4",
117
117
  "webpack-hot-middleware": "^2.26.1",
118
118
  "webpack-merge": "^6.0.1",
119
119
  "workbox-core": "^7.3.0",
@@ -3,6 +3,7 @@ import {
3
3
  type FocusEventHandler,
4
4
  type FunctionComponent,
5
5
  type KeyboardEventHandler,
6
+ type ReactNode,
6
7
  useEffect,
7
8
  useLayoutEffect,
8
9
  useRef,
@@ -13,10 +14,12 @@ import themed, { type Theme } from '@dr.pogodin/react-themes';
13
14
 
14
15
  import defaultTheme from './style.scss';
15
16
 
16
- type ThemeKeyT = 'container' | 'hidden' | 'label' | 'textarea';
17
+ type ThemeKeyT = 'container' | 'error' | 'errorMessage' | 'hidden' | 'label'
18
+ | 'textarea';
17
19
 
18
20
  type Props = {
19
21
  disabled?: boolean;
22
+ error?: ReactNode;
20
23
  label?: string;
21
24
  onBlur?: FocusEventHandler<HTMLTextAreaElement>;
22
25
  onChange?: ChangeEventHandler<HTMLTextAreaElement>;
@@ -29,6 +32,7 @@ type Props = {
29
32
 
30
33
  const TextArea: FunctionComponent<Props> = ({
31
34
  disabled,
35
+ error,
32
36
  label,
33
37
  onBlur,
34
38
  onChange,
@@ -74,9 +78,12 @@ const TextArea: FunctionComponent<Props> = ({
74
78
  if (el) setHeight(el.scrollHeight);
75
79
  }, [localValue]);
76
80
 
81
+ let containerClassName = theme.container;
82
+ if (error) containerClassName += ` ${theme.error}`;
83
+
77
84
  return (
78
85
  <div
79
- className={theme.container}
86
+ className={containerClassName}
80
87
  onFocus={() => {
81
88
  textAreaRef.current?.focus();
82
89
  }}
@@ -122,6 +129,9 @@ const TextArea: FunctionComponent<Props> = ({
122
129
  style={{ height }}
123
130
  value={localValue}
124
131
  />
132
+ {error && error !== true
133
+ ? <div className={theme.errorMessage}>{error}</div>
134
+ : null}
125
135
  </div>
126
136
  );
127
137
  };
@@ -4,6 +4,8 @@
4
4
  .context,
5
5
  .ad.hoc {
6
6
  &.container {
7
+ display: inline-flex;
8
+ flex-wrap: wrap;
7
9
  margin: 0.1em;
8
10
  position: relative;
9
11
  }
@@ -42,6 +44,21 @@
42
44
  }
43
45
  }
44
46
 
47
+ &.error &.textarea {
48
+ border-color: red;
49
+
50
+ &:focus { box-shadow: 0 0 3px 1px orangered }
51
+ }
52
+
53
+ &.errorMessage {
54
+ color: red;
55
+ font-size: 0.8em;
56
+ font-style: italic;
57
+ padding-right: 0.6em;
58
+ text-align: right;
59
+ width: 100%;
60
+ }
61
+
45
62
  &.hidden {
46
63
  // NOTE: We hide it this way, as setting "display: none" will interfere
47
64
  // with measurements, making the hidden input height zero.