elbe-ui 0.2.26 → 0.2.30

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.
Files changed (64) hide show
  1. package/dist/elbe.css +621 -0
  2. package/dist/index.d.ts +1548 -17
  3. package/dist/index.js +63 -18577
  4. package/package.json +15 -13
  5. package/dist/bit/bit.d.ts +0 -34
  6. package/dist/bit/ctrl_bit.d.ts +0 -30
  7. package/dist/service/s_api.d.ts +0 -30
  8. package/dist/ui/color_theme.d.ts +0 -5
  9. package/dist/ui/components/badge.d.ts +0 -25
  10. package/dist/ui/components/box.d.ts +0 -1027
  11. package/dist/ui/components/button.d.ts +0 -23
  12. package/dist/ui/components/card.d.ts +0 -14
  13. package/dist/ui/components/dialog.d.ts +0 -8
  14. package/dist/ui/components/error_view.d.ts +0 -15
  15. package/dist/ui/components/flex.d.ts +0 -11
  16. package/dist/ui/components/icon_button.d.ts +0 -19
  17. package/dist/ui/components/input/checkbox.d.ts +0 -6
  18. package/dist/ui/components/input/input_field.d.ts +0 -22
  19. package/dist/ui/components/input/range.d.ts +0 -8
  20. package/dist/ui/components/input/select.d.ts +0 -10
  21. package/dist/ui/components/input/text_area.d.ts +0 -10
  22. package/dist/ui/components/padded.d.ts +0 -25
  23. package/dist/ui/components/scaffold.d.ts +0 -23
  24. package/dist/ui/components/spinner.d.ts +0 -3
  25. package/dist/ui/components/text.d.ts +0 -33
  26. package/dist/ui/components/toggle_button.d.ts +0 -12
  27. package/dist/ui/components/util.d.ts +0 -3
  28. package/dist/ui/util/confirm_dialog.d.ts +0 -10
  29. package/dist/ui/util/error_view.d.ts +0 -1
  30. package/dist/ui/util/toast.d.ts +0 -5
  31. package/dist/ui/util/util.d.ts +0 -19
  32. package/elbe.scss +0 -100
  33. package/src/bit/bit.tsx +0 -128
  34. package/src/bit/ctrl_bit.tsx +0 -112
  35. package/src/index.tsx +0 -29
  36. package/src/service/s_api.ts +0 -102
  37. package/src/ui/color_theme.ts +0 -24
  38. package/src/ui/components/badge.tsx +0 -78
  39. package/src/ui/components/box.tsx +0 -49
  40. package/src/ui/components/button.tsx +0 -61
  41. package/src/ui/components/card.tsx +0 -45
  42. package/src/ui/components/dialog.tsx +0 -51
  43. package/src/ui/components/error_view.tsx +0 -72
  44. package/src/ui/components/flex.tsx +0 -64
  45. package/src/ui/components/icon_button.tsx +0 -56
  46. package/src/ui/components/input/checkbox.tsx +0 -32
  47. package/src/ui/components/input/input_field.tsx +0 -57
  48. package/src/ui/components/input/range.tsx +0 -37
  49. package/src/ui/components/input/select.tsx +0 -29
  50. package/src/ui/components/input/text_area.tsx +0 -45
  51. package/src/ui/components/padded.tsx +0 -62
  52. package/src/ui/components/scaffold.tsx +0 -79
  53. package/src/ui/components/spinner.tsx +0 -11
  54. package/src/ui/components/text.tsx +0 -78
  55. package/src/ui/components/toggle_button.tsx +0 -52
  56. package/src/ui/components/util.tsx +0 -3
  57. package/src/ui/util/confirm_dialog.ts +0 -53
  58. package/src/ui/util/error_view.tsx +0 -16
  59. package/src/ui/util/toast.ts +0 -14
  60. package/src/ui/util/util.ts +0 -36
  61. package/style/color_style.scss +0 -149
  62. package/style/components.scss +0 -476
  63. package/style/root.scss +0 -50
  64. package/style/type_style.scss +0 -22
