@grucloud/bau-ui 0.31.0 → 0.32.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.
@@ -1,6 +1,5 @@
1
1
  export default function (context, options = {}) {
2
- return function Animate({ parent, animationHide, animationShow }, child) {
3
- const node = child;
2
+ return function Animate({ parent, animationHide, animationShow }, node) {
4
3
  // Show
5
4
  node.style.animation = animationShow;
6
5
  const animationEndHandler = () => {
@@ -15,24 +14,26 @@ export default function (context, options = {}) {
15
14
  .filter((record) => record.removedNodes)
16
15
  .forEach((record) =>
17
16
  [...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;
17
+ parent.style.position = "relative";
18
+ const nodeCloned = removedNode.cloneNode(true);
19
+ nodeCloned.style.top = 0;
20
+ nodeCloned.style.left = 0;
21
+ nodeCloned.style.position = "absolute";
22
+ nodeCloned.style.animation = animationHide;
23
+ if (record.previousSibling) {
24
+ record.previousSibling.after(nodeCloned);
25
+ } else if (record.nextSibling) {
26
+ record.nextSibling.before(nodeCloned);
27
+ } else if (record.target) {
28
+ record.target.appendChild(nodeCloned);
29
+ } else {
35
30
  }
31
+
32
+ nodeCloned.addEventListener("animationend", () =>
33
+ nodeCloned.parentNode.removeChild(nodeCloned)
34
+ );
35
+ observer.disconnect();
36
+ return true;
36
37
  })
37
38
  );
38
39
  }).observe(parent, { childList: true, subtree: true });
@@ -0,0 +1,233 @@
1
+ import classNames from "@grucloud/bau-css/classNames.js";
2
+ import animate from "../animate/animate.js";
3
+
4
+ const animationDuration = "0.3s";
5
+
6
+ const treeAddParent =
7
+ ({ parent, grandParent }) =>
8
+ (tree) => {
9
+ const { children, ...othersTreeProps } = tree;
10
+ const result = structuredClone(othersTreeProps);
11
+ result.children = children?.map(
12
+ treeAddParent({ parent: tree, grandParent: parent })
13
+ );
14
+ if (parent) {
15
+ parent.parentTree = grandParent;
16
+ }
17
+ result.parentTree = parent;
18
+ return result;
19
+ };
20
+
21
+ const findSubTree = (initialPathname) => (tree) => {
22
+ if (!initialPathname) {
23
+ return tree;
24
+ }
25
+ if (tree?.data?.href == initialPathname) {
26
+ return tree.children ? tree : tree.parentTree;
27
+ }
28
+ if (!tree.children) {
29
+ return;
30
+ }
31
+ for (let index = 0; index < tree.children.length; index++) {
32
+ const result = findSubTree(initialPathname)(tree.children[index]);
33
+ if (result) {
34
+ return result;
35
+ }
36
+ }
37
+ };
38
+
39
+ const createStyles = ({ createGlobalStyles, keyframes }) => {
40
+ createGlobalStyles`
41
+ :root {
42
+ --drill-down-menu-color: var(--font-color-base);
43
+ --drill-down-menu-padding: 0.4rem;
44
+ }
45
+ `;
46
+ return {
47
+ hideToLeft: keyframes`
48
+ from {
49
+ transform: translateX(0%);
50
+ opacity: 1;
51
+ }
52
+ to {
53
+ transform: translateX(-100%);
54
+ opacity: 0;
55
+ }
56
+ `,
57
+ showFromLeft: keyframes`
58
+ from {
59
+ transform: translateX(-100%);
60
+ opacity: 0;
61
+ }
62
+ to {
63
+ transform: translateX(0%);
64
+ opacity: 1;
65
+ }
66
+ `,
67
+ hideToRight: keyframes`
68
+ from {
69
+ transform: translateX(0%);
70
+ opacity: 1;
71
+ }
72
+ to {
73
+ transform: translateX(100%);
74
+ opacity: 0;
75
+ }
76
+ `,
77
+ showFromRight: keyframes`
78
+ from {
79
+ transform: translateX(100%);
80
+ opacity: 0;
81
+
82
+ }
83
+ to {
84
+ transform: translateX(0%);
85
+ opacity: 1;
86
+ }
87
+ `,
88
+ };
89
+ };
90
+
91
+ export default function (context, { renderMenuItem }) {
92
+ const { bau, css, window } = context;
93
+ const { ul, li, nav, div, header, a } = bau.tags;
94
+ const Animate = animate(context);
95
+
96
+ const { hideToLeft, hideToRight, showFromRight, showFromLeft } =
97
+ createStyles(context);
98
+
99
+ const className = css`
100
+ font-weight: var(--font-weight-semibold);
101
+ overflow: hidden;
102
+ position: relative;
103
+ & a,
104
+ span {
105
+ flex-grow: 1;
106
+ text-decoration: none;
107
+ color: var(--drill-down-menu-color);
108
+ }
109
+ & header {
110
+ display: flex;
111
+ align-items: center;
112
+ cursor: pointer;
113
+ font-weight: var(--font-weight-bold);
114
+ border-bottom: 1px solid var(--color-emphasis-100);
115
+ padding: var(--drill-down-menu-padding);
116
+ transition: background-color var(--transition-slow) ease-in-out;
117
+ &:hover {
118
+ background: var(--color-emphasis-50);
119
+ }
120
+ &::before {
121
+ content: "\u2190";
122
+ margin-right: 0.5rem;
123
+ }
124
+ }
125
+ & ul {
126
+ display: block;
127
+ list-style: none;
128
+ margin: 0;
129
+ padding-left: 0;
130
+ overflow: hidden;
131
+ & .has-children {
132
+ &::after {
133
+ content: "\u203A";
134
+ padding: 0 0.5rem 0 0.5rem;
135
+ }
136
+ }
137
+ & li {
138
+ padding: var(--drill-down-menu-padding);
139
+ cursor: pointer;
140
+ display: flex;
141
+ justify-content: space-between;
142
+ align-items: center;
143
+ background-color: transparent;
144
+ transition: background-color var(--transition-slow) ease-in-out;
145
+ &:hover {
146
+ background-color: var(--color-emphasis-50);
147
+ }
148
+ }
149
+ }
150
+ `;
151
+
152
+ const Menu = ({ onclickItem, onclickBack, currentTree }) => {
153
+ const { children, parentTree, data } = currentTree;
154
+ return div(
155
+ parentTree &&
156
+ header(
157
+ {
158
+ onclick: onclickBack({ currentTree }),
159
+ },
160
+ a({ href: currentTree.parentTree.children[0].data.href }, data.name)
161
+ ),
162
+ children &&
163
+ ul(
164
+ children.map((subTree) =>
165
+ li(
166
+ subTree.children && {
167
+ class: "has-children",
168
+ onclick: onclickItem({ currentTree: subTree }),
169
+ },
170
+ renderMenuItem(subTree.data)
171
+ )
172
+ )
173
+ )
174
+ );
175
+ };
176
+
177
+ return function DrillDownMenu({
178
+ tree,
179
+ pathnameState = bau.state(window.location.pathname),
180
+ ...otherProps
181
+ }) {
182
+ const onclickItem =
183
+ ({ currentTree }) =>
184
+ (event) =>
185
+ replaceChildren(event, navEl, currentTree, true);
186
+
187
+ const onclickBack =
188
+ ({ currentTree }) =>
189
+ (event) =>
190
+ replaceChildren(event, navEl, currentTree.parentTree, false);
191
+
192
+ const replaceChildren = (event, navEl, currentTree, right) => {
193
+ navEl.replaceChildren(
194
+ Animate(
195
+ {
196
+ parent: navEl,
197
+ animationHide: `${
198
+ right ? hideToLeft : hideToRight
199
+ } ${animationDuration}`,
200
+ animationShow: `${
201
+ right ? showFromRight : showFromLeft
202
+ } ${animationDuration}`,
203
+ },
204
+ Menu({
205
+ currentTree,
206
+ onclickItem,
207
+ onclickBack,
208
+ })
209
+ )
210
+ );
211
+ };
212
+
213
+ const navEl = nav(
214
+ {
215
+ class: classNames(className, otherProps.class),
216
+ },
217
+ () => {
218
+ let currentTree = treeAddParent({})(tree);
219
+ let subTree = findSubTree(pathnameState.val)(currentTree);
220
+ if (!subTree) {
221
+ subTree = currentTree;
222
+ }
223
+ return Menu({
224
+ currentTree: subTree,
225
+ onclickItem,
226
+ onclickBack,
227
+ });
228
+ }
229
+ );
230
+
231
+ return navEl;
232
+ };
233
+ }
@@ -0,0 +1,18 @@
1
+ declare module "@grucloud/bau-ui/drillDownMenu" {
2
+ type Tree = {
3
+ data?: object;
4
+ children?: Tree[];
5
+ };
6
+ export type TreeViewProps = {
7
+ tree: Tree;
8
+ };
9
+
10
+ type Component = import("../bau-ui").Component<TreeViewProps>;
11
+
12
+ type ComponentGeneric = import("../bau-ui").ComponentGeneric;
13
+
14
+ type Option = {
15
+ renderMenuItem: ComponentGeneric;
16
+ };
17
+ export default function (context: Object, option: Option): Component;
18
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./drillDownMenu";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@grucloud/bau-ui",
3
3
  "description": "Components library built with Bau",
4
- "version": "0.31.0",
4
+ "version": "0.32.0",
5
5
  "type": "module",
6
6
  "license": "BSD",
7
7
  "keywords": [
@@ -17,8 +17,8 @@
17
17
  "url": "git@github.com:grucloud/bau.git"
18
18
  },
19
19
  "dependencies": {
20
- "@grucloud/bau": "^0.31.0",
21
- "@grucloud/bau-css": "^0.31.0"
20
+ "@grucloud/bau": "^0.32.0",
21
+ "@grucloud/bau-css": "^0.32.0"
22
22
  },
23
- "gitHead": "1cd3220771a68937b1a9ee8b1c3de7162cbf78f0"
23
+ "gitHead": "c279039e03a1784bb06f21fa8a24fc0b255d471d"
24
24
  }
@@ -144,9 +144,7 @@ export default function (context, { renderMenuItem }) {
144
144
  ul(
145
145
  {
146
146
  bauMounted: ({ element }) => {
147
- closeState.val
148
- ? (element.style.height = "0px")
149
- : (element.style.height = element.scrollHeight + "px");
147
+ closeState.val && (element.style.height = "0px");
150
148
  },
151
149
  "aria-expanded": ({ element }) => {
152
150
  collapseOrExpandSection({ element, closeState });