@gustavo-valsechi/client 1.4.4 → 1.4.5

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.
@@ -33,17 +33,31 @@ __export(button_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(button_exports);
35
35
  var import_jsx_runtime = require("react/jsx-runtime");
36
+ var import_react = require("react");
36
37
  var import_styles = require("./styles");
37
38
  var import_loading = require("./loading");
38
39
  var import_lodash = __toESM(require("lodash"));
39
40
  function Button(props) {
41
+ const [loading, setLoading] = (0, import_react.useState)(false);
42
+ const onClick = async (e) => {
43
+ var _a, _b;
44
+ if (!props.onClick) return;
45
+ setLoading(true);
46
+ if (((_b = (_a = props.onClick) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name) === "AsyncFunction") {
47
+ await props.onClick(e);
48
+ } else {
49
+ props.onClick(e);
50
+ }
51
+ setLoading(false);
52
+ };
40
53
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
41
54
  import_styles.Container,
42
55
  {
43
- loading: String(!!props.loading),
56
+ loading: String(loading || !!props.loading),
44
57
  disabled: props.disabled,
45
58
  type: props.type || "button",
46
- ...import_lodash.default.omit(props, ["loading", "type"]),
59
+ onClick,
60
+ ...import_lodash.default.omit(props, ["loading", "type", "onClick"]),
47
61
  children: [
48
62
  !!props.loading && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_loading.Loading, {}),
49
63
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: props.label })
@@ -1,16 +1,30 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
3
4
  import { Container } from "./styles";
4
5
  import { Loading } from "./loading";
5
6
  import _ from "lodash";
6
7
  function Button(props) {
8
+ const [loading, setLoading] = useState(false);
9
+ const onClick = async (e) => {
10
+ var _a, _b;
11
+ if (!props.onClick) return;
12
+ setLoading(true);
13
+ if (((_b = (_a = props.onClick) == null ? void 0 : _a.constructor) == null ? void 0 : _b.name) === "AsyncFunction") {
14
+ await props.onClick(e);
15
+ } else {
16
+ props.onClick(e);
17
+ }
18
+ setLoading(false);
19
+ };
7
20
  return /* @__PURE__ */ jsxs(
8
21
  Container,
9
22
  {
10
- loading: String(!!props.loading),
23
+ loading: String(loading || !!props.loading),
11
24
  disabled: props.disabled,
12
25
  type: props.type || "button",
13
- ..._.omit(props, ["loading", "type"]),
26
+ onClick,
27
+ ..._.omit(props, ["loading", "type", "onClick"]),
14
28
  children: [
15
29
  !!props.loading && /* @__PURE__ */ jsx(Loading, {}),
16
30
  /* @__PURE__ */ jsx("span", { children: props.label })
@@ -2,6 +2,6 @@ export interface IButton {
2
2
  loading?: boolean;
3
3
  disabled?: boolean;
4
4
  type?: string;
5
- onClick?: () => void;
5
+ onClick?: (e?: any) => void;
6
6
  label: string;
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gustavo-valsechi/client",
3
- "version": "1.4.4",
3
+ "version": "1.4.5",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",