carbon-react 106.0.1 → 106.1.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__/input/index.d.ts +5 -5
- package/esm/__internal__/input/input-presentation.component.d.ts +21 -27
- package/esm/__internal__/input/input-presentation.component.js +7 -20
- package/esm/__internal__/input/input-presentation.style.d.ts +5 -8
- package/esm/__internal__/input/input-presentation.style.js +37 -53
- package/esm/__internal__/input/input-sizes.style.d.ts +8 -18
- package/esm/__internal__/input/input-sizes.style.js +3 -2
- package/esm/__internal__/input/input.component.d.ts +39 -2
- package/esm/__internal__/input/input.component.js +84 -66
- package/esm/__internal__/input/input.style.d.ts +2 -1
- package/esm/__internal__/input/input.style.js +0 -4
- package/esm/__internal__/input-behaviour/index.d.ts +2 -1
- package/esm/__internal__/input-behaviour/input-behaviour.component.d.ts +7 -10
- package/esm/__internal__/input-behaviour/input-behaviour.component.js +2 -7
- package/esm/__internal__/input-behaviour/input-group-behaviour.component.d.ts +8 -12
- package/esm/__internal__/input-behaviour/input-group-behaviour.component.js +1 -7
- package/esm/__internal__/input-behaviour/useInputBehaviour.d.ts +14 -10
- package/esm/__internal__/label/label.d.ts +1 -1
- package/esm/components/badge/badge.component.d.ts +10 -13
- package/esm/components/badge/badge.component.js +60 -24
- package/esm/components/badge/badge.style.d.ts +7 -5
- package/esm/components/badge/index.d.ts +2 -1
- package/esm/components/carbon-provider/carbon-provider.component.d.ts +8 -14
- package/esm/components/carbon-provider/carbon-provider.component.js +110 -14
- package/esm/components/carbon-provider/index.d.ts +2 -1
- package/esm/components/date-range/date-range.style.js +2 -2
- package/esm/components/decimal/decimal.component.js +2 -1
- package/esm/components/heading/heading.style.d.ts +1 -2
- package/esm/components/inline-inputs/index.d.ts +2 -1
- package/esm/components/inline-inputs/index.js +1 -1
- package/esm/components/inline-inputs/inline-inputs.component.d.ts +25 -22
- package/esm/components/inline-inputs/inline-inputs.component.js +96 -60
- package/esm/components/inline-inputs/inline-inputs.config.d.ts +1 -1
- package/esm/components/inline-inputs/inline-inputs.style.d.ts +5 -3
- package/esm/components/inline-inputs/inline-inputs.style.js +2 -2
- package/esm/components/link/index.d.ts +1 -2
- package/esm/components/link/link.component.d.ts +37 -2
- package/esm/components/link/link.component.js +1243 -124
- package/esm/components/link/link.config.d.ts +2 -2
- package/esm/components/link/link.style.d.ts +7 -2
- package/esm/components/link/link.style.js +0 -5
- package/esm/components/pager/pager.style.d.ts +1 -2
- package/esm/components/pod/pod.style.d.ts +1 -2
- package/esm/components/simple-color-picker/simple-color-input/simple-color-input.style.d.ts +1 -1
- package/esm/components/split-button/index.d.ts +1 -0
- package/esm/components/text-editor/__internal__/editor-link/editor-link.style.d.ts +1 -2
- package/esm/components/textarea/textarea-test.stories.js +21 -1
- package/esm/components/tile-select/tile-select.style.d.ts +1 -1
- package/esm/style/fonts.css +22 -16
- package/lib/__internal__/input/index.d.ts +5 -5
- package/lib/__internal__/input/input-presentation.component.d.ts +21 -27
- package/lib/__internal__/input/input-presentation.component.js +7 -23
- package/lib/__internal__/input/input-presentation.style.d.ts +5 -8
- package/lib/__internal__/input/input-presentation.style.js +37 -54
- package/lib/__internal__/input/input-sizes.style.d.ts +8 -18
- package/lib/__internal__/input/input-sizes.style.js +2 -1
- package/lib/__internal__/input/input.component.d.ts +39 -2
- package/lib/__internal__/input/input.component.js +85 -69
- package/lib/__internal__/input/input.style.d.ts +2 -1
- package/lib/__internal__/input/input.style.js +0 -7
- package/lib/__internal__/input-behaviour/index.d.ts +2 -1
- package/lib/__internal__/input-behaviour/input-behaviour.component.d.ts +7 -10
- package/lib/__internal__/input-behaviour/input-behaviour.component.js +3 -10
- package/lib/__internal__/input-behaviour/input-group-behaviour.component.d.ts +8 -12
- package/lib/__internal__/input-behaviour/input-group-behaviour.component.js +2 -10
- package/lib/__internal__/input-behaviour/useInputBehaviour.d.ts +14 -10
- package/lib/__internal__/label/label.d.ts +1 -1
- package/lib/components/badge/badge.component.d.ts +10 -13
- package/lib/components/badge/badge.component.js +51 -29
- package/lib/components/badge/badge.style.d.ts +7 -5
- package/lib/components/badge/index.d.ts +2 -1
- package/lib/components/carbon-provider/carbon-provider.component.d.ts +8 -14
- package/lib/components/carbon-provider/carbon-provider.component.js +115 -20
- package/lib/components/carbon-provider/index.d.ts +2 -1
- package/lib/components/date-range/date-range.style.js +4 -4
- package/lib/components/decimal/decimal.component.js +2 -1
- package/lib/components/heading/heading.style.d.ts +1 -2
- package/lib/components/inline-inputs/index.d.ts +2 -1
- package/lib/components/inline-inputs/index.js +10 -2
- package/lib/components/inline-inputs/inline-inputs.component.d.ts +25 -22
- package/lib/components/inline-inputs/inline-inputs.component.js +143 -68
- package/lib/components/inline-inputs/inline-inputs.config.d.ts +1 -1
- package/lib/components/inline-inputs/inline-inputs.style.d.ts +5 -3
- package/lib/components/inline-inputs/inline-inputs.style.js +2 -2
- package/lib/components/link/index.d.ts +1 -2
- package/lib/components/link/link.component.d.ts +37 -2
- package/lib/components/link/link.component.js +764 -146
- package/lib/components/link/link.config.d.ts +2 -2
- package/lib/components/link/link.style.d.ts +7 -2
- package/lib/components/link/link.style.js +0 -6
- package/lib/components/pager/pager.style.d.ts +1 -2
- package/lib/components/pod/pod.style.d.ts +1 -2
- package/lib/components/simple-color-picker/simple-color-input/simple-color-input.style.d.ts +1 -1
- package/lib/components/split-button/index.d.ts +1 -0
- package/lib/components/text-editor/__internal__/editor-link/editor-link.style.d.ts +1 -2
- package/lib/components/textarea/textarea-test.stories.js +21 -1
- package/lib/components/tile-select/tile-select.style.d.ts +1 -1
- package/lib/style/fonts.css +22 -16
- package/package.json +1 -2
- package/esm/__internal__/input/extract-props/extract-props.d.ts +0 -1
- package/esm/__internal__/input/extract-props/extract-props.js +0 -11
- package/esm/__internal__/input/extract-props/index.d.ts +0 -1
- package/esm/__internal__/input/extract-props/index.js +0 -1
- package/esm/__internal__/input/input-presentation.d.ts +0 -24
- package/esm/__internal__/input/input.d.ts +0 -54
- package/esm/components/badge/badge.d.ts +0 -14
- package/esm/components/carbon-provider/carbon-provider.d.ts +0 -12
- package/esm/components/inline-inputs/inline-inputs.d.ts +0 -30
- package/esm/components/link/link.d.ts +0 -47
- package/lib/__internal__/input/extract-props/extract-props.d.ts +0 -1
- package/lib/__internal__/input/extract-props/extract-props.js +0 -18
- package/lib/__internal__/input/extract-props/index.d.ts +0 -1
- package/lib/__internal__/input/extract-props/index.js +0 -15
- package/lib/__internal__/input/extract-props/package.json +0 -6
- package/lib/__internal__/input/input-presentation.d.ts +0 -24
- package/lib/__internal__/input/input.d.ts +0 -54
- package/lib/components/badge/badge.d.ts +0 -14
- package/lib/components/carbon-provider/carbon-provider.d.ts +0 -12
- package/lib/components/inline-inputs/inline-inputs.d.ts +0 -30
- package/lib/components/link/link.d.ts +0 -47
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import Input from "./input.component";
|
|
2
|
+
import InputPresentation from "./input-presentation.component";
|
|
3
|
+
export type { InputProps } from "./input.component";
|
|
4
|
+
export { Input, InputPresentation };
|
|
5
|
+
export default Input;
|
|
@@ -1,28 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
disabled
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const readOnly: PropTypes.Requireable<boolean>;
|
|
21
|
-
const positionedChildren: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
22
|
-
const size: PropTypes.Requireable<string>;
|
|
23
|
-
const error: PropTypes.Requireable<string | boolean>;
|
|
24
|
-
const warning: PropTypes.Requireable<string | boolean>;
|
|
25
|
-
const info: PropTypes.Requireable<string | boolean>;
|
|
26
|
-
}
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ValidationPropTypes } from "../validations";
|
|
3
|
+
export declare type Sizes = "small" | "medium" | "large";
|
|
4
|
+
export interface CommonInputPresentationProps extends ValidationPropTypes {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
/** If true, the component will be disabled */
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/** The default value alignment on the input */
|
|
9
|
+
align?: string;
|
|
10
|
+
/** The width of the input as a percentage */
|
|
11
|
+
inputWidth?: number;
|
|
12
|
+
/** If true, the component will be read-only */
|
|
13
|
+
readOnly?: boolean;
|
|
14
|
+
/** Size of an input */
|
|
15
|
+
size?: Sizes;
|
|
16
|
+
}
|
|
17
|
+
export interface InputPresentationProps extends CommonInputPresentationProps {
|
|
18
|
+
/** Content to be rendered before the input */
|
|
19
|
+
positionedChildren?: React.ReactNode;
|
|
27
20
|
}
|
|
28
|
-
|
|
21
|
+
declare const InputPresentation: ({ children, positionedChildren, inputWidth, align, disabled, readOnly, size, error, warning, info, }: InputPresentationProps) => JSX.Element;
|
|
22
|
+
export default InputPresentation;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { useContext } from "react";
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
2
|
import InputPresentationStyle, { StyledInputPresentationContainer } from "./input-presentation.style";
|
|
4
3
|
import { InputContext, InputGroupContext } from "../input-behaviour";
|
|
5
4
|
import { NewValidationContext } from "../../components/carbon-provider/carbon-provider.component";
|
|
@@ -11,7 +10,7 @@ const InputPresentation = ({
|
|
|
11
10
|
align,
|
|
12
11
|
disabled,
|
|
13
12
|
readOnly,
|
|
14
|
-
size,
|
|
13
|
+
size = "medium",
|
|
15
14
|
error,
|
|
16
15
|
warning,
|
|
17
16
|
info
|
|
@@ -30,14 +29,14 @@ const InputPresentation = ({
|
|
|
30
29
|
onMouseLeave: onGroupMouseLeave
|
|
31
30
|
} = useContext(InputGroupContext);
|
|
32
31
|
|
|
33
|
-
const handleMouseEnter =
|
|
34
|
-
if (onMouseEnter) onMouseEnter(
|
|
35
|
-
if (onGroupMouseEnter) onGroupMouseEnter(
|
|
32
|
+
const handleMouseEnter = () => {
|
|
33
|
+
if (onMouseEnter) onMouseEnter();
|
|
34
|
+
if (onGroupMouseEnter) onGroupMouseEnter();
|
|
36
35
|
};
|
|
37
36
|
|
|
38
|
-
const handleMouseLeave =
|
|
39
|
-
if (onMouseLeave) onMouseLeave(
|
|
40
|
-
if (onGroupMouseLeave) onGroupMouseLeave(
|
|
37
|
+
const handleMouseLeave = () => {
|
|
38
|
+
if (onMouseLeave) onMouseLeave();
|
|
39
|
+
if (onGroupMouseLeave) onGroupMouseLeave();
|
|
41
40
|
};
|
|
42
41
|
|
|
43
42
|
return /*#__PURE__*/React.createElement(StyledInputPresentationContainer, {
|
|
@@ -59,16 +58,4 @@ const InputPresentation = ({
|
|
|
59
58
|
}, children));
|
|
60
59
|
};
|
|
61
60
|
|
|
62
|
-
InputPresentation.propTypes = {
|
|
63
|
-
children: PropTypes.node,
|
|
64
|
-
align: PropTypes.string,
|
|
65
|
-
disabled: PropTypes.bool,
|
|
66
|
-
inputWidth: PropTypes.number,
|
|
67
|
-
readOnly: PropTypes.bool,
|
|
68
|
-
positionedChildren: PropTypes.node,
|
|
69
|
-
size: PropTypes.oneOf(["small", "medium", "large"]),
|
|
70
|
-
error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
71
|
-
warning: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
72
|
-
info: PropTypes.oneOfType([PropTypes.bool, PropTypes.string])
|
|
73
|
-
};
|
|
74
61
|
export default InputPresentation;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { CommonInputPresentationProps } from "./input-presentation.component";
|
|
2
|
+
import { InputContextProps } from "../input-behaviour";
|
|
3
|
+
import { CarbonProviderProps } from "../../components/carbon-provider";
|
|
4
|
+
export declare const StyledInputPresentationContainer: import("styled-components").StyledComponent<"div", any, Pick<CommonInputPresentationProps, "inputWidth">, never>;
|
|
5
|
+
declare const InputPresentationStyle: import("styled-components").StyledComponent<"div", any, Pick<InputContextProps, "hasFocus"> & Pick<CommonInputPresentationProps, "disabled" | "align" | "error" | "info" | "warning" | "readOnly" | "size"> & Pick<CarbonProviderProps, "validationRedesignOptIn">, never>;
|
|
2
6
|
export default InputPresentationStyle;
|
|
3
|
-
declare const InputPresentationStyle: import("styled-components").StyledComponent<"div", any, {
|
|
4
|
-
error: any;
|
|
5
|
-
warning: any;
|
|
6
|
-
info: any;
|
|
7
|
-
disabled: any;
|
|
8
|
-
validationRedesignOptIn: any;
|
|
9
|
-
}, never>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import styled, { css } from "styled-components";
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
2
|
import sizes from "./input-sizes.style";
|
|
4
3
|
export const StyledInputPresentationContainer = styled.div`
|
|
5
4
|
flex: 0 0 ${({
|
|
@@ -8,6 +7,37 @@ export const StyledInputPresentationContainer = styled.div`
|
|
|
8
7
|
display: flex;
|
|
9
8
|
position: relative;
|
|
10
9
|
`;
|
|
10
|
+
|
|
11
|
+
function stylingForValidations({
|
|
12
|
+
error,
|
|
13
|
+
warning,
|
|
14
|
+
info,
|
|
15
|
+
disabled,
|
|
16
|
+
validationRedesignOptIn
|
|
17
|
+
}) {
|
|
18
|
+
let validationColor;
|
|
19
|
+
|
|
20
|
+
if (disabled) {
|
|
21
|
+
return "";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (error) {
|
|
25
|
+
validationColor = "var(--colorsSemanticNegative500)";
|
|
26
|
+
} else if (warning) {
|
|
27
|
+
validationColor = validationRedesignOptIn ? "var(--colorsUtilityMajor300)" : "var(--colorsSemanticCaution500)";
|
|
28
|
+
} else if (info) {
|
|
29
|
+
validationColor = "var(--colorsSemanticInfo500)";
|
|
30
|
+
} else {
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return css`
|
|
35
|
+
border-color: ${validationColor} !important;
|
|
36
|
+
z-index: 1;
|
|
37
|
+
${error && `box-shadow: inset 1px 1px 0 ${validationColor}, inset -1px -1px 0 ${validationColor};`}
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
|
|
11
41
|
const InputPresentationStyle = styled.div`
|
|
12
42
|
align-items: stretch;
|
|
13
43
|
background: var(--colorsUtilityYang100);
|
|
@@ -18,15 +48,13 @@ const InputPresentationStyle = styled.div`
|
|
|
18
48
|
flex-wrap: wrap;
|
|
19
49
|
width: 100%;
|
|
20
50
|
margin: 0;
|
|
21
|
-
|
|
22
|
-
size
|
|
23
|
-
}) => sizes[size].height};
|
|
24
|
-
padding-left: ${({
|
|
25
|
-
size
|
|
26
|
-
}) => sizes[size].horizontalPadding};
|
|
27
|
-
padding-right: ${({
|
|
51
|
+
${({
|
|
28
52
|
size
|
|
29
|
-
}) =>
|
|
53
|
+
}) => size && css`
|
|
54
|
+
min-height: ${sizes[size].height};
|
|
55
|
+
padding-left: ${sizes[size].horizontalPadding};
|
|
56
|
+
padding-right: ${sizes[size].horizontalPadding};
|
|
57
|
+
`}
|
|
30
58
|
|
|
31
59
|
${({
|
|
32
60
|
disabled
|
|
@@ -65,48 +93,4 @@ const InputPresentationStyle = styled.div`
|
|
|
65
93
|
display: none !important;
|
|
66
94
|
}
|
|
67
95
|
`;
|
|
68
|
-
|
|
69
|
-
function stylingForValidations({
|
|
70
|
-
error,
|
|
71
|
-
warning,
|
|
72
|
-
info,
|
|
73
|
-
disabled,
|
|
74
|
-
validationRedesignOptIn
|
|
75
|
-
}) {
|
|
76
|
-
let validationColor;
|
|
77
|
-
|
|
78
|
-
if (disabled) {
|
|
79
|
-
return "";
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (error) {
|
|
83
|
-
validationColor = "var(--colorsSemanticNegative500)";
|
|
84
|
-
} else if (warning) {
|
|
85
|
-
validationColor = validationRedesignOptIn ? "var(--colorsUtilityMajor300)" : "var(--colorsSemanticCaution500)";
|
|
86
|
-
} else if (info) {
|
|
87
|
-
validationColor = "var(--colorsSemanticInfo500)";
|
|
88
|
-
} else {
|
|
89
|
-
return "";
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return css`
|
|
93
|
-
border-color: ${validationColor} !important;
|
|
94
|
-
z-index: 1;
|
|
95
|
-
${error && `box-shadow: inset 1px 1px 0 ${validationColor}, inset -1px -1px 0 ${validationColor};`}
|
|
96
|
-
`;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
InputPresentationStyle.defaultProps = {
|
|
100
|
-
size: "medium"
|
|
101
|
-
};
|
|
102
|
-
InputPresentationStyle.propTypes = {
|
|
103
|
-
align: PropTypes.string,
|
|
104
|
-
disabled: PropTypes.bool,
|
|
105
|
-
hasFocus: PropTypes.bool,
|
|
106
|
-
readOnly: PropTypes.bool,
|
|
107
|
-
size: PropTypes.oneOf(["small", "medium", "large"]),
|
|
108
|
-
error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
109
|
-
warning: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
110
|
-
info: PropTypes.oneOfType([PropTypes.bool, PropTypes.string])
|
|
111
|
-
};
|
|
112
96
|
export default InputPresentationStyle;
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const horizontalPadding: string;
|
|
5
|
-
}
|
|
6
|
-
namespace medium {
|
|
7
|
-
const height_1: string;
|
|
8
|
-
export { height_1 as height };
|
|
9
|
-
const horizontalPadding_1: string;
|
|
10
|
-
export { horizontalPadding_1 as horizontalPadding };
|
|
11
|
-
}
|
|
12
|
-
namespace large {
|
|
13
|
-
const height_2: string;
|
|
14
|
-
export { height_2 as height };
|
|
15
|
-
const horizontalPadding_2: string;
|
|
16
|
-
export { horizontalPadding_2 as horizontalPadding };
|
|
17
|
-
}
|
|
1
|
+
interface SizesProps {
|
|
2
|
+
height: string;
|
|
3
|
+
horizontalPadding: string;
|
|
18
4
|
}
|
|
19
|
-
|
|
5
|
+
interface InputSizesInterface {
|
|
6
|
+
[key: string]: SizesProps;
|
|
7
|
+
}
|
|
8
|
+
declare const InputSizes: InputSizesInterface;
|
|
9
|
+
export default InputSizes;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const InputSizes = {
|
|
2
2
|
small: {
|
|
3
3
|
height: "var(--sizing400)",
|
|
4
4
|
horizontalPadding: "var(--spacing100)"
|
|
@@ -11,4 +11,5 @@ export default {
|
|
|
11
11
|
height: "var(--sizing600)",
|
|
12
12
|
horizontalPadding: "var(--spacing200)"
|
|
13
13
|
}
|
|
14
|
-
};
|
|
14
|
+
};
|
|
15
|
+
export default InputSizes;
|
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
export default Input;
|
|
2
|
-
declare const Input: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
|
|
3
1
|
import React from "react";
|
|
2
|
+
export interface CommonInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "type"> {
|
|
3
|
+
align?: "right" | "left";
|
|
4
|
+
/** If true the Component will be focused when rendered */
|
|
5
|
+
autoFocus?: boolean;
|
|
6
|
+
/** If true, the component will be disabled */
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/** HTML id attribute of the input */
|
|
9
|
+
id?: string;
|
|
10
|
+
/** A callback to retrieve the input reference */
|
|
11
|
+
inputRef?: (input: React.RefObject<HTMLInputElement>) => void;
|
|
12
|
+
/** Name of the input */
|
|
13
|
+
name?: string;
|
|
14
|
+
/** Specify a callback triggered on blur */
|
|
15
|
+
onBlur?: (ev: React.FocusEvent<HTMLInputElement>) => void;
|
|
16
|
+
/** Specify a callback triggered on change */
|
|
17
|
+
onChange?: (ev: React.ChangeEvent<HTMLInputElement>) => void;
|
|
18
|
+
/** pecify a callback triggered on click */
|
|
19
|
+
onClick?: (ev: React.MouseEvent<HTMLInputElement>) => void;
|
|
20
|
+
/** Specify a callback triggered on focus */
|
|
21
|
+
onFocus?: (ev: React.FocusEvent<HTMLInputElement>) => void;
|
|
22
|
+
/** Specify a callback triggered on keyDown */
|
|
23
|
+
onKeyDown?: (ev: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
24
|
+
/** Placeholder string to be displayed in input */
|
|
25
|
+
placeholder?: string;
|
|
26
|
+
/** If true, the component will be read-only */
|
|
27
|
+
readOnly?: boolean;
|
|
28
|
+
/** Flag to configure component as mandatory */
|
|
29
|
+
required?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface InputProps extends CommonInputProps {
|
|
32
|
+
/** Integer to determine a timeout for the defered callback */
|
|
33
|
+
deferTimeout?: number;
|
|
34
|
+
/** Defered callback to be called after the onChange event */
|
|
35
|
+
onChangeDeferred?: (ev: React.ChangeEvent<HTMLInputElement>) => void;
|
|
36
|
+
/** HTML type attribute of the input */
|
|
37
|
+
type?: string;
|
|
38
|
+
}
|
|
39
|
+
declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
|
|
40
|
+
export default Input;
|
|
@@ -1,9 +1,31 @@
|
|
|
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
3
|
import React, { useEffect, useContext, useRef } from "react";
|
|
4
|
-
import PropTypes from "prop-types";
|
|
5
4
|
import StyledInput from "./input.style";
|
|
6
5
|
import { InputContext, InputGroupContext } from "../input-behaviour";
|
|
6
|
+
|
|
7
|
+
function selectTextOnFocus(input) {
|
|
8
|
+
// setTimeout is required so the dom has a chance to place the cursor in the input
|
|
9
|
+
setTimeout(() => {
|
|
10
|
+
if (input !== null && input !== void 0 && input.current) {
|
|
11
|
+
const {
|
|
12
|
+
selectionStart,
|
|
13
|
+
selectionEnd,
|
|
14
|
+
value
|
|
15
|
+
} = input.current;
|
|
16
|
+
const {
|
|
17
|
+
length
|
|
18
|
+
} = value; // only select text if cursor is at the very end or the very start of the value
|
|
19
|
+
|
|
20
|
+
if (selectionStart === 0 && selectionEnd === 0 || selectionStart === length && selectionEnd === length) {
|
|
21
|
+
if (document.activeElement === input.current) {
|
|
22
|
+
input.current.setSelectionRange(0, length);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
7
29
|
const Input = /*#__PURE__*/React.forwardRef(({
|
|
8
30
|
align,
|
|
9
31
|
placeholder,
|
|
@@ -26,55 +48,91 @@ const Input = /*#__PURE__*/React.forwardRef(({
|
|
|
26
48
|
const groupContext = useContext(InputGroupContext);
|
|
27
49
|
const deferredTimeout = useRef(null);
|
|
28
50
|
let input = useRef(null);
|
|
29
|
-
|
|
51
|
+
|
|
52
|
+
if (ref) {
|
|
53
|
+
input = ref;
|
|
54
|
+
}
|
|
55
|
+
|
|
30
56
|
useEffect(() => {
|
|
31
|
-
if (autoFocus && input.current)
|
|
57
|
+
if (autoFocus && input.current) {
|
|
58
|
+
input.current.focus();
|
|
59
|
+
}
|
|
32
60
|
}, [autoFocus, input]);
|
|
33
61
|
useEffect(() => {
|
|
34
|
-
if (inputRef)
|
|
62
|
+
if (inputRef) {
|
|
63
|
+
inputRef(input);
|
|
64
|
+
}
|
|
35
65
|
}, [input, inputRef]);
|
|
36
66
|
useEffect(() => {
|
|
37
|
-
if (context.inputRef)
|
|
67
|
+
if (context.inputRef) {
|
|
68
|
+
context.inputRef(input);
|
|
69
|
+
}
|
|
38
70
|
}, [context, input]);
|
|
39
71
|
useEffect(() => {
|
|
40
|
-
if (disabled && context.onBlur)
|
|
72
|
+
if (disabled && context.onBlur) {
|
|
73
|
+
context.onBlur();
|
|
74
|
+
}
|
|
41
75
|
}, [disabled, context]);
|
|
42
76
|
|
|
43
77
|
const handleClick = ev => {
|
|
44
|
-
|
|
45
|
-
|
|
78
|
+
var _input, _input$current;
|
|
79
|
+
|
|
80
|
+
if (onClick) {
|
|
81
|
+
onClick(ev);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
(_input = input) === null || _input === void 0 ? void 0 : (_input$current = _input.current) === null || _input$current === void 0 ? void 0 : _input$current.focus();
|
|
46
85
|
};
|
|
47
86
|
|
|
48
87
|
const handleFocus = ev => {
|
|
49
|
-
if (onFocus)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
88
|
+
if (onFocus) {
|
|
89
|
+
onFocus(ev);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (context.onFocus) {
|
|
93
|
+
context.onFocus();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (groupContext.onFocus) {
|
|
97
|
+
groupContext.onFocus();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (type === "text") {
|
|
101
|
+
selectTextOnFocus(input);
|
|
102
|
+
}
|
|
53
103
|
};
|
|
54
104
|
|
|
55
105
|
const handleBlur = ev => {
|
|
56
|
-
if (onBlur)
|
|
57
|
-
|
|
58
|
-
|
|
106
|
+
if (onBlur) {
|
|
107
|
+
onBlur(ev);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (context.onBlur) {
|
|
111
|
+
context.onBlur();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (groupContext.onBlur) {
|
|
115
|
+
groupContext.onBlur();
|
|
116
|
+
}
|
|
59
117
|
};
|
|
60
118
|
|
|
61
|
-
const handleDeferred =
|
|
62
|
-
currentTarget,
|
|
63
|
-
target
|
|
64
|
-
}) => {
|
|
119
|
+
const handleDeferred = ev => {
|
|
65
120
|
if (onChangeDeferred) {
|
|
66
|
-
|
|
121
|
+
if (deferredTimeout.current) {
|
|
122
|
+
clearTimeout(deferredTimeout.current);
|
|
123
|
+
}
|
|
124
|
+
|
|
67
125
|
deferredTimeout.current = setTimeout(() => {
|
|
68
|
-
onChangeDeferred(
|
|
69
|
-
currentTarget,
|
|
70
|
-
target
|
|
71
|
-
});
|
|
126
|
+
onChangeDeferred(ev);
|
|
72
127
|
}, deferTimeout || 750);
|
|
73
128
|
}
|
|
74
129
|
};
|
|
75
130
|
|
|
76
131
|
const handleChange = ev => {
|
|
77
|
-
if (onChange)
|
|
132
|
+
if (onChange) {
|
|
133
|
+
onChange(ev);
|
|
134
|
+
}
|
|
135
|
+
|
|
78
136
|
handleDeferred(ev);
|
|
79
137
|
};
|
|
80
138
|
|
|
@@ -95,45 +153,5 @@ const Input = /*#__PURE__*/React.forwardRef(({
|
|
|
95
153
|
onChange: handleChange
|
|
96
154
|
}));
|
|
97
155
|
});
|
|
98
|
-
Input.
|
|
99
|
-
align: PropTypes.oneOf(["right", "left"]),
|
|
100
|
-
placeholder: PropTypes.string,
|
|
101
|
-
disabled: PropTypes.bool,
|
|
102
|
-
readOnly: PropTypes.bool,
|
|
103
|
-
className: PropTypes.string,
|
|
104
|
-
id: PropTypes.string,
|
|
105
|
-
|
|
106
|
-
/** A callback to retrieve the input reference */
|
|
107
|
-
inputRef: PropTypes.func,
|
|
108
|
-
name: PropTypes.string,
|
|
109
|
-
onBlur: PropTypes.func,
|
|
110
|
-
onClick: PropTypes.func,
|
|
111
|
-
onKeyDown: PropTypes.func,
|
|
112
|
-
onFocus: PropTypes.func,
|
|
113
|
-
autoFocus: PropTypes.bool,
|
|
114
|
-
onChange: PropTypes.func,
|
|
115
|
-
onChangeDeferred: PropTypes.func,
|
|
116
|
-
deferTimeout: PropTypes.number,
|
|
117
|
-
type: PropTypes.string
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
function selectTextOnFocus(input) {
|
|
121
|
-
// setTimeout is required so the dom has a chance to place the cursor in the input
|
|
122
|
-
setTimeout(() => {
|
|
123
|
-
if (input.current) {
|
|
124
|
-
const {
|
|
125
|
-
length
|
|
126
|
-
} = input.current.value;
|
|
127
|
-
const cursorStart = input.current.selectionStart;
|
|
128
|
-
const cursorEnd = input.current.selectionEnd; // only select text if cursor is at the very end or the very start of the value
|
|
129
|
-
|
|
130
|
-
if (cursorStart === 0 && cursorEnd === 0 || cursorStart === length && cursorEnd === length) {
|
|
131
|
-
if (document.activeElement === input.current) {
|
|
132
|
-
input.current.setSelectionRange(0, length);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
156
|
+
Input.displayName = "Input";
|
|
139
157
|
export default Input;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { CommonInputProps } from "./input.component";
|
|
2
|
+
declare const StyledInput: import("styled-components").StyledComponent<"input", any, Pick<CommonInputProps, "disabled" | "align" | "readOnly">, never>;
|
|
1
3
|
export default StyledInput;
|
|
2
|
-
declare const StyledInput: import("styled-components").StyledComponent<"input", any, {}, never>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import styled, { css } from "styled-components";
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
2
|
const StyledInput = styled.input`
|
|
4
3
|
background: transparent;
|
|
5
4
|
border: none;
|
|
@@ -39,7 +38,4 @@ const StyledInput = styled.input`
|
|
|
39
38
|
color: var(--colorsActionMinorYin090);
|
|
40
39
|
`}
|
|
41
40
|
`;
|
|
42
|
-
StyledInput.propTypes = {
|
|
43
|
-
disabled: PropTypes.bool
|
|
44
|
-
};
|
|
45
41
|
export default StyledInput;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { InputBehaviour, InputContext } from "./input-behaviour.component";
|
|
2
|
-
export { InputGroupBehaviour, InputGroupContext } from "./input-group-behaviour.component";
|
|
2
|
+
export { InputGroupBehaviour, InputGroupContext, } from "./input-group-behaviour.component";
|
|
3
|
+
export type { InputContextProps } from "./useInputBehaviour";
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
export const InputContext: React.Context<{}>;
|
|
2
|
-
export function InputBehaviour({ children }: {
|
|
3
|
-
children: any;
|
|
4
|
-
}): JSX.Element;
|
|
5
|
-
export namespace InputBehaviour {
|
|
6
|
-
namespace propTypes {
|
|
7
|
-
const children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
1
|
import React from "react";
|
|
11
|
-
import
|
|
2
|
+
import { InputContextProps } from "./useInputBehaviour";
|
|
3
|
+
declare const InputContext: React.Context<InputContextProps>;
|
|
4
|
+
export interface InputBehaviourProps {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
declare const InputBehaviour: ({ children }: InputBehaviourProps) => JSX.Element;
|
|
8
|
+
export { InputContext, InputBehaviour };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import React, { useContext } from "react";
|
|
2
|
-
import
|
|
3
|
-
import { InlineInputsContext } from "../../components/inline-inputs/inline-inputs.component";
|
|
2
|
+
import { InlineInputsContext } from "../../components/inline-inputs";
|
|
4
3
|
import useInputBehaviour from "./useInputBehaviour";
|
|
5
|
-
const
|
|
6
|
-
const InputContext = /*#__PURE__*/React.createContext(defaultValue);
|
|
4
|
+
const InputContext = /*#__PURE__*/React.createContext({});
|
|
7
5
|
|
|
8
6
|
const InputBehaviour = ({
|
|
9
7
|
children
|
|
@@ -19,7 +17,4 @@ const InputBehaviour = ({
|
|
|
19
17
|
}, children);
|
|
20
18
|
};
|
|
21
19
|
|
|
22
|
-
InputBehaviour.propTypes = {
|
|
23
|
-
children: PropTypes.node
|
|
24
|
-
};
|
|
25
20
|
export { InputContext, InputBehaviour };
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
export const InputGroupContext: React.Context<{}>;
|
|
2
|
-
export function InputGroupBehaviour({ children, blockGroupBehaviour }: {
|
|
3
|
-
children: any;
|
|
4
|
-
blockGroupBehaviour: any;
|
|
5
|
-
}): JSX.Element;
|
|
6
|
-
export namespace InputGroupBehaviour {
|
|
7
|
-
namespace propTypes {
|
|
8
|
-
const children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
9
|
-
const blockGroupBehaviour: PropTypes.Requireable<boolean>;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
1
|
import React from "react";
|
|
13
|
-
import
|
|
2
|
+
import { InputContextProps } from "./useInputBehaviour";
|
|
3
|
+
import { InputBehaviourProps } from "./input-behaviour.component";
|
|
4
|
+
declare const InputGroupContext: React.Context<InputContextProps>;
|
|
5
|
+
export interface InputGroupBehaviourProps extends InputBehaviourProps {
|
|
6
|
+
blockGroupBehaviour?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare const InputGroupBehaviour: ({ children, blockGroupBehaviour, }: InputGroupBehaviourProps) => JSX.Element;
|
|
9
|
+
export { InputGroupContext, InputGroupBehaviour };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
2
|
import useInputBehaviour from "./useInputBehaviour";
|
|
4
|
-
const
|
|
5
|
-
const InputGroupContext = /*#__PURE__*/React.createContext(defaultValue);
|
|
3
|
+
const InputGroupContext = /*#__PURE__*/React.createContext({});
|
|
6
4
|
|
|
7
5
|
const InputGroupBehaviour = ({
|
|
8
6
|
children,
|
|
@@ -14,8 +12,4 @@ const InputGroupBehaviour = ({
|
|
|
14
12
|
}, children);
|
|
15
13
|
};
|
|
16
14
|
|
|
17
|
-
InputGroupBehaviour.propTypes = {
|
|
18
|
-
children: PropTypes.node,
|
|
19
|
-
blockGroupBehaviour: PropTypes.bool
|
|
20
|
-
};
|
|
21
15
|
export { InputGroupContext, InputGroupBehaviour };
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
export interface InputContextProps {
|
|
2
|
+
hasFocus?: boolean;
|
|
3
|
+
hasMouseOver?: boolean;
|
|
4
|
+
onFocus?: () => void;
|
|
5
|
+
onBlur?: () => void;
|
|
6
|
+
onMouseDown?: () => void;
|
|
7
|
+
onMouseEnter?: () => void;
|
|
8
|
+
onMouseLeave?: () => void;
|
|
9
|
+
inputRef?: (input: {
|
|
10
|
+
current: HTMLInputElement | null;
|
|
11
|
+
}) => void;
|
|
12
|
+
ariaLabelledBy?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const useInputBehaviour: (blockGroupBehaviour?: boolean | undefined) => InputContextProps;
|
|
1
15
|
export default useInputBehaviour;
|
|
2
|
-
declare function useInputBehaviour(blockGroupBehaviour: any): {
|
|
3
|
-
hasFocus: boolean;
|
|
4
|
-
hasMouseOver: boolean;
|
|
5
|
-
onFocus: (() => void) | undefined;
|
|
6
|
-
onBlur: (() => void) | undefined;
|
|
7
|
-
onMouseDown: () => void;
|
|
8
|
-
onMouseEnter: (() => void) | undefined;
|
|
9
|
-
onMouseLeave: (() => void) | undefined;
|
|
10
|
-
inputRef: (input: any) => void;
|
|
11
|
-
};
|
|
@@ -29,7 +29,7 @@ export interface LabelPropTypes extends ValidationPropTypes {
|
|
|
29
29
|
/** Whether to show the validation icon */
|
|
30
30
|
useValidationIcon?: boolean;
|
|
31
31
|
/** A string that represents the ID of another form element */
|
|
32
|
-
htmlFor
|
|
32
|
+
htmlFor?: string;
|
|
33
33
|
/** Padding right, integer multiplied by base spacing constant (8) */
|
|
34
34
|
pr?: 1 | 2;
|
|
35
35
|
/** Padding left, integer multiplied by base spacing constant (8) */
|