@elementor/editor-ui 4.0.0-564 → 4.0.0-573

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-ui",
3
3
  "description": "Elementor Editor UI",
4
- "version": "4.0.0-564",
4
+ "version": "4.0.0-573",
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": "4.0.0-564",
40
+ "@elementor/editor-v1-adapters": "4.0.0-573",
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,66 @@
1
+ import * as React from 'react';
2
+ import { type ReactNode, useState } from 'react';
3
+ import { Button, Collapse, Stack, styled } from '@elementor/ui';
4
+ import { __ } from '@wordpress/i18n';
5
+
6
+ import { CollapseIcon } from './collapse-icon';
7
+
8
+ type StaticItem< T = unknown > = T extends ( ...args: unknown[] ) => unknown ? never : T;
9
+
10
+ type CallbackItem< T > = ( isOpen: boolean ) => T;
11
+ export type CollapsibleValue< T > = CallbackItem< T > | StaticItem< T >;
12
+
13
+ type CollapsibleContentProps = React.PropsWithChildren< {
14
+ defaultOpen?: boolean;
15
+ titleEnd?: CollapsibleValue< ReactNode | string > | null;
16
+ } >;
17
+
18
+ const IndicatorsWrapper = styled( 'div' )`
19
+ position: absolute;
20
+ top: 0;
21
+ right: ${ ( { theme } ) => theme.spacing( 3 ) };
22
+ height: 100%;
23
+ display: flex;
24
+ flex-direction: column;
25
+ align-items: center;
26
+ justify-content: center;
27
+ `;
28
+
29
+ export const CollapsibleContent = ( { children, defaultOpen = false, titleEnd = null }: CollapsibleContentProps ) => {
30
+ const [ open, setOpen ] = useState( defaultOpen );
31
+
32
+ const handleToggle = () => {
33
+ setOpen( ( prevOpen ) => ! prevOpen );
34
+ };
35
+
36
+ return (
37
+ <Stack>
38
+ <Stack sx={ { position: 'relative' } }>
39
+ <Button
40
+ fullWidth
41
+ size="small"
42
+ color="secondary"
43
+ variant="outlined"
44
+ onClick={ handleToggle }
45
+ endIcon={ <CollapseIcon open={ open } /> }
46
+ sx={ { my: 0.5 } }
47
+ aria-label={ open ? 'Show less' : 'Show more' }
48
+ >
49
+ { open ? __( 'Show less', 'elementor' ) : __( 'Show more', 'elementor' ) }
50
+ </Button>
51
+ { titleEnd && <IndicatorsWrapper>{ getCollapsibleValue( titleEnd, open ) }</IndicatorsWrapper> }
52
+ </Stack>
53
+ <Collapse in={ open } timeout="auto" unmountOnExit>
54
+ { children }
55
+ </Collapse>
56
+ </Stack>
57
+ );
58
+ };
59
+
60
+ export function getCollapsibleValue< T >( value: CollapsibleValue< T >, isOpen: boolean ): T {
61
+ if ( typeof value === 'function' ) {
62
+ return ( value as CallbackItem< T > )( isOpen );
63
+ }
64
+
65
+ return value;
66
+ }
@@ -1,7 +1,9 @@
1
1
  import * as React from 'react';
2
+ import { useState } from 'react';
2
3
  import { AlertOctagonFilledIcon } from '@elementor/icons';
