allaw-ui 0.0.331 → 0.0.333

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.
@@ -45,6 +45,8 @@
45
45
  .oauth-provider-button.linkedin {
46
46
  background: #0a66c2;
47
47
  width: 100%;
48
+ padding-left: 10px;
49
+ padding-right: 10px;
48
50
  }
49
51
 
50
52
  .oauth-provider-button.apple .label {
@@ -1,10 +1,11 @@
1
- import React from "react";
1
+ import React, { useState, useEffect, useRef } from "react";
2
2
  import "./OAuthProviderButton.css";
3
3
  import "../../../styles/global.css";
4
4
  var OAuthProviderButton = function (_a) {
5
5
  var provider = _a.provider, type = _a.type, url = _a.url, size = _a.size, onClick = _a.onClick;
6
- var getLabel = function () {
7
- var _a;
6
+ var _b = useState(""), label = _b[0], setLabel = _b[1];
7
+ var buttonRef = useRef(null);
8
+ var getLabels = function () {
8
9
  var labels = {
9
10
  google: {
10
11
  login: "Continuer avec Google",
@@ -19,8 +20,52 @@ var OAuthProviderButton = function (_a) {
19
20
  signup: "S'inscrire avec LinkedIn",
20
21
  },
21
22
  };
22
- return ((_a = labels[provider]) === null || _a === void 0 ? void 0 : _a[type]) || "";
23
+ var shortLabels = {
24
+ google: "Google",
25
+ apple: "Apple",
26
+ linkedin: "LinkedIn",
27
+ };
28
+ return { labels: labels, shortLabels: shortLabels };
23
29
  };
30
+ var getThresholdWidth = function (size) {
31
+ switch (size) {
32
+ case 14:
33
+ return 210;
34
+ case 16:
35
+ return 220;
36
+ case 18:
37
+ return 230;
38
+ case 20:
39
+ return 240;
40
+ case 22:
41
+ return 260;
42
+ case 24:
43
+ return 290;
44
+ default:
45
+ return 250;
46
+ }
47
+ };
48
+ var updateLabel = function () {
49
+ var _a;
50
+ var _b = getLabels(), labels = _b.labels, shortLabels = _b.shortLabels;
51
+ var maxWidth = ((_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0;
52
+ var thresholdWidth = getThresholdWidth(size);
53
+ var newLabel = maxWidth < thresholdWidth
54
+ ? shortLabels[provider]
55
+ : labels[provider][type];
56
+ setLabel(newLabel);
57
+ };
58
+ useEffect(function () {
59
+ updateLabel();
60
+ window.addEventListener("resize", updateLabel);
61
+ return function () {
62
+ window.removeEventListener("resize", updateLabel);
63
+ };
64
+ }, [provider, type, size]);
65
+ // Force an update after the first render to ensure the correct label is set
66
+ useEffect(function () {
67
+ setTimeout(updateLabel, 0);
68
+ }, []);
24
69
  var renderIcon = function () {
25
70
  var iconSizes = {
26
71
  google: size * 0.8,
@@ -42,13 +87,15 @@ var OAuthProviderButton = function (_a) {
42
87
  React.createElement("span", { className: "path4" })));
43
88
  }
44
89
  else if (provider === "linkedin") {
45
- var containerSize = size * 1.4; // Adjust this multiplier as needed
90
+ var containerSize = size * 1.4;
46
91
  return (React.createElement("div", { className: "linkedin-icon-container", style: {
47
92
  fontSize: "".concat(iconSize, "px"),
48
93
  width: "".concat(containerSize, "px"),
49
94
  height: "".concat(containerSize, "px"),
95
+ minWidth: "".concat(containerSize, "px"),
96
+ minHeight: "".concat(containerSize, "px"),
50
97
  } },
51
- React.createElement("i", { className: iconClass })));
98
+ React.createElement("i", { className: iconClass, style: { fontSize: "".concat(iconSize, "px") } })));
52
99
  }
53
100
  else {
54
101
  return (React.createElement("i", { className: iconClass, style: { fontSize: "".concat(iconSize, "px") } }));
@@ -80,8 +127,9 @@ var OAuthProviderButton = function (_a) {
80
127
  return "400px";
81
128
  }
82
129
  };
83
- return (React.createElement("button", { className: "oauth-provider-button ".concat(provider), onClick: handleClick, style: { height: "".concat(size * 2.55, "px"), maxWidth: getMaxWidth() } },
130
+ var maxWidth = getMaxWidth();
131
+ return (React.createElement("button", { ref: buttonRef, className: "oauth-provider-button ".concat(provider), onClick: handleClick, style: { height: "".concat(size * 2.55, "px"), maxWidth: maxWidth } },
84
132
  renderIcon(),
85
- React.createElement("span", { className: "label", style: { fontSize: "".concat(size, "px") } }, getLabel())));
133
+ React.createElement("span", { className: "label", style: { fontSize: "".concat(size, "px") } }, label)));
86
134
  };
87
135
  export default OAuthProviderButton;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "allaw-ui",
3
- "version": "0.0.331",
3
+ "version": "0.0.333",
4
4
  "description": "Composants UI pour l'application Allaw",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",