@peassoft/mnr-web-ui-kit 0.1.1 → 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.
- package/dist/button-radio-group/styles.css +1 -1
- package/dist/input-field/styles.css +1 -1
- package/dist/plain-select/styles.css +2 -2
- package/dist/select/index.d.ts +35 -0
- package/dist/select/index.js +67 -0
- package/dist/select/process-key-down.d.ts +2 -0
- package/dist/select/process-key-down.js +14 -0
- package/dist/select/styles.css +49 -0
- package/package.json +2 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
.uikit_PlainSelect_label {
|
|
2
2
|
margin: 0;
|
|
3
|
-
color: #
|
|
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: #
|
|
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,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.
|
|
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",
|