@sproutsocial/racine 11.7.0 → 11.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 (37) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/__flow__/Checkbox/index.stories.js +73 -56
  3. package/__flow__/EnumIconNames.js +1 -1
  4. package/__flow__/Icon/index.stories.js +41 -36
  5. package/__flow__/IconViewBoxes.js +1 -1
  6. package/__flow__/Input/index.js +47 -23
  7. package/__flow__/Input/index.stories.js +59 -33
  8. package/__flow__/Input/index.test.js +20 -0
  9. package/__flow__/Input/styles.js +2 -2
  10. package/__flow__/Loader/index.stories.js +18 -14
  11. package/__flow__/Numeral/index.stories.js +109 -50
  12. package/__flow__/Radio/index.stories.js +41 -26
  13. package/__flow__/Switch/index.stories.js +26 -18
  14. package/__flow__/themes/extendedThemes/sproutTheme/dark/theme.js +9 -0
  15. package/__flow__/themes/extendedThemes/sproutTheme/light/theme.js +9 -0
  16. package/__flow__/types/theme.flow.js +2 -0
  17. package/commonjs/IconViewBoxes.js +2 -0
  18. package/commonjs/Input/index.js +42 -22
  19. package/commonjs/Input/styles.js +2 -2
  20. package/commonjs/include-icons.js +1 -1
  21. package/commonjs/themes/extendedThemes/sproutTheme/dark/theme.js +11 -2
  22. package/commonjs/themes/extendedThemes/sproutTheme/light/theme.js +11 -2
  23. package/dist/iconList.js +1 -1
  24. package/dist/icons.svg +1 -1
  25. package/dist/themes/extendedThemes/sproutTheme/dark/theme.scss +14 -0
  26. package/dist/themes/extendedThemes/sproutTheme/light/theme.scss +14 -0
  27. package/icons/help-alt.svg +3 -0
  28. package/icons/plug.svg +3 -0
  29. package/includeIcons.js +1 -1
  30. package/lib/IconViewBoxes.js +2 -0
  31. package/lib/Input/index.js +42 -22
  32. package/lib/Input/styles.js +2 -2
  33. package/lib/include-icons.js +1 -1
  34. package/lib/themes/extendedThemes/sproutTheme/dark/theme.js +9 -1
  35. package/lib/themes/extendedThemes/sproutTheme/light/theme.js +9 -1
  36. package/lib/types/theme.flow.js +1 -1
  37. package/package.json +1 -1
