@sproutsocial/racine 11.6.1 → 11.7.0-input-beta.4

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 (35) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/__flow__/Checkbox/styles.js +75 -75
  3. package/__flow__/Collapsible/index.js +3 -2
  4. package/__flow__/Image/index.js +10 -2
  5. package/__flow__/Input/index.js +47 -23
  6. package/__flow__/Input/index.stories.js +14 -0
  7. package/__flow__/Input/index.test.js +20 -0
  8. package/__flow__/Input/styles.js +2 -2
  9. package/__flow__/SegmentedControl/index.js +3 -2
  10. package/__flow__/TableCell/index.js +9 -2
  11. package/__flow__/ToggleHint/index.js +9 -2
  12. package/__flow__/systemProps/color.js +1 -2
  13. package/__flow__/themes/extendedThemes/sproutTheme/dark/theme.js +12 -0
  14. package/__flow__/themes/extendedThemes/sproutTheme/light/theme.js +12 -0
  15. package/__flow__/themes/{dark → utils}/_themed.scss +4 -3
  16. package/__flow__/types/theme.flow.js +5 -1
  17. package/__flow__/utils/responsiveProps/index.test.js +10 -2
  18. package/commonjs/Input/index.js +40 -22
  19. package/commonjs/Input/styles.js +2 -2
  20. package/commonjs/themes/extendedThemes/sproutTheme/dark/theme.js +14 -2
  21. package/commonjs/themes/extendedThemes/sproutTheme/light/theme.js +14 -2
  22. package/dist/themes/dark/_themed.scss +4 -3
  23. package/dist/themes/dark/{dark.scss → theme.scss} +1 -1
  24. package/{__flow__/themes/light → dist/themes/extendedThemes/sproutTheme/dark}/_themed.scss +4 -3
  25. package/dist/themes/extendedThemes/sproutTheme/dark/theme.scss +692 -0
  26. package/dist/themes/extendedThemes/sproutTheme/light/_themed.scss +119 -0
  27. package/dist/themes/extendedThemes/sproutTheme/light/theme.scss +692 -0
  28. package/dist/themes/light/_themed.scss +4 -3
  29. package/dist/themes/light/{light.scss → theme.scss} +1 -1
  30. package/lib/Input/index.js +40 -22
  31. package/lib/Input/styles.js +2 -2
  32. package/lib/themes/extendedThemes/sproutTheme/dark/theme.js +12 -1
  33. package/lib/themes/extendedThemes/sproutTheme/light/theme.js +12 -1
  34. package/lib/types/theme.flow.js +1 -1
  35. package/package.json +3 -2
@@ -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,29 @@ 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
+ // Clear the value via the input prototype, then dispatch an input event in order to trigger handleChange
105
+ var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
106
+ nativeInputValueSetter.call(input, "");
107
+ var inputEvent = new Event("input", {
108
+ bubbles: true
109
+ });
110
+ input.dispatchEvent(inputEvent); // Focus the input, update hasValue, and call any onClear callback
111
+
112
+ input.focus();
113
+
114
+ _this.updateState("");
114
115
 
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);
116
+ _this.props.onClear == null ? void 0 : _this.props.onClear(e);
117
+ }
117
118
  };
118
119
 
119
120
  _this.handleChange = function (e) {
120
- return _this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
121
+ _this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
122
+
123
+ _this.updateState(e.currentTarget.value);
121
124
  };
122
125
 
123
126
  _this.handleFocus = function (e) {
@@ -136,6 +139,22 @@ var Input = /*#__PURE__*/function (_React$Component) {
136
139
  return _this.props.onPaste == null ? void 0 : _this.props.onPaste(e, e.currentTarget.value);
137
140
  };
138
141
 
142
+ _this.updateState = function (inputValue) {
143
+ var hasValue = inputValue !== "";
144
+ var previousHasValue = _this.state.hasValue; // Only update state if the value of `hasValue` has changed to avoid unnecessary renders.
145
+
146
+ if (hasValue !== previousHasValue) {
147
+ _this.setState({
148
+ hasValue: hasValue
149
+ });
150
+ }
151
+ };
152
+
153
+ _this.state = {
154
+ // Tracking hasValue in state allows us to hide ClearButton when there is no value to clear
155
+ // for both controlled and uncontrolled inputs.
156
+ hasValue: !!props.value
157
+ };
139
158
  return _this;
140
159
  }
141
160
 
@@ -189,9 +208,9 @@ var Input = /*#__PURE__*/function (_React$Component) {
189
208
  name: "search",
190
209
  ariaHidden: true,
191
210
  color: "icon.base"
192
- }) : elemBefore; // Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
211
+ }) : elemBefore; // Do not add a ClearButton if an elemAfter prop was passed.
193
212
 
