@peassoft/mnr-web-ui-kit 2.2.0 → 2.3.0

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,15 +1,32 @@
1
1
  import { type JSX } from 'react';
2
2
  import './styles.css';
3
3
  type Props = {
4
- /** Type of the inner input element */
4
+ /**
5
+ * Type of the inner input element
6
+ *
7
+ * @default text
8
+ */
5
9
  type?: 'text' | 'email' | 'password';
6
10
  /** Label */
7
11
  label: string;
12
+ /**
13
+ * Description text placed under the input field. Can be used to provide additional
14
+ * information about the input field, for example, about the expected format of the value.
15
+ */
16
+ description?: string;
17
+ /**
18
+ * Whether the input field is required. If true, an asterisk will be displayed next to the label.
19
+ */
20
+ required?: boolean;
8
21
  /** autocomplete attribute */
9
22
  autocompleteAttribute?: string;
10
23
  /** disabled attribule */
11
24
  disabled?: boolean;
12
- /** Width in any CSS length value */
25
+ /**
26
+ * Width in any CSS length value
27
+ *
28
+ * @default 100%
29
+ */
13
30
  width?: string;
14
31
  /** Error message */
15
32
  errorMessage?: string;
@@ -1,11 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState, useCallback, useEffect } from 'react';
2
+ import { useState, useCallback, useMemo, useEffect, useId } from 'react';
3
3
  import './styles.css';
4
4
  import processKeyDown from './process-key-down.js';
