@sproutsocial/racine 11.3.0-beta.0 → 11.3.0-beta.3

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.
@@ -1,35 +1,20 @@
1
- import styled, { css } from "styled-components";
1
+ import styled from "styled-components";
2
2
  import { COMMON } from "../utils/system-props";
3
3
  import { themeGet } from "@styled-system/theme-get";
4
- var colors = {
5
- primary: "colors.neutral.0",
6
- secondary: "colors.neutral.800",
7
- passive: "colors.neutral.800",
8
- common: "colors.neutral.0",
9
- approval: "colors.neutral.800",
10
- default: "colors.neutral.0",
11
- suggestion: "colors.neutral.900"
12
- };
13
- var backgroundColors = {
14
- primary: "colors.blue.700",
15
- secondary: "colors.yellow.500",
16
- passive: "colors.neutral.200",
17
- common: "colors.aqua.600",
18
- approval: "colors.orange.300",
19
- default: "colors.purple.700",
20
- suggestion: "colors.blue.300"
21
- }; // eslint-disable-next-line prettier/prettier
4
+ import { legacyBadgeColors } from "./constants"; // eslint-disable-next-line prettier/prettier
22
5
 
23
6
  var Container = styled.span.withConfig({
24
7
  displayName: "styles__Container",
25
8
  componentId: "sc-g1g76b-0"
26
- })(["display:inline-block;text-align:center;border-radius:50px;font-family:", ";padding:", ";", " ", " ", ""], function (props) {
27
- return props.theme.fontFamily;
28
- }, function (props) {
29
- return props.small ? props.theme.space[200] + " " + props.theme.space[300] : props.theme.space[300] + " " + props.theme.space[350];
30
- }, function (props) {
31
- return props.small ? props.theme.typography[100] : props.theme.typography[200];
32
- }, function (props) {
33
- return css(["color:", ";background:", ";"], themeGet(colors[props.type])(props), themeGet(backgroundColors[props.type])(props));
9
+ })(["font-family:", ";", ";border-radius:9999px;line-height:16px;display:inline-block;color:", ";background:", ";padding:", ";", ";"], function (p) {
10
+ return p.theme.fontFamily;
11
+ }, function (p) {
12
+ return p.size === "small" ? p.theme.typography[100] : p.theme.typography[200];
13
+ }, function (p) {
14
+ return p.type ? themeGet(legacyBadgeColors[p.type].color) : p.theme.colors.text.body;
15
+ }, function (p) {
16
+ return p.type ? themeGet(legacyBadgeColors[p.type].background) : p.theme.colors.container.background.decorative[p.badgeColor];
17
+ }, function (p) {
18
+ return p.size === "small" ? p.theme.space[0] + " " + p.theme.space[200] : "" + p.theme.space[300];
34
19
  }, COMMON);
35
20
  export default Container;
@@ -1,4 +1,4 @@
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"];
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
 
@@ -17,14 +17,44 @@ var InputContext = /*#__PURE__*/React.createContext({});
17
17
  var ClearButton = function ClearButton() {
18
18
  var _React$useContext = React.useContext(InputContext),
19
19
  handleClear = _React$useContext.handleClear,
20
- clearButtonLabel = _React$useContext.clearButtonLabel;
20
+ clearButtonLabel = _React$useContext.clearButtonLabel,
21
+ hasValue = _React$useContext.hasValue,
22
+ size = _React$useContext.size; // Hide the button when there is no text to clear.
23
+
24
+
25
+ if (!hasValue) {
26
+ return null;
27
+ } // Cut down the padding for size small Inputs so that the focus ring won't go outside the bounds of the Input.
28
+ // This adjustment is handled automatically for default and large Inputs via Button's size. There is no "small" Button.
29
+
30
+
31
+ var py = size === "small" ? 100 : undefined;
32
+ var px = size === "small" ? 200 : undefined;
33
+ var buttonSize = size === "small" ? "default" : size; // Warn if clearButtonLabel is not included, so that the unlocalized fallback will not be mistaken for a proper label.
34
+
35
+ if (!clearButtonLabel) {
36
+ console.warn("Warning: clearButtonLabel prop is required when using Input.ClearButton. Please pass a localized label to Input.");
37
+ }
21
38
 
22
39
  return /*#__PURE__*/React.createElement(Button, {
23
- onClick: handleClear
40
+ onClick: handleClear,
41
+ size: buttonSize,
42
+ py: py,
43
+ px: px
24
44
  }, /*#__PURE__*/React.createElement(Icon, {
25
45
  name: "circlex",
26
46
  title: clearButtonLabel || "Clear"
27
47
  }));
48
+ }; // Used for positioning elementAfter. This logic will detect if the element is a ClearButton,
49
+ // regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
50
+
51
+
52
+ var isClearButton = function isClearButton(elem) {
53
+ if (elem != null && elem.type) {
54
+ return elem.type.displayName === "Input.ClearButton";
55
+ }
56
+
57
+ return false;
28
58
  };