194
- var elementAfter = type === "search" && onClear && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
213
+ var elementAfter = type === "search" && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
195
214
  return /*#__PURE__*/React.createElement(_styles.default, _extends({
196
215
  hasBeforeElement: !!elementBefore,
197
216
  hasAfterElement: !!elementAfter,
@@ -204,9 +223,8 @@ var Input = /*#__PURE__*/function (_React$Component) {
204
223
  }, rest), /*#__PURE__*/React.createElement(InputContext.Provider, {
205
224
  value: {
206
225
  handleClear: this.handleClear,
207
- hasValue: !!value,
226
+ hasValue: this.state.hasValue,
208
227
  clearButtonLabel: clearButtonLabel,
209
- onClear: onClear,
210
228
  size: size
211
229
  }
212
230
  }, 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;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.navigation = exports.default = void 0;
4
+ exports.navigation = exports.default = exports.datePicker = void 0;
5
5
 
6
6
  var _theme = _interopRequireDefault(require("../../../dark/theme"));
7
7
 
@@ -38,10 +38,22 @@ var navigation = {
38
38
  }
39
39
  };
40
40
  exports.navigation = navigation;
41
+ var datePicker = {
42
+ comparison: {
43
+ background: {
44
+ base: _theme.default.colors.neutral[400]
45
+ },
46
+ text: {
47
+ base: _theme.default.colors.neutral[800]
48
+ }
49
+ }
50
+ };
51
+ exports.datePicker = datePicker;
41
52
 
42
53
  var darkTheme = _extends({}, _theme.default, {
43
54
  colors: _extends({}, _theme.default.colors, {
44
- navigation: navigation
55
+ navigation: navigation,
56
+ datePicker: datePicker
45
57
  })
46
58
  });
47
59
 
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.navigation = exports.default = void 0;
4
+ exports.navigation = exports.default = exports.datePicker = void 0;
5
5
 
6
6
  var _theme = _interopRequireDefault(require("../../../light/theme"));
7
7
 
@@ -38,10 +38,22 @@ var navigation = {
38
38
  }
39
39
  };
40
40
  exports.navigation = navigation;
41
+ var datePicker = {
42
+ comparison: {
43
+ background: {
44
+ base: _theme.default.colors.neutral[400]
45
+ },
46
+ text: {
47
+ base: _theme.default.colors.neutral[800]
48
+ }
49
+ }
50
+ };
51
+ exports.datePicker = datePicker;
41
52
 
42
53
  var lightTheme = _extends({}, _theme.default, {
43
54
  colors: _extends({}, _theme.default.colors, {
44
- navigation: navigation
55
+ navigation: navigation,
56
+ datePicker: datePicker
45
57
  })
46
58
  });
47
59
 
@@ -2,12 +2,13 @@
2
2
  // This file is excluded from stylelint, because stylelint is only set up to lint styled-components at the moment.
3
3
 
4
4
  // SET-UP
5
- // This file is auto-generated based on the JS theme file, ensuring our SCSS theme variables stay in sync.
6
- @import "../../../dist/themes/dark/dark.scss";
5
+ // theme.scss is auto-generated based on the JS theme file, ensuring our SCSS theme variables stay in sync.
6
+ // _themed.scss will be copied to each theme folder in /dist, where the theme.scss file for that theme will be.
7
+ @import "./theme.scss";
7
8
 
8
9
  // In the JS theme file, the theme object is exported as "default" (i.e., using "export default"),
9
10
  // so we need to map-get "default" to access it.
10
- $theme: map-get($dark, "default");
11
+ $theme: map-get($theme, "default");
11
12
 
12
13
  // FUNCTIONS
13
14
  // This function will allow you to get any value from the theme.
@@ -1,4 +1,4 @@
1
- $dark: (
1
+ $theme: (
2
2
  __esModule: true,
3
3
  default: (
4
4
  utils: (
@@ -2,12 +2,13 @@
2
2
  // This file is excluded from stylelint, because stylelint is only set up to lint styled-components at the moment.
3
3
 
4
4
  // SET-UP
5
- // This file is auto-generated based on the JS theme file, ensuring our SCSS theme variables stay in sync.
6
- @import "../../../dist/themes/light/light.scss";
5
+ // theme.scss is auto-generated based on the JS theme file, ensuring our SCSS theme variables stay in sync.
6
+ // _themed.scss will be copied to each theme folder in /dist, where the theme.scss file for that theme will be.
7
+ @import "./theme.scss";
7
8
 
8
9
  // In the JS theme file, the theme object is exported as "default" (i.e., using "export default"),
9
10
  // so we need to map-get "default" to access it.
10
- $theme: map-get($light, "default");
11
+ $theme: map-get($theme, "default");
11
12
 
12
13
  // FUNCTIONS
13
14
  // This function will allow you to get any value from the theme.