@wordpress/components 19.0.4 → 19.1.2
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/CHANGELOG.md +17 -0
- package/build/card/styles.js +21 -17
- package/build/card/styles.js.map +1 -1
- package/build/circular-option-picker/index.js +2 -2
- package/build/circular-option-picker/index.js.map +1 -1
- package/build/color-palette/index.js +7 -1
- package/build/color-palette/index.js.map +1 -1
- package/build/color-picker/component.js +15 -5
- package/build/color-picker/component.js.map +1 -1
- package/build/date-time/time.js +17 -3
- package/build/date-time/time.js.map +1 -1
- package/build/duotone-picker/duotone-picker.js +2 -1
- package/build/duotone-picker/duotone-picker.js.map +1 -1
- package/build/font-size-picker/index.js +2 -1
- package/build/font-size-picker/index.js.map +1 -1
- package/build/gradient-picker/index.js +2 -2
- package/build/gradient-picker/index.js.map +1 -1
- package/build/index.js +7 -7
- package/build/index.js.map +1 -1
- package/build/mobile/global-styles-context/utils.native.js +2 -2
- package/build/mobile/global-styles-context/utils.native.js.map +1 -1
- package/build/navigation/item/index.js +9 -4
- package/build/navigation/item/index.js.map +1 -1
- package/build/navigation/styles/navigation-styles.js +37 -30
- package/build/navigation/styles/navigation-styles.js.map +1 -1
- package/build/palette-edit/index.js +307 -0
- package/build/palette-edit/index.js.map +1 -0
- package/build/palette-edit/styles.js +112 -0
- package/build/palette-edit/styles.js.map +1 -0
- package/build/popover/index.js +1 -1
- package/build/popover/index.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control-option/component.js +30 -4
- package/build/toggle-group-control/toggle-group-control-option/component.js.map +1 -1
- package/build/tooltip/index.js +4 -4
- package/build/tooltip/index.js.map +1 -1
- package/build-module/card/styles.js +21 -17
- package/build-module/card/styles.js.map +1 -1
- package/build-module/circular-option-picker/index.js +2 -2
- package/build-module/circular-option-picker/index.js.map +1 -1
- package/build-module/color-palette/index.js +6 -1
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/color-picker/component.js +13 -5
- package/build-module/color-picker/component.js.map +1 -1
- package/build-module/date-time/time.js +17 -3
- package/build-module/date-time/time.js.map +1 -1
- package/build-module/duotone-picker/duotone-picker.js +2 -1
- package/build-module/duotone-picker/duotone-picker.js.map +1 -1
- package/build-module/font-size-picker/index.js +2 -1
- package/build-module/font-size-picker/index.js.map +1 -1
- package/build-module/gradient-picker/index.js +2 -2
- package/build-module/gradient-picker/index.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/mobile/global-styles-context/utils.native.js +2 -2
- package/build-module/mobile/global-styles-context/utils.native.js.map +1 -1
- package/build-module/navigation/item/index.js +10 -5
- package/build-module/navigation/item/index.js.map +1 -1
- package/build-module/navigation/styles/navigation-styles.js +34 -28
- package/build-module/navigation/styles/navigation-styles.js.map +1 -1
- package/build-module/palette-edit/index.js +280 -0
- package/build-module/palette-edit/index.js.map +1 -0
- package/build-module/palette-edit/styles.js +90 -0
- package/build-module/palette-edit/styles.js.map +1 -0
- package/build-module/popover/index.js +1 -1
- package/build-module/popover/index.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control-option/component.js +26 -5
- package/build-module/toggle-group-control/toggle-group-control-option/component.js.map +1 -1
- package/build-module/tooltip/index.js +4 -4
- package/build-module/tooltip/index.js.map +1 -1
- package/build-style/style-rtl.css +33 -1
- package/build-style/style.css +33 -1
- package/build-types/card/card/hook.d.ts +1 -1
- package/build-types/card/card-header/component.d.ts +1 -1
- package/build-types/card/styles.d.ts +7 -4
- package/build-types/card/styles.d.ts.map +1 -1
- package/build-types/card/types.d.ts +2 -1
- package/build-types/card/types.d.ts.map +1 -1
- package/build-types/confirm-dialog/component.d.ts +34 -0
- package/build-types/confirm-dialog/component.d.ts.map +1 -0
- package/build-types/confirm-dialog/index.d.ts +6 -0
- package/build-types/confirm-dialog/index.d.ts.map +1 -0
- package/build-types/confirm-dialog/types.d.ts +20 -0
- package/build-types/confirm-dialog/types.d.ts.map +1 -0
- package/build-types/flyout/styles.d.ts +1 -1
- package/build-types/higher-order/with-focus-outside/index.d.ts +3 -0
- package/build-types/higher-order/with-focus-outside/index.d.ts.map +1 -0
- package/build-types/modal/aria-helper.d.ts +27 -0
- package/build-types/modal/aria-helper.d.ts.map +1 -0
- package/build-types/modal/index.d.ts +3 -0
- package/build-types/modal/index.d.ts.map +1 -0
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/style-provider/index.d.ts +5 -0
- package/build-types/style-provider/index.d.ts.map +1 -0
- package/build-types/toggle-group-control/toggle-group-control-option/component.d.ts.map +1 -1
- package/build-types/toggle-group-control/types.d.ts +23 -0
- package/build-types/toggle-group-control/types.d.ts.map +1 -1
- package/build-types/tooltip/index.d.ts +1 -7
- package/build-types/tooltip/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/card/styles.js +8 -3
- package/src/card/test/__snapshots__/index.js.snap +6 -1
- package/src/card/test/index.js +20 -0
- package/src/card/types.ts +2 -1
- package/src/circular-option-picker/index.js +7 -5
- package/src/circular-option-picker/style.scss +1 -0
- package/src/color-palette/index.js +8 -0
- package/src/color-palette/style.scss +21 -0
- package/src/color-palette/test/__snapshots__/index.js.snap +2 -0
- package/src/color-picker/README.md +13 -11
- package/src/color-picker/component.tsx +15 -5
- package/src/color-picker/test/index.js +15 -0
- package/src/date-time/test/time.js +32 -2
- package/src/date-time/time.js +14 -6
- package/src/duotone-picker/duotone-picker.js +8 -5
- package/src/font-size-picker/index.js +1 -0
- package/src/gradient-picker/index.js +7 -4
- package/src/gradient-picker/stories/index.js +23 -0
- package/src/index.js +1 -1
- package/src/mobile/global-styles-context/utils.native.js +2 -2
- package/src/navigation/item/index.js +20 -5
- package/src/navigation/stories/more-examples.js +2 -1
- package/src/navigation/styles/navigation-styles.js +5 -0
- package/src/palette-edit/index.js +398 -0
- package/src/palette-edit/style.scss +19 -0
- package/src/{color-edit → palette-edit}/styles.js +15 -18
- package/src/popover/index.js +5 -1
- package/src/style.scss +1 -1
- package/src/toggle-group-control/stories/index.js +15 -0
- package/src/toggle-group-control/test/index.js +57 -0
- package/src/toggle-group-control/toggle-group-control-option/README.md +8 -1
- package/src/toggle-group-control/toggle-group-control-option/component.tsx +40 -17
- package/src/toggle-group-control/types.ts +24 -0
- package/src/tooltip/index.js +2 -7
- package/tsconfig.tsbuildinfo +1 -1
- package/build/color-edit/index.js +0 -251
- package/build/color-edit/index.js.map +0 -1
- package/build/color-edit/styles.js +0 -112
- package/build/color-edit/styles.js.map +0 -1
- package/build-module/color-edit/index.js +0 -227
- package/build-module/color-edit/index.js.map +0 -1
- package/build-module/color-edit/styles.js +0 -90
- package/build-module/color-edit/styles.js.map +0 -1
- package/src/color-edit/index.js +0 -300
- package/src/color-edit/style.scss +0 -6
|
@@ -84,3 +84,26 @@ export const _default = () => {
|
|
|
84
84
|
/>
|
|
85
85
|
);
|
|
86
86
|
};
|
|
87
|
+
|
|
88
|
+
export const WithNoExistingGradients = () => {
|
|
89
|
+
const disableCustomGradients = boolean( 'Disable Custom Gradients', false );
|
|
90
|
+
const __experimentalHasMultipleOrigins = boolean(
|
|
91
|
+
'Experimental Has Multiple Origins',
|
|
92
|
+
true
|
|
93
|
+
);
|
|
94
|
+
const clearable = boolean( 'Clearable', true );
|
|
95
|
+
const className = text( 'Class Name', '' );
|
|
96
|
+
const gradients = object( 'Gradients', [] );
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<GradientPickerWithState
|
|
100
|
+
__experimentalHasMultipleOrigins={
|
|
101
|
+
__experimentalHasMultipleOrigins
|
|
102
|
+
}
|
|
103
|
+
disableCustomGradients={ disableCustomGradients }
|
|
104
|
+
gradients={ gradients }
|
|
105
|
+
clearable={ clearable }
|
|
106
|
+
className={ className }
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
};
|
package/src/index.js
CHANGED
|
@@ -36,7 +36,7 @@ export {
|
|
|
36
36
|
} from './card';
|
|
37
37
|
export { default as CheckboxControl } from './checkbox-control';
|
|
38
38
|
export { default as ClipboardButton } from './clipboard-button';
|
|
39
|
-
export { default as
|
|
39
|
+
export { default as __experimentalPaletteEdit } from './palette-edit';
|
|
40
40
|
export { default as ColorIndicator } from './color-indicator';
|
|
41
41
|
export { default as ColorPalette } from './color-palette';
|
|
42
42
|
export { ColorPicker } from './color-picker';
|
|
@@ -233,10 +233,10 @@ export function parseStylesVariables( styles, mappedValues, customValues ) {
|
|
|
233
233
|
|
|
234
234
|
export function getMappedValues( features, palette ) {
|
|
235
235
|
const typography = features?.typography;
|
|
236
|
-
const colors = { ...palette?.theme, ...palette?.
|
|
236
|
+
const colors = { ...palette?.theme, ...palette?.custom };
|
|
237
237
|
const fontSizes = {
|
|
238
238
|
...typography?.fontSizes?.theme,
|
|
239
|
-
...typography?.fontSizes?.
|
|
239
|
+
...typography?.fontSizes?.custom,
|
|
240
240
|
};
|
|
241
241
|
const mappedValues = {
|
|
242
242
|
color: {
|
|
@@ -15,7 +15,7 @@ import { isRTL } from '@wordpress/i18n';
|
|
|
15
15
|
*/
|
|
16
16
|
import Button from '../../button';
|
|
17
17
|
import { useNavigationContext } from '../context';
|
|
18
|
-
import { ItemUI } from '../styles/navigation-styles';
|
|
18
|
+
import { ItemUI, ItemIconUI } from '../styles/navigation-styles';
|
|
19
19
|
import NavigationItemBaseContent from './base-content';
|
|
20
20
|
import NavigationItemBase from './base';
|
|
21
21
|
|
|
@@ -29,6 +29,7 @@ export default function NavigationItem( props ) {
|
|
|
29
29
|
navigateToMenu,
|
|
30
30
|
onClick = noop,
|
|
31
31
|
title,
|
|
32
|
+
icon,
|
|
32
33
|
hideIfTargetMenuEmpty,
|
|
33
34
|
isText,
|
|
34
35
|
...restProps
|
|
@@ -51,8 +52,10 @@ export default function NavigationItem( props ) {
|
|
|
51
52
|
return null;
|
|
52
53
|
}
|
|
53
54
|
|
|
55
|
+
const isActive = item && activeItem === item;
|
|
56
|
+
|
|
54
57
|
const classes = classnames( className, {
|
|
55
|
-
'is-active':
|
|
58
|
+
'is-active': isActive,
|
|
56
59
|
} );
|
|
57
60
|
|
|
58
61
|
const onItemClick = ( event ) => {
|
|
@@ -62,22 +65,34 @@ export default function NavigationItem( props ) {
|
|
|
62
65
|
|
|
63
66
|
onClick( event );
|
|
64
67
|
};
|
|
65
|
-
const
|
|
68
|
+
const navigationIcon = isRTL() ? chevronLeft : chevronRight;
|
|
66
69
|
const baseProps = children ? props : { ...props, onClick: undefined };
|
|
67
70
|
const itemProps = isText
|
|
68
71
|
? restProps
|
|
69
|
-
: {
|
|
72
|
+
: {
|
|
73
|
+
as: Button,
|
|
74
|
+
href,
|
|
75
|
+
onClick: onItemClick,
|
|
76
|
+
'aria-current': isActive ? 'page' : undefined,
|
|
77
|
+
...restProps,
|
|
78
|
+
};
|
|
70
79
|
|
|
71
80
|
return (
|
|
72
81
|
<NavigationItemBase { ...baseProps } className={ classes }>
|
|
73
82
|
{ children || (
|
|
74
83
|
<ItemUI { ...itemProps }>
|
|
84
|
+
{ icon && (
|
|
85
|
+
<ItemIconUI>
|
|
86
|
+
<Icon icon={ icon } />
|
|
87
|
+
</ItemIconUI>
|
|
88
|
+
) }
|
|
89
|
+
|
|
75
90
|
<NavigationItemBaseContent
|
|
76
91
|
title={ title }
|
|
77
92
|
badge={ badge }
|
|
78
93
|
/>
|
|
79
94
|
|
|
80
|
-
{ navigateToMenu && <Icon icon={
|
|
95
|
+
{ navigateToMenu && <Icon icon={ navigationIcon } /> }
|
|
81
96
|
</ItemUI>
|
|
82
97
|
) }
|
|
83
98
|
</NavigationItemBase>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useEffect, useState } from '@wordpress/element';
|
|
5
|
-
import { Icon, wordpress } from '@wordpress/icons';
|
|
5
|
+
import { Icon, wordpress, home } from '@wordpress/icons';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
@@ -33,6 +33,7 @@ export function MoreExamplesStory() {
|
|
|
33
33
|
</NavigationGroup>
|
|
34
34
|
<NavigationGroup title="Items with Unusual Features">
|
|
35
35
|
<NavigationItem
|
|
36
|
+
icon={ home }
|
|
36
37
|
item="item-sub-menu"
|
|
37
38
|
navigateToMenu="sub-menu"
|
|
38
39
|
title="Sub-Menu with Custom Back Label"
|
|
@@ -184,6 +184,11 @@ export const ItemUI = styled.div`
|
|
|
184
184
|
opacity: 0.7;
|
|
185
185
|
`;
|
|
186
186
|
|
|
187
|
+
export const ItemIconUI = styled.span`
|
|
188
|
+
display: flex;
|
|
189
|
+
margin-right: ${ space( 2 ) };
|
|
190
|
+
`;
|
|
191
|
+
|
|
187
192
|
export const ItemBadgeUI = styled.span`
|
|
188
193
|
margin-left: ${ () => ( isRTL() ? '0' : space( 2 ) ) };
|
|
189
194
|
margin-right: ${ () => ( isRTL() ? space( 2 ) : '0' ) };
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { kebabCase } from 'lodash';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useState, useRef, useEffect } from '@wordpress/element';
|
|
10
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
11
|
+
import { lineSolid, moreVertical, plus } from '@wordpress/icons';
|
|
12
|
+
import { __experimentalUseFocusOutside as useFocusOutside } from '@wordpress/compose';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import Button from '../button';
|
|
18
|
+
import { ColorPicker } from '../color-picker';
|
|
19
|
+
import { FlexItem } from '../flex';
|
|
20
|
+
import { HStack } from '../h-stack';
|
|
21
|
+
import { ItemGroup } from '../item-group';
|
|
22
|
+
import { VStack } from '../v-stack';
|
|
23
|
+
import GradientPicker from '../gradient-picker';
|
|
24
|
+
import ColorPalette from '../color-palette';
|
|
25
|
+
import DropdownMenu from '../dropdown-menu';
|
|
26
|
+
import Popover from '../popover';
|
|
27
|
+
import {
|
|
28
|
+
PaletteActionsContainer,
|
|
29
|
+
PaletteEditStyles,
|
|
30
|
+
PaletteHeading,
|
|
31
|
+
PaletteHStackHeader,
|
|
32
|
+
IndicatorStyled,
|
|
33
|
+
PaletteItem,
|
|
34
|
+
NameContainer,
|
|
35
|
+
NameInputControl,
|
|
36
|
+
DoneButton,
|
|
37
|
+
RemoveButton,
|
|
38
|
+
} from './styles';
|
|
39
|
+
import { NavigableMenu } from '../navigable-container';
|
|
40
|
+
import { DEFAULT_GRADIENT } from '../custom-gradient-picker/constants';
|
|
41
|
+
import CustomGradientPicker from '../custom-gradient-picker';
|
|
42
|
+
|
|
43
|
+
function NameInput( { value, onChange, label } ) {
|
|
44
|
+
return (
|
|
45
|
+
<NameInputControl
|
|
46
|
+
label={ label }
|
|
47
|
+
hideLabelFromVision
|
|
48
|
+
value={ value }
|
|
49
|
+
onChange={ onChange }
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function Option( {
|
|
55
|
+
canOnlyChangeValues,
|
|
56
|
+
element,
|
|
57
|
+
onChange,
|
|
58
|
+
isEditing,
|
|
59
|
+
onStartEditing,
|
|
60
|
+
onRemove,
|
|
61
|
+
onStopEditing,
|
|
62
|
+
slugPrefix,
|
|
63
|
+
isGradient,
|
|
64
|
+
} ) {
|
|
65
|
+
const focusOutsideProps = useFocusOutside( onStopEditing );
|
|
66
|
+
const value = isGradient ? element.gradient : element.color;
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<PaletteItem
|
|
70
|
+
as="div"
|
|
71
|
+
onClick={ onStartEditing }
|
|
72
|
+
{ ...( isEditing ? focusOutsideProps : {} ) }
|
|
73
|
+
>
|
|
74
|
+
<HStack justify="flex-start">
|
|
75
|
+
<FlexItem>
|
|
76
|
+
<IndicatorStyled
|
|
77
|
+
style={ { background: value, color: 'transparent' } }
|
|
78
|
+
/>
|
|
79
|
+
</FlexItem>
|
|
80
|
+
<FlexItem>
|
|
81
|
+
{ isEditing && ! canOnlyChangeValues ? (
|
|
82
|
+
<NameInput
|
|
83
|
+
label={
|
|
84
|
+
isGradient
|
|
85
|
+
? __( 'Gradient name' )
|
|
86
|
+
: __( 'Color name' )
|
|
87
|
+
}
|
|
88
|
+
value={ element.name }
|
|
89
|
+
onChange={ ( nextName ) =>
|
|
90
|
+
onChange( {
|
|
91
|
+
...element,
|
|
92
|
+
name: nextName,
|
|
93
|
+
slug: slugPrefix + kebabCase( nextName ),
|
|
94
|
+
} )
|
|
95
|
+
}
|
|
96
|
+
/>
|
|
97
|
+
) : (
|
|
98
|
+
<NameContainer>{ element.name }</NameContainer>
|
|
99
|
+
) }
|
|
100
|
+
</FlexItem>
|
|
101
|
+
{ isEditing && ! canOnlyChangeValues && (
|
|
102
|
+
<FlexItem>
|
|
103
|
+
<RemoveButton
|
|
104
|
+
isSmall
|
|
105
|
+
icon={ lineSolid }
|
|
106
|
+
label={ __( 'Remove color' ) }
|
|
107
|
+
onClick={ onRemove }
|
|
108
|
+
/>
|
|
109
|
+
</FlexItem>
|
|
110
|
+
) }
|
|
111
|
+
</HStack>
|
|
112
|
+
{ isEditing && (
|
|
113
|
+
<Popover
|
|
114
|
+
position="bottom left"
|
|
115
|
+
className="components-palette-edit__popover"
|
|
116
|
+
>
|
|
117
|
+
{ ! isGradient && (
|
|
118
|
+
<ColorPicker
|
|
119
|
+
color={ value }
|
|
120
|
+
onChange={ ( newColor ) =>
|
|
121
|
+
onChange( {
|
|
122
|
+
...element,
|
|
123
|
+
color: newColor,
|
|
124
|
+
} )
|
|
125
|
+
}
|
|
126
|
+
/>
|
|
127
|
+
) }
|
|
128
|
+
{ isGradient && (
|
|
129
|
+
<CustomGradientPicker
|
|
130
|
+
value={ value }
|
|
131
|
+
onChange={ ( newGradient ) =>
|
|
132
|
+
onChange( {
|
|
133
|
+
...element,
|
|
134
|
+
gradient: newGradient,
|
|
135
|
+
} )
|
|
136
|
+
}
|
|
137
|
+
/>
|
|
138
|
+
) }
|
|
139
|
+
</Popover>
|
|
140
|
+
) }
|
|
141
|
+
</PaletteItem>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function PaletteEditListView( {
|
|
146
|
+
elements,
|
|
147
|
+
onChange,
|
|
148
|
+
editingElement,
|
|
149
|
+
setEditingElement,
|
|
150
|
+
canOnlyChangeValues,
|
|
151
|
+
slugPrefix,
|
|
152
|
+
isGradient,
|
|
153
|
+
} ) {
|
|
154
|
+
// When unmounting the component if there are empty elements (the user did not complete the insertion) clean them.
|
|
155
|
+
const elementsReference = useRef();
|
|
156
|
+
useEffect( () => {
|
|
157
|
+
elementsReference.current = elements;
|
|
158
|
+
}, [ elements ] );
|
|
159
|
+
useEffect( () => {
|
|
160
|
+
return () => {
|
|
161
|
+
if ( elementsReference.current.some( ( { slug } ) => ! slug ) ) {
|
|
162
|
+
const newElements = elementsReference.current.filter(
|
|
163
|
+
( { slug } ) => slug
|
|
164
|
+
);
|
|
165
|
+
onChange( newElements.length ? newElements : undefined );
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}, [] );
|
|
169
|
+
return (
|
|
170
|
+
<VStack spacing={ 3 }>
|
|
171
|
+
<ItemGroup isBordered isSeparated>
|
|
172
|
+
{ elements.map( ( element, index ) => (
|
|
173
|
+
<Option
|
|
174
|
+
isGradient={ isGradient }
|
|
175
|
+
canOnlyChangeValues={ canOnlyChangeValues }
|
|
176
|
+
key={ index }
|
|
177
|
+
element={ element }
|
|
178
|
+
onStartEditing={ () => {
|
|
179
|
+
if ( editingElement !== index ) {
|
|
180
|
+
setEditingElement( index );
|
|
181
|
+
}
|
|
182
|
+
} }
|
|
183
|
+
onChange={ ( newElement ) => {
|
|
184
|
+
onChange(
|
|
185
|
+
elements.map(
|
|
186
|
+
( currentElement, currentIndex ) => {
|
|
187
|
+
if ( currentIndex === index ) {
|
|
188
|
+
return newElement;
|
|
189
|
+
}
|
|
190
|
+
return currentElement;
|
|
191
|
+
}
|
|
192
|
+
)
|
|
193
|
+
);
|
|
194
|
+
} }
|
|
195
|
+
onRemove={ () => {
|
|
196
|
+
setEditingElement( null );
|
|
197
|
+
const newElements = elements.filter(
|
|
198
|
+
( _currentElement, currentIndex ) => {
|
|
199
|
+
if ( currentIndex === index ) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
onChange(
|
|
206
|
+
newElements.length ? newElements : undefined
|
|
207
|
+
);
|
|
208
|
+
} }
|
|
209
|
+
isEditing={ index === editingElement }
|
|
210
|
+
onStopEditing={ () => {
|
|
211
|
+
if ( index === editingElement ) {
|
|
212
|
+
setEditingElement( null );
|
|
213
|
+
}
|
|
214
|
+
} }
|
|
215
|
+
slugPrefix={ slugPrefix }
|
|
216
|
+
/>
|
|
217
|
+
) ) }
|
|
218
|
+
</ItemGroup>
|
|
219
|
+
</VStack>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const EMPTY_ARRAY = [];
|
|
224
|
+
|
|
225
|
+
export default function PaletteEdit( {
|
|
226
|
+
gradients,
|
|
227
|
+
colors = EMPTY_ARRAY,
|
|
228
|
+
onChange,
|
|
229
|
+
paletteLabel,
|
|
230
|
+
emptyMessage,
|
|
231
|
+
canOnlyChangeValues,
|
|
232
|
+
canReset,
|
|
233
|
+
slugPrefix = '',
|
|
234
|
+
} ) {
|
|
235
|
+
const isGradient = !! gradients;
|
|
236
|
+
const elements = isGradient ? gradients : colors;
|
|
237
|
+
const [ isEditing, setIsEditing ] = useState( false );
|
|
238
|
+
const [ editingElement, setEditingElement ] = useState( null );
|
|
239
|
+
const isAdding =
|
|
240
|
+
isEditing &&
|
|
241
|
+
editingElement &&
|
|
242
|
+
elements[ editingElement ] &&
|
|
243
|
+
! elements[ editingElement ].slug;
|
|
244
|
+
const elementsLength = elements.length;
|
|
245
|
+
const hasElements = elementsLength > 0;
|
|
246
|
+
|
|
247
|
+
return (
|
|
248
|
+
<PaletteEditStyles>
|
|
249
|
+
<PaletteHStackHeader>
|
|
250
|
+
<PaletteHeading>{ paletteLabel }</PaletteHeading>
|
|
251
|
+
<PaletteActionsContainer>
|
|
252
|
+
{ isEditing && (
|
|
253
|
+
<DoneButton
|
|
254
|
+
isSmall
|
|
255
|
+
onClick={ () => {
|
|
256
|
+
setIsEditing( false );
|
|
257
|
+
setEditingElement( null );
|
|
258
|
+
} }
|
|
259
|
+
>
|
|
260
|
+
{ __( 'Done' ) }
|
|
261
|
+
</DoneButton>
|
|
262
|
+
) }
|
|
263
|
+
{ ! canOnlyChangeValues && (
|
|
264
|
+
<Button
|
|
265
|
+
isSmall
|
|
266
|
+
isPressed={ isAdding }
|
|
267
|
+
icon={ plus }
|
|
268
|
+
label={
|
|
269
|
+
isGradient
|
|
270
|
+
? __( 'Add gradient' )
|
|
271
|
+
: __( 'Add color' )
|
|
272
|
+
}
|
|
273
|
+
onClick={ () => {
|
|
274
|
+
const tempOptionName = sprintf(
|
|
275
|
+
/* translators: %s: is a temporary id for a custom color */
|
|
276
|
+
__( 'Color %s ' ),
|
|
277
|
+
elementsLength + 1
|
|
278
|
+
);
|
|
279
|
+
onChange( [
|
|
280
|
+
...elements,
|
|
281
|
+
{
|
|
282
|
+
...( isGradient
|
|
283
|
+
? { gradient: DEFAULT_GRADIENT }
|
|
284
|
+
: { color: '#000' } ),
|
|
285
|
+
name: tempOptionName,
|
|
286
|
+
slug: '',
|
|
287
|
+
},
|
|
288
|
+
] );
|
|
289
|
+
setIsEditing( true );
|
|
290
|
+
setEditingElement( elements.length );
|
|
291
|
+
} }
|
|
292
|
+
/>
|
|
293
|
+
) }
|
|
294
|
+
{ ! isEditing && (
|
|
295
|
+
<Button
|
|
296
|
+
disabled={ ! hasElements }
|
|
297
|
+
isSmall
|
|
298
|
+
icon={ moreVertical }
|
|
299
|
+
label={
|
|
300
|
+
isGradient
|
|
301
|
+
? __( 'Edit gradients' )
|
|
302
|
+
: __( 'Edit colors' )
|
|
303
|
+
}
|
|
304
|
+
onClick={ () => {
|
|
305
|
+
setIsEditing( true );
|
|
306
|
+
} }
|
|
307
|
+
/>
|
|
308
|
+
) }
|
|
309
|
+
{ isEditing && ( canReset || ! canOnlyChangeValues ) && (
|
|
310
|
+
<DropdownMenu
|
|
311
|
+
icon={ moreVertical }
|
|
312
|
+
label={
|
|
313
|
+
isGradient
|
|
314
|
+
? __( 'Gradient options' )
|
|
315
|
+
: __( 'Color options' )
|
|
316
|
+
}
|
|
317
|
+
toggleProps={ {
|
|
318
|
+
isSmall: true,
|
|
319
|
+
} }
|
|
320
|
+
>
|
|
321
|
+
{ ( { onClose } ) => (
|
|
322
|
+
<>
|
|
323
|
+
<NavigableMenu role="menu">
|
|
324
|
+
{ ! canOnlyChangeValues && (
|
|
325
|
+
<Button
|
|
326
|
+
variant="tertiary"
|
|
327
|
+
onClick={ () => {
|
|
328
|
+
setEditingElement( null );
|
|
329
|
+
setIsEditing( false );
|
|
330
|
+
onChange();
|
|
331
|
+
onClose();
|
|
332
|
+
} }
|
|
333
|
+
>
|
|
334
|
+
{ isGradient
|
|
335
|
+
? __(
|
|
336
|
+
'Remove all gradients'
|
|
337
|
+
)
|
|
338
|
+
: __(
|
|
339
|
+
'Remove all colors'
|
|
340
|
+
) }
|
|
341
|
+
</Button>
|
|
342
|
+
) }
|
|
343
|
+
{ canReset && (
|
|
344
|
+
<Button
|
|
345
|
+
variant="tertiary"
|
|
346
|
+
onClick={ () => {
|
|
347
|
+
setEditingElement( null );
|
|
348
|
+
onChange();
|
|
349
|
+
onClose();
|
|
350
|
+
} }
|
|
351
|
+
>
|
|
352
|
+
{ isGradient
|
|
353
|
+
? __( 'Reset gradient' )
|
|
354
|
+
: __( 'Reset colors' ) }
|
|
355
|
+
</Button>
|
|
356
|
+
) }
|
|
357
|
+
</NavigableMenu>
|
|
358
|
+
</>
|
|
359
|
+
) }
|
|
360
|
+
</DropdownMenu>
|
|
361
|
+
) }
|
|
362
|
+
</PaletteActionsContainer>
|
|
363
|
+
</PaletteHStackHeader>
|
|
364
|
+
{ hasElements && (
|
|
365
|
+
<>
|
|
366
|
+
{ isEditing && (
|
|
367
|
+
<PaletteEditListView
|
|
368
|
+
canOnlyChangeValues={ canOnlyChangeValues }
|
|
369
|
+
elements={ elements }
|
|
370
|
+
onChange={ onChange }
|
|
371
|
+
editingElement={ editingElement }
|
|
372
|
+
setEditingElement={ setEditingElement }
|
|
373
|
+
slugPrefix={ slugPrefix }
|
|
374
|
+
isGradient={ isGradient }
|
|
375
|
+
/>
|
|
376
|
+
) }
|
|
377
|
+
{ ! isEditing &&
|
|
378
|
+
( isGradient ? (
|
|
379
|
+
<GradientPicker
|
|
380
|
+
gradients={ gradients }
|
|
381
|
+
onChange={ () => {} }
|
|
382
|
+
clearable={ false }
|
|
383
|
+
disableCustomGradients={ true }
|
|
384
|
+
/>
|
|
385
|
+
) : (
|
|
386
|
+
<ColorPalette
|
|
387
|
+
colors={ colors }
|
|
388
|
+
onChange={ () => {} }
|
|
389
|
+
clearable={ false }
|
|
390
|
+
disableCustomColors={ true }
|
|
391
|
+
/>
|
|
392
|
+
) ) }
|
|
393
|
+
</>
|
|
394
|
+
) }
|
|
395
|
+
{ ! hasElements && emptyMessage }
|
|
396
|
+
</PaletteEditStyles>
|
|
397
|
+
);
|
|
398
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
@include break-medium() {
|
|
2
|
+
.components-palette-edit__popover.components-popover .components-popover__content.components-popover__content.components-popover__content {
|
|
3
|
+
margin-right: #{ math.div($sidebar-width, 2) + $grid-unit-20 };
|
|
4
|
+
margin-top: #{ -($grid-unit-60 + $border-width) };
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.components-palette-edit__popover {
|
|
9
|
+
.components-custom-gradient-picker__gradient-bar {
|
|
10
|
+
margin-top: 0;
|
|
11
|
+
}
|
|
12
|
+
.components-custom-gradient-picker__ui-line {
|
|
13
|
+
margin-bottom: 0;
|
|
14
|
+
}
|
|
15
|
+
.components-custom-gradient-picker {
|
|
16
|
+
width: 280px;
|
|
17
|
+
padding: 8px;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -12,7 +12,6 @@ import { HStack } from '../h-stack';
|
|
|
12
12
|
import { space } from '../ui/utils/space';
|
|
13
13
|
import { COLORS, CONFIG } from '../utils';
|
|
14
14
|
import { View } from '../view';
|
|
15
|
-
import ColorIndicator from '../color-indicator';
|
|
16
15
|
import InputControl from '../input-control';
|
|
17
16
|
import Item from '../item-group/item';
|
|
18
17
|
import {
|
|
@@ -20,20 +19,15 @@ import {
|
|
|
20
19
|
Input,
|
|
21
20
|
BackdropUI as InputBackdropUI,
|
|
22
21
|
} from '../input-control/styles/input-control-styles';
|
|
22
|
+
import CircularOptionPicker from '../circular-option-picker';
|
|
23
23
|
|
|
24
|
-
export const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
border: 0;
|
|
29
|
-
height: ${ space( 6 ) };
|
|
30
|
-
width: ${ space( 6 ) };
|
|
31
|
-
margin-left: 0;
|
|
32
|
-
padding: 0;
|
|
33
|
-
}
|
|
24
|
+
export const IndicatorStyled = styled( CircularOptionPicker.Option )`
|
|
25
|
+
width: ${ space( 6 ) };
|
|
26
|
+
height: ${ space( 6 ) };
|
|
27
|
+
pointer-events: none;
|
|
34
28
|
`;
|
|
35
29
|
|
|
36
|
-
export const
|
|
30
|
+
export const NameInputControl = styled( InputControl )`
|
|
37
31
|
${ InputControlContainer } {
|
|
38
32
|
background: ${ COLORS.gray[ 100 ] };
|
|
39
33
|
border-radius: 2px;
|
|
@@ -47,17 +41,20 @@ export const ColorNameInputControl = styled( InputControl )`
|
|
|
47
41
|
}
|
|
48
42
|
`;
|
|
49
43
|
|
|
50
|
-
export const
|
|
44
|
+
export const PaletteItem = styled( Item )`
|
|
51
45
|
padding: 3px 0 3px ${ space( 3 ) };
|
|
52
46
|
height: calc( 40px - ${ CONFIG.borderWidth } );
|
|
53
47
|
`;
|
|
54
48
|
|
|
55
|
-
export const
|
|
49
|
+
export const NameContainer = styled.div`
|
|
56
50
|
line-height: ${ space( 8 ) };
|
|
57
51
|
margin-left: ${ space( 2 ) };
|
|
52
|
+
margin-right: ${ space( 2 ) };
|
|
53
|
+
white-space: nowrap;
|
|
54
|
+
overflow: hidden;
|
|
58
55
|
`;
|
|
59
56
|
|
|
60
|
-
export const
|
|
57
|
+
export const PaletteHeading = styled( Heading )`
|
|
61
58
|
text-transform: uppercase;
|
|
62
59
|
line-height: ${ space( 6 ) };
|
|
63
60
|
font-weight: 500;
|
|
@@ -67,16 +64,16 @@ export const ColorHeading = styled( Heading )`
|
|
|
67
64
|
}
|
|
68
65
|
`;
|
|
69
66
|
|
|
70
|
-
export const
|
|
67
|
+
export const PaletteActionsContainer = styled( View )`
|
|
71
68
|
height: ${ space( 6 ) };
|
|
72
69
|
display: flex;
|
|
73
70
|
`;
|
|
74
71
|
|
|
75
|
-
export const
|
|
72
|
+
export const PaletteHStackHeader = styled( HStack )`
|
|
76
73
|
margin-bottom: ${ space( 2 ) };
|
|
77
74
|
`;
|
|
78
75
|
|
|
79
|
-
export const
|
|
76
|
+
export const PaletteEditStyles = styled( View )`
|
|
80
77
|
&&& {
|
|
81
78
|
.components-button.has-icon {
|
|
82
79
|
min-width: 0;
|
package/src/popover/index.js
CHANGED
|
@@ -131,7 +131,11 @@ function computeAnchorRect(
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
const { parentNode } = anchorRefFallback.current;
|
|
134
|
-
const rect =
|
|
134
|
+
const rect = offsetIframe(
|
|
135
|
+
parentNode.getBoundingClientRect(),
|
|
136
|
+
parentNode.ownerDocument,
|
|
137
|
+
container
|
|
138
|
+
);
|
|
135
139
|
|
|
136
140
|
if ( shouldAnchorIncludePadding ) {
|
|
137
141
|
return rect;
|
package/src/style.scss
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
@import "./button/style.scss";
|
|
5
5
|
@import "./checkbox-control/style.scss";
|
|
6
6
|
@import "./circular-option-picker/style.scss";
|
|
7
|
-
@import "./
|
|
7
|
+
@import "./palette-edit/style.scss";
|
|
8
8
|
@import "./color-indicator/style.scss";
|
|
9
9
|
@import "./combobox-control/style.scss";
|
|
10
10
|
@import "./color-list-picker/style.scss";
|
|
@@ -71,6 +71,11 @@ const _default = ( { options } ) => {
|
|
|
71
71
|
opt[ 'aria-label' ],
|
|
72
72
|
`${ KNOBS_GROUPS.ToggleGroupControlOption }-${ index + 1 }`
|
|
73
73
|
) }
|
|
74
|
+
showTooltip={ boolean(
|
|
75
|
+
`${ KNOBS_GROUPS.ToggleGroupControlOption }: showTooltip`,
|
|
76
|
+
opt.showTooltip,
|
|
77
|
+
`${ KNOBS_GROUPS.ToggleGroupControlOption }-${ index + 1 }`
|
|
78
|
+
) }
|
|
74
79
|
/>
|
|
75
80
|
) );
|
|
76
81
|
|
|
@@ -101,6 +106,16 @@ Default.args = {
|
|
|
101
106
|
],
|
|
102
107
|
};
|
|
103
108
|
|
|
109
|
+
export const WithTooltip = _default.bind( {} );
|
|
110
|
+
WithTooltip.args = {
|
|
111
|
+
...Default.args,
|
|
112
|
+
options: [
|
|
113
|
+
{ value: 1, label: '1', showTooltip: true, 'aria-label': 'One' },
|
|
114
|
+
{ value: 2, label: '2', showTooltip: true, 'aria-label': 'Two' },
|
|
115
|
+
{ value: 3, label: '3', showTooltip: true, 'aria-label': 'Three' },
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
|
|
104
119
|
export const WithAriaLabel = _default.bind( {} );
|
|
105
120
|
WithAriaLabel.args = {
|
|
106
121
|
...Default.args,
|