bmi-next-brokers 3.0.2 → 3.0.3

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.
@@ -27,5 +27,9 @@ export interface SwitchProps {
27
27
  inactiveTextColor?: string;
28
28
  /** color de fondo del contenedor (CSS var --switch-bg) */
29
29
  background?: string;
30
+ /** si false, cada opción se adapta a su contenido; por defecto true (todas al ancho de la más larga) */
31
+ equalWidth?: boolean;
32
+ /** estilos inline aplicados a todos los botones de opción */
33
+ optionStyle?: React.CSSProperties;
30
34
  }
31
- export declare const Switch: ({ options, active, onChange, size, simpleAnimation, iconSize, className, activeColor, activeTextColor, inactiveTextColor, background, }: SwitchProps) => import("react/jsx-runtime").JSX.Element;
35
+ export declare const Switch: ({ options, active, onChange, size, simpleAnimation, iconSize, className, activeColor, activeTextColor, inactiveTextColor, background, equalWidth, optionStyle, }: SwitchProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,102 +1,106 @@
1
- import { jsxs as E, jsx as m } from "react/jsx-runtime";
2
- import { useRef as p, useState as M, useLayoutEffect as j } from "react";
3
- import { Icon as k } from "../../icons/Icon.js";
4
- import '../../assets/Switch.css';const D = "_small_56b6x_29", R = "_large_56b6x_40", T = "_indicator_56b6x_52", Z = "_simple_56b6x_68", z = "_option_56b6x_74", B = "_active_56b6x_74", K = "_label_56b6x_74", O = "_pop_56b6x_1", r = {
1
+ import { jsxs as L, jsx as m } from "react/jsx-runtime";
2
+ import { useRef as p, useState as k, useLayoutEffect as D } from "react";
3
+ import { Icon as R } from "../../icons/Icon.js";
4
+ import '../../assets/Switch.css';const T = "_small_56b6x_29", Z = "_large_56b6x_40", z = "_indicator_56b6x_52", B = "_simple_56b6x_68", K = "_option_56b6x_74", O = "_active_56b6x_74", V = "_label_56b6x_74", X = "_pop_56b6x_1", r = {
5
5
  switch: "_switch_56b6x_1",
6
- small: D,
7
- large: R,
8
- indicator: T,
9
- simple: Z,
10
- option: z,
11
- active: B,
12
- label: K,
13
- pop: O
14
- }, V = {
6
+ small: T,
7
+ large: Z,
8
+ indicator: z,
9
+ simple: B,
10
+ option: K,
11
+ active: O,
12
+ label: V,
13
+ pop: X
14
+ }, Y = {
15
15
  small: 12,
16
16
  medium: 14,
17
17
  large: 16
18
- }, q = ({
18
+ }, G = ({
19
19
  options: d = [],
20
20
  active: l = 0,
21
21
  onChange: o,
22
22
  size: h = "medium",
23
23
  simpleAnimation: u = !1,
24
- iconSize: L,
25
- className: S = "",
24
+ iconSize: S,
25
+ className: N = "",
26
26
  activeColor: b,
27
27
  activeTextColor: w,
28
28
  inactiveTextColor: x,
29
- background: y
29
+ background: y,
30
+ equalWidth: $ = !0,
31
+ optionStyle: W
30
32
  }) => {
31
- const a = p([]), $ = p(l), n = p(null), [v, I] = M({
33
+ const _ = p([]), v = p(l), n = p(null), [I, E] = k({
32
34
  left: 0,
33
35
  width: 0
34
36
  });
35
- j(() => {
36
- const t = a.current[l], e = a.current[$.current];
37
+ D(() => {
38
+ const t = _.current[l], s = _.current[v.current];
37
39
  if (!t) return;
38
- const i = a.current.filter(
39
- (s) => s !== null
40
+ const i = _.current.filter(
41
+ (e) => e !== null
40
42
  );
41
- i.forEach((s) => s.style.width = "auto");
42
- const _ = Math.max(...i.map((s) => s.offsetWidth));
43
- i.forEach((s) => s.style.width = `${_}px`);
44
- const f = () => I({ left: t.offsetLeft, width: t.offsetWidth });
45
- if (!u && e && e !== t) {
46
- const s = Math.min(e.offsetLeft, t.offsetLeft), c = Math.max(
47
- e.offsetLeft + e.offsetWidth,
43
+ if (i.forEach((e) => e.style.width = "auto"), $) {
44
+ const e = Math.max(...i.map((c) => c.offsetWidth));
45
+ i.forEach((c) => c.style.width = `${e}px`);
46
+ }
47
+ const f = () => E({ left: t.offsetLeft, width: t.offsetWidth });
48
+ if (!u && s && s !== t) {
49
+ const e = Math.min(s.offsetLeft, t.offsetLeft), c = Math.max(
50
+ s.offsetLeft + s.offsetWidth,
48
51
  t.offsetLeft + t.offsetWidth
49
52
  );
50
- I({ left: s, width: c - s }), n.current && clearTimeout(n.current), n.current = setTimeout(f, 160);
53
+ E({ left: e, width: c - e }), n.current && clearTimeout(n.current), n.current = setTimeout(f, 160);
51
54
  } else
52
55
  f();
53
- return $.current = l, () => {
56
+ return v.current = l, () => {
54
57
  n.current && clearTimeout(n.current);
55
58
  };
56
- }, [l, d, u]);
57
- const N = L ?? V[h], W = {
59
+ }, [l, d, u, $]);
60
+ const M = S ?? Y[h], j = {
58
61
  ...b && { "--switch-active-bg": b },
59
62
  ...w && { "--switch-active-text": w },
60
63
  ...x && { "--switch-inactive-text": x },
61
64
  ...y && { "--switch-bg": y }
62
65
  };
63
- return /* @__PURE__ */ E(
66
+ return /* @__PURE__ */ L(
64
67
  "div",
65
68
  {
66
- className: `${r.switch} ${r[h]} ${u ? r.simple : ""} ${S}`,
67
- style: W,
69
+ className: `${r.switch} ${r[h]} ${u ? r.simple : ""} ${N}`,
70
+ style: j,
68
71
  children: [
69
72
  /* @__PURE__ */ m(
70
73
  "span",
71
74
  {
72
75
  className: r.indicator,
73
76
  style: {
74
- transform: `translateX(${v.left}px)`,
75
- width: `${v.width}px`
77
+ transform: `translateX(${I.left}px)`,
78
+ width: `${I.width}px`
76
79
  }
77
80
  }
78
81
  ),
79
- d.map((t, e) => {
80
- const i = typeof t == "string", _ = i ? t : t.label, f = i ? null : t.icon, s = l === e;
81
- return /* @__PURE__ */ E(
82
+ d.map((t, s) => {
83
+ const i = typeof t == "string", f = i ? t : t.label, e = i ? null : t.icon, c = l === s;
84
+ return /* @__PURE__ */ L(
82
85
  "div",
83
86
  {
84
- ref: (c) => {
85
- a.current[e] = c;
87
+ ref: (a) => {
88
+ _.current[s] = a;
86
89
  },
87
90
  role: "button",
88
91
  tabIndex: 0,
89
- onClick: () => o == null ? void 0 : o(e),
90
- onKeyDown: (c) => {
91
- (c.key === "Enter" || c.key === " ") && (c.preventDefault(), o == null || o(e));
92
+ onClick: () => o == null ? void 0 : o(s),
93
+ onKeyDown: (a) => {
94
+ (a.key === "Enter" || a.key === " ") && (a.preventDefault(), o == null || o(s));
92
95
  },
93
- className: `${r.option} ${s ? r.active : ""}`,
96
+ className: `${r.option} ${c ? r.active : ""}`,
97
+ style: W,
94
98
  children: [
95
- f && /* @__PURE__ */ m(k, { name: f, size: N }),
96
- _ && /* @__PURE__ */ m("p", { className: r.label, children: _ })
99
+ e && /* @__PURE__ */ m(R, { name: e, size: M }),
100
+ f && /* @__PURE__ */ m("p", { className: r.label, children: f })
97
101
  ]
98
102
  },
99
- e
103
+ s
100
104
  );
101
105
  })
102
106
  ]
@@ -104,5 +108,5 @@ import '../../assets/Switch.css';const D = "_small_56b6x_29", R = "_large_56b6x_
104
108
  );
105
109
  };
106
110
  export {
107
- q as Switch
111
+ G as Switch
108
112
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bmi-next-brokers",
3
3
  "description": "Componentes de UI para proyecto BMI Next Brokers",
4
- "version": "3.0.2",
4
+ "version": "3.0.3",
5
5
  "author": "BMI Ahorro España",
6
6
  "contributors": [
7
7
  "José Ramón Jiménez <jrjimenez@bmicos.com>",