@wordpress/components 25.3.0 → 25.4.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 (74) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/build/button/index.native.js +9 -6
  3. package/build/button/index.native.js.map +1 -1
  4. package/build/form-token-field/styles.js +4 -2
  5. package/build/form-token-field/styles.js.map +1 -1
  6. package/build/item-group/item/hook.js +1 -1
  7. package/build/item-group/item/hook.js.map +1 -1
  8. package/build/item-group/styles.js +13 -10
  9. package/build/item-group/styles.js.map +1 -1
  10. package/build/mobile/image/index.native.js +4 -3
  11. package/build/mobile/image/index.native.js.map +1 -1
  12. package/build/navigator/navigator-provider/component.js +18 -10
  13. package/build/navigator/navigator-provider/component.js.map +1 -1
  14. package/build/query-controls/index.js +1 -0
  15. package/build/query-controls/index.js.map +1 -1
  16. package/build/query-controls/index.native.js +1 -0
  17. package/build/query-controls/index.native.js.map +1 -1
  18. package/build/text-control/index.js +2 -2
  19. package/build/text-control/index.js.map +1 -1
  20. package/build/toolbar/toolbar-group/toolbar-group-container.native.js +10 -7
  21. package/build/toolbar/toolbar-group/toolbar-group-container.native.js.map +1 -1
  22. package/build-module/button/index.native.js +8 -6
  23. package/build-module/button/index.native.js.map +1 -1
  24. package/build-module/form-token-field/styles.js +3 -2
  25. package/build-module/form-token-field/styles.js.map +1 -1
  26. package/build-module/item-group/item/hook.js +1 -1
  27. package/build-module/item-group/item/hook.js.map +1 -1
  28. package/build-module/item-group/styles.js +13 -11
  29. package/build-module/item-group/styles.js.map +1 -1
  30. package/build-module/mobile/image/index.native.js +4 -3
  31. package/build-module/mobile/image/index.native.js.map +1 -1
  32. package/build-module/navigator/navigator-provider/component.js +18 -10
  33. package/build-module/navigator/navigator-provider/component.js.map +1 -1
  34. package/build-module/query-controls/index.js +1 -0
  35. package/build-module/query-controls/index.js.map +1 -1
  36. package/build-module/query-controls/index.native.js +1 -0
  37. package/build-module/query-controls/index.native.js.map +1 -1
  38. package/build-module/text-control/index.js +2 -2
  39. package/build-module/text-control/index.js.map +1 -1
  40. package/build-module/toolbar/toolbar-group/toolbar-group-container.native.js +11 -7
  41. package/build-module/toolbar/toolbar-group/toolbar-group-container.native.js.map +1 -1
  42. package/build-style/style-rtl.css +3 -0
  43. package/build-style/style.css +3 -0
  44. package/build-types/form-token-field/styles.d.ts.map +1 -1
  45. package/build-types/item-group/item/hook.d.ts.map +1 -1
  46. package/build-types/item-group/stories/index.d.ts.map +1 -1
  47. package/build-types/item-group/styles.d.ts +1 -1
  48. package/build-types/item-group/styles.d.ts.map +1 -1
  49. package/build-types/navigator/navigator-provider/component.d.ts.map +1 -1
  50. package/build-types/navigator/types.d.ts +3 -1
  51. package/build-types/navigator/types.d.ts.map +1 -1
  52. package/build-types/query-controls/index.d.ts.map +1 -1
  53. package/build-types/text-control/test/text-control.d.ts +2 -0
  54. package/build-types/text-control/test/text-control.d.ts.map +1 -0
  55. package/package.json +21 -21
  56. package/src/button/index.native.js +9 -3
  57. package/src/button/style.native.scss +9 -0
  58. package/src/form-token-field/styles.ts +2 -0
  59. package/src/item-group/item/hook.ts +2 -1
  60. package/src/item-group/stories/index.tsx +8 -3
  61. package/src/item-group/styles.ts +39 -28
  62. package/src/mobile/image/index.native.js +8 -6
  63. package/src/mobile/image/style.native.scss +5 -1
  64. package/src/navigator/navigator-provider/component.tsx +30 -23
  65. package/src/navigator/types.ts +4 -1
  66. package/src/placeholder/style.scss +5 -0
  67. package/src/query-controls/index.native.js +1 -0
  68. package/src/query-controls/index.tsx +1 -0
  69. package/src/text-control/index.tsx +2 -2
  70. package/src/text-control/test/text-control.tsx +61 -0
  71. package/src/toolbar/toolbar-group/style.native.scss +2 -3
  72. package/src/toolbar/toolbar-group/toolbar-group-container.native.js +12 -17
  73. package/src/tooltip/README.md +1 -1
  74. package/tsconfig.tsbuildinfo +1 -1
