@elementor/editor-ui 3.35.0-486 → 3.35.0-488

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/index.d.mts CHANGED
@@ -159,10 +159,11 @@ type PopoverMenuListProps<T, V extends string> = {
159
159
  onChange?: (visibleItems: VirtualizedItem<T, V>[]) => void;
160
160
  menuListTemplate?: React$1.ComponentType<React$1.ComponentProps<typeof MenuList>>;
161
161
  menuItemContentTemplate?: (item: VirtualizedItem<T, V>) => React$1.ReactNode;
162
+ categoryItemContentTemplate?: (item: VirtualizedItem<T, V>) => React$1.ReactNode;
162
163
  noResultsComponent?: React$1.ReactNode;
163
164
  };
164
165
  declare const ITEM_HEIGHT = 32;
165
- declare const PopoverMenuList: <T, V extends string>({ items, onSelect, onClose, selectedValue, itemStyle, onChange, "data-testid": dataTestId, menuItemContentTemplate, noResultsComponent, menuListTemplate: CustomMenuList, }: PopoverMenuListProps<T, V>) => React$1.JSX.Element;
166
+ declare const PopoverMenuList: <T, V extends string>({ items, onSelect, onClose, selectedValue, itemStyle, onChange, "data-testid": dataTestId, menuItemContentTemplate, categoryItemContentTemplate, noResultsComponent, menuListTemplate: CustomMenuList, }: PopoverMenuListProps<T, V>) => React$1.JSX.Element;
166
167
  declare const StyledMenuList: _emotion_styled.StyledComponent<any, {}, {
167
168
  ref?: React$1.Ref<any> | undefined;
168
169
  }>;
package/dist/index.d.ts CHANGED
@@ -159,10 +159,11 @@ type PopoverMenuListProps<T, V extends string> = {
159
159
  onChange?: (visibleItems: VirtualizedItem<T, V>[]) => void;
160
160
  menuListTemplate?: React$1.ComponentType<React$1.ComponentProps<typeof MenuList>>;
161
161
  menuItemContentTemplate?: (item: VirtualizedItem<T, V>) => React$1.ReactNode;
162
+ categoryItemContentTemplate?: (item: VirtualizedItem<T, V>) => React$1.ReactNode;
162
163
  noResultsComponent?: React$1.ReactNode;
163
164
  };
164
165
  declare const ITEM_HEIGHT = 32;
165
- declare const PopoverMenuList: <T, V extends string>({ items, onSelect, onClose, selectedValue, itemStyle, onChange, "data-testid": dataTestId, menuItemContentTemplate, noResultsComponent, menuListTemplate: CustomMenuList, }: PopoverMenuListProps<T, V>) => React$1.JSX.Element;
166
+ declare const PopoverMenuList: <T, V extends string>({ items, onSelect, onClose, selectedValue, itemStyle, onChange, "data-testid": dataTestId, menuItemContentTemplate, categoryItemContentTemplate, noResultsComponent, menuListTemplate: CustomMenuList, }: PopoverMenuListProps<T, V>) => React$1.JSX.Element;
166
167
  declare const StyledMenuList: _emotion_styled.StyledComponent<any, {}, {
167
168
  ref?: React$1.Ref<any> | undefined;
168
169
  }>;
package/dist/index.js CHANGED
@@ -679,6 +679,7 @@ var PopoverMenuList = ({
679
679
  onChange,
680
680
  "data-testid": dataTestId,
681
681
  menuItemContentTemplate,
682
+ categoryItemContentTemplate,
682
683
  noResultsComponent,
683
684
  menuListTemplate: CustomMenuList
684
685
  }) => {
@@ -750,7 +751,7 @@ var PopoverMenuList = ({
750
751
  style: shouldStick ? {} : menuSubHeaderAbsoluteStyling(virtualRow.start),
751
752
  sx: { fontWeight: "400", color: "text.tertiary" }
752
753
  },
753
- item.label || item.value
754
+ categoryItemContentTemplate ? categoryItemContentTemplate(item) : item.label || item.value
754
755
  );
755
756
  }
756
757
  const isDisabled = item.disabled;
package/dist/index.mjs CHANGED
@@ -652,6 +652,7 @@ var PopoverMenuList = ({
652
652
  onChange,
653
653
  "data-testid": dataTestId,
654
654
  menuItemContentTemplate,
655
+ categoryItemContentTemplate,
655
656
  noResultsComponent,
656
657
  menuListTemplate: CustomMenuList
657
658
  }) => {
@@ -723,7 +724,7 @@ var PopoverMenuList = ({
723
724
  style: shouldStick ? {} : menuSubHeaderAbsoluteStyling(virtualRow.start),
724
725
  sx: { fontWeight: "400", color: "text.tertiary" }
725
726
  },
726
- item.label || item.value
727
+ categoryItemContentTemplate ? categoryItemContentTemplate(item) : item.label || item.value
727
728
  );
728
729
  }
729
730
  const isDisabled = item.disabled;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-ui",
3
3
  "description": "Elementor Editor UI",
4
- "version": "3.35.0-486",
4
+ "version": "3.35.0-488",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -37,7 +37,7 @@
37
37
  "react-dom": "^18.3.1"
38
38
  },
