@sproutsocial/racine 11.2.5-sproutTheme-beta.2 → 11.2.5-sproutTheme-beta.5

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 (39) hide show
  1. package/__flow__/Button/index.stories.js +6 -21
  2. package/__flow__/Input/index.js +185 -66
  3. package/__flow__/Input/index.stories.js +65 -0
  4. package/__flow__/Input/index.test.js +230 -1
  5. package/__flow__/Input/styles.js +1 -1
  6. package/__flow__/ThemeProvider/index.js +4 -1
  7. package/__flow__/TokenInput/index.js +1 -1
  8. package/__flow__/index.js +1 -0
  9. package/__flow__/themes/dark/theme.js +3 -0
  10. package/__flow__/themes/extendedThemes/sproutTheme/NonColorThemeValues/index.js +1 -1
  11. package/__flow__/themes/extendedThemes/sproutTheme/dark/getDarkThemeColors.js +12 -0
  12. package/__flow__/themes/extendedThemes/sproutTheme/dark/theme.js +11 -13
  13. package/__flow__/themes/extendedThemes/sproutTheme/index.js +2 -0
  14. package/__flow__/themes/extendedThemes/sproutTheme/light/getLightThemeColors.js +10 -0
  15. package/__flow__/themes/extendedThemes/sproutTheme/light/theme.js +11 -13
  16. package/__flow__/themes/light/theme.js +3 -0
  17. package/__flow__/types/theme.colors.flow.js +3 -0
  18. package/commonjs/Input/index.js +124 -30
  19. package/commonjs/Input/styles.js +1 -1
  20. package/commonjs/TokenInput/index.js +1 -1
  21. package/commonjs/themes/dark/theme.js +4 -1
  22. package/commonjs/themes/extendedThemes/sproutTheme/dark/getDarkThemeColors.js +11 -2
  23. package/commonjs/themes/extendedThemes/sproutTheme/dark/theme.js +6 -7
  24. package/commonjs/themes/extendedThemes/sproutTheme/light/getLightThemeColors.js +9 -2
  25. package/commonjs/themes/extendedThemes/sproutTheme/light/theme.js +6 -7
  26. package/commonjs/themes/light/theme.js +4 -1
  27. package/dist/themes/dark/dark.scss +4 -1
  28. package/dist/themes/light/light.scss +4 -1
  29. package/lib/Input/index.js +117 -30
  30. package/lib/Input/styles.js +1 -1
  31. package/lib/TokenInput/index.js +1 -1
  32. package/lib/themes/dark/theme.js +4 -1
  33. package/lib/themes/extendedThemes/sproutTheme/dark/getDarkThemeColors.js +11 -2
  34. package/lib/themes/extendedThemes/sproutTheme/dark/theme.js +5 -7
  35. package/lib/themes/extendedThemes/sproutTheme/light/getLightThemeColors.js +9 -2
  36. package/lib/themes/extendedThemes/sproutTheme/light/theme.js +5 -7
  37. package/lib/themes/light/theme.js +4 -1
  38. package/package.json +1 -1
  39. package/CHANGELOG.md +0 -3133
@@ -8,6 +8,69 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
8
8
 
9
9
  import * as React from "react";
10
10
  import Container, { Accessory } from "./styles";
