elbe-ui 1.0.6 → 1.0.8

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,9 +1,10 @@
1
1
  import type { ElbeChildren } from "../util/types";
2
- export declare function ElbeDialog({ title, open, onClose, children, _style, barrierDismissible, }: {
2
+ export declare function ElbeDialog({ title, open, onClose, children, _style, barrierDismissible, maxWidth, }: {
3
3
  _style?: React.CSSProperties;
4
4
  title: string;
5
5
  open: boolean;
6
6
  onClose: () => void;
7
7
  children: ElbeChildren;
8
8
  barrierDismissible?: boolean;
9
+ maxWidth?: number;
9
10
  }): import("react/jsx-runtime").JSX.Element;
@@ -3,7 +3,7 @@ import { X } from "lucide-react";
3
3
  import { useEffect } from "react";
4
4
  import { IconButton } from "./button/icon_button";
5
5
  import { Spaced } from "./layout/spaced";
6
- export function ElbeDialog({ title, open, onClose, children, _style, barrierDismissible, }) {
6
+ export function ElbeDialog({ title, open, onClose, children, _style, barrierDismissible, maxWidth, }) {
7
7
  useEffect(() => {
8
8
  if (open) {
9
9
  document.body.style.overflow = "hidden";
@@ -20,7 +20,10 @@ export function ElbeDialog({ title, open, onClose, children, _style, barrierDism
20
20
  e.preventDefault();
21
21
  if (barrierDismissible)
22
22
  onClose();
23
- }, open: open, style: Object.assign({ textAlign: "start" }, (_style !== null && _style !== void 0 ? _style : {})), children: _jsxs("div", { className: "elbe_dialog_base primary card plain-opaque padding-none", style: { maxWidth: "40rem", minWidth: "10rem" }, children: [_jsxs("div", { className: "row cross-center padded main-between", children: [_jsx("div", { className: "body-l b", children: title }), _jsx(IconButton.plain, { ariaLabel: "Close", icon: X, onTap: (e) => {
23
+ }, open: open, style: Object.assign({ textAlign: "start" }, (_style !== null && _style !== void 0 ? _style : {})), children: _jsxs("div", { className: "elbe_dialog_base primary card plain-opaque padding-none", style: {
24
+ maxWidth: `min(${maxWidth !== null && maxWidth !== void 0 ? maxWidth : 40}rem, 100%)`,
25
+ minWidth: "10rem",
26
+ }, children: [_jsxs("div", { className: "row cross-center padded main-between", children: [_jsx("div", { className: "body-l b", children: title }), _jsx(IconButton.plain, { ariaLabel: "Close", icon: X, onTap: (e) => {
24
27
  e.stopPropagation();
25
28
  e.preventDefault();
26
29
  onClose();
@@ -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: string;
4
+ key: T;
5
5
  label: string;
6
6
  }[];
7
- value?: string;
7
+ value?: T;
8
8
  label?: string;
9
- onChange: (value: string) => any;
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 { options, value, label, onChange } = _a, elbe = __rest(_a, ["options", "value", "label", "onChange"]);
16
- return (_jsx("select", Object.assign({}, applyProps("select", elbe), { value: value, role: "combobox", onChange: (e) => onChange(e.currentTarget.value), children: options.map(({ key, label }) => (_jsx("option", { value: key, children: label }, key))) })));
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elbe-ui",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "author": "Robin Naumann",
5
5
  "license": "MIT",
6
6
  "repository": {