39
39
  "dependencies": {
40
- "@elementor/editor-v1-adapters": "3.35.0-486",
40
+ "@elementor/editor-v1-adapters": "3.35.0-488",
41
41
  "@elementor/icons": "^1.63.0",
42
42
  "@elementor/ui": "1.36.17",
43
43
  "@tanstack/react-virtual": "^3.13.3",
@@ -0,0 +1,76 @@
1
+ import * as React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+
4
+ import { PopoverMenuList, type VirtualizedItem } from '../menu-list';
5
+
6
+ const mockItems: VirtualizedItem< 'category' | 'item', string >[] = [
7
+ { type: 'category', value: 'Category 1', label: 'Category 1' },
8
+ { type: 'item', value: 'item-1', label: 'Item 1' },
9
+ { type: 'category', value: 'Category 2', label: 'Category 2' },
10
+ { type: 'item', value: 'item-2', label: 'Item 2' },
11
+ ];
12
+
13
+ jest.mock( '@tanstack/react-virtual', () => ( {
14
+ useVirtualizer: jest.fn().mockImplementation( () => ( {
15
+ getVirtualItems: jest
16
+ .fn()
17
+ .mockReturnValue( mockItems.map( ( item, index ) => ( { key: item.value, index, start: index * 32 } ) ) ),
18
+ getTotalSize: jest.fn().mockReturnValue( mockItems.length ),
19
+ scrollToIndex: jest.fn(),
20
+ getVirtualIndexes: jest.fn().mockReturnValue( mockItems.map( ( _, index ) => index ) ),
21
+ } ) ),
22
+ } ) );
23
+
24
+ describe( 'PopoverMenuList - menuCategoryContentTemplate', () => {
25
+ const onSelect = jest.fn();
26
+ const onClose = jest.fn();
27
+
28
+ it.each( [
29
+ {
30
+ scenario: 'default rendering',
31
+ categoryTemplate: undefined,
32
+ itemTemplate: undefined,
33
+ expectCategories: [ 'Category 1', 'Category 2' ],
34
+ expectItems: [ 'Item 1', 'Item 2' ],
35
+ },
36
+ {
37
+ scenario: 'custom category template',
38
+ categoryTemplate: ( item: VirtualizedItem< 'category' | 'item', string > ) => (
39
+ <div data-testid={ `custom-${ item.value }` }>Custom: { item.label }</div>
40
+ ),
41
+ itemTemplate: undefined,
42
+ expectCategories: [ 'Custom: Category 1', 'Custom: Category 2' ],
43
+ expectItems: [ 'Item 1', 'Item 2' ],
44
+ },
45
+ {
46
+ scenario: 'both templates',
47
+ categoryTemplate: ( item: VirtualizedItem< 'category' | 'item', string > ) => (
48
+ <div>Category: { item.label }</div>
49
+ ),
50
+ itemTemplate: ( item: VirtualizedItem< 'category' | 'item', string > ) => <div>Item: { item.label }</div>,
51
+ expectCategories: [ 'Category: Category 1', 'Category: Category 2' ],
52
+ expectItems: [ 'Item: Item 1', 'Item: Item 2' ],
53
+ },
54
+ ] )(
55
+ 'should render correctly with $scenario',
56
+ ( { categoryTemplate, itemTemplate, expectCategories, expectItems } ) => {
57
+ render(
58
+ <PopoverMenuList
59
+ items={ mockItems }
60
+ onSelect={ onSelect }
61
+ onClose={ onClose }
62
+ categoryItemContentTemplate={ categoryTemplate }
63
+ menuItemContentTemplate={ itemTemplate }
64
+ />
65
+ );
66
+
67
+ expectCategories.forEach( ( text ) => {
68
+ expect( screen.getByText( text ) ).toBeInTheDocument();
69
+ } );
70
+
71
+ expectItems.forEach( ( text ) => {
72
+ expect( screen.getByText( text ) ).toBeInTheDocument();
73
+ } );
74
+ }
75
+ );
76
+ } );
@@ -25,6 +25,7 @@ export type PopoverMenuListProps< T, V extends string > = {
25
25
  onChange?: ( visibleItems: VirtualizedItem< T, V >[] ) => void;
26
26
  menuListTemplate?: React.ComponentType< React.ComponentProps< typeof MenuList > >;
27
27
  menuItemContentTemplate?: ( item: VirtualizedItem< T, V > ) => React.ReactNode;
28
+ categoryItemContentTemplate?: ( item: VirtualizedItem< T, V > ) => React.ReactNode;
28
29
  noResultsComponent?: React.ReactNode;
29
30
  };
30
31
 
@@ -59,6 +60,7 @@ export const PopoverMenuList = < T, V extends string >( {
59
60
  onChange,
60
61
  'data-testid': dataTestId,
61
62
  menuItemContentTemplate,
63
+ categoryItemContentTemplate,
62
64
  noResultsComponent,
63
65
  menuListTemplate: CustomMenuList,
64
66
  }: PopoverMenuListProps< T, V > ) => {
@@ -150,7 +152,9 @@ export const PopoverMenuList = < T, V extends string >( {
150
152
  style={ shouldStick ? {} : menuSubHeaderAbsoluteStyling( virtualRow.start ) }
151
153
  sx={ { fontWeight: '400', color: 'text.tertiary' } }
152
154
  >
153
- { item.label || item.value }
155
+ { categoryItemContentTemplate
156
+ ? categoryItemContentTemplate( item )
157
+ : item.label || item.value }
154
158
  </MenuSubheader>
155
159
  );
156
160
  }