carbon-react 128.1.2 → 128.2.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 +2 -0
- package/esm/__internal__/checkable-input/checkable-input.component.js +4 -2
- package/esm/__internal__/fieldset/fieldset.style.js +7 -6
- package/esm/__internal__/form-field/form-field.component.d.ts +1 -1
- package/esm/__internal__/form-field/form-field.component.js +1 -0
- package/esm/__internal__/label/label.style.js +6 -5
- package/esm/components/checkbox/checkbox-group/checkbox-group.component.d.ts +2 -0
- package/esm/components/checkbox/checkbox-group/checkbox-group.component.js +5 -2
- package/esm/components/checkbox/checkbox.component.js +3 -0
- package/esm/components/date-range/date-range.component.d.ts +5 -1
- package/esm/components/date-range/date-range.component.js +5 -1
- package/esm/components/decimal/decimal.component.d.ts +0 -2
- package/esm/components/decimal/decimal.component.js +1 -2
- package/esm/components/fieldset/fieldset.component.d.ts +8 -3
- package/esm/components/fieldset/fieldset.component.js +16 -2
- package/esm/components/fieldset/fieldset.style.d.ts +4 -0
- package/esm/components/fieldset/fieldset.style.js +29 -2
- package/esm/components/file-input/file-input.component.d.ts +4 -0
- package/esm/components/file-input/file-input.component.js +3 -0
- package/esm/components/form/index.d.ts +1 -0
- package/esm/components/form/index.js +2 -1
- package/esm/components/form/required-fields-indicator/index.d.ts +1 -0
- package/esm/components/form/required-fields-indicator/index.js +1 -0
- package/esm/components/form/required-fields-indicator/required-fields-indicator.component.d.ts +7 -0
- package/esm/components/form/required-fields-indicator/required-fields-indicator.component.js +20 -0
- package/esm/components/inline-inputs/inline-inputs.component.d.ts +3 -1
- package/esm/components/inline-inputs/inline-inputs.component.js +13 -3
- package/esm/components/numeral-date/numeral-date.component.d.ts +3 -1
- package/esm/components/numeral-date/numeral-date.component.js +4 -3
- package/esm/components/radio-button/radio-button-group/radio-button-group.component.d.ts +2 -0
- package/esm/components/radio-button/radio-button-group/radio-button-group.component.js +5 -3
- package/esm/components/radio-button/radio-button.component.d.ts +1 -2
- package/esm/components/radio-button/radio-button.component.js +1 -3
- package/esm/components/select/filterable-select/filterable-select.component.d.ts +4 -0
- package/esm/components/select/filterable-select/filterable-select.component.js +5 -0
- package/esm/components/select/multi-select/multi-select.component.d.ts +2 -0
- package/esm/components/select/multi-select/multi-select.component.js +5 -0
- package/esm/components/select/select-textbox/select-textbox.component.d.ts +2 -0
- package/esm/components/select/select-textbox/select-textbox.component.js +3 -0
- package/esm/components/select/simple-select/simple-select.component.d.ts +4 -0
- package/esm/components/select/simple-select/simple-select.component.js +6 -0
- package/esm/components/switch/switch.component.js +1 -0
- package/esm/components/text-editor/text-editor.component.d.ts +3 -1
- package/esm/components/text-editor/text-editor.component.js +16 -2
- package/esm/components/textarea/textarea.component.d.ts +2 -2
- package/esm/components/textarea/textarea.component.js +7 -2
- package/esm/components/textbox/textbox.component.d.ts +2 -2
- package/esm/components/tile-select/tile-select.style.d.ts +1 -1
- package/lib/__internal__/checkable-input/checkable-input.component.d.ts +2 -0
- package/lib/__internal__/checkable-input/checkable-input.component.js +4 -2
- package/lib/__internal__/fieldset/fieldset.style.js +7 -6
- package/lib/__internal__/form-field/form-field.component.d.ts +1 -1
- package/lib/__internal__/form-field/form-field.component.js +1 -0
- package/lib/__internal__/label/label.style.js +6 -5
- package/lib/components/checkbox/checkbox-group/checkbox-group.component.d.ts +2 -0
- package/lib/components/checkbox/checkbox-group/checkbox-group.component.js +5 -2
- package/lib/components/checkbox/checkbox.component.js +3 -0
- package/lib/components/date-range/date-range.component.d.ts +5 -1
- package/lib/components/date-range/date-range.component.js +5 -1
- package/lib/components/decimal/decimal.component.d.ts +0 -2
- package/lib/components/decimal/decimal.component.js +1 -2
- package/lib/components/fieldset/fieldset.component.d.ts +8 -3
- package/lib/components/fieldset/fieldset.component.js +18 -2
- package/lib/components/fieldset/fieldset.style.d.ts +4 -0
- package/lib/components/fieldset/fieldset.style.js +31 -2
- package/lib/components/file-input/file-input.component.d.ts +4 -0
- package/lib/components/file-input/file-input.component.js +3 -0
- package/lib/components/form/index.d.ts +1 -0
- package/lib/components/form/index.js +7 -0
- package/lib/components/form/required-fields-indicator/index.d.ts +1 -0
- package/lib/components/form/required-fields-indicator/index.js +13 -0
- package/lib/components/form/required-fields-indicator/package.json +6 -0
- package/lib/components/form/required-fields-indicator/required-fields-indicator.component.d.ts +7 -0
- package/lib/components/form/required-fields-indicator/required-fields-indicator.component.js +28 -0
- package/lib/components/inline-inputs/inline-inputs.component.d.ts +3 -1
- package/lib/components/inline-inputs/inline-inputs.component.js +14 -4
- package/lib/components/numeral-date/numeral-date.component.d.ts +3 -1
- package/lib/components/numeral-date/numeral-date.component.js +4 -3
- package/lib/components/radio-button/radio-button-group/radio-button-group.component.d.ts +2 -0
- package/lib/components/radio-button/radio-button-group/radio-button-group.component.js +5 -3
- package/lib/components/radio-button/radio-button.component.d.ts +1 -2
- package/lib/components/radio-button/radio-button.component.js +1 -3
- package/lib/components/select/filterable-select/filterable-select.component.d.ts +4 -0
- package/lib/components/select/filterable-select/filterable-select.component.js +5 -0
- package/lib/components/select/multi-select/multi-select.component.d.ts +2 -0
- package/lib/components/select/multi-select/multi-select.component.js +5 -0
- package/lib/components/select/select-textbox/select-textbox.component.d.ts +2 -0
- package/lib/components/select/select-textbox/select-textbox.component.js +3 -0
- package/lib/components/select/simple-select/simple-select.component.d.ts +4 -0
- package/lib/components/select/simple-select/simple-select.component.js +6 -0
- package/lib/components/switch/switch.component.js +1 -0
- package/lib/components/text-editor/text-editor.component.d.ts +3 -1
- package/lib/components/text-editor/text-editor.component.js +16 -2
- package/lib/components/textarea/textarea.component.d.ts +2 -2
- package/lib/components/textarea/textarea.component.js +7 -2
- package/lib/components/textbox/textbox.component.d.ts +2 -2
- package/lib/components/tile-select/tile-select.style.d.ts +1 -1
- package/package.json +1 -1
|
@@ -27,6 +27,8 @@ export interface CommonCheckableInputProps extends ValidationProps, CommonHidden
|
|
|
27
27
|
labelWidth?: number;
|
|
28
28
|
/** Flag to configure component as mandatory */
|
|
29
29
|
required?: boolean;
|
|
30
|
+
/** Flag to configure component as optional. */
|
|
31
|
+
isOptional?: boolean;
|
|
30
32
|
/** If true the label switches position with the input */
|
|
31
33
|
reverse?: boolean;
|
|
32
34
|
/** Size of the component */
|
|
@@ -32,6 +32,7 @@ const CheckableInput = /*#__PURE__*/React.forwardRef(({
|
|
|
32
32
|
onChange,
|
|
33
33
|
onFocus,
|
|
34
34
|
required,
|
|
35
|
+
isOptional,
|
|
35
36
|
reverse = false,
|
|
36
37
|
validationOnLabel,
|
|
37
38
|
warning,
|
|
@@ -53,7 +54,6 @@ const CheckableInput = /*#__PURE__*/React.forwardRef(({
|
|
|
53
54
|
label,
|
|
54
55
|
fieldHelp
|
|
55
56
|
});
|
|
56
|
-
const isRadio = type === "radio";
|
|
57
57
|
const formFieldProps = {
|
|
58
58
|
disabled,
|
|
59
59
|
loading,
|
|
@@ -74,7 +74,8 @@ const CheckableInput = /*#__PURE__*/React.forwardRef(({
|
|
|
74
74
|
validationIconId: validationId,
|
|
75
75
|
// We don't want an asterisk on each radio control, only the legend
|
|
76
76
|
// However, we still want the input element to receive the required prop
|
|
77
|
-
isRequired:
|
|
77
|
+
isRequired: required,
|
|
78
|
+
isOptional,
|
|
78
79
|
useValidationIcon: validationOnLabel
|
|
79
80
|
};
|
|
80
81
|
const inputProps = {
|
|
@@ -203,6 +204,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
203
204
|
"inputMode": PropTypes.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
204
205
|
"inputWidth": PropTypes.number,
|
|
205
206
|
"is": PropTypes.string,
|
|
207
|
+
"isOptional": PropTypes.bool,
|
|
206
208
|
"itemID": PropTypes.string,
|
|
207
209
|
"itemProp": PropTypes.string,
|
|
208
210
|
"itemRef": PropTypes.string,
|
|
@@ -26,11 +26,10 @@ const StyledLegendContent = styled.span`
|
|
|
26
26
|
content: "*";
|
|
27
27
|
line-height: 24px;
|
|
28
28
|
color: var(--colorsSemanticNegative500);
|
|
29
|
-
font-weight:
|
|
30
|
-
margin-left: var(--
|
|
29
|
+
font-weight: var(--fontWeights700);
|
|
30
|
+
margin-left: var(--spacing050);
|
|
31
31
|
position: relative;
|
|
32
32
|
top: 1px;
|
|
33
|
-
left: -4px;
|
|
34
33
|
}
|
|
35
34
|
`}
|
|
36
35
|
|
|
@@ -39,8 +38,9 @@ const StyledLegendContent = styled.span`
|
|
|
39
38
|
}) => isOptional && css`
|
|
40
39
|
::after {
|
|
41
40
|
content: "(optional)";
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
color: var(--colorsUtilityYin055);
|
|
42
|
+
font-weight: var(--fontWeights400);
|
|
43
|
+
margin-left: var(--spacing050);
|
|
44
44
|
}
|
|
45
45
|
`}
|
|
46
46
|
|
|
@@ -58,7 +58,8 @@ const StyledLegend = styled.legend`
|
|
|
58
58
|
align-items: center;
|
|
59
59
|
margin-bottom: var(--spacing100);
|
|
60
60
|
padding: 0;
|
|
61
|
-
font-weight:
|
|
61
|
+
font-weight: var(--fontWeights700);
|
|
62
|
+
color: var(--colorsUtilityYin090);
|
|
62
63
|
${({
|
|
63
64
|
inline,
|
|
64
65
|
width,
|
|
@@ -53,7 +53,7 @@ export interface FormFieldProps extends CommonFormFieldProps, TagProps {
|
|
|
53
53
|
fieldHelpInline?: boolean;
|
|
54
54
|
/** Id of the element a label should be bound to */
|
|
55
55
|
id: string;
|
|
56
|
-
/**
|
|
56
|
+
/** Flag to configure component as optional in Form */
|
|
57
57
|
isOptional?: boolean;
|
|
58
58
|
/** Flag to configure component as mandatory */
|
|
59
59
|
isRequired?: boolean;
|
|
@@ -50,6 +50,7 @@ const FormField = ({
|
|
|
50
50
|
return Object.keys(validationProps).find(propName => validationProps[propName]);
|
|
51
51
|
}, [error, warning, info, disabled]);
|
|
52
52
|
!(invalidValidationProp === undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, `Prop \`${invalidValidationProp}\` cannot be used in conjunction with \`disabled\`. ` + "Use `readOnly` if you require users to see validations with a non-interactive field") : invariant(false) : void 0;
|
|
53
|
+
!!(isRequired && isOptional) ? process.env.NODE_ENV !== "production" ? invariant(false, "an input cannot be set to both required and optional at the same time") : invariant(false) : void 0;
|
|
53
54
|
const largeScreen = useIsAboveBreakpoint(adaptiveLabelBreakpoint);
|
|
54
55
|
let inlineLabel = labelInline;
|
|
55
56
|
if (adaptiveLabelBreakpoint) {
|
|
@@ -2,7 +2,7 @@ import styled, { css } from "styled-components";
|
|
|
2
2
|
const StyledLabel = styled.label`
|
|
3
3
|
color: var(--colorsUtilityYin090);
|
|
4
4
|
display: block;
|
|
5
|
-
font-weight:
|
|
5
|
+
font-weight: var(--fontWeights700);
|
|
6
6
|
|
|
7
7
|
${({
|
|
8
8
|
isRequired
|
|
@@ -10,8 +10,8 @@ const StyledLabel = styled.label`
|
|
|
10
10
|
::after {
|
|
11
11
|
content: "*";
|
|
12
12
|
color: var(--colorsSemanticNegative500);
|
|
13
|
-
font-weight:
|
|
14
|
-
margin-left: var(--
|
|
13
|
+
font-weight: var(--fontWeights700);
|
|
14
|
+
margin-left: var(--spacing050);
|
|
15
15
|
}
|
|
16
16
|
`}
|
|
17
17
|
|
|
@@ -51,8 +51,9 @@ export const StyledLabelContainer = styled.div`
|
|
|
51
51
|
}) => optional && css`
|
|
52
52
|
::after {
|
|
53
53
|
content: "(optional)";
|
|
54
|
-
font-weight:
|
|
55
|
-
margin-left:
|
|
54
|
+
font-weight: var(--fontWeights400);
|
|
55
|
+
margin-left: var(--spacing050);
|
|
56
|
+
color: var(--colorsUtilityYin055);
|
|
56
57
|
}
|
|
57
58
|
`}
|
|
58
59
|
`;
|
|
@@ -20,6 +20,8 @@ export interface CheckboxGroupProps extends ValidationProps, MarginProps {
|
|
|
20
20
|
labelSpacing?: 1 | 2;
|
|
21
21
|
/** Flag to configure component as mandatory */
|
|
22
22
|
required?: boolean;
|
|
23
|
+
/** Flag to configure component as optional. */
|
|
24
|
+
isOptional?: boolean;
|
|
23
25
|
/** Overrides the default tooltip */
|
|
24
26
|
tooltipPosition?: "top" | "bottom" | "left" | "right";
|
|
25
27
|
/** When true, Checkboxes are in line */
|
|
@@ -23,6 +23,7 @@ export const CheckboxGroup = props => {
|
|
|
23
23
|
warning,
|
|
24
24
|
info,
|
|
25
25
|
required,
|
|
26
|
+
isOptional,
|
|
26
27
|
legendInline,
|
|
27
28
|
legendWidth,
|
|
28
29
|
legendAlign,
|
|
@@ -40,7 +41,8 @@ export const CheckboxGroup = props => {
|
|
|
40
41
|
error: error,
|
|
41
42
|
warning: warning,
|
|
42
43
|
info: info,
|
|
43
|
-
isRequired: required
|
|
44
|
+
isRequired: required,
|
|
45
|
+
isOptional: isOptional
|
|
44
46
|
}, tagComponent("checkboxgroup", props), {
|
|
45
47
|
blockGroupBehaviour: !(error || warning)
|
|
46
48
|
}, filterStyledSystemMarginProps(props)), legendHelp && /*#__PURE__*/React.createElement(StyledHintText, null, legendHelp), /*#__PURE__*/React.createElement(Box, {
|
|
@@ -73,7 +75,8 @@ export const CheckboxGroup = props => {
|
|
|
73
75
|
error: error,
|
|
74
76
|
warning: warning,
|
|
75
77
|
info: info,
|
|
76
|
-
isRequired: required
|
|
78
|
+
isRequired: required,
|
|
79
|
+
isOptional: isOptional
|
|
77
80
|
}, tagComponent("checkboxgroup", props), {
|
|
78
81
|
blockGroupBehaviour: !(error || warning || info)
|
|
79
82
|
}, filterStyledSystemMarginProps(props)), /*#__PURE__*/React.createElement(StyledCheckboxGroup, {
|
|
@@ -30,6 +30,7 @@ const Checkbox = /*#__PURE__*/React.forwardRef(({
|
|
|
30
30
|
labelWidth,
|
|
31
31
|
adaptiveSpacingBreakpoint,
|
|
32
32
|
required,
|
|
33
|
+
isOptional,
|
|
33
34
|
error,
|
|
34
35
|
warning,
|
|
35
36
|
info,
|
|
@@ -84,6 +85,7 @@ const Checkbox = /*#__PURE__*/React.forwardRef(({
|
|
|
84
85
|
labelHelp,
|
|
85
86
|
labelSpacing,
|
|
86
87
|
required,
|
|
88
|
+
isOptional,
|
|
87
89
|
fieldHelpInline,
|
|
88
90
|
checked,
|
|
89
91
|
disabled,
|
|
@@ -225,6 +227,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
225
227
|
})]),
|
|
226
228
|
"inputWidth": PropTypes.number,
|
|
227
229
|
"is": PropTypes.string,
|
|
230
|
+
"isOptional": PropTypes.bool,
|
|
228
231
|
"itemID": PropTypes.string,
|
|
229
232
|
"itemProp": PropTypes.string,
|
|
230
233
|
"itemRef": PropTypes.string,
|
|
@@ -80,9 +80,13 @@ export interface DateRangeProps extends StyledDateRangeProps, MarginProps, TagPr
|
|
|
80
80
|
validationOnLabel?: boolean;
|
|
81
81
|
/** Overrides the default tooltip position */
|
|
82
82
|
tooltipPosition?: "top" | "bottom" | "left" | "right";
|
|
83
|
+
/** Flag to configure component as mandatory. */
|
|
84
|
+
required?: boolean;
|
|
85
|
+
/** Flag to configure component as optional. */
|
|
86
|
+
isOptional?: boolean;
|
|
83
87
|
}
|
|
84
88
|
export declare const DateRange: {
|
|
85
|
-
({ endDateProps, id, labelsInline, name, onBlur, onChange, startDateProps, tooltipPosition, validationOnLabel, value, startRef, endRef, ...rest }: DateRangeProps): React.JSX.Element;
|
|
89
|
+
({ endDateProps, id, labelsInline, name, onBlur, onChange, startDateProps, tooltipPosition, validationOnLabel, value, startRef, endRef, required, isOptional, ...rest }: DateRangeProps): React.JSX.Element;
|
|
86
90
|
displayName: string;
|
|
87
91
|
};
|
|
88
92
|
export default DateRange;
|
|
@@ -24,6 +24,8 @@ export const DateRange = ({
|
|
|
24
24
|
value,
|
|
25
25
|
startRef,
|
|
26
26
|
endRef,
|
|
27
|
+
required,
|
|
28
|
+
isOptional,
|
|
27
29
|
...rest
|
|
28
30
|
}) => {
|
|
29
31
|
const l = useLocale();
|
|
@@ -186,7 +188,9 @@ export const DateRange = ({
|
|
|
186
188
|
onBlur: handleOnBlur,
|
|
187
189
|
onChange: onChangeCallback,
|
|
188
190
|
onKeyDown: ev => handleOnKeyDown(ev, propsKey),
|
|
189
|
-
...props
|
|
191
|
+
...props,
|
|
192
|
+
required,
|
|
193
|
+
isOptional
|
|
190
194
|
};
|
|
191
195
|
};
|
|
192
196
|
return /*#__PURE__*/React.createElement(StyledDateRange, _extends({}, tagComponent("date-range", rest), {
|
|
@@ -33,8 +33,6 @@ export interface DecimalProps extends Omit<CommonTextboxProps, "onChange" | "onB
|
|
|
33
33
|
precision?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
|
|
34
34
|
/** If true, the component will be read-only */
|
|
35
35
|
readOnly?: boolean;
|
|
36
|
-
/** Flag to configure component as mandatory */
|
|
37
|
-
required?: boolean;
|
|
38
36
|
/** The value of the input if it's used as a controlled component */
|
|
39
37
|
value?: string;
|
|
40
38
|
/** The locale string - default en */
|
|
@@ -20,7 +20,6 @@ const Decimal = /*#__PURE__*/React.forwardRef(({
|
|
|
20
20
|
id,
|
|
21
21
|
name,
|
|
22
22
|
allowEmptyValue = false,
|
|
23
|
-
required,
|
|
24
23
|
locale,
|
|
25
24
|
value,
|
|
26
25
|
inputRef,
|
|
@@ -177,7 +176,6 @@ const Decimal = /*#__PURE__*/React.forwardRef(({
|
|
|
177
176
|
onKeyPress: onKeyPress,
|
|
178
177
|
align: align,
|
|
179
178
|
readOnly: readOnly,
|
|
180
|
-
required: required,
|
|
181
179
|
inputWidth: inputWidth,
|
|
182
180
|
onChange: handleOnChange,
|
|
183
181
|
onBlur: handleOnBlur,
|
|
@@ -304,6 +302,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
304
302
|
"inputRef": PropTypes.func,
|
|
305
303
|
"inputWidth": PropTypes.number,
|
|
306
304
|
"is": PropTypes.string,
|
|
305
|
+
"isOptional": PropTypes.bool,
|
|
307
306
|
"itemID": PropTypes.string,
|
|
308
307
|
"itemProp": PropTypes.string,
|
|
309
308
|
"itemRef": PropTypes.string,
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { MarginProps } from "styled-system";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export interface FieldsetProps extends MarginProps {
|
|
4
|
+
/** When true, legend is placed in line with the children */
|
|
5
|
+
inline?: boolean;
|
|
5
6
|
/** Child elements */
|
|
6
7
|
children?: React.ReactNode;
|
|
7
8
|
/** The text for the fieldsets legend element. */
|
|
8
9
|
legend?: string;
|
|
10
|
+
/** Flag to configure fields as mandatory. */
|
|
11
|
+
required?: boolean;
|
|
12
|
+
/** Flag to configure fields as optional. */
|
|
13
|
+
isOptional?: boolean;
|
|
9
14
|
}
|
|
10
15
|
export declare const Fieldset: {
|
|
11
|
-
({ children, inline, legend, ...rest }: FieldsetProps): React.JSX.Element;
|
|
16
|
+
({ children, inline, legend, required, isOptional, ...rest }: FieldsetProps): React.JSX.Element;
|
|
12
17
|
displayName: string;
|
|
13
18
|
};
|
|
14
19
|
export default Fieldset;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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
|
-
import React from "react";
|
|
2
|
+
import React, { useState, useEffect } from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import tagComponent from "../../__internal__/utils/helpers/tags/tags";
|
|
5
5
|
import { FieldsetStyle, LegendContainerStyle, FieldsetContentStyle } from "./fieldset.style";
|
|
@@ -10,11 +10,16 @@ export const Fieldset = ({
|
|
|
10
10
|
children,
|
|
11
11
|
inline = false,
|
|
12
12
|
legend,
|
|
13
|
+
required,
|
|
14
|
+
isOptional,
|
|
13
15
|
...rest
|
|
14
16
|
}) => {
|
|
17
|
+
const [ref, setRef] = useState(null);
|
|
15
18
|
const getLegend = () => {
|
|
16
19
|
if (!legend) return null;
|
|
17
20
|
return /*#__PURE__*/React.createElement(LegendContainerStyle, {
|
|
21
|
+
isRequired: required,
|
|
22
|
+
isOptional: isOptional,
|
|
18
23
|
inline: inline,
|
|
19
24
|
"data-component": "legend-style"
|
|
20
25
|
}, /*#__PURE__*/React.createElement("legend", {
|
|
@@ -22,11 +27,20 @@ export const Fieldset = ({
|
|
|
22
27
|
}, legend));
|
|
23
28
|
};
|
|
24
29
|
const marginProps = useFormSpacing(rest);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (ref && required) {
|
|
32
|
+
Array.from(ref.querySelectorAll("input") || /* istanbul ignore next */[]).forEach(el => {
|
|
33
|
+
el.setAttribute("required", "");
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}, [ref, required]);
|
|
25
37
|
return /*#__PURE__*/React.createElement(NewValidationContext.Provider, {
|
|
26
38
|
value: {
|
|
27
39
|
validationRedesignOptIn: false
|
|
28
40
|
}
|
|
29
|
-
}, /*#__PURE__*/React.createElement(FieldsetStyle, _extends({
|
|
41
|
+
}, /*#__PURE__*/React.createElement(FieldsetStyle, _extends({
|
|
42
|
+
ref: setRef
|
|
43
|
+
}, tagComponent("fieldset", rest), rest, marginProps), /*#__PURE__*/React.createElement(FieldsetContentStyle, {
|
|
30
44
|
"data-component": "fieldset-style",
|
|
31
45
|
inline: inline
|
|
32
46
|
}, getLegend(), /*#__PURE__*/React.createElement(FormSpacingProvider, {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export interface StyledFieldsetProps {
|
|
2
2
|
/** When true, legend is placed in line with the children */
|
|
3
3
|
inline?: boolean;
|
|
4
|
+
/** Flag to configure fields as mandatory. */
|
|
5
|
+
isRequired?: boolean;
|
|
6
|
+
/** Flag to configure fields as optional. */
|
|
7
|
+
isOptional?: boolean;
|
|
4
8
|
}
|
|
5
9
|
declare const FieldsetStyle: import("styled-components").StyledComponent<"fieldset", any, {}, never>;
|
|
6
10
|
declare const LegendContainerStyle: import("styled-components").StyledComponent<"div", any, StyledFieldsetProps, never>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import styled from "styled-components";
|
|
1
|
+
import styled, { css } from "styled-components";
|
|
2
2
|
import { margin } from "styled-system";
|
|
3
3
|
import FormFieldStyle from "../../__internal__/form-field/form-field.style";
|
|
4
4
|
import ValidationIconStyle from "../../__internal__/validations/validation-icon.style";
|
|
@@ -37,9 +37,36 @@ const LegendContainerStyle = styled.div`
|
|
|
37
37
|
|
|
38
38
|
legend {
|
|
39
39
|
font-size: 20px;
|
|
40
|
-
font-weight:
|
|
40
|
+
font-weight: var(--fontWeights700);
|
|
41
|
+
color: var(--colorsUtilityYin090);
|
|
41
42
|
line-height: 24px;
|
|
42
43
|
margin-right: 4px;
|
|
44
|
+
|
|
45
|
+
${({
|
|
46
|
+
isRequired
|
|
47
|
+
}) => isRequired && css`
|
|
48
|
+
::after {
|
|
49
|
+
content: "*";
|
|
50
|
+
line-height: 24px;
|
|
51
|
+
color: var(--colorsSemanticNegative500);
|
|
52
|
+
font-weight: var(--fontWeights700);
|
|
53
|
+
margin-left: var(--spacing100);
|
|
54
|
+
position: relative;
|
|
55
|
+
top: 1px;
|
|
56
|
+
left: -4px;
|
|
57
|
+
}
|
|
58
|
+
`}
|
|
59
|
+
|
|
60
|
+
${({
|
|
61
|
+
isOptional
|
|
62
|
+
}) => isOptional && css`
|
|
63
|
+
::after {
|
|
64
|
+
content: "(optional)";
|
|
65
|
+
color: var(--colorsUtilityYin055);
|
|
66
|
+
font-weight: var(--fontWeights400);
|
|
67
|
+
margin-left: var(--spacing050);
|
|
68
|
+
}
|
|
69
|
+
`}
|
|
43
70
|
}
|
|
44
71
|
|
|
45
72
|
${ValidationIconStyle} ${StyledIcon}:focus {
|
|
@@ -31,6 +31,10 @@ export interface FileInputProps extends Pick<ValidationProps, "error">, Pick<Inp
|
|
|
31
31
|
onChange: (files: FileList) => void;
|
|
32
32
|
/** used to control how to display the progress of uploaded file(s) within the component */
|
|
33
33
|
uploadStatus?: FileUploadStatusProps | FileUploadStatusProps[];
|
|
34
|
+
/** Flag to configure component as mandatory. */
|
|
35
|
+
required?: boolean;
|
|
36
|
+
/** Flag to configure component as optional. */
|
|
37
|
+
isOptional?: boolean;
|
|
34
38
|
}
|
|
35
39
|
export declare const FileInput: React.ForwardRefExoticComponent<FileInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
36
40
|
export default FileInput;
|
|
@@ -32,6 +32,7 @@ const FileInput = /*#__PURE__*/React.forwardRef(({
|
|
|
32
32
|
name,
|
|
33
33
|
onChange,
|
|
34
34
|
required,
|
|
35
|
+
isOptional,
|
|
35
36
|
uploadStatus = [],
|
|
36
37
|
...rest
|
|
37
38
|
}, ref) => {
|
|
@@ -149,6 +150,7 @@ const FileInput = /*#__PURE__*/React.forwardRef(({
|
|
|
149
150
|
labelId: labelId,
|
|
150
151
|
id: uniqueId,
|
|
151
152
|
isRequired: required,
|
|
153
|
+
isOptional: isOptional,
|
|
152
154
|
"data-component": "file-input",
|
|
153
155
|
"data-role": dataRole,
|
|
154
156
|
"data-element": dataElement,
|
|
@@ -170,6 +172,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
170
172
|
"error": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
171
173
|
"id": PropTypes.string,
|
|
172
174
|
"inputHint": PropTypes.node,
|
|
175
|
+
"isOptional": PropTypes.bool,
|
|
173
176
|
"isVertical": PropTypes.bool,
|
|
174
177
|
"label": PropTypes.string,
|
|
175
178
|
"m": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from "./form.component";
|
|
1
|
+
export { default } from "./form.component";
|
|
2
|
+
export { default as RequiredFieldsIndicator } from "./required-fields-indicator";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./required-fields-indicator.component";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./required-fields-indicator.component";
|
package/esm/components/form/required-fields-indicator/required-fields-indicator.component.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { MarginProps } from "styled-system";
|
|
3
|
+
export interface RequiredIndicatorProps extends MarginProps {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
declare const _default: ({ children, ...rest }: RequiredIndicatorProps) => React.JSX.Element;
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import styled from "styled-components";
|
|
4
|
+
import Box from "../../box";
|
|
5
|
+
import StyledTypography from "../../typography/typography.style";
|
|
6
|
+
const StyledIndicatorContainer = styled(Box)`
|
|
7
|
+
${StyledTypography} {
|
|
8
|
+
color: var(--colorsUtilityYin090);
|
|
9
|
+
}
|
|
10
|
+
::after {
|
|
11
|
+
content: "*";
|
|
12
|
+
color: var(--colorsSemanticNegative500);
|
|
13
|
+
font-weight: 700;
|
|
14
|
+
margin-left: var(--spacing050);
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
export default (({
|
|
18
|
+
children,
|
|
19
|
+
...rest
|
|
20
|
+
}) => /*#__PURE__*/React.createElement(StyledIndicatorContainer, rest, children));
|
|
@@ -21,9 +21,11 @@ export interface InlineInputsProps extends MarginProps, StyledContentContainerPr
|
|
|
21
21
|
labelId?: string;
|
|
22
22
|
/** Flag to configure component as mandatory. */
|
|
23
23
|
required?: boolean;
|
|
24
|
+
/** Flag to configure component as optional. */
|
|
25
|
+
isOptional?: boolean;
|
|
24
26
|
}
|
|
25
27
|
declare const InlineInputs: {
|
|
26
|
-
({ adaptiveLabelBreakpoint, label, labelAlign, labelId, htmlFor, children, className, gutter, inputWidth, labelInline, labelWidth, required, ...rest }: InlineInputsProps): React.JSX.Element;
|
|
28
|
+
({ adaptiveLabelBreakpoint, label, labelAlign, labelId, htmlFor, children, className, gutter, inputWidth, labelInline, labelWidth, required, isOptional, ...rest }: InlineInputsProps): React.JSX.Element;
|
|
27
29
|
displayName: string;
|
|
28
30
|
};
|
|
29
31
|
export default InlineInputs;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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
|
-
import React from "react";
|
|
2
|
+
import React, { useRef, useEffect } from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import Label from "../../__internal__/label";
|
|
5
5
|
import StyledInlineInputs, { StyledContentContainer, StyledInlineInput } from "./inline-inputs.style";
|
|
@@ -27,9 +27,11 @@ const InlineInputs = ({
|
|
|
27
27
|
labelInline = true,
|
|
28
28
|
labelWidth,
|
|
29
29
|
required,
|
|
30
|
+
isOptional,
|
|
30
31
|
...rest
|
|
31
32
|
}) => {
|
|
32
33
|
const largeScreen = useIsAboveBreakpoint(adaptiveLabelBreakpoint);
|
|
34
|
+
const ref = useRef(null);
|
|
33
35
|
let inlineLabel = labelInline;
|
|
34
36
|
if (adaptiveLabelBreakpoint) {
|
|
35
37
|
inlineLabel = largeScreen;
|
|
@@ -41,16 +43,24 @@ const InlineInputs = ({
|
|
|
41
43
|
labelId: labelId,
|
|
42
44
|
inline: inlineLabel,
|
|
43
45
|
htmlFor: htmlFor,
|
|
44
|
-
isRequired: required
|
|
46
|
+
isRequired: required,
|
|
47
|
+
optional: isOptional
|
|
45
48
|
}, label);
|
|
46
49
|
}
|
|
47
50
|
const marginProps = useFormSpacing(rest);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (required) {
|
|
53
|
+
const elements = Array.from(ref.current?.querySelectorAll("input") || /* istanbul ignore next */[]);
|
|
54
|
+
elements.forEach(el => el.setAttribute("required", ""));
|
|
55
|
+
}
|
|
56
|
+
}, [required]);
|
|
48
57
|
return /*#__PURE__*/React.createElement(StyledInlineInputs, _extends({
|
|
49
58
|
gutter: gutter,
|
|
50
59
|
"data-component": "inline-inputs",
|
|
51
60
|
className: className,
|
|
52
61
|
labelWidth: labelWidth,
|
|
53
|
-
labelInline: inlineLabel
|
|
62
|
+
labelInline: inlineLabel,
|
|
63
|
+
ref: ref
|
|
54
64
|
}, marginProps), renderLabel(), /*#__PURE__*/React.createElement(StyledContentContainer, {
|
|
55
65
|
gutter: gutter,
|
|
56
66
|
"data-element": "inline-inputs-container",
|
|
@@ -87,7 +87,9 @@ export interface NumeralDateProps<DateType extends NumeralDateObject = FullDate>
|
|
|
87
87
|
* A React ref to pass to the input corresponding to the year
|
|
88
88
|
*/
|
|
89
89
|
yearRef?: React.ForwardedRef<HTMLInputElement>;
|
|
90
|
+
/** Flag to configure component as optional. */
|
|
91
|
+
isOptional?: boolean;
|
|
90
92
|
}
|
|
91
93
|
export declare type ValidDateFormat = typeof ALLOWED_DATE_FORMATS[number];
|
|
92
|
-
export declare const NumeralDate: <DateType extends NumeralDateObject = FullDate>({ dateFormat, defaultValue, disabled, error, warning, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, info, id, name, onBlur, onChange, value, validationOnLabel, label, labelInline, labelWidth, labelAlign, labelHelp, labelSpacing, fieldHelp, adaptiveLabelBreakpoint, required, readOnly, size, enableInternalError, enableInternalWarning, tooltipPosition, helpAriaLabel, dayRef, monthRef, yearRef, ...rest }: NumeralDateProps<DateType>) => React.JSX.Element;
|
|
94
|
+
export declare const NumeralDate: <DateType extends NumeralDateObject = FullDate>({ dateFormat, defaultValue, disabled, error, warning, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, info, id, name, onBlur, onChange, value, validationOnLabel, label, labelInline, labelWidth, labelAlign, labelHelp, labelSpacing, fieldHelp, adaptiveLabelBreakpoint, required, isOptional, readOnly, size, enableInternalError, enableInternalWarning, tooltipPosition, helpAriaLabel, dayRef, monthRef, yearRef, ...rest }: NumeralDateProps<DateType>) => React.JSX.Element;
|
|
93
95
|
export default NumeralDate;
|
|
@@ -103,6 +103,7 @@ export const NumeralDate = ({
|
|
|
103
103
|
fieldHelp,
|
|
104
104
|
adaptiveLabelBreakpoint,
|
|
105
105
|
required,
|
|
106
|
+
isOptional,
|
|
106
107
|
readOnly,
|
|
107
108
|
size,
|
|
108
109
|
enableInternalError,
|
|
@@ -215,6 +216,7 @@ export const NumeralDate = ({
|
|
|
215
216
|
fieldHelp: fieldHelp,
|
|
216
217
|
adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
|
|
217
218
|
isRequired: required,
|
|
219
|
+
isOptional: isOptional,
|
|
218
220
|
validationRedesignOptIn: validationRedesignOptIn
|
|
219
221
|
}, filterStyledSystemMarginProps(rest)), validationRedesignOptIn && labelHelp && /*#__PURE__*/React.createElement(StyledHintText, null, labelHelp), /*#__PURE__*/React.createElement(Box, {
|
|
220
222
|
position: "relative"
|
|
@@ -285,8 +287,6 @@ export const NumeralDate = ({
|
|
|
285
287
|
error: !!internalError,
|
|
286
288
|
warning: !!internalWarning,
|
|
287
289
|
info: !!info
|
|
288
|
-
}, required && {
|
|
289
|
-
required
|
|
290
290
|
}, isEnd && !validationRedesignOptIn && !validationOnLabel && {
|
|
291
291
|
error: internalError,
|
|
292
292
|
warning: internalWarning,
|
|
@@ -294,7 +294,8 @@ export const NumeralDate = ({
|
|
|
294
294
|
}, {
|
|
295
295
|
size: size,
|
|
296
296
|
tooltipPosition: tooltipPosition,
|
|
297
|
-
"aria-labelledby": labelId
|
|
297
|
+
"aria-labelledby": labelId,
|
|
298
|
+
required: required
|
|
298
299
|
})))));
|
|
299
300
|
}))))));
|
|
300
301
|
};
|
|
@@ -32,6 +32,8 @@ export interface RadioButtonGroupProps extends ValidationProps, MarginProps {
|
|
|
32
32
|
onChange?: (ev: React.ChangeEvent<HTMLInputElement>) => void;
|
|
33
33
|
/** Flag to configure component as mandatory */
|
|
34
34
|
required?: boolean;
|
|
35
|
+
/** Flag to configure component as optional. */
|
|
36
|
+
isOptional?: boolean;
|
|
35
37
|
/** value of the selected RadioButton */
|
|
36
38
|
value?: string;
|
|
37
39
|
/** Overrides the default tooltip position */
|
|
@@ -35,6 +35,7 @@ export const RadioButtonGroup = props => {
|
|
|
35
35
|
adaptiveLegendBreakpoint,
|
|
36
36
|
adaptiveSpacingBreakpoint,
|
|
37
37
|
required,
|
|
38
|
+
isOptional,
|
|
38
39
|
tooltipPosition
|
|
39
40
|
} = props;
|
|
40
41
|
const {
|
|
@@ -64,7 +65,8 @@ export const RadioButtonGroup = props => {
|
|
|
64
65
|
legendWidth: legendWidth,
|
|
65
66
|
legendAlign: legendAlign,
|
|
66
67
|
legendSpacing: legendSpacing,
|
|
67
|
-
isRequired: required
|
|
68
|
+
isRequired: required,
|
|
69
|
+
isOptional: isOptional
|
|
68
70
|
}, tagComponent("radiogroup", props), marginProps, {
|
|
69
71
|
ml: marginLeft,
|
|
70
72
|
blockGroupBehaviour: !(error || warning)
|
|
@@ -110,7 +112,8 @@ export const RadioButtonGroup = props => {
|
|
|
110
112
|
legendWidth: legendWidth,
|
|
111
113
|
legendAlign: legendAlign,
|
|
112
114
|
legendSpacing: legendSpacing,
|
|
113
|
-
isRequired: required
|
|
115
|
+
isRequired: required,
|
|
116
|
+
isOptional: isOptional
|
|
114
117
|
}, tagComponent("radiogroup", props), marginProps, {
|
|
115
118
|
ml: marginLeft,
|
|
116
119
|
blockGroupBehaviour: !(error || warning || info)
|
|
@@ -134,7 +137,6 @@ export const RadioButtonGroup = props => {
|
|
|
134
137
|
error: !!error,
|
|
135
138
|
warning: !!warning,
|
|
136
139
|
info: !!info,
|
|
137
|
-
required,
|
|
138
140
|
...child.props
|
|
139
141
|
});
|
|
140
142
|
}))))));
|
|
@@ -3,9 +3,8 @@ import { MarginProps } from "styled-system";
|
|
|
3
3
|
import { CommonCheckableInputProps } from "../../__internal__/checkable-input";
|
|
4
4
|
interface InternalRadioButtonProps {
|
|
5
5
|
inline?: boolean;
|
|
6
|
-
required?: boolean;
|
|
7
6
|
}
|
|
8
|
-
export interface RadioButtonProps extends CommonCheckableInputProps, MarginProps {
|
|
7
|
+
export interface RadioButtonProps extends Omit<CommonCheckableInputProps, "required" | "IsOptional">, MarginProps {
|
|
9
8
|
/** Identifier used for testing purposes, applied to the root element of the component. */
|
|
10
9
|
"data-component"?: string;
|
|
11
10
|
/** Identifier used for testing purposes, applied to the root element of the component. */
|