@grucloud/bau-ui 0.21.0

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/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # BauUI
2
+
3
+ A component library for built with Bau.
4
+
5
+ The library provides 20+ components such as button, input, tabs, tree etc ...
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@grucloud/bau-ui",
3
+ "description": "Components library built with Bau",
4
+ "version": "0.21.0",
5
+ "type": "module",
6
+ "license": "BSD",
7
+ "files": [
8
+ "src"
9
+ ],
10
+ "keywords": [
11
+ "Component",
12
+ "Bau",
13
+ "Design System",
14
+ "CSS in JS"
15
+ ],
16
+ "author": "Frederic Heem",
17
+ "scripts": {
18
+ "build": "vite build",
19
+ "preview": "vite preview",
20
+ "bundle-visualizer": "vite-bundle-visualizer",
21
+ "test": "vitest",
22
+ "coverage": "vitest run --coverage"
23
+ },
24
+ "devDependencies": {
25
+ "@vitest/coverage-c8": "0.32.0",
26
+ "happy-dom": "9.20.3",
27
+ "vite": "4.3.9",
28
+ "vite-bundle-visualizer": "0.7.0",
29
+ "vitest": "0.31.4"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git@github.com:grucloud/bau.git"
34
+ },
35
+ "dependencies": {
36
+ "@grucloud/bau": "0.21.0",
37
+ "@grucloud/bau-css": "0.21.0"
38
+ }
39
+ }
@@ -0,0 +1,96 @@
1
+ import button from "../button";
2
+
3
+ const severityMap = {
4
+ danger: "\u26A0",
5
+ warning: "\u26A0",
6
+ success: "\u2714",
7
+ info: "\u2139",
8
+ };
9
+
10
+ const darkVar = (severity) => `var(--color-${severity}-darkest)`;
11
+
12
+ const severitiesToCss = () =>
13
+ Object.keys(severityMap)
14
+ .map(
15
+ (severity) =>
16
+ `.alert-${severity} {
17
+ border-left: var(--alert-border-left-width) solid ${darkVar(severity)};
18
+ color: ${darkVar(severity)};
19
+ background-color: var(--background-color);
20
+ & .button-close {
21
+ color: ${darkVar(severity)};
22
+ }
23
+ }`
24
+ )
25
+ .join("\n");
26
+
27
+ const createStyles = ({ css, createGlobalStyles }) => {
28
+ createGlobalStyles`
29
+ :root {
30
+ --alert-border-left-width: 8px;
31
+ }
32
+ ${severitiesToCss()}
33
+ `;
34
+
35
+ return {
36
+ base: css`
37
+ display: flex;
38
+ max-width: 600px;
39
+ justify-content: flex-start;
40
+ align-items: center;
41
+ margin: 0.5rem;
42
+ font-weight: var(--font-weight-semibold);
43
+ box-shadow: var(--global-shadow-md);
44
+ border-radius: var(--global-radius);
45
+ & .icon {
46
+ padding: 0 1rem;
47
+ font-size: 2.5rem;
48
+ }
49
+ & .content {
50
+ padding: 0 0.5rem;
51
+ display: flex;
52
+ flex-grow: 1;
53
+ flex-direction: column;
54
+ align-items: flex-start;
55
+ justify-content: space-around;
56
+ }
57
+ & .button-close {
58
+ margin: 1rem;
59
+ }
60
+ `,
61
+ };
62
+ };
63
+
64
+ export default function (context, options = {}) {
65
+ const { bau, css, createGlobalStyles, tr } = context;
66
+ const { div } = bau.tags;
67
+
68
+ const styles = createStyles({ css, createGlobalStyles });
69
+
70
+ const Button = button(context);
71
+
72
+ const CloseIcon = ({ onclick }) =>
73
+ Button(
74
+ {
75
+ "aria-label": "Close",
76
+ onclick,
77
+ class: "button-close",
78
+ },
79
+ "\u2716"
80
+ );
81
+
82
+ return function Alert(props, ...children) {
83
+ const { severity = "info", onRemove, ...otherProps } = props;
84
+
85
+ return div(
86
+ {
87
+ ...otherProps,
88
+ class: `${styles.base} alert-${severity}`,
89
+ role: "alert",
90
+ },
91
+ div({ class: "icon" }, severityMap[severity]),
92
+ div({ class: "content" }, ...children),
93
+ onRemove && CloseIcon({ onclick: onRemove })
94
+ );
95
+ };
96
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./alert";
@@ -0,0 +1,97 @@
1
+ export default (context, { limit = 10, deleteAfterDuration = 5e3 } = {}) => {
2
+ const { bau, css, keyframes } = context;
3
+ const { div } = bau.tags;
4
+ const messagesState = bau.state([]);
5
+
6
+ const animation = {
7
+ inserting: keyframes`
8
+ 0% { transform: scale(0.5); opacity: 0 }
9
+ 100% { transform: scale(1); opacity: 1 }
10
+ `,
11
+ removing: keyframes`
12
+ 0% { transform: scale(1); opacity: 1 }
13
+ 100% { transform: scale(0); opacity: 0 }
14
+ `,
15
+ };
16
+ const styles = {
17
+ stack: css`
18
+ min-width: 300px;
19
+ max-width: 600px;
20
+ position: fixed;
21
+ right: var(--global-spacing);
22
+ top: var(--global-spacing);
23
+ z-index: 10;
24
+ `,
25
+ item: css`
26
+ margin: 0.2rem;
27
+ padding: 0.2rem;
28
+ display: flex;
29
+ justify-content: flex-start;
30
+ align-items: center;
31
+ cursor: pointer;
32
+ animation: ${animation.inserting} var(--transition-slow) ease-out;
33
+ `,
34
+ itemOut: css`
35
+ animation: ${animation.removing} var(--transition-slow) ease-out;
36
+ `,
37
+ };
38
+
39
+ const AlertItem = (message) =>
40
+ div(
41
+ {
42
+ class: styles.item,
43
+ onclick: () => AlertStack.remove(message),
44
+ },
45
+ message.component()
46
+ );
47
+
48
+ const AlertStack = (props, ...children) =>
49
+ div(
50
+ {
51
+ class: styles.stack,
52
+ },
53
+ bau.bind({
54
+ deps: [messagesState],
55
+ render:
56
+ ({ renderItem }) =>
57
+ (arr) =>
58
+ div(arr.map(renderItem())),
59
+ renderItem: () => AlertItem,
60
+ })
61
+ );
62
+
63
+ AlertStack.add = ({ component }) => {
64
+ const message = {
65
+ id: Math.random().toString(10).split(".")[1],
66
+ component,
67
+ status: "inserting",
68
+ };
69
+
70
+ if (messagesState.val.length >= limit) {
71
+ AlertStack.remove({ id: messagesState.val[0].id });
72
+ }
73
+
74
+ messagesState.val.push(message);
75
+
76
+ setTimeout(() => AlertStack.remove(message), deleteAfterDuration);
77
+ };
78
+
79
+ const setStatus = ({ id, status }) => {
80
+ const idx = messagesState.val.findIndex((message) => message.id === id);
81
+ if (idx != -1) {
82
+ messagesState.val[idx].status = status;
83
+ }
84
+ };
85
+
86
+ AlertStack.remove = ({ id }) => {
87
+ setStatus({ id, status: "removing" });
88
+ const idx = messagesState.val.findIndex((message) => message.id === id);
89
+ if (idx != -1) {
90
+ messagesState.val.splice(idx, 1);
91
+ } else {
92
+ // console.log("remove: no id", id);
93
+ }
94
+ };
95
+
96
+ return AlertStack;
97
+ };
@@ -0,0 +1 @@
1
+ export { default } from "./alertStack";
@@ -0,0 +1,42 @@
1
+ export default function (context, options = {}) {
2
+ return function Animate({ Component, parent, animationHide, animationShow }) {
3
+ const node = Component();
4
+ // Show
5
+ node.style.animation = animationShow;
6
+ const animationEndHandler = () => {
7
+ node.removeEventListener("animationend", animationEndHandler);
8
+ node.style.animation = "";
9
+ };
10
+ node.addEventListener("animationend", animationEndHandler);
11
+
12
+ // Hide
13
+ new MutationObserver((mutationList, observer) => {
14
+ mutationList
15
+ .filter((record) => record.removedNodes)
16
+ .forEach((record) =>
17
+ [...record.removedNodes].find((removedNode) => {
18
+ if (removedNode === node) {
19
+ const nodeCloned = node.cloneNode(true);
20
+ nodeCloned.style.animation = animationHide;
21
+ if (record.previousSibling) {
22
+ record.previousSibling.after(nodeCloned);
23
+ } else if (record.nextSibling) {
24
+ record.nextSibling.before(nodeCloned);
25
+ } else if (record.target) {
26
+ record.target.appendChild(nodeCloned);
27
+ } else {
28
+ }
29
+
30
+ nodeCloned.addEventListener("animationend", () =>
31
+ nodeCloned.parentNode.removeChild(nodeCloned)
32
+ );
33
+ observer.disconnect();
34
+ return true;
35
+ }
36
+ })
37
+ );
38
+ }).observe(parent, { childList: true, subtree: true });
39
+
40
+ return node;
41
+ };
42
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./animate";
@@ -0,0 +1,36 @@
1
+ import { classNames } from "../utils/classNames";
2
+
3
+ export default function (context, options = {}) {
4
+ const { bau, css } = context;
5
+ const { cssOverride } = options;
6
+ const { span, img } = bau.tags;
7
+
8
+ const loadingState = bau.state(true);
9
+ const errorState = bau.state(false);
10
+
11
+ const onload = () => (loadingState.val = false);
12
+
13
+ const onerror = (event) => {
14
+ loadingState.val = false;
15
+ errorState.val = true;
16
+ };
17
+
18
+ return function Avatar({ width = 60, height = 60, ...props }, ...children) {
19
+ return span(
20
+ { class: classNames(cssOverride) },
21
+ bau.bind({
22
+ deps: [loadingState],
23
+ render: () => (loading) => {
24
+ if (loading) {
25
+ return "Loading...";
26
+ } else return "";
27
+ },
28
+ }),
29
+ bau.bind({
30
+ deps: [errorState],
31
+ render: () => (error) => error ? "Error" : "",
32
+ }),
33
+ img({ width, height, onload, onerror, ...props })
34
+ );
35
+ };
36
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./avatar";
@@ -0,0 +1,158 @@
1
+ import { classNames } from "../utils/classNames";
2
+
3
+ export default function (context, options = {}) {
4
+ const { bau, css } = context;
5
+ const { span } = bau.tags;
6
+
7
+ const styles = {
8
+ root: css`
9
+ color: var(--font-color-base);
10
+ display: inline-flex;
11
+ align-items: center;
12
+ justify-content: center;
13
+ position: relative;
14
+ padding: 0 0.5rem;
15
+ min-width: 2rem;
16
+ min-height: 2rem;
17
+ outline: none;
18
+ border: none;
19
+ border-radius: var(--global-radius);
20
+ background: transparent;
21
+ font-size: 1rem;
22
+ font-weight: var(--font-weight-semibold);
23
+ text-align: center;
24
+ text-decoration: none;
25
+ text-transform: uppercase;
26
+ overflow: hidden;
27
+ box-sizing: border-box;
28
+ user-select: none;
29
+ transition: background-color var(--transition-fast);
30
+ &::before {
31
+ background-color: rgba(0, 0, 0, 0.2);
32
+ position: absolute;
33
+ top: calc(50% - 100%);
34
+ left: calc(50% - 100%);
35
+ width: 200%;
36
+ height: 200%;
37
+ transition: opacity var(--transition-fast) linear;
38
+ border-radius: 50%;
39
+ opacity: 0;
40
+ pointer-events: none;
41
+ content: "";
42
+ }
43
+ &:active {
44
+ &::before {
45
+ opacity: 1;
46
+ }
47
+ }
48
+ &:hover {
49
+ &::before {
50
+ opacity: 0.5;
51
+ }
52
+ }
53
+ `,
54
+ button: css`
55
+ cursor: pointer;
56
+ `,
57
+ a: css``,
58
+ flat: css`
59
+ border-width: 0;
60
+ `,
61
+ flatPrimary: css`
62
+ color: var(--color-primary);
63
+ `,
64
+ flatAccent: css`
65
+ color: var(--color-secondary);
66
+ `,
67
+ raised: css`
68
+ box-shadow: var(--global-shadow-lw);
69
+ &:active {
70
+ box-shadow: var(--global-shadow-md);
71
+ }
72
+ `,
73
+ raisedPrimary: css`
74
+ background-color: var(--color-primary);
75
+ color: var(--color-content-inverse);
76
+ `,
77
+ raisedAccent: css`
78
+ background-color: var(--color-secondary);
79
+ color: var(--color-content-inverse);
80
+ `,
81
+ disabled: css`
82
+ color: rgba(0, 0, 0, 0.26);
83
+ cursor: default;
84
+ pointer-events: none;
85
+ box-shadow: none;
86
+ `,
87
+ raisedDisabled: css`
88
+ background-color: rgba(0, 0, 0, 0.12);
89
+ `,
90
+ fullWidth: css`
91
+ text-align: center;
92
+ width: 100%;
93
+ `,
94
+ ripple: css`
95
+ position: relative;
96
+ overflow: hidden;
97
+ transform: translate3d(0, 0, 0);
98
+ &::after {
99
+ content: "";
100
+ display: block;
101
+ position: absolute;
102
+ width: 100%;
103
+ height: 100%;
104
+ top: 0;
105
+ left: 0;
106
+ pointer-events: none;
107
+ background-image: radial-gradient(circle, #000 10%, transparent 10%);
108
+ background-repeat: no-repeat;
109
+ background-position: 50%;
110
+ transform: scale(10, 10);
111
+ opacity: 0;
112
+ transition: transform var(--transition-slow), opacity 1s;
113
+ }
114
+ &:active::after {
115
+ transform: scale(0, 0);
116
+ opacity: 0.2;
117
+ transition: 0s;
118
+ }
119
+ `,
120
+ };
121
+
122
+ return function Button(props, ...children) {
123
+ const {
124
+ fullWidth,
125
+ label,
126
+ primary,
127
+ accent,
128
+ raised,
129
+ disabled,
130
+ ripple,
131
+ href,
132
+ icon,
133
+ ...otherProps
134
+ } = props;
135
+ const tagButton = href ? bau.tags.a : bau.tags.button;
136
+ return tagButton(
137
+ {
138
+ ...otherProps,
139
+ class: classNames(
140
+ styles.root,
141
+ href ? styles.a : styles.button,
142
+ raised ? styles.raised : styles.flat,
143
+ !raised && primary && styles.flatPrimary,
144
+ !raised && accent && styles.flatAccent,
145
+ raised && primary && styles.raisedPrimary,
146
+ raised && accent && styles.raisedAccent,
147
+ ripple && styles.rippledisabled && styles.disabled,
148
+ disabled && raised && styles.raisedDisabled,
149
+ fullWidth && styles.fullWidth,
150
+ props.class
151
+ ),
152
+ href,
153
+ ...(!href && { type: "button" }),
154
+ },
155
+ children
156
+ );
157
+ };
158
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./button";
@@ -0,0 +1,51 @@
1
+ export default function (context, options = {}) {
2
+ const { bau, css } = context;
3
+ const { input } = bau.tags;
4
+ const style = {
5
+ base: css`
6
+ width: 1.5rem;
7
+ height: 1.5rem;
8
+ border-radius: var(--global-radius);
9
+ appearance: none;
10
+ outline: none;
11
+ box-sizing: border-box;
12
+ transition: all var(--transition-fast) ease-in-out;
13
+ box-shadow: var(--global-shadow-lw);
14
+ border: 2px solid var(--color-gray-600);
15
+ position: relative;
16
+ &:hover {
17
+ transform: scale(1.05);
18
+ }
19
+ &:disabled {
20
+ border: 2px dashed var(--color-gray-500);
21
+ }
22
+ &:checked {
23
+ border: 2px solid var(--color-primary);
24
+ background-color: var(--color-primary);
25
+ }
26
+ &::after {
27
+ content: "\u2716";
28
+ position: absolute;
29
+ font-size: 1.2rem;
30
+ top: 50%;
31
+ left: 50%;
32
+ transform: translate(-50%, -50%);
33
+ color: var(--color-primary);
34
+ opacity: 0;
35
+ }
36
+ &:checked::after {
37
+ color: var(--color-gray-100);
38
+ opacity: 1;
39
+ }
40
+ `,
41
+ };
42
+
43
+ return function Checkbox(props, ...children) {
44
+ return input({
45
+ class: style.base,
46
+ type: "checkbox",
47
+ required: "required",
48
+ ...props,
49
+ });
50
+ };
51
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./checkbox";
@@ -0,0 +1,70 @@
1
+ import { classNames } from "../utils/classNames";
2
+
3
+ export default function (context) {
4
+ const { bau, css } = context;
5
+ const { div } = bau.tags;
6
+ const style = css`
7
+ position: fixed;
8
+ top: 80px;
9
+ left: 0px;
10
+ z-index: 2;
11
+ & .overlay {
12
+ position: absolute;
13
+ z-index: -1;
14
+ opacity: 0;
15
+ background-color: var(--background-color);
16
+ top: 0;
17
+ left: 0;
18
+ height: 100%;
19
+ width: 100%;
20
+ transition: opacity var(--transition-fast) ease-out;
21
+ }
22
+ & .overlay-open {
23
+ z-index: 1;
24
+ opacity: 0.5;
25
+ }
26
+ & .content {
27
+ transform: translate(-100%, 0px);
28
+ z-index: 2;
29
+ position: absolute;
30
+ box-shadow: var(--global-shadow-md);
31
+ background-color: var(--background-color);
32
+ top: 0;
33
+ left: 0;
34
+ transition: transform var(--transition-fast) ease-out;
35
+ }
36
+ & .content-open {
37
+ transform: translate(0%, 0px);
38
+ z-index: 2;
39
+ position: absolute;
40
+ box-shadow: var(--global-shadow-md);
41
+ background-color: var(--background-color);
42
+ top: 0;
43
+ left: 0;
44
+ transition: transform var(--transition-fast) ease-out;
45
+ }
46
+ `;
47
+
48
+ return function Drawer({ openState }, ...children) {
49
+ return div(
50
+ { class: style },
51
+ div({
52
+ class: {
53
+ deps: [openState],
54
+ renderProp: () => (open) =>
55
+ classNames("overlay", open && "overlay-open"),
56
+ },
57
+ }),
58
+ div(
59
+ {
60
+ class: {
61
+ deps: [openState],
62
+ renderProp: () => (open) =>
63
+ classNames("content", open && "content-open"),
64
+ },
65
+ },
66
+ ...children
67
+ )
68
+ );
69
+ };
70
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./drawer";
@@ -0,0 +1,66 @@
1
+ import { classNames } from "../utils/classNames";
2
+
3
+ export default function (context, options = {}) {
4
+ const { bau, css } = context;
5
+ const { div, span, label, input } = bau.tags;
6
+
7
+ const style = {
8
+ base: css`
9
+ display: inline-block;
10
+ width: 25rem;
11
+ > * {
12
+ margin: 1rem 0;
13
+ }
14
+ & input {
15
+ width: 0.1px;
16
+ height: 0.1px;
17
+ opacity: 0;
18
+ overflow: hidden;
19
+ position: absolute;
20
+ z-index: -1;
21
+ }
22
+ & .filename-display {
23
+ display: inline-block;
24
+ white-space: nowrap;
25
+ overflow: hidden;
26
+ text-overflow: ellipsis;
27
+ }
28
+ & label {
29
+ border-radius: var(--global-radius);
30
+ display: flex;
31
+ justify-content: center;
32
+ align-items: center;
33
+ cursor: pointer;
34
+ border: var(--global-border-width) dotted;
35
+ box-shadow: var(--global-shadow-lw);
36
+ &:hover {
37
+ box-shadow: var(--global-shadow-md);
38
+ }
39
+ }
40
+ `,
41
+ disabled: css`
42
+ color: var(--color-gray-500);
43
+ & label {
44
+ background-color: var(--color-gray-100);
45
+ border: var(--global-border-width) var(--color-gray-500) dotted;
46
+ &:hover {
47
+ box-shadow: var(--global-shadow-lw);
48
+ }
49
+ cursor: not-allowed;
50
+ }
51
+ `,
52
+ };
53
+
54
+ return function FileInput(props, ...children) {
55
+ const { Component, disabled, ...otherProps } = props;
56
+
57
+ return div(
58
+ { class: classNames(style.base, disabled && style.disabled) },
59
+ label(
60
+ Component({ disabled }),
61
+ input({ type: "file", disabled, ...otherProps })
62
+ ),
63
+ span({ class: "filename-display" })
64
+ );
65
+ };
66
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./fileInput";
@@ -0,0 +1 @@
1
+ export { default } from "./input";