@wordpress/components 29.7.0 → 29.9.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 (63) hide show
  1. package/.stylelintrc.js +1 -1
  2. package/CHANGELOG.md +37 -0
  3. package/build/guide/index.js +4 -2
  4. package/build/guide/index.js.map +1 -1
  5. package/build/guide/types.js.map +1 -1
  6. package/build/item-group/styles.js +10 -10
  7. package/build/item-group/styles.js.map +1 -1
  8. package/build/popover/index.js +38 -18
  9. package/build/popover/index.js.map +1 -1
  10. package/build/popover/types.js.map +1 -1
  11. package/build/toggle-group-control/toggle-group-control/component.js +1 -1
  12. package/build/toggle-group-control/toggle-group-control/component.js.map +1 -1
  13. package/build/unit-control/utils.js +9 -8
  14. package/build/unit-control/utils.js.map +1 -1
  15. package/build-module/guide/index.js +4 -2
  16. package/build-module/guide/index.js.map +1 -1
  17. package/build-module/guide/types.js.map +1 -1
  18. package/build-module/item-group/styles.js +10 -10
  19. package/build-module/item-group/styles.js.map +1 -1
  20. package/build-module/popover/index.js +37 -17
  21. package/build-module/popover/index.js.map +1 -1
  22. package/build-module/popover/types.js.map +1 -1
  23. package/build-module/toggle-group-control/toggle-group-control/component.js +1 -1
  24. package/build-module/toggle-group-control/toggle-group-control/component.js.map +1 -1
  25. package/build-module/unit-control/utils.js +9 -8
  26. package/build-module/unit-control/utils.js.map +1 -1
  27. package/build-style/style-rtl.css +17 -12
  28. package/build-style/style.css +17 -12
  29. package/build-types/guide/index.d.ts +1 -1
  30. package/build-types/guide/index.d.ts.map +1 -1
  31. package/build-types/guide/stories/index.story.d.ts.map +1 -1
  32. package/build-types/guide/types.d.ts +12 -0
  33. package/build-types/guide/types.d.ts.map +1 -1
  34. package/build-types/popover/index.d.ts +18 -2
  35. package/build-types/popover/index.d.ts.map +1 -1
  36. package/build-types/popover/stories/e2e/index.story.d.ts +8 -1
  37. package/build-types/popover/stories/e2e/index.story.d.ts.map +1 -1
  38. package/build-types/popover/stories/index.story.d.ts +1 -0
  39. package/build-types/popover/stories/index.story.d.ts.map +1 -1
  40. package/build-types/popover/test/utils/index.d.ts.map +1 -1
  41. package/build-types/popover/types.d.ts +9 -0
  42. package/build-types/popover/types.d.ts.map +1 -1
  43. package/build-types/unit-control/utils.d.ts.map +1 -1
  44. package/package.json +20 -20
  45. package/src/button/style.scss +1 -1
  46. package/src/color-picker/test/index.tsx +103 -26
  47. package/src/combobox-control/style.scss +4 -2
  48. package/src/duotone-picker/style.scss +4 -0
  49. package/src/form-token-field/style.scss +5 -5
  50. package/src/guide/README.md +16 -0
  51. package/src/guide/index.tsx +4 -2
  52. package/src/guide/stories/index.story.tsx +2 -0
  53. package/src/guide/types.ts +12 -0
  54. package/src/item-group/styles.ts +1 -1
  55. package/src/item-group/test/__snapshots__/index.js.snap +1 -1
  56. package/src/popover/index.tsx +46 -21
  57. package/src/popover/stories/index.story.tsx +83 -2
  58. package/src/popover/test/utils/index.tsx +0 -1
  59. package/src/popover/types.ts +10 -0
  60. package/src/toggle-group-control/toggle-group-control/component.tsx +1 -1
  61. package/src/unit-control/test/utils.ts +36 -0
  62. package/src/unit-control/utils.ts +8 -11
  63. package/tsconfig.tsbuildinfo +1 -1
@@ -42,6 +42,42 @@ describe( 'UnitControl utils', () => {
42
42
  ] );
43
43
  } );
44
44
 
45
+ it( 'should not mutate default units argument definiton', () => {
46
+ const unitsA = useCustomUnits( {
47
+ availableUnits: [ 'px', 'em', 'rem' ],
48
+ defaultValues: { px: 8, em: 0.5, rem: 0.5 },
49
+ } );
50
+
51
+ const unitsB = useCustomUnits( {
52
+ availableUnits: [ 'px', 'em', 'rem' ],
53
+ defaultValues: { px: 16, em: 1, rem: 1 },
54
+ } );
55
+
56
+ expect( unitsA ).not.toEqual( unitsB );
57
+ } );
58
+
59
+ it( 'should not mutate custon units argument definitons', () => {
60
+ const units = [
61
+ { value: 'px', label: 'pixel' },
62
+ { value: 'em', label: 'em' },
63
+ { value: 'rem', label: 'rem' },
64
+ ];
65
+
66
+ const unitsA = useCustomUnits( {
67
+ availableUnits: [ 'px', 'em', 'rem' ],
68
+ defaultValues: { px: 8, em: 0.5, rem: 0.5 },
69
+ units,
70
+ } );
71
+
72
+ const unitsB = useCustomUnits( {
73
+ availableUnits: [ 'px', 'em', 'rem' ],
74
+ defaultValues: { px: 16, em: 1, rem: 1 },
75
+ units,
76
+ } );
77
+
78
+ expect( unitsA ).not.toEqual( unitsB );
79
+ } );
80
+
45
81
  it( 'should add default values to available units even if the default values are strings', () => {
46
82
  // Although the public APIs of the component expect a `number` as the type of the
47
83
  // default values, it's still good to test for strings (as it can happen in un-typed
@@ -428,19 +428,16 @@ export const useCustomUnits = ( {
428
428
  units
429
429
  );
430
430
 
431
- if ( defaultValues ) {
432
- customUnitsToReturn.forEach( ( unit, i ) => {
433
- if ( defaultValues[ unit.value ] ) {
434
- const [ parsedDefaultValue ] = parseQuantityAndUnitFromRawValue(
435
- defaultValues[ unit.value ]
436
- );
437
-
438
- customUnitsToReturn[ i ].default = parsedDefaultValue;
439
- }
440
- } );
431
+ if ( ! defaultValues ) {
432
+ return customUnitsToReturn;
441
433
  }
442
434
 
443
- return customUnitsToReturn;
435
+ return customUnitsToReturn.map( ( unit ) => {
436
+ const [ defaultValue ] = defaultValues[ unit.value ]
437
+ ? parseQuantityAndUnitFromRawValue( defaultValues[ unit.value ] )
438
+ : [];
439
+ return { ...unit, default: defaultValue };
440
+ } );
444
441
  };
445
442
 
446
443
  /**