carbon-react 144.4.1 → 144.6.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.
Files changed (61) hide show
  1. package/esm/__internal__/checkable-input/checkable-input.style.js +5 -2
  2. package/esm/__internal__/label/label.component.d.ts +4 -2
  3. package/esm/__internal__/label/label.component.js +3 -1
  4. package/esm/__internal__/label/label.style.d.ts +2 -0
  5. package/esm/__internal__/label/label.style.js +5 -1
  6. package/esm/__internal__/validation-message/validation-message.component.d.ts +3 -1
  7. package/esm/__internal__/validation-message/validation-message.component.js +4 -2
  8. package/esm/__internal__/validation-message/validation-message.style.d.ts +1 -0
  9. package/esm/__internal__/validation-message/validation-message.style.js +11 -7
  10. package/esm/components/date/__internal__/date-formats/index.d.ts +1 -1
  11. package/esm/components/date/__internal__/date-formats/index.js +25 -1
  12. package/esm/components/date/date.component.d.ts +2 -0
  13. package/esm/components/date/date.component.js +4 -2
  14. package/esm/components/date-range/date-range.component.d.ts +2 -0
  15. package/esm/components/date-range/date-range.component.js +3 -2
  16. package/esm/components/flat-table/flat-table.component.d.ts +3 -1
  17. package/esm/components/flat-table/flat-table.component.js +3 -1
  18. package/esm/components/switch/__internal__/switch-slider-panel.style.d.ts +1 -0
  19. package/esm/components/switch/__internal__/switch-slider-panel.style.js +6 -4
  20. package/esm/components/switch/__internal__/switch-slider.component.d.ts +2 -1
  21. package/esm/components/switch/__internal__/switch-slider.component.js +6 -3
  22. package/esm/components/switch/__internal__/switch-slider.style.d.ts +2 -1
  23. package/esm/components/switch/__internal__/switch-slider.style.js +7 -6
  24. package/esm/components/switch/switch.component.d.ts +2 -0
  25. package/esm/components/switch/switch.component.js +64 -18
  26. package/esm/components/switch/switch.style.d.ts +6 -1
  27. package/esm/components/switch/switch.style.js +29 -16
  28. package/esm/components/time/time.style.d.ts +1 -1
  29. package/esm/locales/en-gb.js +2 -1
  30. package/esm/locales/locale.d.ts +1 -0
  31. package/lib/__internal__/checkable-input/checkable-input.style.js +5 -2
  32. package/lib/__internal__/label/label.component.d.ts +4 -2
  33. package/lib/__internal__/label/label.component.js +3 -1
  34. package/lib/__internal__/label/label.style.d.ts +2 -0
  35. package/lib/__internal__/label/label.style.js +5 -1
  36. package/lib/__internal__/validation-message/validation-message.component.d.ts +3 -1
  37. package/lib/__internal__/validation-message/validation-message.component.js +4 -2
  38. package/lib/__internal__/validation-message/validation-message.style.d.ts +1 -0
  39. package/lib/__internal__/validation-message/validation-message.style.js +11 -7
  40. package/lib/components/date/__internal__/date-formats/index.d.ts +1 -1
  41. package/lib/components/date/__internal__/date-formats/index.js +25 -1
  42. package/lib/components/date/date.component.d.ts +2 -0
  43. package/lib/components/date/date.component.js +4 -2
  44. package/lib/components/date-range/date-range.component.d.ts +2 -0
  45. package/lib/components/date-range/date-range.component.js +3 -2
  46. package/lib/components/flat-table/flat-table.component.d.ts +3 -1
  47. package/lib/components/flat-table/flat-table.component.js +3 -1
  48. package/lib/components/switch/__internal__/switch-slider-panel.style.d.ts +1 -0
  49. package/lib/components/switch/__internal__/switch-slider-panel.style.js +6 -4
  50. package/lib/components/switch/__internal__/switch-slider.component.d.ts +2 -1
  51. package/lib/components/switch/__internal__/switch-slider.component.js +6 -3
  52. package/lib/components/switch/__internal__/switch-slider.style.d.ts +2 -1
  53. package/lib/components/switch/__internal__/switch-slider.style.js +7 -6
  54. package/lib/components/switch/switch.component.d.ts +2 -0
  55. package/lib/components/switch/switch.component.js +64 -18
  56. package/lib/components/switch/switch.style.d.ts +6 -1
  57. package/lib/components/switch/switch.style.js +29 -16
  58. package/lib/components/time/time.style.d.ts +1 -1
  59. package/lib/locales/en-gb.js +2 -1
  60. package/lib/locales/locale.d.ts +1 -0
  61. package/package.json +1 -1
@@ -1,10 +1,10 @@
1
1
  import styled, { css } from "styled-components";
