carbon-react 126.7.1 → 126.8.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/components/button-toggle/button-toggle-group/button-toggle-group.component.d.ts +13 -8
- package/esm/components/button-toggle/button-toggle-group/button-toggle-group.component.js +25 -13
- package/esm/components/button-toggle/button-toggle-group/button-toggle-group.style.d.ts +5 -2
- package/esm/components/button-toggle/button-toggle-group/button-toggle-group.style.js +37 -7
- package/esm/components/button-toggle/button-toggle.component.d.ts +1 -1
- package/esm/components/button-toggle/button-toggle.component.js +7 -1
- package/esm/components/button-toggle/button-toggle.style.d.ts +1 -1
- package/esm/components/button-toggle/button-toggle.style.js +54 -77
- package/esm/components/time/__internal__/time-toggle/time-toggle.component.js +4 -9
- package/esm/components/time/time.component.js +1 -1
- package/esm/components/time/time.style.js +1 -1
- package/lib/components/button-toggle/button-toggle-group/button-toggle-group.component.d.ts +13 -8
- package/lib/components/button-toggle/button-toggle-group/button-toggle-group.component.js +23 -11
- package/lib/components/button-toggle/button-toggle-group/button-toggle-group.style.d.ts +5 -2
- package/lib/components/button-toggle/button-toggle-group/button-toggle-group.style.js +38 -8
- package/lib/components/button-toggle/button-toggle.component.d.ts +1 -1
- package/lib/components/button-toggle/button-toggle.component.js +7 -1
- package/lib/components/button-toggle/button-toggle.style.d.ts +1 -1
- package/lib/components/button-toggle/button-toggle.style.js +54 -77
- package/lib/components/time/__internal__/time-toggle/time-toggle.component.js +4 -9
- package/lib/components/time/time.component.js +1 -1
- package/lib/components/time/time.style.js +1 -1
- package/package.json +1 -1
- package/esm/components/time/__internal__/time-toggle/time-toggle.style.d.ts +0 -8
- package/esm/components/time/__internal__/time-toggle/time-toggle.style.js +0 -19
- package/lib/components/time/__internal__/time-toggle/time-toggle.style.d.ts +0 -8
- package/lib/components/time/__internal__/time-toggle/time-toggle.style.js +0 -26
|
@@ -18,17 +18,19 @@ export interface ButtonToggleGroupProps extends MarginProps, TagProps {
|
|
|
18
18
|
"aria-label"?: string;
|
|
19
19
|
/** Text for the visible label of the button group. */
|
|
20
20
|
label?: string;
|
|
21
|
-
/** Text for the label's help tooltip. */
|
|
21
|
+
/** [Legacy] Text for the label's help tooltip. */
|
|
22
22
|
labelHelp?: React.ReactNode;
|
|
23
|
-
/** Spacing between label and a field for inline label, given number will be multiplied by base spacing unit (8) */
|
|
23
|
+
/** [Legacy] Spacing between label and a field for inline label, given number will be multiplied by base spacing unit (8) */
|
|
24
24
|
labelSpacing?: 1 | 2;
|
|
25
|
+
/** A hint string rendered before the input but after the label. Intended to describe the purpose or content of the input. */
|
|
26
|
+
inputHint?: React.ReactNode;
|
|
25
27
|
/** The percentage width of the ButtonToggleGroup. */
|
|
26
28
|
inputWidth?: number | string;
|
|
27
|
-
/** The text for the field help. */
|
|
29
|
+
/** [Legacy] The text for the field help. */
|
|
28
30
|
fieldHelp?: string;
|
|
29
|
-
/** Sets the field help to inline. */
|
|
31
|
+
/** [Legacy] Sets the field help to inline. */
|
|
30
32
|
fieldHelpInline?: boolean;
|
|
31
|
-
/** Sets the label to be inline. */
|
|
33
|
+
/** [Legacy] Sets the label to be inline. */
|
|
32
34
|
labelInline?: boolean;
|
|
33
35
|
/** The percentage width of the label. */
|
|
34
36
|
labelWidth?: number;
|
|
@@ -38,10 +40,12 @@ export interface ButtonToggleGroupProps extends MarginProps, TagProps {
|
|
|
38
40
|
onChange?: (ev: React.MouseEvent<HTMLButtonElement>, value?: string, name?: string) => void;
|
|
39
41
|
/** Determines which child button is selected when the component is used as a controlled component */
|
|
40
42
|
value?: string;
|
|
41
|
-
/** Aria label for rendered help component */
|
|
43
|
+
/** [Legacy] Aria label for rendered help component */
|
|
42
44
|
helpAriaLabel?: string;
|
|
43
|
-
/**
|
|
45
|
+
/** Allow buttons within the group to be deselected when already selected, leaving no selected button */
|
|
44
46
|
allowDeselect?: boolean;
|
|
47
|
+
/** Disable all user interaction. */
|
|
48
|
+
disabled?: boolean;
|
|
45
49
|
/**
|
|
46
50
|
* @private @ignore
|
|
47
51
|
* Set a class on the component
|
|
@@ -56,12 +60,13 @@ declare type ButtonToggleGroupContextType = {
|
|
|
56
60
|
name?: string;
|
|
57
61
|
allowDeselect?: boolean;
|
|
58
62
|
isInGroup: boolean;
|
|
63
|
+
isDisabled?: boolean;
|
|
59
64
|
firstButton?: HTMLButtonElement;
|
|
60
65
|
childButtonCallbackRef?: (button: HTMLButtonElement | null) => void;
|
|
61
66
|
};
|
|
62
67
|
export declare const ButtonToggleGroupContext: React.Context<ButtonToggleGroupContextType>;
|
|
63
68
|
declare const ButtonToggleGroup: {
|
|
64
|
-
({ children, fieldHelp, fieldHelpInline, "aria-label": ariaLabel, label, labelHelp, labelSpacing, inputWidth, fullWidth, labelInline, labelWidth, name, onChange, value, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, helpAriaLabel, id, allowDeselect, className, ...props }: ButtonToggleGroupProps): React.JSX.Element;
|
|
69
|
+
({ children, fieldHelp, fieldHelpInline, "aria-label": ariaLabel, label, labelHelp, labelSpacing, inputHint, inputWidth, fullWidth, labelInline, labelWidth, name, onChange, value, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, helpAriaLabel, id, allowDeselect, disabled, className, ...props }: ButtonToggleGroupProps): React.JSX.Element;
|
|
65
70
|
displayName: string;
|
|
66
71
|
};
|
|
67
72
|
export default ButtonToggleGroup;
|
|
@@ -1,16 +1,17 @@
|
|
|
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, { createContext, useMemo, useState, useRef } from "react";
|
|
2
|
+
import React, { createContext, useMemo, useState, useRef, useContext } from "react";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import invariant from "invariant";
|
|
5
5
|
import FormField from "../../../__internal__/form-field";
|
|
6
6
|
import guid from "../../../__internal__/utils/helpers/guid";
|
|
7
|
-
import StyledButtonToggleGroup, { StyledButtonToggleGroupWrapper } from "./button-toggle-group.style";
|
|
7
|
+
import StyledButtonToggleGroup, { StyledButtonToggleGroupWrapper, StyledHintText } from "./button-toggle-group.style";
|
|
8
8
|
import { ButtonToggle } from "..";
|
|
9
9
|
import { filterStyledSystemMarginProps } from "../../../style/utils";
|
|
10
10
|
import { TooltipProvider } from "../../../__internal__/tooltip-provider";
|
|
11
11
|
import { InputGroupBehaviour } from "../../../__internal__/input-behaviour";
|
|
12
12
|
import Logger from "../../../__internal__/utils/logger";
|
|
13
13
|
import Events from "../../../__internal__/utils/helpers/events";
|
|
14
|
+
import { NewValidationContext } from "../../carbon-provider/carbon-provider.component";
|
|
14
15
|
let deprecateNameWarnTriggered = false;
|
|
15
16
|
const BUTTON_TOGGLE_SELECTOR = '[data-element="button-toggle-button"]';
|
|
16
17
|
export const ButtonToggleGroupContext = /*#__PURE__*/createContext({
|
|
@@ -18,7 +19,8 @@ export const ButtonToggleGroupContext = /*#__PURE__*/createContext({
|
|
|
18
19
|
handleKeyDown: /* istanbul ignore next */() => {},
|
|
19
20
|
pressedButtonValue: undefined,
|
|
20
21
|
allowDeselect: false,
|
|
21
|
-
isInGroup: false
|
|
22
|
+
isInGroup: false,
|
|
23
|
+
isDisabled: false
|
|
22
24
|
});
|
|
23
25
|
const ButtonToggleGroup = ({
|
|
24
26
|
children,
|
|
@@ -28,6 +30,7 @@ const ButtonToggleGroup = ({
|
|
|
28
30
|
label,
|
|
29
31
|
labelHelp,
|
|
30
32
|
labelSpacing,
|
|
33
|
+
inputHint,
|
|
31
34
|
inputWidth,
|
|
32
35
|
fullWidth,
|
|
33
36
|
labelInline,
|
|
@@ -41,6 +44,7 @@ const ButtonToggleGroup = ({
|
|
|
41
44
|
helpAriaLabel,
|
|
42
45
|
id,
|
|
43
46
|
allowDeselect,
|
|
47
|
+
disabled,
|
|
44
48
|
className,
|
|
45
49
|
...props
|
|
46
50
|
}) => {
|
|
@@ -59,6 +63,10 @@ const ButtonToggleGroup = ({
|
|
|
59
63
|
Logger.deprecate(`The \`name\` prop in \`ButtonToggleGroup\` component is deprecated and will soon be removed. It does not provide any functionality
|
|
60
64
|
since the component can no longer be used in an uncontrolled fashion.`);
|
|
61
65
|
}
|
|
66
|
+
const {
|
|
67
|
+
validationRedesignOptIn
|
|
68
|
+
} = useContext(NewValidationContext);
|
|
69
|
+
const computeLabelPropValues = prop => validationRedesignOptIn ? undefined : prop;
|
|
62
70
|
const onButtonClick = buttonValue => {
|
|
63
71
|
let newValue = buttonValue;
|
|
64
72
|
const currentValue = value || pressedButtonValue;
|
|
@@ -112,18 +120,19 @@ const ButtonToggleGroup = ({
|
|
|
112
120
|
helpAriaLabel: helpAriaLabel
|
|
113
121
|
}, /*#__PURE__*/React.createElement(InputGroupBehaviour, null, /*#__PURE__*/React.createElement(FormField, _extends({
|
|
114
122
|
label: label,
|
|
115
|
-
labelHelp: labelHelp,
|
|
123
|
+
labelHelp: computeLabelPropValues(labelHelp),
|
|
116
124
|
labelSpacing: labelSpacing,
|
|
117
|
-
fieldHelp: fieldHelp,
|
|
118
|
-
fieldHelpInline: fieldHelpInline,
|
|
119
|
-
labelInline: labelInline,
|
|
120
|
-
labelWidth: labelWidth,
|
|
125
|
+
fieldHelp: computeLabelPropValues(fieldHelp),
|
|
126
|
+
fieldHelpInline: computeLabelPropValues(fieldHelpInline),
|
|
127
|
+
labelInline: computeLabelPropValues(labelInline),
|
|
128
|
+
labelWidth: computeLabelPropValues(labelWidth),
|
|
121
129
|
labelId: labelId.current,
|
|
122
130
|
"data-component": dataComponent,
|
|
123
131
|
"data-role": dataRole,
|
|
124
132
|
"data-element": dataElement,
|
|
125
133
|
id: id,
|
|
126
|
-
labelAs: "span"
|
|
134
|
+
labelAs: "span",
|
|
135
|
+
disabled: disabled
|
|
127
136
|
}, filterStyledSystemMarginProps(props)), /*#__PURE__*/React.createElement(ButtonToggleGroupContext.Provider, {
|
|
128
137
|
value: {
|
|
129
138
|
onButtonClick,
|
|
@@ -133,10 +142,13 @@ const ButtonToggleGroup = ({
|
|
|
133
142
|
name,
|
|
134
143
|
allowDeselect,
|
|
135
144
|
isInGroup: true,
|
|
145
|
+
isDisabled: disabled,
|
|
136
146
|
firstButton,
|
|
137
147
|
childButtonCallbackRef
|
|
138
148
|
}
|
|
139
|
-
}, /*#__PURE__*/React.createElement(
|
|
149
|
+
}, inputHint && /*#__PURE__*/React.createElement(StyledHintText, {
|
|
150
|
+
isDisabled: disabled
|
|
151
|
+
}, inputHint), /*#__PURE__*/React.createElement(StyledButtonToggleGroupWrapper, {
|
|
140
152
|
labelInline: labelInline,
|
|
141
153
|
ref: wrapperRef
|
|
142
154
|
}, /*#__PURE__*/React.createElement(StyledButtonToggleGroup, _extends({}, label ? {
|
|
@@ -150,9 +162,9 @@ const ButtonToggleGroup = ({
|
|
|
150
162
|
"data-component": dataComponent,
|
|
151
163
|
"data-role": dataRole,
|
|
152
164
|
"data-element": dataElement,
|
|
153
|
-
id: id
|
|
154
|
-
|
|
155
|
-
|
|
165
|
+
id: id,
|
|
166
|
+
className: className,
|
|
167
|
+
disabled: disabled
|
|
156
168
|
}), children))))));
|
|
157
169
|
};
|
|
158
170
|
ButtonToggleGroup.displayName = "ButtonToggleGroup";
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ButtonToggleGroupProps } from ".";
|
|
2
|
-
declare type StyledButtonToggleGroupProps = Pick<ButtonToggleGroupProps, "inputWidth" | "fullWidth">;
|
|
2
|
+
declare type StyledButtonToggleGroupProps = Pick<ButtonToggleGroupProps, "inputWidth" | "fullWidth" | "disabled">;
|
|
3
3
|
declare type StyledButtonToggleGroupWrapperProps = Pick<ButtonToggleGroupProps, "labelInline">;
|
|
4
|
-
export declare const StyledButtonToggleGroupWrapper: import("styled-components").StyledComponent<"div", any, StyledButtonToggleGroupWrapperProps, never>;
|
|
5
4
|
declare const StyledButtonToggleGroup: import("styled-components").StyledComponent<"div", any, StyledButtonToggleGroupProps, never>;
|
|
5
|
+
export declare const StyledButtonToggleGroupWrapper: import("styled-components").StyledComponent<"div", any, StyledButtonToggleGroupWrapperProps, never>;
|
|
6
|
+
export declare const StyledHintText: import("styled-components").StyledComponent<"div", any, {
|
|
7
|
+
isDisabled?: boolean | undefined;
|
|
8
|
+
}, never>;
|
|
6
9
|
export default StyledButtonToggleGroup;
|
|
@@ -2,21 +2,29 @@ import styled, { css } from "styled-components";
|
|
|
2
2
|
import { margin } from "styled-system";
|
|
3
3
|
import { baseTheme } from "../../../style/themes";
|
|
4
4
|
import { StyledButtonToggle, StyledButtonToggleWrapper } from "../button-toggle.style";
|
|
5
|
-
export const StyledButtonToggleGroupWrapper = styled.div`
|
|
6
|
-
${({
|
|
7
|
-
labelInline
|
|
8
|
-
}) => labelInline && css`
|
|
9
|
-
display: flex;
|
|
10
|
-
`}
|
|
11
|
-
`;
|
|
12
5
|
const StyledButtonToggleGroup = styled.div`
|
|
13
6
|
${margin}
|
|
14
7
|
|
|
15
8
|
display: flex;
|
|
9
|
+
box-shadow: inset 0px 0px 0px 1px var(--colorsActionMinor500);
|
|
10
|
+
border-radius: var(--borderRadius100);
|
|
11
|
+
padding: 4px;
|
|
12
|
+
gap: 4px;
|
|
13
|
+
width: fit-content;
|
|
14
|
+
height: fit-content;
|
|
15
|
+
flex-wrap: wrap;
|
|
16
|
+
|
|
17
|
+
${({
|
|
18
|
+
disabled
|
|
19
|
+
}) => disabled && css`
|
|
20
|
+
cursor: not-allowed;
|
|
21
|
+
box-shadow: inset 0px 0px 0px 1px var(--colorsActionDisabled600);
|
|
22
|
+
`}
|
|
16
23
|
|
|
17
24
|
${({
|
|
18
25
|
fullWidth
|
|
19
26
|
}) => fullWidth && css`
|
|
27
|
+
width: 100%;
|
|
20
28
|
${StyledButtonToggle} {
|
|
21
29
|
width: 100%;
|
|
22
30
|
}
|
|
@@ -31,6 +39,28 @@ const StyledButtonToggleGroup = styled.div`
|
|
|
31
39
|
width: ${`${inputWidth}%`};
|
|
32
40
|
`}
|
|
33
41
|
`;
|
|
42
|
+
export const StyledButtonToggleGroupWrapper = styled.div`
|
|
43
|
+
${({
|
|
44
|
+
labelInline
|
|
45
|
+
}) => labelInline && css`
|
|
46
|
+
display: flex;
|
|
47
|
+
${StyledButtonToggleGroup} {
|
|
48
|
+
flex-wrap: nowrap;
|
|
49
|
+
}
|
|
50
|
+
`}
|
|
51
|
+
`;
|
|
52
|
+
export const StyledHintText = styled.div`
|
|
53
|
+
::after {
|
|
54
|
+
content: " ";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
margin-top: var(--spacing000);
|
|
58
|
+
margin-bottom: var(--spacing150);
|
|
59
|
+
color: ${({
|
|
60
|
+
isDisabled
|
|
61
|
+
}) => isDisabled ? "var(--colorsUtilityYin030)" : "var(--colorsUtilityYin055)"};
|
|
62
|
+
font-size: 14px;
|
|
63
|
+
`;
|
|
34
64
|
StyledButtonToggleGroup.defaultProps = {
|
|
35
65
|
theme: baseTheme
|
|
36
66
|
};
|
|
@@ -15,7 +15,7 @@ export interface ButtonToggleProps extends Partial<StyledButtonToggleProps> {
|
|
|
15
15
|
"data-element"?: string;
|
|
16
16
|
/** Identifier used for testing purposes, applied to the root element of the component. */
|
|
17
17
|
"data-role"?: string;
|
|
18
|
-
/** Remove spacing from between buttons. */
|
|
18
|
+
/** DEPRECATED: Remove spacing from between buttons. */
|
|
19
19
|
grouped?: boolean;
|
|
20
20
|
/** An optional string by which to identify the button in an onChange handler on the parent ButtonToggleGroup. */
|
|
21
21
|
name?: string;
|
|
@@ -11,6 +11,7 @@ import { InputGroupContext } from "../../__internal__/input-behaviour";
|
|
|
11
11
|
let deprecateCheckedWarnTriggered = false;
|
|
12
12
|
let deprecateNameWarnTriggered = false;
|
|
13
13
|
let deprecateUncontrolledWarnTriggered = false;
|
|
14
|
+
let deprecateGroupedWarnTriggered = false;
|
|
14
15
|
export const ButtonToggle = ({
|
|
15
16
|
"aria-label": ariaLabel,
|
|
16
17
|
"aria-labelledby": ariaLabelledBy,
|
|
@@ -41,6 +42,10 @@ export const ButtonToggle = ({
|
|
|
41
42
|
Logger.deprecate(`The \`name\` prop in \`ButtonToggle\` component is deprecated and will soon be removed. It does not provide any functionality
|
|
42
43
|
since the component can no longer be used in an uncontrolled fashion.`);
|
|
43
44
|
}
|
|
45
|
+
if (grouped && !deprecateGroupedWarnTriggered) {
|
|
46
|
+
deprecateGroupedWarnTriggered = true;
|
|
47
|
+
Logger.deprecate("The `grouped` prop in `ButtonToggle` component is deprecated and will soon be removed. Spacing between buttons is no longer no removed.");
|
|
48
|
+
}
|
|
44
49
|
const pressedPropValue = pressed === undefined ? checked : pressed;
|
|
45
50
|
const buttonRef = useRef(null);
|
|
46
51
|
const {
|
|
@@ -57,6 +62,7 @@ export const ButtonToggle = ({
|
|
|
57
62
|
name: groupName,
|
|
58
63
|
allowDeselect,
|
|
59
64
|
isInGroup,
|
|
65
|
+
isDisabled,
|
|
60
66
|
firstButton,
|
|
61
67
|
childButtonCallbackRef
|
|
62
68
|
} = useContext(ButtonToggleGroupContext);
|
|
@@ -129,7 +135,7 @@ export const ButtonToggle = ({
|
|
|
129
135
|
buttonIcon: buttonIcon,
|
|
130
136
|
buttonIconSize: buttonIconSize,
|
|
131
137
|
"data-element": "button-toggle-button",
|
|
132
|
-
disabled: disabled,
|
|
138
|
+
disabled: disabled || isDisabled,
|
|
133
139
|
id: inputGuid.current,
|
|
134
140
|
onMouseEnter: onMouseEnter,
|
|
135
141
|
onMouseLeave: onMouseLeave,
|
|
@@ -26,7 +26,7 @@ export interface StyledButtonToggleProps {
|
|
|
26
26
|
/** ButtonToggle size */
|
|
27
27
|
size: "small" | "medium" | "large";
|
|
28
28
|
grouped?: boolean;
|
|
29
|
-
/**
|
|
29
|
+
/** Allow button to be deselected when already selected */
|
|
30
30
|
allowDeselect?: boolean;
|
|
31
31
|
}
|
|
32
32
|
declare const StyledButtonToggle: import("styled-components").StyledComponent<"button", any, StyledButtonToggleProps, never>;
|
|
@@ -3,9 +3,9 @@ import StyledIcon from "../icon/icon.style";
|
|
|
3
3
|
import addFocusStyling from "../../style/utils/add-focus-styling";
|
|
4
4
|
import baseTheme from "../../style/themes/base";
|
|
5
5
|
export const heightConfig = {
|
|
6
|
-
small:
|
|
7
|
-
medium:
|
|
8
|
-
large:
|
|
6
|
+
small: 24,
|
|
7
|
+
medium: 32,
|
|
8
|
+
large: 40
|
|
9
9
|
};
|
|
10
10
|
export const fontSizeConfig = {
|
|
11
11
|
small: 14,
|
|
@@ -13,17 +13,17 @@ export const fontSizeConfig = {
|
|
|
13
13
|
large: 16
|
|
14
14
|
};
|
|
15
15
|
export const paddingConfig = {
|
|
16
|
-
small:
|
|
17
|
-
medium:
|
|
18
|
-
large:
|
|
16
|
+
small: 8,
|
|
17
|
+
medium: 8,
|
|
18
|
+
large: 12
|
|
19
19
|
};
|
|
20
20
|
const heightLargeIconConfig = {
|
|
21
|
-
small:
|
|
22
|
-
medium:
|
|
23
|
-
large:
|
|
21
|
+
small: 72,
|
|
22
|
+
medium: 88,
|
|
23
|
+
large: 120
|
|
24
24
|
};
|
|
25
25
|
const paddingLargeIconConfig = {
|
|
26
|
-
small:
|
|
26
|
+
small: 24,
|
|
27
27
|
medium: 40,
|
|
28
28
|
large: 48
|
|
29
29
|
};
|
|
@@ -46,6 +46,17 @@ const StyledButtonToggle = styled.button`
|
|
|
46
46
|
box-sizing: border-box;
|
|
47
47
|
max-width: 100%;
|
|
48
48
|
|
|
49
|
+
font-weight: 700;
|
|
50
|
+
background-color: transparent;
|
|
51
|
+
cursor: pointer;
|
|
52
|
+
text-align: start;
|
|
53
|
+
color: var(--colorsActionMinor500);
|
|
54
|
+
border: none;
|
|
55
|
+
|
|
56
|
+
${StyledIcon} {
|
|
57
|
+
color: var(--colorsActionMinor500);
|
|
58
|
+
}
|
|
59
|
+
|
|
49
60
|
${({
|
|
50
61
|
size
|
|
51
62
|
}) => css`
|
|
@@ -53,14 +64,17 @@ const StyledButtonToggle = styled.button`
|
|
|
53
64
|
padding: 0 ${paddingConfig[size]}px;
|
|
54
65
|
font-size: ${fontSizeConfig[size]}px;
|
|
55
66
|
`}
|
|
56
|
-
font-weight: 700;
|
|
57
|
-
background-color: transparent;
|
|
58
|
-
cursor: pointer;
|
|
59
|
-
text-align: start;
|
|
60
|
-
color: inherit;
|
|
61
|
-
|
|
62
|
-
border: 1px solid var(--colorsActionMinor500);
|
|
63
67
|
|
|
68
|
+
${({
|
|
69
|
+
buttonIcon,
|
|
70
|
+
buttonIconSize,
|
|
71
|
+
size
|
|
72
|
+
}) => buttonIcon && buttonIconSize === "large" && css`
|
|
73
|
+
height: ${heightLargeIconConfig[size]}px;
|
|
74
|
+
padding: 0 ${paddingLargeIconConfig[size]}px;
|
|
75
|
+
flex-direction: column;
|
|
76
|
+
`}
|
|
77
|
+
|
|
64
78
|
&:focus {
|
|
65
79
|
${({
|
|
66
80
|
theme
|
|
@@ -68,9 +82,22 @@ const StyledButtonToggle = styled.button`
|
|
|
68
82
|
z-index: 100;
|
|
69
83
|
}
|
|
70
84
|
|
|
85
|
+
&:not(:disabled):hover {
|
|
86
|
+
background-color: var(--colorsActionMinor600);
|
|
87
|
+
color: var(--colorsActionMinorYang100);
|
|
88
|
+
${StyledIcon} {
|
|
89
|
+
color: var(--colorsActionMinorYang100);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
71
93
|
&[aria-pressed="true"] {
|
|
72
|
-
background-color: var(--
|
|
73
|
-
color: var(--
|
|
94
|
+
background-color: var(--colorsActionMinor850);
|
|
95
|
+
color: var(--colorsActionMinorYang100);
|
|
96
|
+
|
|
97
|
+
${StyledIcon} {
|
|
98
|
+
color: var(--colorsActionMinorYang100);
|
|
99
|
+
}
|
|
100
|
+
|
|
74
101
|
${({
|
|
75
102
|
allowDeselect
|
|
76
103
|
}) => !allowDeselect && css`
|
|
@@ -78,72 +105,26 @@ const StyledButtonToggle = styled.button`
|
|
|
78
105
|
`}
|
|
79
106
|
}
|
|
80
107
|
|
|
81
|
-
${StyledIcon} {
|
|
82
|
-
width: 16px;
|
|
83
|
-
height: 16px;
|
|
84
|
-
color: var(--colorsActionMinor500);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
${({
|
|
88
|
-
buttonIcon,
|
|
89
|
-
buttonIconSize,
|
|
90
|
-
size
|
|
91
|
-
}) => buttonIcon && buttonIconSize === "large" && css`
|
|
92
|
-
height: ${heightLargeIconConfig[size]}px;
|
|
93
|
-
padding: 0 ${paddingLargeIconConfig[size]}px;
|
|
94
|
-
flex-direction: column;
|
|
95
|
-
`}
|
|
96
108
|
${({
|
|
97
109
|
disabled
|
|
98
110
|
}) => disabled && css`
|
|
111
|
+
cursor: not-allowed;
|
|
112
|
+
|
|
99
113
|
& {
|
|
100
|
-
border-color: var(--colorsActionDisabled500);
|
|
101
114
|
color: var(--colorsActionMinorYin030);
|
|
102
115
|
${StyledIcon} {
|
|
103
116
|
color: var(--colorsActionMinorYin030);
|
|
104
117
|
}
|
|
105
118
|
}
|
|
106
|
-
cursor: not-allowed;
|
|
107
|
-
`}
|
|
108
|
-
|
|
109
|
-
& ${StyledIcon} {
|
|
110
|
-
color: var(--colorsActionMinor500);
|
|
111
|
-
:not([aria-pressed="true"]):not(:disabled):hover {
|
|
112
|
-
color: var(--colorsActionMinorYang100);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
color: var(--colorsActionMinor500);
|
|
117
|
-
|
|
118
|
-
&[aria-pressed="true"]:not(:hover) {
|
|
119
|
-
box-shadow: inset 0px 0px 0px 3px var(--colorsActionMinor500);
|
|
120
|
-
background-color: transparent;
|
|
121
|
-
:focus {
|
|
122
|
-
box-shadow: inset 0px 0px 0px 3px var(--colorsActionMinor500),
|
|
123
|
-
0px 0px 0px var(--borderWidth300) var(--colorsSemanticFocus500),
|
|
124
|
-
0px 0px 0px var(--borderWidth600) var(--colorsUtilityYin090);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
119
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
&:not(:disabled):hover {
|
|
137
|
-
background-color: var(--colorsActionMinor600);
|
|
138
|
-
color: var(--colorsActionMinorYang100);
|
|
139
|
-
|
|
140
|
-
${StyledIcon} {
|
|
141
|
-
color: var(--colorsActionMinorYang100);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
120
|
+
&[aria-pressed="true"] {
|
|
121
|
+
cursor: not-allowed;
|
|
122
|
+
background-color: var(--colorsActionMinorYin030);
|
|
123
|
+
}
|
|
124
|
+
`}
|
|
144
125
|
`;
|
|
145
126
|
const iconFontSizes = {
|
|
146
|
-
smallIcon:
|
|
127
|
+
smallIcon: 20,
|
|
147
128
|
largeIcon: 32
|
|
148
129
|
};
|
|
149
130
|
const StyledButtonToggleIcon = styled.div`
|
|
@@ -207,10 +188,6 @@ const StyledButtonToggleWrapper = styled.div`
|
|
|
207
188
|
`}
|
|
208
189
|
`}
|
|
209
190
|
|
|
210
|
-
&:not(:first-of-type) {
|
|
211
|
-
margin-left: 8px;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
191
|
${({
|
|
215
192
|
grouped
|
|
216
193
|
}) => grouped && css`
|
|
@@ -3,8 +3,7 @@ import React, { useRef, useCallback } from "react";
|
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import guid from "../../../../__internal__/utils/helpers/guid";
|
|
5
5
|
import useLocale from "../../../../hooks/__internal__/useLocale";
|
|
6
|
-
import ButtonToggleGroup from "
|
|
7
|
-
import { ButtonToggle } from "../../../button-toggle";
|
|
6
|
+
import { ButtonToggle, ButtonToggleGroup } from "../../../button-toggle";
|
|
8
7
|
const Toggle = ({
|
|
9
8
|
size,
|
|
10
9
|
onChange,
|
|
@@ -29,23 +28,19 @@ const Toggle = ({
|
|
|
29
28
|
}, [toggleValue, onChange]);
|
|
30
29
|
return /*#__PURE__*/React.createElement(ButtonToggleGroup, _extends({}, wrapperProps, {
|
|
31
30
|
"data-component": "time-button-toggle-group",
|
|
32
|
-
m: "0px 0px 0px
|
|
31
|
+
m: "0px 0px 0px 16px",
|
|
33
32
|
id: internalId.current,
|
|
34
33
|
onChange: handleChange,
|
|
35
34
|
value: toggleValue,
|
|
36
35
|
disabled: disabled
|
|
37
36
|
}), /*#__PURE__*/React.createElement(ButtonToggle, _extends({}, amToggleProps, {
|
|
38
37
|
"data-component": "am-button-toggle",
|
|
39
|
-
grouped: true,
|
|
40
38
|
value: "AM",
|
|
41
|
-
size: size
|
|
42
|
-
disabled: disabled
|
|
39
|
+
size: size
|
|
43
40
|
}), amText), /*#__PURE__*/React.createElement(ButtonToggle, _extends({}, pmToggleProps, {
|
|
44
41
|
"data-component": "pm-button-toggle",
|
|
45
|
-
grouped: true,
|
|
46
42
|
value: "PM",
|
|
47
|
-
size: size
|
|
48
|
-
disabled: disabled
|
|
43
|
+
size: size
|
|
49
44
|
}), pmText));
|
|
50
45
|
};
|
|
51
46
|
Toggle.displayName = "Toggle";
|
|
@@ -18,17 +18,19 @@ export interface ButtonToggleGroupProps extends MarginProps, TagProps {
|
|
|
18
18
|
"aria-label"?: string;
|
|
19
19
|
/** Text for the visible label of the button group. */
|
|
20
20
|
label?: string;
|
|
21
|
-
/** Text for the label's help tooltip. */
|
|
21
|
+
/** [Legacy] Text for the label's help tooltip. */
|
|
22
22
|
labelHelp?: React.ReactNode;
|
|
23
|
-
/** Spacing between label and a field for inline label, given number will be multiplied by base spacing unit (8) */
|
|
23
|
+
/** [Legacy] Spacing between label and a field for inline label, given number will be multiplied by base spacing unit (8) */
|
|
24
24
|
labelSpacing?: 1 | 2;
|
|
25
|
+
/** A hint string rendered before the input but after the label. Intended to describe the purpose or content of the input. */
|
|
26
|
+
inputHint?: React.ReactNode;
|
|
25
27
|
/** The percentage width of the ButtonToggleGroup. */
|
|
26
28
|
inputWidth?: number | string;
|
|
27
|
-
/** The text for the field help. */
|
|
29
|
+
/** [Legacy] The text for the field help. */
|
|
28
30
|
fieldHelp?: string;
|
|
29
|
-
/** Sets the field help to inline. */
|
|
31
|
+
/** [Legacy] Sets the field help to inline. */
|
|
30
32
|
fieldHelpInline?: boolean;
|
|
31
|
-
/** Sets the label to be inline. */
|
|
33
|
+
/** [Legacy] Sets the label to be inline. */
|
|
32
34
|
labelInline?: boolean;
|
|
33
35
|
/** The percentage width of the label. */
|
|
34
36
|
labelWidth?: number;
|
|
@@ -38,10 +40,12 @@ export interface ButtonToggleGroupProps extends MarginProps, TagProps {
|
|
|
38
40
|
onChange?: (ev: React.MouseEvent<HTMLButtonElement>, value?: string, name?: string) => void;
|
|
39
41
|
/** Determines which child button is selected when the component is used as a controlled component */
|
|
40
42
|
value?: string;
|
|
41
|
-
/** Aria label for rendered help component */
|
|
43
|
+
/** [Legacy] Aria label for rendered help component */
|
|
42
44
|
helpAriaLabel?: string;
|
|
43
|
-
/**
|
|
45
|
+
/** Allow buttons within the group to be deselected when already selected, leaving no selected button */
|
|
44
46
|
allowDeselect?: boolean;
|
|
47
|
+
/** Disable all user interaction. */
|
|
48
|
+
disabled?: boolean;
|
|
45
49
|
/**
|
|
46
50
|
* @private @ignore
|
|
47
51
|
* Set a class on the component
|
|
@@ -56,12 +60,13 @@ declare type ButtonToggleGroupContextType = {
|
|
|
56
60
|
name?: string;
|
|
57
61
|
allowDeselect?: boolean;
|
|
58
62
|
isInGroup: boolean;
|
|
63
|
+
isDisabled?: boolean;
|
|
59
64
|
firstButton?: HTMLButtonElement;
|
|
60
65
|
childButtonCallbackRef?: (button: HTMLButtonElement | null) => void;
|
|
61
66
|
};
|
|
62
67
|
export declare const ButtonToggleGroupContext: React.Context<ButtonToggleGroupContextType>;
|
|
63
68
|
declare const ButtonToggleGroup: {
|
|
64
|
-
({ children, fieldHelp, fieldHelpInline, "aria-label": ariaLabel, label, labelHelp, labelSpacing, inputWidth, fullWidth, labelInline, labelWidth, name, onChange, value, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, helpAriaLabel, id, allowDeselect, className, ...props }: ButtonToggleGroupProps): React.JSX.Element;
|
|
69
|
+
({ children, fieldHelp, fieldHelpInline, "aria-label": ariaLabel, label, labelHelp, labelSpacing, inputHint, inputWidth, fullWidth, labelInline, labelWidth, name, onChange, value, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, helpAriaLabel, id, allowDeselect, disabled, className, ...props }: ButtonToggleGroupProps): React.JSX.Element;
|
|
65
70
|
displayName: string;
|
|
66
71
|
};
|
|
67
72
|
export default ButtonToggleGroup;
|
|
@@ -16,6 +16,7 @@ var _tooltipProvider = require("../../../__internal__/tooltip-provider");
|
|
|
16
16
|
var _inputBehaviour = require("../../../__internal__/input-behaviour");
|
|
17
17
|
var _logger = _interopRequireDefault(require("../../../__internal__/utils/logger"));
|
|
18
18
|
var _events = _interopRequireDefault(require("../../../__internal__/utils/helpers/events"));
|
|
19
|
+
var _carbonProvider = require("../../carbon-provider/carbon-provider.component");
|
|
19
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
21
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
21
22
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -27,7 +28,8 @@ const ButtonToggleGroupContext = exports.ButtonToggleGroupContext = /*#__PURE__*
|
|
|
27
28
|
handleKeyDown: /* istanbul ignore next */() => {},
|
|
28
29
|
pressedButtonValue: undefined,
|
|
29
30
|
allowDeselect: false,
|
|
30
|
-
isInGroup: false
|
|
31
|
+
isInGroup: false,
|
|
32
|
+
isDisabled: false
|
|
31
33
|
});
|
|
32
34
|
const ButtonToggleGroup = ({
|
|
33
35
|
children,
|
|
@@ -37,6 +39,7 @@ const ButtonToggleGroup = ({
|
|
|
37
39
|
label,
|
|
38
40
|
labelHelp,
|
|
39
41
|
labelSpacing,
|
|
42
|
+
inputHint,
|
|
40
43
|
inputWidth,
|
|
41
44
|
fullWidth,
|
|
42
45
|
labelInline,
|
|
@@ -50,6 +53,7 @@ const ButtonToggleGroup = ({
|
|
|
50
53
|
helpAriaLabel,
|
|
51
54
|
id,
|
|
52
55
|
allowDeselect,
|
|
56
|
+
disabled,
|
|
53
57
|
className,
|
|
54
58
|
...props
|
|
55
59
|
}) => {
|
|
@@ -68,6 +72,10 @@ const ButtonToggleGroup = ({
|
|
|
68
72
|
_logger.default.deprecate(`The \`name\` prop in \`ButtonToggleGroup\` component is deprecated and will soon be removed. It does not provide any functionality
|
|
69
73
|
since the component can no longer be used in an uncontrolled fashion.`);
|
|
70
74
|
}
|
|
75
|
+
const {
|
|
76
|
+
validationRedesignOptIn
|
|
77
|
+
} = (0, _react.useContext)(_carbonProvider.NewValidationContext);
|
|
78
|
+
const computeLabelPropValues = prop => validationRedesignOptIn ? undefined : prop;
|
|
71
79
|
const onButtonClick = buttonValue => {
|
|
72
80
|
let newValue = buttonValue;
|
|
73
81
|
const currentValue = value || pressedButtonValue;
|
|
@@ -121,18 +129,19 @@ const ButtonToggleGroup = ({
|
|
|
121
129
|
helpAriaLabel: helpAriaLabel
|
|
122
130
|
}, /*#__PURE__*/_react.default.createElement(_inputBehaviour.InputGroupBehaviour, null, /*#__PURE__*/_react.default.createElement(_formField.default, _extends({
|
|
123
131
|
label: label,
|
|
124
|
-
labelHelp: labelHelp,
|
|
132
|
+
labelHelp: computeLabelPropValues(labelHelp),
|
|
125
133
|
labelSpacing: labelSpacing,
|
|
126
|
-
fieldHelp: fieldHelp,
|
|
127
|
-
fieldHelpInline: fieldHelpInline,
|
|
128
|
-
labelInline: labelInline,
|
|
129
|
-
labelWidth: labelWidth,
|
|
134
|
+
fieldHelp: computeLabelPropValues(fieldHelp),
|
|
135
|
+
fieldHelpInline: computeLabelPropValues(fieldHelpInline),
|
|
136
|
+
labelInline: computeLabelPropValues(labelInline),
|
|
137
|
+
labelWidth: computeLabelPropValues(labelWidth),
|
|
130
138
|
labelId: labelId.current,
|
|
131
139
|
"data-component": dataComponent,
|
|
132
140
|
"data-role": dataRole,
|
|
133
141
|
"data-element": dataElement,
|
|
134
142
|
id: id,
|
|
135
|
-
labelAs: "span"
|
|
143
|
+
labelAs: "span",
|
|
144
|
+
disabled: disabled
|
|
136
145
|
}, (0, _utils.filterStyledSystemMarginProps)(props)), /*#__PURE__*/_react.default.createElement(ButtonToggleGroupContext.Provider, {
|
|
137
146
|
value: {
|
|
138
147
|
onButtonClick,
|
|
@@ -142,10 +151,13 @@ const ButtonToggleGroup = ({
|
|
|
142
151
|
name,
|
|
143
152
|
allowDeselect,
|
|
144
153
|
isInGroup: true,
|
|
154
|
+
isDisabled: disabled,
|
|
145
155
|
firstButton,
|
|
146
156
|
childButtonCallbackRef
|
|
147
157
|
}
|
|
148
|
-
}, /*#__PURE__*/_react.default.createElement(_buttonToggleGroup.
|
|
158
|
+
}, inputHint && /*#__PURE__*/_react.default.createElement(_buttonToggleGroup.StyledHintText, {
|
|
159
|
+
isDisabled: disabled
|
|
160
|
+
}, inputHint), /*#__PURE__*/_react.default.createElement(_buttonToggleGroup.StyledButtonToggleGroupWrapper, {
|
|
149
161
|
labelInline: labelInline,
|
|
150
162
|
ref: wrapperRef
|
|
151
163
|
}, /*#__PURE__*/_react.default.createElement(_buttonToggleGroup.default, _extends({}, label ? {
|
|
@@ -159,9 +171,9 @@ const ButtonToggleGroup = ({
|
|
|
159
171
|
"data-component": dataComponent,
|
|
160
172
|
"data-role": dataRole,
|
|
161
173
|
"data-element": dataElement,
|
|
162
|
-
id: id
|
|
163
|
-
|
|
164
|
-
|
|
174
|
+
id: id,
|
|
175
|
+
className: className,
|
|
176
|
+
disabled: disabled
|
|
165
177
|
}), children))))));
|
|
166
178
|
};
|
|
167
179
|
ButtonToggleGroup.displayName = "ButtonToggleGroup";
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ButtonToggleGroupProps } from ".";
|
|
2
|
-
declare type StyledButtonToggleGroupProps = Pick<ButtonToggleGroupProps, "inputWidth" | "fullWidth">;
|
|
2
|
+
declare type StyledButtonToggleGroupProps = Pick<ButtonToggleGroupProps, "inputWidth" | "fullWidth" | "disabled">;
|
|
3
3
|
declare type StyledButtonToggleGroupWrapperProps = Pick<ButtonToggleGroupProps, "labelInline">;
|
|
4
|
-
export declare const StyledButtonToggleGroupWrapper: import("styled-components").StyledComponent<"div", any, StyledButtonToggleGroupWrapperProps, never>;
|
|
5
4
|
declare const StyledButtonToggleGroup: import("styled-components").StyledComponent<"div", any, StyledButtonToggleGroupProps, never>;
|
|
5
|
+
export declare const StyledButtonToggleGroupWrapper: import("styled-components").StyledComponent<"div", any, StyledButtonToggleGroupWrapperProps, never>;
|
|
6
|
+
export declare const StyledHintText: import("styled-components").StyledComponent<"div", any, {
|
|
7
|
+
isDisabled?: boolean | undefined;
|
|
8
|
+
}, never>;
|
|
6
9
|
export default StyledButtonToggleGroup;
|
|
@@ -3,28 +3,36 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.StyledButtonToggleGroupWrapper = void 0;
|
|
6
|
+
exports.default = exports.StyledHintText = exports.StyledButtonToggleGroupWrapper = void 0;
|
|
7
7
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
8
8
|
var _styledSystem = require("styled-system");
|
|
9
9
|
var _themes = require("../../../style/themes");
|
|
10
10
|
var _buttonToggle = require("../button-toggle.style");
|
|
11
11
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
12
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
-
const StyledButtonToggleGroupWrapper = exports.StyledButtonToggleGroupWrapper = _styledComponents.default.div`
|
|
14
|
-
${({
|
|
15
|
-
labelInline
|
|
16
|
-
}) => labelInline && (0, _styledComponents.css)`
|
|
17
|
-
display: flex;
|
|
18
|
-
`}
|
|
19
|
-
`;
|
|
20
13
|
const StyledButtonToggleGroup = _styledComponents.default.div`
|
|
21
14
|
${_styledSystem.margin}
|
|
22
15
|
|
|
23
16
|
display: flex;
|
|
17
|
+
box-shadow: inset 0px 0px 0px 1px var(--colorsActionMinor500);
|
|
18
|
+
border-radius: var(--borderRadius100);
|
|
19
|
+
padding: 4px;
|
|
20
|
+
gap: 4px;
|
|
21
|
+
width: fit-content;
|
|
22
|
+
height: fit-content;
|
|
23
|
+
flex-wrap: wrap;
|
|
24
|
+
|
|
25
|
+
${({
|
|
26
|
+
disabled
|
|
27
|
+
}) => disabled && (0, _styledComponents.css)`
|
|
28
|
+
cursor: not-allowed;
|
|
29
|
+
box-shadow: inset 0px 0px 0px 1px var(--colorsActionDisabled600);
|
|
30
|
+
`}
|
|
24
31
|
|
|
25
32
|
${({
|
|
26
33
|
fullWidth
|
|
27
34
|
}) => fullWidth && (0, _styledComponents.css)`
|
|
35
|
+
width: 100%;
|
|
28
36
|
${_buttonToggle.StyledButtonToggle} {
|
|
29
37
|
width: 100%;
|
|
30
38
|
}
|
|
@@ -39,6 +47,28 @@ const StyledButtonToggleGroup = _styledComponents.default.div`
|
|
|
39
47
|
width: ${`${inputWidth}%`};
|
|
40
48
|
`}
|
|
41
49
|
`;
|
|
50
|
+
const StyledButtonToggleGroupWrapper = exports.StyledButtonToggleGroupWrapper = _styledComponents.default.div`
|
|
51
|
+
${({
|
|
52
|
+
labelInline
|
|
53
|
+
}) => labelInline && (0, _styledComponents.css)`
|
|
54
|
+
display: flex;
|
|
55
|
+
${StyledButtonToggleGroup} {
|
|
56
|
+
flex-wrap: nowrap;
|
|
57
|
+
}
|
|
58
|
+
`}
|
|
59
|
+
`;
|
|
60
|
+
const StyledHintText = exports.StyledHintText = _styledComponents.default.div`
|
|
61
|
+
::after {
|
|
62
|
+
content: " ";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
margin-top: var(--spacing000);
|
|
66
|
+
margin-bottom: var(--spacing150);
|
|
67
|
+
color: ${({
|
|
68
|
+
isDisabled
|
|
69
|
+
}) => isDisabled ? "var(--colorsUtilityYin030)" : "var(--colorsUtilityYin055)"};
|
|
70
|
+
font-size: 14px;
|
|
71
|
+
`;
|
|
42
72
|
StyledButtonToggleGroup.defaultProps = {
|
|
43
73
|
theme: _themes.baseTheme
|
|
44
74
|
};
|
|
@@ -15,7 +15,7 @@ export interface ButtonToggleProps extends Partial<StyledButtonToggleProps> {
|
|
|
15
15
|
"data-element"?: string;
|
|
16
16
|
/** Identifier used for testing purposes, applied to the root element of the component. */
|
|
17
17
|
"data-role"?: string;
|
|
18
|
-
/** Remove spacing from between buttons. */
|
|
18
|
+
/** DEPRECATED: Remove spacing from between buttons. */
|
|
19
19
|
grouped?: boolean;
|
|
20
20
|
/** An optional string by which to identify the button in an onChange handler on the parent ButtonToggleGroup. */
|
|
21
21
|
name?: string;
|
|
@@ -20,6 +20,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
20
20
|
let deprecateCheckedWarnTriggered = false;
|
|
21
21
|
let deprecateNameWarnTriggered = false;
|
|
22
22
|
let deprecateUncontrolledWarnTriggered = false;
|
|
23
|
+
let deprecateGroupedWarnTriggered = false;
|
|
23
24
|
const ButtonToggle = ({
|
|
24
25
|
"aria-label": ariaLabel,
|
|
25
26
|
"aria-labelledby": ariaLabelledBy,
|
|
@@ -50,6 +51,10 @@ const ButtonToggle = ({
|
|
|
50
51
|
_logger.default.deprecate(`The \`name\` prop in \`ButtonToggle\` component is deprecated and will soon be removed. It does not provide any functionality
|
|
51
52
|
since the component can no longer be used in an uncontrolled fashion.`);
|
|
52
53
|
}
|
|
54
|
+
if (grouped && !deprecateGroupedWarnTriggered) {
|
|
55
|
+
deprecateGroupedWarnTriggered = true;
|
|
56
|
+
_logger.default.deprecate("The `grouped` prop in `ButtonToggle` component is deprecated and will soon be removed. Spacing between buttons is no longer no removed.");
|
|
57
|
+
}
|
|
53
58
|
const pressedPropValue = pressed === undefined ? checked : pressed;
|
|
54
59
|
const buttonRef = (0, _react.useRef)(null);
|
|
55
60
|
const {
|
|
@@ -66,6 +71,7 @@ const ButtonToggle = ({
|
|
|
66
71
|
name: groupName,
|
|
67
72
|
allowDeselect,
|
|
68
73
|
isInGroup,
|
|
74
|
+
isDisabled,
|
|
69
75
|
firstButton,
|
|
70
76
|
childButtonCallbackRef
|
|
71
77
|
} = (0, _react.useContext)(_buttonToggleGroup.ButtonToggleGroupContext);
|
|
@@ -138,7 +144,7 @@ const ButtonToggle = ({
|
|
|
138
144
|
buttonIcon: buttonIcon,
|
|
139
145
|
buttonIconSize: buttonIconSize,
|
|
140
146
|
"data-element": "button-toggle-button",
|
|
141
|
-
disabled: disabled,
|
|
147
|
+
disabled: disabled || isDisabled,
|
|
142
148
|
id: inputGuid.current,
|
|
143
149
|
onMouseEnter: onMouseEnter,
|
|
144
150
|
onMouseLeave: onMouseLeave,
|
|
@@ -26,7 +26,7 @@ export interface StyledButtonToggleProps {
|
|
|
26
26
|
/** ButtonToggle size */
|
|
27
27
|
size: "small" | "medium" | "large";
|
|
28
28
|
grouped?: boolean;
|
|
29
|
-
/**
|
|
29
|
+
/** Allow button to be deselected when already selected */
|
|
30
30
|
allowDeselect?: boolean;
|
|
31
31
|
}
|
|
32
32
|
declare const StyledButtonToggle: import("styled-components").StyledComponent<"button", any, StyledButtonToggleProps, never>;
|
|
@@ -12,9 +12,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
12
12
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
14
|
const heightConfig = exports.heightConfig = {
|
|
15
|
-
small:
|
|
16
|
-
medium:
|
|
17
|
-
large:
|
|
15
|
+
small: 24,
|
|
16
|
+
medium: 32,
|
|
17
|
+
large: 40
|
|
18
18
|
};
|
|
19
19
|
const fontSizeConfig = exports.fontSizeConfig = {
|
|
20
20
|
small: 14,
|
|
@@ -22,17 +22,17 @@ const fontSizeConfig = exports.fontSizeConfig = {
|
|
|
22
22
|
large: 16
|
|
23
23
|
};
|
|
24
24
|
const paddingConfig = exports.paddingConfig = {
|
|
25
|
-
small:
|
|
26
|
-
medium:
|
|
27
|
-
large:
|
|
25
|
+
small: 8,
|
|
26
|
+
medium: 8,
|
|
27
|
+
large: 12
|
|
28
28
|
};
|
|
29
29
|
const heightLargeIconConfig = {
|
|
30
|
-
small:
|
|
31
|
-
medium:
|
|
32
|
-
large:
|
|
30
|
+
small: 72,
|
|
31
|
+
medium: 88,
|
|
32
|
+
large: 120
|
|
33
33
|
};
|
|
34
34
|
const paddingLargeIconConfig = {
|
|
35
|
-
small:
|
|
35
|
+
small: 24,
|
|
36
36
|
medium: 40,
|
|
37
37
|
large: 48
|
|
38
38
|
};
|
|
@@ -55,6 +55,17 @@ const StyledButtonToggle = exports.StyledButtonToggle = _styledComponents.defaul
|
|
|
55
55
|
box-sizing: border-box;
|
|
56
56
|
max-width: 100%;
|
|
57
57
|
|
|
58
|
+
font-weight: 700;
|
|
59
|
+
background-color: transparent;
|
|
60
|
+
cursor: pointer;
|
|
61
|
+
text-align: start;
|
|
62
|
+
color: var(--colorsActionMinor500);
|
|
63
|
+
border: none;
|
|
64
|
+
|
|
65
|
+
${_icon.default} {
|
|
66
|
+
color: var(--colorsActionMinor500);
|
|
67
|
+
}
|
|
68
|
+
|
|
58
69
|
${({
|
|
59
70
|
size
|
|
60
71
|
}) => (0, _styledComponents.css)`
|
|
@@ -62,14 +73,17 @@ const StyledButtonToggle = exports.StyledButtonToggle = _styledComponents.defaul
|
|
|
62
73
|
padding: 0 ${paddingConfig[size]}px;
|
|
63
74
|
font-size: ${fontSizeConfig[size]}px;
|
|
64
75
|
`}
|
|
65
|
-
font-weight: 700;
|
|
66
|
-
background-color: transparent;
|
|
67
|
-
cursor: pointer;
|
|
68
|
-
text-align: start;
|
|
69
|
-
color: inherit;
|
|
70
|
-
|
|
71
|
-
border: 1px solid var(--colorsActionMinor500);
|
|
72
76
|
|
|
77
|
+
${({
|
|
78
|
+
buttonIcon,
|
|
79
|
+
buttonIconSize,
|
|
80
|
+
size
|
|
81
|
+
}) => buttonIcon && buttonIconSize === "large" && (0, _styledComponents.css)`
|
|
82
|
+
height: ${heightLargeIconConfig[size]}px;
|
|
83
|
+
padding: 0 ${paddingLargeIconConfig[size]}px;
|
|
84
|
+
flex-direction: column;
|
|
85
|
+
`}
|
|
86
|
+
|
|
73
87
|
&:focus {
|
|
74
88
|
${({
|
|
75
89
|
theme
|
|
@@ -77,9 +91,22 @@ const StyledButtonToggle = exports.StyledButtonToggle = _styledComponents.defaul
|
|
|
77
91
|
z-index: 100;
|
|
78
92
|
}
|
|
79
93
|
|
|
94
|
+
&:not(:disabled):hover {
|
|
95
|
+
background-color: var(--colorsActionMinor600);
|
|
96
|
+
color: var(--colorsActionMinorYang100);
|
|
97
|
+
${_icon.default} {
|
|
98
|
+
color: var(--colorsActionMinorYang100);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
80
102
|
&[aria-pressed="true"] {
|
|
81
|
-
background-color: var(--
|
|
82
|
-
color: var(--
|
|
103
|
+
background-color: var(--colorsActionMinor850);
|
|
104
|
+
color: var(--colorsActionMinorYang100);
|
|
105
|
+
|
|
106
|
+
${_icon.default} {
|
|
107
|
+
color: var(--colorsActionMinorYang100);
|
|
108
|
+
}
|
|
109
|
+
|
|
83
110
|
${({
|
|
84
111
|
allowDeselect
|
|
85
112
|
}) => !allowDeselect && (0, _styledComponents.css)`
|
|
@@ -87,72 +114,26 @@ const StyledButtonToggle = exports.StyledButtonToggle = _styledComponents.defaul
|
|
|
87
114
|
`}
|
|
88
115
|
}
|
|
89
116
|
|
|
90
|
-
${_icon.default} {
|
|
91
|
-
width: 16px;
|
|
92
|
-
height: 16px;
|
|
93
|
-
color: var(--colorsActionMinor500);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
${({
|
|
97
|
-
buttonIcon,
|
|
98
|
-
buttonIconSize,
|
|
99
|
-
size
|
|
100
|
-
}) => buttonIcon && buttonIconSize === "large" && (0, _styledComponents.css)`
|
|
101
|
-
height: ${heightLargeIconConfig[size]}px;
|
|
102
|
-
padding: 0 ${paddingLargeIconConfig[size]}px;
|
|
103
|
-
flex-direction: column;
|
|
104
|
-
`}
|
|
105
117
|
${({
|
|
106
118
|
disabled
|
|
107
119
|
}) => disabled && (0, _styledComponents.css)`
|
|
120
|
+
cursor: not-allowed;
|
|
121
|
+
|
|
108
122
|
& {
|
|
109
|
-
border-color: var(--colorsActionDisabled500);
|
|
110
123
|
color: var(--colorsActionMinorYin030);
|
|
111
124
|
${_icon.default} {
|
|
112
125
|
color: var(--colorsActionMinorYin030);
|
|
113
126
|
}
|
|
114
127
|
}
|
|
115
|
-
cursor: not-allowed;
|
|
116
|
-
`}
|
|
117
|
-
|
|
118
|
-
& ${_icon.default} {
|
|
119
|
-
color: var(--colorsActionMinor500);
|
|
120
|
-
:not([aria-pressed="true"]):not(:disabled):hover {
|
|
121
|
-
color: var(--colorsActionMinorYang100);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
color: var(--colorsActionMinor500);
|
|
126
|
-
|
|
127
|
-
&[aria-pressed="true"]:not(:hover) {
|
|
128
|
-
box-shadow: inset 0px 0px 0px 3px var(--colorsActionMinor500);
|
|
129
|
-
background-color: transparent;
|
|
130
|
-
:focus {
|
|
131
|
-
box-shadow: inset 0px 0px 0px 3px var(--colorsActionMinor500),
|
|
132
|
-
0px 0px 0px var(--borderWidth300) var(--colorsSemanticFocus500),
|
|
133
|
-
0px 0px 0px var(--borderWidth600) var(--colorsUtilityYin090);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
128
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
&:not(:disabled):hover {
|
|
146
|
-
background-color: var(--colorsActionMinor600);
|
|
147
|
-
color: var(--colorsActionMinorYang100);
|
|
148
|
-
|
|
149
|
-
${_icon.default} {
|
|
150
|
-
color: var(--colorsActionMinorYang100);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
129
|
+
&[aria-pressed="true"] {
|
|
130
|
+
cursor: not-allowed;
|
|
131
|
+
background-color: var(--colorsActionMinorYin030);
|
|
132
|
+
}
|
|
133
|
+
`}
|
|
153
134
|
`;
|
|
154
135
|
const iconFontSizes = {
|
|
155
|
-
smallIcon:
|
|
136
|
+
smallIcon: 20,
|
|
156
137
|
largeIcon: 32
|
|
157
138
|
};
|
|
158
139
|
const StyledButtonToggleIcon = exports.StyledButtonToggleIcon = _styledComponents.default.div`
|
|
@@ -216,10 +197,6 @@ const StyledButtonToggleWrapper = exports.StyledButtonToggleWrapper = _styledCom
|
|
|
216
197
|
`}
|
|
217
198
|
`}
|
|
218
199
|
|
|
219
|
-
&:not(:first-of-type) {
|
|
220
|
-
margin-left: 8px;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
200
|
${({
|
|
224
201
|
grouped
|
|
225
202
|
}) => grouped && (0, _styledComponents.css)`
|
|
@@ -8,7 +8,6 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _guid = _interopRequireDefault(require("../../../../__internal__/utils/helpers/guid"));
|
|
10
10
|
var _useLocale = _interopRequireDefault(require("../../../../hooks/__internal__/useLocale"));
|
|
11
|
-
var _timeToggle = _interopRequireDefault(require("./time-toggle.style"));
|
|
12
11
|
var _buttonToggle = require("../../../button-toggle");
|
|
13
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
13
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -36,25 +35,21 @@ const Toggle = ({
|
|
|
36
35
|
onChange(selectedButtonValue);
|
|
37
36
|
}
|
|
38
37
|
}, [toggleValue, onChange]);
|
|
39
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
38
|
+
return /*#__PURE__*/_react.default.createElement(_buttonToggle.ButtonToggleGroup, _extends({}, wrapperProps, {
|
|
40
39
|
"data-component": "time-button-toggle-group",
|
|
41
|
-
m: "0px 0px 0px
|
|
40
|
+
m: "0px 0px 0px 16px",
|
|
42
41
|
id: internalId.current,
|
|
43
42
|
onChange: handleChange,
|
|
44
43
|
value: toggleValue,
|
|
45
44
|
disabled: disabled
|
|
46
45
|
}), /*#__PURE__*/_react.default.createElement(_buttonToggle.ButtonToggle, _extends({}, amToggleProps, {
|
|
47
46
|
"data-component": "am-button-toggle",
|
|
48
|
-
grouped: true,
|
|
49
47
|
value: "AM",
|
|
50
|
-
size: size
|
|
51
|
-
disabled: disabled
|
|
48
|
+
size: size
|
|
52
49
|
}), amText), /*#__PURE__*/_react.default.createElement(_buttonToggle.ButtonToggle, _extends({}, pmToggleProps, {
|
|
53
50
|
"data-component": "pm-button-toggle",
|
|
54
|
-
grouped: true,
|
|
55
51
|
value: "PM",
|
|
56
|
-
size: size
|
|
57
|
-
disabled: disabled
|
|
52
|
+
size: size
|
|
58
53
|
}), pmText));
|
|
59
54
|
};
|
|
60
55
|
Toggle.displayName = "Toggle";
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
declare const _default: import("styled-components").StyledComponent<{
|
|
3
|
-
({ children, fieldHelp, fieldHelpInline, "aria-label": ariaLabel, label, labelHelp, labelSpacing, inputWidth, fullWidth, labelInline, labelWidth, name, onChange, value, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, helpAriaLabel, id, allowDeselect, className, ...props }: import("../../../button-toggle").ButtonToggleGroupProps): import("react").JSX.Element;
|
|
4
|
-
displayName: string;
|
|
5
|
-
}, any, {
|
|
6
|
-
disabled?: boolean | undefined;
|
|
7
|
-
}, never>;
|
|
8
|
-
export default _default;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import styled, { css } from "styled-components";
|
|
2
|
-
import { ButtonToggleGroup } from "../../../button-toggle";
|
|
3
|
-
|
|
4
|
-
// TODO this can be removed as part of FE-6335
|
|
5
|
-
export default styled(ButtonToggleGroup)`
|
|
6
|
-
${({
|
|
7
|
-
disabled
|
|
8
|
-
}) => disabled && css`
|
|
9
|
-
opacity: 0.3;
|
|
10
|
-
|
|
11
|
-
[aria-pressed="true"] {
|
|
12
|
-
cursor: not-allowed;
|
|
13
|
-
:hover {
|
|
14
|
-
background-color: transparent;
|
|
15
|
-
box-shadow: inset 0px 0px 0px 3px var(--colorsActionMinor500);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
`}
|
|
19
|
-
`;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
declare const _default: import("styled-components").StyledComponent<{
|
|
3
|
-
({ children, fieldHelp, fieldHelpInline, "aria-label": ariaLabel, label, labelHelp, labelSpacing, inputWidth, fullWidth, labelInline, labelWidth, name, onChange, value, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, helpAriaLabel, id, allowDeselect, className, ...props }: import("../../../button-toggle").ButtonToggleGroupProps): import("react").JSX.Element;
|
|
4
|
-
displayName: string;
|
|
5
|
-
}, any, {
|
|
6
|
-
disabled?: boolean | undefined;
|
|
7
|
-
}, never>;
|
|
8
|
-
export default _default;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
8
|
-
var _buttonToggle = require("../../../button-toggle");
|
|
9
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
-
// TODO this can be removed as part of FE-6335
|
|
12
|
-
var _default = exports.default = (0, _styledComponents.default)(_buttonToggle.ButtonToggleGroup)`
|
|
13
|
-
${({
|
|
14
|
-
disabled
|
|
15
|
-
}) => disabled && (0, _styledComponents.css)`
|
|
16
|
-
opacity: 0.3;
|
|
17
|
-
|
|
18
|
-
[aria-pressed="true"] {
|
|
19
|
-
cursor: not-allowed;
|
|
20
|
-
:hover {
|
|
21
|
-
background-color: transparent;
|
|
22
|
-
box-shadow: inset 0px 0px 0px 3px var(--colorsActionMinor500);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
`}
|
|
26
|
-
`;
|