allaw-ui 0.1.27 → 0.1.28

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,14 +1,18 @@
1
- import React from "react";
1
+ import React, { ButtonHTMLAttributes } from "react";
2
2
  import "./SecondaryButton.css";
3
3
  import "../../../styles/global.css";
4
- export interface SecondaryButtonProps {
4
+ export interface SecondaryButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
5
5
  startIcon?: React.ReactNode;
6
6
  endIcon?: React.ReactNode;
7
+ startIconName?: string;
8
+ endIconName?: string;
7
9
  label: string;
8
10
  disabled?: boolean;
9
11
  mode?: "dark" | "light";
10
- onClick?: () => void;
12
+ onClick?: () => Promise<void> | void;
11
13
  fullWidth?: boolean;
14
+ type?: "button" | "submit" | "reset";
15
+ isLoading?: boolean;
12
16
  }
13
- declare const SecondaryButton: React.FC<SecondaryButtonProps>;
17
+ declare const SecondaryButton: React.ForwardRefExoticComponent<SecondaryButtonProps & React.RefAttributes<HTMLButtonElement>>;
14
18
  export default SecondaryButton;
@@ -1,11 +1,117 @@
1
- import React from "react";
1
+ "use client";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
60
+ import React, { forwardRef, useImperativeHandle, useState, useEffect, } from "react";
2
61
  import "./SecondaryButton.css";
3
62
  import "../../../styles/global.css";
4
- var SecondaryButton = function (_a) {
5
- var startIcon = _a.startIcon, endIcon = _a.endIcon, label = _a.label, _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.mode, mode = _c === void 0 ? "dark" : _c, onClick = _a.onClick, _d = _a.fullWidth, fullWidth = _d === void 0 ? false : _d;
6
- return (React.createElement("button", { className: "secondary-button ".concat(disabled ? "secondary-button-disabled" : "secondary-button-enabled", " secondary-button-").concat(mode, " ").concat(fullWidth ? "secondary-button-full-width" : ""), disabled: disabled, onClick: onClick },
7
- startIcon && React.createElement("span", { className: "secondary-button-icon ".concat(startIcon) }),
63
+ var SecondaryButton = forwardRef(function (_a, ref) {
64
+ var startIcon = _a.startIcon, endIcon = _a.endIcon, startIconName = _a.startIconName, endIconName = _a.endIconName, label = _a.label, _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.mode, mode = _c === void 0 ? "dark" : _c, onClick = _a.onClick, _d = _a.fullWidth, fullWidth = _d === void 0 ? false : _d, _e = _a.type, type = _e === void 0 ? "button" : _e, _f = _a.isLoading, isLoading = _f === void 0 ? false : _f, props = __rest(_a, ["startIcon", "endIcon", "startIconName", "endIconName", "label", "disabled", "mode", "onClick", "fullWidth", "type", "isLoading"]);
65
+ var buttonRef = React.useRef(null);
66
+ var _g = useState(false), internalIsLoading = _g[0], setInternalIsLoading = _g[1];
67
+ var _h = useState(""), loadingDots = _h[0], setLoadingDots = _h[1];
68
+ useImperativeHandle(ref, function () { return buttonRef.current; });
69
+ var isButtonLoading = isLoading || internalIsLoading;
70
+ useEffect(function () {
71
+ var interval = null;
72
+ if (isButtonLoading) {
73
+ interval = setInterval(function () {
74
+ setLoadingDots(function (prev) {
75
+ if (prev.length >= 3)
76
+ return "";
77
+ return prev + ".";
78
+ });
79
+ }, 500);
80
+ }
81
+ return function () {
82
+ if (interval) {
83
+ clearInterval(interval);
84
+ }
85
+ };
86
+ }, [isButtonLoading]);
87
+ var handleClick = function (event) { return __awaiter(void 0, void 0, void 0, function () {
88
+ return __generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0:
91
+ if (isButtonLoading) {
92
+ event.preventDefault();
93
+ return [2 /*return*/];
94
+ }
95
+ if (!onClick) return [3 /*break*/, 4];
96
+ setInternalIsLoading(true);
97
+ _a.label = 1;
98
+ case 1:
99
+ _a.trys.push([1, , 3, 4]);
100
+ return [4 /*yield*/, onClick()];
101
+ case 2:
102
+ _a.sent();
103
+ return [3 /*break*/, 4];
104
+ case 3:
105
+ setInternalIsLoading(false);
106
+ return [7 /*endfinally*/];
107
+ case 4: return [2 /*return*/];
108
+ }
109
+ });
110
+ }); };
111
+ return (React.createElement("button", __assign({ ref: buttonRef, className: "secondary-button ".concat(disabled ? "secondary-button-disabled" : "secondary-button-enabled", " secondary-button-").concat(mode, " ").concat(fullWidth ? "secondary-button-full-width" : "", " ").concat(isButtonLoading ? "secondary-button-loading" : ""), disabled: disabled, onClick: handleClick, type: type }, props),
112
+ startIcon && (React.createElement("span", { className: "secondary-button-icon ".concat(startIconName) })),
8
113
  React.createElement("span", { className: "secondary-button-label" }, label),
9
- endIcon && React.createElement("span", { className: "secondary-button-icon ".concat(endIcon) })));
10
- };
114
+ isButtonLoading ? (React.createElement("span", { className: "secondary-button-loading-dots" }, loadingDots)) : (endIcon && React.createElement("span", { className: "secondary-button-icon ".concat(endIconName) }))));
115
+ });
116
+ SecondaryButton.displayName = "SecondaryButton";
11
117
  export default SecondaryButton;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "allaw-ui",
3
- "version": "0.1.27",
3
+ "version": "0.1.28",
4
4
  "description": "Composants UI pour l'application Allaw",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",