2
2
  import FieldHelpStyle from "../field-help/field-help.style";
3
3
  import { FieldLineStyle } from "../form-field/form-field.style";
4
- import HiddenCheckableInputStyle from "./hidden-checkable-input.style";
5
4
  import LabelStyle, { StyledLabelContainer } from "../label/label.style";
6
- import StyledHelp from "../../components/help/help.style";
7
5
  import StyledValidationIcon from "../validations/validation-icon.style";
6
+ import StyledHelp from "../../components/help/help.style";
7
+ import HiddenCheckableInputStyle from "./hidden-checkable-input.style";
8
8
  const StyledCheckableInput = styled.div`
9
9
  display: inline-block;
10
10
  position: relative;
@@ -18,6 +18,8 @@ const StyledCheckableInputWrapper = styled.div`
18
18
  labelInline,
19
19
  reverse
20
20
  }) => css`
21
+ width: 100% !important;
22
+
21
23
  ${FieldLineStyle} {
22
24
  display: flex;
23
25
  }
@@ -86,6 +88,7 @@ const StyledCheckableInputWrapper = styled.div`
86
88
  ${inputWidth !== undefined && inputWidth !== 0 && css`
87
89
  ${StyledCheckableInput} {
88
90
  width: ${inputWidth}% !important;
91
+ min-width: 67px;
89
92
  }
90
93
  `}
91
94
 
@@ -24,7 +24,9 @@ export interface LabelProps extends ValidationProps, StyledLabelProps, StyledLab
24
24
  className?: string;
25
25
  /** Sets aria-label for label element */
26
26
  "aria-label"?: string;
27
+ /** Whether this component is shown against a dark background */
28
+ isDarkBackground?: boolean;
27
29
  }
28
- export declare const Label: ({ align, as, children, disabled, error, help, helpIcon, htmlFor, info, inline, isRequired, labelId, optional, pr, pl, tooltipId, useValidationIcon, validationIconId, warning, width, className, "aria-label": ariaLabel, }: LabelProps) => React.JSX.Element;
29
- declare const _default: React.MemoExoticComponent<({ align, as, children, disabled, error, help, helpIcon, htmlFor, info, inline, isRequired, labelId, optional, pr, pl, tooltipId, useValidationIcon, validationIconId, warning, width, className, "aria-label": ariaLabel, }: LabelProps) => React.JSX.Element>;
30
+ export declare const Label: ({ align, as, children, disabled, error, help, helpIcon, htmlFor, info, inline, isDarkBackground, isRequired, labelId, optional, pr, pl, tooltipId, useValidationIcon, validationIconId, warning, width, className, "aria-label": ariaLabel, }: LabelProps) => React.JSX.Element;
31
+ declare const _default: React.MemoExoticComponent<({ align, as, children, disabled, error, help, helpIcon, htmlFor, info, inline, isDarkBackground, isRequired, labelId, optional, pr, pl, tooltipId, useValidationIcon, validationIconId, warning, width, className, "aria-label": ariaLabel, }: LabelProps) => React.JSX.Element>;
30
32
  export default _default;
@@ -34,6 +34,7 @@ export const Label = ({
34
34
  htmlFor,
35
35
  info,
36
36
  inline,
37
+ isDarkBackground = false,
37
38
  isRequired,
38
39
  labelId,
39
40
  optional,
@@ -116,7 +117,8 @@ export const Label = ({
116
117
  onMouseLeave: handleMouseLeave,
117
118
  isRequired: isRequired,
118
119
  as: as,
119
- "aria-label": ariaLabel
120
+ "aria-label": ariaLabel,
121
+ isDarkBackground: isDarkBackground
120
122
  }), children), icon());
121
123
  };
122
124
  export default /*#__PURE__*/React.memo(Label);
@@ -3,6 +3,8 @@ export interface StyledLabelProps {
3
3
  disabled?: boolean;
4
4
  /** Flag to configure component as mandatory */
5
5
  isRequired?: boolean;
6
+ /** Flag to determine whether to use colours for dark backgrounds */
7
+ isDarkBackground?: boolean;
6
8
  }
7
9
  declare const StyledLabel: import("styled-components").StyledComponent<"label", any, StyledLabelProps, never>;