@@ -148,6 +148,7 @@ function UnconnectedNavigatorProvider(
148
148
  focusTargetSelector,
149
149
  isBack = false,
150
150
  skipFocus = false,
151
+ replace = false,
151
152
  ...restOptions
152
153
  } = options;
153
154
 
@@ -172,34 +173,38 @@ function UnconnectedNavigatorProvider(
172
173
  skipFocus,
173
174
  };
174
175
 
175
- if ( prevLocationHistory.length < 1 ) {
176
- return [ newLocation ];
176
+ if ( prevLocationHistory.length === 0 ) {
177
+ return replace ? [] : [ newLocation ];
177
178
  }
178
179
 
179
- return [
180
- ...prevLocationHistory.slice(
181
- prevLocationHistory.length > MAX_HISTORY_LENGTH - 1
182
- ? 1
183
- : 0,
184
- -1
185
- ),
186
- // Assign `focusTargetSelector` to the previous location in history
187
- // (the one we just navigated from).
188
- {
189
- ...prevLocationHistory[
190
- prevLocationHistory.length - 1
191
- ],
192
- focusTargetSelector,
193
- },
194
- newLocation,
195
- ];
180
+ const newLocationHistory = prevLocationHistory.slice(
181
+ prevLocationHistory.length > MAX_HISTORY_LENGTH - 1 ? 1 : 0,
182
+ -1
183
+ );
184
+
185
+ if ( ! replace ) {
186
+ newLocationHistory.push(
187
+ // Assign `focusTargetSelector` to the previous location in history
188
+ // (the one we just navigated from).
189
+ {
190
+ ...prevLocationHistory[
191
+ prevLocationHistory.length - 1
192
+ ],
193
+ focusTargetSelector,
194
+ }
195
+ );
196
+ }
197
+
198
+ newLocationHistory.push( newLocation );
199
+
200
+ return newLocationHistory;
196
201
  } );
197
202
  },
198
203
  [ goBack ]
199
204
  );
200
205
 