11
+ import Button from "../Button";
12
+ import Icon from "../Icon";
13
+ import styled from "styled-components";
14
+ var InputContext = /*#__PURE__*/React.createContext({});
15
+ var StyledButton = styled(Button).withConfig({
16
+ displayName: "Input__StyledButton",
17
+ componentId: "sc-1ck1dnm-0"
18
+ })(["&:hover,&:active{color:", ";}"], function (props) {
19
+ return props.theme.utils.interact(props.theme.colors.icon.base);
20
+ });
21
+
22
+ var ClearButton = function ClearButton() {
23
+ var _React$useContext = React.useContext(InputContext),
24
+ onClear = _React$useContext.onClear,
25
+ handleClear = _React$useContext.handleClear,
26
+ clearButtonLabel = _React$useContext.clearButtonLabel,
27
+ hasValue = _React$useContext.hasValue,
28
+ inputSize = _React$useContext.size; // Hide the button when there is no text to clear.
29
+
30
+
31
+ if (!hasValue) {
32
+ return null;
33
+ } // Log a warning and hide the button when no onClear callback is provided.
34
+ // If we called handleClear with no onClear prop, all the button would do is focus the Input.
35
+
36
+
37
+ if (!onClear) {
38
+ console.warn("Warning: No onClear prop provided to Input when using Input.ClearButton. Omitting Input.ClearButton.");
39
+ return null;
40
+ } // Warn if clearButtonLabel is not included, so that the unlocalized fallback will not be mistaken for a proper label.
41
+
42
+
43
+ if (!clearButtonLabel) {
44
+ console.warn("Warning: clearButtonLabel prop is required when using Input.ClearButton. Please pass a localized clearButtonLabel to Input.");
45
+ } // Reduce Button padding for size small Inputs so that the Button won't go outside the bounds of the Input.
46
+ // This adjustment is handled automatically for default and large Inputs via Button's size. There is no "small" Button.
47
+
48
+
49
+ var py = inputSize === "small" ? 100 : undefined;
50
+ var px = inputSize === "small" ? 200 : undefined;
51
+ var buttonSize = inputSize === "small" ? "default" : inputSize;
52
+ return /*#__PURE__*/React.createElement(StyledButton, {
53
+ onClick: handleClear,
54
+ size: buttonSize,
55
+ py: py,
56
+ px: px,
57
+ title: clearButtonLabel || "Clear",
58
+ ariaLabel: clearButtonLabel || "Clear",
59
+ color: "icon.base"
60
+ }, /*#__PURE__*/React.createElement(Icon, {
61
+ name: "circlex"
62
+ }));
63
+ }; // Used for positioning elementAfter. This logic will detect if the element is a ClearButton,
64
+ // regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
65
+
66
+
67
+ var isClearButton = function isClearButton(elem) {
68
+ if (elem != null && elem.type) {
69
+ return elem.type.displayName === "Input.ClearButton";
70
+ }
71
+
72
+ return false;
73
+ };
11
74
 