8
10
  export interface StyledLabelContainerProps {
@@ -1,6 +1,10 @@
1
1
  import styled, { css } from "styled-components";
2
2
  const StyledLabel = styled.label`
3
- color: var(--colorsUtilityYin090);
3
+ ${({
4
+ isDarkBackground
5
+ }) => css`
6
+ color: ${isDarkBackground ? "var(--colorsUtilityYang100)" : "var(--colorsUtilityYin090)"};
7
+ `}
4
8
  display: block;
5
9
  font-weight: var(--fontWeights500);
6
10
 
@@ -8,6 +8,8 @@ export interface ValidationMessageProps {
8
8
  /** Indicate that warning has occurred
9
9
  Pass string to display hint with warning */
10
10
  warning?: boolean | string;
11
+ /** Whether this component resides on a dark background */
12
+ isDarkBackground?: boolean;
11
13
  }
12
- declare const ValidationMessage: ({ error, validationId, warning, }: ValidationMessageProps) => React.JSX.Element | null;
14
+ declare const ValidationMessage: ({ error, validationId, warning, isDarkBackground, }: ValidationMessageProps) => React.JSX.Element | null;
13
15
  export default ValidationMessage;
@@ -4,14 +4,16 @@ import StyledValidationMessage from "./validation-message.style";
4
4
  const ValidationMessage = ({
5
5
  error,
6
6
  validationId,
7
- warning
7
+ warning,
8
+ isDarkBackground
8
9
  }) => {
9
10
  const validation = error || warning;
10
11
  const isStringValidation = typeof validation === "string";
11
12
  return isStringValidation ? /*#__PURE__*/React.createElement(StyledValidationMessage, {
12
13
  id: validationId,
13
14
  isWarning: !!(!error && warning),
14
- "data-role": "validation-message"
15
+ "data-role": "validation-message",
16
+ isDarkBackground: isDarkBackground
15
17
  }, validation) : null;
16
18
  };
17
19
  export default ValidationMessage;
@@ -1,5 +1,6 @@
1
1
  interface StyledValidationMessageProps {
2
2
  isWarning?: boolean;
3
+ isDarkBackground?: boolean;
3
4
  }
4
5
  declare const StyledValidationMessage: import("styled-components").StyledComponent<"p", any, StyledValidationMessageProps, never>;
5
6
  export default StyledValidationMessage;
@@ -1,12 +1,16 @@
1
1
  import styled, { css } from "styled-components";
2
2
  const StyledValidationMessage = styled.p`
3
3
  ${({
4
- isWarning
5
- }) => css`
6
- color: ${isWarning ? "var(--colorsSemanticCaution600)" : "var(--colorsSemanticNegative500)"};
7
- font-weight: ${isWarning ? "normal" : "500"};
8
- margin-top: 0px;
9
- margin-bottom: 8px;
10
- `}
4
+ isWarning,
5
+ isDarkBackground
6
+ }) => {
7
+ const darkBgColour = isDarkBackground ? "var(--colorsSemanticNegative450)" : "var(--colorsSemanticNegative500)";
8
+ return css`
9
+ color: ${isWarning ? "var(--colorsSemanticCaution600)" : darkBgColour};
10
+ font-weight: ${isWarning ? "normal" : "500"};
11
+ margin-top: 0px;
12
+ margin-bottom: 8px;
13
+ `;
14
+ }}
11
15
  `;
12
16
  export default StyledValidationMessage;
@@ -3,5 +3,5 @@ interface LocaleFormats {
3
3
  formats: string[];
4
4
  format: string;
5
5
  }
6
- declare const getFormatData: ({ code }: DateFnsLocale) => LocaleFormats;
6
+ declare const getFormatData: ({ code }: DateFnsLocale, dateFormatOverride?: string) => LocaleFormats;
7
7
  export default getFormatData;
@@ -72,7 +72,31 @@ const getTrailingChar = format => {
72
72
  };
73
73
  const getFormatData = ({
74
74
  code = "en-GB"
75
- }) => {
75
+ }, dateFormatOverride) => {
76
+ if (dateFormatOverride) {
77
+ const {
78
+ format
79
+ } = getOutputFormatForLocale(code);
80
+ let formatFromLocale;
81
+ switch (code) {
82
+ case "en-CA":
83
+ case "en-US":
84
+ formatFromLocale = "MM/dd/yyyy";
85
+ break;
86
+ case "ar-EG":
87
+ case "en-ZA":
88
+ case "fr-CA":
89
+ formatFromLocale = "dd/MM/yyyy";
90
+ break;
91
+ default:
92
+ formatFromLocale = format;
93
+ }
94
+ const formatsForLocale = getInputFormatsArrayForLocale(formatFromLocale);
95
+ return {
96
+ format: dateFormatOverride,
97
+ formats: generateFormats(formatsForLocale, "/")
98
+ };
99
+ }
76
100
  if (["en-CA", "en-US"].includes(code)) {
77
101
  const format = "MM/dd/yyyy";
78
102
  const formats = getInputFormatsArrayForLocale(format);
@@ -42,6 +42,8 @@ export interface DateInputProps extends Omit<TextboxProps, "value" | "formattedV
42
42
  onPickerOpen?: () => void;
43
43
  /** Callback triggered when the picker is closed */
44
44
  onPickerClose?: () => void;
45
+ /** Date format string to be applied to the date inputs */
46
+ dateFormatOverride?: string;
45
47
  }
46
48
  export declare const DateInput: React.ForwardRefExoticComponent<DateInputProps & React.RefAttributes<HTMLInputElement>>;
47
49
  export default DateInput;
@@ -52,12 +52,13 @@ const DateInput = /*#__PURE__*/React.forwardRef(({
52
52
  const blockClose = useRef(false);
53
53
  const locale = useLocale();
54
54
  const {
55
- dateFnsLocale
55
+ dateFnsLocale,
56
+ dateFormatOverride
56
57
  } = locale.date;
57
58
  const {
58
59
  format,
59
60
  formats
60
- } = useMemo(() => getFormatData(dateFnsLocale()), [dateFnsLocale]);
61
+ } = useMemo(() => getFormatData(dateFnsLocale(), dateFormatOverride), [dateFnsLocale, dateFormatOverride]);
61
62
  const {
62
63
  inputRefMap,
63
64
  setInputRefMap
@@ -480,6 +481,7 @@ if (process.env.NODE_ENV !== "production") {
480
481
  "data-element": PropTypes.string,
481
482
  "data-role": PropTypes.string,
482
483
  "datatype": PropTypes.string,
484
+ "dateFormatOverride": PropTypes.string,
483
485
  "defaultChecked": PropTypes.bool,
484
486
  "defaultValue": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.number, PropTypes.string]),
485
487
  "dir": PropTypes.string,
@@ -85,6 +85,8 @@ export interface DateRangeProps extends StyledDateRangeProps, MarginProps, TagPr
85
85
  required?: boolean;
86
86
  /** Flag to configure component as optional. */
87
87
  isOptional?: boolean;
88
+ /** Date format string to be applied to the date inputs */
89
+ dateFormatOverride?: string;
88
90
  }
89
91
  export declare const DateRange: {
90
92
  ({ endDateProps, id, labelsInline, name, onBlur, onChange, startDateProps, tooltipPosition, validationOnLabel, value, startRef, endRef, required, isOptional, ...rest }: DateRangeProps): React.JSX.Element;
@@ -35,11 +35,12 @@ export const DateRange = ({
35
35
  const labelsInlineWithNewValidation = validationRedesignOptIn ? false : labelsInline;
36
36
  const l = useLocale();
37
37
  const {
38
- dateFnsLocale
38
+ dateFnsLocale,
39
+ dateFormatOverride
39
40
  } = l.date;
40
41
  const {
41
42
  format
42
- } = useMemo(() => getFormatData(dateFnsLocale()), [dateFnsLocale]);
43
+ } = useMemo(() => getFormatData(dateFnsLocale(), dateFormatOverride), [dateFnsLocale, dateFormatOverride]);
43
44
  const inlineLabelWidth = 40;
44
45
  const [lastChangedDate, setLastChangedDate] = useState("");
45
46
  const computedValue = useCallback(valueString => {
@@ -35,9 +35,11 @@ export interface FlatTableProps extends MarginProps, Omit<TagProps, "data-compon
35
35
  overflowX?: string;
36
36
  /** Width of the table. Any valid CSS string */
37
37
  width?: string;
38
+ /** The title to describe the table when one or more tables are used on a single page */
39
+ title?: string;
38
40
  }
39
41
  export declare const FlatTable: {
40
- ({ caption, children, hasStickyHead, colorTheme, footer, hasStickyFooter, height, isZebra, size, hasMaxHeight, hasOuterVerticalBorders, bottomBorderRadius, ariaDescribedby, minHeight, overflowX, width, ...rest }: FlatTableProps): React.JSX.Element;
42
+ ({ caption, children, hasStickyHead, colorTheme, footer, hasStickyFooter, height, isZebra, size, hasMaxHeight, hasOuterVerticalBorders, bottomBorderRadius, ariaDescribedby, minHeight, overflowX, width, title, ...rest }: FlatTableProps): React.JSX.Element;
41
43
  displayName: string;
42
44
  };
43
45
  export default FlatTable;
@@ -23,6 +23,7 @@ export const FlatTable = ({
23
23
  minHeight,
24
24
  overflowX,
25
25
  width,
26
+ title,
26
27
  ...rest
27
28
  }) => {
28
29
  const wrapperRef = useRef(null);
@@ -162,7 +163,8 @@ export const FlatTable = ({
162
163
  onKeyDown: handleKeyDown,
163
164
  isFocused: focused
164
165
  }, rest, {
165
- "data-component": "flat-table-wrapper"
166
+ "data-component": "flat-table-wrapper",
167
+ title: title
166
168
  }), /*#__PURE__*/React.createElement(StyledTableContainer, {
167
169
  ref: container,
168
170
  onFocus: () => {
@@ -2,6 +2,7 @@ import { SwitchProps } from "../switch.component";
2
2
  export interface SwitchSliderPanelProps {
3
3
  isLoading?: boolean;
4
4
  size?: SwitchProps["size"];
5
+ isDarkBackground?: boolean;
5
6
  }
6
7
  declare const SwitchSliderPanel: import("styled-components").StyledComponent<"div", any, SwitchSliderPanelProps, never>;
7
8
  export default SwitchSliderPanel;
@@ -1,24 +1,26 @@
1
1
  import styled, { css } from "styled-components";
2
- import StyledLoader from "../../loader/loader.style";
3
2
  import StyledLoaderSquare from "../../loader/loader-square.style";
3
+ import StyledLoader from "../../loader/loader.style";
4
4
  const SwitchSliderPanel = styled.div`
