@wordpress/components 19.9.0 → 19.10.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 (185) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/CONTRIBUTING.md +80 -7
  3. package/build/angle-picker-control/angle-circle.js +5 -7
  4. package/build/angle-picker-control/angle-circle.js.map +1 -1
  5. package/build/box-control/index.js +0 -21
  6. package/build/box-control/index.js.map +1 -1
  7. package/build/box-control/utils.js +1 -8
  8. package/build/box-control/utils.js.map +1 -1
  9. package/build/button/index.js +3 -5
  10. package/build/button/index.js.map +1 -1
  11. package/build/circular-option-picker/index.js +1 -2
  12. package/build/circular-option-picker/index.js.map +1 -1
  13. package/build/disabled/index.js +4 -76
  14. package/build/disabled/index.js.map +1 -1
  15. package/build/input-control/index.js +3 -2
  16. package/build/input-control/index.js.map +1 -1
  17. package/build/input-control/styles/input-control-styles.js +42 -30
  18. package/build/input-control/styles/input-control-styles.js.map +1 -1
  19. package/build/mobile/bottom-sheet-select-control/index.native.js +1 -0
  20. package/build/mobile/bottom-sheet-select-control/index.native.js.map +1 -1
  21. package/build/popover/index.js +6 -52
  22. package/build/popover/index.js.map +1 -1
  23. package/build/select-control/index.js +31 -4
  24. package/build/select-control/index.js.map +1 -1
  25. package/build/select-control/styles/select-control-styles.js +8 -8
  26. package/build/select-control/styles/select-control-styles.js.map +1 -1
  27. package/build/text-control/index.js +35 -28
  28. package/build/text-control/index.js.map +1 -1
  29. package/build/text-control/types.js +6 -0
  30. package/build/text-control/types.js.map +1 -0
  31. package/build/toggle-group-control/toggle-group-control-option-icon/component.js +6 -4
  32. package/build/toggle-group-control/toggle-group-control-option-icon/component.js.map +1 -1
  33. package/build/tools-panel/tools-panel-header/component.js +52 -36
  34. package/build/tools-panel/tools-panel-header/component.js.map +1 -1
  35. package/build/unit-control/index.js +3 -3
  36. package/build/unit-control/index.js.map +1 -1
  37. package/build/unit-control/styles/unit-control-styles.js +11 -20
  38. package/build/unit-control/styles/unit-control-styles.js.map +1 -1
  39. package/build/unit-control/utils.js.map +1 -1
  40. package/build-module/angle-picker-control/angle-circle.js +5 -7
  41. package/build-module/angle-picker-control/angle-circle.js.map +1 -1
  42. package/build-module/box-control/index.js +1 -20
  43. package/build-module/box-control/index.js.map +1 -1
  44. package/build-module/box-control/utils.js +0 -6
  45. package/build-module/box-control/utils.js.map +1 -1
  46. package/build-module/button/index.js +3 -4
  47. package/build-module/button/index.js.map +1 -1
  48. package/build-module/circular-option-picker/index.js +1 -2
  49. package/build-module/circular-option-picker/index.js.map +1 -1
  50. package/build-module/disabled/index.js +5 -76
  51. package/build-module/disabled/index.js.map +1 -1
  52. package/build-module/input-control/index.js +3 -2
  53. package/build-module/input-control/index.js.map +1 -1
  54. package/build-module/input-control/styles/input-control-styles.js +42 -30
  55. package/build-module/input-control/styles/input-control-styles.js.map +1 -1
  56. package/build-module/mobile/bottom-sheet-select-control/index.native.js +1 -0
  57. package/build-module/mobile/bottom-sheet-select-control/index.native.js.map +1 -1
  58. package/build-module/popover/index.js +6 -52
  59. package/build-module/popover/index.js.map +1 -1
  60. package/build-module/select-control/index.js +29 -3
  61. package/build-module/select-control/index.js.map +1 -1
  62. package/build-module/select-control/styles/select-control-styles.js +8 -8
  63. package/build-module/select-control/styles/select-control-styles.js.map +1 -1
  64. package/build-module/text-control/index.js +35 -27
  65. package/build-module/text-control/index.js.map +1 -1
  66. package/build-module/text-control/types.js +2 -0
  67. package/build-module/text-control/types.js.map +1 -0
  68. package/build-module/toggle-group-control/toggle-group-control-option-icon/component.js +1 -5
  69. package/build-module/toggle-group-control/toggle-group-control-option-icon/component.js.map +1 -1
  70. package/build-module/tools-panel/tools-panel-header/component.js +51 -36
  71. package/build-module/tools-panel/tools-panel-header/component.js.map +1 -1
  72. package/build-module/unit-control/index.js +3 -3
  73. package/build-module/unit-control/index.js.map +1 -1
  74. package/build-module/unit-control/styles/unit-control-styles.js +11 -20
  75. package/build-module/unit-control/styles/unit-control-styles.js.map +1 -1
  76. package/build-module/unit-control/utils.js.map +1 -1
  77. package/build-style/style-rtl.css +7 -0
  78. package/build-style/style.css +7 -0
  79. package/build-types/button/index.d.ts.map +1 -1
  80. package/build-types/circular-option-picker/index.d.ts.map +1 -1
  81. package/build-types/color-picker/styles.d.ts +3 -3
  82. package/build-types/disabled/index.d.ts.map +1 -1
  83. package/build-types/input-control/index.d.ts +4 -3
  84. package/build-types/input-control/index.d.ts.map +1 -1
  85. package/build-types/input-control/stories/index.d.ts +5 -5
  86. package/build-types/input-control/stories/index.d.ts.map +1 -1
  87. package/build-types/input-control/styles/input-control-styles.d.ts +1 -0
  88. package/build-types/input-control/styles/input-control-styles.d.ts.map +1 -1
  89. package/build-types/input-control/types.d.ts +6 -0
  90. package/build-types/input-control/types.d.ts.map +1 -1
  91. package/build-types/number-control/styles/number-control-styles.d.ts +1 -1
  92. package/build-types/popover/index.d.ts +0 -1
  93. package/build-types/popover/index.d.ts.map +1 -1
  94. package/build-types/select-control/index.d.ts +30 -26
  95. package/build-types/select-control/index.d.ts.map +1 -1
  96. package/build-types/select-control/stories/index.d.ts +23 -0
  97. package/build-types/select-control/stories/index.d.ts.map +1 -0
  98. package/build-types/select-control/styles/select-control-styles.d.ts +3 -4
  99. package/build-types/select-control/styles/select-control-styles.d.ts.map +1 -1
  100. package/build-types/select-control/test/select-control.d.ts +2 -0
  101. package/build-types/select-control/test/select-control.d.ts.map +1 -0
  102. package/build-types/select-control/types.d.ts +52 -1
  103. package/build-types/select-control/types.d.ts.map +1 -1
  104. package/build-types/text-control/index.d.ts +32 -0
  105. package/build-types/text-control/index.d.ts.map +1 -0
  106. package/build-types/text-control/stories/index.d.ts +13 -0
  107. package/build-types/text-control/stories/index.d.ts.map +1 -0
  108. package/build-types/text-control/types.d.ts +25 -0
  109. package/build-types/text-control/types.d.ts.map +1 -0
  110. package/build-types/toggle-group-control/toggle-group-control-option-icon/component.d.ts.map +1 -1
  111. package/build-types/tools-panel/tools-panel-header/component.d.ts.map +1 -1
  112. package/build-types/tools-panel/types.d.ts +0 -1
  113. package/build-types/tools-panel/types.d.ts.map +1 -1
  114. package/build-types/unit-control/index.d.ts +2 -2
  115. package/build-types/unit-control/index.d.ts.map +1 -1
  116. package/build-types/unit-control/styles/unit-control-styles.d.ts.map +1 -1
  117. package/build-types/unit-control/test/index.d.ts +2 -0
  118. package/build-types/unit-control/test/index.d.ts.map +1 -0
  119. package/build-types/unit-control/test/utils.d.ts +2 -0
  120. package/build-types/unit-control/test/utils.d.ts.map +1 -0
  121. package/build-types/unit-control/types.d.ts +1 -1
  122. package/build-types/unit-control/types.d.ts.map +1 -1
  123. package/build-types/unit-control/utils.d.ts +3 -3
  124. package/build-types/unit-control/utils.d.ts.map +1 -1
  125. package/package.json +17 -17
  126. package/src/angle-picker-control/angle-circle.js +3 -3
  127. package/src/box-control/README.md +0 -74
  128. package/src/box-control/index.js +0 -15
  129. package/src/box-control/stories/index.js +0 -29
  130. package/src/box-control/utils.js +0 -7
  131. package/src/button/index.js +2 -4
  132. package/src/button/test/index.js +16 -1
  133. package/src/circular-option-picker/index.js +1 -2
  134. package/src/color-palette/README.md +0 -1
  135. package/src/color-palette/test/__snapshots__/index.js.snap +2 -3
  136. package/src/confirm-dialog/stories/index.js +87 -99
  137. package/src/date-time/stories/index.js +19 -0
  138. package/src/date-time/test/date.js +107 -78
  139. package/src/dimension-control/test/__snapshots__/index.test.js.snap +4 -4
  140. package/src/disabled/index.js +5 -90
  141. package/src/form-file-upload/test/index.js +15 -12
  142. package/src/input-control/README.md +1 -1
  143. package/src/input-control/index.tsx +3 -2
  144. package/src/input-control/stories/index.tsx +1 -1
  145. package/src/input-control/styles/input-control-styles.tsx +19 -5
  146. package/src/input-control/types.ts +6 -0
  147. package/src/menu-item/style.scss +10 -0
  148. package/src/mobile/bottom-sheet/bottom-sheet-navigation/test/navigation-container.native.js +8 -1
  149. package/src/mobile/bottom-sheet-select-control/index.native.js +1 -0
  150. package/src/mobile/html-text-input/style.android.scss +1 -0
  151. package/src/mobile/html-text-input/style.ios.scss +1 -0
  152. package/src/mobile/link-settings/test/link-settings-navigation.native.js +9 -1
  153. package/src/popover/index.js +5 -51
  154. package/src/select-control/README.md +2 -2
  155. package/src/select-control/index.tsx +30 -29
  156. package/src/select-control/stories/index.tsx +90 -0
  157. package/src/select-control/styles/select-control-styles.ts +9 -8
  158. package/src/select-control/test/{select-control.js → select-control.tsx} +2 -2
  159. package/src/select-control/types.ts +66 -1
  160. package/src/text-control/index.tsx +84 -0
  161. package/src/text-control/stories/index.tsx +66 -0
  162. package/src/text-control/types.ts +29 -0
  163. package/src/toggle-group-control/toggle-group-control-option-icon/component.tsx +1 -5
  164. package/src/tools-panel/test/__snapshots__/index.js.snap +1 -1
  165. package/src/tools-panel/test/index.js +71 -18
  166. package/src/tools-panel/tools-panel-header/component.tsx +75 -33
  167. package/src/tools-panel/types.ts +0 -1
  168. package/src/tooltip/test/index.js +6 -0
  169. package/src/unit-control/index.tsx +2 -5
  170. package/src/unit-control/styles/unit-control-styles.ts +3 -13
  171. package/src/unit-control/test/__snapshots__/index.tsx.snap +33 -0
  172. package/src/unit-control/test/{index.js → index.tsx} +214 -165
  173. package/src/unit-control/test/{utils.js → utils.ts} +38 -19
  174. package/src/unit-control/types.ts +4 -1
  175. package/src/unit-control/utils.ts +5 -3
  176. package/tsconfig.json +2 -1
  177. package/tsconfig.tsbuildinfo +1 -1
  178. package/build/box-control/visualizer.js +0 -165
  179. package/build/box-control/visualizer.js.map +0 -1
  180. package/build-module/box-control/visualizer.js +0 -154
  181. package/build-module/box-control/visualizer.js.map +0 -1
  182. package/src/box-control/visualizer.js +0 -116
  183. package/src/select-control/stories/index.js +0 -104
  184. package/src/text-control/index.js +0 -72
  185. package/src/text-control/stories/index.js +0 -46
