@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.
Files changed (103) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/build/circular-option-picker/index.js +2 -2
  3. package/build/circular-option-picker/index.js.map +1 -1
  4. package/build/date-time/time.js +17 -3
  5. package/build/date-time/time.js.map +1 -1
  6. package/build/font-size-picker/index.js +2 -1
  7. package/build/font-size-picker/index.js.map +1 -1
  8. package/build/index.js +7 -7
  9. package/build/index.js.map +1 -1
  10. package/build/mobile/global-styles-context/utils.native.js +2 -2
  11. package/build/mobile/global-styles-context/utils.native.js.map +1 -1
  12. package/build/navigation/item/index.js +6 -3
  13. package/build/navigation/item/index.js.map +1 -1
  14. package/build/navigation/styles/navigation-styles.js +37 -30
  15. package/build/navigation/styles/navigation-styles.js.map +1 -1
  16. package/build/palette-edit/index.js +303 -0
  17. package/build/palette-edit/index.js.map +1 -0
  18. package/build/palette-edit/styles.js +112 -0
  19. package/build/palette-edit/styles.js.map +1 -0
  20. package/build/popover/index.js +1 -1
  21. package/build/popover/index.js.map +1 -1
  22. package/build/toggle-group-control/toggle-group-control-option/component.js +30 -4
  23. package/build/toggle-group-control/toggle-group-control-option/component.js.map +1 -1
  24. package/build/tooltip/index.js +4 -4
  25. package/build/tooltip/index.js.map +1 -1
  26. package/build-module/circular-option-picker/index.js +2 -2
  27. package/build-module/circular-option-picker/index.js.map +1 -1
  28. package/build-module/date-time/time.js +17 -3
  29. package/build-module/date-time/time.js.map +1 -1
  30. package/build-module/font-size-picker/index.js +2 -1
  31. package/build-module/font-size-picker/index.js.map +1 -1
  32. package/build-module/index.js +1 -1
  33. package/build-module/index.js.map +1 -1
  34. package/build-module/mobile/global-styles-context/utils.native.js +2 -2
  35. package/build-module/mobile/global-styles-context/utils.native.js.map +1 -1
  36. package/build-module/navigation/item/index.js +7 -4
  37. package/build-module/navigation/item/index.js.map +1 -1
  38. package/build-module/navigation/styles/navigation-styles.js +34 -28
  39. package/build-module/navigation/styles/navigation-styles.js.map +1 -1
  40. package/build-module/palette-edit/index.js +276 -0
  41. package/build-module/palette-edit/index.js.map +1 -0
  42. package/build-module/palette-edit/styles.js +90 -0
  43. package/build-module/palette-edit/styles.js.map +1 -0
  44. package/build-module/popover/index.js +1 -1
  45. package/build-module/popover/index.js.map +1 -1
  46. package/build-module/toggle-group-control/toggle-group-control-option/component.js +26 -5
  47. package/build-module/toggle-group-control/toggle-group-control-option/component.js.map +1 -1
  48. package/build-module/tooltip/index.js +4 -4
  49. package/build-module/tooltip/index.js.map +1 -1
  50. package/build-style/style-rtl.css +12 -1
  51. package/build-style/style.css +12 -1
  52. package/build-types/confirm-dialog/component.d.ts +34 -0
  53. package/build-types/confirm-dialog/component.d.ts.map +1 -0
  54. package/build-types/confirm-dialog/index.d.ts +6 -0
  55. package/build-types/confirm-dialog/index.d.ts.map +1 -0
  56. package/build-types/confirm-dialog/types.d.ts +20 -0
  57. package/build-types/confirm-dialog/types.d.ts.map +1 -0
  58. package/build-types/higher-order/with-focus-outside/index.d.ts +3 -0
  59. package/build-types/higher-order/with-focus-outside/index.d.ts.map +1 -0
  60. package/build-types/modal/aria-helper.d.ts +27 -0
  61. package/build-types/modal/aria-helper.d.ts.map +1 -0
  62. package/build-types/modal/index.d.ts +3 -0
  63. package/build-types/modal/index.d.ts.map +1 -0
  64. package/build-types/popover/index.d.ts.map +1 -1
  65. package/build-types/style-provider/index.d.ts +5 -0
  66. package/build-types/style-provider/index.d.ts.map +1 -0
  67. package/build-types/toggle-group-control/toggle-group-control-option/component.d.ts.map +1 -1
  68. package/build-types/toggle-group-control/types.d.ts +23 -0
  69. package/build-types/toggle-group-control/types.d.ts.map +1 -1
  70. package/build-types/tooltip/index.d.ts +1 -7
  71. package/build-types/tooltip/index.d.ts.map +1 -1
  72. package/package.json +2 -2
  73. package/src/circular-option-picker/index.js +7 -5
  74. package/src/date-time/test/time.js +32 -2
  75. package/src/date-time/time.js +14 -6
  76. package/src/font-size-picker/index.js +1 -0
  77. package/src/index.js +1 -1
  78. package/src/mobile/global-styles-context/utils.native.js +2 -2
  79. package/src/navigation/item/index.js +10 -3
  80. package/src/navigation/stories/more-examples.js +2 -1
  81. package/src/navigation/styles/navigation-styles.js +5 -0
  82. package/src/palette-edit/index.js +392 -0
  83. package/src/palette-edit/style.scss +19 -0
  84. package/src/{color-edit → palette-edit}/styles.js +15 -18
  85. package/src/popover/index.js +5 -1
  86. package/src/style.scss +1 -1
  87. package/src/toggle-group-control/stories/index.js +15 -0
  88. package/src/toggle-group-control/test/index.js +57 -0
  89. package/src/toggle-group-control/toggle-group-control-option/README.md +8 -1
  90. package/src/toggle-group-control/toggle-group-control-option/component.tsx +40 -17
  91. package/src/toggle-group-control/types.ts +24 -0
  92. package/src/tooltip/index.js +2 -7
  93. package/tsconfig.tsbuildinfo +1 -1
  94. package/build/color-edit/index.js +0 -271
  95. package/build/color-edit/index.js.map +0 -1
  96. package/build/color-edit/styles.js +0 -112
  97. package/build/color-edit/styles.js.map +0 -1
  98. package/build-module/color-edit/index.js +0 -247
  99. package/build-module/color-edit/index.js.map +0 -1
  100. package/build-module/color-edit/styles.js +0 -90
  101. package/build-module/color-edit/styles.js.map +0 -1
  102. package/src/color-edit/index.js +0 -329
  103. 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 ColorIndicatorStyled = styled( ColorIndicator )`
25
- && {
26
- display: block;
27
- border-radius: 50%;
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 ColorNameInputControl = styled( InputControl )`
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 ColorItem = styled( Item )`
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 ColorNameContainer = styled.span`
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 ColorHeading = styled( Heading )`
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 ColorActionsContainer = styled( View )`
67
+ export const PaletteActionsContainer = styled( View )`
71
68
  height: ${ space( 6 ) };
72
69
  display: flex;
73
70
  `;
74
71
 
75
- export const ColorHStackHeader = styled( HStack )`
72
+ export const PaletteHStackHeader = styled( HStack )`
76
73
  margin-bottom: ${ space( 2 ) };
77
74
  `;
78
75
 
79
- export const ColorEditStyles = styled( View )`
76
+ export const PaletteEditStyles = styled( View )`
80
77
  &&& {
81
78
  .components-button.has-icon {
82
79
  min-width: 0;
@@ -131,7 +131,11 @@ function computeAnchorRect(
131
131
  }
132
132
 
133
133
  const { parentNode } = anchorRefFallback.current;
134
- const rect = parentNode.getBoundingClientRect();
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 "./color-edit/style.scss";
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 { className, isBlock = false, label, value, ...radioProps } = {
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
- <Radio
61
- { ...radioProps }
62
- as="button"
63
- aria-label={ radioProps[ 'aria-label' ] ?? label }
64
- className={ classes }
65
- data-value={ value }
66
- ref={ forwardedRef }
67
- value={ value }
68
- >
69
- <ButtonContentView>{ label }</ButtonContentView>
70
- <LabelPlaceholderView aria-hidden>
71
- { label }
72
- </LabelPlaceholderView>
73
- </Radio>
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<
@@ -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.