@sproutsocial/racine 11.2.5-sproutTheme-beta.3 → 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.
@@ -3,7 +3,6 @@ import { boolean, text, number } from "@storybook/addon-knobs";
3
3
  import Button from "./index";
4
4
  import Icon from "../Icon";
5
5
  import Box from "../Box";
6
- import ThemeProvider from "../ThemeProvider";
7
6
 
8
7
  export default {
9
8
  title: "Button",
@@ -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
- // Only attempt to focus the input if the ref is an object. It won't work for refs that are functions.
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}
@@ -3,24 +3,21 @@ import clone from "just-clone";
3
3
  import baseDarkTheme from "../../../dark/theme";
4
4
  import { getDarkThemeColors } from "./getDarkThemeColors";
5
5
  import { getNonColorThemeValues } from "../NonColorThemeValues";
6
- import type { TypeTheme } from "../../../../types/theme.flow.js";
7
6
  import type { TypeSproutTheme } from "../sproutThemeType.flow";
8
7
 
9
- const darkTheme = (baseDarkTheme: TypeTheme): TypeSproutTheme => {
10
- // clone base theme. (we don't want to mutate the base theme)
11
- const themeClone = clone(baseDarkTheme);
8
+ // clone base theme. (we don't want to mutate the base theme)
9
+ const themeClone = clone(baseDarkTheme);
12
10
 
13
- // get non color theme values
14
- const nonColorThemeValues = getNonColorThemeValues(themeClone);
11
+ // get non color theme values
12
+ const nonColorThemeValues = getNonColorThemeValues(themeClone);
15
13
 
16
- // get sprout specific dark theme colors
17
- const darkThemeColors = getDarkThemeColors(themeClone.colors);
14
+ // get sprout specific dark theme colors
15
+ const darkThemeColors = getDarkThemeColors(themeClone.colors);
18
16
 
19
- return {
20
- ...themeClone,
21
- ...nonColorThemeValues,
22
- ...darkThemeColors,
23
- };
17
+ const darkTheme: TypeSproutTheme = {
18
+ ...themeClone,
19
+ ...nonColorThemeValues,
20
+ ...darkThemeColors,
24
21
  };
25
22
 
26
23
  export default darkTheme;
@@ -3,23 +3,21 @@ import clone from "just-clone";
3
3
  import baseLightTheme from "../../../light/theme";
4
4
  import { getLightThemeColors } from "./getLightThemeColors";
5
5
  import { getNonColorThemeValues } from "../NonColorThemeValues";
6
- import type { TypeTheme } from "../../../../types/theme.flow.js";
6
+ import type { TypeSproutTheme } from "../sproutThemeType.flow";
7
7
 
8
- const lightTheme = (baseLightTheme: TypeTheme) => {
9
- // clone base theme. (we don't want to mutate the base theme)
10
- const themeClone = clone(baseLightTheme);
8
+ // clone base theme. (we don't want to mutate the base theme)
9
+ const themeClone = clone(baseLightTheme);
11
10
 
12
- // get non color theme values
13
- const nonColorThemeValues = getNonColorThemeValues(themeClone);
11
+ // get non color theme values
12
+ const nonColorThemeValues = getNonColorThemeValues(themeClone);
14
13
 
15
- // get sprout specific light theme colors
16
- const lightThemeColors = getLightThemeColors(themeClone.colors);
14
+ // get sprout specific light theme colors
15
+ const lightThemeColors = getLightThemeColors(themeClone.colors);
17
16
 
18
- return {
19
- ...themeClone,
20
- ...nonColorThemeValues,
21
- ...lightThemeColors,
22
- };
17
+ const lightTheme: TypeSproutTheme = {
18
+ ...themeClone,
19
+ ...nonColorThemeValues,
20
+ ...lightThemeColors,
23
21
  };
24
22
 
25
23
  export default lightTheme;
@@ -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
+ };
@@ -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
- // Only attempt to focus the input if the ref is an object. It won't work for refs that are functions.
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";
@@ -15,15 +15,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
15
15
 
16
16
  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); }
17
17
 
18
- var darkTheme = function darkTheme(baseDarkTheme) {
19
- // clone base theme. (we don't want to mutate the base theme)
20
- var themeClone = (0, _justClone.default)(baseDarkTheme); // get non color theme values
18
+ // clone base theme. (we don't want to mutate the base theme)
19
+ var themeClone = (0, _justClone.default)(_theme.default); // get non color theme values
21
20
 
22
- var nonColorThemeValues = (0, _NonColorThemeValues.getNonColorThemeValues)(themeClone); // get sprout specific dark theme colors
21
+ var nonColorThemeValues = (0, _NonColorThemeValues.getNonColorThemeValues)(themeClone); // get sprout specific dark theme colors
23
22
 
24
- var darkThemeColors = (0, _getDarkThemeColors.getDarkThemeColors)(themeClone.colors);
25
- return _extends({}, themeClone, nonColorThemeValues, darkThemeColors);
26
- };
23
+ var darkThemeColors = (0, _getDarkThemeColors.getDarkThemeColors)(themeClone.colors);
24
+
25
+ var darkTheme = _extends({}, themeClone, nonColorThemeValues, darkThemeColors);
27
26
 
28
27
  var _default = darkTheme;
29
28
  exports.default = _default;
@@ -15,15 +15,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
15
15
 
16
16
  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); }
17
17
 
18
- var lightTheme = function lightTheme(baseLightTheme) {
19
- // clone base theme. (we don't want to mutate the base theme)
20
- var themeClone = (0, _justClone.default)(baseLightTheme); // get non color theme values
18
+ // clone base theme. (we don't want to mutate the base theme)
19
+ var themeClone = (0, _justClone.default)(_theme.default); // get non color theme values
21
20
 
22
- var nonColorThemeValues = (0, _NonColorThemeValues.getNonColorThemeValues)(themeClone); // get sprout specific light theme colors
21
+ var nonColorThemeValues = (0, _NonColorThemeValues.getNonColorThemeValues)(themeClone); // get sprout specific light theme colors
23
22
 
24
- var lightThemeColors = (0, _getLightThemeColors.getLightThemeColors)(themeClone.colors);
25
- return _extends({}, themeClone, nonColorThemeValues, lightThemeColors);
26
- };
23
+ var lightThemeColors = (0, _getLightThemeColors.getLightThemeColors)(themeClone.colors);
24
+
25
+ var lightTheme = _extends({}, themeClone, nonColorThemeValues, lightThemeColors);
27
26
 
28
27
  var _default = lightTheme;
29
28
  exports.default = _default;
@@ -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;
@@ -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
- // 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();
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";
@@ -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;
@@ -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;
@@ -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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sproutsocial/racine",
3
- "version": "11.2.5-sproutTheme-beta.3",
3
+ "version": "11.2.5-sproutTheme-beta.6",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "__flow__",