@sproutsocial/racine 11.2.5-sproutTheme-beta.5 → 11.2.5-sproutTheme-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 +7 -6
- package/__flow__/utils/index.js +23 -0
- package/commonjs/Input/index.js +7 -9
- package/commonjs/utils/index.js +29 -2
- package/lib/Input/index.js +6 -9
- package/lib/utils/index.js +24 -0
- package/package.json +1 -1
package/__flow__/Input/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import Icon from "../Icon";
|
|
|
6
6
|
import styled from "styled-components";
|
|
7
7
|
import type { StyledComponent } from "styled-components";
|
|
8
8
|
import type { TypeTheme } from "../types/theme.flow";
|
|
9
|
+
import { mergeRefs } from "../utils";
|
|
9
10
|
|
|
10
11
|
type TypeProps = {
|
|
11
12
|
/** ID of the form element, should match the "for" value of the associated label */
|
|
@@ -160,19 +161,19 @@ class Input extends React.Component<TypeProps> {
|
|
|
160
161
|
type: "text",
|
|
161
162
|
size: "default",
|
|
162
163
|
appearance: "primary",
|
|
163
|
-
innerRef: React.createRef<HTMLInputElement>(),
|
|
164
164
|
};
|
|
165
165
|
|
|
166
166
|
static ClearButton = ClearButton;
|
|
167
167
|
|
|
168
|
+
// Define our own ref for focus management.
|
|
169
|
+
// We use mergeRefs to pass both this.inputRef and this.props.innerRef to input.
|
|
170
|
+
inputRef = React.createRef<HTMLInputElement>();
|
|
171
|
+
|
|
168
172
|
handleBlur = (e: SyntheticFocusEvent<HTMLInputElement>) =>
|
|
169
173
|
this.props.onBlur?.(e);
|
|
170
174
|
|
|
171
175
|
handleClear = (e: SyntheticEvent<HTMLButtonElement>) => {
|
|
172
|
-
|
|
173
|
-
if (typeof this.props.innerRef === "object") {
|
|
174
|
-
this.props.innerRef.current?.focus();
|
|
175
|
-
}
|
|
176
|
+
this.inputRef?.current?.focus();
|
|
176
177
|
this.props.onClear?.(e);
|
|
177
178
|
};
|
|
178
179
|
|
|
@@ -287,7 +288,7 @@ class Input extends React.Component<TypeProps> {
|
|
|
287
288
|
onKeyDown={this.handleKeyDown}
|
|
288
289
|
onKeyUp={this.handleKeyUp}
|
|
289
290
|
onPaste={this.handlePaste}
|
|
290
|
-
ref={innerRef}
|
|
291
|
+
ref={mergeRefs([innerRef, this.inputRef])}
|
|
291
292
|
data-qa-input={name || ""}
|
|
292
293
|
data-qa-input-isdisabled={disabled === true}
|
|
293
294
|
data-qa-input-isrequired={required === true}
|
package/__flow__/utils/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
|
+
import { type ElementRef } from "react";
|
|
4
|
+
|
|
3
5
|
export const canUseDOM = () => {
|
|
4
6
|
return Boolean(
|
|
5
7
|
typeof window !== "undefined" &&
|
|
@@ -7,3 +9,24 @@ export const canUseDOM = () => {
|
|
|
7
9
|
window.document.createElement
|
|
8
10
|
);
|
|
9
11
|
};
|
|
12
|
+
|
|
13
|
+
type TypeRef =
|
|
14
|
+
| {| current: null | HTMLInputElement |}
|
|
15
|
+
| ((ElementRef<any> | HTMLElement) => void);
|
|
16
|
+
|
|
17
|
+
// Allows a component to pass its own ref *and* a ref prop to the same element.
|
|
18
|
+
// Via https://www.davedrinks.coffee/how-do-i-use-two-react-refs/
|
|
19
|
+
export const mergeRefs = (refs: (?TypeRef)[]) => {
|
|
20
|
+
const filteredRefs = refs.filter(Boolean);
|
|
21
|
+
if (!filteredRefs.length) return null;
|
|
22
|
+
if (filteredRefs.length === 0) return filteredRefs[0];
|
|
23
|
+
return (inst: any) => {
|
|
24
|
+
for (const ref of filteredRefs) {
|
|
25
|
+
if (typeof ref === "function") {
|
|
26
|
+
ref(inst);
|
|
27
|
+
} else if (ref) {
|
|
28
|
+
ref.current = inst;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
package/commonjs/Input/index.js
CHANGED
|
@@ -13,6 +13,8 @@ var _Icon = _interopRequireDefault(require("../Icon"));
|
|
|
13
13
|
|
|
14
14
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
15
15
|
|
|
16
|
+
var _utils = require("../utils");
|
|
17
|
+
|
|
16
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
19
|
|
|
18
20
|
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); }
|
|
@@ -99,19 +101,16 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
104
|
+
_this.inputRef = /*#__PURE__*/React.createRef();
|
|
102
105
|
|
|
103
106
|
_this.handleBlur = function (e) {
|
|
104
107
|
return _this.props.onBlur == null ? void 0 : _this.props.onBlur(e);
|
|
105
108
|
};
|
|
106
109
|
|
|
107
110
|
_this.handleClear = function (e) {
|
|
108
|
-
|
|
109
|
-
if (typeof _this.props.innerRef === "object") {
|
|
110
|
-
var _this$props$innerRef$;
|
|
111
|
-
|
|
112
|
-
(_this$props$innerRef$ = _this.props.innerRef.current) == null ? void 0 : _this$props$innerRef$.focus();
|
|
113
|
-
}
|
|
111
|
+
var _this$inputRef, _this$inputRef$curren;
|
|
114
112
|
|
|
113
|
+
(_this$inputRef = _this.inputRef) == null ? void 0 : (_this$inputRef$curren = _this$inputRef.current) == null ? void 0 : _this$inputRef$curren.focus();
|
|
115
114
|
_this.props.onClear == null ? void 0 : _this.props.onClear(e);
|
|
116
115
|
};
|
|
117
116
|
|
|
@@ -231,7 +230,7 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
231
230
|
onKeyDown: this.handleKeyDown,
|
|
232
231
|
onKeyUp: this.handleKeyUp,
|
|
233
232
|
onPaste: this.handlePaste,
|
|
234
|
-
ref: innerRef,
|
|
233
|
+
ref: (0, _utils.mergeRefs)([innerRef, this.inputRef]),
|
|
235
234
|
"data-qa-input": name || "",
|
|
236
235
|
"data-qa-input-isdisabled": disabled === true,
|
|
237
236
|
"data-qa-input-isrequired": required === true
|
|
@@ -249,8 +248,7 @@ Input.defaultProps = {
|
|
|
249
248
|
disabled: false,
|
|
250
249
|
type: "text",
|
|
251
250
|
size: "default",
|
|
252
|
-
appearance: "primary"
|
|
253
|
-
innerRef: /*#__PURE__*/React.createRef()
|
|
251
|
+
appearance: "primary"
|
|
254
252
|
};
|
|
255
253
|
Input.ClearButton = ClearButton;
|
|
256
254
|
Input.ClearButton.displayName = "Input.ClearButton";
|
package/commonjs/utils/index.js
CHANGED
|
@@ -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;
|
package/lib/Input/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import Container, { Accessory } from "./styles";
|
|
|
11
11
|
import Button from "../Button";
|
|
12
12
|
import Icon from "../Icon";
|
|
13
13
|
import styled from "styled-components";
|
|
14
|
+
import { mergeRefs } from "../utils";
|
|
14
15
|
var InputContext = /*#__PURE__*/React.createContext({});
|
|
15
16
|
var StyledButton = styled(Button).withConfig({
|
|
16
17
|
displayName: "Input__StyledButton",
|
|
@@ -83,19 +84,16 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
87
|
+
_this.inputRef = /*#__PURE__*/React.createRef();
|
|
86
88
|
|
|
87
89
|
_this.handleBlur = function (e) {
|
|
88
90
|
return _this.props.onBlur == null ? void 0 : _this.props.onBlur(e);
|
|
89
91
|
};
|
|
90
92
|
|
|
91
93
|
_this.handleClear = function (e) {
|
|
92
|
-
|
|
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();
|
|
97
|
-
}
|
|
94
|
+
var _this$inputRef, _this$inputRef$curren;
|
|
98
95
|
|
|
96
|
+
(_this$inputRef = _this.inputRef) == null ? void 0 : (_this$inputRef$curren = _this$inputRef.current) == null ? void 0 : _this$inputRef$curren.focus();
|
|
99
97
|
_this.props.onClear == null ? void 0 : _this.props.onClear(e);
|
|
100
98
|
};
|
|
101
99
|
|
|
@@ -215,7 +213,7 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
215
213
|
onKeyDown: this.handleKeyDown,
|
|
216
214
|
onKeyUp: this.handleKeyUp,
|
|
217
215
|
onPaste: this.handlePaste,
|
|
218
|
-
ref: innerRef,
|
|
216
|
+
ref: mergeRefs([innerRef, this.inputRef]),
|
|
219
217
|
"data-qa-input": name || "",
|
|
220
218
|
"data-qa-input-isdisabled": disabled === true,
|
|
221
219
|
"data-qa-input-isrequired": required === true
|
|
@@ -233,8 +231,7 @@ Input.defaultProps = {
|
|
|
233
231
|
disabled: false,
|
|
234
232
|
type: "text",
|
|
235
233
|
size: "default",
|
|
236
|
-
appearance: "primary"
|
|
237
|
-
innerRef: /*#__PURE__*/React.createRef()
|
|
234
|
+
appearance: "primary"
|
|
238
235
|
};
|
|
239
236
|
Input.ClearButton = ClearButton;
|
|
240
237
|
Input.ClearButton.displayName = "Input.ClearButton";
|
package/lib/utils/index.js
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
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."); }
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
1
7
|
export var canUseDOM = function canUseDOM() {
|
|
2
8
|
return Boolean(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
9
|
+
};
|
|
10
|
+
// Allows a component to pass its own ref *and* a ref prop to the same element.
|
|
11
|
+
// Via https://www.davedrinks.coffee/how-do-i-use-two-react-refs/
|
|
12
|
+
export var mergeRefs = function mergeRefs(refs) {
|
|
13
|
+
var filteredRefs = refs.filter(Boolean);
|
|
14
|
+
if (!filteredRefs.length) return null;
|
|
15
|
+
if (filteredRefs.length === 0) return filteredRefs[0];
|
|
16
|
+
return function (inst) {
|
|
17
|
+
for (var _iterator = _createForOfIteratorHelperLoose(filteredRefs), _step; !(_step = _iterator()).done;) {
|
|
18
|
+
var ref = _step.value;
|
|
19
|
+
|
|
20
|
+
if (typeof ref === "function") {
|
|
21
|
+
ref(inst);
|
|
22
|
+
} else if (ref) {
|
|
23
|
+
ref.current = inst;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
3
27
|
};
|