@skyscanner/backpack-web 34.16.0 → 35.0.0-premajor.1
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/bpk-component-button/src/BpkButtonDestructive.module.css +18 -0
- package/bpk-component-button/src/BpkButtonFeatured.module.css +18 -0
- package/bpk-component-button/src/BpkButtonLink.module.css +18 -0
- package/bpk-component-button/src/BpkButtonLinkOnDark.module.css +18 -0
- package/bpk-component-button/src/BpkButtonPrimaryOnDark.module.css +18 -0
- package/bpk-component-button/src/BpkButtonPrimaryOnLight.module.css +18 -0
- package/bpk-component-button/src/BpkButtonSecondary.module.css +18 -0
- package/bpk-component-button/src/BpkButtonSecondaryOnDark.module.css +18 -0
- package/bpk-component-close-button/src/BpkCloseButton.d.ts +10 -0
- package/bpk-component-close-button/src/BpkCloseButton.js +21 -37
- package/bpk-component-datepicker/src/BpkDatepicker.module.css +18 -0
- package/bpk-component-flare/src/__generated__/js/corner-radius.d.ts +5 -0
- package/bpk-component-flare/src/__generated__/js/pointer.d.ts +5 -0
- package/bpk-component-input/src/BpkClearButton.module.css +18 -0
- package/bpk-component-input/src/BpkInput.js +1 -1
- package/bpk-component-input/src/common-types.d.ts +1 -1
- package/bpk-component-loading-button/src/BpkLoadingButton.d.ts +6 -38
- package/bpk-component-loading-button/src/BpkLoadingButton.js +13 -44
- package/bpk-component-navigation-bar/src/BpkNavigationBarButtonLink.module.css +18 -0
- package/bpk-component-nudger/index.d.ts +1 -2
- package/bpk-component-nudger/index.js +1 -2
- package/bpk-component-nudger/src/BpkNudger.d.ts +1 -1
- package/bpk-component-nudger/src/BpkNudger.js +102 -20
- package/bpk-component-nudger/src/BpkNudger.module.css +1 -1
- package/bpk-component-nudger/src/common-types.d.ts +7 -5
- package/bpk-component-slider/src/BpkSlider.d.ts +4 -1
- package/bpk-component-slider/src/BpkSlider.js +51 -3
- package/bpk-component-spinner/src/BpkExtraLargeSpinner.d.ts +4 -14
- package/bpk-component-spinner/src/BpkExtraLargeSpinner.js +5 -16
- package/bpk-component-spinner/src/BpkLargeSpinner.d.ts +5 -17
- package/bpk-component-spinner/src/BpkLargeSpinner.js +6 -19
- package/bpk-component-spinner/src/BpkSpinner.d.ts +5 -17
- package/bpk-component-spinner/src/BpkSpinner.js +6 -19
- package/bpk-component-split-input/src/BpkInputField.d.ts +21 -0
- package/bpk-component-split-input/src/BpkInputField.js +12 -17
- package/bpk-component-split-input/src/BpkSplitInput.d.ts +44 -0
- package/bpk-component-split-input/src/BpkSplitInput.js +22 -33
- package/bpk-react-utils/src/nativeEventHandler.d.ts +1 -1
- package/bpk-react-utils/src/nativeEventHandler.js +7 -5
- package/bpk-stylesheets/test.css +164 -0
- package/package.json +3 -1
- package/bpk-component-nudger/src/BpkConfigurableNudger.d.ts +0 -26
- package/bpk-component-nudger/src/BpkConfigurableNudger.js +0 -96
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
|
-
*/
|
|
17
|
+
*/
|
|
18
|
+
|
|
18
19
|
import { Component } from 'react';
|
|
19
20
|
import { INPUT_TYPES } from "../../bpk-component-input";
|
|
20
21
|
import { cssModules } from "../../bpk-react-utils";
|
|
@@ -31,22 +32,25 @@ const DELETE = 46;
|
|
|
31
32
|
const SPACEBAR = 32;
|
|
32
33
|
const ENTER = 13;
|
|
33
34
|
class BpkSplitInput extends Component {
|
|
35
|
+
static defaultProps = {
|
|
36
|
+
type: INPUT_TYPES.number,
|
|
37
|
+
inputLength: 4,
|
|
38
|
+
large: true,
|
|
39
|
+
placeholder: ''
|
|
40
|
+
};
|
|
34
41
|
constructor(props) {
|
|
35
42
|
super(props);
|
|
36
43
|
this.state = {
|
|
37
44
|
focusedInput: 0,
|
|
38
|
-
inputValue:
|
|
45
|
+
inputValue: Array(props.inputLength).fill('')
|
|
39
46
|
};
|
|
40
47
|
}
|
|
41
48
|
onInputChange = input => {
|
|
42
49
|
this.setState({
|
|
43
50
|
inputValue: input
|
|
44
51
|
});
|
|
45
|
-
const {
|
|
46
|
-
onChange
|
|
47
|
-
} = this.props;
|
|
48
52
|
const value = input.join('');
|
|
49
|
-
|
|
53
|
+
this.props.onInputChange(value);
|
|
50
54
|
};
|
|
51
55
|
updateInputValue = value => {
|
|
52
56
|
const {
|
|
@@ -83,8 +87,8 @@ class BpkSplitInput extends Component {
|
|
|
83
87
|
};
|
|
84
88
|
isNumeric = () => this.props.type === INPUT_TYPES.number;
|
|
85
89
|
isInputValid = value => {
|
|
86
|
-
const isTypeValid = this.isNumeric() ? /^\d$/.test(value) : typeof value === 'string';
|
|
87
|
-
return isTypeValid && value
|
|
90
|
+
const isTypeValid = this.isNumeric() ? /^\d$/.test(`${value}`) : typeof value === 'string';
|
|
91
|
+
return isTypeValid && `${value}`.trim().length === 1;
|
|
88
92
|
};
|
|
89
93
|
focusInput = inputIndex => {
|
|
90
94
|
const {
|
|
@@ -132,23 +136,23 @@ class BpkSplitInput extends Component {
|
|
|
132
136
|
this.onInputChange(inputValue);
|
|
133
137
|
};
|
|
134
138
|
handleOnKeyDown = e => {
|
|
135
|
-
if (e.
|
|
139
|
+
if (e.key === 'Backspace') {
|
|
136
140
|
e.preventDefault();
|
|
137
141
|
this.updateInputValue('');
|
|
138
142
|
this.focusPreviousInput();
|
|
139
|
-
} else if (e.
|
|
143
|
+
} else if (e.key === 'Delete') {
|
|
140
144
|
e.preventDefault();
|
|
141
145
|
this.updateInputValue('');
|
|
142
|
-
} else if (e.
|
|
146
|
+
} else if (e.key === 'Left' || e.key === 'ArrowLeft') {
|
|
143
147
|
e.preventDefault();
|
|
144
148
|
this.focusPreviousInput();
|
|
145
|
-
} else if (e.
|
|
149
|
+
} else if (e.key === 'Right' || e.key === 'ArrowRight') {
|
|
146
150
|
e.preventDefault();
|
|
147
151
|
this.focusNextInput();
|
|
148
|
-
} else if (e.
|
|
152
|
+
} else if (e.key === 'Enter') {
|
|
149
153
|
e.preventDefault();
|
|
150
154
|
this.handleSubmit();
|
|
151
|
-
} else if (e.
|
|
155
|
+
} else if (e.key === ' ' || e.key === 'Spacebar' || e.key === 'Space') {
|
|
152
156
|
e.preventDefault();
|
|
153
157
|
}
|
|
154
158
|
};
|
|
@@ -179,7 +183,8 @@ class BpkSplitInput extends Component {
|
|
|
179
183
|
large,
|
|
180
184
|
name,
|
|
181
185
|
placeholder,
|
|
182
|
-
type
|
|
186
|
+
type,
|
|
187
|
+
...rest
|
|
183
188
|
} = this.props;
|
|
184
189
|
const inputs = [];
|
|
185
190
|
for (let index = 0; index < inputLength; index += 1) {
|
|
@@ -197,7 +202,8 @@ class BpkSplitInput extends Component {
|
|
|
197
202
|
onInput: this.handleOnChange,
|
|
198
203
|
onKeyDown: this.handleOnKeyDown,
|
|
199
204
|
onPaste: this.handleOnPaste,
|
|
200
|
-
onFocus: e => this.handleOnFocus(e, index)
|
|
205
|
+
onFocus: e => this.handleOnFocus(e, index),
|
|
206
|
+
...rest
|
|
201
207
|
}, index));
|
|
202
208
|
}
|
|
203
209
|
return inputs;
|
|
@@ -209,22 +215,5 @@ class BpkSplitInput extends Component {
|
|
|
209
215
|
});
|
|
210
216
|
}
|
|
211
217
|
}
|
|
212
|
-
BpkSplitInput.propTypes = {
|
|
213
|
-
type: PropTypes.oneOf([INPUT_TYPES.text, INPUT_TYPES.number]),
|
|
214
|
-
id: PropTypes.string.isRequired,
|
|
215
|
-
label: PropTypes.string.isRequired,
|
|
216
|
-
name: PropTypes.string.isRequired,
|
|
217
|
-
inputLength: PropTypes.number,
|
|
218
|
-
placeholder: PropTypes.string,
|
|
219
|
-
onChange: PropTypes.func.isRequired,
|
|
220
|
-
onSubmit: PropTypes.func.isRequired,
|
|
221
|
-
large: PropTypes.bool
|
|
222
|
-
};
|
|
223
|
-
BpkSplitInput.defaultProps = {
|
|
224
|
-
type: INPUT_TYPES.number,
|
|
225
|
-
inputLength: 4,
|
|
226
|
-
large: true,
|
|
227
|
-
placeholder: ''
|
|
228
|
-
};
|
|
229
218
|
export default BpkSplitInput;
|
|
230
219
|
export { INPUT_TYPES };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function setNativeValue(element: HTMLInputElement, value: string): void;
|
|
1
|
+
declare function setNativeValue(element: HTMLInputElement, value: string | number, shouldDispatchChange?: boolean): void;
|
|
2
2
|
export { setNativeValue };
|
|
@@ -20,16 +20,18 @@
|
|
|
20
20
|
// This causes the elements to not emit events that would have been if they had been modified by the user directly.
|
|
21
21
|
// In order to maintain the expected native behaviour of the input element, It's possible to call this function during an
|
|
22
22
|
// "onEvent" handler and update the element value, together with updating react it's own state which isn't mapped to the elements value prop.
|
|
23
|
-
function setNativeValue(element, value) {
|
|
23
|
+
function setNativeValue(element, value, shouldDispatchChange = true) {
|
|
24
24
|
const inputProto = window.HTMLInputElement.prototype;
|
|
25
25
|
const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'value');
|
|
26
26
|
const setValue = descriptor.set;
|
|
27
27
|
if (setValue) {
|
|
28
|
-
const event = new Event('change', {
|
|
29
|
-
bubbles: true
|
|
30
|
-
});
|
|
31
28
|
setValue.call(element, value);
|
|
32
|
-
|
|
29
|
+
if (shouldDispatchChange) {
|
|
30
|
+
const event = new Event('change', {
|
|
31
|
+
bubbles: true
|
|
32
|
+
});
|
|
33
|
+
element.dispatchEvent(event);
|
|
34
|
+
}
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
|