@wordpress/components 19.0.5 → 19.1.0
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 +10 -0
- package/build/circular-option-picker/index.js +2 -2
- package/build/circular-option-picker/index.js.map +1 -1
- package/build/date-time/time.js +17 -3
- package/build/date-time/time.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/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 +6 -3
- 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 +303 -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/circular-option-picker/index.js +2 -2
- package/build-module/circular-option-picker/index.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/font-size-picker/index.js +2 -1
- package/build-module/font-size-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 +7 -4
- 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 +276 -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 +12 -1
- package/build-style/style.css +12 -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/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/circular-option-picker/index.js +7 -5
- package/src/date-time/test/time.js +32 -2
- package/src/date-time/time.js +14 -6
- package/src/font-size-picker/index.js +1 -0
- package/src/index.js +1 -1
- package/src/mobile/global-styles-context/utils.native.js +2 -2
- package/src/navigation/item/index.js +10 -3
- package/src/navigation/stories/more-examples.js +2 -1
- package/src/navigation/styles/navigation-styles.js +5 -0
- package/src/palette-edit/index.js +392 -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 -271
- 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 -247
- 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 -329
- package/src/color-edit/style.scss +0 -6
|
@@ -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,
|
|
@@ -15,16 +15,35 @@ describe( 'ToggleGroupControl', () => {
|
|
|
15
15
|
<ToggleGroupControlOption value="jack" label="J" />
|
|
16
16
|
</>
|
|
17
17
|
);
|
|
18
|
+
const optionsWithTooltip = (
|
|
19
|
+
<>
|
|
20
|
+
<ToggleGroupControlOption
|
|
21
|
+
value="gnocchi"
|
|
22
|
+
label="Delicious Gnocchi"
|
|
23
|
+
aria-label="Click for Delicious Gnocchi"
|
|
24
|
+
showTooltip={ true }
|
|
25
|
+
/>
|
|
26
|
+
<ToggleGroupControlOption
|
|
27
|
+
value="caponata"
|
|
28
|
+
label="Sumptuous Caponata"
|
|
29
|
+
aria-label="Click for Sumptuous Caponata"
|
|
30
|
+
/>
|
|
31
|
+
</>
|
|
32
|
+
);
|
|
33
|
+
|
|
18
34
|
it( 'should render correctly', () => {
|
|
19
35
|
const { container } = render(
|
|
20
36
|
<ToggleGroupControl label="Test Toggle Group Control">
|
|
21
37
|
{ options }
|
|
22
38
|
</ToggleGroupControl>
|
|
23
39
|
);
|
|
40
|
+
|
|
24
41
|
expect( container.firstChild ).toMatchSnapshot();
|
|
25
42
|
} );
|
|
43
|
+
|
|
26
44
|
it( 'should call onChange with proper value', () => {
|
|
27
45
|
const mockOnChange = jest.fn();
|
|
46
|
+
|
|
28
47
|
render(
|
|
29
48
|
<ToggleGroupControl
|
|
30
49
|
value="jack"
|
|
@@ -34,8 +53,46 @@ describe( 'ToggleGroupControl', () => {
|
|
|
34
53
|
{ options }
|
|
35
54
|
</ToggleGroupControl>
|
|
36
55
|
);
|
|
56
|
+
|
|
37
57
|
const firstRadio = screen.getByRole( 'radio', { name: 'R' } );
|
|
58
|
+
|
|
38
59
|
fireEvent.click( firstRadio );
|
|
60
|
+
|
|
39
61
|
expect( mockOnChange ).toHaveBeenCalledWith( 'rigas' );
|
|
40
62
|
} );
|
|
63
|
+
it( 'should render tooltip where `showTooltip` === `true`', () => {
|
|
64
|
+
render(
|
|
65
|
+
<ToggleGroupControl label="Test Toggle Group Control">
|
|
66
|
+
{ optionsWithTooltip }
|
|
67
|
+
</ToggleGroupControl>
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const firstRadio = screen.getByLabelText(
|
|
71
|
+
'Click for Delicious Gnocchi'
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
fireEvent.focus( firstRadio );
|
|
75
|
+
|
|
76
|
+
expect(
|
|
77
|
+
screen.getByText( 'Click for Delicious Gnocchi' )
|
|
78
|
+
).toBeInTheDocument();
|
|
79
|
+
} );
|
|
80
|
+
|
|
81
|
+
it( 'should not render tooltip', () => {
|
|
82
|
+
render(
|
|
83
|
+
<ToggleGroupControl label="Test Toggle Group Control">
|
|
84
|
+
{ optionsWithTooltip }
|
|
85
|
+
</ToggleGroupControl>
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const secondRadio = screen.getByLabelText(
|
|
89
|
+
'Click for Sumptuous Caponata'
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
fireEvent.focus( secondRadio );
|
|
93
|
+
|
|
94
|
+
expect(
|
|
95
|
+
screen.queryByText( 'Click for Sumptuous Caponata' )
|
|
96
|
+
).not.toBeInTheDocument();
|
|
97
|
+
} );
|
|
41
98
|
} );
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
function Example() {
|
|
19
19
|
return (
|
|
20
20
|
<ToggleGroupControl label="my label" value="vertical" isBlock>
|
|
21
|
-
<ToggleGroupControlOption value="horizontal" label="Horizontal" />
|
|
21
|
+
<ToggleGroupControlOption value="horizontal" label="Horizontal" showTooltip={ true } />
|
|
22
22
|
<ToggleGroupControlOption value="vertical" label="Vertical" />
|
|
23
23
|
</ToggleGroupControl>
|
|
24
24
|
);
|
|
@@ -38,3 +38,10 @@ Label for the option. If needed, the `aria-label` prop can be used in addition t
|
|
|
38
38
|
The value of the `ToggleGroupControlOption`.
|
|
39
39
|
|
|
40
40
|
- Required: Yes
|
|
41
|
+
|
|
42
|
+
### `showTooltip`: `boolean`
|
|
43
|
+
|
|
44
|
+
Whether to show a tooltip when hovering over the option. The tooltip will attempt to use the `aria-label` prop text first, then the `label` prop text if no `aria-label` prop is found.
|
|
45
|
+
|
|
46
|
+
- Required: No
|
|
47
|
+
|
|
@@ -9,7 +9,6 @@ import { Radio } from 'reakit';
|
|
|
9
9
|
/**
|
|
10
10
|
* WordPress dependencies
|
|
11
11
|
*/
|
|
12
|
-
import { __ } from '@wordpress/i18n';
|
|
13
12
|
import { useInstanceId } from '@wordpress/compose';
|
|
14
13
|
|
|
15
14
|
/**
|
|
@@ -20,13 +19,25 @@ import {
|
|
|
20
19
|
useContextSystem,
|
|
21
20
|
WordPressComponentProps,
|
|
22
21
|
} from '../../ui/context';
|
|
23
|
-
import type { ToggleGroupControlOptionProps } from '../types';
|
|
22
|
+
import type { ToggleGroupControlOptionProps, WithToolTipProps } from '../types';
|
|
24
23
|
import { useToggleGroupControlContext } from '../context';
|
|
25
24
|
import * as styles from './styles';
|
|
26
25
|
import { useCx } from '../../utils/hooks';
|
|
26
|
+
import Tooltip from '../../tooltip';
|
|
27
27
|
|
|
28
28
|
const { ButtonContentView, LabelPlaceholderView, LabelView } = styles;
|
|
29
29
|
|
|
30
|
+
const WithToolTip = ( { showTooltip, text, children }: WithToolTipProps ) => {
|
|
31
|
+
if ( showTooltip && text ) {
|
|
32
|
+
return (
|
|
33
|
+
<Tooltip text={ text } position="top center">
|
|
34
|
+
{ children }
|
|
35
|
+
</Tooltip>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return <>{ children }</>;
|
|
39
|
+
};
|
|
40
|
+
|
|
30
41
|
function ToggleGroupControlOption(
|
|
31
42
|
props: WordPressComponentProps< ToggleGroupControlOptionProps, 'button' >,
|
|
32
43
|
forwardedRef: Ref< any >
|
|
@@ -41,7 +52,14 @@ function ToggleGroupControlOption(
|
|
|
41
52
|
'ToggleGroupControlOption'
|
|
42
53
|
);
|
|
43
54
|
|
|
44
|
-
const {
|
|
55
|
+
const {
|
|
56
|
+
className,
|
|
57
|
+
isBlock = false,
|
|
58
|
+
label,
|
|
59
|
+
value,
|
|
60
|
+
showTooltip = false,
|
|
61
|
+
...radioProps
|
|
62
|
+
} = {
|
|
45
63
|
...toggleGroupControlContext,
|
|
46
64
|
...buttonProps,
|
|
47
65
|
};
|
|
@@ -54,23 +72,28 @@ function ToggleGroupControlOption(
|
|
|
54
72
|
className,
|
|
55
73
|
isActive && styles.buttonActive
|
|
56
74
|
);
|
|
75
|
+
const optionLabel = !! radioProps[ 'aria-label' ]
|
|
76
|
+
? radioProps[ 'aria-label' ]
|
|
77
|
+
: label;
|
|
57
78
|
|
|
58
79
|
return (
|
|
59
80
|
<LabelView className={ labelViewClasses } data-active={ isActive }>
|
|
60
|
-
<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
81
|
+
<WithToolTip showTooltip={ showTooltip } text={ optionLabel }>
|
|
82
|
+
<Radio
|
|
83
|
+
{ ...radioProps }
|
|
84
|
+
as="button"
|
|
85
|
+
aria-label={ optionLabel }
|
|
86
|
+
className={ classes }
|
|
87
|
+
data-value={ value }
|
|
88
|
+
ref={ forwardedRef }
|
|
89
|
+
value={ value }
|
|
90
|
+
>
|
|
91
|
+
<ButtonContentView>{ label }</ButtonContentView>
|
|
92
|
+
<LabelPlaceholderView aria-hidden>
|
|
93
|
+
{ label }
|
|
94
|
+
</LabelPlaceholderView>
|
|
95
|
+
</Radio>
|
|
96
|
+
</WithToolTip>
|
|
74
97
|
</LabelView>
|
|
75
98
|
);
|
|
76
99
|
}
|
|
@@ -18,6 +18,30 @@ export type ToggleGroupControlOptionProps = {
|
|
|
18
18
|
* to specify a different label for assistive technologies.
|
|
19
19
|
*/
|
|
20
20
|
label: string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether to display a Tooltip for the control option. If set to `true`, the tooltip will
|
|
23
|
+
* show the aria-label or the label prop text.
|
|
24
|
+
*
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
showTooltip?: boolean;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type WithToolTipProps = {
|
|
31
|
+
/**
|
|
32
|
+
* React children
|
|
33
|
+
*/
|
|
34
|
+
children: ReactNode;
|
|
35
|
+
/**
|
|
36
|
+
* Label for the Tooltip component.
|
|
37
|
+
*/
|
|
38
|
+
text: string;
|
|
39
|
+
/**
|
|
40
|
+
* Whether to wrap the control option in a Tooltip component.
|
|
41
|
+
*
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
showTooltip?: boolean;
|
|
21
45
|
};
|
|
22
46
|
|
|
23
47
|
export type ToggleGroupControlProps = Omit<
|
package/src/tooltip/index.js
CHANGED
|
@@ -92,13 +92,8 @@ const emitToChild = ( children, eventName, event ) => {
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
function Tooltip( {
|
|
96
|
-
children,
|
|
97
|
-
position,
|
|
98
|
-
text,
|
|
99
|
-
shortcut,
|
|
100
|
-
delay = TOOLTIP_DELAY,
|
|
101
|
-
} ) {
|
|
95
|
+
function Tooltip( props ) {
|
|
96
|
+
const { children, position, text, shortcut, delay = TOOLTIP_DELAY } = props;
|
|
102
97
|
/**
|
|
103
98
|
* Whether a mouse is currently pressed, used in determining whether
|
|
104
99
|
* to handle a focus event as displaying the tooltip immediately.
|