12
75
  var Input = /*#__PURE__*/function (_React$Component) {
13
76
  _inheritsLoose(Input, _React$Component);
@@ -22,39 +85,38 @@ var Input = /*#__PURE__*/function (_React$Component) {
22
85
  _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
23
86
 
24
87
  _this.handleBlur = function (e) {
25
- if (_this.props.onBlur) {
26
- _this.props.onBlur(e);
88
+ return _this.props.onBlur == null ? void 0 : _this.props.onBlur(e);
89
+ };
90
+
91
+ _this.handleClear = function (e) {
92
+ // Only attempt to focus the input if the ref is an object. It won't work for refs that are functions.
93
+ if (typeof _this.props.innerRef === "object") {
94
+ var _this$props$innerRef$;
95
+
96
+ (_this$props$innerRef$ = _this.props.innerRef.current) == null ? void 0 : _this$props$innerRef$.focus();
27
97
  }
98
+
99
+ _this.props.onClear == null ? void 0 : _this.props.onClear(e);
28
100
  };
29
101
 
30
102
  _this.handleChange = function (e) {
31
- if (_this.props.onChange) {
32
- _this.props.onChange(e, e.currentTarget.value);
33
- }
103
+ return _this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
34
104
  };
35
105
 
36
106
  _this.handleFocus = function (e) {
37
- if (_this.props.onFocus) {
38
- _this.props.onFocus(e);
39
- }
107
+ return _this.props.onFocus == null ? void 0 : _this.props.onFocus(e);
40
108
  };
41
109
 
42
110
  _this.handleKeyDown = function (e) {
43
- if (_this.props.onKeyDown) {
44
- _this.props.onKeyDown(e, e.currentTarget.value);
45
- }
111
+ return _this.props.onKeyDown == null ? void 0 : _this.props.onKeyDown(e, e.currentTarget.value);
46
112
  };
47
113
 
48
114
  _this.handleKeyUp = function (e) {
49
- if (_this.props.onKeyUp) {
50
- _this.props.onKeyUp(e, e.currentTarget.value);
51
- }
115
+ return _this.props.onKeyUp == null ? void 0 : _this.props.onKeyUp(e, e.currentTarget.value);
52
116
  };
53
117
 
54
118
  _this.handlePaste = function (e) {
55
- if (_this.props.onPaste) {
56
- _this.props.onPaste(e, e.currentTarget.value);
57
- }
119
+ return _this.props.onPaste == null ? void 0 : _this.props.onPaste(e, e.currentTarget.value);
58
120
  };
59
121
 
60
122
  return _this;
@@ -81,9 +143,11 @@ var Input = /*#__PURE__*/function (_React$Component) {
81
143
  maxLength = _this$props.maxLength,
82
144
  ariaLabel = _this$props.ariaLabel,
83
145
  ariaDescribedby = _this$props.ariaDescribedby,
146
+ clearButtonLabel = _this$props.clearButtonLabel,
84
147
  innerRef = _this$props.innerRef,
85
148
  onBlur = _this$props.onBlur,
86
149
  onChange = _this$props.onChange,
150
+ onClear = _this$props.onClear,
87
151
  onFocus = _this$props.onFocus,
88
152
  onKeyDown = _this$props.onKeyDown,
89
153
  onKeyUp = _this$props.onKeyUp,
@@ -93,25 +157,44 @@ var Input = /*#__PURE__*/function (_React$Component) {
93
157
  _this$props$qa = _this$props.qa,
94
158
  qa = _this$props$qa === void 0 ? {} : _this$props$qa,
95
159
  appearance = _this$props.appearance,
96
- rest = _objectWithoutPropertiesLoose(_this$props, ["autoComplete", "autoFocus", "disabled", "readOnly", "isInvalid", "hasWarning", "id", "name", "placeholder", "type", "required", "value", "elemBefore", "elemAfter", "maxLength", "ariaLabel", "ariaDescribedby", "innerRef", "onBlur", "onChange", "onFocus", "onKeyDown", "onKeyUp", "onPaste", "inputProps", "qa", "appearance"]);
160
+ size = _this$props.size,
161
+ rest = _objectWithoutPropertiesLoose(_this$props, ["autoComplete", "autoFocus", "disabled", "readOnly", "isInvalid", "hasWarning", "id", "name", "placeholder", "type", "required", "value", "elemBefore", "elemAfter", "maxLength", "ariaLabel", "ariaDescribedby", "clearButtonLabel", "innerRef", "onBlur", "onChange", "onClear", "onFocus", "onKeyDown", "onKeyUp", "onPaste", "inputProps", "qa", "appearance", "size"]); // Convert autoComplete from a boolean prop to a string value.
162
+
97
163
 
98
164
  var autoCompleteValue = undefined;
99
165
 
100
166
  if (autoComplete !== undefined) {
101
167
  autoCompleteValue = autoComplete ? "on" : "off";
102
- }
168
+ } // Add default elemBefore and elemAfter elements if type is search.
103
169
 
170
+
171
+ var elementBefore = type === "search" && !elemBefore ? /*#__PURE__*/React.createElement(Icon, {
172
+ name: "search",
173
+ ariaHidden: true,
174
+ color: "icon.base"
175
+ }) : elemBefore; // Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
176
+
177
+ var elementAfter = type === "search" && onClear && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
104
178
  return /*#__PURE__*/React.createElement(Container, _extends({
105
- hasBeforeElement: !!elemBefore,
106
- hasAfterElement: !!elemAfter,
179
+ hasBeforeElement: !!elementBefore,
180
+ hasAfterElement: !!elementAfter,
107
181
  disabled: disabled,
108
182
  invalid: !!isInvalid,
109
183
  warning: hasWarning,
110
- appearance: appearance // $FlowIssue - upgrade v0.112.0
111
-
112
- }, rest), elemBefore && /*#__PURE__*/React.createElement(Accessory, {
184
+ appearance: appearance,
185
+ size: size // $FlowIssue - upgrade v0.112.0
186
+
187
+ }, rest), /*#__PURE__*/React.createElement(InputContext.Provider, {
188
+ value: {
189
+ handleClear: this.handleClear,
190
+ hasValue: !!value,
191
+ clearButtonLabel: clearButtonLabel,
192
+ onClear: onClear,
193
+ size: size
194
+ }
195
+ }, elementBefore && /*#__PURE__*/React.createElement(Accessory, {
113
196
  before: true
114
- }, elemBefore), /*#__PURE__*/React.createElement("input", _extends({
197
+ }, elementBefore), /*#__PURE__*/React.createElement("input", _extends({
115
198
  "aria-invalid": !!isInvalid,
116
199
  "aria-label": ariaLabel,
117
200
  "aria-describedby": ariaDescribedby,
@@ -136,9 +219,10 @@ var Input = /*#__PURE__*/function (_React$Component) {
136
219
  "data-qa-input": name || "",
137
220
  "data-qa-input-isdisabled": disabled === true,
138
221
  "data-qa-input-isrequired": required === true
139
- }, qa, inputProps)), elemAfter && /*#__PURE__*/React.createElement(Accessory, {
140
- after: true
141
- }, elemAfter));
222
+ }, qa, inputProps)), elementAfter && /*#__PURE__*/React.createElement(Accessory, {
223
+ after: true,
224
+ isClearButton: isClearButton(elementAfter)
225
+ }, elementAfter)));
142
226
  };
143
227
 
144
228
  return Input;
@@ -149,6 +233,9 @@ Input.defaultProps = {
149
233
  disabled: false,
150
234
  type: "text",
151
235
  size: "default",
152
- appearance: "primary"
236
+ appearance: "primary",
237
+ innerRef: /*#__PURE__*/React.createRef()
153
238
  };
154
- export { Input as default };
239
+ Input.ClearButton = ClearButton;
240
+ Input.ClearButton.displayName = "Input.ClearButton";
241
+ export default Input;
@@ -73,7 +73,7 @@ export var Accessory = styled.div.withConfig({
73
73
  }, function (props) {
74
74
  return props.before && css(["left:", ";"], props.theme.space[350]);
75
75
  }, function (props) {
76
- return props.after && css(["right:", ";"], props.theme.space[350]);
76
+ return props.after && css(["right:", ";"], props.isClearButton ? 0 : props.theme.space[350]);
77
77
  });
78
78
  Container.displayName = "InputContainer";
79
79
  Accessory.displayName = "InputAccessory";
@@ -282,7 +282,7 @@ var TokenInput = /*#__PURE__*/function (_React$Component) {
282
282
  "aria-invalid": !!isInvalid,
283
283
  "aria-label": ariaLabel,
284
284
  autoFocus: autoFocus,
285
- autocomplete: autocomplete,
285
+ autoComplete: autocomplete,
286
286
  disabled: disabled,
287
287
  id: id,
288
288
  name: name,
@@ -159,7 +159,10 @@ var colors = _extends({}, lightTheme.colors, {
159
159
  subtext: COLORS.COLOR_NEUTRAL_300,
160
160
  body: COLORS.COLOR_NEUTRAL_100,
161
161
  inverse: COLORS.COLOR_NEUTRAL_900,
162
- error: COLORS.COLOR_RED_400
162
+ error: COLORS.COLOR_RED_400,
163
+ background: {
164
+ highlight: COLORS.COLOR_YELLOW_900
165
+ }
163
166
  },
164
167
  icon: {
165
168
  base: COLORS.COLOR_NEUTRAL_100,
@@ -30,7 +30,16 @@ export function getDarkThemeColors(themeColors) {
30
30
  }
31
31
  }
32
32
  },
33
- icon: {
33
+ container: _extends({}, themeColors.container, {
34
+ background: _extends({}, themeColors.container.background, {
35
+ // FIX: These need to be changed to have dark mode colors
36
+ // For now we've copied the light mode values here as well.
37
+ positive_sentiment: themeColors.blue[500],
38
+ negative_sentiment: themeColors.red[500],
39
+ neutral_sentiment: themeColors.neutral[300]
40
+ })
41
+ }),
42
+ icon: _extends({}, themeColors.icon, {
34
43
  // FIX: These need to be changed to have dark mode colors
35
44
  // For now we've copied the light mode values here as well.
36
45
  sentiment: {
@@ -38,6 +47,6 @@ export function getDarkThemeColors(themeColors) {
38
47
  negative_sentiment: themeColors.red[500],
39
48
  neutral_sentiment: themeColors.neutral[300]
40
49
  }
41
- }
50
+ })
42
51
  });
43
52
  }
