@peassoft/mnr-web-ui-kit 0.1.0 → 0.1.2

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,6 +1,6 @@
1
1
  .uikit_ButtonRadioGroup_label {
2
2
  margin: 0 0 0.5em;
3
- color: #848484;
3
+ color: #757575;
4
4
  }
5
5
 
6
6
  .uikit_ButtonRadioGroup_cont {
@@ -7,6 +7,8 @@ type Props = {
7
7
  label: string;
8
8
  /** autocomplete attribute */
9
9
  autocompleteAttribute?: string;
10
+ /** disabled attribule */
11
+ disabled?: boolean;
10
12
  /** Width in any CSS length value */
11
13
  width?: string;
12
14
  /** Error message */
@@ -15,7 +17,13 @@ type Props = {
15
17
  value: string;
16
18
  /** Ref */
17
19
  ref?: React.RefObject<HTMLInputElement | null>;
18
- /** onChange callback */
20
+ /**
21
+ * onChange callback
22
+ *
23
+ * For disabled state (when passing `disabled` attribute), pass a noop function
24
+ * (like, `() => {}`) to prevent React's warnings about controlled components
25
+ * (with `value` prop) having no `onChange` handler.
26
+ */
19
27
  onChange: (newValue: string) => unknown;
20
28
  /** Optional handler of Tab key press */
21
29
  onTab?: () => unknown;
@@ -7,6 +7,7 @@ export function InputField(props) {
7
7
  type = 'text',
8
8
  label,
9
9
  autocompleteAttribute,
10
+ disabled = false,
10
11
  width = '100%',
11
12
  errorMessage,
12
13
  value,
@@ -59,6 +60,7 @@ export function InputField(props) {
59
60
  className: 'uikit_InputField_input',
60
61
  type: type,
61
62
  autoComplete: autocompleteAttribute,
63
+ disabled: disabled,
62
64
  value: value,
63
65
  onChange: handleChange,
64
66
  onKeyDown: handleKeyDown,
@@ -11,7 +11,7 @@
11
11
  .uikit_InputField_label {
12
12
  display: block;
13
13
  margin-bottom: 0.25em;
14
- color: #848484;
14
+ color: #757575;
15
15
  width: 100%;
16
16
  }
17
17
 
@@ -28,6 +28,11 @@
28
28
  font-family: inherit;
29
29
  }
30
30
 
31
+ .uikit_InputField_input:disabled {
32
+ color: #848484;
33
+ background-color: #efefef;
34
+ }
35
+
31
36
  .uikit_InputField_capslockMsg {
32
37
  display: flex;
33
38
  gap: .5em;
@@ -1,6 +1,6 @@
1
1
  .uikit_PlainSelect_label {
2
2
  margin: 0;
3
- color: #848484;
3
+ color: #757575;
4
4
  }
5
5
 
6
6
  .uikit_PlainSelect_cont {
@@ -36,6 +36,6 @@
36
36
 
37
37
  .uikit_PlainSelect_description {
38
38
  margin-top: 0.5em;
39
- color: #848484;
39
+ color: #757575;
40
40
  font-size: 87.5%;
41
41
  }
@@ -0,0 +1,35 @@
1
+ import { type JSX } from 'react';
2
+ import './styles.css';
3
+ export type SelectItem = {
4
+ id: string;
5
+ value: string;
6
+ };
7
+ type Props = {
8
+ /** Label */
9
+ label: string;
10
+ /** Width in any CSS length value */
11
+ width?: string;
12
+ /** Error message */
13
+ errorMessage?: string;
14
+ /** Collection of items */
15
+ items: SelectItem[];
16
+ /** Controlled selected item ID */
17
+ selectedItemId: string | null;
18
+ /** Ref */
19
+ ref?: React.RefObject<HTMLSelectElement | null>;
20
+ /** onChange callback */
21
+ onChange: (id: string) => unknown;
22
+ /** Optional handler of Tab key press */
23
+ onTab?: () => unknown;
24
+ /** Optional handler of Shift + Tab key press */
25
+ onShiftTab?: () => unknown;
26
+ /** Optional handler of the input onBlur event */
27
+ onBlur?: () => unknown;
28
+ };
29
+ /**
30
+ * Select component.
31
+ *
32
+ * Can only be used in controlled mode.
33
+ */
34
+ export declare function Select(props: Props): JSX.Element;
35
+ export {};
@@ -0,0 +1,67 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback } from 'react';
3
+ import './styles.css';
4
+ import processKeyDown from './process-key-down.js';
5
+ /**
6
+ * Select component.
7
+ *
8
+ * Can only be used in controlled mode.
9
+ */
10
+ export function Select(props) {
11
+ const {
12
+ label,
13
+ width = '100%',
14
+ errorMessage,
15
+ items,
16
+ selectedItemId,
17
+ ref,
18
+ onChange,
19
+ onTab,
20
+ onShiftTab,
21
+ onBlur
22
+ } = props;
23
+ const handleChange = useCallback(e => {
24
+ onChange(e.target.value);
25
+ }, [onChange]);
26
+ const handleKeyDown = useCallback(e => processKeyDown(e, onTab, onShiftTab, onBlur), [onTab, onShiftTab, onBlur]);
27
+ return _jsxs("div", {
28
+ className: 'uikit_Select_cont',
29
+ style: {
30
+ width
31
+ },
32
+ children: [_jsxs("label", {
33
+ className: 'uikit_Select_innerCont',
34
+ children: [_jsx("span", {
35
+ className: 'uikit_Select_label',
36
+ children: label
37
+ }), _jsxs("div", {
38
+ className: 'uikit_Select_selectCont',
39
+ children: [_jsxs("select", {
40
+ ref: ref,
41
+ className: 'uikit_Select_input',
42
+ value: selectedItemId ?? undefined,
43
+ onChange: handleChange,
44
+ onKeyDown: handleKeyDown,
45
+ onBlur: onBlur || undefined,
46
+ children: [selectedItemId == null && _jsx("option", {}), items.map(item => _jsx("option", {
47
+ value: item.id,
48
+ children: item.value
49
+ }, item.id))]
50
+ }), _jsx("div", {
51
+ className: 'uikit_Select_arrowCont',
52
+ children: _jsx("svg", {
53
+ width: '24',
54
+ height: '24',
55
+ viewBox: '0 0 24 24',
56
+ children: _jsx("path", {
57
+ d: 'M7.406 8.578l4.594 4.594 4.594-4.594 1.406 1.406-6 6-6-6z'
58
+ })
59
+ })
60
+ })]
61
+ })]
62
+ }), !!errorMessage && _jsx("div", {
63
+ className: 'uikit_Select_errorMsg',
64
+ children: errorMessage
65
+ })]
66
+ });
67
+ }
@@ -0,0 +1,2 @@
1
+ export declare const TAB_KEYCODE = 9;
2
+ export default function processKeyDown(e: Pick<React.KeyboardEvent, 'which' | 'shiftKey' | 'preventDefault'>, onTab: (() => unknown) | undefined, onShiftTab: (() => unknown) | undefined, onBlur: (() => unknown) | undefined): void;
@@ -0,0 +1,14 @@
1
+ export const TAB_KEYCODE = 9;
2
+ export default function processKeyDown(e, onTab, onShiftTab, onBlur) {
3
+ if (e.which === TAB_KEYCODE && onTab && !e.shiftKey) {
4
+ e.preventDefault();
5
+ onTab();
6
+ if (onBlur) onBlur();
7
+ return;
8
+ }
9
+ if (e.which === TAB_KEYCODE && onShiftTab && e.shiftKey) {
10
+ e.preventDefault();
11
+ onShiftTab();
12
+ if (onBlur) onBlur();
13
+ }
14
+ }
@@ -0,0 +1,49 @@
1
+ .uikit_Select_cont:not(:first-child) {
2
+ margin-top: 1.5em;
3
+ }
4
+
5
+ .uikit_Select_innerCont {
6
+ display: block;
7
+ box-sizing: border-box;
8
+ width: 100%;
9
+ }
10
+
11
+ .uikit_Select_label {
12
+ display: block;
13
+ margin-bottom: 0.25em;
14
+ color: #757575;
15
+ width: 100%;
16
+ }
17
+
18
+ .uikit_Select_selectCont {
19
+ position: relative;
20
+ }
21
+
22
+ .uikit_Select_input {
23
+ display: block;
24
+ box-sizing: border-box;
25
+ width: 100%;
26
+ border: 1px solid #bcbcbc;
27
+ border-radius: 5px;
28
+ font-size: 1.2em;
29
+ padding: 0.5em 2.5em 0.5em 1em;
30
+ color: #242629;
31
+ background-color: #fff;
32
+ font-family: inherit;
33
+ appearance: none;
34
+ }
35
+
36
+ .uikit_Select_arrowCont {
37
+ position: absolute;
38
+ top: 0;
39
+ right: 0.5em;
40
+ bottom: 0;
41
+ display: flex;
42
+ align-items: center;
43
+ }
44
+
45
+ .uikit_Select_errorMsg {
46
+ color: #a7241b;
47
+ font-size: 0.85rem;
48
+ margin-top: 0.2em;
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peassoft/mnr-web-ui-kit",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Peassoft web UI kit for MNR web applications",
5
5
  "type": "module",
6
6
  "exports": {
@@ -47,6 +47,7 @@
47
47
  "@babel/preset-env": "^7.22.15",
48
48
  "@memnrev/browserslist-config": "^0.1.0",
49
49
  "@memnrev/eslint-v9-config": "^0.1.1",
50
+ "@storybook/addon-a11y": "^8.5.4",
50
51
  "@storybook/addon-essentials": "^8.0.5",
51
52
  "@storybook/addon-interactions": "^8.0.5",
52
53
  "@storybook/addon-links": "^8.0.5",