@telefonica/mistica 14.26.0 → 14.27.0

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.
package/dist-es/menu.js CHANGED
@@ -51,15 +51,15 @@ function _object_spread_props(target, source) {
51
51
  return target;
52
52
  }
53
53
  import { jsx as e, jsxs as C, Fragment as U } from "react/jsx-runtime";
54
- import * as n from "react";
54
+ import * as o from "react";
55
55
  import ne from "classnames";
56
56
  import { TAB as oe, ENTER as W, SPACE as G, ESC as se, UP as re, LEFT as ie, DOWN as K, RIGHT as ce } from "./utils/key-codes.js";
57
57
  import { getPrefixedDataAttributes as le, cancelEvent as S } from "./utils/dom.js";
58
58
  import ae from "./overlay.js";
59
- import { menuItem as me, menuItemEnabled as ue, menuItemDisabled as de, menuItemHovered as fe, menuSectionDivider as pe, menuTransitionClasses as he, vars as I, itemContent as Y, iconContainer as j, menuContainer as ge } from "./menu.css-mistica.js";
59
+ import { menuItem as ue, menuItemEnabled as me, menuItemDisabled as de, menuItemHovered as fe, menuSectionDivider as pe, menuTransitionClasses as he, vars as b, itemContent as Y, iconContainer as j, menuContainer as ge } from "./menu.css-mistica.js";
60
60
  import { useWindowSize as xe } from "./hooks.js";
61
- import { Portal as Ie } from "./portal.js";
62
- import { assignInlineVars as be } from "@vanilla-extract/dynamic";
61
+ import { Portal as be } from "./portal.js";
62
+ import { assignInlineVars as Ie } from "@vanilla-extract/dynamic";
63
63
  import y from "./box.js";
64
64
  import ve from "./inline.js";
65
65
  import Me from "./touchable.js";
@@ -69,25 +69,25 @@ import Oe from "./divider.js";
69
69
  import Te from "./checkbox.js";
70
70
  import { CSSTransition as Se } from "react-transition-group";
71
71
  import { combineRefs as Ce } from "./utils/common.js";