@@ -4,15 +4,13 @@ import clone from "just-clone";
4
4
  import baseDarkTheme from "../../../dark/theme";
5
5
  import { getDarkThemeColors } from "./getDarkThemeColors";
6
6
  import { getNonColorThemeValues } from "../NonColorThemeValues";
7
+ // clone base theme. (we don't want to mutate the base theme)
8
+ var themeClone = clone(baseDarkTheme); // get non color theme values
7
9
 
8
- var darkTheme = function darkTheme(baseDarkTheme) {
9
- // clone base theme. (we don't want to mutate the base theme)
10
- var themeClone = clone(baseDarkTheme); // get non color theme values
10
+ var nonColorThemeValues = getNonColorThemeValues(themeClone); // get sprout specific dark theme colors
11
11
 
12
- var nonColorThemeValues = getNonColorThemeValues(themeClone); // get sprout specific dark theme colors
12
+ var darkThemeColors = getDarkThemeColors(themeClone.colors);
13
13
 
14
- var darkThemeColors = getDarkThemeColors(themeClone.colors);
15
- return _extends({}, themeClone, nonColorThemeValues, darkThemeColors);
16
- };
14
+ var darkTheme = _extends({}, themeClone, nonColorThemeValues, darkThemeColors);
17
15
 
18
16
  export default darkTheme;
