@sproutsocial/racine 11.3.1-beta-deps.5 → 11.4.1-input-beta.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 (43) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/__flow__/Button/__snapshots__/index.test.js.snap +511 -0
  3. package/__flow__/Button/index.js +0 -2
  4. package/__flow__/Button/index.stories.js +67 -51
  5. package/__flow__/Button/index.test.js +113 -0
  6. package/__flow__/Button/styles.js +1 -1
  7. package/__flow__/EmptyState/index.test.js +1 -1
  8. package/__flow__/Input/index.js +187 -67
  9. package/__flow__/Input/index.stories.js +65 -0
  10. package/__flow__/Input/index.test.js +230 -1
  11. package/__flow__/Input/styles.js +1 -1
  12. package/__flow__/Link/index.js +2 -1
  13. package/__flow__/Menu/__snapshots__/index.test.js.snap +2 -2
  14. package/__flow__/TokenInput/index.js +1 -1
  15. package/__flow__/setupTests.js +1 -1
  16. package/__flow__/systemProps/tests/__snapshots__/layout.test.js.snap +14 -0
  17. package/__flow__/systemProps/tests/layout.test.js +9 -0
  18. package/__flow__/themes/dark/theme.js +3 -0
  19. package/__flow__/themes/light/theme.js +3 -0
  20. package/__flow__/types/theme.colors.flow.js +3 -0
  21. package/__flow__/utils/index.js +23 -0
  22. package/commonjs/Button/index.js +0 -1
  23. package/commonjs/Button/styles.js +0 -1
  24. package/commonjs/Input/index.js +124 -32
  25. package/commonjs/Input/styles.js +1 -1
  26. package/commonjs/Message/styles.js +1 -1
  27. package/commonjs/TokenInput/index.js +1 -1
  28. package/commonjs/themes/dark/theme.js +4 -1
  29. package/commonjs/themes/light/theme.js +4 -1
  30. package/commonjs/utils/index.js +29 -2
  31. package/dist/themes/dark/dark.scss +4 -1
  32. package/dist/themes/light/light.scss +4 -1
  33. package/lib/Button/index.js +0 -1
  34. package/lib/Button/styles.js +0 -1
  35. package/lib/Input/index.js +116 -32
  36. package/lib/Input/styles.js +1 -1
  37. package/lib/Message/styles.js +1 -1
  38. package/lib/TokenInput/index.js +1 -1
  39. package/lib/themes/dark/theme.js +4 -1
  40. package/lib/themes/light/theme.js +4 -1
  41. package/lib/utils/index.js +24 -0
  42. package/package.json +20 -24
  43. package/bin/buildNpm.js +0 -58
@@ -7,7 +7,17 @@ var React = _interopRequireWildcard(require("react"));
7
7
 
8
8
  var _styles = _interopRequireWildcard(require("./styles"));
9
9
 
10
- var _excluded = ["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"];
10
+ var _Button = _interopRequireDefault(require("../Button"));
11
+
12
+ var _Icon = _interopRequireDefault(require("../Icon"));
13
+
14
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
15
+
16
+ var _utils = require("../utils");
17
+
18
+ var _excluded = ["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"];
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
21
 
12
22
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
23
 
@@ -21,6 +31,67 @@ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.crea
21
31
 
22
32
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
23
33
 
