carbon-react 153.6.0 → 153.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/__internal__/checkable-input/checkable-input.component.d.ts +4 -1
- package/esm/__internal__/fieldset/fieldset.component.d.ts +4 -1
- package/esm/__internal__/fieldset/fieldset.style.d.ts +4 -0
- package/esm/__internal__/form-field/form-field.component.d.ts +4 -1
- package/esm/__internal__/utils/createStrictContext.d.ts +31 -0
- package/esm/__internal__/utils/createStrictContext.js +36 -0
- package/esm/__internal__/utils/logger/index.d.ts +7 -0
- package/esm/__internal__/utils/logger/index.js +11 -9
- package/esm/components/button/button.component.js +9 -1
- package/esm/components/checkbox/checkbox-group/checkbox-group.component.d.ts +4 -1
- package/esm/components/checkbox/checkbox-group/checkbox-group.component.js +6 -0
- package/esm/components/date-range/date-range.component.d.ts +4 -1
- package/esm/components/date-range/date-range.component.js +6 -0
- package/esm/components/fieldset/fieldset.component.d.ts +4 -1
- package/esm/components/fieldset/fieldset.component.js +6 -0
- package/esm/components/fieldset/fieldset.style.d.ts +4 -1
- package/esm/components/file-input/file-input.component.d.ts +4 -1
- package/esm/components/file-input/file-input.component.js +6 -0
- package/esm/components/inline-inputs/inline-inputs.component.d.ts +4 -1
- package/esm/components/inline-inputs/inline-inputs.component.js +6 -0
- package/esm/components/menu/__internal__/menu.context.d.ts +3 -12
- package/esm/components/menu/__internal__/menu.context.js +3 -5
- package/esm/components/menu/__internal__/strict-menu.context.d.ts +14 -0
- package/esm/components/menu/__internal__/strict-menu.context.js +11 -0
- package/esm/components/menu/__internal__/submenu/submenu.component.js +3 -4
- package/esm/components/menu/__internal__/submenu/submenu.style.d.ts +1 -1
- package/esm/components/menu/index.d.ts +1 -1
- package/esm/components/menu/menu-divider/menu-divider.component.js +6 -4
- package/esm/components/menu/menu-divider/menu-divider.style.d.ts +1 -1
- package/esm/components/menu/menu-full-screen/menu-full-screen.component.js +4 -5
- package/esm/components/menu/menu-full-screen/menu-full-screen.style.d.ts +1 -1
- package/esm/components/menu/menu-item/menu-item.component.js +4 -4
- package/esm/components/menu/menu-item/menu-item.style.d.ts +1 -1
- package/esm/components/menu/menu-segment-title/menu-segment-title.component.js +10 -7
- package/esm/components/menu/menu-segment-title/menu-segment-title.style.d.ts +1 -1
- package/esm/components/menu/menu.component.d.ts +1 -9
- package/esm/components/menu/menu.component.js +9 -5
- package/esm/components/menu/menu.style.d.ts +1 -1
- package/esm/components/menu/menu.types.d.ts +10 -0
- package/esm/components/menu/menu.types.js +1 -0
- package/esm/components/menu/scrollable-block/scrollable-block.component.js +3 -3
- package/esm/components/menu/scrollable-block/scrollable-block.style.d.ts +1 -1
- package/esm/components/numeral-date/numeral-date.component.d.ts +4 -1
- package/esm/components/numeral-date/numeral-date.component.js +5 -0
- package/esm/components/radio-button/radio-button-group/radio-button-group.component.d.ts +4 -1
- package/esm/components/radio-button/radio-button-group/radio-button-group.component.js +5 -0
- package/esm/components/select/__internal__/select-textbox/select-textbox.component.d.ts +4 -1
- package/esm/components/select/filterable-select/filterable-select.component.d.ts +4 -1
- package/esm/components/select/filterable-select/filterable-select.component.js +5 -0
- package/esm/components/select/multi-select/multi-select.component.d.ts +4 -1
- package/esm/components/select/multi-select/multi-select.component.js +5 -0
- package/esm/components/select/simple-select/simple-select.component.d.ts +4 -1
- package/esm/components/select/simple-select/simple-select.component.js +5 -0
- package/esm/components/text-editor/text-editor.component.d.ts +4 -1
- package/esm/components/text-editor/text-editor.component.js +6 -0
- package/esm/components/textarea/textarea.component.d.ts +4 -1
- package/esm/components/textarea/textarea.component.js +6 -1
- package/esm/components/textbox/textbox.component.d.ts +4 -1
- package/esm/components/textbox/textbox.component.js +6 -1
- package/esm/components/time/time.component.d.ts +4 -1
- package/esm/components/time/time.component.js +6 -0
- package/esm/components/vertical-divider/vertical-divider.component.js +1 -1
- package/lib/__internal__/checkable-input/checkable-input.component.d.ts +4 -1
- package/lib/__internal__/fieldset/fieldset.component.d.ts +4 -1
- package/lib/__internal__/fieldset/fieldset.style.d.ts +4 -0
- package/lib/__internal__/form-field/form-field.component.d.ts +4 -1
- package/lib/__internal__/utils/createStrictContext.d.ts +31 -0
- package/lib/__internal__/utils/createStrictContext.js +43 -0
- package/lib/__internal__/utils/logger/index.d.ts +7 -0
- package/lib/__internal__/utils/logger/index.js +11 -9
- package/lib/components/button/button.component.js +9 -1
- package/lib/components/checkbox/checkbox-group/checkbox-group.component.d.ts +4 -1
- package/lib/components/checkbox/checkbox-group/checkbox-group.component.js +6 -0
- package/lib/components/date-range/date-range.component.d.ts +4 -1
- package/lib/components/date-range/date-range.component.js +6 -0
- package/lib/components/fieldset/fieldset.component.d.ts +4 -1
- package/lib/components/fieldset/fieldset.component.js +6 -0
- package/lib/components/fieldset/fieldset.style.d.ts +4 -1
- package/lib/components/file-input/file-input.component.d.ts +4 -1
- package/lib/components/file-input/file-input.component.js +6 -0
- package/lib/components/inline-inputs/inline-inputs.component.d.ts +4 -1
- package/lib/components/inline-inputs/inline-inputs.component.js +6 -0
- package/lib/components/menu/__internal__/menu.context.d.ts +3 -12
- package/lib/components/menu/__internal__/menu.context.js +3 -6
- package/lib/components/menu/__internal__/strict-menu.context.d.ts +14 -0
- package/lib/components/menu/__internal__/strict-menu.context.js +19 -0
- package/lib/components/menu/__internal__/submenu/submenu.component.js +3 -4
- package/lib/components/menu/__internal__/submenu/submenu.style.d.ts +1 -1
- package/lib/components/menu/index.d.ts +1 -1
- package/lib/components/menu/menu-divider/menu-divider.component.js +8 -8
- package/lib/components/menu/menu-divider/menu-divider.style.d.ts +1 -1
- package/lib/components/menu/menu-full-screen/menu-full-screen.component.js +3 -4
- package/lib/components/menu/menu-full-screen/menu-full-screen.style.d.ts +1 -1
- package/lib/components/menu/menu-item/menu-item.component.js +7 -7
- package/lib/components/menu/menu-item/menu-item.style.d.ts +1 -1
- package/lib/components/menu/menu-segment-title/menu-segment-title.component.js +12 -9
- package/lib/components/menu/menu-segment-title/menu-segment-title.style.d.ts +1 -1
- package/lib/components/menu/menu.component.d.ts +1 -9
- package/lib/components/menu/menu.component.js +9 -5
- package/lib/components/menu/menu.style.d.ts +1 -1
- package/lib/components/menu/menu.types.d.ts +10 -0
- package/lib/components/menu/menu.types.js +5 -0
- package/lib/components/menu/scrollable-block/scrollable-block.component.js +3 -5
- package/lib/components/menu/scrollable-block/scrollable-block.style.d.ts +1 -1
- package/lib/components/numeral-date/numeral-date.component.d.ts +4 -1
- package/lib/components/numeral-date/numeral-date.component.js +5 -0
- package/lib/components/radio-button/radio-button-group/radio-button-group.component.d.ts +4 -1
- package/lib/components/radio-button/radio-button-group/radio-button-group.component.js +5 -0
- package/lib/components/select/__internal__/select-textbox/select-textbox.component.d.ts +4 -1
- package/lib/components/select/filterable-select/filterable-select.component.d.ts +4 -1
- package/lib/components/select/filterable-select/filterable-select.component.js +5 -0
- package/lib/components/select/multi-select/multi-select.component.d.ts +4 -1
- package/lib/components/select/multi-select/multi-select.component.js +5 -0
- package/lib/components/select/simple-select/simple-select.component.d.ts +4 -1
- package/lib/components/select/simple-select/simple-select.component.js +5 -0
- package/lib/components/text-editor/text-editor.component.d.ts +4 -1
- package/lib/components/text-editor/text-editor.component.js +6 -0
- package/lib/components/textarea/textarea.component.d.ts +4 -1
- package/lib/components/textarea/textarea.component.js +6 -1
- package/lib/components/textbox/textbox.component.d.ts +4 -1
- package/lib/components/textbox/textbox.component.js +6 -1
- package/lib/components/time/time.component.d.ts +4 -1
- package/lib/components/time/time.component.js +6 -0
- package/lib/components/vertical-divider/vertical-divider.component.js +1 -1
- package/package.json +5 -4
|
@@ -27,7 +27,10 @@ export interface CommonCheckableInputProps extends ValidationProps, CommonHidden
|
|
|
27
27
|
labelWidth?: number;
|
|
28
28
|
/** Flag to configure component as mandatory */
|
|
29
29
|
required?: boolean;
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* [Legacy] Flag to configure component as optional.
|
|
32
|
+
* @deprecated If the value of this component is not required, use the `required` prop and set it to false instead.
|
|
33
|
+
*/
|
|
31
34
|
isOptional?: boolean;
|
|
32
35
|
/** If true the label switches position with the input */
|
|
33
36
|
reverse?: boolean;
|
|
@@ -26,7 +26,10 @@ export interface FieldsetProps extends MarginProps {
|
|
|
26
26
|
legendMargin?: Pick<MarginProps, "mb">;
|
|
27
27
|
/** Any valid CSS string to set the component's width */
|
|
28
28
|
width?: string;
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* [Legacy] Flag to configure component as optional.
|
|
31
|
+
* @deprecated If the value of this component is not required, use the `isRequired` prop and set it to false instead.
|
|
32
|
+
*/
|
|
30
33
|
isOptional?: boolean;
|
|
31
34
|
/** Apply disabled styling to the legend content */
|
|
32
35
|
isDisabled?: boolean;
|
|
@@ -4,6 +4,10 @@ type StyledFieldsetProps = {
|
|
|
4
4
|
declare const StyledFieldset: import("styled-components").StyledComponent<"fieldset", any, StyledFieldsetProps, never>;
|
|
5
5
|
type StyledLegendContentProps = {
|
|
6
6
|
isRequired?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* [Legacy] Flag to configure component as optional.
|
|
9
|
+
* @deprecated If the value of this component is not required, use the `isRequired` prop and set it to false instead.
|
|
10
|
+
*/
|
|
7
11
|
isOptional?: boolean;
|
|
8
12
|
isDisabled?: boolean;
|
|
9
13
|
optionalLabel?: string;
|
|
@@ -53,7 +53,10 @@ 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
|
+
/**
|
|
57
|
+
* [Legacy] Flag to configure component as optional.
|
|
58
|
+
* @deprecated If the value of this component is not required, use the `isRequired` prop and set it to false instead.
|
|
59
|
+
*/
|
|
57
60
|
isOptional?: boolean;
|
|
58
61
|
/** Flag to configure component as mandatory */
|
|
59
62
|
isRequired?: boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type CreateStrictContextArgs<ContextType> = {
|
|
3
|
+
/** The display name of the context. */
|
|
4
|
+
name?: string;
|
|
5
|
+
/** Error message to log if context is accessed outside its provider. */
|
|
6
|
+
errorMessage: string;
|
|
7
|
+
/** Default value to return if context is accessed outside its provider. */
|
|
8
|
+
defaultValue: ContextType;
|
|
9
|
+
};
|
|
10
|
+
type CreateStrictContextReturn<ContextType> = readonly [
|
|
11
|
+
React.Provider<ContextType | null>,
|
|
12
|
+
() => ContextType
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Creates a React context with a provider and a hook for accessing the context.
|
|
16
|
+
* Logs an error and returns a default value if the hook is used outside of the provider.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const [ListProvider, useList] = createStrictContext<{ size: number }>({
|
|
22
|
+
* name: "ListContext",
|
|
23
|
+
* errorMessage: "ListContext is undefined. Make sure to wrap your component with <ListProvider />",
|
|
24
|
+
* defaultValue: {
|
|
25
|
+
* size: 0,
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function createStrictContext<ContextType>({ name, errorMessage, defaultValue, }: CreateStrictContextArgs<ContextType>): CreateStrictContextReturn<ContextType>;
|
|
31
|
+
export default createStrictContext;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Logger from "./logger";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a React context with a provider and a hook for accessing the context.
|
|
5
|
+
* Logs an error and returns a default value if the hook is used outside of the provider.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const [ListProvider, useList] = createStrictContext<{ size: number }>({
|
|
11
|
+
* name: "ListContext",
|
|
12
|
+
* errorMessage: "ListContext is undefined. Make sure to wrap your component with <ListProvider />",
|
|
13
|
+
* defaultValue: {
|
|
14
|
+
* size: 0,
|
|
15
|
+
* },
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
function createStrictContext({
|
|
20
|
+
name,
|
|
21
|
+
errorMessage,
|
|
22
|
+
defaultValue
|
|
23
|
+
}) {
|
|
24
|
+
const Context = /*#__PURE__*/React.createContext(null);
|
|
25
|
+
Context.displayName = name;
|
|
26
|
+
function useContext() {
|
|
27
|
+
const context = React.useContext(Context);
|
|
28
|
+
if (!context) {
|
|
29
|
+
Logger.error(`${errorMessage}\nThis logged warning will become a thrown error in a future major release.`);
|
|
30
|
+
return defaultValue;
|
|
31
|
+
}
|
|
32
|
+
return context;
|
|
33
|
+
}
|
|
34
|
+
return [Context.Provider, useContext];
|
|
35
|
+
}
|
|
36
|
+
export default createStrictContext;
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility for dispatching messages to the browser console.
|
|
3
|
+
* By default, logging is disabled in production mode.
|
|
4
|
+
*/
|
|
1
5
|
declare const Logger: {
|
|
2
6
|
setEnabledState: (newState: boolean) => void;
|
|
7
|
+
/** Logs warning-level message to browser console with [Deprecation] prefix */
|
|
3
8
|
deprecate: (message: string) => void;
|
|
9
|
+
/** Logs error-level message to browser console. Includes stack trace. */
|
|
10
|
+
error: (message: string) => void;
|
|
4
11
|
};
|
|
5
12
|
export default Logger;
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
+
|
|
2
3
|
// Globally enable the logger
|
|
3
4
|
let enabled = process.env.NODE_ENV !== "production";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Logger function will only output when enabled. By default this
|
|
9
|
-
* enabled state is set when your NODE_ENV !== 'production'
|
|
10
|
-
*
|
|
11
|
-
* Methods
|
|
12
|
-
* deprecate - console.warn which prepends the message with [Deprecation]
|
|
13
|
-
*
|
|
6
|
+
/**
|
|
7
|
+
* Utility for dispatching messages to the browser console.
|
|
8
|
+
* By default, logging is disabled in production mode.
|
|
14
9
|
*/
|
|
15
10
|
const Logger = {
|
|
16
11
|
setEnabledState: newState => {
|
|
17
12
|
enabled = newState;
|
|
18
13
|
},
|
|
14
|
+
/** Logs warning-level message to browser console with [Deprecation] prefix */
|
|
19
15
|
deprecate: message => {
|
|
20
16
|
if (enabled) {
|
|
21
17
|
console.warn(`[Deprecation] ${message}`);
|
|
22
18
|
}
|
|
19
|
+
},
|
|
20
|
+
/** Logs error-level message to browser console. Includes stack trace. */
|
|
21
|
+
error: message => {
|
|
22
|
+
if (enabled) {
|
|
23
|
+
console.error(message);
|
|
24
|
+
}
|
|
23
25
|
}
|
|
24
26
|
};
|
|
25
27
|
export default Logger;
|
|
@@ -112,6 +112,14 @@ const Button = /*#__PURE__*/React.forwardRef(({
|
|
|
112
112
|
internalRef?.click();
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
|
+
const handleClick = event => {
|
|
116
|
+
internalRef?.focus();
|
|
117
|
+
if (inSplitButton) {
|
|
118
|
+
onChildButtonClick?.(onClick)?.(event);
|
|
119
|
+
} else if (onClick) {
|
|
120
|
+
onClick(event);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
115
123
|
switch (size) {
|
|
116
124
|
case "small":
|
|
117
125
|
paddingX = 2;
|
|
@@ -135,7 +143,7 @@ const Button = /*#__PURE__*/React.forwardRef(({
|
|
|
135
143
|
"aria-describedby": ariaDescribedBy,
|
|
136
144
|
as: !isDisabled && href ? "a" : "button",
|
|
137
145
|
onKeyDown: href ? handleLinkKeyDown : undefined,
|
|
138
|
-
onClick:
|
|
146
|
+
onClick: handleClick,
|
|
139
147
|
draggable: false,
|
|
140
148
|
buttonType: buttonType,
|
|
141
149
|
disabled: isDisabled,
|
|
@@ -29,7 +29,10 @@ export interface CheckboxGroupProps extends ValidationProps, MarginProps, TagPro
|
|
|
29
29
|
labelSpacing?: 1 | 2;
|
|
30
30
|
/** Flag to configure component as mandatory */
|
|
31
31
|
required?: boolean;
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* [Legacy] Flag to configure component as optional.
|
|
34
|
+
* @deprecated If the value of this component is not required, use the `required` prop and set it to false instead.
|
|
35
|
+
*/
|
|
33
36
|
isOptional?: boolean;
|
|
34
37
|
/** [Legacy] Overrides the default tooltip */
|
|
35
38
|
tooltipPosition?: "top" | "bottom" | "left" | "right";
|
|
@@ -13,6 +13,8 @@ import CheckboxGroupContext from "./__internal__/checkbox-group.context";
|
|
|
13
13
|
import guid from "../../../__internal__/utils/helpers/guid";
|
|
14
14
|
import useInputAccessibility from "../../../hooks/__internal__/useInputAccessibility";
|
|
15
15
|
import HintText from "../../../__internal__/hint-text";
|
|
16
|
+
import Logger from "../../../__internal__/utils/logger";
|
|
17
|
+
let deprecateOptionalWarnTriggered = false;
|
|
16
18
|
export const CheckboxGroup = ({
|
|
17
19
|
children,
|
|
18
20
|
legend,
|
|
@@ -31,6 +33,10 @@ export const CheckboxGroup = ({
|
|
|
31
33
|
id,
|
|
32
34
|
...rest
|
|
33
35
|
}) => {
|
|
36
|
+
if (!deprecateOptionalWarnTriggered && isOptional) {
|
|
37
|
+
deprecateOptionalWarnTriggered = true;
|
|
38
|
+
Logger.deprecate("`isOptional` is deprecated in CheckboxGroup and support will soon be removed. If the value of this component is not required, use the `required` prop and set it to false instead.");
|
|
39
|
+
}
|
|
34
40
|
const {
|
|
35
41
|
validationRedesignOptIn
|
|
36
42
|
} = useContext(NewValidationContext);
|
|
@@ -83,7 +83,10 @@ export interface DateRangeProps extends StyledDateRangeProps, MarginProps, TagPr
|
|
|
83
83
|
tooltipPosition?: "top" | "bottom" | "left" | "right";
|
|
84
84
|
/** Flag to configure component as mandatory. */
|
|
85
85
|
required?: boolean;
|
|
86
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* [Legacy] Flag to configure component as optional.
|
|
88
|
+
* @deprecated If the value of this component is not required, use the `required` prop and set it to false instead.
|
|
89
|
+
*/
|
|
87
90
|
isOptional?: boolean;
|
|
88
91
|
/** Date format string to be applied to the date inputs */
|
|
89
92
|
dateFormatOverride?: string;
|
|
@@ -11,6 +11,8 @@ import usePrevious from "../../hooks/__internal__/usePrevious";
|
|
|
11
11
|
import getFormatData from "../date/__internal__/date-formats";
|
|
12
12
|
import DateRangeContext from "./__internal__/date-range.context";
|
|
13
13
|
import NewValidationContext from "../carbon-provider/__internal__/new-validation.context";
|
|
14
|
+
import Logger from "../../__internal__/utils/logger";
|
|
15
|
+
let deprecateOptionalWarnTriggered = false;
|
|
14
16
|
export const DateRange = ({
|
|
15
17
|
endDateProps = {},
|
|
16
18
|
id,
|
|
@@ -32,6 +34,10 @@ export const DateRange = ({
|
|
|
32
34
|
datePickerEndAriaLabelledBy,
|
|
33
35
|
...rest
|
|
34
36
|
}) => {
|
|
37
|
+
if (!deprecateOptionalWarnTriggered && isOptional) {
|
|
38
|
+
deprecateOptionalWarnTriggered = true;
|
|
39
|
+
Logger.deprecate("`isOptional` is deprecated in DateRange and support will soon be removed. If the value of this component is not required, use the `required` prop and set it to false instead.");
|
|
40
|
+
}
|
|
35
41
|
const {
|
|
36
42
|
validationRedesignOptIn
|
|
37
43
|
} = useContext(NewValidationContext);
|
|
@@ -8,7 +8,10 @@ export interface FieldsetProps extends MarginProps, TagProps {
|
|
|
8
8
|
legend?: string;
|
|
9
9
|
/** Flag to configure fields as mandatory. */
|
|
10
10
|
required?: boolean;
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* [Legacy] Flag to configure component as optional.
|
|
13
|
+
* @deprecated If the value of this component is not required, use the `required` prop and set it to false instead.
|
|
14
|
+
*/
|
|
12
15
|
isOptional?: boolean;
|
|
13
16
|
}
|
|
14
17
|
export declare const Fieldset: {
|
|
@@ -5,6 +5,8 @@ import { FieldsetStyle, StyledLegend } from "./fieldset.style";
|
|
|
5
5
|
import NewValidationContext from "../carbon-provider/__internal__/new-validation.context";
|
|
6
6
|
import { filterStyledSystemMarginProps } from "../../style/utils";
|
|
7
7
|
import useLocale from "../../hooks/__internal__/useLocale";
|
|
8
|
+
import Logger from "../../__internal__/utils/logger";
|
|
9
|
+
let deprecateOptionalWarnTriggered = false;
|
|
8
10
|
export const Fieldset = ({
|
|
9
11
|
children,
|
|
10
12
|
legend,
|
|
@@ -12,6 +14,10 @@ export const Fieldset = ({
|
|
|
12
14
|
isOptional,
|
|
13
15
|
...rest
|
|
14
16
|
}) => {
|
|
17
|
+
if (!deprecateOptionalWarnTriggered && isOptional) {
|
|
18
|
+
deprecateOptionalWarnTriggered = true;
|
|
19
|
+
Logger.deprecate("`isOptional` is deprecated in Fieldset and support will soon be removed. If the value of this component is not required, use the `required` prop and set it to false instead.");
|
|
20
|
+
}
|
|
15
21
|
const [ref, setRef] = useState(null);
|
|
16
22
|
const marginProps = filterStyledSystemMarginProps(rest);
|
|
17
23
|
const {
|
|
@@ -5,7 +5,10 @@ declare const FieldsetStyle: import("styled-components").StyledComponent<"fields
|
|
|
5
5
|
export interface StyledLegendProps {
|
|
6
6
|
/** Flag to configure fields as mandatory. */
|
|
7
7
|
isRequired?: boolean;
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* [Legacy] Flag to configure fields as optional.
|
|
10
|
+
* @deprecated If the value of this component is not required, use the `required` prop and set it to false instead.
|
|
11
|
+
*/
|
|
9
12
|
isOptional?: boolean;
|
|
10
13
|
/** Text used for the optional label */
|
|
11
14
|
optionalLabel?: string;
|
|
@@ -33,7 +33,10 @@ export interface FileInputProps extends Pick<ValidationProps, "error">, Pick<Inp
|
|
|
33
33
|
uploadStatus?: FileUploadStatusProps | FileUploadStatusProps[];
|
|
34
34
|
/** Flag to configure component as mandatory. */
|
|
35
35
|
required?: boolean;
|
|
36
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* [Legacy] Flag to configure component as optional.
|
|
38
|
+
* @deprecated If the value of this component is not required, use the `required` prop and set it to false instead.
|
|
39
|
+
*/
|
|
37
40
|
isOptional?: boolean;
|
|
38
41
|
}
|
|
39
42
|
export declare const FileInput: React.ForwardRefExoticComponent<FileInputProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -14,6 +14,8 @@ import FileUploadStatus from "./__internal__/file-upload-status";
|
|
|
14
14
|
import Box from "../box";
|
|
15
15
|
import useLocale from "../../hooks/__internal__/useLocale";
|
|
16
16
|
import HintText from "../../__internal__/hint-text";
|
|
17
|
+
import Logger from "../../__internal__/utils/logger";
|
|
18
|
+
let deprecateOptionalWarnTriggered = false;
|
|
17
19
|
export const FileInput = /*#__PURE__*/React.forwardRef(({
|
|
18
20
|
accept,
|
|
19
21
|
buttonText,
|
|
@@ -36,6 +38,10 @@ export const FileInput = /*#__PURE__*/React.forwardRef(({
|
|
|
36
38
|
uploadStatus = [],
|
|
37
39
|
...rest
|
|
38
40
|
}, ref) => {
|
|
41
|
+
if (!deprecateOptionalWarnTriggered && isOptional) {
|
|
42
|
+
deprecateOptionalWarnTriggered = true;
|
|
43
|
+
Logger.deprecate("`isOptional` is deprecated in FileInput and support will soon be removed. If the value of this component is not required, use the `required` prop and set it to false instead.");
|
|
44
|
+
}
|
|
39
45
|
const locale = useLocale();
|
|
40
46
|
const textOnButton = buttonText || locale.fileInput.selectFile();
|
|
41
47
|
const mainText = dragAndDropText || locale.fileInput.dragAndDrop();
|
|
@@ -26,7 +26,10 @@ export interface InlineInputsProps extends MarginProps, StyledContentContainerPr
|
|
|
26
26
|
labelId?: string;
|
|
27
27
|
/** Flag to configure component as mandatory. */
|
|
28
28
|
required?: boolean;
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* [Legacy] Flag to configure component as optional.
|
|
31
|
+
* @deprecated If the value of this component is not required, use the `required` prop and set it to false instead.
|
|
32
|
+
*/
|
|
30
33
|
isOptional?: boolean;
|
|
31
34
|
}
|
|
32
35
|
declare const InlineInputs: {
|
|
@@ -5,6 +5,7 @@ import StyledInlineInputs, { StyledContentContainer, StyledInlineInput } from ".
|
|
|
5
5
|
import useIsAboveBreakpoint from "../../hooks/__internal__/useIsAboveBreakpoint";
|
|
6
6
|
import tagComponent from "../../__internal__/utils/helpers/tags";
|
|
7
7
|
import { filterStyledSystemMarginProps } from "../../style/utils";
|
|
8
|
+
import Logger from "../../__internal__/utils/logger";
|
|
8
9
|
const columnWrapper = (children, gutter) => {
|
|
9
10
|
return React.Children.map(children, input => {
|
|
10
11
|
return /*#__PURE__*/React.createElement(StyledInlineInput, {
|
|
@@ -13,6 +14,7 @@ const columnWrapper = (children, gutter) => {
|
|
|
13
14
|
}, input);
|
|
14
15
|
});
|
|
15
16
|
};
|
|
17
|
+
let deprecateOptionalWarnTriggered = false;
|
|
16
18
|
const InlineInputs = ({
|
|
17
19
|
adaptiveLabelBreakpoint,
|
|
18
20
|
label,
|
|
@@ -28,6 +30,10 @@ const InlineInputs = ({
|
|
|
28
30
|
isOptional,
|
|
29
31
|
...rest
|
|
30
32
|
}) => {
|
|
33
|
+
if (!deprecateOptionalWarnTriggered && isOptional) {
|
|
34
|
+
deprecateOptionalWarnTriggered = true;
|
|
35
|
+
Logger.deprecate("`isOptional` is deprecated in InlineInputs and support will soon be removed. If the value of this component is not required, use the `required` prop and set it to false instead.");
|
|
36
|
+
}
|
|
31
37
|
const largeScreen = useIsAboveBreakpoint(adaptiveLabelBreakpoint);
|
|
32
38
|
const ref = useRef(null);
|
|
33
39
|
let inlineLabel = labelInline;
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface MenuContextProps {
|
|
4
|
-
menuType: MenuType;
|
|
5
|
-
openSubmenuId: string | null;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface MenuContextType {
|
|
6
3
|
inMenu?: boolean;
|
|
7
|
-
inFullscreenView?: boolean;
|
|
8
|
-
setOpenSubmenuId: (id: string | null) => void;
|
|
9
|
-
registerItem?: (id: string) => void;
|
|
10
|
-
unregisterItem?: (id: string) => void;
|
|
11
|
-
focusId?: string;
|
|
12
|
-
updateFocusId?: (id: string) => void;
|
|
13
4
|
}
|
|
14
|
-
declare const _default:
|
|
5
|
+
declare const _default: import("react").Context<MenuContextType>;
|
|
15
6
|
export default _default;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default /*#__PURE__*/
|
|
3
|
-
|
|
4
|
-
openSubmenuId: null,
|
|
5
|
-
setOpenSubmenuId: /* istanbul ignore next */() => {}
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
export default /*#__PURE__*/createContext({
|
|
3
|
+
inMenu: false
|
|
6
4
|
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { MenuType } from "../menu.types";
|
|
3
|
+
export interface StrictMenuContextType {
|
|
4
|
+
menuType: MenuType;
|
|
5
|
+
openSubmenuId: string | null;
|
|
6
|
+
inFullscreenView?: boolean;
|
|
7
|
+
setOpenSubmenuId: (id: string | null) => void;
|
|
8
|
+
registerItem?: (id: string) => void;
|
|
9
|
+
unregisterItem?: (id: string) => void;
|
|
10
|
+
focusId?: string;
|
|
11
|
+
updateFocusId?: (id: string) => void;
|
|
12
|
+
}
|
|
13
|
+
declare const StrictMenuProvider: import("react").Provider<StrictMenuContextType | null>, useStrictMenuContext: () => StrictMenuContextType;
|
|
14
|
+
export { StrictMenuProvider, useStrictMenuContext };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import createStrictContext from "../../../__internal__/utils/createStrictContext";
|
|
2
|
+
const [StrictMenuProvider, useStrictMenuContext] = createStrictContext({
|
|
3
|
+
name: "MenuContext",
|
|
4
|
+
errorMessage: "Carbon Menu: Context not found. Have you wrapped your Carbon subcomponents properly? See stack trace for more details.",
|
|
5
|
+
defaultValue: {
|
|
6
|
+
menuType: "light",
|
|
7
|
+
openSubmenuId: null,
|
|
8
|
+
setOpenSubmenuId: /* istanbul ignore next */() => {}
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
export { StrictMenuProvider, useStrictMenuContext };
|
|
@@ -3,7 +3,7 @@ import React, { useCallback, useEffect, useContext, useMemo, useRef, useState }
|
|
|
3
3
|
import StyledMenuItemWrapper from "../../menu-item/menu-item.style";
|
|
4
4
|
import { StyledSubmenu, StyledSubmenuWrapper } from "./submenu.style";
|
|
5
5
|
import Events from "../../../../__internal__/utils/helpers/events";
|
|
6
|
-
import
|
|
6
|
+
import { useStrictMenuContext } from "../strict-menu.context";
|
|
7
7
|
import { characterNavigation } from "../keyboard-navigation";
|
|
8
8
|
import SubmenuContext from "./submenu.context";
|
|
9
9
|
import guid from "../../../../__internal__/utils/helpers/guid";
|
|
@@ -33,13 +33,12 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
33
33
|
}, ref) => {
|
|
34
34
|
const [submenuRef, setSubmenuRef] = useState(null);
|
|
35
35
|
const submenuId = useRef(guid());
|
|
36
|
-
const menuContext = useContext(MenuContext);
|
|
37
36
|
const {
|
|
38
37
|
inFullscreenView,
|
|
39
38
|
openSubmenuId,
|
|
40
39
|
setOpenSubmenuId,
|
|
41
40
|
menuType
|
|
42
|
-
} =
|
|
41
|
+
} = useStrictMenuContext();
|
|
43
42
|
const [submenuOpen, setSubmenuOpen] = useState(false);
|
|
44
43
|
const [submenuFocusId, setSubmenuFocusId] = useState(null);
|
|
45
44
|
const [submenuItemIds, setSubmenuItemIds] = useState([]);
|
|
@@ -265,7 +264,7 @@ const Submenu = /*#__PURE__*/React.forwardRef(({
|
|
|
265
264
|
"data-component": "submenu-wrapper",
|
|
266
265
|
inFullscreenView: inFullscreenView,
|
|
267
266
|
asPassiveItem: asPassiveItem,
|
|
268
|
-
menuType:
|
|
267
|
+
menuType: menuType
|
|
269
268
|
}, /*#__PURE__*/React.createElement(StyledMenuItemWrapper, _extends({}, rest, {
|
|
270
269
|
onClick: asPassiveItem ? undefined : onClick,
|
|
271
270
|
className: className,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { default as Menu } from "./menu.component";
|
|
2
|
-
export type { MenuProps } from "./menu.
|
|
2
|
+
export type { MenuProps } from "./menu.types";
|
|
3
3
|
export { default as MenuItem } from "./menu-item";
|
|
4
4
|
export type { MenuWithIcon, MenuWithChildren } from "./menu-item";
|
|
5
5
|
export { default as MenuDivider } from "./menu-divider";
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
-
import React
|
|
2
|
+
import React from "react";
|
|
3
3
|
import StyledDivider from "./menu-divider.style";
|
|
4
|
-
import
|
|
4
|
+
import { useStrictMenuContext } from "../__internal__/strict-menu.context";
|
|
5
5
|
import { StyledMenuItem } from "../menu.style";
|
|
6
6
|
import tagComponent from "../../../__internal__/utils/helpers/tags";
|
|
7
7
|
const MenuDivider = /*#__PURE__*/React.forwardRef(({
|
|
8
8
|
size = "default",
|
|
9
9
|
...rest
|
|
10
10
|
}, ref) => {
|
|
11
|
-
const
|
|
11
|
+
const {
|
|
12
|
+
menuType
|
|
13
|
+
} = useStrictMenuContext();
|
|
12
14
|
return /*#__PURE__*/React.createElement(StyledMenuItem, {
|
|
13
15
|
inSubmenu: true
|
|
14
16
|
}, /*#__PURE__*/React.createElement(StyledDivider, _extends({
|
|
15
17
|
size: size
|
|
16
18
|
}, tagComponent("menu-divider", rest), {
|
|
17
|
-
menuType:
|
|
19
|
+
menuType: menuType,
|
|
18
20
|
ref: ref
|
|
19
21
|
})));
|
|
20
22
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MenuDividerProps } from "./menu-divider.component";
|
|
2
|
-
import { MenuType } from "../
|
|
2
|
+
import type { MenuType } from "../menu.types";
|
|
3
3
|
declare const StyledDivider: import("styled-components").StyledComponent<"div", any, MenuDividerProps & {
|
|
4
4
|
menuType: MenuType;
|
|
5
5
|
}, never>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { useCallback,
|
|
1
|
+
import React, { useCallback, useRef } from "react";
|
|
2
2
|
import { CSSTransition } from "react-transition-group";
|
|
3
3
|
import { StyledMenuFullscreen, StyledMenuModal, StyledMenuFullscreenHeader } from "./menu-full-screen.style";
|
|
4
4
|
import { StyledMenuWrapper } from "../menu.style";
|
|
5
|
-
import
|
|
5
|
+
import { useStrictMenuContext, StrictMenuProvider } from "../__internal__/strict-menu.context";
|
|
6
6
|
import Events from "../../../__internal__/utils/helpers/events";
|
|
7
7
|
import Box from "../../box";
|
|
8
8
|
import IconButton from "../../icon-button";
|
|
@@ -30,7 +30,7 @@ export const MenuFullscreen = ({
|
|
|
30
30
|
const isTopModal = useModalAria(modalRef);
|
|
31
31
|
const {
|
|
32
32
|
menuType
|
|
33
|
-
} =
|
|
33
|
+
} = useStrictMenuContext();
|
|
34
34
|
const isDarkVariant = ["dark", "black"].includes(menuType);
|
|
35
35
|
const transitionDuration = 200;
|
|
36
36
|
const locale = useLocale();
|
|
@@ -101,11 +101,10 @@ export const MenuFullscreen = ({
|
|
|
101
101
|
flexDirection: "column",
|
|
102
102
|
role: "list",
|
|
103
103
|
inFullscreenView: true
|
|
104
|
-
}, /*#__PURE__*/React.createElement(
|
|
104
|
+
}, /*#__PURE__*/React.createElement(StrictMenuProvider, {
|
|
105
105
|
value: {
|
|
106
106
|
inFullscreenView: true,
|
|
107
107
|
menuType,
|
|
108
|
-
inMenu: true,
|
|
109
108
|
openSubmenuId: null,
|
|
110
109
|
setOpenSubmenuId: /* istanbul ignore next */() => {}
|
|
111
110
|
}
|
|
@@ -5,7 +5,7 @@ import { defaultFocusableSelectors as focusableSelectors } from "../../../__inte
|
|
|
5
5
|
import { filterStyledSystemPaddingProps } from "../../../style/utils";
|
|
6
6
|
import StyledMenuItemWrapper from "./menu-item.style";
|
|
7
7
|
import Events from "../../../__internal__/utils/helpers/events";
|
|
8
|
-
import
|
|
8
|
+
import { useStrictMenuContext } from "../__internal__/strict-menu.context";
|
|
9
9
|
import Submenu from "../__internal__/submenu/submenu.component";
|
|
10
10
|
import SubmenuContext from "../__internal__/submenu/submenu.context";
|
|
11
11
|
import MenuSegmentContext from "../menu-segment-title/menu-segment-title.context";
|
|
@@ -52,7 +52,7 @@ export const MenuItem = ({
|
|
|
52
52
|
focusId,
|
|
53
53
|
updateFocusId,
|
|
54
54
|
menuType
|
|
55
|
-
} =
|
|
55
|
+
} = useStrictMenuContext();
|
|
56
56
|
const submenuContext = useContext(SubmenuContext);
|
|
57
57
|
const isInSubmenu = Object.keys(submenuContext).length > 0;
|
|
58
58
|
const {
|
|
@@ -70,7 +70,7 @@ export const MenuItem = ({
|
|
|
70
70
|
if (firstFocusable !== firstFocusableChild) {
|
|
71
71
|
setFirstFocusableChild(firstFocusable);
|
|
72
72
|
}
|
|
73
|
-
}, [ref]);
|
|
73
|
+
}, [firstFocusableChild, ref]);
|
|
74
74
|
useEffect(() => {
|
|
75
75
|
const id = menuItemId.current;
|
|
76
76
|
|
|
@@ -93,7 +93,7 @@ export const MenuItem = ({
|
|
|
93
93
|
}
|
|
94
94
|
ref?.focus();
|
|
95
95
|
}
|
|
96
|
-
}, [firstFocusableChild, focusFromMenu, focusFromSubmenu]);
|
|
96
|
+
}, [firstFocusableChild, focusFromMenu, focusFromSubmenu, ref]);
|
|
97
97
|
const handleFocus = event => {
|
|
98
98
|
if (isInSubmenu) {
|
|
99
99
|
event.stopPropagation();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { PaddingProps } from "styled-system";
|
|
3
|
-
import { MenuType } from "../__internal__/menu.context";
|
|
4
3
|
import { MenuWithChildren } from "./menu-item.component";
|
|
4
|
+
import type { MenuType } from "../menu.types";
|
|
5
5
|
interface StyledMenuItemWrapperProps extends Pick<MenuWithChildren, "href" | "showDropdownArrow" | "overrideColor" | "clickToOpen" | "maxWidth">, PaddingProps {
|
|
6
6
|
menuType: MenuType;
|
|
7
7
|
selected?: boolean;
|