@elementor/editor-variables 0.16.0 → 3.32.0-20

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.
Files changed (67) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/index.d.mts +19 -1
  3. package/dist/index.d.ts +19 -1
  4. package/dist/index.js +1397 -885
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +1399 -871
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +16 -14
  9. package/src/api.ts +18 -2
  10. package/src/components/fields/color-field.tsx +3 -3
  11. package/src/components/fields/font-field.tsx +21 -10
  12. package/src/components/fields/label-field.tsx +31 -5
  13. package/src/components/ui/delete-confirmation-dialog.tsx +4 -7
  14. package/src/components/ui/deleted-variable-alert.tsx +47 -0
  15. package/src/components/ui/edit-confirmation-dialog.tsx +75 -0
  16. package/src/components/ui/missing-variable-alert.tsx +39 -0
  17. package/src/components/ui/no-variables.tsx +59 -26
  18. package/src/components/ui/tags/assigned-tag.tsx +21 -19
  19. package/src/components/ui/tags/deleted-tag.tsx +29 -18
  20. package/src/components/ui/tags/missing-tag.tsx +25 -0
  21. package/src/components/ui/variable/assigned-variable.tsx +11 -14
  22. package/src/components/ui/variable/deleted-variable.tsx +115 -7
  23. package/src/components/ui/variable/missing-variable.tsx +44 -0
  24. package/src/components/variable-creation.tsx +135 -0
  25. package/src/components/variable-edit.tsx +221 -0
  26. package/src/components/variable-restore.tsx +117 -0
  27. package/src/components/variable-selection-popover.tsx +91 -92
  28. package/src/components/variables-manager/variables-manager-panel.tsx +115 -0
  29. package/src/components/variables-selection.tsx +148 -0
  30. package/src/context/variable-selection-popover.context.tsx +19 -0
  31. package/src/context/variable-type-context.tsx +23 -0
  32. package/src/controls/variable-control.tsx +26 -0
  33. package/src/create-style-variables-repository.ts +44 -5
  34. package/src/hooks/use-initial-value.ts +22 -0
  35. package/src/hooks/use-permissions.ts +15 -0
  36. package/src/hooks/use-prop-variable-action.tsx +53 -0
  37. package/src/hooks/use-prop-variables.ts +6 -0
  38. package/src/index.ts +1 -0
  39. package/src/init.ts +33 -4
  40. package/src/register-variable-types.tsx +29 -0
  41. package/src/renderers/style-variables-renderer.tsx +10 -4
  42. package/src/repeater-injections.ts +5 -1
  43. package/src/service.ts +8 -4
  44. package/src/sync/enqueue-font.ts +7 -0
  45. package/src/sync/types.ts +5 -0
  46. package/src/transformers/inheritance-transformer.tsx +30 -0
  47. package/src/transformers/utils/resolve-css-variable.ts +24 -0
  48. package/src/transformers/variable-transformer.ts +8 -3
  49. package/src/types.ts +1 -1
  50. package/src/utils/tracking.ts +39 -0
  51. package/src/utils/validations.ts +40 -6
  52. package/src/variables-registry/create-variable-type-registry.ts +77 -0
  53. package/src/variables-registry/variable-type-registry.ts +3 -0
  54. package/src/components/color-variable-creation.tsx +0 -86
  55. package/src/components/color-variable-edit.tsx +0 -138
  56. package/src/components/color-variables-selection.tsx +0 -130
  57. package/src/components/font-variable-creation.tsx +0 -86
  58. package/src/components/font-variable-edit.tsx +0 -138
  59. package/src/components/font-variables-selection.tsx +0 -129
  60. package/src/components/variable-selection-popover.context.ts +0 -7
  61. package/src/controls/color-variable-control.tsx +0 -33
  62. package/src/controls/font-variable-control.tsx +0 -31
  63. package/src/hooks/use-prop-color-variable-action.tsx +0 -25
  64. package/src/hooks/use-prop-font-variable-action.tsx +0 -25
  65. package/src/init-color-variables.ts +0 -27
  66. package/src/init-font-variables.ts +0 -24
  67. package/src/utils.ts +0 -20
