@sproutsocial/racine 11.3.0-beta.3 → 11.3.0-beta.6
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.
- package/__flow__/Input/index.js +53 -14
- package/__flow__/Menu/index.js +0 -1
- package/commonjs/Input/index.js +35 -15
- package/commonjs/Menu/index.js +0 -1
- package/lib/Input/index.js +34 -15
- package/lib/Menu/index.js +0 -1
- package/package.json +1 -1
package/__flow__/Input/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import Container, { Accessory } from "./styles";
|
|
4
4
|
import Button from "../Button";
|
|
5
5
|
import Icon from "../Icon";
|
|
6
|
+
import styled from "styled-components";
|
|
6
7
|
|
|
7
8
|
type TypeProps = {
|
|
8
9
|
/** ID of the form element, should match the "for" value of the associated label */
|
|
@@ -43,10 +44,13 @@ type TypeProps = {
|
|
|
43
44
|
/** Props to spread onto the underlying input element */
|
|
44
45
|
inputProps?: any,
|
|
45
46
|
/** Used to get a reference to the underlying element */
|
|
46
|
-
innerRef?:
|
|
47
|
+
innerRef?:
|
|
48
|
+
| {| current: HTMLInputElement | null | undefined |}
|
|
49
|
+
| ((React.ElementRef<any> | HTMLInputElement) => mixed),
|
|
47
50
|
onBlur?: (e: SyntheticFocusEvent<HTMLInputElement>) => void,
|
|
48
51
|
onChange?: (e: SyntheticInputEvent<HTMLInputElement>, value: string) => void,
|
|
49
|
-
/**
|
|
52
|
+
/** Input.ClearButton onClick callback. Required when using <Input type="search"/> or <Input.ClearButton/>.
|
|
53
|
+
The component handles returning focus to Input after onClear is called only. You must reset "value" yourself.*/
|
|
50
54
|
onClear?: (e: SyntheticEvent<HTMLButtonElement>) => void,
|
|
51
55
|
onFocus?: (e: SyntheticFocusEvent<HTMLInputElement>) => void,
|
|
52
56
|
onKeyDown?: (
|
|
@@ -70,38 +74,71 @@ type TypeProps = {
|
|
|
70
74
|
// Using Context so that Input's Input.ClearButton-specific props can be passed to Input.ClearButton,
|
|
71
75
|
// regardless of whether it is manually included as elemAfter or automatically included for type="search" Inputs.
|
|
72
76
|
type TypeInputContext = $Shape<{
|
|
77
|
+
onClear?: (e: SyntheticEvent<HTMLButtonElement>) => void,
|
|
73
78
|
handleClear: (e: SyntheticEvent<HTMLButtonElement>) => void,
|
|
74
79
|
clearButtonLabel: string,
|
|
75
80
|
hasValue: boolean,
|
|
81
|
+
size: "large" | "small" | "default",
|
|
76
82
|
}>;
|
|
77
83
|
|
|
78
84
|
const InputContext = React.createContext<TypeInputContext>({});
|
|
79
85
|
|
|
86
|
+
const StyledButton = styled(Button)`
|
|
87
|
+
&:hover,
|
|
88
|
+
&:active {
|
|
89
|
+
color: ${(props) =>
|
|
90
|
+
props.theme.utils.interact(props.theme.colors.icon.base)};
|
|
91
|
+
}
|
|
92
|
+
`;
|
|
93
|
+
|
|
80
94
|
const ClearButton = () => {
|
|
81
|
-
const {
|
|
82
|
-
|
|
95
|
+
const {
|
|
96
|
+
onClear,
|
|
97
|
+
handleClear,
|
|
98
|
+
clearButtonLabel,
|
|
99
|
+
hasValue,
|
|
100
|
+
size: inputSize,
|
|
101
|
+
} = React.useContext(InputContext);
|
|
83
102
|
|
|
84
103
|
// Hide the button when there is no text to clear.
|
|
85
104
|
if (!hasValue) {
|
|
86
105
|
return null;
|
|
87
106
|
}
|
|
88
107
|
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
108
|
+
// Log a warning and hide the button when no onClear callback is provided.
|
|
109
|
+
// If we called handleClear with no onClear prop, all the button would do is focus the Input.
|
|
110
|
+
if (!onClear) {
|
|
111
|
+
console.warn(
|
|
112
|
+
"Warning: No onClear prop provided to Input when using Input.ClearButton. Omitting Input.ClearButton."
|
|
113
|
+
);
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
94
116
|
|
|
95
117
|
// Warn if clearButtonLabel is not included, so that the unlocalized fallback will not be mistaken for a proper label.
|
|
96
118
|
if (!clearButtonLabel) {
|
|
97
119
|
console.warn(
|
|
98
|
-
"Warning: clearButtonLabel prop is required when using Input.ClearButton. Please pass a localized
|
|
120
|
+
"Warning: clearButtonLabel prop is required when using Input.ClearButton. Please pass a localized clearButtonLabel to Input."
|
|
99
121
|
);
|
|
100
122
|
}
|
|
123
|
+
|
|
124
|
+
// Reduce Button padding for size small Inputs so that the Button won't go outside the bounds of the Input.
|
|
125
|
+
// This adjustment is handled automatically for default and large Inputs via Button's size. There is no "small" Button.
|
|
126
|
+
const py = inputSize === "small" ? 100 : undefined;
|
|
127
|
+
const px = inputSize === "small" ? 200 : undefined;
|
|
128
|
+
const buttonSize = inputSize === "small" ? "default" : inputSize;
|
|
129
|
+
|
|
101
130
|
return (
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
131
|
+
<StyledButton
|
|
132
|
+
onClick={handleClear}
|
|
133
|
+
size={buttonSize}
|
|
134
|
+
py={py}
|
|
135
|
+
px={px}
|
|
136
|
+
title={clearButtonLabel || "Clear"}
|
|
137
|
+
ariaLabel={clearButtonLabel || "Clear"}
|
|
138
|
+
color="icon.base"
|
|
139
|
+
>
|
|
140
|
+
<Icon name="circlex" />
|
|
141
|
+
</StyledButton>
|
|
105
142
|
);
|
|
106
143
|
};
|
|
107
144
|
|
|
@@ -121,6 +158,7 @@ class Input extends React.Component<TypeProps> {
|
|
|
121
158
|
type: "text",
|
|
122
159
|
size: "default",
|
|
123
160
|
appearance: "primary",
|
|
161
|
+
innerRef: React.createRef<HTMLInputElement>(),
|
|
124
162
|
};
|
|
125
163
|
|
|
126
164
|
static ClearButton = ClearButton;
|
|
@@ -129,8 +167,8 @@ class Input extends React.Component<TypeProps> {
|
|
|
129
167
|
this.props.onBlur?.(e);
|
|
130
168
|
|
|
131
169
|
handleClear = (e: SyntheticEvent<HTMLButtonElement>) => {
|
|
170
|
+
this.props.innerRef.current?.focus();
|
|
132
171
|
this.props.onClear?.(e);
|
|
133
|
-
this.props.innerRef?.current?.focus();
|
|
134
172
|
};
|
|
135
173
|
|
|
136
174
|
handleChange = (e: SyntheticInputEvent<HTMLInputElement>) =>
|
|
@@ -217,6 +255,7 @@ class Input extends React.Component<TypeProps> {
|
|
|
217
255
|
handleClear: this.handleClear,
|
|
218
256
|
hasValue: !!value,
|
|
219
257
|
clearButtonLabel,
|
|
258
|
+
onClear,
|
|
220
259
|
size,
|
|
221
260
|
}}
|
|
222
261
|
>
|
package/__flow__/Menu/index.js
CHANGED
package/commonjs/Input/index.js
CHANGED
|
@@ -11,6 +11,8 @@ var _Button = _interopRequireDefault(require("../Button"));
|
|
|
11
11
|
|
|
12
12
|
var _Icon = _interopRequireDefault(require("../Icon"));
|
|
13
13
|
|
|
14
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
15
|
+
|
|
14
16
|
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"];
|
|
15
17
|
|
|
16
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -28,37 +30,53 @@ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.crea
|
|
|
28
30
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
29
31
|
|
|
30
32
|
var InputContext = /*#__PURE__*/React.createContext({});
|
|
33
|
+
var StyledButton = (0, _styledComponents.default)(_Button.default).withConfig({
|
|
34
|
+
displayName: "Input__StyledButton",
|
|
35
|
+
componentId: "sc-1ck1dnm-0"
|
|
36
|
+
})(["&:hover,&:active{color:", ";}"], function (props) {
|
|
37
|
+
return props.theme.utils.interact(props.theme.colors.icon.base);
|
|
38
|
+
});
|
|
31
39
|
|
|
32
40
|
var ClearButton = function ClearButton() {
|
|
33
41
|
var _React$useContext = React.useContext(InputContext),
|
|
42
|
+
onClear = _React$useContext.onClear,
|
|
34
43
|
handleClear = _React$useContext.handleClear,
|
|
35
44
|
clearButtonLabel = _React$useContext.clearButtonLabel,
|
|
36
45
|
hasValue = _React$useContext.hasValue,
|
|
37
|
-
|
|
46
|
+
inputSize = _React$useContext.size; // Hide the button when there is no text to clear.
|
|
38
47
|
|
|
39
48
|
|
|
40
49
|
if (!hasValue) {
|
|
41
50
|
return null;
|
|
42
|
-
} //
|
|
43
|
-
//
|
|
51
|
+
} // Log a warning and hide the button when no onClear callback is provided.
|
|
52
|
+
// If we called handleClear with no onClear prop, all the button would do is focus the Input.
|
|
44
53
|
|
|
45
54
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
if (!onClear) {
|
|
56
|
+
console.warn("Warning: No onClear prop provided to Input when using Input.ClearButton. Omitting Input.ClearButton.");
|
|
57
|
+
return null;
|
|
58
|
+
} // Warn if clearButtonLabel is not included, so that the unlocalized fallback will not be mistaken for a proper label.
|
|
59
|
+
|
|
49
60
|
|
|
50
61
|
if (!clearButtonLabel) {
|
|
51
|
-
console.warn("Warning: clearButtonLabel prop is required when using Input.ClearButton. Please pass a localized
|
|
52
|
-
}
|
|
62
|
+
console.warn("Warning: clearButtonLabel prop is required when using Input.ClearButton. Please pass a localized clearButtonLabel to Input.");
|
|
63
|
+
} // Reduce Button padding for size small Inputs so that the Button won't go outside the bounds of the Input.
|
|
64
|
+
// This adjustment is handled automatically for default and large Inputs via Button's size. There is no "small" Button.
|
|
65
|
+
|
|
53
66
|
|
|
54
|
-
|
|
67
|
+
var py = inputSize === "small" ? 100 : undefined;
|
|
68
|
+
var px = inputSize === "small" ? 200 : undefined;
|
|
69
|
+
var buttonSize = inputSize === "small" ? "default" : inputSize;
|
|
70
|
+
return /*#__PURE__*/React.createElement(StyledButton, {
|
|
55
71
|
onClick: handleClear,
|
|
56
72
|
size: buttonSize,
|
|
57
73
|
py: py,
|
|
58
|
-
px: px
|
|
74
|
+
px: px,
|
|
75
|
+
title: clearButtonLabel || "Clear",
|
|
76
|
+
ariaLabel: clearButtonLabel || "Clear",
|
|
77
|
+
color: "icon.base"
|
|
59
78
|
}, /*#__PURE__*/React.createElement(_Icon.default, {
|
|
60
|
-
name: "circlex"
|
|
61
|
-
title: clearButtonLabel || "Clear"
|
|
79
|
+
name: "circlex"
|
|
62
80
|
}));
|
|
63
81
|
}; // Used for positioning elementAfter. This logic will detect if the element is a ClearButton,
|
|
64
82
|
// regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
|
|
@@ -89,10 +107,10 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
89
107
|
};
|
|
90
108
|
|
|
91
109
|
_this.handleClear = function (e) {
|
|
92
|
-
var _this$props$innerRef
|
|
110
|
+
var _this$props$innerRef$;
|
|
93
111
|
|
|
112
|
+
(_this$props$innerRef$ = _this.props.innerRef.current) == null ? void 0 : _this$props$innerRef$.focus();
|
|
94
113
|
_this.props.onClear == null ? void 0 : _this.props.onClear(e);
|
|
95
|
-
(_this$props$innerRef = _this.props.innerRef) == null ? void 0 : (_this$props$innerRef$ = _this$props$innerRef.current) == null ? void 0 : _this$props$innerRef$.focus();
|
|
96
114
|
};
|
|
97
115
|
|
|
98
116
|
_this.handleChange = function (e) {
|
|
@@ -185,6 +203,7 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
185
203
|
handleClear: this.handleClear,
|
|
186
204
|
hasValue: !!value,
|
|
187
205
|
clearButtonLabel: clearButtonLabel,
|
|
206
|
+
onClear: onClear,
|
|
188
207
|
size: size
|
|
189
208
|
}
|
|
190
209
|
}, elementBefore && /*#__PURE__*/React.createElement(_styles.Accessory, {
|
|
@@ -228,7 +247,8 @@ Input.defaultProps = {
|
|
|
228
247
|
disabled: false,
|
|
229
248
|
type: "text",
|
|
230
249
|
size: "default",
|
|
231
|
-
appearance: "primary"
|
|
250
|
+
appearance: "primary",
|
|
251
|
+
innerRef: /*#__PURE__*/React.createRef()
|
|
232
252
|
};
|
|
233
253
|
Input.ClearButton = ClearButton;
|
|
234
254
|
Input.ClearButton.displayName = "Input.ClearButton";
|
package/commonjs/Menu/index.js
CHANGED
package/lib/Input/index.js
CHANGED
|
@@ -12,38 +12,55 @@ import * as React from "react";
|
|
|
12
12
|
import Container, { Accessory } from "./styles";
|
|
13
13
|
import Button from "../Button";
|
|
14
14
|
import Icon from "../Icon";
|
|
15
|
+
import styled from "styled-components";
|
|
15
16
|
var InputContext = /*#__PURE__*/React.createContext({});
|
|
17
|
+
var StyledButton = styled(Button).withConfig({
|
|
18
|
+
displayName: "Input__StyledButton",
|
|
19
|
+
componentId: "sc-1ck1dnm-0"
|
|
20
|
+
})(["&:hover,&:active{color:", ";}"], function (props) {
|
|
21
|
+
return props.theme.utils.interact(props.theme.colors.icon.base);
|
|
22
|
+
});
|
|
16
23
|
|
|
17
24
|
var ClearButton = function ClearButton() {
|
|
18
25
|
var _React$useContext = React.useContext(InputContext),
|
|
26
|
+
onClear = _React$useContext.onClear,
|
|
19
27
|
handleClear = _React$useContext.handleClear,
|
|
20
28
|
clearButtonLabel = _React$useContext.clearButtonLabel,
|
|
21
29
|
hasValue = _React$useContext.hasValue,
|
|
22
|
-
|
|
30
|
+
inputSize = _React$useContext.size; // Hide the button when there is no text to clear.
|
|
23
31
|
|
|
24
32
|
|
|
25
33
|
if (!hasValue) {
|
|
26
34
|
return null;
|
|
27
|
-
} //
|
|
28
|
-
//
|
|
35
|
+
} // Log a warning and hide the button when no onClear callback is provided.
|
|
36
|
+
// If we called handleClear with no onClear prop, all the button would do is focus the Input.
|
|
37
|
+
|
|
29
38
|
|
|
39
|
+
if (!onClear) {
|
|
40
|
+
console.warn("Warning: No onClear prop provided to Input when using Input.ClearButton. Omitting Input.ClearButton.");
|
|
41
|
+
return null;
|
|
42
|
+
} // Warn if clearButtonLabel is not included, so that the unlocalized fallback will not be mistaken for a proper label.
|
|
30
43
|
|
|
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
44
|
|
|
35
45
|
if (!clearButtonLabel) {
|
|
36
|
-
console.warn("Warning: clearButtonLabel prop is required when using Input.ClearButton. Please pass a localized
|
|
37
|
-
}
|
|
46
|
+
console.warn("Warning: clearButtonLabel prop is required when using Input.ClearButton. Please pass a localized clearButtonLabel to Input.");
|
|
47
|
+
} // Reduce Button padding for size small Inputs so that the Button won't go outside the bounds of the Input.
|
|
48
|
+
// This adjustment is handled automatically for default and large Inputs via Button's size. There is no "small" Button.
|
|
49
|
+
|
|
38
50
|
|
|
39
|
-
|
|
51
|
+
var py = inputSize === "small" ? 100 : undefined;
|
|
52
|
+
var px = inputSize === "small" ? 200 : undefined;
|
|
53
|
+
var buttonSize = inputSize === "small" ? "default" : inputSize;
|
|
54
|
+
return /*#__PURE__*/React.createElement(StyledButton, {
|
|
40
55
|
onClick: handleClear,
|
|
41
56
|
size: buttonSize,
|
|
42
57
|
py: py,
|
|
43
|
-
px: px
|
|
58
|
+
px: px,
|
|
59
|
+
title: clearButtonLabel || "Clear",
|
|
60
|
+
ariaLabel: clearButtonLabel || "Clear",
|
|
61
|
+
color: "icon.base"
|
|
44
62
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
45
|
-
name: "circlex"
|
|
46
|
-
title: clearButtonLabel || "Clear"
|
|
63
|
+
name: "circlex"
|
|
47
64
|
}));
|
|
48
65
|
}; // Used for positioning elementAfter. This logic will detect if the element is a ClearButton,
|
|
49
66
|
// regardless of whether it was manually passed as elemAfter or automatically added to a search Input.
|
|
@@ -74,10 +91,10 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
74
91
|
};
|
|
75
92
|
|
|
76
93
|
_this.handleClear = function (e) {
|
|
77
|
-
var _this$props$innerRef
|
|
94
|
+
var _this$props$innerRef$;
|
|
78
95
|
|
|
96
|
+
(_this$props$innerRef$ = _this.props.innerRef.current) == null ? void 0 : _this$props$innerRef$.focus();
|
|
79
97
|
_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();
|
|
81
98
|
};
|
|
82
99
|
|
|
83
100
|
_this.handleChange = function (e) {
|
|
@@ -170,6 +187,7 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
170
187
|
handleClear: this.handleClear,
|
|
171
188
|
hasValue: !!value,
|
|
172
189
|
clearButtonLabel: clearButtonLabel,
|
|
190
|
+
onClear: onClear,
|
|
173
191
|
size: size
|
|
174
192
|
}
|
|
175
193
|
}, elementBefore && /*#__PURE__*/React.createElement(Accessory, {
|
|
@@ -213,7 +231,8 @@ Input.defaultProps = {
|
|
|
213
231
|
disabled: false,
|
|
214
232
|
type: "text",
|
|
215
233
|
size: "default",
|
|
216
|
-
appearance: "primary"
|
|
234
|
+
appearance: "primary",
|
|
235
|
+
innerRef: /*#__PURE__*/React.createRef()
|
|
217
236
|
};
|
|
218
237
|
Input.ClearButton = ClearButton;
|
|
219
238
|
Input.ClearButton.displayName = "Input.ClearButton";
|
package/lib/Menu/index.js
CHANGED