201
- const goToParent: NavigatorContextType[ 'goToParent' ] =
202
- useCallback( () => {
206
+ const goToParent: NavigatorContextType[ 'goToParent' ] = useCallback(
207
+ ( options = {} ) => {
203
208
  const currentPath =
204
209
  currentLocationHistory.current[
205
210
  currentLocationHistory.current.length - 1
@@ -214,8 +219,10 @@ function UnconnectedNavigatorProvider(
214
219
  if ( parentPath === undefined ) {
215
220
  return;
216
221
  }
217
- goTo( parentPath, { isBack: true } );
218
- }, [ goTo ] );
222
+ goTo( parentPath, { ...options, isBack: true } );
223
+ },
224
+ [ goTo ]
225
+ );
219
226
 
220
227
  const navigatorContextValue: NavigatorContextType = useMemo(
221
228
  () => ( {
@@ -14,8 +14,11 @@ export type NavigateOptions = {
14
14
  focusTargetSelector?: string;
15
15
  isBack?: boolean;
16
16
  skipFocus?: boolean;
17
+ replace?: boolean;
17
18
  };
18
19
 
20
+ export type NavigateToParentOptions = Omit< NavigateOptions, 'isBack' >;
21
+
19
22
  export type NavigatorLocation = NavigateOptions & {
20
23
  isInitial?: boolean;
21
24
  path?: string;
@@ -28,7 +31,7 @@ export type Navigator = {
28
31
  params: MatchParams;
29
32
  goTo: ( path: string, options?: NavigateOptions ) => void;
30
33
  goBack: () => void;
31
- goToParent: () => void;
34
+ goToParent: ( options?: NavigateToParentOptions ) => void;
32
35
  };
33
36
 
34
37
  export type NavigatorContext = Navigator & {
@@ -161,6 +161,11 @@
161
161
  padding: 0 $grid-unit-10 2px;
162
162
  }
163
163
  }
164
+ .components-placeholder__learn-more {
165
+ .components-external-link {
166
+ color: var(--wp-admin-theme-color);
167
+ }
168
+ }
164
169
  }
165
170
 
166
171
 
@@ -84,6 +84,7 @@ const QueryControls = memo(
84
84
  ) }
85
85
  { onNumberOfItemsChange && (
86
86
  <RangeControl
87
+ __next40pxDefaultSize
87
88
  label={ __( 'Number of items' ) }
88
89
  value={ numberOfItems }
89
90
  onChange={ onNumberOfItemsChange }
@@ -177,6 +177,7 @@ export function QueryControls( {
177
177
  onNumberOfItemsChange && (
178
178
  <RangeControl
179
179
  __nextHasNoMarginBottom
180
+ __next40pxDefaultSize
180
181
  key="query-controls-range-control"
181
182
  label={ __( 'Number of items' ) }
182
183
  value={ numberOfItems }
@@ -26,13 +26,13 @@ function UnforwardedTextControl(
26
26
  hideLabelFromVision,
27
27
  value,
28
28
  help,
29
+ id: idProp,
29
30
  className,
30
31
  onChange,
31
32
  type = 'text',
32
33
  ...additionalProps
33
34
  } = props;
34
- const instanceId = useInstanceId( TextControl );
35
- const id = `inspector-text-control-${ instanceId }`;
35
+ const id = useInstanceId( TextControl, 'inspector-text-control', idProp );
36
36
  const onChangeValue = ( event: ChangeEvent< HTMLInputElement > ) =>
37
37
  onChange( event.target.value );
38
38
 
@@ -0,0 +1,61 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { render, screen } from '@testing-library/react';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import TextControl from '..';
10
+
11
+ const noop = () => {};
12
+
13
+ describe( 'TextControl', () => {
14
+ describe( 'When no ID prop is provided', () => {
15
+ it( 'should generate an ID', () => {
16
+ render( <TextControl onChange={ noop } value="" /> );
17
+
18
+ expect( screen.getByRole( 'textbox' ) ).toHaveAttribute(
19
+ 'id',
20
+ expect.stringMatching( /^inspector-text-control-/ )
21
+ );
22
+ } );
23
+
24
+ it( 'should be labelled correctly', () => {
25
+ const labelValue = 'Test Label';
26
+ render(
27
+ <TextControl label={ labelValue } onChange={ noop } value="" />
28
+ );
29
+
30
+ expect(
31
+ screen.getByRole( 'textbox', { name: labelValue } )
32
+ ).toBeVisible();
33
+ } );
34
+ } );
35
+
36
+ describe( 'When an ID prop is provided', () => {
37
+ const id = 'test-id';
38
+
39
+ it( 'should use the passed ID prop if provided', () => {
40
+ render( <TextControl id={ id } onChange={ noop } value="" /> );
41
+
42
+ expect( screen.getByRole( 'textbox' ) ).toHaveAttribute( 'id', id );
43
+ } );
44
+
45
+ it( 'should be labelled correctly', () => {
46
+ const labelValue = 'Test Label';
47
+ render(
48
+ <TextControl
49
+ label={ labelValue }
50
+ id={ id }
51
+ onChange={ noop }
52
+ value=""
53
+ />
54
+ );
55
+
56
+ expect(
57
+ screen.getByRole( 'textbox', { name: labelValue } )
58
+ ).toBeVisible();
59
+ } );
60
+ } );
61
+ } );
@@ -1,11 +1,10 @@
1
1
  .container {
2
2
  flex-direction: row;
3
- border-left-width: 1px;
4
- border-color: #e9eff3;
3
+ border-color: $light-quaternary;
5
4
  padding-left: 5px;
6
5
  padding-right: 5px;
7
6
  }
8
7
 
9
8
  .containerDark {
10
- border-color: #525354;
9
+ border-color: $dark-quaternary;
11
10
  }
@@ -1,31 +1,26 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { View } from 'react-native';
4
+ import { StyleSheet, View } from 'react-native';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { withPreferredColorScheme } from '@wordpress/compose';
9
+ import { usePreferredColorSchemeStyle } from '@wordpress/compose';
10
10
 
11
11
  /**
12
12
  * Internal dependencies
13
13
  */
14
14
  import styles from './style.scss';
15
15
 
16
- const ToolbarGroupContainer = ( {
17
- getStylesFromColorScheme,
18
- passedStyle,
19
- children,
20
- } ) => (
21
- <View
22
- style={ [
23
- getStylesFromColorScheme( styles.container, styles.containerDark ),
24
- passedStyle,
25
- ] }
26
- >
27
- { children }
28
- </View>
29
- );
16
+ const ToolbarGroupContainer = ( { passedStyle, children } ) => {
17
+ const groupStyles = [
18
+ usePreferredColorSchemeStyle( styles.container, styles.containerDark ),
19
+ { borderLeftWidth: StyleSheet.hairlineWidth },
20
+ passedStyle,
21
+ ];
30
22
 
31
- export default withPreferredColorScheme( ToolbarGroupContainer );
23
+ return <View style={ groupStyles }>{ children }</View>;
24
+ };
25
+
26
+ export default ToolbarGroupContainer;
@@ -28,7 +28,7 @@ The direction in which the tooltip should open relative to its parent node. Spec
28
28
 
29
29
  - Type: `String`
30
30
  - Required: No
31
- - Default: `"top center"`
31
+ - Default: `"bottom"`
32
32
 
33
33
  ### children
34
34