@@ -30,12 +30,19 @@ export function getLightThemeColors(themeColors) {
30
30
  }
31
31
  }
32
32
  },
33
- icon: {
33
+ container: _extends({}, themeColors.container, {
34
+ background: _extends({}, themeColors.container.background, {
35
+ positive_sentiment: themeColors.blue[500],
36
+ negative_sentiment: themeColors.red[500],
37
+ neutral_sentiment: themeColors.neutral[300]
38
+ })
39
+ }),
40
+ icon: _extends({}, themeColors.icon, {
34
41
  sentiment: {
35
42
  positive_sentiment: themeColors.blue[500],
36
43
  negative_sentiment: themeColors.red[500],
37
44
  neutral_sentiment: themeColors.neutral[300]
38
45
  }
39
- }
46
+ })
40
47
  });
41
48
  }
@@ -4,15 +4,13 @@ import clone from "just-clone";
4
4
  import baseLightTheme from "../../../light/theme";
5
5
  import { getLightThemeColors } from "./getLightThemeColors";
6
6
  import { getNonColorThemeValues } from "../NonColorThemeValues";
7
+ // clone base theme. (we don't want to mutate the base theme)
8
+ var themeClone = clone(baseLightTheme); // get non color theme values
7
9
 
8
- var lightTheme = function lightTheme(baseLightTheme) {
9
- // clone base theme. (we don't want to mutate the base theme)
10
- var themeClone = clone(baseLightTheme); // get non color theme values
10
+ var nonColorThemeValues = getNonColorThemeValues(themeClone); // get sprout specific light theme colors
11
11
 
12
- var nonColorThemeValues = getNonColorThemeValues(themeClone); // get sprout specific light theme colors
12
+ var lightThemeColors = getLightThemeColors(themeClone.colors);
13
13
 
14
- var lightThemeColors = getLightThemeColors(themeClone.colors);
15
- return _extends({}, themeClone, nonColorThemeValues, lightThemeColors);
16
- };
14
+ var lightTheme = _extends({}, themeClone, nonColorThemeValues, lightThemeColors);
17
15
 
18
16
  export default lightTheme;
@@ -157,7 +157,10 @@ var colors = _extends({
157
157
  subtext: COLORS.COLOR_NEUTRAL_700,
158
158
  body: COLORS.COLOR_NEUTRAL_800,
159
159
  inverse: COLORS.COLOR_NEUTRAL_0,
160
- error: COLORS.COLOR_RED_800
160
+ error: COLORS.COLOR_RED_800,
161
+ background: {
162
+ highlight: COLORS.COLOR_YELLOW_200
163
+ }
161
164
  },
162
165
  icon: {
163
166
  base: COLORS.COLOR_NEUTRAL_800,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sproutsocial/racine",
3
- "version": "11.2.5-sproutTheme-beta.2",
3
+ "version": "11.2.5-sproutTheme-beta.5",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "__flow__",