@@ -1,57 +0,0 @@
1
- import React from "preact/compat";
2
- import { applyProps, type ElbeProps } from "../box";
3
- import { _TextArea } from "./text_area";
4
-
5
- export type InputFieldProps = {
6
- label?: string;
7
- hint: string;
8
- readonly?: boolean;
9
- value: string | number;
10
- onInput?: (value: string) => void;
11
- } & ElbeProps;
12
-
13
- export class Field extends React.Component<
14
- InputFieldProps & {
15
- type?: "text" | "number" | "password" | "date" | "time" | "email";
16
- }
17
- > {
18
- static text = (p: InputFieldProps) => <Field {...p} type="text" />;
19
- static number = (p: InputFieldProps) => <Field {...p} type="number" />;
20
- static password = (p: InputFieldProps) => <Field {...p} type="password" />;
21
- static date = (p: InputFieldProps) => <Field {...p} type="date" />;
22
- static time = (p: InputFieldProps) => <Field {...p} type="time" />;
23
- static email = (p: InputFieldProps) => <Field {...p} type="email" />;
24
-
25
- static multiLine = _TextArea;
26
-
27
- render() {
28
- const { label, hint, readonly, type, value, onInput, ...elbe } = this.props;
29
-
30
- return (
31
- <div
32
- style={{
33
- width: "12rem !important",
34
- display: "flex",
35
- flexDirection: "column",
36
- alignItems: "stretch",
37
- }}
38
- data-tooltip={this.props?.tooltip}
39
- >
40
- <input
41
- type={this.props.type}
42
- {...applyProps(this.props, null, {
43
- width: "100%",
44
- })}
45
- size={5}
46
- label={this.props.label}
47
- placeholder={this.props.hint}
48
- value={this.props.value}
49
- onInput={(e) =>
50
- this.props.onInput && this.props.onInput(e.currentTarget.value)
51
- }
52
- readonly={this.props.readonly}
53
- />
54
- </div>
55
- );
56
- }
57
- }
@@ -1,37 +0,0 @@
1
- import { _ElbeErr } from "../../util/error_view";
2
- import { applyProps, type ElbeProps } from "../box";
3
-
4
- export function Range({
5
- value,
6
- onChange,
7
- min = 0,
8
- max = 100,
9
- step = 1,
10
- ...elbe
11
- }: {
12
- value: number;
13
- min?: number;
14
- step?: number;
15
- max?: number;
16
- onChange?: ((value: number) => void) | null;
17
- } & ElbeProps) {
18
- return min > max ? (
19
- _ElbeErr("Range: max is smaller than min")
20
- ) : (
21
- <input
22
- type="range"
23
- {...applyProps(elbe, null, {
24
- filter: onChange ? "" : "grayscale(1)",
25
- opacity: onChange ? "" : "0.5",
26
- cursor: onChange ? "pointer" : "not-allowed",
27
- width: "100%",
28
- })}
29
- min={min}
30
- max={max}
31
- step={step}
32
- disabled={!onChange}
33
- value={value}
34
- onInput={(e) => onChange?.(Number(e.currentTarget.value))}
35
- />
36
- );
37
- }
@@ -1,29 +0,0 @@
1
- import { applyProps, type ElbeProps } from "../box";
2
-
3
- export function Select({
4
- options,
5
- value,
6
- label,
7
- onChange,
8
- ...elbe
9
- }: {
10
- options: { key: string; label: string }[];
11
- value?: string;
12
- label?: string;
13
- onChange: (value: string) => any;
14
- } & ElbeProps) {
15
- return (
16
- <select
17
- {...applyProps(elbe)}
18
- value={value}
19
- label={label}
20
- onChange={(e) => onChange(e.currentTarget.value)}
21
- >
22
- {options.map(({ key, label }) => (
23
- <option key={key} value={key}>
24
- {label}
25
- </option>
26
- ))}
27
- </select>
28
- );
29
- }
@@ -1,45 +0,0 @@
1
- import { applyProps, type ElbeProps } from "../box";
2
-
3
- export function _TextArea({
4
- label,
5
- hint,
6
- readonly,
7
- rows = 4,
8
- maxLength,
9
- value,
10
- onInput,
11
- ...elbe
12
- }: {
13
- label?: string;
14
- hint: string;
15
- rows?: number;
16
- maxLength?: number;
17
- readonly?: boolean;
18
- value: string | number;
19
- onInput?: (value: string) => void;
20
- } & ElbeProps) {
21
- return (
22
- <div
23
- style={{
24
- width: "12rem !important",
25
- display: "flex",
26
- flexDirection: "column",
27
- alignItems: "stretch",
28
- }}
29
- data-tooltip={elbe.tooltip}
30
- >
31
- <textarea
32
- {...applyProps(elbe, null, { width: "100%" })}
33
- label={label}
34
- size={5}
35
- cols={5}
36
- placeholder={hint}
37
- rows={rows}
38
- maxLength={maxLength}
39
- value={value}
40
- onInput={(e) => onInput && onInput(e.currentTarget.value)}
41
- readonly={readonly}
42
- />
43
- </div>
44
- );
45
- }
@@ -1,62 +0,0 @@
1
- import React from "preact/compat";
2
-
3
- export type PaddedProps = {
4
- children: any;
5
- };
6
-
7
- export class Padded extends React.Component<
8
- PaddedProps & {
9
- top: number;
10
- right: number;
11
- bottom: number;
12
- left: number;
13
- }
14
- > {
15
- constructor(
16
- props: PaddedProps & {
17
- top: number;
18
- right: number;
19
- bottom: number;
20
- left: number;
21
- }
22
- ) {
23
- super(props);
24
- }
25
-
26
- static all = ({ amount = 1, ...p }: PaddedProps & { amount: number }) => (
27
- <Padded
28
- {...{ ...p, top: amount, right: amount, bottom: amount, left: amount }}
29
- />
30
- );
31
-
32
- static symmetric = ({
33
- vertical = 0,
34
- horizontal = 0,
35
- ...p
36
- }: PaddedProps & { vertical: number; horizontal: number }) => (
37
- <Padded
38
- {...{
39
- ...p,
40
- top: vertical,
41
- bottom: vertical,
42
- left: horizontal,
43
- right: horizontal,
44
- }}
45
- />
46
- );
47
-
48
- render() {
49
- return (
50
- <div
51
- style={{
52
- paddingTop: `${this.props.top}rem`,
53
- paddingRight: `${this.props.right}rem`,
54
- paddingBottom: `${this.props.bottom}rem`,
55
- paddingLeft: `${this.props.left}rem`,
56
- }}
57
- >
58
- {this.props.children}
59
- </div>
60
- );
61
- }
62
- }
@@ -1,79 +0,0 @@
1
- import { useEffect, useState } from "preact/compat";
2
- import { Column, IconButton, Icons, Row, Text } from "../..";
3
-
4
- type HeaderParams = {
5
- title?: string;
6
- back: null | "close" | "back";
7
- actions?: any;
8
- };
9
-
10
- /**
11
- * Header is a layout component that provides a header for a page.
12
- * It is used to create a consistent header for pages.
13
- * @param back - The back button type. If null, no back button is shown. If "close", a close button is shown. If "back", a back button is shown.
14
- * @param title - The title of the page.
15
- * @param actions - The actions to show on the right side of the header.
16
- */
17
- export function Header({ back, title, actions }: HeaderParams) {
18
- if (history.length == 0) back = null;
19
- const goBack = () => history.go(-1);
20
-
21
- const [isScrolledTop, setIsScrolled] = useState(false);
22
-
23
- useEffect(() => {
24
- const _handle = () => setIsScrolled(window.scrollY > 0);
25
- window.addEventListener("scroll", _handle);
26
- return () => {
27
- window.removeEventListener("scroll", _handle);
28
- };
29
- }, []);
30
-
31
- return (
32
- <div>
33
- <div style="height: 4.5rem"></div>
34
- <div
35
- class="header"
36
- style={isScrolledTop ? "" : "border-color: transparent"}
37
- >
38
- <div class="flex-1">
39
- {back === "close" ? (
40
- <IconButton.integrated icon={Icons.X} onTap={goBack} />
41
- ) : back === "back" ? (
42
- <IconButton.integrated icon={Icons.ArrowLeft} onTap={goBack} />
43
- ) : null}
44
- </div>
45
- <Text.h4 v={title} />
46
- <Row class="flex-1" gap={0.5} main="end">
47
- {actions}
48
- </Row>
49
- </div>
50
- </div>
51
- );
52
- }
53
-
54
- /**
55
- * Scaffold is a layout component that provides a header and a content area.
56
- * It is used to create a consistent layout for pages.
57
- */
58
- export function Scaffold({
59
- children,
60
- limited = false,
61
- gap = 1,
62
- ...header
63
- }: {
64
- limited?: boolean;
65
- children: any;
66
- gap?: number;
67
- } & HeaderParams) {
68
- return (
69
- <Column cross="stretch" gap={0}>
70
- <Header {...header} />
71
-
72
- <div class={`padded ${limited ? "base-limited" : ""}`}>
73
- <Column cross="stretch" gap={gap ?? 1}>
74
- {children}
75
- </Column>
76
- </div>
77
- </Column>
78
- );
79
- }
@@ -1,11 +0,0 @@
1
- import { Icons } from "../..";
2
-
3
- export function Spinner({ padding = 2 }: { padding?: number }) {
4
- return (
5
- <div style={{ padding: `${padding}rem` }} class="centered">
6
- <div class="rotate-box">
7
- <Icons.LoaderCircle />
8
- </div>
9
- </div>
10
- );
11
- }
@@ -1,78 +0,0 @@
1
- import React from "preact/compat";
2
- import type { ElbeTypeStyles } from "../color_theme";
3
- import type { ElbeChildren } from "../util/util";
4
- import { applyProps, type ElbeProps } from "./box";
5
-
6
- export type TextProps = {
7
- align?: "start" | "center" | "end";
8
- bold?: boolean;
9
- italic?: boolean;
10
- underline?: boolean;
11
- striked?: boolean;
12
- color?: string;
13
- size?: number;
14
- children?: ElbeChildren;
15
- v?: string;
16
- } & ElbeProps;
17
-
18
- export class Text extends React.Component<
19
- TextProps & { typeStyle?: ElbeTypeStyles }
20
- > {
21
- static h1 = (p: TextProps) => <Text {...p} typeStyle="header-1" />;
22
- static h2 = (p: TextProps) => <Text {...p} typeStyle="header-2" />;
23
- static h3 = (p: TextProps) => <Text {...p} typeStyle="header-3" />;
24
- static h4 = (p: TextProps) => <Text {...p} typeStyle="header-4" />;
25
- static h5 = (p: TextProps) => <Text {...p} typeStyle="header-5" />;
26
- static h6 = (p: TextProps) => <Text {...p} typeStyle="header-6" />;
27
- static s = (p: TextProps) => <Text {...p} typeStyle="text-s" />;
28
- static m = (p: TextProps) => <Text {...p} typeStyle="text-m" />;
29
- static l = (p: TextProps) => <Text {...p} typeStyle="text-l" />;
30
- static code = (p: TextProps) => <Text {...p} typeStyle="code" />;
31
-
32
- constructor({
33
- typeStyle = "text-m",
34
- ...props
35
- }: TextProps & { typeStyle?: ElbeTypeStyles }) {
36
- super({ ...props, typeStyle });
37
- }
38
-
39
- render() {
40
- const {
41
- align,
42
- bold,
43
- italic,
44
- underline,
45
- striked,
46
- color,
47
- size,
48
- children,
49
- typeStyle,
50
- v,
51
- ...elbe
52
- } = this.props;
53
- return (
54
- <span
55
- {...applyProps(
56
- elbe,
57
- [
58
- "text",
59
- align,
60
- bold && "b",
61
- italic && "i",
62
- underline && "underline",
63
- striked && "striked",
64
- color,
65
- typeStyle,
66
- ],
67
- {
68
- fontSize: size ? `${size}rem` : "",
69
- color: color || "",
70
- }
71
- )}
72
- >
73
- {v}
74
- {children}
75
- </span>
76
- );
77
- }
78
- }
@@ -1,52 +0,0 @@
1
- import { Icons, applyProps } from "../..";
2
- import { _ElbeErr } from "../util/error_view";
3
- import type { ElbeChild } from "../util/util";
4
- import type { ElbeProps } from "./box";
5
- import { Card } from "./card";
6
- import { Column, FlexSpace } from "./flex";
7
-
8
- export type ToggleButtonItem<T> = {
9
- icon?: (_: any) => ElbeChild;
10
- label: string;
11
- key: T;
12
- };
13
-
14
- export function ToggleButton<T>({
15
- items,
16
- onSelect,
17
- value,
18
- ...elbe
19
- }: {
20
- items: ToggleButtonItem<T>[];
21
-
22
- onSelect: ((value: T) => void) | null;
23
- value: T;
24
- } & ElbeProps) {
25
- return items.length < 1 ? (
26
- _ElbeErr("ToggleButton requires at least one item")
27
- ) : (
28
- <Card
29
- mode="light"
30
- colorScheme="primary"
31
- padding={0}
32
- {...applyProps(elbe, null, { overflow: "hidden", width: "100%" })}
33
- >
34
- <Column stretch gap={0}>
35
- {items.map((item) => (
36
- <Card
37
- onTap={onSelect ? () => onSelect(item.key) : undefined}
38
- class={`row b ${onSelect ? "pointer" : "disabled"}`}
39
- style={{ border: "none", borderRadius: 0, gap: ".75rem" }}
40
- colorStyle="accent"
41
- colorManner={value === item.key ? "minor" : "action"}
42
- >
43
- {item.icon?.({})}
44
- {item.label}
45
- <FlexSpace />
46
- {value === item.key && <Icons.Check />}
47
- </Card>
48
- ))}
49
- </Column>
50
- </Card>
51
- );
52
- }
@@ -1,3 +0,0 @@
1
- export function Spaced({ amount = 1 }) {
2
- return <div style={{ width: amount + "rem", height: amount + "rem" }}></div>;
3
- }
@@ -1,53 +0,0 @@
1
- /**
2
- * show a simple confirm dialog
3
- * @param param0 the title and message of the dialog
4
- * @returns a promise that resolves to true if the user clicks "yes" or "okay" and false if the user clicks "no"
5
- */
6
- export function showConfirmDialog({
7
- title,
8
- message,
9
- okay = false,
10
- }: {
11
- message: string;
12
- title: string;
13
- okay?: boolean;
14
- }): Promise<boolean> {
15
- return new Promise((resolve, reject) => {
16
- const dialog = document.createElement("div");
17
- dialog.classList.add("dialog");
18
- dialog.innerHTML = `<dialog open>
19
- <div
20
- class=" card plain-opaque"
21
- style="max-width: 30rem; min-width: 10rem"
22
- >
23
- <div class="row cross-start">
24
- <div class="flex-1 b" style="margin-top: 0.47rem; font-size: 1.2rem">
25
- ${title}
26
- </div>
27
- <button class="integrated" style="width: 3rem" onclick="conf_resolve(false)">
28
- <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-x "><path d="M18 6 6 18"></path><path d="m6 6 12 12"></path></svg>
29
- </button>
30
- </div>
31
- <div style="margin-top: 1rem; margin-bottom: 1rem">
32
- ${message}
33
- </div>
34
- <div class="row main-end gap">
35
-
36
- ${
37
- okay
38
- ? '<button class="loud" style="padding-left:1rem; padding-right:1rem" onclick="conf_resolve(true)">okay</button>'
39
- : '<button class="loud minor" style="padding-left:1rem; padding-right:1rem" onclick="conf_resolve(false)">no</button>' +
40
- '<button class="loud" style="padding-left:1rem; padding-right:1rem" onclick="conf_resolve(true)">yes</button>'
41
- }
42
- </div>
43
-
44
- </div>
45
- </dialog>
46
- `;
47
- document.body.appendChild(dialog);
48
- (window as any)["conf_resolve"] = (v: any) => {
49
- document.body.removeChild(dialog);
50
- resolve(v);
51
- };
52
- });
53
- }
@@ -1,16 +0,0 @@
1
- import { Icons } from "../..";
2
-
3
- export function _ElbeErr(msg: string) {
4
- return (
5
- <div
6
- class="row text-s gap-half"
7
- style="background: #ee0044; color: white; border-radius: 4px; text-align: left; padding: .5rem"
8
- >
9
- <Icons.CircleX />
10
- <div class="column gap-none cross-stretch">
11
- <b class="text-s">elbe error</b>
12
- <span style="margin-top: -.125rem">{msg}</span>
13
- </div>
14
- </div>
15
- );
16
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * show a toast message at the bottom of the screen
3
- * @param message the message to show
4
- */
5
-
6
- export function showToast(message: string) {
7
- const toast = document.createElement("div");
8
- toast.classList.add("toast");
9
- toast.innerText = message;
10
- document.body.appendChild(toast);
11
- setTimeout(() => {
12
- toast.remove();
13
- }, 3000);
14
- }
@@ -1,36 +0,0 @@
1
- import type React from "preact/compat";
2
- import { showToast } from "./toast";
3
-
4
- export type ElbeChild = React.ReactNode;
5
- export type ElbeChildren = ElbeChild[] | ElbeChild;
6
-
7
- /**
8
- * use the web share api if available, otherwise copy the data to the clipboard
9
- * @param data the data you want to share
10
- * @param toastMsg the message to show in the toast if the share api is not available
11
- */
12
- export function share(
13
- data: { title: string; text?: string; url: string },
14
- toastMsg = "copied to clipboard. Share it with others."
15
- ) {
16
- const msg = `${data.title}\n${data.text ?? ""}\n\n${data.url}`;
17
-
18
- if (navigator.share) {
19
- navigator.share(data).catch(() => copyToClipboard(msg, toastMsg));
20
- } else {
21
- copyToClipboard(msg, toastMsg);
22
- }
23
- }
24
-
25
- /**
26
- * copy the text to the clipboard
27
- * @param text the text to copy to the clipboard
28
- * @param toastMsg the message to show in the toast
29
- */
30
- export function copyToClipboard(
31
- text: string,
32
- toastMsg = "copied to clipboard"
33
- ) {
34
- navigator.clipboard.writeText(text);
35
- if (toastMsg) showToast(toastMsg);
36
- }