34
+ var InputContext = /*#__PURE__*/React.createContext({});
35
+ var StyledButton = (0, _styledComponents.default)(_Button.default).withConfig({
36
+ displayName: "Input__StyledButton",
37
+ componentId: "sc-1ck1dnm-0"
38
+ })(["&:hover,&:active{color:", ";}"], function (props) {
39
+ return props.theme.utils.interact(props.theme.colors.icon.base);
40
+ });
41
+
42
+ var ClearButton = function ClearButton() {
43
+ var _React$useContext = React.useContext(InputContext),
44
+ onClear = _React$useContext.onClear,
45
+ handleClear = _React$useContext.handleClear,
46
+ clearButtonLabel = _React$useContext.clearButtonLabel,
47
+ hasValue = _React$useContext.hasValue,
48
+ inputSize = _React$useContext.size; // Hide the button when there is no text to clear.
49
+
50
+
51
+ if (!hasValue) {
52
+ 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
+ } // Warn if clearButtonLabel is not included, so that the unlocalized fallback will not be mistaken for a proper label.
61
+
62
+
63
+ if (!clearButtonLabel) {
64
+ console.warn("Warning: clearButtonLabel prop is required when using Input.ClearButton. Please pass a localized clearButtonLabel to Input.");
65
+ } // Reduce Button padding for size small Inputs so that the Button won't go outside the bounds of the Input.
66
+ // This adjustment is handled automatically for default and large Inputs via Button's size. There is no "small" Button.
67
+
68
+
69
+ var py = inputSize === "small" ? 100 : undefined;
70
+ var px = inputSize === "small" ? 200 : undefined;
71
+ var buttonSize = inputSize === "small" ? "default" : inputSize;
72
+ return /*#__PURE__*/React.createElement(StyledButton, {
73
+ onClick: handleClear,
74
+ size: buttonSize,
75
+ py: py,
76
+ px: px,
77
+ title: clearButtonLabel || "Clear",
78
+ ariaLabel: clearButtonLabel || "Clear",
79
+ color: "icon.base"
80
+ }, /*#__PURE__*/React.createElement(_Icon.default, {
81
+ name: "circlex"
82
+ }));
83
+ }; // Used for positioning elementAfter. This logic will detect if the element is a ClearButton,
84
+ // regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
85
+
86
+
87
+ var isClearButton = function isClearButton(elem) {
88
+ if (elem != null && elem.type) {
89
+ return elem.type.displayName === "Input.ClearButton";
90
+ }
91
+
92
+ return false;
93
+ };
94
+
24
95
  var Input = /*#__PURE__*/function (_React$Component) {
25
96
  _inheritsLoose(Input, _React$Component);
26
97
 
@@ -32,41 +103,37 @@ var Input = /*#__PURE__*/function (_React$Component) {
32
103
  }
33
104
 
34
105
  _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
106
+ _this.inputRef = /*#__PURE__*/React.createRef();
35
107
 
36
108
  _this.handleBlur = function (e) {
37
- if (_this.props.onBlur) {
38
- _this.props.onBlur(e);
39
- }
109
+ return _this.props.onBlur == null ? void 0 : _this.props.onBlur(e);
110
+ };
111
+
112
+ _this.handleClear = function (e) {
113
+ var _this$inputRef, _this$inputRef$curren;
114
+
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);
40
117
  };
41
118
 
42
119
  _this.handleChange = function (e) {
43
- if (_this.props.onChange) {
44
- _this.props.onChange(e, e.currentTarget.value);
45
- }
120
+ return _this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
46
121
  };
47
122
 
48
123
  _this.handleFocus = function (e) {
49
- if (_this.props.onFocus) {
50
- _this.props.onFocus(e);
51
- }
124
+ return _this.props.onFocus == null ? void 0 : _this.props.onFocus(e);
52
125
  };
53
126
 
54
127
  _this.handleKeyDown = function (e) {
55
- if (_this.props.onKeyDown) {
56
- _this.props.onKeyDown(e, e.currentTarget.value);
57
- }
128
+ return _this.props.onKeyDown == null ? void 0 : _this.props.onKeyDown(e, e.currentTarget.value);
58
129
  };
59
130
 
60
131
  _this.handleKeyUp = function (e) {
61
- if (_this.props.onKeyUp) {
62
- _this.props.onKeyUp(e, e.currentTarget.value);
63
- }
132
+ return _this.props.onKeyUp == null ? void 0 : _this.props.onKeyUp(e, e.currentTarget.value);
64
133
  };
65
134
 
66
135
  _this.handlePaste = function (e) {
67
- if (_this.props.onPaste) {
68
- _this.props.onPaste(e, e.currentTarget.value);
69
- }
136
+ return _this.props.onPaste == null ? void 0 : _this.props.onPaste(e, e.currentTarget.value);
70
137
  };
71
138
 
72
139
  return _this;
