@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
@@ -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,29 @@ 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
+ // Clear the value via the input prototype, then dispatch an input event in order to trigger handleChange
88
+ var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
89
+ nativeInputValueSetter.call(input, "");
90
+ var inputEvent = new Event("input", {
91
+ bubbles: true
92
+ });
93
+ input.dispatchEvent(inputEvent); // Focus the input, update hasValue, and call any onClear callback
94
+
95
+ input.focus();
96
+
97
+ _this.updateState("");
97
98
 
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);
99
+ _this.props.onClear == null ? void 0 : _this.props.onClear(e);
100
+ }
100
101
  };
101
102
 
102
103
  _this.handleChange = function (e) {
103
- return _this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
104
+ _this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
105
+
106
+ _this.updateState(e.currentTarget.value);
104
107
  };
105
108
 
106
109
  _this.handleFocus = function (e) {
@@ -119,6 +122,22 @@ var Input = /*#__PURE__*/function (_React$Component) {
119
122
  return _this.props.onPaste == null ? void 0 : _this.props.onPaste(e, e.currentTarget.value);
120
123
  };
121
124
 
125
+ _this.updateState = function (inputValue) {
126
+ var hasValue = inputValue !== "";
127
+ var previousHasValue = _this.state.hasValue; // Only update state if the value of `hasValue` has changed to avoid unnecessary renders.
128
+
129
+ if (hasValue !== previousHasValue) {
130
+ _this.setState({
131
+ hasValue: hasValue
132
+ });
133
+ }
134
+ };
135
+
136
+ _this.state = {
137
+ // Tracking hasValue in state allows us to hide ClearButton when there is no value to clear
138
+ // for both controlled and uncontrolled inputs.
139
+ hasValue: !!props.value
140
+ };
122
141
  return _this;
123
142
  }
124
143
 
@@ -172,9 +191,9 @@ var Input = /*#__PURE__*/function (_React$Component) {
172
191
  name: "search",
173
192
  ariaHidden: true,
174
193
  color: "icon.base"
175
- }) : elemBefore; // Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
194
+ }) : elemBefore; // Do not add a ClearButton if an elemAfter prop was passed.
176
195
 
177
- var elementAfter = type === "search" && onClear && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
196
+ var elementAfter = type === "search" && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
178
197
  return /*#__PURE__*/React.createElement(Container, _extends({
179
198
  hasBeforeElement: !!elementBefore,
180
199
  hasAfterElement: !!elementAfter,
@@ -187,9 +206,8 @@ var Input = /*#__PURE__*/function (_React$Component) {
187
206
  }, rest), /*#__PURE__*/React.createElement(InputContext.Provider, {
188
207
  value: {
189
208
  handleClear: this.handleClear,
190
- hasValue: !!value,
209
+ hasValue: this.state.hasValue,
191
210
  clearButtonLabel: clearButtonLabel,
192
- onClear: onClear,
193
211
  size: size
194
212
  }
195
213
  }, 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";
@@ -29,10 +29,21 @@ export var navigation = {
29
29
  }
30
30
  }
31
31
  };
32
+ export var datePicker = {
33
+ comparison: {
34
+ background: {
35
+ base: baseDarkTheme.colors.neutral[400]
36
+ },
37
+ text: {
38
+ base: baseDarkTheme.colors.neutral[800]
39
+ }
40
+ }
41
+ };
32
42
 
33
43
  var darkTheme = _extends({}, baseDarkTheme, {
34
44
  colors: _extends({}, baseDarkTheme.colors, {
35
- navigation: navigation
45
+ navigation: navigation,
46
+ datePicker: datePicker
36
47
  })
37
48
  });
38
49
 
@@ -29,10 +29,21 @@ export var navigation = {
29
29
  }
30
30
  }
31
31
  };
32
+ export var datePicker = {
33
+ comparison: {
34
+ background: {
35
+ base: baseLightTheme.colors.neutral[400]
36
+ },
37
+ text: {
38
+ base: baseLightTheme.colors.neutral[800]
39
+ }
40
+ }
41
+ };
32
42
 
33
43
  var lightTheme = _extends({}, baseLightTheme, {
34
44
  colors: _extends({}, baseLightTheme.colors, {
35
- navigation: navigation
45
+ navigation: navigation,
46
+ datePicker: datePicker
36
47
  })
37
48
  });
38
49
 
@@ -1,2 +1,2 @@
1
1
  import { breakpoints, typography, fontWeights, radii, borders, borderWidths, shadows, space, easing, duration } from "../themes/light/theme";
2
- import { navigation } from "../themes/extendedThemes/sproutTheme/light/theme";
2
+ import { datePicker, navigation } from "../themes/extendedThemes/sproutTheme/light/theme";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sproutsocial/racine",
3
- "version": "11.6.1",
3
+ "version": "11.7.0-input-beta.4",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "__flow__",
@@ -48,6 +48,7 @@
48
48
  "release": "yarn test && yarn changeset publish",
49
49
  "storybook": "start-storybook -c .storybook -p 9999",
50
50
  "build-storybook": "build-storybook --quiet -c .storybook -o .storybook-dist",
51
+ "build-chromatic": "yarn build-icons && build-storybook --quiet -c .storybook -o .storybook-dist",
51
52
  "icon-lint": "node bin/icon-lint/cli",
52
53
  "playroom:start": "playroom start",
53
54
  "playroom:build": "playroom build"
@@ -166,7 +167,7 @@
166
167
  "svgo": "^1.3.0",
167
168
  "svgstore": "^2.0.3",
168
169
  "webpack": "^4.20.0",
169
- "webpack-dev-server": "^3.11.0"
170
+ "webpack-dev-server": "^4.9.0"
170
171
  },
171
172
  "peerDependencies": {
172
173
  "@sproutsocial/seeds-border": ">=0.3.0",