29
59
 
30
60
  var Input = /*#__PURE__*/function (_React$Component) {
@@ -44,11 +74,10 @@ var Input = /*#__PURE__*/function (_React$Component) {
44
74
  };
45
75
 
46
76
  _this.handleClear = function (e) {
47
- if (_this.props.onClear) {
48
- _this.props.onClear(e);
49
- } else if (_this.props.onChange) {
50
- _this.props.onChange(e, "");
51
- }
77
+ var _this$props$innerRef, _this$props$innerRef$;
78
+
79
+ _this.props.onClear == null ? void 0 : _this.props.onClear(e);
80
+ (_this$props$innerRef = _this.props.innerRef) == null ? void 0 : (_this$props$innerRef$ = _this$props$innerRef.current) == null ? void 0 : _this$props$innerRef$.focus();
52
81
  };
53
82
 
54
83
  _this.handleChange = function (e) {
@@ -77,8 +106,6 @@ var Input = /*#__PURE__*/function (_React$Component) {
77
106
  var _proto = Input.prototype;
78
107
 
79
108
  _proto.render = function render() {
80
- var _elementAfter$type;
81
-
82
109
  var _this$props = this.props,
83
110
  autoComplete = _this$props.autoComplete,
84
111
  autoFocus = _this$props.autoFocus,
@@ -111,6 +138,7 @@ var Input = /*#__PURE__*/function (_React$Component) {
111
138
  _this$props$qa = _this$props.qa,
112
139
  qa = _this$props$qa === void 0 ? {} : _this$props$qa,
113
140
  appearance = _this$props.appearance,
141
+ size = _this$props.size,
114
142
  rest = _objectWithoutPropertiesLoose(_this$props, _excluded); // Convert autoComplete from a boolean prop to a string value.
115
143
 
116
144
 
@@ -123,21 +151,26 @@ var Input = /*#__PURE__*/function (_React$Component) {
123
151
 
124
152
  var elementBefore = type === "search" && !elemBefore ? /*#__PURE__*/React.createElement(Icon, {
125
153
  name: "search",
126
- ariaHidden: true
127
- }) : elemBefore;
128
- var elementAfter = type === "search" && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
154
+ ariaHidden: true,
155
+ color: "icon.base"
156
+ }) : elemBefore; // Do not add a ClearButton if no onClear callback is provided or if an elemAfter prop was passed.
157
+
158
+ var elementAfter = type === "search" && onClear && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
129
159
  return /*#__PURE__*/React.createElement(Container, _extends({
130
160
  hasBeforeElement: !!elementBefore,
131
161
  hasAfterElement: !!elementAfter,
132
162
  disabled: disabled,
133
163
  invalid: !!isInvalid,
134
164
  warning: hasWarning,
135
- appearance: appearance // $FlowIssue - upgrade v0.112.0
165
+ appearance: appearance,
166
+ size: size // $FlowIssue - upgrade v0.112.0
136
167
 
137
168
  }, rest), /*#__PURE__*/React.createElement(InputContext.Provider, {
138
169
  value: {
139
170
  handleClear: this.handleClear,
140
- clearButtonLabel: clearButtonLabel
171
+ hasValue: !!value,
172
+ clearButtonLabel: clearButtonLabel,
173
+ size: size
141
174
  }
142
175
  }, elementBefore && /*#__PURE__*/React.createElement(Accessory, {
143
176
  before: true
@@ -167,10 +200,8 @@ var Input = /*#__PURE__*/function (_React$Component) {
167
200
  "data-qa-input-isdisabled": disabled === true,
168
201
  "data-qa-input-isrequired": required === true
169
202
  }, qa, inputProps)), elementAfter && /*#__PURE__*/React.createElement(Accessory, {
170
- after: true // Used for positioning. This logic will detect if the element is a ClearButton,
171
- // regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
172
- ,
173
- isClearButton: (elementAfter == null ? void 0 : (_elementAfter$type = elementAfter.type) == null ? void 0 : _elementAfter$type.prototype) === Input.ClearButton.prototype
203
+ after: true,
204
+ isClearButton: isClearButton(elementAfter)
174
205
  }, elementAfter)));
175
206
  };
176
207
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sproutsocial/racine",
3
- "version": "11.3.0-beta.0",
3
+ "version": "11.3.0-beta.3",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "__flow__",