carbon-react 104.56.0 → 104.57.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__/form-field/form-field.component.js +3 -3
- package/esm/__internal__/input/input-presentation.component.js +6 -1
- package/esm/__internal__/input/input-presentation.style.d.ts +1 -0
- package/esm/__internal__/input/input-presentation.style.js +3 -2
- package/esm/__internal__/validation-message/index.d.ts +1 -0
- package/esm/__internal__/validation-message/index.js +1 -0
- package/esm/__internal__/validation-message/validation-message.component.d.ts +11 -0
- package/esm/__internal__/validation-message/validation-message.component.js +15 -0
- package/esm/__internal__/validation-message/validation-message.style.d.ts +5 -0
- package/esm/__internal__/validation-message/validation-message.style.js +12 -0
- package/esm/components/carbon-provider/carbon-provider.component.d.ts +5 -1
- package/esm/components/carbon-provider/carbon-provider.component.js +11 -4
- package/esm/components/carbon-provider/carbon-provider.d.ts +1 -0
- package/esm/components/date-range/date-range.style.js +1 -1
- package/esm/components/fieldset/fieldset.component.js +7 -2
- package/esm/components/numeral-date/numeral-date-context.d.ts +3 -0
- package/esm/components/numeral-date/numeral-date-context.js +2 -0
- package/esm/components/numeral-date/numeral-date.component.js +22 -6
- package/esm/components/textarea/textarea.component.js +27 -12
- package/esm/components/textbox/textbox.component.js +36 -15
- package/esm/components/textbox/textbox.d.ts +1 -1
- package/esm/components/textbox/textbox.style.d.ts +2 -0
- package/esm/components/textbox/textbox.style.js +33 -0
- package/esm/style/themes/base/base-theme.config.d.ts +2 -0
- package/esm/style/themes/base/base-theme.config.js +3 -1
- package/esm/style/themes/base/index.d.ts +2 -0
- package/lib/__internal__/form-field/form-field.component.js +3 -3
- package/lib/__internal__/input/input-presentation.component.js +7 -1
- package/lib/__internal__/input/input-presentation.style.d.ts +1 -0
- package/lib/__internal__/input/input-presentation.style.js +3 -2
- package/lib/__internal__/validation-message/index.d.ts +1 -0
- package/lib/__internal__/validation-message/index.js +15 -0
- package/lib/__internal__/validation-message/package.json +6 -0
- package/lib/__internal__/validation-message/validation-message.component.d.ts +11 -0
- package/lib/__internal__/validation-message/validation-message.component.js +26 -0
- package/lib/__internal__/validation-message/validation-message.style.d.ts +5 -0
- package/lib/__internal__/validation-message/validation-message.style.js +25 -0
- package/lib/components/carbon-provider/carbon-provider.component.d.ts +5 -1
- package/lib/components/carbon-provider/carbon-provider.component.js +18 -5
- package/lib/components/carbon-provider/carbon-provider.d.ts +1 -0
- package/lib/components/date-range/date-range.style.js +1 -1
- package/lib/components/fieldset/fieldset.component.js +8 -2
- package/lib/components/numeral-date/numeral-date-context.d.ts +3 -0
- package/lib/components/numeral-date/numeral-date-context.js +14 -0
- package/lib/components/numeral-date/numeral-date.component.js +25 -5
- package/lib/components/textarea/textarea.component.js +30 -12
- package/lib/components/textbox/textbox.component.js +44 -15
- package/lib/components/textbox/textbox.d.ts +1 -1
- package/lib/components/textbox/textbox.style.d.ts +2 -0
- package/lib/components/textbox/textbox.style.js +49 -0
- package/lib/style/themes/base/base-theme.config.d.ts +2 -0
- package/lib/style/themes/base/base-theme.config.js +3 -1
- package/lib/style/themes/base/index.d.ts +2 -0
- package/package.json +1 -1
|
@@ -67,9 +67,9 @@ const FormField = ({
|
|
|
67
67
|
labelId: labelId,
|
|
68
68
|
align: labelAlign,
|
|
69
69
|
disabled: disabled,
|
|
70
|
-
error: error,
|
|
71
|
-
warning: warning,
|
|
72
|
-
info: info,
|
|
70
|
+
error: !rest.validationRedesignOptIn && error,
|
|
71
|
+
warning: !rest.validationRedesignOptIn && warning,
|
|
72
|
+
info: !rest.validationRedesignOptIn && info,
|
|
73
73
|
help: labelHelp,
|
|
74
74
|
tooltipId: tooltipId,
|
|
75
75
|
helpTabIndex: helpTabIndex,
|
|
@@ -2,6 +2,7 @@ import React, { useContext } from "react";
|
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import InputPresentationStyle, { StyledInputPresentationContainer } from "./input-presentation.style";
|
|
4
4
|
import { InputContext, InputGroupContext } from "../input-behaviour";
|
|
5
|
+
import { NewValidationContext } from "../../components/carbon-provider/carbon-provider.component";
|
|
5
6
|
|
|
6
7
|
const InputPresentation = ({
|
|
7
8
|
children,
|
|
@@ -21,6 +22,9 @@ const InputPresentation = ({
|
|
|
21
22
|
onMouseEnter,
|
|
22
23
|
onMouseLeave
|
|
23
24
|
} = useContext(InputContext);
|
|
25
|
+
const {
|
|
26
|
+
validationRedesignOptIn
|
|
27
|
+
} = useContext(NewValidationContext);
|
|
24
28
|
const {
|
|
25
29
|
onMouseEnter: onGroupMouseEnter,
|
|
26
30
|
onMouseLeave: onGroupMouseLeave
|
|
@@ -50,7 +54,8 @@ const InputPresentation = ({
|
|
|
50
54
|
size: size,
|
|
51
55
|
warning: warning,
|
|
52
56
|
error: error,
|
|
53
|
-
info: info
|
|
57
|
+
info: info,
|
|
58
|
+
validationRedesignOptIn: validationRedesignOptIn
|
|
54
59
|
}, children));
|
|
55
60
|
};
|
|
56
61
|
|
|
@@ -70,7 +70,8 @@ function stylingForValidations({
|
|
|
70
70
|
error,
|
|
71
71
|
warning,
|
|
72
72
|
info,
|
|
73
|
-
disabled
|
|
73
|
+
disabled,
|
|
74
|
+
validationRedesignOptIn
|
|
74
75
|
}) {
|
|
75
76
|
let validationColor;
|
|
76
77
|
|
|
@@ -81,7 +82,7 @@ function stylingForValidations({
|
|
|
81
82
|
if (error) {
|
|
82
83
|
validationColor = "var(--colorsSemanticNegative500)";
|
|
83
84
|
} else if (warning) {
|
|
84
|
-
validationColor = "var(--colorsSemanticCaution500)";
|
|
85
|
+
validationColor = validationRedesignOptIn ? "var(--colorsUtilityMajor300)" : "var(--colorsSemanticCaution500)";
|
|
85
86
|
} else if (info) {
|
|
86
87
|
validationColor = "var(--colorsSemanticInfo500)";
|
|
87
88
|
} else {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./validation-message.component";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./validation-message.component";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface ValidationMessageProps {
|
|
3
|
+
/** Indicate that error has occurred
|
|
4
|
+
Pass string to display hint with error */
|
|
5
|
+
error?: boolean | string;
|
|
6
|
+
/** Indicate that warning has occurred
|
|
7
|
+
Pass string to display hint with warning */
|
|
8
|
+
warning?: boolean | string;
|
|
9
|
+
}
|
|
10
|
+
declare const ValidationMessage: ({ error, warning }: ValidationMessageProps) => JSX.Element | null;
|
|
11
|
+
export default ValidationMessage;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import StyledValidationMessage from "./validation-message.style";
|
|
3
|
+
|
|
4
|
+
const ValidationMessage = ({
|
|
5
|
+
error,
|
|
6
|
+
warning
|
|
7
|
+
}) => {
|
|
8
|
+
const validation = error || warning;
|
|
9
|
+
const isStringValidation = typeof validation === "string";
|
|
10
|
+
return isStringValidation ? /*#__PURE__*/React.createElement(StyledValidationMessage, {
|
|
11
|
+
isWarning: !!(!error && warning)
|
|
12
|
+
}, validation) : null;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default ValidationMessage;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import styled, { css } from "styled-components";
|
|
2
|
+
const StyledValidationMessage = styled.p`
|
|
3
|
+
${({
|
|
4
|
+
isWarning
|
|
5
|
+
}) => css`
|
|
6
|
+
color: ${isWarning ? "var(--colorsSemanticCaution600)" : "var(--colorsSemanticNegative500)"};
|
|
7
|
+
font-weight: ${isWarning ? "regular" : "bold"};
|
|
8
|
+
margin-top: 0px;
|
|
9
|
+
margin-bottom: 8px;
|
|
10
|
+
`}
|
|
11
|
+
`;
|
|
12
|
+
export default StyledValidationMessage;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
export const NewValidationContext: React.Context<{}>;
|
|
1
2
|
export default CarbonProvider;
|
|
2
|
-
|
|
3
|
+
import React from "react";
|
|
4
|
+
declare function CarbonProvider({ children, theme, validationRedesignOptIn, }: {
|
|
3
5
|
children: any;
|
|
4
6
|
theme?: import("../../style/themes/base").ThemeObject | undefined;
|
|
7
|
+
validationRedesignOptIn?: boolean | undefined;
|
|
5
8
|
}): JSX.Element;
|
|
6
9
|
declare namespace CarbonProvider {
|
|
7
10
|
namespace propTypes {
|
|
8
11
|
const children: PropTypes.Validator<string | number | boolean | {} | PropTypes.ReactElementLike | PropTypes.ReactNodeArray>;
|
|
9
12
|
const theme: PropTypes.Requireable<object>;
|
|
13
|
+
const validationRedesignOptIn: PropTypes.Requireable<boolean>;
|
|
10
14
|
}
|
|
11
15
|
}
|
|
12
16
|
import PropTypes from "prop-types";
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { createContext } from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import { ThemeProvider } from "styled-components";
|
|
4
4
|
import mintTheme from "../../style/themes/mint";
|
|
5
5
|
import CarbonScopedTokensProvider from "../../style/design-tokens/carbon-scoped-tokens-provider";
|
|
6
|
+
export const NewValidationContext = /*#__PURE__*/createContext({});
|
|
6
7
|
|
|
7
8
|
const CarbonProvider = ({
|
|
8
9
|
children,
|
|
9
|
-
theme = mintTheme
|
|
10
|
+
theme = mintTheme,
|
|
11
|
+
validationRedesignOptIn = false
|
|
10
12
|
}) => /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
11
13
|
theme: theme
|
|
12
|
-
}, /*#__PURE__*/React.createElement(CarbonScopedTokensProvider, null,
|
|
14
|
+
}, /*#__PURE__*/React.createElement(CarbonScopedTokensProvider, null, /*#__PURE__*/React.createElement(NewValidationContext.Provider, {
|
|
15
|
+
value: {
|
|
16
|
+
validationRedesignOptIn
|
|
17
|
+
}
|
|
18
|
+
}, children)));
|
|
13
19
|
|
|
14
20
|
CarbonProvider.propTypes = {
|
|
15
21
|
children: PropTypes.node.isRequired,
|
|
16
|
-
theme: PropTypes.object
|
|
22
|
+
theme: PropTypes.object,
|
|
23
|
+
validationRedesignOptIn: PropTypes.bool
|
|
17
24
|
};
|
|
18
25
|
export default CarbonProvider;
|
|
@@ -7,6 +7,7 @@ import { validProps } from "../../__internal__/utils/ether";
|
|
|
7
7
|
import tagComponent from "../../__internal__/utils/helpers/tags/tags";
|
|
8
8
|
import { filterStyledSystemMarginProps } from "../../style/utils";
|
|
9
9
|
import { FieldsetStyle, LegendContainerStyle, FieldsetContentStyle } from "./fieldset.style";
|
|
10
|
+
import { NewValidationContext } from "../carbon-provider/carbon-provider.component";
|
|
10
11
|
const marginPropTypes = filterStyledSystemMarginProps(styledSystemPropTypes.space);
|
|
11
12
|
|
|
12
13
|
const Fieldset = props => {
|
|
@@ -25,12 +26,16 @@ const Fieldset = props => {
|
|
|
25
26
|
propTypes: Fieldset.propTypes,
|
|
26
27
|
props
|
|
27
28
|
});
|
|
28
|
-
return /*#__PURE__*/React.createElement(
|
|
29
|
+
return /*#__PURE__*/React.createElement(NewValidationContext.Provider, {
|
|
30
|
+
value: {
|
|
31
|
+
validationRedesignOptIn: false
|
|
32
|
+
}
|
|
33
|
+
}, /*#__PURE__*/React.createElement(FieldsetStyle, _extends({}, tagComponent("fieldset", props), safeProps, {
|
|
29
34
|
m: 0
|
|
30
35
|
}, filterStyledSystemMarginProps(props)), /*#__PURE__*/React.createElement(FieldsetContentStyle, {
|
|
31
36
|
"data-component": "fieldset-style",
|
|
32
37
|
inline: props.inline
|
|
33
|
-
}, legend(), props.children));
|
|
38
|
+
}, legend(), props.children)));
|
|
34
39
|
};
|
|
35
40
|
|
|
36
41
|
Fieldset.propTypes = {
|
|
@@ -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, { useState, useEffect, useRef } from "react";
|
|
3
|
+
import React, { useContext, useState, useEffect, useRef } from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import styledSystemPropTypes from "@styled-system/prop-types";
|
|
6
6
|
import invariant from "invariant";
|
|
@@ -8,11 +8,15 @@ import { filterStyledSystemMarginProps } from "../../style/utils";
|
|
|
8
8
|
import Events from "../../__internal__/utils/helpers/events";
|
|
9
9
|
import { StyledNumeralDate, StyledDateField } from "./numeral-date.style";
|
|
10
10
|
import Textbox from "../textbox";
|
|
11
|
+
import { StyledHintText } from "../textbox/textbox.style";
|
|
12
|
+
import ValidationMessage from "../../__internal__/validation-message";
|
|
11
13
|
import guid from "../../__internal__/utils/helpers/guid";
|
|
12
14
|
import useLocale from "../../hooks/__internal__/useLocale";
|
|
13
15
|
import FormField from "../../__internal__/form-field";
|
|
14
16
|
import { InputGroupBehaviour } from "../../__internal__/input-behaviour";
|
|
15
17
|
import { TooltipProvider } from "../../__internal__/tooltip-provider";
|
|
18
|
+
import { NewValidationContext } from "../carbon-provider/carbon-provider.component";
|
|
19
|
+
import NumeralDateContext from "./numeral-date-context";
|
|
16
20
|
const marginPropTypes = filterStyledSystemMarginProps(styledSystemPropTypes.space);
|
|
17
21
|
const ALLOWED_DATE_FORMATS = [["dd", "mm", "yyyy"], ["mm", "dd", "yyyy"], ["dd", "mm"], ["mm", "dd"], ["mm", "yyyy"]];
|
|
18
22
|
|
|
@@ -62,6 +66,9 @@ const NumeralDate = ({
|
|
|
62
66
|
...rest
|
|
63
67
|
}) => {
|
|
64
68
|
const l = useLocale();
|
|
69
|
+
const {
|
|
70
|
+
validationRedesignOptIn
|
|
71
|
+
} = useContext(NewValidationContext);
|
|
65
72
|
const {
|
|
66
73
|
current: uniqueId
|
|
67
74
|
} = useRef(id || guid());
|
|
@@ -162,8 +169,12 @@ const NumeralDate = ({
|
|
|
162
169
|
labelSpacing: labelSpacing,
|
|
163
170
|
fieldHelp: fieldHelp,
|
|
164
171
|
adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
|
|
165
|
-
isRequired: required
|
|
166
|
-
|
|
172
|
+
isRequired: required,
|
|
173
|
+
validationRedesignOptIn: validationRedesignOptIn
|
|
174
|
+
}, filterStyledSystemMarginProps(rest)), validationRedesignOptIn && labelHelp && /*#__PURE__*/React.createElement(StyledHintText, null, labelHelp), validationRedesignOptIn && /*#__PURE__*/React.createElement(ValidationMessage, {
|
|
175
|
+
error: internalError,
|
|
176
|
+
warning: internalWarning
|
|
177
|
+
}), /*#__PURE__*/React.createElement(StyledNumeralDate, {
|
|
167
178
|
name: name,
|
|
168
179
|
onKeyPress: onKeyPress,
|
|
169
180
|
"data-component": "numeral-date"
|
|
@@ -173,7 +184,12 @@ const NumeralDate = ({
|
|
|
173
184
|
const validation = error || warning || info;
|
|
174
185
|
const isStringValidation = typeof validation === "string";
|
|
175
186
|
const hasValidationIcon = isStringValidation && validation.length;
|
|
176
|
-
return /*#__PURE__*/React.createElement(
|
|
187
|
+
return /*#__PURE__*/React.createElement(NumeralDateContext.Provider, {
|
|
188
|
+
value: {
|
|
189
|
+
disableErrorBorder: index !== 0
|
|
190
|
+
},
|
|
191
|
+
key: datePart
|
|
192
|
+
}, /*#__PURE__*/React.createElement(StyledDateField, {
|
|
177
193
|
key: datePart,
|
|
178
194
|
isYearInput: datePart.length === 4,
|
|
179
195
|
isMiddle: isMiddle,
|
|
@@ -196,14 +212,14 @@ const NumeralDate = ({
|
|
|
196
212
|
info: !!info
|
|
197
213
|
}, required && {
|
|
198
214
|
required
|
|
199
|
-
}, isEnd && !validationOnLabel && {
|
|
215
|
+
}, isEnd && !validationRedesignOptIn && !validationOnLabel && {
|
|
200
216
|
error: internalError,
|
|
201
217
|
warning: internalWarning,
|
|
202
218
|
info
|
|
203
219
|
}, {
|
|
204
220
|
size: size,
|
|
205
221
|
tooltipPosition: tooltipPosition
|
|
206
|
-
})));
|
|
222
|
+
}))));
|
|
207
223
|
})))));
|
|
208
224
|
};
|
|
209
225
|
|
|
@@ -15,6 +15,9 @@ import StyledTextarea from "./textarea.style";
|
|
|
15
15
|
import LocaleContext from "../../__internal__/i18n-context";
|
|
16
16
|
import { TooltipProvider } from "../../__internal__/tooltip-provider";
|
|
17
17
|
import useInputAccessibility from "../../hooks/__internal__/useInputAccessibility";
|
|
18
|
+
import { NewValidationContext } from "../carbon-provider/carbon-provider.component";
|
|
19
|
+
import { ErrorBorder, StyledHintText } from "../textbox/textbox.style";
|
|
20
|
+
import ValidationMessage from "../../__internal__/validation-message";
|
|
18
21
|
|
|
19
22
|
const getFormatNumber = (value, locale) => new Intl.NumberFormat(locale).format(value);
|
|
20
23
|
|
|
@@ -59,6 +62,12 @@ const Textarea = ({
|
|
|
59
62
|
...props
|
|
60
63
|
}) => {
|
|
61
64
|
const locale = useContext(LocaleContext);
|
|
65
|
+
const {
|
|
66
|
+
validationRedesignOptIn
|
|
67
|
+
} = useContext(NewValidationContext);
|
|
68
|
+
|
|
69
|
+
const computeLabelPropValues = prop => validationRedesignOptIn ? undefined : prop;
|
|
70
|
+
|
|
62
71
|
const {
|
|
63
72
|
current: id
|
|
64
73
|
} = useRef(idProp || guid());
|
|
@@ -134,7 +143,7 @@ const Textarea = ({
|
|
|
134
143
|
"data-role": dataRole,
|
|
135
144
|
"data-element": dataElement
|
|
136
145
|
}, filterStyledSystemMarginProps(props)), /*#__PURE__*/React.createElement(FormField, {
|
|
137
|
-
fieldHelp: fieldHelp,
|
|
146
|
+
fieldHelp: computeLabelPropValues(fieldHelp),
|
|
138
147
|
fieldHelpId: fieldHelpId,
|
|
139
148
|
error: error,
|
|
140
149
|
warning: warning,
|
|
@@ -143,15 +152,19 @@ const Textarea = ({
|
|
|
143
152
|
labelId: labelId,
|
|
144
153
|
disabled: disabled,
|
|
145
154
|
id: id,
|
|
146
|
-
labelInline: labelInline,
|
|
147
|
-
labelAlign: labelAlign,
|
|
148
|
-
labelWidth: labelWidth,
|
|
149
|
-
labelHelp: labelHelp,
|
|
155
|
+
labelInline: computeLabelPropValues(labelInline),
|
|
156
|
+
labelAlign: computeLabelPropValues(labelAlign),
|
|
157
|
+
labelWidth: computeLabelPropValues(labelWidth),
|
|
158
|
+
labelHelp: computeLabelPropValues(labelHelp),
|
|
150
159
|
labelSpacing: labelSpacing,
|
|
151
160
|
isRequired: props.required,
|
|
152
|
-
useValidationIcon: validationOnLabel,
|
|
153
|
-
adaptiveLabelBreakpoint: adaptiveLabelBreakpoint
|
|
154
|
-
|
|
161
|
+
useValidationIcon: computeLabelPropValues(validationOnLabel),
|
|
162
|
+
adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
|
|
163
|
+
validationRedesignOptIn: validationRedesignOptIn
|
|
164
|
+
}, validationRedesignOptIn && labelHelp && /*#__PURE__*/React.createElement(StyledHintText, null, labelHelp), validationRedesignOptIn && /*#__PURE__*/React.createElement(ValidationMessage, {
|
|
165
|
+
error: error,
|
|
166
|
+
warning: warning
|
|
167
|
+
}), /*#__PURE__*/React.createElement(InputPresentation, {
|
|
155
168
|
size: size,
|
|
156
169
|
disabled: disabled,
|
|
157
170
|
readOnly: readOnly,
|
|
@@ -159,10 +172,12 @@ const Textarea = ({
|
|
|
159
172
|
error: error,
|
|
160
173
|
warning: warning,
|
|
161
174
|
info: info
|
|
162
|
-
}, /*#__PURE__*/React.createElement(
|
|
175
|
+
}, validationRedesignOptIn && (error || warning) && /*#__PURE__*/React.createElement(ErrorBorder, {
|
|
176
|
+
warning: !!(!error && warning)
|
|
177
|
+
}), /*#__PURE__*/React.createElement(Input, _extends({
|
|
163
178
|
"aria-invalid": !!error,
|
|
164
179
|
"aria-labelledby": ariaLabelledBy,
|
|
165
|
-
"aria-describedby": ariaDescribedBy,
|
|
180
|
+
"aria-describedby": validationRedesignOptIn ? undefined : ariaDescribedBy,
|
|
166
181
|
autoFocus: autoFocus,
|
|
167
182
|
name: name,
|
|
168
183
|
value: value,
|
|
@@ -185,8 +200,8 @@ const Textarea = ({
|
|
|
185
200
|
error: error,
|
|
186
201
|
warning: warning,
|
|
187
202
|
info: info,
|
|
188
|
-
validationIconId: validationIconId,
|
|
189
|
-
useValidationIcon: !validationOnLabel
|
|
203
|
+
validationIconId: validationRedesignOptIn ? undefined : validationIconId,
|
|
204
|
+
useValidationIcon: !(validationRedesignOptIn || validationOnLabel)
|
|
190
205
|
}))), characterCount())));
|
|
191
206
|
};
|
|
192
207
|
|
|
@@ -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 from "react";
|
|
3
|
+
import React, { useContext } from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import styledSystemPropTypes from "@styled-system/prop-types";
|
|
6
6
|
import { filterStyledSystemMarginProps } from "../../style/utils";
|
|
@@ -13,6 +13,10 @@ import StyledPrefix from "./__internal__/prefix.style";
|
|
|
13
13
|
import { TooltipProvider } from "../../__internal__/tooltip-provider";
|
|
14
14
|
import useCharacterCount from "../../hooks/__internal__/useCharacterCount";
|
|
15
15
|
import useInputAccessibility from "../../hooks/__internal__/useInputAccessibility/useInputAccessibility";
|
|
16
|
+
import { ErrorBorder, StyledHintText } from "./textbox.style";
|
|
17
|
+
import ValidationMessage from "../../__internal__/validation-message";
|
|
18
|
+
import { NewValidationContext } from "../carbon-provider/carbon-provider.component";
|
|
19
|
+
import NumeralDateContext from "../numeral-date/numeral-date-context";
|
|
16
20
|
const marginPropTypes = filterStyledSystemMarginProps(styledSystemPropTypes.space);
|
|
17
21
|
|
|
18
22
|
const Textbox = ({
|
|
@@ -70,6 +74,15 @@ const Textbox = ({
|
|
|
70
74
|
...props
|
|
71
75
|
}) => {
|
|
72
76
|
const [maxLength, characterCount] = useCharacterCount(value, characterLimit, warnOverLimit, enforceCharacterLimit);
|
|
77
|
+
const {
|
|
78
|
+
validationRedesignOptIn
|
|
79
|
+
} = useContext(NewValidationContext);
|
|
80
|
+
const {
|
|
81
|
+
disableErrorBorder
|
|
82
|
+
} = useContext(NumeralDateContext);
|
|
83
|
+
|
|
84
|
+
const computeLabelPropValues = prop => validationRedesignOptIn ? undefined : prop;
|
|
85
|
+
|
|
73
86
|
const {
|
|
74
87
|
labelId: internalLabelId,
|
|
75
88
|
validationIconId,
|
|
@@ -90,29 +103,35 @@ const Textbox = ({
|
|
|
90
103
|
tooltipPosition: tooltipPosition
|
|
91
104
|
}, /*#__PURE__*/React.createElement(InputBehaviour, null, /*#__PURE__*/React.createElement(FormField, _extends({
|
|
92
105
|
disabled: disabled,
|
|
93
|
-
fieldHelp: fieldHelp,
|
|
94
106
|
fieldHelpId: fieldHelpId,
|
|
107
|
+
fieldHelp: computeLabelPropValues(fieldHelp),
|
|
95
108
|
error: error,
|
|
96
109
|
warning: warning,
|
|
97
110
|
info: info,
|
|
98
111
|
label: label,
|
|
99
112
|
labelId: labelId,
|
|
100
|
-
labelAlign: labelAlign,
|
|
101
|
-
labelHelp: labelHelp,
|
|
102
|
-
labelInline: labelInline,
|
|
113
|
+
labelAlign: computeLabelPropValues(labelAlign),
|
|
114
|
+
labelHelp: computeLabelPropValues(labelHelp),
|
|
115
|
+
labelInline: computeLabelPropValues(labelInline),
|
|
103
116
|
labelSpacing: labelSpacing,
|
|
104
|
-
labelWidth: labelWidth,
|
|
117
|
+
labelWidth: computeLabelPropValues(labelWidth),
|
|
105
118
|
id: id,
|
|
106
|
-
reverse: reverse,
|
|
119
|
+
reverse: computeLabelPropValues(reverse),
|
|
107
120
|
isOptional: isOptional,
|
|
108
|
-
useValidationIcon: validationOnLabel,
|
|
121
|
+
useValidationIcon: computeLabelPropValues(validationOnLabel),
|
|
109
122
|
adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
|
|
110
123
|
isRequired: required,
|
|
111
124
|
"data-component": dataComponent,
|
|
112
125
|
"data-role": dataRole,
|
|
113
126
|
"data-element": dataElement,
|
|
114
|
-
validationIconId: validationIconId
|
|
115
|
-
|
|
127
|
+
validationIconId: validationRedesignOptIn ? undefined : validationIconId,
|
|
128
|
+
validationRedesignOptIn: validationRedesignOptIn,
|
|
129
|
+
size: size,
|
|
130
|
+
readOnly: readOnly
|
|
131
|
+
}, filterStyledSystemMarginProps(props)), validationRedesignOptIn && labelHelp && /*#__PURE__*/React.createElement(StyledHintText, null, labelHelp), validationRedesignOptIn && /*#__PURE__*/React.createElement(ValidationMessage, {
|
|
132
|
+
error: error,
|
|
133
|
+
warning: warning
|
|
134
|
+
}), /*#__PURE__*/React.createElement(InputPresentation, {
|
|
116
135
|
align: align,
|
|
117
136
|
disabled: disabled,
|
|
118
137
|
readOnly: readOnly,
|
|
@@ -122,15 +141,17 @@ const Textbox = ({
|
|
|
122
141
|
info: info,
|
|
123
142
|
inputWidth: inputWidth || 100 - labelWidth,
|
|
124
143
|
positionedChildren: positionedChildren
|
|
125
|
-
}, leftChildren, prefix
|
|
144
|
+
}, leftChildren, prefix && /*#__PURE__*/React.createElement(StyledPrefix, {
|
|
126
145
|
"data-element": "textbox-prefix"
|
|
127
|
-
}, prefix)
|
|
146
|
+
}, prefix), validationRedesignOptIn && !disableErrorBorder && (error || warning) && /*#__PURE__*/React.createElement(ErrorBorder, {
|
|
147
|
+
warning: !!(!error && warning)
|
|
148
|
+
}), /*#__PURE__*/React.createElement(Input, _extends({}, required && {
|
|
128
149
|
required
|
|
129
150
|
}, {
|
|
130
151
|
align: align,
|
|
131
152
|
"aria-invalid": !!error,
|
|
132
153
|
"aria-labelledby": labelId,
|
|
133
|
-
"aria-describedby": ariaDescribedBy,
|
|
154
|
+
"aria-describedby": validationRedesignOptIn ? undefined : ariaDescribedBy,
|
|
134
155
|
autoFocus: autoFocus,
|
|
135
156
|
deferTimeout: deferTimeout,
|
|
136
157
|
disabled: disabled,
|
|
@@ -158,9 +179,9 @@ const Textbox = ({
|
|
|
158
179
|
onMouseDown: iconOnMouseDown || onMouseDown,
|
|
159
180
|
readOnly: readOnly,
|
|
160
181
|
size: size,
|
|
161
|
-
useValidationIcon: !validationOnLabel,
|
|
182
|
+
useValidationIcon: !(validationRedesignOptIn || validationOnLabel),
|
|
162
183
|
warning: warning,
|
|
163
|
-
validationIconId: validationIconId
|
|
184
|
+
validationIconId: validationRedesignOptIn ? undefined : validationIconId
|
|
164
185
|
}))), characterCount));
|
|
165
186
|
};
|
|
166
187
|
|
|
@@ -20,7 +20,7 @@ export interface CommonTextboxProps
|
|
|
20
20
|
"data-role"?: string;
|
|
21
21
|
/** Breakpoint for adaptive label (inline labels change to top aligned). Enables the adaptive behaviour when set */
|
|
22
22
|
adaptiveLabelBreakpoint?: number;
|
|
23
|
-
/** Integer to determine a timeout for the
|
|
23
|
+
/** Integer to determine a timeout for the deferred callback */
|
|
24
24
|
deferTimeout?: number;
|
|
25
25
|
/** If true, the component will be disabled */
|
|
26
26
|
disabled?: boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import styled, { css } from "styled-components";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
const ErrorBorder = styled.span`
|
|
4
|
+
${({
|
|
5
|
+
warning
|
|
6
|
+
}) => css`
|
|
7
|
+
position: absolute;
|
|
8
|
+
z-index: 6;
|
|
9
|
+
width: 2px;
|
|
10
|
+
height: calc(100% + var(--spacing300));
|
|
11
|
+
background-color: ${warning ? "var(--colorsSemanticCaution500)" : "var(--colorsSemanticNegative500)"};
|
|
12
|
+
left: -12px;
|
|
13
|
+
bottom: 0px;
|
|
14
|
+
`}
|
|
15
|
+
`;
|
|
16
|
+
const StyledHintText = styled.p`
|
|
17
|
+
margin-top: 0px;
|
|
18
|
+
margin-bottom: 8px;
|
|
19
|
+
color: var(--colorsUtilityYin055);
|
|
20
|
+
font-size: 14px;
|
|
21
|
+
`;
|
|
22
|
+
StyledHintText.defaultProps = {
|
|
23
|
+
size: "medium"
|
|
24
|
+
};
|
|
25
|
+
ErrorBorder.propTypes = {
|
|
26
|
+
warning: PropTypes.bool,
|
|
27
|
+
size: PropTypes.string
|
|
28
|
+
};
|
|
29
|
+
ErrorBorder.defaultProps = {
|
|
30
|
+
warning: false,
|
|
31
|
+
size: "medium"
|
|
32
|
+
};
|
|
33
|
+
export { StyledHintText, ErrorBorder };
|
|
@@ -19,9 +19,11 @@ export default (palette => {
|
|
|
19
19
|
focus: palette.gold,
|
|
20
20
|
info: palette.productBlueShade(3),
|
|
21
21
|
warning: palette.carrotOrange,
|
|
22
|
+
warningText: palette.carrotOrangeShade(20),
|
|
22
23
|
destructive: {
|
|
23
24
|
hover: palette.errorRedShade(20)
|
|
24
|
-
}
|
|
25
|
+
},
|
|
26
|
+
placeholder: palette.blackOpacity(0.55)
|
|
25
27
|
},
|
|
26
28
|
disabled: {
|
|
27
29
|
background: palette.slateTint(90)
|
|
@@ -90,9 +90,9 @@ const FormField = ({
|
|
|
90
90
|
labelId: labelId,
|
|
91
91
|
align: labelAlign,
|
|
92
92
|
disabled: disabled,
|
|
93
|
-
error: error,
|
|
94
|
-
warning: warning,
|
|
95
|
-
info: info,
|
|
93
|
+
error: !rest.validationRedesignOptIn && error,
|
|
94
|
+
warning: !rest.validationRedesignOptIn && warning,
|
|
95
|
+
info: !rest.validationRedesignOptIn && info,
|
|
96
96
|
help: labelHelp,
|
|
97
97
|
tooltipId: tooltipId,
|
|
98
98
|
helpTabIndex: helpTabIndex,
|
|
@@ -13,6 +13,8 @@ var _inputPresentation = _interopRequireWildcard(require("./input-presentation.s
|
|
|
13
13
|
|
|
14
14
|
var _inputBehaviour = require("../input-behaviour");
|
|
15
15
|
|
|
16
|
+
var _carbonProvider = require("../../components/carbon-provider/carbon-provider.component");
|
|
17
|
+
|
|
16
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
19
|
|
|
18
20
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -37,6 +39,9 @@ const InputPresentation = ({
|
|
|
37
39
|
onMouseEnter,
|
|
38
40
|
onMouseLeave
|
|
39
41
|
} = (0, _react.useContext)(_inputBehaviour.InputContext);
|
|
42
|
+
const {
|
|
43
|
+
validationRedesignOptIn
|
|
44
|
+
} = (0, _react.useContext)(_carbonProvider.NewValidationContext);
|
|
40
45
|
const {
|
|
41
46
|
onMouseEnter: onGroupMouseEnter,
|
|
42
47
|
onMouseLeave: onGroupMouseLeave
|
|
@@ -66,7 +71,8 @@ const InputPresentation = ({
|
|
|
66
71
|
size: size,
|
|
67
72
|
warning: warning,
|
|
68
73
|
error: error,
|
|
69
|
-
info: info
|
|
74
|
+
info: info,
|
|
75
|
+
validationRedesignOptIn: validationRedesignOptIn
|
|
70
76
|
}, children));
|
|
71
77
|
};
|
|
72
78
|
|