@@ -93,9 +160,11 @@ var Input = /*#__PURE__*/function (_React$Component) {
93
160
  maxLength = _this$props.maxLength,
94
161
  ariaLabel = _this$props.ariaLabel,
95
162
  ariaDescribedby = _this$props.ariaDescribedby,
163
+ clearButtonLabel = _this$props.clearButtonLabel,
96
164
  innerRef = _this$props.innerRef,
97
165
  onBlur = _this$props.onBlur,
98
166
  onChange = _this$props.onChange,
167
+ onClear = _this$props.onClear,
99
168
  onFocus = _this$props.onFocus,
100
169
  onKeyDown = _this$props.onKeyDown,
101
170
  onKeyUp = _this$props.onKeyUp,
@@ -105,25 +174,44 @@ var Input = /*#__PURE__*/function (_React$Component) {
105
174
  _this$props$qa = _this$props.qa,
106
175
  qa = _this$props$qa === void 0 ? {} : _this$props$qa,
107
176
  appearance = _this$props.appearance,
108
- rest = _objectWithoutPropertiesLoose(_this$props, _excluded);
177
+ size = _this$props.size,
178
+ rest = _objectWithoutPropertiesLoose(_this$props, _excluded); // Convert autoComplete from a boolean prop to a string value.
179
+
109
180
 
110
181
  var autoCompleteValue = undefined;
111
182
 
112
183
  if (autoComplete !== undefined) {
113
184
  autoCompleteValue = autoComplete ? "on" : "off";
114
- }
185
+ } // Add default elemBefore and elemAfter elements if type is search.
186
+
115
187
 
188
+ var elementBefore = type === "search" && !elemBefore ? /*#__PURE__*/React.createElement(_Icon.default, {
189
+ name: "search",
190
+ ariaHidden: true,
191
+ color: "icon.base"
192
+ }) : elemBefore; // Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
193
+
194
+ var elementAfter = type === "search" && onClear && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
116
195
  return /*#__PURE__*/React.createElement(_styles.default, _extends({
117
- hasBeforeElement: !!elemBefore,
118
- hasAfterElement: !!elemAfter,
196
+ hasBeforeElement: !!elementBefore,
197
+ hasAfterElement: !!elementAfter,
119
198
  disabled: disabled,
120
199
  invalid: !!isInvalid,
121
200
  warning: hasWarning,
122
- appearance: appearance // $FlowIssue - upgrade v0.112.0
201
+ appearance: appearance,
202
+ size: size // $FlowIssue - upgrade v0.112.0
123
203
 
124
- }, rest), elemBefore && /*#__PURE__*/React.createElement(_styles.Accessory, {
204
+ }, rest), /*#__PURE__*/React.createElement(InputContext.Provider, {
205
+ value: {
206
+ handleClear: this.handleClear,
207
+ hasValue: !!value,
208
+ clearButtonLabel: clearButtonLabel,
209
+ onClear: onClear,
210
+ size: size
211
+ }
212
+ }, elementBefore && /*#__PURE__*/React.createElement(_styles.Accessory, {
125
213
  before: true
126
- }, elemBefore), /*#__PURE__*/React.createElement("input", _extends({
214
+ }, elementBefore), /*#__PURE__*/React.createElement("input", _extends({
127
215
  "aria-invalid": !!isInvalid,
128
216
  "aria-label": ariaLabel,
129
217
  "aria-describedby": ariaDescribedby,
@@ -144,23 +232,27 @@ var Input = /*#__PURE__*/function (_React$Component) {
144
232
  onKeyDown: this.handleKeyDown,
145
233
  onKeyUp: this.handleKeyUp,
146
234
  onPaste: this.handlePaste,
147
- ref: innerRef,
235
+ ref: (0, _utils.mergeRefs)([innerRef, this.inputRef]),
148
236
  "data-qa-input": name || "",
149
237
  "data-qa-input-isdisabled": disabled === true,
150
238
  "data-qa-input-isrequired": required === true
151
- }, qa, inputProps)), elemAfter && /*#__PURE__*/React.createElement(_styles.Accessory, {
152
- after: true
153
- }, elemAfter));
239
+ }, qa, inputProps)), elementAfter && /*#__PURE__*/React.createElement(_styles.Accessory, {
240
+ after: true,
241
+ isClearButton: isClearButton(elementAfter)
242
+ }, elementAfter)));
154
243
  };
155
244
 
156
245
  return Input;
157
246
  }(React.Component);
158
247
 