5
5
  export function InputField(props) {
6
6
  const {
7
7
  type = 'text',
8
8
  label,
9
+ description,
10
+ required,
9
11
  autocompleteAttribute,
10
12
  disabled = false,
11
13
  width = '100%',
@@ -18,6 +20,14 @@ export function InputField(props) {
18
20
  onBlur
19
21
  } = props;
20
22
  const [isCapslockOn, setIsCapslockOn] = useState(false);
23
+ const descriptionId = useId();
24
+ const errorMessageId = useId();
25
+ const inputDescribedByAttribute = useMemo(() => {
26
+ let returnValue = '';
27
+ if (errorMessage) returnValue = errorMessageId;
28
+ if (description) returnValue += ` ${descriptionId}`;
29
+ return returnValue || undefined;
30
+ }, [errorMessage, description, errorMessageId, descriptionId]);
21
31
  const handleChange = useCallback(e => onChange(e.target.value), [onChange]);
22
32
  const handleKeyDown = useCallback(e => processKeyDown(e, onTab, onShiftTab, onBlur), [onTab, onShiftTab, onBlur]);
23
33
  useEffect(() => {
@@ -52,9 +62,13 @@ export function InputField(props) {
52
62
  },
53
63
  children: [_jsxs("label", {
54
64
  className: 'uikit_InputField_innerCont',
55
- children: [_jsx("span", {
65
+ children: [_jsxs("span", {
56
66
  className: 'uikit_InputField_label',
57
- children: label
67
+ children: [label, required && _jsx("span", {
68
+ className: 'uikit_InputField_required',
69
+ "aria-hidden": 'true',
70
+ children: "\u00A0*"
71
+ })]
58
72
  }), _jsx("input", {
59
73
  ref: ref,
60
74
  className: 'uikit_InputField_input',
@@ -62,6 +76,8 @@ export function InputField(props) {
62
76
  autoComplete: autocompleteAttribute,
63
77
  disabled: disabled,
64
78
  value: value,
79
+ "aria-describedby": inputDescribedByAttribute,
80
+ "aria-required": required || undefined,
65
81
  onChange: handleChange,
66
82
  onKeyDown: handleKeyDown,
67
83
  onBlur: onBlur || undefined
@@ -79,9 +95,17 @@ export function InputField(props) {
79
95
  }), _jsx("span", {
80
96
  children: "CapsLock"
81
97
  })]
82
- }), !!errorMessage && _jsx("div", {
83
- className: 'uikit_InputField_errorMsg',
84
- children: errorMessage
98
+ }), _jsx("div", {
99
+ "aria-live": 'assertive',
100
+ children: !!errorMessage && _jsx("div", {
101
+ className: 'uikit_InputField_errorMsg',
102
+ id: errorMessageId,
103
+ children: errorMessage
104
+ })
105
+ }), !!description && _jsx("div", {
106
+ className: 'uikit_InputField_description',
107
+ id: descriptionId,
108
+ children: description
85
109
  })]
86
110
  });
87
111
  }
@@ -11,13 +11,23 @@
11
11
  .uikit_InputField_label {
12
12
  display: block;
13
13
  margin-bottom: 0.25em;
14
- color: #757575;
14
+ color: #737373;
15
15
  width: 100%;
16
16
  }
17
17
 
18
18
  @media (prefers-color-scheme: dark) {
19
19
  .uikit_InputField_label {
20
- color: #979797;
20
+ color: #acacac;
21
+ }
22
+ }
23
+
24
+ .uikit_InputField_required {
25
+ color: #a7241b;
26
+ }
27
+
28
+ @media (prefers-color-scheme: dark) {
29
+ .uikit_InputField_required {
30
+ color: #fb827a;
21
31
  }
22
32
  }
23
33
 
@@ -63,7 +73,7 @@
63
73
 
64
74
  @media (prefers-color-scheme: dark) {
65
75
  .uikit_InputField_capslockMsg {
66
- color: #979797;
76
+ color: #acacac;
67
77
  }
68
78
  }
69
79
 
@@ -89,3 +99,15 @@
89
99
  color: #fb827a;
90
100
  }
91
101
  }
102
+
103
+ .uikit_InputField_description {
104
+ color: #737373;
105
+ font-size: 0.85rem;
106
+ margin-top: 0.2em;
107
+ }
108
+
109
+ @media (prefers-color-scheme: dark) {
110
+ .uikit_InputField_description {
111
+ color: #acacac;
112
+ }
113
+ }
@@ -20,6 +20,9 @@ export function TextButton(props) {
20
20
  tabIndex: tabIndex,
21
21
  onClick: handleClick,
22
22
  onKeyDown: handleKeyDown,
23
- children: label
23
+ children: _jsx("span", {
24
+ className: 'uikit_TextButton_innerWrapper',
25
+ children: label
26
+ })
24
27
  });
25
28
  }
@@ -1,8 +1,7 @@
1
1
  .uikit_TextButton_btn {
2
2
  display: inline;
3
3
  appearance: none;
4
- border: 0;
5
- border-bottom: 1px solid currentColor;
4
+ border: none;
6
5
  color: #3f72af;
7
6
  background-color: transparent;
8
7
  font-family: inherit;
@@ -11,6 +10,7 @@
11
10
  padding: 0;
12
11
  cursor: pointer;
13
12
  outline-offset: 3px;
13
+ text-align: start;
14
14
  }
15
15
 
16
16
  @media (prefers-color-scheme: dark) {
@@ -18,3 +18,10 @@
18
18
  color: #dbe2ef;
19
19
  }
20
20
  }
21
+
22
+ .uikit_TextButton_innerWrapper {
23
+ border-bottom: 1px solid currentColor;
24
+ border-top: 1px solid transparent;
25
+ padding-bottom: 0.125em;
26
+ line-height: 1.4;
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peassoft/mnr-web-ui-kit",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Peassoft web UI kit for MNR web applications",
5
5
  "type": "module",
6
6
  "exports": {
@@ -46,7 +46,7 @@
46
46
  "react-dom": "^19.0.0",
47
47
  "storybook": "^10.1.4",
48
48
  "stylelint": "^17.0.0",
49
- "typescript": "^5.2.2",
49
+ "typescript": "^6.0.2",
50
50
  "vitest": "^4.0.7"
51
51
  },
52
52
  "peerDependencies": {