@@ -1,86 +0,0 @@
1
- import * as React from 'react';
2
- import { useState } from 'react';
3
- import { PopoverContent, useBoundProp } from '@elementor/editor-controls';
4
- import { PopoverScrollableContent } from '@elementor/editor-editing-panel';
5
- import { PopoverHeader } from '@elementor/editor-ui';
6
- import { ArrowLeftIcon, BrushIcon } from '@elementor/icons';
7
- import { Button, CardActions, Divider, IconButton } from '@elementor/ui';
8
- import { __ } from '@wordpress/i18n';
9
-
10
- import { createVariable } from '../hooks/use-prop-variables';
11
- import { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';
12
- import { ColorField } from './fields/color-field';
13
- import { LabelField } from './fields/label-field';
14
-
15
- const SIZE = 'tiny';
16
-
17
- type Props = {
18
- onGoBack?: () => void;
19
- onClose: () => void;
20
- };
21
-
22
- export const ColorVariableCreation = ( { onGoBack, onClose }: Props ) => {
23
- const { setValue: setVariable } = useBoundProp( colorVariablePropTypeUtil );
24
-
25
- const [ color, setColor ] = useState( '' );
26
- const [ label, setLabel ] = useState( '' );
27
-
28
- const resetFields = () => {
29
- setColor( '' );
30
- setLabel( '' );
31
- };
32
-
33
- const closePopover = () => {
34
- resetFields();
35
- onClose();
36
- };
37
-
38
- const handleCreate = () => {
39
- createVariable( {
40
- value: color,
41
- label,
42
- type: colorVariablePropTypeUtil.key,
43
- } ).then( ( key ) => {
44
- setVariable( key );
45
- closePopover();
46
- } );
47
- };
48
-
49
- const hasEmptyValue = () => {
50
- return '' === color.trim() || '' === label.trim();
51
- };
52
-
53
- const isSubmitDisabled = hasEmptyValue();
54
-
55
- return (
56
- <PopoverScrollableContent height="auto">
57
- <PopoverHeader
58
- icon={
59
- <>
60
- { onGoBack && (
61
- <IconButton size={ SIZE } aria-label={ __( 'Go Back', 'elementor' ) } onClick={ onGoBack }>
62
- <ArrowLeftIcon fontSize={ SIZE } />
63
- </IconButton>
64
- ) }
65
- <BrushIcon fontSize={ SIZE } />
66
- </>
67
- }
68
- title={ __( 'Create variable', 'elementor' ) }
69
- onClose={ closePopover }
70
- />
71
-
72
- <Divider />
73
-
74
- <PopoverContent p={ 2 }>
75
- <LabelField value={ label } onChange={ setLabel } />
76
- <ColorField value={ color } onChange={ setColor } />
77
- </PopoverContent>
78
-
79
- <CardActions sx={ { pt: 0.5, pb: 1 } }>
80
- <Button size="small" variant="contained" disabled={ isSubmitDisabled } onClick={ handleCreate }>
81
- { __( 'Create', 'elementor' ) }
82
- </Button>
83
- </CardActions>
84
- </PopoverScrollableContent>
85
- );
86
- };
@@ -1,138 +0,0 @@
1
- import * as React from 'react';
2
- import { useState } from 'react';
3
- import { PopoverContent, useBoundProp } from '@elementor/editor-controls';
4
- import { PopoverScrollableContent } from '@elementor/editor-editing-panel';
5
- import { PopoverHeader } from '@elementor/editor-ui';
6
- import { ArrowLeftIcon, BrushIcon, TrashIcon } from '@elementor/icons';
7
- import { Button, CardActions, Divider, IconButton } from '@elementor/ui';
8
- import { __ } from '@wordpress/i18n';
9
-
10
- import { deleteVariable, updateVariable, useVariable } from '../hooks/use-prop-variables';
11
- import { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';
12
- import { ColorField } from './fields/color-field';
13
- import { LabelField } from './fields/label-field';
14
- import { DeleteConfirmationDialog } from './ui/delete-confirmation-dialog';
15
-
16
- const SIZE = 'tiny';
17
-
18
- type Props = {
19
- editId: string;
20
- onClose: () => void;
21
- onGoBack?: () => void;
22
- onSubmit?: () => void;
23
- };
24
-
25
- export const ColorVariableEdit = ( { onClose, onGoBack, onSubmit, editId }: Props ) => {
26
- const { setValue: notifyBoundPropChange, value: assignedValue } = useBoundProp( colorVariablePropTypeUtil );
27
- const [ deleteConfirmation, setDeleteConfirmation ] = useState( false );
28
-
29
- const variable = useVariable( editId );
30
- if ( ! variable ) {
31
- throw new Error( `Global color variable not found` );
32
- }
33
-
34
- const [ color, setColor ] = useState( variable.value );
35
- const [ label, setLabel ] = useState( variable.label );
36
-
37
- const handleUpdate = () => {
38
- updateVariable( editId, {
39
- value: color,
40
- label,
41
- } ).then( () => {
42
- maybeTriggerBoundPropChange();
43
- onSubmit?.();
44
- } );
45
- };
46
-
47
- const handleDelete = () => {
48
- deleteVariable( editId ).then( () => {
49
- maybeTriggerBoundPropChange();
50
- onSubmit?.();
51
- } );
52
- };
53
-
54
- const maybeTriggerBoundPropChange = () => {
55
- if ( editId === assignedValue ) {
56
- notifyBoundPropChange( editId );
57
- }
58
- };
59
-
60
- const handleDeleteConfirmation = () => {
61
- setDeleteConfirmation( true );
62
- };
63
-
64
- const closeDeleteDialog = () => () => {
65
- setDeleteConfirmation( false );
66
- };
67
-
68
- const actions = [];
69
-
70
- actions.push(
71
- <IconButton
72
- key="delete"
73
- size={ SIZE }
74
- aria-label={ __( 'Delete', 'elementor' ) }
75
- onClick={ handleDeleteConfirmation }
76
- >
77
- <TrashIcon fontSize={ SIZE } />
78
- </IconButton>
79
- );
80
-
81
- const hasEmptyValues = () => {
82
- return ! color.trim() || ! label.trim();
83
- };
84
-
85
- const noValueChanged = () => {
86
- return color === variable.value && label === variable.label;
87
- };
88
-
89
- const isSubmitDisabled = noValueChanged() || hasEmptyValues();
90
-
91
- return (
92
- <>
93
- <PopoverScrollableContent height="auto">
94
- <PopoverHeader
95
- title={ __( 'Edit variable', 'elementor' ) }
96
- onClose={ onClose }
97
- icon={
98
- <>
99
- { onGoBack && (
100
- <IconButton
101
- size={ SIZE }
102
- aria-label={ __( 'Go Back', 'elementor' ) }
103
- onClick={ onGoBack }
104
- >
105
- <ArrowLeftIcon fontSize={ SIZE } />
106
- </IconButton>
107
- ) }
108
- <BrushIcon fontSize={ SIZE } />
109
- </>
110
- }
111
- actions={ actions }
112
- />
113
-
114
- <Divider />
115
-
116
- <PopoverContent p={ 2 }>
117
- <LabelField value={ label } onChange={ setLabel } />
118
- <ColorField value={ color } onChange={ setColor } />
119
- </PopoverContent>
120
-
121
- <CardActions sx={ { pt: 0.5, pb: 1 } }>
122
- <Button size="small" variant="contained" disabled={ isSubmitDisabled } onClick={ handleUpdate }>
123
- { __( 'Save', 'elementor' ) }
124
- </Button>
125
- </CardActions>
126
- </PopoverScrollableContent>
127
-
128
- { deleteConfirmation && (
129
- <DeleteConfirmationDialog
130
- open
131
- label={ label }
132
- onConfirm={ handleDelete }
133
- closeDialog={ closeDeleteDialog() }
134
- />
135
- ) }
136
- </>
137
- );
138
- };
@@ -1,130 +0,0 @@
1
- import * as React from 'react';
2
- import { useState } from 'react';
3
- import { useBoundProp } from '@elementor/editor-controls';
4
- import { PopoverScrollableContent } from '@elementor/editor-editing-panel';
5
- import { PopoverHeader, PopoverMenuList, PopoverSearch, type VirtualizedItem } from '@elementor/editor-ui';
6
- import { BrushIcon, ColorFilterIcon, PlusIcon, SettingsIcon } from '@elementor/icons';
7
- import { Divider, IconButton } from '@elementor/ui';
8
- import { __ } from '@wordpress/i18n';
9
-
10
- import { useFilteredVariables } from '../hooks/use-prop-variables';
11
- import { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';
12
- import { type ExtendedVirtualizedItem } from '../types';
13
- import { ColorIndicator } from './ui/color-indicator';
14
- import { MenuItemContent } from './ui/menu-item-content';
15
- import { NoSearchResults } from './ui/no-search-results';
16
- import { NoVariables } from './ui/no-variables';
17
- import { VariablesStyledMenuList } from './ui/styled-menu-list';
18
-
19
- const SIZE = 'tiny';
20
-
21
- type Props = {
22
- closePopover: () => void;
23
- onAdd?: () => void;
24
- onEdit?: ( key: string ) => void;
25
- onSettings?: () => void;
26
- };
27
-
28
- export const ColorVariablesSelection = ( { closePopover, onAdd, onEdit, onSettings }: Props ) => {
29
- const { value: variable, setValue: setVariable } = useBoundProp( colorVariablePropTypeUtil );
30
- const [ searchValue, setSearchValue ] = useState( '' );
31
-
32
- const {
33
- list: variables,
34
- hasMatches: hasSearchResults,
35
- isSourceNotEmpty: hasVariables,
36
- } = useFilteredVariables( searchValue, colorVariablePropTypeUtil.key );
37
-
38
- const handleSetColorVariable = ( key: string ) => {
39
- setVariable( key );
40
- closePopover();
41
- };
42
-
43
- const actions = [];
44
-
45
- if ( onAdd ) {
46
- actions.push(
47
- <IconButton key="add" size={ SIZE } onClick={ onAdd }>
48
- <PlusIcon fontSize={ SIZE } />
49
- </IconButton>
50
- );
51
- }
52
-
53
- if ( onSettings ) {
54
- actions.push(
55
- <IconButton key="settings" size={ SIZE } onClick={ onSettings }>
56
- <SettingsIcon fontSize={ SIZE } />
57
- </IconButton>
58
- );
59
- }
60
-
61
- const items: ExtendedVirtualizedItem[] = variables.map( ( { value, label, key } ) => ( {
62
- type: 'item' as const,
63
- value: key,
64
- label,
65
- icon: <ColorIndicator size="inherit" component="span" value={ value } />,
66
- secondaryText: value,
67
- onEdit: () => onEdit?.( key ),
68
- } ) );
69
-
70
- const handleSearch = ( search: string ) => {
71
- setSearchValue( search );
72
- };
73
-
74
- const handleClearSearch = () => {
75
- setSearchValue( '' );
76
- };
77
-
78
- return (
79
- <>
80
- <PopoverHeader
81
- title={ __( 'Variables', 'elementor' ) }
82
- icon={ <ColorFilterIcon fontSize={ SIZE } /> }
83
- onClose={ closePopover }
84
- actions={ actions }
85
- />
86
-
87
- { hasVariables && (
88
- <PopoverSearch
89
- value={ searchValue }
90
- onSearch={ handleSearch }
91
- placeholder={ __( 'Search', 'elementor' ) }
92
- />
93
- ) }
94
-
95
- <Divider />
96
-
97
- <PopoverScrollableContent>
98
- { hasVariables && hasSearchResults && (
99
- <PopoverMenuList
100
- items={ items }
101
- onSelect={ handleSetColorVariable }
102
- onClose={ () => {} }
103
- selectedValue={ variable }
104
- data-testid="color-variables-list"
105
- menuListTemplate={ VariablesStyledMenuList }
106
- menuItemContentTemplate={ ( item: VirtualizedItem< 'item', string > ) => (
107
- <MenuItemContent item={ item } />
108
- ) }
109
- />
110
- ) }
111
-
112
- { ! hasSearchResults && hasVariables && (
113
- <NoSearchResults
114
- searchValue={ searchValue }
115
- onClear={ handleClearSearch }
116
- icon={ <BrushIcon fontSize="large" /> }
117
- />
118
- ) }
119
-
120
- { ! hasVariables && (
121
- <NoVariables
122
- title={ __( 'Create your first color variable', 'elementor' ) }
123
- icon={ <BrushIcon fontSize="large" /> }
124
- onAdd={ onAdd }
125
- />
126
- ) }
127
- </PopoverScrollableContent>
128
- </>
129
- );
130
- };
@@ -1,86 +0,0 @@
1
- import * as React from 'react';
2
- import { useState } from 'react';
3
- import { PopoverContent, useBoundProp } from '@elementor/editor-controls';
4
- import { PopoverScrollableContent } from '@elementor/editor-editing-panel';
5
- import { PopoverHeader } from '@elementor/editor-ui';
6
- import { ArrowLeftIcon, TextIcon } from '@elementor/icons';
7
- import { Button, CardActions, Divider, IconButton } from '@elementor/ui';
8
- import { __ } from '@wordpress/i18n';
9
-
10
- import { createVariable } from '../hooks/use-prop-variables';
11
- import { fontVariablePropTypeUtil } from '../prop-types/font-variable-prop-type';
12
- import { FontField } from './fields/font-field';
13
- import { LabelField } from './fields/label-field';
14
-
15
- const SIZE = 'tiny';
16
-
17
- type Props = {
18
- onGoBack?: () => void;
19
- onClose: () => void;
20
- };
21
-
22
- export const FontVariableCreation = ( { onClose, onGoBack }: Props ) => {
23
- const { setValue: setVariable } = useBoundProp( fontVariablePropTypeUtil );
24
-
25
- const [ fontFamily, setFontFamily ] = useState( '' );
26
- const [ label, setLabel ] = useState( '' );
27
-
28
- const resetFields = () => {
29
- setFontFamily( '' );
30
- setLabel( '' );
31
- };
32
-
33
- const closePopover = () => {
34
- resetFields();
35
- onClose();
36
- };
37
-
38
- const handleCreate = () => {
39
- createVariable( {
40
- value: fontFamily,
41
- label,
42
- type: fontVariablePropTypeUtil.key,
43
- } ).then( ( key ) => {
44
- setVariable( key );
45
- closePopover();
46
- } );
47
- };
48
-
49
- const hasEmptyValue = () => {
50
- return '' === fontFamily.trim() || '' === label.trim();
51
- };
52
-
53
- const isSubmitDisabled = hasEmptyValue();
54
-
55
- return (
56
- <PopoverScrollableContent height="auto">
57
- <PopoverHeader
58
- icon={
59
- <>
60
- { onGoBack && (
61
- <IconButton size={ SIZE } aria-label={ __( 'Go Back', 'elementor' ) } onClick={ onGoBack }>
62
- <ArrowLeftIcon fontSize={ SIZE } />
63
- </IconButton>
64
- ) }
65
- <TextIcon fontSize={ SIZE } />
66
- </>
67
- }
68
- title={ __( 'Create variable', 'elementor' ) }
69
- onClose={ closePopover }
70
- />
71
-
72
- <Divider />
73
-
74
- <PopoverContent p={ 2 }>
75
- <LabelField value={ label } onChange={ setLabel } />
76
- <FontField value={ fontFamily } onChange={ setFontFamily } />
77
- </PopoverContent>
78
-
79
- <CardActions sx={ { pt: 0.5, pb: 1 } }>
80
- <Button size="small" variant="contained" disabled={ isSubmitDisabled } onClick={ handleCreate }>
81
- { __( 'Create', 'elementor' ) }
82
- </Button>
83
- </CardActions>
84
- </PopoverScrollableContent>
85
- );
86
- };
@@ -1,138 +0,0 @@
1
- import * as React from 'react';
2
- import { useState } from 'react';
3
- import { PopoverContent, useBoundProp } from '@elementor/editor-controls';
4
- import { PopoverScrollableContent } from '@elementor/editor-editing-panel';
5
- import { PopoverHeader } from '@elementor/editor-ui';
6
- import { ArrowLeftIcon, TextIcon, TrashIcon } from '@elementor/icons';
7
- import { Button, CardActions, Divider, IconButton } from '@elementor/ui';
8
- import { __ } from '@wordpress/i18n';
9
-
10
- import { deleteVariable, updateVariable, useVariable } from '../hooks/use-prop-variables';
11
- import { fontVariablePropTypeUtil } from '../prop-types/font-variable-prop-type';
12
- import { FontField } from './fields/font-field';
13
- import { LabelField } from './fields/label-field';
14
- import { DeleteConfirmationDialog } from './ui/delete-confirmation-dialog';
15
-
16
- const SIZE = 'tiny';
17
-
18
- type Props = {
19
- editId: string;
20
- onClose: () => void;
21
- onGoBack?: () => void;
22
- onSubmit?: () => void;
23
- };
24
-
25
- export const FontVariableEdit = ( { onClose, onGoBack, onSubmit, editId }: Props ) => {
26
- const { setValue: notifyBoundPropChange, value: assignedValue } = useBoundProp( fontVariablePropTypeUtil );
27
- const [ deleteConfirmation, setDeleteConfirmation ] = useState( false );
28
-
29
- const variable = useVariable( editId );
30
- if ( ! variable ) {
31
- throw new Error( `Global font variable "${ editId }" not found` );
32
- }
33
-
34
- const [ fontFamily, setFontFamily ] = useState( variable.value );
35
- const [ label, setLabel ] = useState( variable.label );
36
-
37
- const handleUpdate = () => {
38
- updateVariable( editId, {
39
- value: fontFamily,
40
- label,
41
- } ).then( () => {
42
- maybeTriggerBoundPropChange();
43
- onSubmit?.();
44
- } );
45
- };
46
-
47
- const handleDelete = () => {
48
- deleteVariable( editId ).then( () => {
49
- maybeTriggerBoundPropChange();
50
- onSubmit?.();
51
- } );
52
- };
53
-
54
- const maybeTriggerBoundPropChange = () => {
55
- if ( editId === assignedValue ) {
56
- notifyBoundPropChange( editId );
57
- }
58
- };
59
-
60
- const handleDeleteConfirmation = () => {
61
- setDeleteConfirmation( true );
62
- };
63
-
64
- const closeDeleteDialog = () => () => {
65
- setDeleteConfirmation( false );
66
- };
67
-
68
- const hasEmptyValue = () => {
69
- return ! fontFamily.trim() || ! label.trim();
70
- };
71
-
72
- const noValueChanged = () => {
73
- return fontFamily === variable.value && label === variable.label;
74
- };
75
-
76
- const isSubmitDisabled = noValueChanged() || hasEmptyValue();
77
-
78
- const actions = [];
79
-
80
- actions.push(
81
- <IconButton
82
- key="delete"
83
- size={ SIZE }
84
- aria-label={ __( 'Delete', 'elementor' ) }
85
- onClick={ handleDeleteConfirmation }
86
- >
87
- <TrashIcon fontSize={ SIZE } />
88
- </IconButton>
89
- );
90
-
91
- return (
92
- <>
93
- <PopoverScrollableContent height="auto">
94
- <PopoverHeader
95
- icon={
96
- <>
97
- { onGoBack && (
98
- <IconButton
99
- size={ SIZE }
100
- aria-label={ __( 'Go Back', 'elementor' ) }
101
- onClick={ onGoBack }
102
- >
103
- <ArrowLeftIcon fontSize={ SIZE } />
104
- </IconButton>
105
- ) }
106
- <TextIcon fontSize={ SIZE } />
107
- </>
108
- }
109
- title={ __( 'Edit variable', 'elementor' ) }
110
- onClose={ onClose }
111
- actions={ actions }
112
- />
113
-
114
- <Divider />
115
-
116
- <PopoverContent p={ 2 }>
117
- <LabelField value={ label } onChange={ setLabel } />
118
- <FontField value={ fontFamily } onChange={ setFontFamily } />
119
- </PopoverContent>
120
-
121
- <CardActions sx={ { pt: 0.5, pb: 1 } }>
122
- <Button size="small" variant="contained" disabled={ isSubmitDisabled } onClick={ handleUpdate }>
123
- { __( 'Save', 'elementor' ) }
124
- </Button>
125
- </CardActions>
126
- </PopoverScrollableContent>
127
-
128
- { deleteConfirmation && (
129
- <DeleteConfirmationDialog
130
- open
131
- label={ label }
132
- onConfirm={ handleDelete }
133
- closeDialog={ closeDeleteDialog() }
134
- />
135
- ) }
136
- </>
137
- );
138
- };
@@ -1,129 +0,0 @@
1
- import * as React from 'react';
2
- import { useState } from 'react';
3
- import { useBoundProp } from '@elementor/editor-controls';
4
- import { PopoverScrollableContent } from '@elementor/editor-editing-panel';
5
- import { PopoverHeader, PopoverMenuList, PopoverSearch, type VirtualizedItem } from '@elementor/editor-ui';
6
- import { ColorFilterIcon, PlusIcon, SettingsIcon, TextIcon } from '@elementor/icons';
7
- import { Divider, IconButton } from '@elementor/ui';
8
- import { __ } from '@wordpress/i18n';
9
-
10
- import { useFilteredVariables } from '../hooks/use-prop-variables';
11
- import { fontVariablePropTypeUtil } from '../prop-types/font-variable-prop-type';
12
- import { type ExtendedVirtualizedItem } from '../types';
13
- import { MenuItemContent } from './ui/menu-item-content';
14
- import { NoSearchResults } from './ui/no-search-results';
15
- import { NoVariables } from './ui/no-variables';
16
- import { VariablesStyledMenuList } from './ui/styled-menu-list';
17
-
18
- const SIZE = 'tiny';
19
-
20
- type Props = {
21
- closePopover: () => void;
22
- onAdd?: () => void;
23
- onEdit?: ( key: string ) => void;
24
- onSettings?: () => void;
25
- };
26
-
27
- export const FontVariablesSelection = ( { closePopover, onAdd, onEdit, onSettings }: Props ) => {
28
- const { value: variable, setValue: setVariable } = useBoundProp( fontVariablePropTypeUtil );
29
- const [ searchValue, setSearchValue ] = useState( '' );
30
-
31
- const {
32
- list: variables,
33
- hasMatches: hasSearchResults,
34
- isSourceNotEmpty: hasVariables,
35
- } = useFilteredVariables( searchValue, fontVariablePropTypeUtil.key );
36
-
37
- const handleSetVariable = ( key: string ) => {
38
- setVariable( key );
39
- closePopover();
40
- };
41
-
42
- const actions = [];
43
-
44
- if ( onAdd ) {
45
- actions.push(
46
- <IconButton key="add" size={ SIZE } onClick={ onAdd }>
47
- <PlusIcon fontSize={ SIZE } />
48
- </IconButton>
49
- );
50
- }
51
-
52
- if ( onSettings ) {
53
- actions.push(
54
- <IconButton key="settings" size={ SIZE } onClick={ onSettings }>
55
- <SettingsIcon fontSize={ SIZE } />
56
- </IconButton>
57
- );
58
- }
59
-
60
- const items: ExtendedVirtualizedItem[] = variables.map( ( { value, label, key } ) => ( {
61
- type: 'item' as const,
62
- value: key,
63
- label,
64
- icon: <TextIcon fontSize={ SIZE } />,
65
- secondaryText: value,
66
- onEdit: () => onEdit?.( key ),
67
- } ) );
68
-
69
- const handleSearch = ( search: string ) => {
70
- setSearchValue( search );
71
- };
72
-
73
- const handleClearSearch = () => {
74
- setSearchValue( '' );
75
- };
76
-
77
- return (
78
- <>
79
- <PopoverHeader
80
- title={ __( 'Variables', 'elementor' ) }
81
- onClose={ closePopover }
82
- icon={ <ColorFilterIcon fontSize={ SIZE } /> }
83
- actions={ actions }
84
- />
85
-
86
- { hasVariables && (
87
- <PopoverSearch
88
- value={ searchValue }
89
- onSearch={ handleSearch }
90
- placeholder={ __( 'Search', 'elementor' ) }
91
- />
92
- ) }
93
-
94
- <Divider />
95
-
96
- <PopoverScrollableContent>
97
- { hasVariables && hasSearchResults && (
98
- <PopoverMenuList
99
- items={ items }
100
- onSelect={ handleSetVariable }
101
- onClose={ () => {} }
102
- selectedValue={ variable }
103
- data-testid="font-variables-list"
104
- menuListTemplate={ VariablesStyledMenuList }
105
- menuItemContentTemplate={ ( item: VirtualizedItem< 'item', string > ) => (
106
- <MenuItemContent item={ item } />
107
- ) }
108
- />
109
- ) }
110
-
111
- { ! hasSearchResults && hasVariables && (
112
- <NoSearchResults
113
- searchValue={ searchValue }
114
- onClear={ handleClearSearch }
115
- icon={ <TextIcon fontSize="large" /> }
116
- />
117
- ) }
118
-
119
- { ! hasVariables && (
120
- <NoVariables
121
- title={ __( 'Create your first font variable', 'elementor' ) }
122
- icon={ <TextIcon fontSize="large" /> }
123
- onAdd={ onAdd }
124
- />
125
- ) }
126
- </PopoverScrollableContent>
127
- </>
128
- );
129
- };