72
- const Ee = 120, Q = /*#__PURE__*/ n.createContext({
72
+ const Ee = 120, Q = /*#__PURE__*/ o.createContext({
73
73
  focusedItem: null,
74
74
  isMenuOpen: !1,
75
75
  setFocusedItem: ()=>{},
76
76
  closeMenu: ()=>{}
77
- }), ke = ()=>n.useContext(Q), D = (r)=>r ? Array.from(r.querySelectorAll("[role=menuitem],[role=menuitemcheckbox]")) : [], Ne = (r, d)=>{
77
+ }), ke = ()=>o.useContext(Q), D = (r)=>r ? Array.from(r.querySelectorAll("[role=menuitem],[role=menuitemcheckbox]")) : [], Ne = (r, d)=>{
78
78
  if (!d) return null;
79
79
  const f = D(r).indexOf(d);
80
80
  return f < 0 ? null : f;
81
81
  }, je = (param)=>{
82
- let { label: r , Icon: d , destructive: f , disabled: m , onPress: E , controlType: o , checked: p } = param;
83
- const { focusedItem: s , setFocusedItem: v , closeMenu: i , isMenuOpen: k } = ke(), c = n.useRef(null), h = f ? q.colors.textLinkDanger : q.colors.neutralHigh, x = c == null ? void 0 : c.current, M = (x == null ? void 0 : x.closest("[role=menu]")) || null, u = Ne(M, x), l = ()=>o === "checkbox" ? /* @__PURE__ */ e(Te, {
82
+ let { label: r , Icon: d , destructive: f , disabled: u , onPress: E , controlType: s , checked: p } = param;
83
+ const { focusedItem: n , setFocusedItem: v , closeMenu: i , isMenuOpen: k } = ke(), c = o.useRef(null), h = f ? q.colors.textLinkDanger : q.colors.neutralHigh, x = c == null ? void 0 : c.current, M = (x == null ? void 0 : x.closest("[role=menu]")) || null, m = Ne(M, x), l = ()=>s === "checkbox" ? /* @__PURE__ */ e(Te, {
84
84
  ref: c,
85
85
  name: r,
86
86
  checked: p,
87
87
  onChange: ()=>{
88
- k && u !== null && (E(u), i());
88
+ k && m !== null && (E(m), i());
89
89
  },
90
- disabled: m,
90
+ disabled: u,
91
91
  role: "menuitemcheckbox",
92
92
  render: (param)=>/* @__PURE__ */ {
93
93
  let { controlElement: N } = param;
@@ -126,9 +126,9 @@ const Ee = 120, Q = /*#__PURE__*/ n.createContext({
126
126
  }) : /* @__PURE__ */ e(Me, {
127
127
  ref: c,
128
128
  onPress: ()=>{
129
- k && u !== null && (E(u), i());
129
+ k && m !== null && (E(m), i());
130
130
  },
131
- disabled: m,
131
+ disabled: u,
132
132
  role: "menuitem",
133
133
  children: /* @__PURE__ */ e(y, {
134
134
  paddingX: 8,
@@ -153,12 +153,12 @@ const Ee = 120, Q = /*#__PURE__*/ n.createContext({
153
153
  })
154
154
  });
155
155
  return /* @__PURE__ */ e("div", {
156
- className: ne(me, {
157
- [ue]: !m,
158
- [de]: m,
159
- [fe]: !m && u !== null && s === u
156
+ className: ne(ue, {
157
+ [me]: !u,
158
+ [de]: u,
159
+ [fe]: !u && m !== null && n === m
160
160
  }),
161
- onMouseMove: ()=>v(m ? null : u),
161
+ onMouseMove: ()=>v(u ? null : m),
162
162
  onMouseLeave: ()=>v(null),
163
163
  children: l()
164
164
  });
@@ -175,75 +175,75 @@ const Ee = 120, Q = /*#__PURE__*/ n.createContext({
175
175
  ]
176
176
  }) : /* @__PURE__ */ e(U, {});
177
177
  }, V = 12, J = 8, qe = (param)=>{
178
- let { renderTarget: r , renderMenu: d , width: f , position: m = "left" , dataAttributes: E } = param;
179
- const [o, p] = n.useState(!1), [s, v] = n.useState(null), [i, k] = n.useState(null), [c, h] = n.useState(null), [x, M] = n.useState(!1), u = n.useRef(null), [l, N] = n.useState(null), R = xe();
180
- n.useEffect(()=>{
181
- const a = s == null ? void 0 : s.getBoundingClientRect();
182
- if (!i || !a || !o) return;
183
- const { top: t , right: O , left: g , bottom: F } = a, T = i.scrollHeight, b = m === "left" ? g : void 0, A = m === "right" ? R.width - O : void 0, L = t - J, $ = F + J, H = R.height - $ - V, P = L - V, B = H > T, z = P > T, te = B || !z && H > P;
178
+ let { renderTarget: r , renderMenu: d , width: f , position: u = "left" , dataAttributes: E } = param;
179
+ const [s, p] = o.useState(!1), [n, v] = o.useState(null), [i, k] = o.useState(null), [c, h] = o.useState(null), [x, M] = o.useState(!1), m = o.useRef(null), [l, N] = o.useState(null), R = xe();
180
+ o.useEffect(()=>{
181
+ const a = n == null ? void 0 : n.getBoundingClientRect();
182
+ if (!i || !a || !s) return;
183
+ const { top: t , right: O , left: g , bottom: A } = a, T = i.scrollHeight, I = u === "left" ? g : void 0, F = u === "right" ? R.width - O : void 0, L = t - J, $ = A + J, H = R.height - $ - V, P = L - V, B = H > T, z = P > T, te = B || !z && H > P;
184
184
  N(te ? {
185
- left: b,
186
- right: A,
185
+ left: I,
186
+ right: F,
187
187
  top: `${$}px`,
188
188
  bottom: "auto",
189
189
  maxHeight: B ? void 0 : H,
190
190
  transformOrigin: "center top"
191
191
  } : {
192
- left: b,
193
- right: A,
192
+ left: I,
193
+ right: F,
194
194
  top: "auto",
195
195
  bottom: `${R.height - L}px`,
196
196
  maxHeight: z ? void 0 : P,
197
197
  transformOrigin: "center bottom"
198
198
  });
199
199
  }, [
200
- m,
201
- o,
202
- i,
200
+ u,
203
201
  s,
202
+ i,
203
+ n,
204
204
  f,
205
205
  R
206
206
  ]);
207
- const Z = n.useMemo(()=>({
207
+ const Z = o.useMemo(()=>({
208
208
  ref: v,
209
209
  onPress: ()=>{
210
- p(!o);
210
+ p(!s);
211
211
  }
212
212
  }), [
213
213
  v,
214
- o
214
+ s
215
215
  ]), ee = {
216
- ref: Ce(k, u),
216
+ ref: Ce(k, m),
217
217
  className: ge,
218
218
  close: ()=>p(!1)
219
- }, w = n.useCallback(()=>{
219
+ }, w = o.useCallback(()=>{
220
220
  const t = D(i).findIndex((O)=>!O.getAttribute("aria-disabled"));
221
221
  h(t < 0 ? null : t);
222
222
  }, [
223
223
  i
224
- ]), _ = n.useCallback((a)=>{
224
+ ]), _ = o.useCallback((a)=>{
225
225
  var T;
226
226
  const t = D(i);
227
227
  a && t.reverse();
228
228
  const O = c === null ? -1 : a ? t.length - 1 - c : c;
229
- let g = t.findIndex((b, A)=>!b.getAttribute("aria-disabled") && A > O);
230
- g === -1 && (g = t.findIndex((b)=>!b.getAttribute("aria-disabled")));
231
- const F = a && g !== -1 ? t.length - 1 - g : g;
232
- h(F < 0 ? null : F), (T = t[g]) == null || T.focus();
229
+ let g = t.findIndex((I, F)=>!I.getAttribute("aria-disabled") && F > O);
230
+ g === -1 && (g = t.findIndex((I)=>!I.getAttribute("aria-disabled")));
231
+ const A = a && g !== -1 ? t.length - 1 - g : g;
232
+ h(A < 0 ? null : A), (T = t[g]) == null || T.focus();
233
233
  }, [
234
234
  c,
235
235
  i
236
236
  ]);
237
- return n.useEffect(()=>{
238
- o ? x && i && (w(), M(!1)) : h(null);
237
+ return o.useEffect(()=>{
238
+ s ? x && i && (w(), M(!1)) : h(null);
239
239
  }, [
240
- o,
240
+ s,
241
241
  w,
242
242
  x,
243
243
  i
244
- ]), n.useEffect(()=>{
244
+ ]), o.useEffect(()=>{
245
245
  const a = (t)=>{
246
- if (o) switch(t.keyCode){
246
+ if (s) switch(t.keyCode){
247
247
  case ce:
248
248
  case K:
249
249
  S(t), _();
@@ -269,55 +269,55 @@ const Ee = 120, Q = /*#__PURE__*/ n.createContext({
269
269
  M(!0);
270
270
  break;
271
271
  case K:
272
- s === document.activeElement && (M(!0), p(!0));
272
+ n === document.activeElement && (M(!0), p(!0));
273
273
  break;
274
274
  }
275
275
  };
276
276
  return document.addEventListener("keydown", a, !1), ()=>{
277
277
  document.removeEventListener("keydown", a, !1);
278
278
  };
279
- }), n.useEffect(()=>{
280
- s == null || s.setAttribute("aria-expanded", String(o));
279
+ }), o.useEffect(()=>{
280
+ n == null || n.setAttribute("aria-haspopup", "menu"), n == null || n.setAttribute("aria-expanded", String(s));
281
281
  }, [
282
- s,
283
- o
282
+ n,
283
+ s
284
284
  ]), /* @__PURE__ */ C("div", _object_spread_props(_object_spread({}, le(E, "Menu")), {
285
285
  children: [
286
286
  r(_object_spread_props(_object_spread({}, Z), {
287
- isMenuOpen: o
287
+ isMenuOpen: s
288
288
  })),
289
- /* @__PURE__ */ e(Ie, {
289
+ /* @__PURE__ */ e(be, {
290
290
  children: /* @__PURE__ */ e(Se, {
291
- in: o,
292
- nodeRef: u,
291
+ in: s,
292
+ nodeRef: m,
293
293
  timeout: Ee,
294
294
  classNames: he,
295
295
  mountOnEnter: !0,
296
296
  unmountOnExit: !0,
297
- onExit: ()=>s == null ? void 0 : s.focus(),
297
+ onExit: ()=>n == null ? void 0 : n.focus(),
298
298
  children: /* @__PURE__ */ e(ae, {
299
299
  onPress: (a)=>{
300
300
  S(a), p(!1);
301
301
  },
302
302
  disableScroll: !0,
303
303
  children: /* @__PURE__ */ e("div", {
304
- style: _object_spread({}, be(_object_spread({}, l ? _object_spread({
305
- [I.top]: l.top,
306
- [I.bottom]: l.bottom,
307
- [I.transformOrigin]: l.transformOrigin
304
+ style: _object_spread({}, Ie(_object_spread({}, l ? _object_spread({
305
+ [b.top]: l.top,
306
+ [b.bottom]: l.bottom,
307
+ [b.transformOrigin]: l.transformOrigin
308
308
  }, l.left !== void 0 && {
309
- [I.left]: `${l.left}px`
309
+ [b.left]: `${l.left}px`
310
310
  }, l.right !== void 0 && {
311
- [I.right]: `${l.right}px`
311
+ [b.right]: `${l.right}px`
312
312
  }, l.maxHeight !== void 0 && {
313
- [I.maxHeight]: `${l.maxHeight}px`
313
+ [b.maxHeight]: `${l.maxHeight}px`
314
314
  }, f !== void 0 && {
315
- [I.width]: f ? `${f}px` : ""
315
+ [b.width]: f ? `${f}px` : ""
316
316
  }) : {}))),
317
317
  role: "menu",
318
318
  children: /* @__PURE__ */ e(Q.Provider, {
319
319
  value: {
320
- isMenuOpen: o,
320
+ isMenuOpen: s,
321
321
  focusedItem: c,
322
322
  setFocusedItem: h,
323
323
  closeMenu: ()=>p(!1)
@@ -1,2 +1,2 @@
1
- const o = "14.26.0";
1
+ const o = "14.27.0";
2
2
  export { o as PACKAGE_VERSION };