3
4
  import {
4
5
  Button,
6
+ Checkbox,
5
7
  Dialog,
6
8
  DialogActions,
7
9
  DialogContent,
@@ -9,6 +11,8 @@ import {
9
11
  type DialogContentTextProps,
10
12
  type DialogProps,
11
13
  DialogTitle,
14
+ FormControlLabel,
15
+ Typography,
12
16
  } from '@elementor/ui';
13
17
  import { __ } from '@wordpress/i18n';
14
18
 
@@ -22,9 +26,18 @@ export const ConfirmationDialog = ( { open, onClose, children }: ConfirmationDia
22
26
  </Dialog>
23
27
  );
24
28
 
25
- const ConfirmationDialogTitle = ( { children }: React.PropsWithChildren ) => (
29
+ type ConfirmationDialogTitleProps = React.PropsWithChildren< {
30
+ icon?: React.ElementType;
31
+ iconColor?: 'error' | 'secondary';
32
+ } >;
33
+
34
+ const ConfirmationDialogTitle = ( {
35
+ children,
36
+ icon: Icon = AlertOctagonFilledIcon,
37
+ iconColor = 'error',
38
+ }: ConfirmationDialogTitleProps ) => (
26
39
  <DialogTitle id={ TITLE_ID } display="flex" alignItems="center" gap={ 1 } sx={ { lineHeight: 1 } }>
27
- <AlertOctagonFilledIcon color="error" />
40
+ <Icon color={ iconColor } />
28
41
  { children }
29
42
  </DialogTitle>
30
43
  );
@@ -42,6 +55,9 @@ type ConfirmationDialogActionsProps = {
42
55
  onConfirm: () => void;
43
56
  cancelLabel?: string;
44
57
  confirmLabel?: string;
58
+ color?: 'error' | 'secondary';
59
+ onSuppressMessage?: () => void;
60
+ suppressLabel?: string;
45
61
  };
46
62
 
47
63
  const ConfirmationDialogActions = ( {
@@ -49,17 +65,47 @@ const ConfirmationDialogActions = ( {
49
65
  onConfirm,
50
66
  cancelLabel,
51
67
  confirmLabel,
52
- }: ConfirmationDialogActionsProps ) => (
53
- <DialogActions>
54
- <Button color="secondary" onClick={ onClose }>
55
- { cancelLabel ?? __( 'Not now', 'elementor' ) }
56
- </Button>
57
- { /* eslint-disable-next-line jsx-a11y/no-autofocus */ }
58
- <Button autoFocus variant="contained" color="error" onClick={ onConfirm }>
59
- { confirmLabel ?? __( 'Delete', 'elementor' ) }
60
- </Button>
61
- </DialogActions>
62
- );
68
+ color = 'error',
69
+ onSuppressMessage,
70
+ suppressLabel = __( "Don't show this again", 'elementor' ),
71
+ }: ConfirmationDialogActionsProps ) => {
72
+ const [ dontShowAgain, setDontShowAgain ] = useState( false );
73
+
74
+ const handleConfirm = () => {
75
+ if ( dontShowAgain && onSuppressMessage ) {
76
+ onSuppressMessage();
77
+ }
78
+ onConfirm();
79
+ };
80
+
81
+ return (
82
+ <DialogActions sx={ onSuppressMessage ? { justifyContent: 'space-between', alignItems: 'center' } : undefined }>
83
+ { onSuppressMessage && (
84
+ <FormControlLabel
85
+ control={
86
+ <Checkbox
87
+ checked={ dontShowAgain }
88
+ onChange={ ( event: React.ChangeEvent< HTMLInputElement > ) =>
89
+ setDontShowAgain( event.target.checked )
90
+ }
91
+ size="small"
92
+ />
93
+ }
94
+ label={ <Typography variant="body2">{ suppressLabel }</Typography> }
95
+ />
96
+ ) }
97
+ <div>
98
+ <Button color="secondary" onClick={ onClose }>
99
+ { cancelLabel ?? __( 'Not now', 'elementor' ) }
100
+ </Button>
101
+ { /* eslint-disable-next-line jsx-a11y/no-autofocus */ }
102
+ <Button autoFocus variant="contained" color={ color } onClick={ handleConfirm } sx={ { ml: 1 } }>
103
+ { confirmLabel ?? __( 'Delete', 'elementor' ) }
104
+ </Button>
105
+ </div>
106
+ </DialogActions>
107
+ );
108
+ };
63
109
 
64
110
  ConfirmationDialog.Title = ConfirmationDialogTitle;
65
111
  ConfirmationDialog.Content = ConfirmationDialogContent;
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { type MouseEvent } from 'react';
2
+ import { type MouseEvent, type RefObject } from 'react';
3
3
  import { CrownFilledIcon } from '@elementor/icons';
4
4
  import {
5
5
  Alert,
@@ -25,6 +25,7 @@ type PromotionPopoverProps = React.PropsWithChildren<
25
25
  open: boolean;
26
26
  placement?: InfotipProps[ 'placement' ];
27
27
  slotProps?: InfotipProps[ 'slotProps' ];
28
+ anchorRef?: RefObject< HTMLElement | null >;
28
29
  }
29
30
  >;
30
31
 
@@ -33,15 +34,19 @@ export const PromotionPopover = ( {
33
34
  open,
34
35
  placement = 'right',
35
36
  slotProps,
37
+ anchorRef,
36
38
  ...cardProps
37
39
  }: PromotionPopoverProps ) => {
40
+ const anchorEl = anchorRef?.current;
41
+
38
42
  const defaultSlotProps: InfotipProps[ 'slotProps' ] = {
39
43
  popper: {
44
+ ...( anchorEl && { anchorEl } ),
40
45
  modifiers: [
41
46
  {
42
47
  name: 'offset',
43
48
  options: {
44
- offset: [ 0, 10 ],
49
+ offset: anchorRef ? [ 0, 4 ] : [ 0, 10 ],
45
50
  },
46
51
  },
47
52
  ],
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  // components
2
2
  export { CollapseIcon } from './components/collapse-icon';
3
+ export { CollapsibleContent, getCollapsibleValue, type CollapsibleValue } from './components/collapsible-content';
3
4
  export { EllipsisWithTooltip } from './components/ellipsis-with-tooltip';
4
5
  export { EditableField } from './components/editable-field';
5
6
  export { IntroductionModal } from './components/introduction-modal';