@sproutsocial/racine 11.6.2 → 11.7.0-input-beta.4
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/CHANGELOG.md +7 -0
- package/__flow__/Checkbox/styles.js +75 -75
- package/__flow__/Collapsible/index.js +3 -2
- package/__flow__/Image/index.js +10 -2
- package/__flow__/Input/index.js +47 -23
- package/__flow__/Input/index.stories.js +14 -0
- package/__flow__/Input/index.test.js +20 -0
- package/__flow__/Input/styles.js +2 -2
- package/__flow__/SegmentedControl/index.js +3 -2
- package/__flow__/TableCell/index.js +9 -2
- package/__flow__/ToggleHint/index.js +9 -2
- package/__flow__/systemProps/color.js +1 -2
- package/__flow__/themes/{dark → utils}/_themed.scss +4 -3
- package/__flow__/utils/responsiveProps/index.test.js +10 -2
- package/commonjs/Input/index.js +40 -22
- package/commonjs/Input/styles.js +2 -2
- package/dist/themes/dark/_themed.scss +4 -3
- package/dist/themes/dark/{dark.scss → theme.scss} +1 -1
- package/{__flow__/themes/light → dist/themes/extendedThemes/sproutTheme/dark}/_themed.scss +4 -3
- package/dist/themes/extendedThemes/sproutTheme/dark/theme.scss +692 -0
- package/dist/themes/extendedThemes/sproutTheme/light/_themed.scss +119 -0
- package/dist/themes/extendedThemes/sproutTheme/light/theme.scss +692 -0
- package/dist/themes/light/_themed.scss +4 -3
- package/dist/themes/light/{light.scss → theme.scss} +1 -1
- package/lib/Input/index.js +40 -22
- package/lib/Input/styles.js +2 -2
- package/package.json +2 -1
package/lib/Input/index.js
CHANGED
|
@@ -24,7 +24,6 @@ var StyledButton = styled(Button).withConfig({
|
|
|
24
24
|
|
|
25
25
|
var ClearButton = function ClearButton() {
|
|
26
26
|
var _React$useContext = React.useContext(InputContext),
|
|
27
|
-
onClear = _React$useContext.onClear,
|
|
28
27
|
handleClear = _React$useContext.handleClear,
|
|
29
28
|
clearButtonLabel = _React$useContext.clearButtonLabel,
|
|
30
29
|
hasValue = _React$useContext.hasValue,
|
|
@@ -33,13 +32,6 @@ var ClearButton = function ClearButton() {
|
|
|
33
32
|
|
|
34
33
|
if (!hasValue) {
|
|
35
34
|
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
35
|
} // Warn if clearButtonLabel is not included, so that the unlocalized fallback will not be mistaken for a proper label.
|
|
44
36
|
|
|
45
37
|
|
|
@@ -78,14 +70,10 @@ var isClearButton = function isClearButton(elem) {
|
|
|
78
70
|
var Input = /*#__PURE__*/function (_React$Component) {
|
|
79
71
|
_inheritsLoose(Input, _React$Component);
|
|
80
72
|
|
|
81
|
-
function Input() {
|
|
73
|
+
function Input(props) {
|
|
82
74
|
var _this;
|
|
83
75
|
|
|
84
|
-
|
|
85
|
-
args[_key] = arguments[_key];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
76
|
+
_this = _React$Component.call(this, props) || this;
|
|
89
77
|
_this.inputRef = /*#__PURE__*/React.createRef();
|
|
90
78
|
|
|
91
79
|
_this.handleBlur = function (e) {
|
|
@@ -93,14 +81,29 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
93
81
|
};
|
|
94
82
|
|
|
95
83
|
_this.handleClear = function (e) {
|
|
96
|
-
var
|
|
84
|
+
var input = _this.inputRef.current;
|
|
85
|
+
|
|
86
|
+
if (input) {
|
|
87
|
+
// Clear the value via the input prototype, then dispatch an input event in order to trigger handleChange
|
|
88
|
+
var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
|
|
89
|
+
nativeInputValueSetter.call(input, "");
|
|
90
|
+
var inputEvent = new Event("input", {
|
|
91
|
+
bubbles: true
|
|
92
|
+
});
|
|
93
|
+
input.dispatchEvent(inputEvent); // Focus the input, update hasValue, and call any onClear callback
|
|
94
|
+
|
|
95
|
+
input.focus();
|
|
96
|
+
|
|
97
|
+
_this.updateState("");
|
|
97
98
|
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
_this.props.onClear == null ? void 0 : _this.props.onClear(e);
|
|
100
|
+
}
|
|
100
101
|
};
|
|
101
102
|
|
|
102
103
|
_this.handleChange = function (e) {
|
|
103
|
-
|
|
104
|
+
_this.props.onChange == null ? void 0 : _this.props.onChange(e, e.currentTarget.value);
|
|
105
|
+
|
|
106
|
+
_this.updateState(e.currentTarget.value);
|
|
104
107
|
};
|
|
105
108
|
|
|
106
109
|
_this.handleFocus = function (e) {
|
|
@@ -119,6 +122,22 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
119
122
|
return _this.props.onPaste == null ? void 0 : _this.props.onPaste(e, e.currentTarget.value);
|
|
120
123
|
};
|
|
121
124
|
|
|
125
|
+
_this.updateState = function (inputValue) {
|
|
126
|
+
var hasValue = inputValue !== "";
|
|
127
|
+
var previousHasValue = _this.state.hasValue; // Only update state if the value of `hasValue` has changed to avoid unnecessary renders.
|
|
128
|
+
|
|
129
|
+
if (hasValue !== previousHasValue) {
|
|
130
|
+
_this.setState({
|
|
131
|
+
hasValue: hasValue
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
_this.state = {
|
|
137
|
+
// Tracking hasValue in state allows us to hide ClearButton when there is no value to clear
|
|
138
|
+
// for both controlled and uncontrolled inputs.
|
|
139
|
+
hasValue: !!props.value
|
|
140
|
+
};
|
|
122
141
|
return _this;
|
|
123
142
|
}
|
|
124
143
|
|
|
@@ -172,9 +191,9 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
172
191
|
name: "search",
|
|
173
192
|
ariaHidden: true,
|
|
174
193
|
color: "icon.base"
|
|
175
|
-
}) : elemBefore; // Do not add a ClearButton if
|
|
194
|
+
}) : elemBefore; // Do not add a ClearButton if an elemAfter prop was passed.
|
|
176
195
|
|
|
177
|
-
var elementAfter = type === "search" &&
|
|
196
|
+
var elementAfter = type === "search" && !elemAfter ? /*#__PURE__*/React.createElement(ClearButton, null) : elemAfter;
|
|
178
197
|
return /*#__PURE__*/React.createElement(Container, _extends({
|
|
179
198
|
hasBeforeElement: !!elementBefore,
|
|
180
199
|
hasAfterElement: !!elementAfter,
|
|
@@ -187,9 +206,8 @@ var Input = /*#__PURE__*/function (_React$Component) {
|
|
|
187
206
|
}, rest), /*#__PURE__*/React.createElement(InputContext.Provider, {
|
|
188
207
|
value: {
|
|
189
208
|
handleClear: this.handleClear,
|
|
190
|
-
hasValue:
|
|
209
|
+
hasValue: this.state.hasValue,
|
|
191
210
|
clearButtonLabel: clearButtonLabel,
|
|
192
|
-
onClear: onClear,
|
|
193
211
|
size: size
|
|
194
212
|
}
|
|
195
213
|
}, elementBefore && /*#__PURE__*/React.createElement(Accessory, {
|
package/lib/Input/styles.js
CHANGED
|
@@ -71,9 +71,9 @@ export var Accessory = styled.div.withConfig({
|
|
|
71
71
|
})(["position:absolute;top:50%;transform:translateY(-50%);color:", ";display:flex;align-items:center;", ";", ";"], function (props) {
|
|
72
72
|
return props.theme.colors.icon.base;
|
|
73
73
|
}, function (props) {
|
|
74
|
-
return props.before && css(["left:", ";"], props.theme.space[
|
|
74
|
+
return props.before && css(["left:", ";"], props.theme.space[300]);
|
|
75
75
|
}, function (props) {
|
|
76
|
-
return props.after && css(["right:", ";"], props.isClearButton ? 0 : props.theme.space[
|
|
76
|
+
return props.after && css(["right:", ";"], props.isClearButton ? 0 : props.theme.space[300]);
|
|
77
77
|
});
|
|
78
78
|
Container.displayName = "InputContainer";
|
|
79
79
|
Accessory.displayName = "InputAccessory";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sproutsocial/racine",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.7.0-input-beta.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"__flow__",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"release": "yarn test && yarn changeset publish",
|
|
49
49
|
"storybook": "start-storybook -c .storybook -p 9999",
|
|
50
50
|
"build-storybook": "build-storybook --quiet -c .storybook -o .storybook-dist",
|
|
51
|
+
"build-chromatic": "yarn build-icons && build-storybook --quiet -c .storybook -o .storybook-dist",
|
|
51
52
|
"icon-lint": "node bin/icon-lint/cli",
|
|
52
53
|
"playroom:start": "playroom start",
|
|
53
54
|
"playroom:build": "playroom build"
|