carbon-react 114.7.0 → 114.8.0
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/esm/__internal__/checkable-input/checkable-input.component.d.ts +1 -1
- package/esm/__internal__/checkable-input/checkable-input.component.js +5 -10
- package/esm/__internal__/checkable-input/hidden-checkable-input.component.d.ts +1 -3
- package/esm/__internal__/checkable-input/hidden-checkable-input.component.js +5 -10
- package/esm/__internal__/input/input.component.d.ts +2 -2
- package/esm/__internal__/input/input.component.js +14 -7
- package/esm/__internal__/input-behaviour/useInputBehaviour.d.ts +1 -1
- package/esm/components/advanced-color-picker/advanced-color-picker.component.js +1 -3
- package/esm/components/button/button.component.js +21 -5
- package/esm/components/button-bar/button-bar.component.d.ts +8 -3
- package/esm/components/button-bar/button-bar.component.js +14 -35
- package/esm/components/checkbox/checkbox.component.d.ts +3 -4
- package/esm/components/checkbox/checkbox.component.js +13 -5
- package/esm/components/date/date.component.js +32 -17
- package/esm/components/date-range/date-range.component.js +20 -2
- package/esm/components/date-range/date-range.d.ts +8 -0
- package/esm/components/decimal/decimal.component.d.ts +1 -1
- package/esm/components/decimal/decimal.component.js +17 -7
- package/esm/components/grouped-character/grouped-character.component.d.ts +1 -1
- package/esm/components/grouped-character/grouped-character.component.js +15 -5
- package/esm/components/icon-button/icon-button.component.js +7 -2
- package/esm/components/menu/menu-item/menu-item.component.js +1 -1
- package/esm/components/number/number.component.d.ts +2 -2
- package/esm/components/number/number.component.js +15 -5
- package/esm/components/numeral-date/numeral-date.component.d.ts +13 -1
- package/esm/components/numeral-date/numeral-date.component.js +48 -5
- package/esm/components/radio-button/radio-button.component.d.ts +2 -0
- package/esm/components/radio-button/radio-button.component.js +10 -1
- package/esm/components/search/search.component.d.ts +1 -1
- package/esm/components/search/search.component.js +13 -12
- package/esm/components/select/filterable-select/filterable-select.component.js +23 -7
- package/esm/components/select/multi-select/multi-select.component.js +23 -7
- package/esm/components/select/select-textbox/select-textbox.component.js +5 -5
- package/esm/components/select/simple-select/simple-select.component.js +23 -7
- package/esm/components/simple-color-picker/simple-color/simple-color.style.d.ts +1 -1
- package/esm/components/switch/switch.component.d.ts +4 -2
- package/esm/components/switch/switch.component.js +14 -5
- package/esm/components/textarea/textarea.component.d.ts +1 -1
- package/esm/components/textarea/textarea.component.js +37 -14
- package/esm/components/textbox/textbox.component.d.ts +1 -1
- package/esm/components/textbox/textbox.component.js +13 -5
- package/esm/components/tile-select/tile-select.component.js +14 -5
- package/lib/__internal__/checkable-input/checkable-input.component.d.ts +1 -1
- package/lib/__internal__/checkable-input/checkable-input.component.js +5 -8
- package/lib/__internal__/checkable-input/hidden-checkable-input.component.d.ts +1 -3
- package/lib/__internal__/checkable-input/hidden-checkable-input.component.js +5 -8
- package/lib/__internal__/input/input.component.d.ts +2 -2
- package/lib/__internal__/input/input.component.js +13 -6
- package/lib/__internal__/input-behaviour/useInputBehaviour.d.ts +1 -1
- package/lib/components/advanced-color-picker/advanced-color-picker.component.js +1 -3
- package/lib/components/button/button.component.js +22 -4
- package/lib/components/button-bar/button-bar.component.d.ts +8 -3
- package/lib/components/button-bar/button-bar.component.js +17 -43
- package/lib/components/checkbox/checkbox.component.d.ts +3 -4
- package/lib/components/checkbox/checkbox.component.js +16 -3
- package/lib/components/date/date.component.js +33 -14
- package/lib/components/date-range/date-range.component.js +20 -2
- package/lib/components/date-range/date-range.d.ts +8 -0
- package/lib/components/decimal/decimal.component.d.ts +1 -1
- package/lib/components/decimal/decimal.component.js +20 -5
- package/lib/components/grouped-character/grouped-character.component.d.ts +1 -1
- package/lib/components/grouped-character/grouped-character.component.js +18 -4
- package/lib/components/icon-button/icon-button.component.js +7 -1
- package/lib/components/menu/menu-item/menu-item.component.js +1 -1
- package/lib/components/number/number.component.d.ts +2 -2
- package/lib/components/number/number.component.js +18 -4
- package/lib/components/numeral-date/numeral-date.component.d.ts +13 -1
- package/lib/components/numeral-date/numeral-date.component.js +48 -5
- package/lib/components/radio-button/radio-button.component.d.ts +2 -0
- package/lib/components/radio-button/radio-button.component.js +13 -1
- package/lib/components/search/search.component.d.ts +1 -1
- package/lib/components/search/search.component.js +16 -10
- package/lib/components/select/filterable-select/filterable-select.component.js +25 -7
- package/lib/components/select/multi-select/multi-select.component.js +25 -7
- package/lib/components/select/select-textbox/select-textbox.component.js +5 -3
- package/lib/components/select/simple-select/simple-select.component.js +26 -7
- package/lib/components/simple-color-picker/simple-color/simple-color.style.d.ts +1 -1
- package/lib/components/switch/switch.component.d.ts +4 -2
- package/lib/components/switch/switch.component.js +17 -3
- package/lib/components/textarea/textarea.component.d.ts +1 -1
- package/lib/components/textarea/textarea.component.js +38 -11
- package/lib/components/textbox/textbox.component.d.ts +1 -1
- package/lib/components/textbox/textbox.component.js +16 -3
- package/lib/components/tile-select/tile-select.component.js +17 -4
- package/package.json +1 -1
|
@@ -46,5 +46,5 @@ export interface CheckableInputProps extends CommonCheckableInputProps {
|
|
|
46
46
|
/** When true label is inline */
|
|
47
47
|
labelInline?: boolean;
|
|
48
48
|
}
|
|
49
|
-
declare const CheckableInput:
|
|
49
|
+
declare const CheckableInput: React.ForwardRefExoticComponent<CheckableInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
50
50
|
export default CheckableInput;
|
|
@@ -6,8 +6,7 @@ import FormField from "../form-field";
|
|
|
6
6
|
import HiddenCheckableInput from "./hidden-checkable-input.component";
|
|
7
7
|
import guid from "../utils/helpers/guid";
|
|
8
8
|
import useInputAccessibility from "../../hooks/__internal__/useInputAccessibility";
|
|
9
|
-
|
|
10
|
-
const CheckableInput = ({
|
|
9
|
+
const CheckableInput = /*#__PURE__*/React.forwardRef(({
|
|
11
10
|
ariaLabelledBy: externalAriaLabelledBy,
|
|
12
11
|
autoFocus,
|
|
13
12
|
checked,
|
|
@@ -18,7 +17,6 @@ const CheckableInput = ({
|
|
|
18
17
|
fieldHelpInline,
|
|
19
18
|
info,
|
|
20
19
|
id: inputId,
|
|
21
|
-
inputRef,
|
|
22
20
|
type,
|
|
23
21
|
value,
|
|
24
22
|
inputWidth,
|
|
@@ -37,7 +35,7 @@ const CheckableInput = ({
|
|
|
37
35
|
validationOnLabel,
|
|
38
36
|
warning,
|
|
39
37
|
...props
|
|
40
|
-
}) => {
|
|
38
|
+
}, ref) => {
|
|
41
39
|
const {
|
|
42
40
|
current: id
|
|
43
41
|
} = useRef(inputId || guid());
|
|
@@ -88,7 +86,6 @@ const CheckableInput = ({
|
|
|
88
86
|
checked,
|
|
89
87
|
disabled,
|
|
90
88
|
id,
|
|
91
|
-
inputRef,
|
|
92
89
|
type,
|
|
93
90
|
value,
|
|
94
91
|
name,
|
|
@@ -96,6 +93,7 @@ const CheckableInput = ({
|
|
|
96
93
|
onChange,
|
|
97
94
|
onFocus,
|
|
98
95
|
required,
|
|
96
|
+
ref,
|
|
99
97
|
...props
|
|
100
98
|
};
|
|
101
99
|
return /*#__PURE__*/React.createElement(StyledCheckableInputWrapper, {
|
|
@@ -106,8 +104,7 @@ const CheckableInput = ({
|
|
|
106
104
|
labelInline: labelInline,
|
|
107
105
|
reverse: reverse
|
|
108
106
|
}, /*#__PURE__*/React.createElement(InputBehaviour, null, /*#__PURE__*/React.createElement(FormField, formFieldProps, /*#__PURE__*/React.createElement(StyledCheckableInput, null, /*#__PURE__*/React.createElement(HiddenCheckableInput, inputProps), children))));
|
|
109
|
-
};
|
|
110
|
-
|
|
107
|
+
});
|
|
111
108
|
CheckableInput.propTypes = {
|
|
112
109
|
"about": PropTypes.string,
|
|
113
110
|
"accept": PropTypes.string,
|
|
@@ -203,9 +200,6 @@ CheckableInput.propTypes = {
|
|
|
203
200
|
"info": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
204
201
|
"inlist": PropTypes.any,
|
|
205
202
|
"inputMode": PropTypes.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
206
|
-
"inputRef": PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
207
|
-
"current": PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.object]).isRequired
|
|
208
|
-
})]),
|
|
209
203
|
"inputWidth": PropTypes.number,
|
|
210
204
|
"is": PropTypes.string,
|
|
211
205
|
"itemID": PropTypes.string,
|
|
@@ -469,4 +463,5 @@ CheckableInput.propTypes = {
|
|
|
469
463
|
"warning": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
470
464
|
"width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
471
465
|
};
|
|
466
|
+
CheckableInput.displayName = "CheckableInput";
|
|
472
467
|
export default CheckableInput;
|
|
@@ -18,8 +18,6 @@ export interface CommonHiddenCheckableInputProps extends Omit<React.InputHTMLAtt
|
|
|
18
18
|
onMouseEnter?: (ev: React.MouseEvent<HTMLInputElement>) => void;
|
|
19
19
|
/** Value of the input */
|
|
20
20
|
value?: string;
|
|
21
|
-
/** A callback to retrieve the input reference */
|
|
22
|
-
inputRef?: React.Ref<HTMLInputElement>;
|
|
23
21
|
}
|
|
24
22
|
export interface HiddenCheckableInputProps extends CommonHiddenCheckableInputProps {
|
|
25
23
|
/** HTML type attribute of the input */
|
|
@@ -27,5 +25,5 @@ export interface HiddenCheckableInputProps extends CommonHiddenCheckableInputPro
|
|
|
27
25
|
/** Role attribute of the input */
|
|
28
26
|
role?: string;
|
|
29
27
|
}
|
|
30
|
-
declare const _default: React.MemoExoticComponent<
|
|
28
|
+
declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<HiddenCheckableInputProps & React.RefAttributes<HTMLInputElement>>>;
|
|
31
29
|
export default _default;
|
|
@@ -4,18 +4,16 @@ import React, { useContext } from "react";
|
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import HiddenCheckableInputStyle from "./hidden-checkable-input.style";
|
|
6
6
|
import { InputContext, InputGroupContext } from "../input-behaviour";
|
|
7
|
-
|
|
8
|
-
const HiddenCheckableInput = ({
|
|
7
|
+
const HiddenCheckableInput = /*#__PURE__*/React.forwardRef(({
|
|
9
8
|
name,
|
|
10
9
|
checked,
|
|
11
10
|
type,
|
|
12
11
|
value,
|
|
13
|
-
inputRef,
|
|
14
12
|
onChange,
|
|
15
13
|
autoFocus,
|
|
16
14
|
role,
|
|
17
15
|
...props
|
|
18
|
-
}) => {
|
|
16
|
+
}, ref) => {
|
|
19
17
|
const {
|
|
20
18
|
onBlur,
|
|
21
19
|
onFocus,
|
|
@@ -70,10 +68,9 @@ const HiddenCheckableInput = ({
|
|
|
70
68
|
onMouseEnter: handleMouseEnter,
|
|
71
69
|
onMouseLeave: handleMouseLeave,
|
|
72
70
|
onChange: onChange,
|
|
73
|
-
ref:
|
|
71
|
+
ref: ref
|
|
74
72
|
}));
|
|
75
|
-
};
|
|
76
|
-
|
|
73
|
+
});
|
|
77
74
|
HiddenCheckableInput.propTypes = {
|
|
78
75
|
"about": PropTypes.string,
|
|
79
76
|
"accept": PropTypes.string,
|
|
@@ -164,9 +161,6 @@ HiddenCheckableInput.propTypes = {
|
|
|
164
161
|
"id": PropTypes.string,
|
|
165
162
|
"inlist": PropTypes.any,
|
|
166
163
|
"inputMode": PropTypes.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
167
|
-
"inputRef": PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
168
|
-
"current": PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.object]).isRequired
|
|
169
|
-
})]),
|
|
170
164
|
"is": PropTypes.string,
|
|
171
165
|
"itemID": PropTypes.string,
|
|
172
166
|
"itemProp": PropTypes.string,
|
|
@@ -369,4 +363,5 @@ HiddenCheckableInput.propTypes = {
|
|
|
369
363
|
"vocab": PropTypes.string,
|
|
370
364
|
"width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
371
365
|
};
|
|
366
|
+
HiddenCheckableInput.displayName = "HiddenCheckableInput";
|
|
372
367
|
export default /*#__PURE__*/React.memo(HiddenCheckableInput);
|
|
@@ -10,7 +10,7 @@ export interface CommonInputProps extends Omit<React.InputHTMLAttributes<HTMLInp
|
|
|
10
10
|
/** HTML id attribute of the input */
|
|
11
11
|
id?: string;
|
|
12
12
|
/** A callback to retrieve the input reference */
|
|
13
|
-
inputRef?: (input: React.RefObject<HTMLInputElement>) => void;
|
|
13
|
+
inputRef?: (input: React.RefObject<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
14
14
|
/** Name of the input */
|
|
15
15
|
name?: string;
|
|
16
16
|
/** Specify a callback triggered on blur */
|
|
@@ -42,5 +42,5 @@ export interface InputProps extends CommonInputProps {
|
|
|
42
42
|
/** HTML type attribute of the input */
|
|
43
43
|
type?: string;
|
|
44
44
|
}
|
|
45
|
-
declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
|
|
45
|
+
declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement | HTMLTextAreaElement>>;
|
|
46
46
|
export default Input;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
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); }
|
|
2
2
|
|
|
3
|
-
import React, { useEffect, useContext, useRef } from "react";
|
|
3
|
+
import React, { useEffect, useContext, useRef, useCallback } from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import StyledInput from "./input.style";
|
|
6
6
|
import { InputContext, InputGroupContext } from "../input-behaviour";
|
|
@@ -33,6 +33,7 @@ const Input = /*#__PURE__*/React.forwardRef(({
|
|
|
33
33
|
disabled,
|
|
34
34
|
readOnly,
|
|
35
35
|
autoFocus,
|
|
36
|
+
// TODO: remove inputRef prop from this component (and props interface) when it has been removed from all exposed input components
|
|
36
37
|
inputRef,
|
|
37
38
|
onClick,
|
|
38
39
|
onChangeDeferred,
|
|
@@ -50,15 +51,21 @@ const Input = /*#__PURE__*/React.forwardRef(({
|
|
|
50
51
|
const deferredTimeout = useRef(null);
|
|
51
52
|
let input = useRef(null);
|
|
52
53
|
|
|
53
|
-
if (ref) {
|
|
54
|
+
if (ref && "current" in ref) {
|
|
54
55
|
input = ref;
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const callbackRef = useCallback(element => {
|
|
59
|
+
input.current = element;
|
|
60
|
+
|
|
61
|
+
if (typeof ref === "function") {
|
|
62
|
+
ref(element);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (autoFocus && element) {
|
|
66
|
+
element.focus();
|
|
60
67
|
}
|
|
61
|
-
}, [autoFocus,
|
|
68
|
+
}, [autoFocus, ref]);
|
|
62
69
|
useEffect(() => {
|
|
63
70
|
if (inputRef) {
|
|
64
71
|
inputRef(input);
|
|
@@ -146,7 +153,7 @@ const Input = /*#__PURE__*/React.forwardRef(({
|
|
|
146
153
|
name: name,
|
|
147
154
|
type: type,
|
|
148
155
|
id: id || name,
|
|
149
|
-
ref:
|
|
156
|
+
ref: callbackRef,
|
|
150
157
|
"data-element": "input",
|
|
151
158
|
onFocus: handleFocus,
|
|
152
159
|
onBlur: handleBlur,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
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); }
|
|
2
2
|
|
|
3
|
-
import React, { useCallback, useState } from "react";
|
|
3
|
+
import React, { useCallback, useState, useContext } from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import invariant from "invariant";
|
|
6
6
|
import Icon from "../icon";
|
|
@@ -8,6 +8,7 @@ import StyledButton, { StyledButtonSubtext } from "./button.style";
|
|
|
8
8
|
import tagComponent from "../../__internal__/utils/helpers/tags/tags";
|
|
9
9
|
import { TooltipProvider } from "../../__internal__/tooltip-provider";
|
|
10
10
|
import Logger from "../../__internal__/utils/logger";
|
|
11
|
+
import { ButtonBarContext } from "../button-bar/button-bar.component";
|
|
11
12
|
|
|
12
13
|
function renderChildren({
|
|
13
14
|
/* eslint-disable react/prop-types */
|
|
@@ -75,8 +76,9 @@ renderChildren.propTypes = {
|
|
|
75
76
|
}
|
|
76
77
|
};
|
|
77
78
|
let deprecatedForwardRefWarnTriggered = false;
|
|
79
|
+
let deprecatedDashedButtonWarnTriggered = false;
|
|
78
80
|
const Button = /*#__PURE__*/React.forwardRef(({
|
|
79
|
-
size = "medium",
|
|
81
|
+
size: sizeProp = "medium",
|
|
80
82
|
subtext = "",
|
|
81
83
|
children,
|
|
82
84
|
forwardRef,
|
|
@@ -85,7 +87,7 @@ const Button = /*#__PURE__*/React.forwardRef(({
|
|
|
85
87
|
destructive = false,
|
|
86
88
|
buttonType: buttonTypeProp = "secondary",
|
|
87
89
|
iconType,
|
|
88
|
-
iconPosition = "before",
|
|
90
|
+
iconPosition: iconPositionProp = "before",
|
|
89
91
|
href,
|
|
90
92
|
m = 0,
|
|
91
93
|
px,
|
|
@@ -94,9 +96,19 @@ const Button = /*#__PURE__*/React.forwardRef(({
|
|
|
94
96
|
rel,
|
|
95
97
|
iconTooltipMessage,
|
|
96
98
|
iconTooltipPosition,
|
|
97
|
-
fullWidth = false,
|
|
99
|
+
fullWidth: fullWidthProp = false,
|
|
98
100
|
...rest
|
|
99
101
|
}, ref) => {
|
|
102
|
+
const {
|
|
103
|
+
buttonType: buttonTypeContext,
|
|
104
|
+
size: sizeContext,
|
|
105
|
+
iconPosition: iconPositionContext,
|
|
106
|
+
fullWidth: fullWidthContext
|
|
107
|
+
} = useContext(ButtonBarContext);
|
|
108
|
+
const buttonType = buttonTypeContext || buttonTypeProp;
|
|
109
|
+
const size = sizeContext || sizeProp;
|
|
110
|
+
const iconPosition = iconPositionContext || iconPositionProp;
|
|
111
|
+
const fullWidth = fullWidthContext || fullWidthProp;
|
|
100
112
|
!!!(children || iconType) ? process.env.NODE_ENV !== "production" ? invariant(false, "Either prop `iconType` must be defined or this node must have children.") : invariant(false) : void 0;
|
|
101
113
|
|
|
102
114
|
if (subtext) {
|
|
@@ -108,8 +120,12 @@ const Button = /*#__PURE__*/React.forwardRef(({
|
|
|
108
120
|
Logger.deprecate("The `forwardRef` prop in `Button` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
109
121
|
}
|
|
110
122
|
|
|
123
|
+
if (!deprecatedDashedButtonWarnTriggered && buttonType === "dashed") {
|
|
124
|
+
deprecatedDashedButtonWarnTriggered = true;
|
|
125
|
+
Logger.deprecate("The `dashed` variant of the `buttonType` prop for `Button` component is deprecated and will soon be removed.");
|
|
126
|
+
}
|
|
127
|
+
|
|
111
128
|
const [internalRef, setInternalRef] = useState();
|
|
112
|
-
const buttonType = buttonTypeProp;
|
|
113
129
|
let paddingX;
|
|
114
130
|
|
|
115
131
|
const handleLinkKeyDown = event => {
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { SpaceProps } from "styled-system";
|
|
3
|
-
export interface
|
|
4
|
-
/** Button or IconButton Elements, to be rendered inside the component */
|
|
5
|
-
children: React.ReactNode;
|
|
3
|
+
export interface ButtonBarContextProps {
|
|
6
4
|
/** Apply fullWidth style to the button bar */
|
|
7
5
|
fullWidth?: boolean;
|
|
8
6
|
/** Defines an Icon position for buttons: "before" | "after" */
|
|
9
7
|
iconPosition?: "before" | "after";
|
|
10
8
|
/** Assigns a size to the buttons: "small" | "medium" | "large" */
|
|
11
9
|
size?: "small" | "medium" | "large";
|
|
10
|
+
/** Color variants for new business themes: "primary" | "secondary" | "tertiary" | "darkBackground" */
|
|
11
|
+
buttonType?: "primary" | "secondary" | "primary";
|
|
12
|
+
}
|
|
13
|
+
export interface ButtonBarProps extends ButtonBarContextProps, SpaceProps {
|
|
14
|
+
/** Button or IconButton Elements, to be rendered inside the component */
|
|
15
|
+
children: React.ReactNode;
|
|
12
16
|
}
|
|
17
|
+
export declare const ButtonBarContext: React.Context<ButtonBarContextProps>;
|
|
13
18
|
export declare const ButtonBar: {
|
|
14
19
|
({ children, size, iconPosition, fullWidth, ...rest }: ButtonBarProps): JSX.Element;
|
|
15
20
|
displayName: string;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
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); }
|
|
2
2
|
|
|
3
|
-
import React
|
|
3
|
+
import React from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
|
-
import invariant from "invariant";
|
|
6
5
|
import StyledButtonBar from "./button-bar.style";
|
|
7
|
-
|
|
8
|
-
import IconButton from "../icon-button";
|
|
6
|
+
export const ButtonBarContext = /*#__PURE__*/React.createContext({});
|
|
9
7
|
|
|
10
8
|
const ButtonBar = ({
|
|
11
9
|
children,
|
|
@@ -13,39 +11,20 @@ const ButtonBar = ({
|
|
|
13
11
|
iconPosition = "before",
|
|
14
12
|
fullWidth = false,
|
|
15
13
|
...rest
|
|
16
|
-
}) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
!hasProperChildren ? process.env.NODE_ENV !== "production" ? invariant(false, "ButtonBar accepts only `Button` or `IconButton` elements.") : invariant(false) : void 0;
|
|
28
|
-
|
|
29
|
-
const getBtnProps = child => {
|
|
30
|
-
var _child$props, _child$props2, _child$props2$childre, _child$props2$childre2;
|
|
31
|
-
|
|
32
|
-
const btnProps = { ...child.props,
|
|
33
|
-
buttonType: "secondary",
|
|
34
|
-
size,
|
|
35
|
-
iconPosition,
|
|
36
|
-
fullWidth,
|
|
37
|
-
"aria-label": child.type === IconButton ? ((_child$props = child.props) === null || _child$props === void 0 ? void 0 : _child$props.ariaLabel) || ((_child$props2 = child.props) === null || _child$props2 === void 0 ? void 0 : (_child$props2$childre = _child$props2.children) === null || _child$props2$childre === void 0 ? void 0 : (_child$props2$childre2 = _child$props2$childre.props) === null || _child$props2$childre2 === void 0 ? void 0 : _child$props2$childre2.type) : ""
|
|
38
|
-
};
|
|
39
|
-
return btnProps;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
return /*#__PURE__*/React.createElement(StyledButtonBar, _extends({}, rest, {
|
|
43
|
-
fullWidth: fullWidth,
|
|
44
|
-
size: size
|
|
45
|
-
}), React.Children.map(children, child => /*#__PURE__*/React.createElement(child.type, getBtnProps(child))));
|
|
46
|
-
};
|
|
14
|
+
}) => /*#__PURE__*/React.createElement(StyledButtonBar, _extends({}, rest, {
|
|
15
|
+
fullWidth: fullWidth,
|
|
16
|
+
size: size
|
|
17
|
+
}), /*#__PURE__*/React.createElement(ButtonBarContext.Provider, {
|
|
18
|
+
value: {
|
|
19
|
+
buttonType: "secondary",
|
|
20
|
+
size,
|
|
21
|
+
iconPosition,
|
|
22
|
+
fullWidth
|
|
23
|
+
}
|
|
24
|
+
}, children));
|
|
47
25
|
|
|
48
26
|
ButtonBar.propTypes = {
|
|
27
|
+
"buttonType": PropTypes.oneOf(["primary", "secondary"]),
|
|
49
28
|
"children": PropTypes.node,
|
|
50
29
|
"fullWidth": PropTypes.bool,
|
|
51
30
|
"iconPosition": PropTypes.oneOf(["after", "before"]),
|
|
@@ -22,9 +22,8 @@ export interface CheckboxProps extends CommonCheckableInputProps, MarginProps {
|
|
|
22
22
|
tooltipPosition?: "top" | "bottom" | "left" | "right";
|
|
23
23
|
/** The value of the checkbox, passed on form submit */
|
|
24
24
|
value?: string;
|
|
25
|
+
/** A callback to retrieve the input reference (deprecated) */
|
|
26
|
+
inputRef?: React.Ref<HTMLInputElement>;
|
|
25
27
|
}
|
|
26
|
-
export declare const Checkbox:
|
|
27
|
-
({ id, label, onChange, name, onClick, onBlur, onFocus, value, fieldHelp, autoFocus, labelHelp, labelSpacing, labelWidth, adaptiveSpacingBreakpoint, required, error, warning, info, fieldHelpInline, reverse, checked, disabled, inputWidth, size, tooltipPosition, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, helpAriaLabel, ...props }: CheckboxProps): JSX.Element;
|
|
28
|
-
displayName: string;
|
|
29
|
-
};
|
|
28
|
+
export declare const Checkbox: React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLInputElement>>;
|
|
30
29
|
export default Checkbox;
|
|
@@ -9,8 +9,9 @@ import useIsAboveBreakpoint from "../../hooks/__internal__/useIsAboveBreakpoint"
|
|
|
9
9
|
import { filterStyledSystemMarginProps } from "../../style/utils";
|
|
10
10
|
import { TooltipProvider } from "../../__internal__/tooltip-provider";
|
|
11
11
|
import { CheckboxGroupContext } from "./checkbox-group.component";
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
import Logger from "../../__internal__/utils/logger";
|
|
13
|
+
let deprecateInputRefWarnTriggered = false;
|
|
14
|
+
const Checkbox = /*#__PURE__*/React.forwardRef(({
|
|
14
15
|
id,
|
|
15
16
|
label,
|
|
16
17
|
onChange,
|
|
@@ -42,8 +43,9 @@ const Checkbox = ({
|
|
|
42
43
|
"data-element": dataElement,
|
|
43
44
|
"data-role": dataRole,
|
|
44
45
|
helpAriaLabel,
|
|
46
|
+
inputRef,
|
|
45
47
|
...props
|
|
46
|
-
}) => {
|
|
48
|
+
}, ref) => {
|
|
47
49
|
const largeScreen = useIsAboveBreakpoint(adaptiveSpacingBreakpoint);
|
|
48
50
|
const adaptiveSpacingSmallScreen = !!(adaptiveSpacingBreakpoint && !largeScreen);
|
|
49
51
|
const {
|
|
@@ -51,6 +53,12 @@ const Checkbox = ({
|
|
|
51
53
|
warning: contextWarning,
|
|
52
54
|
info: contextInfo
|
|
53
55
|
} = useContext(CheckboxGroupContext);
|
|
56
|
+
|
|
57
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
58
|
+
deprecateInputRefWarnTriggered = true;
|
|
59
|
+
Logger.deprecate("The `inputRef` prop in `Checkbox` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
60
|
+
}
|
|
61
|
+
|
|
54
62
|
const inputProps = {
|
|
55
63
|
onClick,
|
|
56
64
|
onChange,
|
|
@@ -77,6 +85,7 @@ const Checkbox = ({
|
|
|
77
85
|
inputWidth,
|
|
78
86
|
labelWidth,
|
|
79
87
|
tooltipPosition,
|
|
88
|
+
ref: ref || inputRef,
|
|
80
89
|
...props
|
|
81
90
|
};
|
|
82
91
|
return /*#__PURE__*/React.createElement(TooltipProvider, {
|
|
@@ -97,8 +106,7 @@ const Checkbox = ({
|
|
|
97
106
|
reverse: reverse,
|
|
98
107
|
size: size
|
|
99
108
|
}, filterStyledSystemMarginProps(props)), /*#__PURE__*/React.createElement(CheckableInput, inputProps, /*#__PURE__*/React.createElement(CheckboxSvg, null))));
|
|
100
|
-
};
|
|
101
|
-
|
|
109
|
+
});
|
|
102
110
|
Checkbox.propTypes = {
|
|
103
111
|
"about": PropTypes.string,
|
|
104
112
|
"accept": PropTypes.string,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
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); }
|
|
2
2
|
|
|
3
|
-
import React, { useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import React, { useContext, useEffect, useMemo, useRef, useState, useCallback } from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import styledSystemPropTypes from "@styled-system/prop-types";
|
|
6
6
|
import { additionalYears, findMatchedFormatAndValue, formattedValue, formatToISO, isDateValid, parseDate, parseISODate, checkISOFormatAndLength, getSeparator } from "./__internal__/utils";
|
|
@@ -13,9 +13,10 @@ import Textbox from "../textbox";
|
|
|
13
13
|
import DatePicker from "./__internal__/date-picker";
|
|
14
14
|
import DateRangeContext from "../date-range/date-range.context";
|
|
15
15
|
import useClickAwayListener from "../../hooks/__internal__/useClickAwayListener";
|
|
16
|
+
import Logger from "../../__internal__/utils/logger";
|
|
16
17
|
const marginPropTypes = filterStyledSystemMarginProps(styledSystemPropTypes.space);
|
|
17
|
-
|
|
18
|
-
const DateInput = ({
|
|
18
|
+
let deprecateInputRefWarnTriggered = false;
|
|
19
|
+
const DateInput = /*#__PURE__*/React.forwardRef(({
|
|
19
20
|
adaptiveLabelBreakpoint,
|
|
20
21
|
allowEmptyValue,
|
|
21
22
|
autoFocus,
|
|
@@ -38,11 +39,12 @@ const DateInput = ({
|
|
|
38
39
|
size = "medium",
|
|
39
40
|
tooltipPosition,
|
|
40
41
|
value,
|
|
42
|
+
inputRef,
|
|
41
43
|
...rest
|
|
42
|
-
}) => {
|
|
44
|
+
}, ref) => {
|
|
43
45
|
const wrapperRef = useRef();
|
|
44
46
|
const parentRef = useRef();
|
|
45
|
-
const
|
|
47
|
+
const internalInputRef = useRef();
|
|
46
48
|
const alreadyFocused = useRef(false);
|
|
47
49
|
const isBlurBlocked = useRef(false);
|
|
48
50
|
const focusedViaPicker = useRef(false);
|
|
@@ -63,6 +65,11 @@ const DateInput = ({
|
|
|
63
65
|
const [selectedDays, setSelectedDays] = useState(checkISOFormatAndLength(value) ? parseISODate(value) : parseDate(format, value));
|
|
64
66
|
const isInitialValue = useRef(true);
|
|
65
67
|
|
|
68
|
+
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
69
|
+
deprecateInputRefWarnTriggered = true;
|
|
70
|
+
Logger.deprecate("The `inputRef` prop in `DateInput` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
71
|
+
}
|
|
72
|
+
|
|
66
73
|
const computeInvalidRawValue = inputValue => allowEmptyValue && !inputValue.length ? inputValue : null;
|
|
67
74
|
|
|
68
75
|
const buildCustomEvent = ev => {
|
|
@@ -90,9 +97,9 @@ const DateInput = ({
|
|
|
90
97
|
const handleClickAway = () => {
|
|
91
98
|
if (open) {
|
|
92
99
|
alreadyFocused.current = true;
|
|
93
|
-
|
|
100
|
+
internalInputRef.current.focus();
|
|
94
101
|
isBlurBlocked.current = false;
|
|
95
|
-
|
|
102
|
+
internalInputRef.current.blur();
|
|
96
103
|
setOpen(false);
|
|
97
104
|
alreadyFocused.current = false;
|
|
98
105
|
}
|
|
@@ -106,10 +113,10 @@ const DateInput = ({
|
|
|
106
113
|
};
|
|
107
114
|
|
|
108
115
|
const focusInput = () => {
|
|
109
|
-
var
|
|
116
|
+
var _internalInputRef$cur;
|
|
110
117
|
|
|
111
118
|
focusedViaPicker.current = true;
|
|
112
|
-
(
|
|
119
|
+
(_internalInputRef$cur = internalInputRef.current) === null || _internalInputRef$cur === void 0 ? void 0 : _internalInputRef$cur.focus();
|
|
113
120
|
};
|
|
114
121
|
|
|
115
122
|
const handleDayClick = (day, ev) => {
|
|
@@ -234,11 +241,19 @@ const DateInput = ({
|
|
|
234
241
|
handleClickInside(ev);
|
|
235
242
|
};
|
|
236
243
|
|
|
237
|
-
const assignInput =
|
|
244
|
+
const assignInput = useCallback(inputElement => {
|
|
238
245
|
var _inputRefMap$inputNam;
|
|
239
246
|
|
|
240
|
-
|
|
241
|
-
parentRef.current =
|
|
247
|
+
internalInputRef.current = inputElement;
|
|
248
|
+
parentRef.current = inputElement === null || inputElement === void 0 ? void 0 : inputElement.parentElement;
|
|
249
|
+
|
|
250
|
+
if (ref) {
|
|
251
|
+
if (typeof ref === "function") {
|
|
252
|
+
ref(inputElement);
|
|
253
|
+
} else {
|
|
254
|
+
ref.current = inputElement;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
242
257
|
|
|
243
258
|
if (inputRefMap && ((_inputRefMap$inputNam = inputRefMap[inputName]) === null || _inputRefMap$inputNam === void 0 ? void 0 : _inputRefMap$inputNam.setOpen) !== setOpen) {
|
|
244
259
|
setInputRefMap({
|
|
@@ -248,8 +263,7 @@ const DateInput = ({
|
|
|
248
263
|
}
|
|
249
264
|
});
|
|
250
265
|
}
|
|
251
|
-
};
|
|
252
|
-
|
|
266
|
+
}, [inputName, inputRefMap, setInputRefMap, ref]);
|
|
253
267
|
useEffect(() => {
|
|
254
268
|
const [matchedFormat, matchedValue] = findMatchedFormatAndValue(value, formats);
|
|
255
269
|
|
|
@@ -292,6 +306,7 @@ const DateInput = ({
|
|
|
292
306
|
}, filterStyledSystemMarginProps(rest), {
|
|
293
307
|
applyDateRangeStyling: !!inputRefMap
|
|
294
308
|
}), /*#__PURE__*/React.createElement(Textbox, _extends({}, filterOutStyledSystemSpacingProps(rest), {
|
|
309
|
+
inputRef: inputRef,
|
|
295
310
|
value: computedValue(),
|
|
296
311
|
onBlur: handleBlur,
|
|
297
312
|
onChange: handleChange,
|
|
@@ -303,7 +318,7 @@ const DateInput = ({
|
|
|
303
318
|
iconOnMouseDown: handleIconMouseDown,
|
|
304
319
|
inputIcon: "calendar",
|
|
305
320
|
labelInline: labelInline,
|
|
306
|
-
|
|
321
|
+
ref: assignInput,
|
|
307
322
|
adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
|
|
308
323
|
tooltipPosition: tooltipPosition,
|
|
309
324
|
helpAriaLabel: helpAriaLabel,
|
|
@@ -323,8 +338,7 @@ const DateInput = ({
|
|
|
323
338
|
pickerMouseDown: handlePickerMouseDown,
|
|
324
339
|
open: open
|
|
325
340
|
}));
|
|
326
|
-
};
|
|
327
|
-
|
|
341
|
+
});
|
|
328
342
|
DateInput.propTypes = { ...Textbox.propTypes,
|
|
329
343
|
...marginPropTypes,
|
|
330
344
|
|
|
@@ -351,4 +365,5 @@ DateInput.propTypes = { ...Textbox.propTypes,
|
|
|
351
365
|
/** Boolean to allow the input to have an empty value */
|
|
352
366
|
allowEmptyValue: PropTypes.bool
|
|
353
367
|
};
|
|
368
|
+
DateInput.displayName = "DateInput";
|
|
354
369
|
export default DateInput;
|
|
@@ -26,6 +26,8 @@ const DateRange = ({
|
|
|
26
26
|
tooltipPosition,
|
|
27
27
|
validationOnLabel,
|
|
28
28
|
value,
|
|
29
|
+
startRef,
|
|
30
|
+
endRef,
|
|
29
31
|
...rest
|
|
30
32
|
}) => {
|
|
31
33
|
const l = useLocale();
|
|
@@ -220,13 +222,15 @@ const DateRange = ({
|
|
|
220
222
|
"data-element": "start-date",
|
|
221
223
|
labelWidth: inlineLabelWidth // Textbox only applies this when labelsInLine prop is true
|
|
222
224
|
,
|
|
223
|
-
tooltipPosition: tooltipPosition
|
|
225
|
+
tooltipPosition: tooltipPosition,
|
|
226
|
+
ref: startRef
|
|
224
227
|
})), /*#__PURE__*/React.createElement(DateInput, _extends({}, dateProps("end"), {
|
|
225
228
|
onFocus: () => handleFocus("start"),
|
|
226
229
|
"data-element": "end-date",
|
|
227
230
|
labelWidth: inlineLabelWidth // Textbox only applies this when labelsInLine prop is true
|
|
228
231
|
,
|
|
229
|
-
tooltipPosition: tooltipPosition
|
|
232
|
+
tooltipPosition: tooltipPosition,
|
|
233
|
+
ref: endRef
|
|
230
234
|
}))));
|
|
231
235
|
};
|
|
232
236
|
|
|
@@ -268,6 +272,13 @@ DateRange.propTypes = {
|
|
|
268
272
|
Pass true boolean to only display blue border */
|
|
269
273
|
startInfo: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
270
274
|
|
|
275
|
+
/**
|
|
276
|
+
* A React ref to pass to the first of the two Date Input fields
|
|
277
|
+
*/
|
|
278
|
+
startRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
279
|
+
current: PropTypes.instanceOf(HTMLInputElement)
|
|
280
|
+
})]),
|
|
281
|
+
|
|
271
282
|
/** Indicate that error has occurred on end date
|
|
272
283
|
Pass string to display icon, tooltip and red border
|
|
273
284
|
Pass true boolean to only display red border */
|
|
@@ -283,6 +294,13 @@ DateRange.propTypes = {
|
|
|
283
294
|
Pass true boolean to only display blue border */
|
|
284
295
|
endInfo: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
285
296
|
|
|
297
|
+
/**
|
|
298
|
+
* A React ref to pass to the second of the two Date Input fields
|
|
299
|
+
*/
|
|
300
|
+
endRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
|
301
|
+
current: PropTypes.instanceOf(HTMLInputElement)
|
|
302
|
+
})]),
|
|
303
|
+
|
|
286
304
|
/** When true, validation icons will be placed on labels instead of being placed on the inputs */
|
|
287
305
|
validationOnLabel: PropTypes.bool,
|
|
288
306
|
|