5
5
  ${({
6
6
  isLoading,
7
- size
7
+ size,
8
+ isDarkBackground
8
9
  }) => css`
9
10
  border: 0;
10
- color: var(--colorsActionMinorYang100);
11
+ color: ${isDarkBackground ? "var(--colorsUtilityYin100)" : "var(--colorsActionMinorYang100)"};
11
12
  margin: auto;
12
13
  position: absolute;
13
14
  left: 0;
14
15
 
15
16
  &[type="on"] {
17
+ color: ${isDarkBackground ? "var(--colorsUtilityYin100)" : "var(--colorsUtilityYang100)"};
16
18
  margin-left: 9px;
17
19
  padding-right: ${size === "large" ? "43px" : "27px"};
18
20
  }
19
21
 
20
22
  &[type="off"] {
21
- color: var(--colorsActionMinor500);
23
+ color: ${isDarkBackground ? "var(--colorsUtilityYang100)" : "var(--colorsActionMinor500)"};
22
24
  margin-right: 9px;
23
25
  padding-left: ${size === "large" ? "43px" : "27px"};
24
26
  }
@@ -6,6 +6,7 @@ export interface SwitchSliderProps extends ValidationProps {
6
6
  loading?: boolean;
7
7
  size?: "small" | "large";
8
8
  useValidationIcon?: boolean;
9
+ isDarkBackground?: boolean;
9
10
  }
10
- declare const SwitchSlider: ({ checked, disabled, loading, size, error, warning, info, useValidationIcon, }: SwitchSliderProps) => React.JSX.Element;
11
+ declare const SwitchSlider: ({ checked, disabled, loading, size, error, warning, info, useValidationIcon, isDarkBackground, }: SwitchSliderProps) => React.JSX.Element;
11
12
  export default SwitchSlider;
@@ -14,7 +14,8 @@ const SwitchSlider = ({
14
14
  error,
15
15
  warning,
16
16
  info,
17
- useValidationIcon
17
+ useValidationIcon,
18
+ isDarkBackground
18
19
  }) => {
19
20
  const locale = useLocale();
20
21
  const onText = locale.switch.on();
@@ -31,13 +32,15 @@ const SwitchSlider = ({
31
32
  size,
32
33
  error,
33
34
  warning,
34
- info
35
+ info,
36
+ isDarkBackground
35
37
  };
36
38
  const sliderPanelStyleProps = {
37
39
  isLoading: loading,
38
40
  size,
39
41
  type: checked ? "on" : "off",
40
- disabled
42
+ disabled,
43
+ isDarkBackground
41
44
  };
42
45
  const loaderProps = {
43
46
  isInsideButton: true,
@@ -1,8 +1,9 @@
1
- import { SwitchSliderProps } from "./switch-slider.component";
2
1
  import { ThemeObject } from "../../../style/themes/base";
2
+ import { SwitchSliderProps } from "./switch-slider.component";
3
3
  interface StyledSwitchSliderProps extends Pick<SwitchSliderProps, "checked" | "disabled" | "size" | "error" | "warning"> {
4
4
  isLoading?: boolean;
5
5
  theme?: Partial<ThemeObject>;
6
+ isDarkBackground?: boolean;
6
7
  }
7
8
  declare const StyledSwitchSlider: import("styled-components").StyledComponent<"div", any, {}, never>;
8
9
  declare const HiddenContent: import("styled-components").StyledComponent<"div", any, Pick<StyledSwitchSliderProps, "size">, never>;
@@ -1,7 +1,7 @@
1
1
  import styled, { css } from "styled-components";
2
- import SwitchSliderPanel from "./switch-slider-panel.style";
3
2
  import StyledValidationIcon from "../../../__internal__/validations/validation-icon.style";
4
3
  import baseTheme from "../../../style/themes/base";
4
+ import SwitchSliderPanel from "./switch-slider-panel.style";
5
5
  const StyledSwitchSlider = styled.div`
6
6
  ${({
7
7
  checked,
@@ -10,7 +10,8 @@ const StyledSwitchSlider = styled.div`
10
10
  size,
11
11
  error,
12
12
  warning,
13
- theme
13
+ theme,
14
+ isDarkBackground
14
15
  }) => css`
15
16
  display: flex;
16
17
  font-size: 12px;
@@ -25,14 +26,14 @@ const StyledSwitchSlider = styled.div`
25
26
  z-index: 2;
26
27
  border-radius: ${theme?.roundedCornersOptOut ? "90px" : "var(--borderRadius400)"};
27
28
  border-style: solid;
28
- border-color: var(--colorsActionMinor400);
29
+ border-color: ${isDarkBackground ? "var(--colorsUtilityYang100)" : "var(--colorsActionMinor400)"};
29
30
  border-width: var(--borderWidth200);
30
31
  box-sizing: border-box;
31
32
  margin-top: ${size === "large" ? "-47px" : "-28px"};
32
33
  align-items: center;
33
34
 
34
35
  &::before {
35
- background-color: var(--colorsActionMinor400);
36
+ background-color: ${isDarkBackground ? "var(--colorsUtilityYang100)" : "var(--colorsActionMinor400)"};
36
37
  bottom: 4px;
37
38
  content: "";
38
39
  height: ${size === "large" ? "var(--spacing400)" : "var(--spacing200)"};
@@ -45,7 +46,7 @@ const StyledSwitchSlider = styled.div`
45
46
  }
46
47
 
47
48
  ${checked && css`
48
- background-color: var(--colorsActionMinor500);
49
+ background-color: ${isDarkBackground ? "var(--colorsUtilityYang100)" : "var(--colorsActionMinor500)"};
49
50
  border-color: var(--colorsActionMinorTransparent);
50
51
 
51
52
  &::before {
@@ -53,7 +54,7 @@ const StyledSwitchSlider = styled.div`
53
54
  100% -
54
55
  ${size === "large" ? "var(--spacing500)" : "var(--spacing300)"}
55
56
  );
56
- background-color: var(--colorsActionMinorYang100);
57
+ background-color: ${isDarkBackground ? "var(--colorsUtilityYin100)" : "var(--colorsActionMinorYang100)"};
57
58
  }
58
59
  `}
59
60
 
@@ -24,6 +24,8 @@ export interface SwitchProps extends CommonCheckableInputProps, MarginProps {
24
24
  tooltipPosition?: "top" | "bottom" | "left" | "right";
25
25
  /** [Legacy] Aria label for rendered help component */
26
26
  helpAriaLabel?: string;
27
+ /** Whether this component resides on a dark background */
28
+ isDarkBackground?: boolean;
27
29
  }
28
30
  export declare const Switch: React.ForwardRefExoticComponent<SwitchProps & React.RefAttributes<HTMLInputElement>>;
29
31
  export default Switch;
@@ -1,17 +1,17 @@
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
2
  import React, { useState, useCallback, useContext, useRef } from "react";
3
3
  import PropTypes from "prop-types";
4
- import StyledSwitch, { ErrorBorder, StyledHintText } from "./switch.style";
4
+ import Box from "../box";
5
5
  import CheckableInput from "../../__internal__/checkable-input";
6
- import SwitchSlider from "./__internal__/switch-slider.component";
7
- import useIsAboveBreakpoint from "../../hooks/__internal__/useIsAboveBreakpoint";
6
+ import Label from "../../__internal__/label";
8
7
  import { TooltipProvider } from "../../__internal__/tooltip-provider";
9
- import Logger from "../../__internal__/utils/logger";
10
- import useFormSpacing from "../../hooks/__internal__/useFormSpacing";
11
8
  import NewValidationContext from "../carbon-provider/__internal__/new-validation.context";
9
+ import Logger from "../../__internal__/utils/logger";
12
10
  import ValidationMessage from "../../__internal__/validation-message/validation-message.component";
13
- import Box from "../box";
14
- import Label from "../../__internal__/label";
11
+ import useFormSpacing from "../../hooks/__internal__/useFormSpacing";
12
+ import useIsAboveBreakpoint from "../../hooks/__internal__/useIsAboveBreakpoint";
13
+ import StyledSwitch, { ErrorBorder, StyledHintText } from "./switch.style";
14
+ import SwitchSlider from "./__internal__/switch-slider.component";
15
15
  import guid from "../../__internal__/utils/helpers/guid";
16
16
  let deprecateUncontrolledWarnTriggered = false;
17
17
  const Switch = /*#__PURE__*/React.forwardRef(({
@@ -45,6 +45,7 @@ const Switch = /*#__PURE__*/React.forwardRef(({
45
45
  "data-element": dataElement,
46
46
  "data-role": dataRole,
47
47
  helpAriaLabel,
48
+ isDarkBackground = false,
48
49
  ...rest
49
50
  }, ref) => {
50
51
  const isControlled = checked !== undefined;
@@ -77,6 +78,7 @@ const Switch = /*#__PURE__*/React.forwardRef(({
77
78
  "data-role": dataRole,
78
79
  "data-element": dataElement,
79
80
  checked: isControlled ? checked : checkedInternal,
81
+ isDarkBackground,
80
82
  fieldHelpInline,
81
83
  labelInline: shouldLabelBeInline,
82
84
  labelSpacing,
@@ -89,6 +91,7 @@ const Switch = /*#__PURE__*/React.forwardRef(({
89
91
  checked: isControlled ? checked : checkedInternal,
90
92
  disabled: disabled || loading,
91
93
  loading,
94
+ isDarkBackground,
92
95
  size,
93
96
  error,
94
97
  warning,
@@ -109,6 +112,7 @@ const Switch = /*#__PURE__*/React.forwardRef(({
109
112
  labelInline: shouldLabelBeInline,
110
113
  labelSpacing,
111
114
  onBlur,
115
+ isDarkBackground,
112
116
  onFocus,
113
117
  onChange: isControlled ? onChange : onChangeInternal,
114
118
  id,
@@ -132,6 +136,8 @@ const Switch = /*#__PURE__*/React.forwardRef(({
132
136
  "data-role": dataRole,
133
137
  "data-element": dataElement,
134
138
  checked: isControlled ? checked : checkedInternal,
139
+ labelInline: shouldLabelBeInline,
140
+ isDarkBackground,
135
141
  size,
136
142
  ...marginProps
137
143
  };
@@ -139,6 +145,7 @@ const Switch = /*#__PURE__*/React.forwardRef(({
139
145
  checked: isControlled ? checked : checkedInternal,
140
146
  disabled: disabled || loading,
141
147
  loading,
148
+ isDarkBackground,
142
149
  size,
143
150
  error,
144
151
  warning
@@ -147,10 +154,12 @@ const Switch = /*#__PURE__*/React.forwardRef(({
147
154
  autoFocus,
148
155
  // set aria-invalid but prevent validationIconId from being added to aria-describedby
149
156
  error: !!error,
157
+ warning,
150
158
  disabled: disabled || loading,
151
159
  loading,
152
160
  checked: isControlled ? checked : checkedInternal,
153
161
  onBlur,
162
+ isDarkBackground,
154
163
  onFocus,
155
164
  onChange: isControlled ? onChange : onChangeInternal,
156
165
  id,
@@ -165,30 +174,66 @@ const Switch = /*#__PURE__*/React.forwardRef(({
165
174
  };
166
175
  const applyValidation = error || warning;
167
176
  const ariaDescribedBy = [labelHelp && inputHintId.current, applyValidation && validationMessageId.current].filter(Boolean).join(" ");
168
- return /*#__PURE__*/React.createElement(React.Fragment, null, validationRedesignOptIn ? /*#__PURE__*/React.createElement(StyledSwitch, switchStylePropsForNewValidation, /*#__PURE__*/React.createElement(Label, {
177
+ if (!validationRedesignOptIn) {
178
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TooltipProvider, {
179
+ helpAriaLabel: helpAriaLabel,
180
+ tooltipPosition: tooltipPosition
181
+ }, /*#__PURE__*/React.createElement(StyledSwitch, switchStyleProps, /*#__PURE__*/React.createElement(CheckableInput, inputProps, /*#__PURE__*/React.createElement(SwitchSlider, switchSliderProps)))));
182
+ }
183
+ const defaultMargin = labelInline ? 1 : 0;
184
+ const defaultInputWrapperMargin = labelInline ? 3 : 0;
185
+ const errorMargin = error || warning ? defaultInputWrapperMargin : defaultMargin;
186
+ const direction = labelInline ? "row" : "column";
187
+ const reverseDirection = labelInline ? "row-reverse" : "column";
188
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(StyledSwitch, switchStylePropsForNewValidation, /*#__PURE__*/React.createElement(Box, {
189
+ "data-role": "field-reverse-wrapper",
190
+ display: "flex",
191
+ flexWrap: "wrap",
192
+ alignItems: error || warning ? "flex-start" : undefined,
193
+ flexDirection: !reverse ? reverseDirection : direction,
194
+ width: labelInline ? "100%" : "auto"
195
+ }, /*#__PURE__*/React.createElement(Box, {
196
+ "data-role": "label-wrapper"
197
+ // width={labelInline ? rest.labelWidth : 30}
198
+ // minWidth={label && labelInline ? "32px" : 0}
199
+ }, /*#__PURE__*/React.createElement(Label, {
200
+ isDarkBackground: isDarkBackground,
169
201
  labelId: labelId.current,
170
202
  disabled: disabled,
171
203
  isRequired: required,
172
204
  optional: isOptional
173
- }, label), labelHelp && /*#__PURE__*/React.createElement(StyledHintText, {
205
+ }, label), labelHelp && /*#__PURE__*/React.createElement(Box, {
206
+ "data-role": "hint-text-wrapper",
207
+ mb: labelInline ? 0 : 1,
208
+ mr: reverse ? 0 : 1,
209
+ ml: reverse ? 0 : 1
210
+ }, /*#__PURE__*/React.createElement(StyledHintText, {
174
211
  "data-role": "hint-text",
175
- id: inputHintId.current
176
- }, labelHelp), /*#__PURE__*/React.createElement(Box, {
177
- position: "relative"
212
+ id: inputHintId.current,
213
+ isDarkBackground: isDarkBackground
214
+ }, labelHelp))), /*#__PURE__*/React.createElement(Box, {
215
+ ml: reverse ? errorMargin : defaultInputWrapperMargin,
216
+ mr: !reverse ? errorMargin : defaultInputWrapperMargin,
217
+ position: "relative",
218
+ id: "input-wrapper"
178
219
  }, /*#__PURE__*/React.createElement(ValidationMessage, {
179
220
  error: error,
180
221
  warning: warning,
181
- validationId: validationMessageId.current
222
+ validationId: validationMessageId.current,
223
+ isDarkBackground: isDarkBackground
182
224
  }), applyValidation && /*#__PURE__*/React.createElement(ErrorBorder, {
183
225
  "data-role": "error-border",
184
- warning: !!(!error && warning)
226
+ warning: !!(!error && warning),
227
+ reverse: !reverse,
228
+ isDarkBackground: isDarkBackground
185
229
  }), /*#__PURE__*/React.createElement(CheckableInput, _extends({
186
230
  ariaLabelledBy: `${label && labelId.current}`,
187
231
  ariaDescribedBy: ariaDescribedBy
188
- }, inputPropsForNewValidation), /*#__PURE__*/React.createElement(SwitchSlider, switchSliderPropsForNewValidation)))) : /*#__PURE__*/React.createElement(TooltipProvider, {
189
- helpAriaLabel: helpAriaLabel,
190
- tooltipPosition: tooltipPosition
191
- }, /*#__PURE__*/React.createElement(StyledSwitch, switchStyleProps, /*#__PURE__*/React.createElement(CheckableInput, inputProps, /*#__PURE__*/React.createElement(SwitchSlider, switchSliderProps)))));
232
+ }, inputPropsForNewValidation, {
233
+ fieldHelp: labelInline ? undefined : rest.fieldHelp
234
+ }), /*#__PURE__*/React.createElement(SwitchSlider, switchSliderPropsForNewValidation))))), labelInline && rest.fieldHelp && /*#__PURE__*/React.createElement(Box, {
235
+ color: isDarkBackground ? "var(--colorsUtilityYang100)" : "var(--colorsUtilityYin090)"
236
+ }, rest.fieldHelp));
192
237
  });
193
238
  if (process.env.NODE_ENV !== "production") {
194
239
  Switch.propTypes = {
@@ -341,6 +386,7 @@ if (process.env.NODE_ENV !== "production") {
341
386
  "inputMode": PropTypes.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
342
387
  "inputWidth": PropTypes.number,
343
388
  "is": PropTypes.string,
389
+ "isDarkBackground": PropTypes.bool,
344
390
  "isOptional": PropTypes.bool,
345
391
  "itemID": PropTypes.string,
346
392
  "itemProp": PropTypes.string,
@@ -1,6 +1,11 @@
1
+ interface StyledHintTextProps {
2
+ isDarkBackground?: boolean;
3
+ }
1
4
  export declare const ErrorBorder: import("styled-components").StyledComponent<"span", any, {
5
+ reverse: boolean;
2
6
  warning: boolean;
7
+ isDarkBackground: boolean;
3
8
  }, never>;
4
- export declare const StyledHintText: import("styled-components").StyledComponent<"div", any, {}, never>;
9
+ export declare const StyledHintText: import("styled-components").StyledComponent<"div", any, StyledHintTextProps, never>;
5
10
  declare const StyledSwitch: import("styled-components").StyledComponent<"div", any, {}, never>;
6
11
  export default StyledSwitch;