@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
@@ -171,6 +171,7 @@ module.exports = {
171
171
  "heart-outline": "0 0 16 16",
172
172
  "heart": "0 0 16 16",
173
173
  "heartbeat": "0 0 18 16",
174
+ "help-alt": "0 0 12 16",
174
175
  "help": "0 0 16 16",
175
176
  "hiking": "0 0 16 16",
176
177
  "history": "0 0 16 16",
@@ -253,6 +254,7 @@ module.exports = {
253
254
  "pinterest": "0 0 16 16",
254
255
  "play-circle": "0 0 16 16",
255
256
  "play": "0 0 14 16",
257
+ "plug": "0 0 12 16",
256
258
  "plus": "0 0 16 18",
257
259
  "positive-sentiment": "0 0 16 16",
258
260
  "power-up-outline": "0 0 12 16",
@@ -24,7 +24,6 @@ var StyledButton = styled(Button).withConfig({
24
24
 
25
25
  var ClearButton = function ClearButton() {
26
26
  var _React$useContext = React.useContext(InputContext),
27
- onClear = _React$useContext.onClear,
28
27
  handleClear = _React$useContext.handleClear,
29
28
  clearButtonLabel = _React$useContext.clearButtonLabel,
30
29
  hasValue = _React$useContext.hasValue,
@@ -33,13 +32,6 @@ var ClearButton = function ClearButton() {
33
32
 
34
33
  if (!hasValue) {
35
34
  return null;
36
- } // Log a warning and hide the button when no onClear callback is provided.
37
- // If we called handleClear with no onClear prop, all the button would do is focus the Input.
38
-
39
-
40
- if (!onClear) {
41
- console.warn("Warning: No onClear prop provided to Input when using Input.ClearButton. Omitting Input.ClearButton.");
42
- return null;
43
35
  } // Warn if clearButtonLabel is not included, so that the unlocalized fallback will not be mistaken for a proper label.
44
36
 
45
37
 
@@ -78,14 +70,10 @@ var isClearButton = function isClearButton(elem) {
78
70
  var Input = /*#__PURE__*/function (_React$Component) {
79
71
  _inheritsLoose(Input, _React$Component);
80
72
 
81
- function Input() {
73
+ function Input(props) {
82
74
  var _this;
83
75
 
84
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
85
- args[_key] = arguments[_key];
86
- }
87
-
88
- _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
76
+ _this = _React$Component.call(this, props) || this;
89
77
  _this.inputRef = /*#__PURE__*/React.createRef();
90
78
 
91
79
  _this.handleBlur = function (e) {
@@ -93,14 +81,31 @@ var Input = /*#__PURE__*/function (_React$Component) {
93
81
  };
94
82
 
95
83
  _this.handleClear = function (e) {
96
- var _this$inputRef, _this$inputRef$curren;
84
+ var input = _this.inputRef.current;
85
+
86
+ if (input) {
87
+ var _Object$getOwnPropert;
88
+
89
+ // Clear the value via the input prototype, then dispatch an input event in order to trigger handleChange
90
+ var nativeInputValueSetter = (_Object$getOwnPropert = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")) == null ? void 0 : _Object$getOwnPropert.set;
91
+ nativeInputValueSetter == null ? void 0 : nativeInputValueSetter.call(input, "");
92
+ var inputEvent = new Event("input", {
93
+ bubbles: true
94
+ });
95
+ input.dispatchEvent(inputEvent); // Focus the input, update hasValue, and call any onClear callback
96
+
97
+ input.focus();
98
+
99
+ _this.updateState("");
97
100
 
98
- (_this$inputRef = _this.inputRef) == null ? void 0 : (_this$inputRef$curren = _this$inputRef.current) == null ? void 0 : _this$inputRef$curren.focus();
99
- _this.props.onClear == null ? void 0 : _this.props.onClear(e);
101
+ _this.props.onClear == null ? void 0 : _this.props.onClear(e);
102
+ }
100
103
  };
101
104
 
102
105
  _this.handleChange = function (e) {
103
- return _this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
106
+ _this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
107
+
108
+ _this.updateState(e.currentTarget.value);
104
109
  };
105
110
 
106
111
  _this.handleFocus = function (e) {
@@ -119,6 +124,22 @@ var Input = /*#__PURE__*/function (_React$Component) {
119
124
  return _this.props.onPaste == null ? void 0 : _this.props.onPaste(e, e.currentTarget.value);
120
125
  };
121
126
 
127
+ _this.updateState = function (inputValue) {
128
+ var hasValue = inputValue !== "";
129
+ var previousHasValue = _this.state.hasValue; // Only update state if the value of `hasValue` has changed to avoid unnecessary renders.
130
+
131
+ if (hasValue !== previousHasValue) {
132
+ _this.setState({
133
+ hasValue: hasValue
134
+ });
135
+ }
136
+ };
137
+
138
+ _this.state = {
139
+ // Tracking hasValue in state allows us to hide ClearButton when there is no value to clear
140
+ // for both controlled and uncontrolled inputs.
141
+ hasValue: !!props.value
142
+ };
122
143
  return _this;
123
144
  }
124
145
 
@@ -172,9 +193,9 @@ var Input = /*#__PURE__*/function (_React$Component) {
172
193
  name: "search",
173
194
  ariaHidden: true,
174
195
  color: "icon.base"
175
- }) : elemBefore; // Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
196
+ }) : elemBefore; // Do not add a ClearButton if an elemAfter prop was passed.
176
197
 
177
- var elementAfter = type === "search" && onClear && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
198
+ var elementAfter = type === "search" && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
178
199
  return /*#__PURE__*/React.createElement(Container, _extends({
179
200
  hasBeforeElement: !!elementBefore,
180
201
  hasAfterElement: !!elementAfter,
@@ -187,9 +208,8 @@ var Input = /*#__PURE__*/function (_React$Component) {
187
208
  }, rest), /*#__PURE__*/React.createElement(InputContext.Provider, {
188
209
  value: {
189
210
  handleClear: this.handleClear,
190
- hasValue: !!value,
211
+ hasValue: this.state.hasValue,
191
212
  clearButtonLabel: clearButtonLabel,
192
- onClear: onClear,
193
213
  size: size
194
214
  }
195
215
  }, elementBefore && /*#__PURE__*/React.createElement(Accessory, {
@@ -71,9 +71,9 @@ export var Accessory = styled.div.withConfig({
71
71
  })(["position:absolute;top:50%;transform:translateY(-50%);color:", ";display:flex;align-items:center;", ";", ";"], function (props) {
72
72
  return props.theme.colors.icon.base;
73
73
  }, function (props) {
74
- return props.before && css(["left:", ";"], props.theme.space[350]);
74
+ return props.before && css(["left:", ";"], props.theme.space[300]);
75
75
  }, function (props) {
76
- return props.after && css(["right:", ";"], props.isClearButton ? 0 : props.theme.space[350]);
76
+ return props.after && css(["right:", ";"], props.isClearButton ? 0 : props.theme.space[300]);
77
77
  });
78
78
  Container.displayName = "InputContainer";
79
79
  Accessory.displayName = "InputAccessory";