@@ -1,165 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = BoxControlVisualizer;
9
-
10
- var _element = require("@wordpress/element");
11
-
12
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
-
14
- var _boxControlVisualizerStyles = require("./styles/box-control-visualizer-styles");
15
-
16
- var _utils = require("./utils");
17
-
18
- /**
19
- * WordPress dependencies
20
- */
21
-
22
- /**
23
- * Internal dependencies
24
- */
25
- function BoxControlVisualizer(_ref) {
26
- let {
27
- children,
28
- showValues = _utils.DEFAULT_VISUALIZER_VALUES,
29
- values: valuesProp = _utils.DEFAULT_VALUES,
30
- ...props
31
- } = _ref;
32
- const isPositionAbsolute = !children;
33
- return (0, _element.createElement)(_boxControlVisualizerStyles.Container, (0, _extends2.default)({}, props, {
34
- isPositionAbsolute: isPositionAbsolute,
35
- "aria-hidden": "true"
36
- }), (0, _element.createElement)(Sides, {
37
- showValues: showValues,
38
- values: valuesProp
39
- }), children);
40
- }
41
-
42
- function Sides(_ref2) {
43
- let {
44
- showValues = _utils.DEFAULT_VISUALIZER_VALUES,
45
- values
46
- } = _ref2;
47
- const {
48
- top,
49
- right,
50
- bottom,
51
- left
52
- } = values;
53
- return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(Top, {
54
- isVisible: showValues.top,
55
- value: top
56
- }), (0, _element.createElement)(Right, {
57
- isVisible: showValues.right,
58
- value: right
59
- }), (0, _element.createElement)(Bottom, {
60
- isVisible: showValues.bottom,
61
- value: bottom
62
- }), (0, _element.createElement)(Left, {
63
- isVisible: showValues.left,
64
- value: left
65
- }));
66
- }
67
-
68
- function Top(_ref3) {
69
- let {
70
- isVisible = false,
71
- value
72
- } = _ref3;
73
- const height = value;
74
- const animationProps = useSideAnimation(height);
75
- const isActive = animationProps.isActive || isVisible;
76
- return (0, _element.createElement)(_boxControlVisualizerStyles.TopView, {
77
- isActive: isActive,
78
- style: {
79
- height
80
- }
81
- });
82
- }
83
-
84
- function Right(_ref4) {
85
- let {
86
- isVisible = false,
87
- value
88
- } = _ref4;
89
- const width = value;
90
- const animationProps = useSideAnimation(width);
91
- const isActive = animationProps.isActive || isVisible;
92
- return (0, _element.createElement)(_boxControlVisualizerStyles.RightView, {
93
- isActive: isActive,
94
- style: {
95
- width
96
- }
97
- });
98
- }
99
-
100
- function Bottom(_ref5) {
101
- let {
102
- isVisible = false,
103
- value
104
- } = _ref5;
105
- const height = value;
106
- const animationProps = useSideAnimation(height);
107
- const isActive = animationProps.isActive || isVisible;
108
- return (0, _element.createElement)(_boxControlVisualizerStyles.BottomView, {
109
- isActive: isActive,
110
- style: {
111
- height
112
- }
113
- });
114
- }
115
-
116
- function Left(_ref6) {
117
- let {
118
- isVisible = false,
119
- value
120
- } = _ref6;
121
- const width = value;
122
- const animationProps = useSideAnimation(width);
123
- const isActive = animationProps.isActive || isVisible;
124
- return (0, _element.createElement)(_boxControlVisualizerStyles.LeftView, {
125
- isActive: isActive,
126
- style: {
127
- width
128
- }
129
- });
130
- }
131
- /**
132
- * Custom hook that renders the "flash" animation whenever the value changes.
133
- *
134
- * @param {string} value Value of (box) side.
135
- */
136
-
137
-
138
- function useSideAnimation(value) {
139
- const [isActive, setIsActive] = (0, _element.useState)(false);
140
- const valueRef = (0, _element.useRef)(value);
141
- const timeoutRef = (0, _element.useRef)();
142
-
143
- const clearTimer = () => {
144
- if (timeoutRef.current) {
145
- window.clearTimeout(timeoutRef.current);
146
- }
147
- };
148
-
149
- (0, _element.useEffect)(() => {
150
- if (value !== valueRef.current) {
151
- setIsActive(true);
152
- valueRef.current = value;
153
- clearTimer();
154
- timeoutRef.current = setTimeout(() => {
155
- setIsActive(false);
156
- }, 400);
157
- }
158
-
159
- return () => clearTimer();
160
- }, [value]);
161
- return {
162
- isActive
163
- };
164
- }
165
- //# sourceMappingURL=visualizer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/components/src/box-control/visualizer.js"],"names":["BoxControlVisualizer","children","showValues","DEFAULT_VISUALIZER_VALUES","values","valuesProp","DEFAULT_VALUES","props","isPositionAbsolute","Sides","top","right","bottom","left","Top","isVisible","value","height","animationProps","useSideAnimation","isActive","Right","width","Bottom","Left","setIsActive","valueRef","timeoutRef","clearTimer","current","window","clearTimeout","setTimeout"],"mappings":";;;;;;;;;AAGA;;;;AAKA;;AAOA;;AAfA;AACA;AACA;;AAGA;AACA;AACA;AAUe,SAASA,oBAAT,OAKX;AAAA,MAL0C;AAC7CC,IAAAA,QAD6C;AAE7CC,IAAAA,UAAU,GAAGC,gCAFgC;AAG7CC,IAAAA,MAAM,EAAEC,UAAU,GAAGC,qBAHwB;AAI7C,OAAGC;AAJ0C,GAK1C;AACH,QAAMC,kBAAkB,GAAG,CAAEP,QAA7B;AACA,SACC,4BAAC,qCAAD,6BACMM,KADN;AAEC,IAAA,kBAAkB,EAAGC,kBAFtB;AAGC,mBAAY;AAHb,MAKC,4BAAC,KAAD;AAAO,IAAA,UAAU,EAAGN,UAApB;AAAiC,IAAA,MAAM,EAAGG;AAA1C,IALD,EAMGJ,QANH,CADD;AAUA;;AAED,SAASQ,KAAT,QAAqE;AAAA,MAArD;AAAEP,IAAAA,UAAU,GAAGC,gCAAf;AAA0CC,IAAAA;AAA1C,GAAqD;AACpE,QAAM;AAAEM,IAAAA,GAAF;AAAOC,IAAAA,KAAP;AAAcC,IAAAA,MAAd;AAAsBC,IAAAA;AAAtB,MAA+BT,MAArC;AAEA,SACC,qDACC,4BAAC,GAAD;AAAK,IAAA,SAAS,EAAGF,UAAU,CAACQ,GAA5B;AAAkC,IAAA,KAAK,EAAGA;AAA1C,IADD,EAEC,4BAAC,KAAD;AAAO,IAAA,SAAS,EAAGR,UAAU,CAACS,KAA9B;AAAsC,IAAA,KAAK,EAAGA;AAA9C,IAFD,EAGC,4BAAC,MAAD;AAAQ,IAAA,SAAS,EAAGT,UAAU,CAACU,MAA/B;AAAwC,IAAA,KAAK,EAAGA;AAAhD,IAHD,EAIC,4BAAC,IAAD;AAAM,IAAA,SAAS,EAAGV,UAAU,CAACW,IAA7B;AAAoC,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AAAA;AAArB,GAA+B;AAC7C,QAAMM,KAAK,GAAGN,KAAd;AACA,QAAME,cAAc,GAAGC,gBAAgB,CAAEG,KAAF,CAAvC;AACA,QAAMF,QAAQ,GAAGF,cAAc,CAACE,QAAf,IAA2BL,SAA5C;AAEA,SAAO,4BAAC,oCAAD;AAAU,IAAA,QAAQ,EAAGK,QAArB;AAAgC,IAAA,KAAK,EAAG;AAAEE,MAAAA;AAAF;AAAxC,IAAP;AACA;AAED;AACA;AACA;AACA;AACA;;;AACA,SAASH,gBAAT,CAA2BH,KAA3B,EAAmC;AAClC,QAAM,CAAEI,QAAF,EAAYK,WAAZ,IAA4B,uBAAU,KAAV,CAAlC;AACA,QAAMC,QAAQ,GAAG,qBAAQV,KAAR,CAAjB;AACA,QAAMW,UAAU,GAAG,sBAAnB;;AAEA,QAAMC,UAAU,GAAG,MAAM;AACxB,QAAKD,UAAU,CAACE,OAAhB,EAA0B;AACzBC,MAAAA,MAAM,CAACC,YAAP,CAAqBJ,UAAU,CAACE,OAAhC;AACA;AACD,GAJD;;AAMA,0BAAW,MAAM;AAChB,QAAKb,KAAK,KAAKU,QAAQ,CAACG,OAAxB,EAAkC;AACjCJ,MAAAA,WAAW,CAAE,IAAF,CAAX;AACAC,MAAAA,QAAQ,CAACG,OAAT,GAAmBb,KAAnB;AAEAY,MAAAA,UAAU;AAEVD,MAAAA,UAAU,CAACE,OAAX,GAAqBG,UAAU,CAAE,MAAM;AACtCP,QAAAA,WAAW,CAAE,KAAF,CAAX;AACA,OAF8B,EAE5B,GAF4B,CAA/B;AAGA;;AAED,WAAO,MAAMG,UAAU,EAAvB;AACA,GAbD,EAaG,CAAEZ,KAAF,CAbH;AAeA,SAAO;AACNI,IAAAA;AADM,GAAP;AAGA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tContainer,\n\tTopView,\n\tRightView,\n\tBottomView,\n\tLeftView,\n} from './styles/box-control-visualizer-styles';\nimport { DEFAULT_VALUES, DEFAULT_VISUALIZER_VALUES } from './utils';\n\nexport default function BoxControlVisualizer( {\n\tchildren,\n\tshowValues = DEFAULT_VISUALIZER_VALUES,\n\tvalues: valuesProp = DEFAULT_VALUES,\n\t...props\n} ) {\n\tconst isPositionAbsolute = ! children;\n\treturn (\n\t\t<Container\n\t\t\t{ ...props }\n\t\t\tisPositionAbsolute={ isPositionAbsolute }\n\t\t\taria-hidden=\"true\"\n\t\t>\n\t\t\t<Sides showValues={ showValues } values={ valuesProp } />\n\t\t\t{ children }\n\t\t</Container>\n\t);\n}\n\nfunction Sides( { showValues = DEFAULT_VISUALIZER_VALUES, values } ) {\n\tconst { top, right, bottom, left } = values;\n\n\treturn (\n\t\t<>\n\t\t\t<Top isVisible={ showValues.top } value={ top } />\n\t\t\t<Right isVisible={ showValues.right } value={ right } />\n\t\t\t<Bottom isVisible={ showValues.bottom } value={ bottom } />\n\t\t\t<Left isVisible={ showValues.left } value={ left } />\n\t\t</>\n\t);\n}\n\nfunction Top( { isVisible = false, value } ) {\n\tconst height = value;\n\tconst animationProps = useSideAnimation( height );\n\tconst isActive = animationProps.isActive || isVisible;\n\n\treturn <TopView isActive={ isActive } style={ { height } } />;\n}\n\nfunction Right( { isVisible = false, value } ) {\n\tconst width = value;\n\tconst animationProps = useSideAnimation( width );\n\tconst isActive = animationProps.isActive || isVisible;\n\n\treturn <RightView isActive={ isActive } style={ { width } } />;\n}\n\nfunction Bottom( { isVisible = false, value } ) {\n\tconst height = value;\n\tconst animationProps = useSideAnimation( height );\n\tconst isActive = animationProps.isActive || isVisible;\n\n\treturn <BottomView isActive={ isActive } style={ { height } } />;\n}\n\nfunction Left( { isVisible = false, value } ) {\n\tconst width = value;\n\tconst animationProps = useSideAnimation( width );\n\tconst isActive = animationProps.isActive || isVisible;\n\n\treturn <LeftView isActive={ isActive } style={ { width } } />;\n}\n\n/**\n * Custom hook that renders the \"flash\" animation whenever the value changes.\n *\n * @param {string} value Value of (box) side.\n */\nfunction useSideAnimation( value ) {\n\tconst [ isActive, setIsActive ] = useState( false );\n\tconst valueRef = useRef( value );\n\tconst timeoutRef = useRef();\n\n\tconst clearTimer = () => {\n\t\tif ( timeoutRef.current ) {\n\t\t\twindow.clearTimeout( timeoutRef.current );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( value !== valueRef.current ) {\n\t\t\tsetIsActive( true );\n\t\t\tvalueRef.current = value;\n\n\t\t\tclearTimer();\n\n\t\t\ttimeoutRef.current = setTimeout( () => {\n\t\t\t\tsetIsActive( false );\n\t\t\t}, 400 );\n\t\t}\n\n\t\treturn () => clearTimer();\n\t}, [ value ] );\n\n\treturn {\n\t\tisActive,\n\t};\n}\n"]}
@@ -1,154 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { createElement, Fragment } from "@wordpress/element";
3
-
4
- /**
5
- * WordPress dependencies
6
- */
7
- import { useRef, useEffect, useState } from '@wordpress/element';
8
- /**
9
- * Internal dependencies
10
- */
11
-
12
- import { Container, TopView, RightView, BottomView, LeftView } from './styles/box-control-visualizer-styles';
13
- import { DEFAULT_VALUES, DEFAULT_VISUALIZER_VALUES } from './utils';
14
- export default function BoxControlVisualizer(_ref) {
15
- let {
16
- children,
17
- showValues = DEFAULT_VISUALIZER_VALUES,
18
- values: valuesProp = DEFAULT_VALUES,
19
- ...props
20
- } = _ref;
21
- const isPositionAbsolute = !children;
22
- return createElement(Container, _extends({}, props, {
23
- isPositionAbsolute: isPositionAbsolute,
24
- "aria-hidden": "true"
25
- }), createElement(Sides, {
26
- showValues: showValues,
27
- values: valuesProp
28
- }), children);
29
- }
30
-
31
- function Sides(_ref2) {
32
- let {
33
- showValues = DEFAULT_VISUALIZER_VALUES,
34
- values
35
- } = _ref2;
36
- const {
37
- top,
38
- right,
39
- bottom,
40
- left
41
- } = values;
42
- return createElement(Fragment, null, createElement(Top, {
43
- isVisible: showValues.top,
44
- value: top
45
- }), createElement(Right, {
46
- isVisible: showValues.right,
47
- value: right
48
- }), createElement(Bottom, {
49
- isVisible: showValues.bottom,
50
- value: bottom
51
- }), createElement(Left, {
52
- isVisible: showValues.left,
53
- value: left
54
- }));
55
- }
56
-
57
- function Top(_ref3) {
58
- let {
59
- isVisible = false,
60
- value
61
- } = _ref3;
62
- const height = value;
63
- const animationProps = useSideAnimation(height);
64
- const isActive = animationProps.isActive || isVisible;
65
- return createElement(TopView, {
66
- isActive: isActive,
67
- style: {
68
- height
69
- }
70
- });
71
- }
72
-
73
- function Right(_ref4) {
74
- let {
75
- isVisible = false,
76
- value
77
- } = _ref4;
78
- const width = value;
79
- const animationProps = useSideAnimation(width);
80
- const isActive = animationProps.isActive || isVisible;
81
- return createElement(RightView, {
82
- isActive: isActive,
83
- style: {
84
- width
85
- }
86
- });
87
- }
88
-
89
- function Bottom(_ref5) {
90
- let {
91
- isVisible = false,
92
- value
93
- } = _ref5;
94
- const height = value;
95
- const animationProps = useSideAnimation(height);
96
- const isActive = animationProps.isActive || isVisible;
97
- return createElement(BottomView, {
98
- isActive: isActive,
99
- style: {
100
- height
101
- }
102
- });
103
- }
104
-
105
- function Left(_ref6) {
106
- let {
107
- isVisible = false,
108
- value
109
- } = _ref6;
110
- const width = value;
111
- const animationProps = useSideAnimation(width);
112
- const isActive = animationProps.isActive || isVisible;
113
- return createElement(LeftView, {
114
- isActive: isActive,
115
- style: {
116
- width
117
- }
118
- });
119
- }
120
- /**
121
- * Custom hook that renders the "flash" animation whenever the value changes.
122
- *
123
- * @param {string} value Value of (box) side.
124
- */
125
-
126
-
127
- function useSideAnimation(value) {
128
- const [isActive, setIsActive] = useState(false);
129
- const valueRef = useRef(value);
130
- const timeoutRef = useRef();
131
-
132
- const clearTimer = () => {
133
- if (timeoutRef.current) {
134
- window.clearTimeout(timeoutRef.current);
135
- }
136
- };
137
-
138
- useEffect(() => {
139
- if (value !== valueRef.current) {
140
- setIsActive(true);
141
- valueRef.current = value;
142
- clearTimer();
143
- timeoutRef.current = setTimeout(() => {
144
- setIsActive(false);
145
- }, 400);
146
- }
147
-
148
- return () => clearTimer();
149
- }, [value]);
150
- return {
151
- isActive
152
- };
153
- }
154
- //# sourceMappingURL=visualizer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/components/src/box-control/visualizer.js"],"names":["useRef","useEffect","useState","Container","TopView","RightView","BottomView","LeftView","DEFAULT_VALUES","DEFAULT_VISUALIZER_VALUES","BoxControlVisualizer","children","showValues","values","valuesProp","props","isPositionAbsolute","Sides","top","right","bottom","left","Top","isVisible","value","height","animationProps","useSideAnimation","isActive","Right","width","Bottom","Left","setIsActive","valueRef","timeoutRef","clearTimer","current","window","clearTimeout","setTimeout"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,MAAT,EAAiBC,SAAjB,EAA4BC,QAA5B,QAA4C,oBAA5C;AAEA;AACA;AACA;;AACA,SACCC,SADD,EAECC,OAFD,EAGCC,SAHD,EAICC,UAJD,EAKCC,QALD,QAMO,wCANP;AAOA,SAASC,cAAT,EAAyBC,yBAAzB,QAA0D,SAA1D;AAEA,eAAe,SAASC,oBAAT,OAKX;AAAA,MAL0C;AAC7CC,IAAAA,QAD6C;AAE7CC,IAAAA,UAAU,GAAGH,yBAFgC;AAG7CI,IAAAA,MAAM,EAAEC,UAAU,GAAGN,cAHwB;AAI7C,OAAGO;AAJ0C,GAK1C;AACH,QAAMC,kBAAkB,GAAG,CAAEL,QAA7B;AACA,SACC,cAAC,SAAD,eACMI,KADN;AAEC,IAAA,kBAAkB,EAAGC,kBAFtB;AAGC,mBAAY;AAHb,MAKC,cAAC,KAAD;AAAO,IAAA,UAAU,EAAGJ,UAApB;AAAiC,IAAA,MAAM,EAAGE;AAA1C,IALD,EAMGH,QANH,CADD;AAUA;;AAED,SAASM,KAAT,QAAqE;AAAA,MAArD;AAAEL,IAAAA,UAAU,GAAGH,yBAAf;AAA0CI,IAAAA;AAA1C,GAAqD;AACpE,QAAM;AAAEK,IAAAA,GAAF;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,MAAAA,WAAW,CAAE,IAAF,CAAX;AACAC,MAAAA,QAAQ,CAACG,OAAT,GAAmBb,KAAnB;AAEAY,MAAAA,UAAU;AAEVD,MAAAA,UAAU,CAACE,OAAX,GAAqBG,UAAU,CAAE,MAAM;AACtCP,QAAAA,WAAW,CAAE,KAAF,CAAX;AACA,OAF8B,EAE5B,GAF4B,CAA/B;AAGA;;AAED,WAAO,MAAMG,UAAU,EAAvB;AACA,GAbQ,EAaN,CAAEZ,KAAF,CAbM,CAAT;AAeA,SAAO;AACNI,IAAAA;AADM,GAAP;AAGA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tContainer,\n\tTopView,\n\tRightView,\n\tBottomView,\n\tLeftView,\n} from './styles/box-control-visualizer-styles';\nimport { DEFAULT_VALUES, DEFAULT_VISUALIZER_VALUES } from './utils';\n\nexport default function BoxControlVisualizer( {\n\tchildren,\n\tshowValues = DEFAULT_VISUALIZER_VALUES,\n\tvalues: valuesProp = DEFAULT_VALUES,\n\t...props\n} ) {\n\tconst isPositionAbsolute = ! children;\n\treturn (\n\t\t<Container\n\t\t\t{ ...props }\n\t\t\tisPositionAbsolute={ isPositionAbsolute }\n\t\t\taria-hidden=\"true\"\n\t\t>\n\t\t\t<Sides showValues={ showValues } values={ valuesProp } />\n\t\t\t{ children }\n\t\t</Container>\n\t);\n}\n\nfunction Sides( { showValues = DEFAULT_VISUALIZER_VALUES, values } ) {\n\tconst { top, right, bottom, left } = values;\n\n\treturn (\n\t\t<>\n\t\t\t<Top isVisible={ showValues.top } value={ top } />\n\t\t\t<Right isVisible={ showValues.right } value={ right } />\n\t\t\t<Bottom isVisible={ showValues.bottom } value={ bottom } />\n\t\t\t<Left isVisible={ showValues.left } value={ left } />\n\t\t</>\n\t);\n}\n\nfunction Top( { isVisible = false, value } ) {\n\tconst height = value;\n\tconst animationProps = useSideAnimation( height );\n\tconst isActive = animationProps.isActive || isVisible;\n\n\treturn <TopView isActive={ isActive } style={ { height } } />;\n}\n\nfunction Right( { isVisible = false, value } ) {\n\tconst width = value;\n\tconst animationProps = useSideAnimation( width );\n\tconst isActive = animationProps.isActive || isVisible;\n\n\treturn <RightView isActive={ isActive } style={ { width } } />;\n}\n\nfunction Bottom( { isVisible = false, value } ) {\n\tconst height = value;\n\tconst animationProps = useSideAnimation( height );\n\tconst isActive = animationProps.isActive || isVisible;\n\n\treturn <BottomView isActive={ isActive } style={ { height } } />;\n}\n\nfunction Left( { isVisible = false, value } ) {\n\tconst width = value;\n\tconst animationProps = useSideAnimation( width );\n\tconst isActive = animationProps.isActive || isVisible;\n\n\treturn <LeftView isActive={ isActive } style={ { width } } />;\n}\n\n/**\n * Custom hook that renders the \"flash\" animation whenever the value changes.\n *\n * @param {string} value Value of (box) side.\n */\nfunction useSideAnimation( value ) {\n\tconst [ isActive, setIsActive ] = useState( false );\n\tconst valueRef = useRef( value );\n\tconst timeoutRef = useRef();\n\n\tconst clearTimer = () => {\n\t\tif ( timeoutRef.current ) {\n\t\t\twindow.clearTimeout( timeoutRef.current );\n\t\t}\n\t};\n\n\tuseEffect( () => {\n\t\tif ( value !== valueRef.current ) {\n\t\t\tsetIsActive( true );\n\t\t\tvalueRef.current = value;\n\n\t\t\tclearTimer();\n\n\t\t\ttimeoutRef.current = setTimeout( () => {\n\t\t\t\tsetIsActive( false );\n\t\t\t}, 400 );\n\t\t}\n\n\t\treturn () => clearTimer();\n\t}, [ value ] );\n\n\treturn {\n\t\tisActive,\n\t};\n}\n"]}
@@ -1,116 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useRef, useEffect, useState } from '@wordpress/element';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import {
10
- Container,
11
- TopView,
12
- RightView,
13
- BottomView,
14
- LeftView,
15
- } from './styles/box-control-visualizer-styles';
16
- import { DEFAULT_VALUES, DEFAULT_VISUALIZER_VALUES } from './utils';
17
-
18
- export default function BoxControlVisualizer( {
19
- children,
20
- showValues = DEFAULT_VISUALIZER_VALUES,
21
- values: valuesProp = DEFAULT_VALUES,
22
- ...props
23
- } ) {
24
- const isPositionAbsolute = ! children;
25
- return (
26
- <Container
27
- { ...props }
28
- isPositionAbsolute={ isPositionAbsolute }
29
- aria-hidden="true"
30
- >
31
- <Sides showValues={ showValues } values={ valuesProp } />
32
- { children }
33
- </Container>
34
- );
35
- }
36
-
37
- function Sides( { showValues = DEFAULT_VISUALIZER_VALUES, values } ) {
38
- const { top, right, bottom, left } = values;
39
-
40
- return (
41
- <>
42
- <Top isVisible={ showValues.top } value={ top } />
43
- <Right isVisible={ showValues.right } value={ right } />
44
- <Bottom isVisible={ showValues.bottom } value={ bottom } />
45
- <Left isVisible={ showValues.left } value={ left } />
46
- </>
47
- );
48
- }
49
-
50
- function Top( { isVisible = false, value } ) {
51
- const height = value;
52
- const animationProps = useSideAnimation( height );
53
- const isActive = animationProps.isActive || isVisible;
54
-
55
- return <TopView isActive={ isActive } style={ { height } } />;
56
- }
57
-
58
- function Right( { isVisible = false, value } ) {
59
- const width = value;
60
- const animationProps = useSideAnimation( width );
61
- const isActive = animationProps.isActive || isVisible;
62
-
63
- return <RightView isActive={ isActive } style={ { width } } />;
64
- }
65
-
66
- function Bottom( { isVisible = false, value } ) {
67
- const height = value;
68
- const animationProps = useSideAnimation( height );
69
- const isActive = animationProps.isActive || isVisible;
70
-
71
- return <BottomView isActive={ isActive } style={ { height } } />;
72
- }
73
-
74
- function Left( { isVisible = false, value } ) {
75
- const width = value;
76
- const animationProps = useSideAnimation( width );
77
- const isActive = animationProps.isActive || isVisible;
78
-
79
- return <LeftView isActive={ isActive } style={ { width } } />;
80
- }
81
-
82
- /**
83
- * Custom hook that renders the "flash" animation whenever the value changes.
84
- *
85
- * @param {string} value Value of (box) side.
86
- */
87
- function useSideAnimation( value ) {
88
- const [ isActive, setIsActive ] = useState( false );
89
- const valueRef = useRef( value );
90
- const timeoutRef = useRef();
91
-
92
- const clearTimer = () => {
93
- if ( timeoutRef.current ) {
94
- window.clearTimeout( timeoutRef.current );
95
- }
96
- };
97
-
98
- useEffect( () => {
99
- if ( value !== valueRef.current ) {
100
- setIsActive( true );
101
- valueRef.current = value;
102
-
103
- clearTimer();
104
-
105
- timeoutRef.current = setTimeout( () => {
106
- setIsActive( false );
107
- }, 400 );
108
- }
109
-
110
- return () => clearTimer();
111
- }, [ value ] );
112
-
113
- return {
114
- isActive,
115
- };
116
- }
@@ -1,104 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { boolean, object, select, text } from '@storybook/addon-knobs';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { useState } from '@wordpress/element';
10
-
11
- /**
12
- * Internal dependencies
13
- */
14
- import SelectControl from '..';
15
-
16
- export default {
17
- title: 'Components/SelectControl',
18
- component: SelectControl,
19
- parameters: {
20
- knobs: { disable: false },
21
- },
22
- };
23
-
24
- const SelectControlWithState = ( props ) => {
25
- const [ selection, setSelection ] = useState();
26
-
27
- return (
28
- <SelectControl
29
- { ...props }
30
- value={ selection }
31
- onChange={ setSelection }
32
- />
33
- );
34
- };
35
-
36
- export const _default = () => {
37
- const props = {
38
- disabled: boolean( 'disabled', false ),
39
- help: text( 'help', 'Help text to explain the select control.' ),
40
- hideLabelFromVision: boolean( 'hideLabelFromVision', false ),
41
- label: text( 'label', 'Value' ),
42
- labelPosition: select(
43
- 'labelPosition',
44
- {
45
- top: 'top',
46
- side: 'side',
47
- bottom: 'bottom',
48
- },
49
- 'top'
50
- ),
51
- multiple: boolean( 'multiple', false ),
52
- options: object( 'Options', [
53
- { value: null, label: 'Select an Option', disabled: true },
54
- { value: 'a', label: 'Option A' },
55
- { value: 'b', label: 'Option B' },
56
- { value: 'c', label: 'Option C' },
57
- ] ),
58
- size: select(
59
- 'size',
60
- {
61
- default: 'default',
62
- small: 'small',
63
- '__unstable-large': '__unstable-large',
64
- },
65
- 'default'
66
- ),
67
- };
68
-
69
- return <SelectControlWithState { ...props } />;
70
- };
71
-
72
- export const withCustomChildren = () => {
73
- return (
74
- <SelectControlWithState label="Value">
75
- <option value="option-1">Option 1</option>
76
- <option value="option-2" disabled>
77
- Option 2 - Disabled
78
- </option>
79
- <option value="option-3">Option 3</option>
80
- <optgroup label="Option Group 1">
81
- <option value="option-group-1-option-1">
82
- Option Group 1 - Option 1
83
- </option>
84
- <option value="option-group-1-option-2" disabled>
85
- Option Group 1 - Option 2 - Disabled
86
- </option>
87
- <option value="option-group-1-option-3">
88
- Option Group 1 - Option 3
89
- </option>
90
- </optgroup>
91
- <optgroup label="Option Group 2">
92
- <option value="option-group-2-option-1">
93
- Option Group 2 - Option 1
94
- </option>
95
- <option value="option-group-2-option-2" disabled>
96
- Option Group 2 - Option 2 - Disabled
97
- </option>
98
- <option value="option-group-2-option-3">
99
- Option Group 2 - Option 3
100
- </option>
101
- </optgroup>
102
- </SelectControlWithState>
103
- );
104
- };
@@ -1,72 +0,0 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useInstanceId } from '@wordpress/compose';
5
- import { forwardRef } from '@wordpress/element';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import BaseControl from '../base-control';
11
-
12
- /**
13
- * @typedef OwnProps
14
- * @property {string} label Label for the control.
15
- * @property {boolean} [hideLabelFromVision] Whether to accessibly hide the label.
16
- * @property {string} value Value of the input.
17
- * @property {string} [help] Optional help text for the control.
18
- * @property {string} [className] Classname passed to BaseControl wrapper
19
- * @property {(value: string) => void} onChange Handle changes.
20
- * @property {string} [type='text'] Type of the input.
21
- */
22
-
23
- /** @typedef {OwnProps & import('react').ComponentProps<'input'>} Props */
24
-
25
- /**
26
- *
27
- * @param {Props} props Props
28
- * @param {import('react').ForwardedRef<HTMLInputElement>} ref
29
- */
30
- function TextControl(
31
- {
32
- label,
33
- hideLabelFromVision,
34
- value,
35
- help,
36
- className,
37
- onChange,
38
- type = 'text',
39
- ...props
40
- },
41
- ref
42
- ) {
43
- const instanceId = useInstanceId( TextControl );
44
- const id = `inspector-text-control-${ instanceId }`;
45
- const onChangeValue = (
46
- /** @type {import('react').ChangeEvent<HTMLInputElement>} */
47
- event
48
- ) => onChange( event.target.value );
49
-
50
- return (
51
- <BaseControl
52
- label={ label }
53
- hideLabelFromVision={ hideLabelFromVision }
54
- id={ id }
55
- help={ help }
56
- className={ className }
57
- >
58
- <input
59
- className="components-text-control__input"
60
- type={ type }
61
- id={ id }
62
- value={ value }
63
- onChange={ onChangeValue }
64
- aria-describedby={ !! help ? id + '__help' : undefined }
65
- ref={ ref }
66
- { ...props }
67
- />
68
- </BaseControl>
69
- );
70
- }
71
-
72
- export default forwardRef( TextControl );
@@ -1,46 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { boolean, text } from '@storybook/addon-knobs';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { useState } from '@wordpress/element';
10
-
11
- /**
12
- * Internal dependencies
13
- */
14
- import TextControl from '../';
15
-
16
- export default {
17
- title: 'Components/TextControl',
18
- component: TextControl,
19
- parameters: {
20
- knobs: { disable: false },
21
- },
22
- };
23
-
24
- const TextControlWithState = ( props ) => {
25
- const [ value, setValue ] = useState();
26
-
27
- return <TextControl { ...props } value={ value } onChange={ setValue } />;
28
- };
29
-
30
- export const _default = () => {
31
- const label = text( 'Label', 'Label Text' );
32
- const hideLabelFromVision = boolean( 'Hide Label From Vision', false );
33
- const help = text( 'Help Text', 'Help text to explain the input.' );
34
- const type = text( 'Input Type', 'text' );
35
- const className = text( 'Class Name', '' );
36
-
37
- return (
38
- <TextControlWithState
39
- label={ label }
40
- hideLabelFromVision={ hideLabelFromVision }
41
- help={ help }
42
- type={ type }
43
- className={ className }
44
- />
45
- );
46
- };