elbe-ui 1.0.5 → 1.0.7
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,10 +1,12 @@
|
|
|
1
1
|
import { ActionElbeProps } from "../base/box";
|
|
2
|
-
export declare function Select({ options, value, label, onChange, ...elbe }: {
|
|
2
|
+
export declare function Select<T>({ options, value, label, hideLabel, width, onChange, ...elbe }: {
|
|
3
3
|
options: {
|
|
4
|
-
key:
|
|
4
|
+
key: T;
|
|
5
5
|
label: string;
|
|
6
6
|
}[];
|
|
7
|
-
value?:
|
|
7
|
+
value?: T;
|
|
8
8
|
label?: string;
|
|
9
|
-
|
|
9
|
+
hideLabel?: boolean;
|
|
10
|
+
width?: number;
|
|
11
|
+
onChange?: (value: T) => any;
|
|
10
12
|
} & ActionElbeProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -9,9 +9,41 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { randomAlphaNum } from "../../util/util";
|
|
13
14
|
import { applyProps } from "../base/box";
|
|
14
15
|
export function Select(_a) {
|
|
15
|
-
var
|
|
16
|
-
|
|
16
|
+
var _b;
|
|
17
|
+
var { options, value, label, hideLabel, width, onChange } = _a, elbe = __rest(_a, ["options", "value", "label", "hideLabel", "width", "onChange"]);
|
|
18
|
+
const id = (_b = elbe.id) !== null && _b !== void 0 ? _b : randomAlphaNum(8, "input_field_");
|
|
19
|
+
let valueIndex = options.findIndex((o) => o.key === value);
|
|
20
|
+
// If the value is not found, select the first option without a key (if any) or the first option
|
|
21
|
+
if (valueIndex === -1) {
|
|
22
|
+
valueIndex = options.findIndex((v) => !v.key);
|
|
23
|
+
if (valueIndex === -1) {
|
|
24
|
+
valueIndex = 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
let valStr = "-".repeat(valueIndex + 1);
|
|
28
|
+
return (_jsxs("div", { style: {
|
|
29
|
+
flex: elbe.flex ? (elbe.flex === true ? 1 : elbe.flex) : undefined,
|
|
30
|
+
width: elbe.flex ? undefined : (width !== null && width !== void 0 ? width : 12) + "rem",
|
|
31
|
+
display: "flex",
|
|
32
|
+
flexDirection: "column",
|
|
33
|
+
alignItems: "stretch",
|
|
34
|
+
filter: onChange ? undefined : "grayscale(1) opacity(0.5)",
|
|
35
|
+
pointerEvents: onChange ? undefined : "none",
|
|
36
|
+
cursor: onChange ? undefined : "not-allowed",
|
|
37
|
+
}, "data-tooltip": elbe.tooltip, children: [_jsx("label", { htmlFor: id, style: {
|
|
38
|
+
display: hideLabel ? "none" : "block",
|
|
39
|
+
fontSize: "0.8rem",
|
|
40
|
+
padding: "0.2rem 0.5rem",
|
|
41
|
+
}, children: label }), _jsx("select", Object.assign({ id: id }, applyProps("select", elbe, [], {
|
|
42
|
+
minHeight: "3rem",
|
|
43
|
+
cursor: onChange ? "pointer" : "not-allowed",
|
|
44
|
+
}), { value: valStr, disabled: !onChange, role: "combobox", onChange: (e) => {
|
|
45
|
+
const index = e.currentTarget.value.length - 1;
|
|
46
|
+
const selectedOption = options[index];
|
|
47
|
+
selectedOption && onChange ? onChange(selectedOption.key) : null;
|
|
48
|
+
}, children: options.map(({ key, label }, i) => (_jsx("option", { value: "-".repeat(i + 1), children: label }, JSON.stringify(key)))) }))] }));
|
|
17
49
|
}
|
|
@@ -50,7 +50,7 @@ export function Menu(p) {
|
|
|
50
50
|
: {})), children: wideOrOpen() && (_jsxs(_Fragment, { children: [_jsx(Button.plain, { contentAlign: "start", ariaLabel: "open/close menu", onTap: () => appBase.setMenuOpen(!appBase.menuOpen), icon: MenuIcon, style: {
|
|
51
51
|
marginBottom: ".5rem",
|
|
52
52
|
borderRadius: "3rem",
|
|
53
|
-
}, children: !layoutMode.isWide && (_jsx(_Logo, { logo: appBase === null || appBase === void 0 ? void 0 : appBase.icons.logo, logoDark: appBase === null || appBase === void 0 ? void 0 : appBase.icons.logoDark, lMargin: 0.5 })) }), _jsx(Column, { flex: 1, scroll: true, noScrollbar: true, children: topBot.top.map((i) => (_jsx(_MenuItemView, { item: i }))) }), topBot.bottom.map((i) => (_jsx(_MenuItemView, { item: i })))] })) })] }));
|
|
53
|
+
}, children: !layoutMode.isWide && (_jsx(_Logo, { logo: appBase === null || appBase === void 0 ? void 0 : appBase.icons.logo, logoDark: appBase === null || appBase === void 0 ? void 0 : appBase.icons.logoDark, lMargin: 0.5 })) }), _jsx(Column, { flex: 1, scroll: true, noScrollbar: true, children: topBot.top.map((i, index) => (_jsx(_MenuItemView, { item: i }, index))) }), topBot.bottom.map((i, index) => (_jsx(_MenuItemView, { item: i }, index)))] })) })] }));
|
|
54
54
|
}
|
|
55
55
|
function _MenuItemView({ item }) {
|
|
56
56
|
const appBase = useAppBase();
|