@@ -41,7 +41,6 @@ var StyledButton = (0, _styledComponents.default)(_Button.default).withConfig({
41
41
 
42
42
  var ClearButton = function ClearButton() {
43
43
  var _React$useContext = React.useContext(InputContext),
44
- onClear = _React$useContext.onClear,
45
44
  handleClear = _React$useContext.handleClear,
46
45
  clearButtonLabel = _React$useContext.clearButtonLabel,
47
46
  hasValue = _React$useContext.hasValue,
@@ -50,13 +49,6 @@ var ClearButton = function ClearButton() {
50
49
 
51
50
  if (!hasValue) {
52
51
  return null;
53
- } // Log a warning and hide the button when no onClear callback is provided.
54
- // If we called handleClear with no onClear prop, all the button would do is focus the Input.
55
-
56
-
57
- if (!onClear) {
58
- console.warn("Warning: No onClear prop provided to Input when using Input.ClearButton. Omitting Input.ClearButton.");
59
- return null;
60
52
  } // Warn if clearButtonLabel is not included, so that the unlocalized fallback will not be mistaken for a proper label.
61
53
 
62
54
 
@@ -95,14 +87,10 @@ var isClearButton = function isClearButton(elem) {
95
87
  var Input = /*#__PURE__*/function (_React$Component) {
96
88
  _inheritsLoose(Input, _React$Component);
97
89
 
98
- function Input() {
90
+ function Input(props) {
99
91
  var _this;
100
92
 
101
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
102
- args[_key] = arguments[_key];
103
- }
104
-
105
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
93
+ _this = _React$Component.call(this, props) || this;
106
94
  _this.inputRef = /*#__PURE__*/React.createRef();
107
95
 
108
96
  _this.handleBlur = function (e) {
@@ -110,14 +98,31 @@ var Input = /*#__PURE__*/function (_React$Component) {
110
98
  };
111
99
 
112
100
  _this.handleClear = function (e) {
113
- var _this$inputRef, _this$inputRef$curren;
101
+ var input = _this.inputRef.current;
102
+
103
+ if (input) {
104
+ var _Object$getOwnPropert;
105
+
106
+ // Clear the value via the input prototype, then dispatch an input event in order to trigger handleChange
107
+ var nativeInputValueSetter = (_Object$getOwnPropert = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")) == null ? void 0 : _Object$getOwnPropert.set;
108
+ nativeInputValueSetter == null ? void 0 : nativeInputValueSetter.call(input, "");
109
+ var inputEvent = new Event("input", {
110
+ bubbles: true
111
+ });
112
+ input.dispatchEvent(inputEvent); // Focus the input, update hasValue, and call any onClear callback
113
+
114
+ input.focus();
115
+
116
+ _this.updateState("");
114
117
 
115
- (_this$inputRef = _this.inputRef) == null ? void 0 : (_this$inputRef$curren = _this$inputRef.current) == null ? void 0 : _this$inputRef$curren.focus();
116
- _this.props.onClear == null ? void 0 : _this.props.onClear(e);
118
+ _this.props.onClear == null ? void 0 : _this.props.onClear(e);
119
+ }
117
120
  };
118
121
 
119
122
  _this.handleChange = function (e) {
120
- return _this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
123
+ _this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
124
+
125
+ _this.updateState(e.currentTarget.value);
121
126
  };
122
127
 
123
128
  _this.handleFocus = function (e) {
@@ -136,6 +141,22 @@ var Input = /*#__PURE__*/function (_React$Component) {
136
141
  return _this.props.onPaste == null ? void 0 : _this.props.onPaste(e, e.currentTarget.value);
137
142
  };
138
143
 
144
+ _this.updateState = function (inputValue) {
145
+ var hasValue = inputValue !== "";
146
+ var previousHasValue = _this.state.hasValue; // Only update state if the value of `hasValue` has changed to avoid unnecessary renders.
147
+
148
+ if (hasValue !== previousHasValue) {
149
+ _this.setState({
150
+ hasValue: hasValue
151
+ });
152
+ }
153
+ };
154
+
155
+ _this.state = {
156
+ // Tracking hasValue in state allows us to hide ClearButton when there is no value to clear
157
+ // for both controlled and uncontrolled inputs.
158
+ hasValue: !!props.value
159
+ };
139
160
  return _this;
140
161
  }
141
162
 
@@ -189,9 +210,9 @@ var Input = /*#__PURE__*/function (_React$Component) {
189
210
  name: "search",
190
211
  ariaHidden: true,
191
212
  color: "icon.base"
192
- }) : elemBefore; // Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
213
+ }) : elemBefore; // Do not add a ClearButton if an elemAfter prop was passed.
193
214
 
194
- var elementAfter = type === "search" && onClear && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
215
+ var elementAfter = type === "search" && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
195
216
  return /*#__PURE__*/React.createElement(_styles.default, _extends({
196
217
  hasBeforeElement: !!elementBefore,
197
218
  hasAfterElement: !!elementAfter,
@@ -204,9 +225,8 @@ var Input = /*#__PURE__*/function (_React$Component) {
204
225
  }, rest), /*#__PURE__*/React.createElement(InputContext.Provider, {
205
226
  value: {
206
227
  handleClear: this.handleClear,
207
- hasValue: !!value,
228
+ hasValue: this.state.hasValue,
208
229
  clearButtonLabel: clearButtonLabel,
209
- onClear: onClear,
210
230
  size: size
211
231
  }
212
232
  }, elementBefore && /*#__PURE__*/React.createElement(_styles.Accessory, {
@@ -84,9 +84,9 @@ var Accessory = _styledComponents.default.div.withConfig({
84
84
  })(["position:absolute;top:50%;transform:translateY(-50%);color:", ";display:flex;align-items:center;", ";", ";"], function (props) {
85
85
  return props.theme.colors.icon.base;
86
86
  }, function (props) {
87
- return props.before && (0, _styledComponents.css)(["left:", ";"], props.theme.space[350]);
87
+ return props.before && (0, _styledComponents.css)(["left:", ";"], props.theme.space[300]);
88
88
  }, function (props) {
89
- return props.after && (0, _styledComponents.css)(["right:", ";"], props.isClearButton ? 0 : props.theme.space[350]);
89
+ return props.after && (0, _styledComponents.css)(["right:", ";"], props.isClearButton ? 0 : props.theme.space[300]);
90
90
  });
91
91
 
92
92
  exports.Accessory = Accessory;