159
- exports.default = Input;
160
248
  Input.defaultProps = {
161
249
  autoFocus: false,
162
250
  disabled: false,
163
251
  type: "text",
164
252
  size: "default",
165
253
  appearance: "primary"
166
- };
254
+ };
255
+ Input.ClearButton = ClearButton;
256
+ Input.ClearButton.displayName = "Input.ClearButton";
257
+ var _default = Input;
258
+ exports.default = _default;
@@ -86,7 +86,7 @@ var Accessory = _styledComponents.default.div.withConfig({
86
86
  }, function (props) {
87
87
  return props.before && (0, _styledComponents.css)(["left:", ";"], props.theme.space[350]);
88
88
  }, function (props) {
89
- return props.after && (0, _styledComponents.css)(["right:", ";"], props.theme.space[350]);
89
+ return props.after && (0, _styledComponents.css)(["right:", ";"], props.isClearButton ? 0 : props.theme.space[350]);
90
90
  });
91
91
 
92
92
  exports.Accessory = Accessory;
@@ -105,7 +105,7 @@ exports.MessageBody = MessageBody;
105
105
  var MessageFooter = (0, _styledComponents.default)(_Box.default).withConfig({
106
106
  displayName: "styles__MessageFooter",
107
107
  componentId: "sc-1ju6d1v-3"
108
- })(["padding-bottom:", ";padding-left:", ";padding-right:", ";border-radius:0 0 ", " ", ";display:flex;justify-content:space-between;align-items:center;flex-wrap:", ";> :first-child{margin-left:-", ";}"], function (props) {
108
+ })(["padding-bottom:", ";padding-left:", ";padding-right:", ";border-radius:0 0 ", " ", ";display:flex;justify-content:space-between;align-items:center;flex-wrap:", ";>:first-child{margin-left:-", ";}"], function (props) {
109
109
  return props.density === _Message.default.DENSITIES.CONDENSED ? 0 : props.theme.space[300];
110
110
  }, function (props) {
111
111
  return getContentPadding(props);
@@ -302,7 +302,7 @@ var TokenInput = /*#__PURE__*/function (_React$Component) {
302
302
  "aria-invalid": !!isInvalid,
303
303
  "aria-label": ariaLabel,
304
304
  autoFocus: autoFocus,
305
- autocomplete: autocomplete,
305
+ autoComplete: autocomplete,
306
306
  disabled: disabled,
307
307
  id: id,
308
308
  name: name,
@@ -175,7 +175,10 @@ var colors = _extends({}, _theme.default.colors, {
175
175
  subtext: _seedsColor.default.COLOR_NEUTRAL_300,
176
176
  body: _seedsColor.default.COLOR_NEUTRAL_100,
177
177
  inverse: _seedsColor.default.COLOR_NEUTRAL_900,
178
- error: _seedsColor.default.COLOR_RED_400
178
+ error: _seedsColor.default.COLOR_RED_400,
179
+ background: {
180
+ highlight: _seedsColor.default.COLOR_YELLOW_900
181
+ }
179
182
  },
180
183
  icon: {
181
184
  base: _seedsColor.default.COLOR_NEUTRAL_100,
@@ -177,7 +177,10 @@ var colors = _extends({
177
177
  subtext: _seedsColor.default.COLOR_NEUTRAL_700,
178
178
  body: _seedsColor.default.COLOR_NEUTRAL_800,
179
179
  inverse: _seedsColor.default.COLOR_NEUTRAL_0,
180
- error: _seedsColor.default.COLOR_RED_800
180
+ error: _seedsColor.default.COLOR_RED_800,
181
+ background: {
182
+ highlight: _seedsColor.default.COLOR_YELLOW_200
183
+ }
181
184
  },
182
185
  icon: {
183
186
  base: _seedsColor.default.COLOR_NEUTRAL_800,
@@ -1,10 +1,37 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.canUseDOM = void 0;
4
+ exports.mergeRefs = exports.canUseDOM = void 0;
5
+
6
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+
8
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9
+
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
5
11
 
6
12
  var canUseDOM = function canUseDOM() {
7
13
  return Boolean(typeof window !== "undefined" && window.document && window.document.createElement);
8
14
  };
9
15
 
10
- exports.canUseDOM = canUseDOM;
16
+ exports.canUseDOM = canUseDOM;
17
+
18
+ // Allows a component to pass its own ref *and* a ref prop to the same element.
19
+ // Via https://www.davedrinks.coffee/how-do-i-use-two-react-refs/
20
+ var mergeRefs = function mergeRefs(refs) {
21
+ var filteredRefs = refs.filter(Boolean);
22
+ if (!filteredRefs.length) return null;
23
+ if (filteredRefs.length === 0) return filteredRefs[0];
24
+ return function (inst) {
25
+ for (var _iterator = _createForOfIteratorHelperLoose(filteredRefs), _step; !(_step = _iterator()).done;) {
26
+ var ref = _step.value;
27
+
28
+ if (typeof ref === "function") {
29
+ ref(inst);
30
+ } else if (ref) {
31
+ ref.current = inst;
32
+ }
33
+ }
34
+ };
35
+ };
36
+
37
+ exports.mergeRefs = mergeRefs;
@@ -147,7 +147,10 @@ $dark: (
147
147
  subtext: #c8cccc,
148
148
  body: #f3f4f4,
149
149
  inverse: #273333,
150
- error: #ff7f6e
150
+ error: #ff7f6e,
151
+ background: (
152
+ highlight: #944c0c
153
+ )
151
154
  ),
152
155
  icon: (
153
156
  base: #f3f4f4,
@@ -154,7 +154,10 @@ $light: (
154
154
  subtext: #515e5f,
155
155
  body: #364141,
156
156
  inverse: #FFFFFF,
157
- error: #c63434
157
+ error: #c63434,
158
+ background: (
159
+ highlight: #ffe99a
160
+ )
158
161
  ),
159
162
  icon: (
160
163
  base: #364141,
@@ -53,5 +53,4 @@ var Button = function Button(_ref) {
53
53
  }, qa, rest), children);
54
54
  };
55
55
 
56
- Button.displayName = "Button";
57
56
  export default Button;
@@ -44,5 +44,4 @@ var Container = styled.button.withConfig({
44
44
  }, function (props) {
45
45
  return props.appearance === "pill" && css(["display:inline-flex;align-items:center;justify-content:center;mix-blend-mode:", ";", ""], props.theme.mode === "dark" ? "screen" : "multiply", pill);
46
46
  }, Icon, LAYOUT, COMMON);
47
- Container.displayName = "Button-Container";
48
47
  export default Container; //${props.theme.mode === "dark" ? "screen" : "multiply"}
@@ -1,4 +1,4 @@
1
- var _excluded = ["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"];
1
+ var _excluded = ["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"];
2
2
 
3
3
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
4
 
@@ -10,6 +10,70 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func
10
10
 
11
11
  import * as React from "react";
12
12
  import Container, { Accessory } from "./styles";
13
+ import Button from "../Button";
14
+ import Icon from "../Icon";
15
+ import styled from "styled-components";
16
+ import { mergeRefs } from "../utils";
17
+ var InputContext = /*#__PURE__*/React.createContext({});
18
+ var StyledButton = styled(Button).withConfig({
19
+ displayName: "Input__StyledButton",
20
+ componentId: "sc-1ck1dnm-0"
21
+ })(["&:hover,&:active{color:", ";}"], function (props) {
22
+ return props.theme.utils.interact(props.theme.colors.icon.base);
23
+ });
24
+
25
+ var ClearButton = function ClearButton() {
26
+ var _React$useContext = React.useContext(InputContext),
27
+ onClear = _React$useContext.onClear,
28
+ handleClear = _React$useContext.handleClear,
29
+ clearButtonLabel = _React$useContext.clearButtonLabel,
30
+ hasValue = _React$useContext.hasValue,
31
+ inputSize = _React$useContext.size; // Hide the button when there is no text to clear.
32
+
33
+
34
+ if (!hasValue) {
35
+ 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
+ } // Warn if clearButtonLabel is not included, so that the unlocalized fallback will not be mistaken for a proper label.
44
+
45
+
46
+ if (!clearButtonLabel) {
47
+ console.warn("Warning: clearButtonLabel prop is required when using Input.ClearButton. Please pass a localized clearButtonLabel to Input.");
48
+ } // Reduce Button padding for size small Inputs so that the Button won't go outside the bounds of the Input.
49
+ // This adjustment is handled automatically for default and large Inputs via Button's size. There is no "small" Button.
50
+
51
+
52
+ var py = inputSize === "small" ? 100 : undefined;
53
+ var px = inputSize === "small" ? 200 : undefined;
54
+ var buttonSize = inputSize === "small" ? "default" : inputSize;
55
+ return /*#__PURE__*/React.createElement(StyledButton, {
56
+ onClick: handleClear,
57
+ size: buttonSize,
58
+ py: py,
59
+ px: px,
60
+ title: clearButtonLabel || "Clear",
61
+ ariaLabel: clearButtonLabel || "Clear",
62
+ color: "icon.base"
63
+ }, /*#__PURE__*/React.createElement(Icon, {
64
+ name: "circlex"
65
+ }));
66
+ }; // Used for positioning elementAfter. This logic will detect if the element is a ClearButton,
67
+ // regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
68
+
69
+
70
+ var isClearButton = function isClearButton(elem) {
71
+ if (elem != null && elem.type) {
72
+ return elem.type.displayName === "Input.ClearButton";
73
+ }
74
+
75
+ return false;
76
+ };
13
77
 
14
78
  var Input = /*#__PURE__*/function (_React$Component) {
15
79
  _inheritsLoose(Input, _React$Component);
@@ -22,41 +86,37 @@ var Input = /*#__PURE__*/function (_React$Component) {
22
86
  }
23
87
 
24
88
  _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
89
+ _this.inputRef = /*#__PURE__*/React.createRef();
25
90
 
26
91
  _this.handleBlur = function (e) {
27
- if (_this.props.onBlur) {
28
- _this.props.onBlur(e);
29
- }
92
+ return _this.props.onBlur == null ? void 0 : _this.props.onBlur(e);
93
+ };
94
+
95
+ _this.handleClear = function (e) {
96
+ var _this$inputRef, _this$inputRef$curren;
97
+
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);
30
100
  };
31
101
 
32
102
  _this.handleChange = function (e) {
33
- if (_this.props.onChange) {
34
- _this.props.onChange(e, e.currentTarget.value);
35
- }
103
+ return _this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
36
104
  };
37
105
 
38
106
  _this.handleFocus = function (e) {
39
- if (_this.props.onFocus) {
40
- _this.props.onFocus(e);
41
- }
107
+ return _this.props.onFocus == null ? void 0 : _this.props.onFocus(e);
42
108
  };
43
109
 
44
110
  _this.handleKeyDown = function (e) {
45
- if (_this.props.onKeyDown) {
46
- _this.props.onKeyDown(e, e.currentTarget.value);
47
- }
111
+ return _this.props.onKeyDown == null ? void 0 : _this.props.onKeyDown(e, e.currentTarget.value);
48
112
  };
49
113
 
50
114
  _this.handleKeyUp = function (e) {
51
- if (_this.props.onKeyUp) {
52
- _this.props.onKeyUp(e, e.currentTarget.value);
53
- }
115
+ return _this.props.onKeyUp == null ? void 0 : _this.props.onKeyUp(e, e.currentTarget.value);
54
116
  };
55
117
 
56
118
  _this.handlePaste = function (e) {
57
- if (_this.props.onPaste) {
58
- _this.props.onPaste(e, e.currentTarget.value);
59
- }
119
+ return _this.props.onPaste == null ? void 0 : _this.props.onPaste(e, e.currentTarget.value);
60
120
  };
61
121
 
62
122
  return _this;
@@ -83,9 +143,11 @@ var Input = /*#__PURE__*/function (_React$Component) {
83
143
  maxLength = _this$props.maxLength,
84
144
  ariaLabel = _this$props.ariaLabel,
85
145
  ariaDescribedby = _this$props.ariaDescribedby,
146
+ clearButtonLabel = _this$props.clearButtonLabel,
86
147
  innerRef = _this$props.innerRef,
87
148
  onBlur = _this$props.onBlur,
88
149
  onChange = _this$props.onChange,
150
+ onClear = _this$props.onClear,
89
151
  onFocus = _this$props.onFocus,
90
152
  onKeyDown = _this$props.onKeyDown,
91
153
  onKeyUp = _this$props.onKeyUp,
@@ -95,25 +157,44 @@ var Input = /*#__PURE__*/function (_React$Component) {
95
157
  _this$props$qa = _this$props.qa,
96
158
  qa = _this$props$qa === void 0 ? {} : _this$props$qa,
97
159
  appearance = _this$props.appearance,
98
- rest = _objectWithoutPropertiesLoose(_this$props, _excluded);
160
+ size = _this$props.size,
161
+ rest = _objectWithoutPropertiesLoose(_this$props, _excluded); // Convert autoComplete from a boolean prop to a string value.
162
+
99
163
 
100
164
  var autoCompleteValue = undefined;
101
165
 
102
166
  if (autoComplete !== undefined) {
103
167
  autoCompleteValue = autoComplete ? "on" : "off";
104
- }
168
+ } // Add default elemBefore and elemAfter elements if type is search.
105
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;
106
178
  return /*#__PURE__*/React.createElement(Container, _extends({
107
- hasBeforeElement: !!elemBefore,
108
- hasAfterElement: !!elemAfter,
179
+ hasBeforeElement: !!elementBefore,
180
+ hasAfterElement: !!elementAfter,
109
181
  disabled: disabled,
110
182
  invalid: !!isInvalid,
111
183
  warning: hasWarning,
112
- appearance: appearance // $FlowIssue - upgrade v0.112.0
113
-
114
- }, 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, {
115
196
  before: true
116
- }, elemBefore), /*#__PURE__*/React.createElement("input", _extends({
197
+ }, elementBefore), /*#__PURE__*/React.createElement("input", _extends({
117
198
  "aria-invalid": !!isInvalid,
118
199
  "aria-label": ariaLabel,
119
200
  "aria-describedby": ariaDescribedby,
@@ -134,13 +215,14 @@ var Input = /*#__PURE__*/function (_React$Component) {
134
215
  onKeyDown: this.handleKeyDown,
135
216
  onKeyUp: this.handleKeyUp,
136
217
  onPaste: this.handlePaste,
137
- ref: innerRef,
218
+ ref: mergeRefs([innerRef, this.inputRef]),
138
219
  "data-qa-input": name || "",
139
220
  "data-qa-input-isdisabled": disabled === true,
140
221
  "data-qa-input-isrequired": required === true
141
- }, qa, inputProps)), elemAfter && /*#__PURE__*/React.createElement(Accessory, {
142
- after: true
143
- }, elemAfter));
222
+ }, qa, inputProps)), elementAfter && /*#__PURE__*/React.createElement(Accessory, {
223
+ after: true,
224
+ isClearButton: isClearButton(elementAfter)
225
+ }, elementAfter)));
144
226
  };
145
227
 
146
228
  return Input;
@@ -153,4 +235,6 @@ Input.defaultProps = {
153
235
  size: "default",
154
236
  appearance: "primary"
155
237
  };
156
- export { Input as default };
238
+ Input.ClearButton = ClearButton;
239
+ Input.ClearButton.displayName = "Input.ClearButton";
240
+ 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";
@@ -91,7 +91,7 @@ export var MessageBody = styled(Box).withConfig({
91
91
  export var MessageFooter = styled(Box).withConfig({
92
92
  displayName: "styles__MessageFooter",
93
93
  componentId: "sc-1ju6d1v-3"
94
- })(["padding-bottom:", ";padding-left:", ";padding-right:", ";border-radius:0 0 ", " ", ";display:flex;justify-content:space-between;align-items:center;flex-wrap:", ";> :first-child{margin-left:-", ";}"], function (props) {
94
+ })(["padding-bottom:", ";padding-left:", ";padding-right:", ";border-radius:0 0 ", " ", ";display:flex;justify-content:space-between;align-items:center;flex-wrap:", ";>:first-child{margin-left:-", ";}"], function (props) {
95
95
  return props.density === Message.DENSITIES.CONDENSED ? 0 : props.theme.space[300];
96
96
  }, function (props) {
97
97
  return getContentPadding(props);
@@ -284,7 +284,7 @@ var TokenInput = /*#__PURE__*/function (_React$Component) {
284
284
  "aria-invalid": !!isInvalid,
285
285
  "aria-label": ariaLabel,
286
286
  autoFocus: autoFocus,
287
- autocomplete: autocomplete,
287
+ autoComplete: autocomplete,
288
288
  disabled: disabled,
289
289
  id: id,
290
290
  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,
@@ -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,