@nr1e/qwik-ui 2.0.19 → 2.0.20

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.
@@ -5,37 +5,26 @@ const qwik = require("@builder.io/qwik");
5
5
  const qwikIcons = require("@nr1e/qwik-icons");
6
6
  const button = require("./button.qwik.cjs");
7
7
  const ProcessingButton = qwik.component$((props) => {
8
- const externalProcessing = qwik.isSignal(props.processing) ? props.processing : void 0;
9
8
  const internalProcessing = qwik.useSignal(qwik.isSignal(props.processing) ? props.processing.value : props.processing ?? false);
9
+ const processing = qwik.isSignal(props.processing) ? props.processing : internalProcessing;
10
10
  const onClick$ = props.onClick$;
11
- qwik.useTask$(({ track }) => {
12
- if (externalProcessing) {
13
- track(() => externalProcessing.value);
14
- if (externalProcessing.value !== internalProcessing.value) {
15
- internalProcessing.value = externalProcessing.value;
16
- }
17
- }
18
- });
19
- qwik.useTask$(({ track }) => {
20
- if (externalProcessing) {
21
- track(() => internalProcessing.value);
22
- if (externalProcessing.value !== internalProcessing.value) {
23
- externalProcessing.value = internalProcessing.value;
24
- }
25
- }
26
- });
27
11
  return /* @__PURE__ */ jsxRuntime.jsx(button.Button, {
28
12
  ...props,
29
13
  class: `${props.processing || props.disabled ? "disabled" : ""} ${props.class ?? ""}`,
30
- disabled: internalProcessing.value || props.disabled,
14
+ disabled: processing.value || props.disabled,
31
15
  onClick$: (e) => {
32
- internalProcessing.value = true;
16
+ processing.value = true;
33
17
  if (onClick$) {
34
- onClick$(e);
18
+ const result = onClick$(e);
19
+ if (result instanceof Promise) {
20
+ result.finally(() => {
21
+ processing.value = false;
22
+ });
23
+ }
35
24
  }
36
25
  },
37
- icon: internalProcessing.value ? qwikIcons.SpinnersBarsFade : props.icon,
38
- iconClass: internalProcessing.value ? "animate-spin" : props.iconClass,
26
+ icon: processing.value ? qwikIcons.SpinnersBarsFade : props.icon,
27
+ iconClass: processing.value ? "animate-spin" : props.iconClass,
39
28
  children: /* @__PURE__ */ jsxRuntime.jsx(qwik.Slot, {})
40
29
  });
41
30
  });
@@ -1,39 +1,28 @@
1
1
  import { jsx } from "@builder.io/qwik/jsx-runtime";
2
- import { component$, isSignal, useSignal, useTask$, Slot } from "@builder.io/qwik";
2
+ import { component$, useSignal, isSignal, Slot } from "@builder.io/qwik";
3
3
  import { SpinnersBarsFade } from "@nr1e/qwik-icons";
4
4
  import { Button } from "./button.qwik.mjs";
5
5
  const ProcessingButton = component$((props) => {
6
- const externalProcessing = isSignal(props.processing) ? props.processing : void 0;
7
6
  const internalProcessing = useSignal(isSignal(props.processing) ? props.processing.value : props.processing ?? false);
7
+ const processing = isSignal(props.processing) ? props.processing : internalProcessing;
8
8
  const onClick$ = props.onClick$;
9
- useTask$(({ track }) => {
10
- if (externalProcessing) {
11
- track(() => externalProcessing.value);
12
- if (externalProcessing.value !== internalProcessing.value) {
13
- internalProcessing.value = externalProcessing.value;
14
- }
15
- }
16
- });
17
- useTask$(({ track }) => {
18
- if (externalProcessing) {
19
- track(() => internalProcessing.value);
20
- if (externalProcessing.value !== internalProcessing.value) {
21
- externalProcessing.value = internalProcessing.value;
22
- }
23
- }
24
- });
25
9
  return /* @__PURE__ */ jsx(Button, {
26
10
  ...props,
27
11
  class: `${props.processing || props.disabled ? "disabled" : ""} ${props.class ?? ""}`,
28
- disabled: internalProcessing.value || props.disabled,
12
+ disabled: processing.value || props.disabled,
29
13
  onClick$: (e) => {
30
- internalProcessing.value = true;
14
+ processing.value = true;
31
15
  if (onClick$) {
32
- onClick$(e);
16
+ const result = onClick$(e);
17
+ if (result instanceof Promise) {
18
+ result.finally(() => {
19
+ processing.value = false;
20
+ });
21
+ }
33
22
  }
34
23
  },
35
- icon: internalProcessing.value ? SpinnersBarsFade : props.icon,
36
- iconClass: internalProcessing.value ? "animate-spin" : props.iconClass,
24
+ icon: processing.value ? SpinnersBarsFade : props.icon,
25
+ iconClass: processing.value ? "animate-spin" : props.iconClass,
37
26
  children: /* @__PURE__ */ jsx(Slot, {})
38
27
  });
39
28
  });
@@ -15,7 +15,7 @@ export interface ButtonProps {
15
15
  /**
16
16
  * Callback function to be called when the button is clicked.
17
17
  */
18
- onClick$?: QRL<(event: Event) => void>;
18
+ onClick$?: QRL<(event: Event) => void | Promise<void>>;
19
19
  /**
20
20
  * Whether the button is disabled.
21
21
  */
@@ -2,9 +2,7 @@ import { Signal } from '@builder.io/qwik';
2
2
  import { ButtonProps } from './button';
3
3
  /**
4
4
  * Props for the ProcessingButton component. This class will replace the icon
5
- * with a rotating spinner when the button is processing. It will also
6
- * automatically set processing to true when the button is clicked. It does
7
- * not set processing to false when the button is clicked.
5
+ * with a rotating spinner when clicked.
8
6
  */
9
7
  export interface ProcessingButtonProps extends ButtonProps {
10
8
  /**
@@ -11,7 +11,7 @@ export interface RefreshButtonProps {
11
11
  /**
12
12
  * Callback function to be called when the button is clicked.
13
13
  */
14
- onClick$?: QRL<(event: Event) => void>;
14
+ onClick$?: QRL<(event: Event) => void | Promise<void>>;
15
15
  /**
16
16
  * Whether the button is disabled.
17
17
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nr1e/qwik-ui",
3
- "version": "2.0.19",
3
+ "version": "2.0.20",
4
4
  "description": "NR1E Qwik UI Library",
5
5
  "author": "NR1E, Inc.",
6
6
  "publishConfig": {