ywana-core8 0.2.19 → 0.2.21

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/src/html/menu.js CHANGED
@@ -28,34 +28,54 @@ export const Menu = (props) => {
28
28
 
29
29
  /**
30
30
  * Menu Icon
31
+ * @param {string} icon - Icon name (default: "more_vert")
32
+ * @param {string} position - Menu position relative to icon:
33
+ * "bottom-left" (default), "bottom-right", "top-left", "top-right",
34
+ * "left", "right", "top", "bottom"
35
+ * @param {string} align - Deprecated, use position instead
36
+ * @param {string} size - Icon size
37
+ * @param {string} menuSize - Menu size: "normal" (default), "compact"
31
38
  */
32
39
  export const MenuIcon = (props) => {
33
40
 
34
- const { icon = "more_vert", children, align = "left", size="normal" } = props
41
+ const {
42
+ icon = "more_vert",
43
+ children,
44
+ align, // Deprecated, kept for backwards compatibility
45
+ position = align === "right" ? "bottom-right" : "bottom-left",
46
+ size = "normal",
47
+ menuSize = "normal"
48
+ } = props
35
49
  const [open, setOpen] = useState(false)
36
50
 
37
51
  function toggle() {
38
52
  setOpen(!open)
39
53
  }
40
54
 
41
- // Convertir valores de align a clases CSS
42
- const getAlignClass = (alignment) => {
43
- switch (alignment) {
44
- case 'right':
45
- return 'alignRight'
46
- case 'left':
47
- return 'alignLeft'
48
- default:
49
- return 'alignLeft' // Por defecto a la izquierda
50
- }
55
+ // Convertir position a clase CSS
56
+ const getPositionClass = (pos) => {
57
+ const validPositions = [
58
+ 'bottom-left', 'bottom-right',
59
+ 'top-left', 'top-right',
60
+ 'left', 'right',
61
+ 'top', 'bottom'
62
+ ]
63
+
64
+ return validPositions.includes(pos) ? `position-${pos}` : 'position-bottom-left'
51
65
  }
52
66
 
67
+ // Construir clases del menú
68
+ const menuClasses = [
69
+ getPositionClass(position),
70
+ menuSize === "compact" ? "menu-compact" : ""
71
+ ].filter(Boolean).join(' ')
72
+
53
73
  return (
54
- <MenuContext.Provider value={[open, setOpen]}>
74
+ <MenuContext.Provider value={[open, setOpen, menuSize]}>
55
75
  <div className="menu-icon">
56
76
  <Icon icon={icon} size={size} clickable action={toggle} />
57
77
  {open ? (
58
- <menu className={getAlignClass(align)}>
78
+ <menu className={menuClasses}>
59
79
  {children}
60
80
  </menu>
61
81
  ) : null}
@@ -70,8 +90,12 @@ export const MenuIcon = (props) => {
70
90
  */
71
91
  export const MenuItem = (props) => {
72
92
 
73
- const { id, icon, label, meta, disabled=false, size="normal", onSelect } = props
74
- const [open, setOpen] = useContext(MenuContext)
93
+ const { id, icon, label, meta, disabled=false, size, onSelect } = props
94
+ const context = useContext(MenuContext)
95
+ const [open, setOpen, menuSize] = Array.isArray(context) ? context : [context, null, "normal"]
96
+
97
+ // Use menuSize from context if size prop is not provided
98
+ const iconSize = size || (menuSize === "compact" ? "small" : "normal")
75
99
 
76
100
  function select() {
77
101
  if (!disabled) {
@@ -85,7 +109,7 @@ export const MenuItem = (props) => {
85
109
 
86
110
  return (
87
111
  <li className={`menu-item ${style}`} onClick={select}>
88
- {icon ? <Icon icon={icon} size={size} /> : null}
112
+ {icon ? <Icon icon={icon} size={iconSize} /> : null}
89
113
  <label>{labelTxt}</label>
90
114
  {meta ? <div className="meta">{meta}</div> : null}
91
115
  </li>