@grucloud/bau-ui 0.55.0 → 0.56.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.
@@ -264,13 +264,6 @@ export default function (context, componentOptions = {}) {
264
264
  `,
265
265
  });
266
266
 
267
- bau.derive(() => {
268
- if (selectedState.val) {
269
- inputShadowEl.value = getOptionValue(selectedState.val);
270
- onSelect(selectedState.val);
271
- }
272
- });
273
-
274
267
  return div(
275
268
  {
276
269
  ...props,
@@ -281,6 +274,15 @@ export default function (context, componentOptions = {}) {
281
274
  props?.class
282
275
  ),
283
276
  },
277
+ bau.bind({
278
+ deps: [selectedState],
279
+ render: () => (selected) => {
280
+ if (selected) {
281
+ inputShadowEl.value = getOptionValue(selected);
282
+ onSelect(selected);
283
+ }
284
+ },
285
+ }),
284
286
  buttonEl,
285
287
  inputShadowEl,
286
288
  popoverEl
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.55.0",
4
+ "version": "0.56.0",
5
5
  "type": "module",
6
6
  "license": "BSD",
7
7
  "keywords": [
@@ -20,11 +20,11 @@
20
20
  "directory": "bau-ui"
21
21
  },
22
22
  "dependencies": {
23
- "@grucloud/bau": "^0.55.0",
24
- "@grucloud/bau-css": "^0.55.0"
23
+ "@grucloud/bau": "^0.56.0",
24
+ "@grucloud/bau-css": "^0.56.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "typedoc": "0.24.8"
28
28
  },
29
- "gitHead": "ee5d05d4fdeaf72e84a473e0549af00b867910c7"
29
+ "gitHead": "e5671d456337fd1f4a85e5f6cb0eb3c75e82d340"
30
30
  }
@@ -18,6 +18,7 @@ declare module "@grucloud/bau-ui/stepper" {
18
18
  } & StepperPagePropBase;
19
19
 
20
20
  export type StepperProps = {
21
+ stepperName: string;
21
22
  stepperDefs: StepperPage[];
22
23
  };
23
24
 
@@ -25,5 +26,10 @@ declare module "@grucloud/bau-ui/stepper" {
25
26
 
26
27
  type Option = {} & ComponentOption;
27
28
 
29
+ export function NextUrl(
30
+ context: any,
31
+ stepperName: string
32
+ ): (nextStep: string, state?: any) => string;
33
+
28
34
  export default function (context: any, option?: Option): Component;
29
35
  }
package/stepper/index.js CHANGED
@@ -1 +1 @@
1
- export { default } from "./stepper";
1
+ export { default, NextUrl } from "./stepper";
@@ -3,36 +3,41 @@ import classNames from "@grucloud/bau-css/classNames.js";
3
3
 
4
4
  import { Colors } from "../constants.js";
5
5
 
6
- const colorsToCss = () =>
7
- Colors.map(
8
- (color) =>
9
- `
10
- `
11
- ).join("\n");
6
+ const colorsToCss = () => Colors.map((color) => ``).join("\n");
7
+
8
+ export const NextUrl = (context, stepperName) => (nextStep, state) => {
9
+ const search = new URLSearchParams(context.window.location.search);
10
+ search.delete(stepperName);
11
+ search.append(stepperName, nextStep);
12
+ state &&
13
+ Object.entries(state).map(
14
+ ([k, v]) => (search.delete(k), search.append(k, v))
15
+ );
16
+ return `?${search.toString()}`;
17
+ };
12
18
 
13
19
  export default function (context, options = {}) {
14
20
  const { bau, css, window } = context;
15
- const { div, ul, li, span, footer } = bau.tags;
21
+ const { div, ul, li, span, section } = bau.tags;
16
22
 
17
23
  const className = css`
18
24
  display: flex;
19
25
  flex-direction: column;
20
- padding: 1rem;
21
26
  & > ul {
22
27
  display: flex;
23
28
  align-items: flex-end;
24
- justify-content: space-around;
29
+ justify-content: flex-start;
25
30
  align-items: flex-start;
26
31
  padding: 0;
32
+ gap: 1rem;
27
33
  list-style: none;
28
34
  & > li {
29
35
  display: flex;
30
36
  flex-direction: column;
31
37
  align-items: center;
32
38
  box-sizing: border-box;
33
- flex-grow: 1;
39
+ flex-grow: 0;
34
40
  padding: 0.5rem;
35
- padding-bottom: 0rem;
36
41
  color: inherit;
37
42
  font-weight: var(--font-weight-semibold);
38
43
  transition: all var(--transition-slow) ease-in-out;
@@ -76,19 +81,15 @@ export default function (context, options = {}) {
76
81
  }
77
82
  }
78
83
  ${colorsToCss()}
79
- &.stepper > .content {
84
+ &.stepper > section > .content {
80
85
  visibility: hidden;
81
86
  display: none;
82
87
  }
83
88
 
84
- &.stepper > .visible {
89
+ &.stepper > section > .visible {
85
90
  visibility: visible;
86
91
  display: block;
87
92
  }
88
- &.stepper footer {
89
- display: flex;
90
- gap: 1rem;
91
- }
92
93
  `;
93
94
 
94
95
  return function Stepper(...args) {
@@ -98,28 +99,44 @@ export default function (context, options = {}) {
98
99
  variant = "plain",
99
100
  size,
100
101
  stepperDefs = [],
102
+ stepperName,
101
103
  activeStepIndex = bau.state(0),
102
104
  ...props
103
105
  },
104
106
  ...children
105
107
  ] = toPropsAndChildren(args);
106
-
107
108
  const stepperState = bau.state(
108
109
  stepperDefs.map((stepper, index) => ({ ...stepper, index }))
109
110
  );
110
111
 
112
+ const stepsCreatedState = bau.state([]);
113
+
111
114
  const hashchange = () => {
112
- const stepNameInitial = window.location.hash.slice(1).split("?")[0];
113
- console.log("hashchange", stepNameInitial);
114
- const initialActiveStep = stepperDefs.findIndex(
115
- ({ name }) => name == stepNameInitial
115
+ const search = new URLSearchParams(window.location.search);
116
+ const stepNameInitial = search.get(stepperName) ?? stepperDefs[0].name;
117
+ const nextActiveStep = Math.max(
118
+ stepperDefs.findIndex(({ name }) => name == stepNameInitial),
119
+ 0
116
120
  );
121
+ // console.log(
122
+ // "hashchange",
123
+ // stepNameInitial,
124
+ // " stepsCreatedState.val",
125
+ // stepsCreatedState.val,
126
+ // "nextActiveStep",
127
+ // nextActiveStep
128
+ // );
117
129
 
118
- if (initialActiveStep >= 0) {
119
- activeStepIndex.val = initialActiveStep;
120
- } else {
121
- activeStepIndex.val = 0;
130
+ if (nextActiveStep < activeStepIndex.val) {
131
+ console.log("remove last step");
132
+ stepsCreatedState.val.pop();
122
133
  }
134
+
135
+ if (!stepsCreatedState.val.some(({ name }) => stepNameInitial == name)) {
136
+ console.log("add new step");
137
+ stepsCreatedState.val.push(stepperDefs[nextActiveStep]);
138
+ }
139
+ activeStepIndex.val = nextActiveStep;
123
140
  };
124
141
 
125
142
  hashchange();
@@ -127,6 +144,8 @@ export default function (context, options = {}) {
127
144
  window.history.pushState = new Proxy(window.history.pushState, {
128
145
  apply: (target, thisArg, argArray) => {
129
146
  target.apply(thisArg, argArray);
147
+ console.log("stepper pushState");
148
+
130
149
  const url = argArray[2] ?? "";
131
150
  if (["?", "#"].includes(url[0])) {
132
151
  hashchange();
@@ -137,8 +156,9 @@ export default function (context, options = {}) {
137
156
  const { target } = event;
138
157
  const href = target.getAttribute("href");
139
158
  if (target.tagName === "A" && href && ["?", "#"].includes(href[0])) {
140
- //console.log("a click");
141
- hashchange();
159
+ console.log("stepper click");
160
+ //hashchange();
161
+ event.preventDefault();
142
162
  }
143
163
  });
144
164
  //TODO bauMounted
@@ -167,8 +187,10 @@ export default function (context, options = {}) {
167
187
  span({ class: "step-label" }, () => Header(stepper))
168
188
  );
169
189
  };
190
+ const getIndex = (step) =>
191
+ stepperDefs.findIndex(({ name }) => name == step.name);
170
192
 
171
- const rootEl = div(
193
+ return div(
172
194
  {
173
195
  class: classNames(
174
196
  "stepper",
@@ -182,8 +204,7 @@ export default function (context, options = {}) {
182
204
  },
183
205
  // Header
184
206
  bau.loop(stepperState, ul(), StepperHeader),
185
- // Content
186
- stepperDefs.map((stepperDef) =>
207
+ bau.loop(stepsCreatedState, section(), (stepperDef) =>
187
208
  div(
188
209
  {
189
210
  class: () =>
@@ -192,11 +213,12 @@ export default function (context, options = {}) {
192
213
  stepperDef.name == stepperCurrentState.val.name && "visible"
193
214
  ),
194
215
  },
195
- () => (stepperDef.Content ? stepperDef.Content(props) : ""),
196
- footer(stepperDef.Footer ? stepperDef.Footer(props) : "")
216
+ stepperDef.Content({
217
+ nextStep: stepperDefs[getIndex(stepperDef) + 1],
218
+ previousStep: stepperDefs[getIndex(stepperDef) - 1],
219
+ })
197
220
  )
198
221
  )
199
222
  );
200
- return rootEl;
201
223
  };
202
224
  }
package/tabs/tabs.js CHANGED
@@ -129,9 +129,13 @@ export default function (context, options = {}) {
129
129
  },
130
130
  // Header
131
131
  bau.loop(tabsState, ul(), TabHeader),
132
- // Content
133
- () =>
134
- tabCurrentState.val.Content ? tabCurrentState.val.Content(props) : ""
132
+ bau.bind({
133
+ deps: [tabCurrentState],
134
+ render:
135
+ () =>
136
+ ({ Content }) =>
137
+ Content ? Content(props) : "",
138
+ })
135
139
  );
136
140
 
137
141
  rootEl.addEventListener(